<commit_before>package com.servegame.abendstern.tunnelblick.backend;

import java.awt.event.*;

/**
 * Input driver which translates mouse motion into pointer and/or body
 * control.
 *
 * The driver is modal in that, at any given time, it is controlling EITHER
 * pointer zero or body 0. The mouse whell is used to select mode; up shifts to
 * pointer mode, down to body mode.
 */
public final class ModalMouseMotionInputDriver
extends AWTInputDriver
implements MouseMotionListener, MouseWheelListener {
  private boolean pointerMode = true;
  private GameManager manager = null;

  /**
   * Sets the mode to use. True is pointer mode, false is body mode.
   */
  public void setPointerMode(boolean pointerMode) {
    this.pointerMode = pointerMode;
  }

  public void installInto(GameManager man) {
    manager = man;
    man.getCanvas().addMouseMotionListener(this);
    man.getFrame ().addMouseWheelListener (this);
  }

  public void mouseMoved(MouseEvent evt) {
    java.awt.Component canvas = manager.getCanvas();
    float x = evt.getX() / (float)canvas.getWidth();
    float y = evt.getY() / (float)canvas.getHeight() * manager.vheight();
    //OpenGL's Y axis is upside-down
    y = manager.vheight() - y;

    InputStatus is = manager.getSharedInputStatus();

    if (pointerMode) {
      is.pointers[0][0] = x;
      is.pointers[0][1] = y;
      enqueue(new InputEvent(InputEvent.TYPE_POINTER_MOVEMENT, 0, x, y));
    } else {
      is.bodies[0] = x;
      enqueue(new InputEvent(InputEvent.TYPE_BODY_MOVEMENT, 0, x, y));
    }
  }

  public void mouseDragged(MouseEvent evt) {
    mouseMoved(evt);
  }

  public void mouseWheelMoved(MouseWheelEvent evt) {
    pointerMode = (evt.getWheelRotation() < 0);
  }
}<commit_msg>Fix ModalMouseMotionInputDriver not synchronising on the manager when mutating state.<commit_after>package com.servegame.abendstern.tunnelblick.backend;

import java.awt.event.*;

/**
 * Input driver which translates mouse motion into pointer and/or body
 * control.
 *
 * The driver is modal in that, at any given time, it is controlling EITHER
 * pointer zero or body 0. The mouse whell is used to select mode; up shifts to
 * pointer mode, down to body mode.
 */
public final class ModalMouseMotionInputDriver
extends AWTInputDriver
implements MouseMotionListener, MouseWheelListener {
  private boolean pointerMode = true;
  private GameManager manager = null;

  /**
   * Sets the mode to use. True is pointer mode, false is body mode.
   */
  public void setPointerMode(boolean pointerMode) {
    this.pointerMode = pointerMode;
  }

  public void installInto(GameManager man) {
    manager = man;
    man.getCanvas().addMouseMotionListener(this);
    man.getFrame ().addMouseWheelListener (this);
  }

  public void mouseMoved(MouseEvent evt) {
    java.awt.Component canvas = manager.getCanvas();
    float x = evt.getX() / (float)canvas.getWidth();
    float y = evt.getY() / (float)canvas.getHeight() * manager.vheight();
    //OpenGL's Y axis is upside-down
    y = manager.vheight() - y;

    InputStatus is = manager.getSharedInputStatus();

    synchronized (manager) {
      if (pointerMode) {
        is.pointers[0][0] = x;
        is.pointers[0][1] = y;
        enqueue(new InputEvent(InputEvent.TYPE_POINTER_MOVEMENT, 0, x, y));
      } else {
        is.bodies[0] = x;
        enqueue(new InputEvent(InputEvent.TYPE_BODY_MOVEMENT, 0, x, y));
      }
    }
  }

  public void mouseDragged(MouseEvent evt) {
    mouseMoved(evt);
  }

  public void mouseWheelMoved(MouseWheelEvent evt) {
    pointerMode = (evt.getWheelRotation() < 0);
  }
}
{'fraction_non_alphanumeric': 0.10665552770815928, 'fraction_numerical': 0.005012531328320802, 'mean_word_length': 3.484394506866417, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6349555', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1121, 'n_words': 321}