more controls fixes

This commit is contained in:
austin 2022-02-18 00:01:12 -05:00
parent 5c38ad7e1a
commit 7efa0acf70
5 changed files with 48 additions and 4 deletions

View File

@ -7,7 +7,7 @@ import electrosphere.logger.LoggerInterface;
public class ControlCallback implements GLFWKeyCallbackI {
static final int KEY_VALUE_ARRAY_SIZE = 512;
static final short KEY_VALUE_ARRAY_SIZE = 512;
boolean[] keyValues = new boolean[KEY_VALUE_ARRAY_SIZE];

View File

@ -363,7 +363,6 @@ public class ControlHandler {
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
if(
(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) &&
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
){
@ -377,7 +376,6 @@ public class ControlHandler {
GroundMovementTree movementTree = CreatureUtils.getEntityMovementTree(Globals.playerCharacter);
Vector3f cameraEyeVector = CameraEntityUtils.getCameraEye(Globals.playerCamera);
if(
(movementTree.getState()==MovementTreeState.IDLE || movementTree.getState()==MovementTreeState.SLOWDOWN) &&
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_FORWARD).getKeyValue())) &&
(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).isIsKey() && !Globals.controlCallback.getKey(controls.get(DATA_STRING_INPUT_CODE_MOVEMENT_BACKWARD).getKeyValue()))
){
@ -658,7 +656,7 @@ public class ControlHandler {
control.setState(false);
}
} else if(control.isIsMouse()){
if(Globals.controlCallback.getKey(control.getKeyValue())){
if(Globals.mouseCallback.getButton(control.getKeyValue())){
if(!control.isState()){
//on press
control.onPress();

View File

@ -0,0 +1,39 @@
package electrosphere.controls;
import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWMouseButtonCallback;
import electrosphere.logger.LoggerInterface;
public class MouseCallback extends GLFWMouseButtonCallback {
static final short KEY_VALUE_ARRAY_SIZE = 512;
boolean[] buttonValues = new boolean[KEY_VALUE_ARRAY_SIZE];
@Override
public void invoke(long window, int button, int action, int mods) {
if(button >= 0 && button < KEY_VALUE_ARRAY_SIZE){
if(action == GLFW.GLFW_PRESS || action == GLFW.GLFW_REPEAT){
buttonValues[button] = true;
} else {
buttonValues[button] = false;
}
}
}
/**
* !!!WARNING!!!, will silently fail if
* @param keycode
* @return
*/
public boolean getButton(int keycode){
if(keycode >= 0 && keycode < KEY_VALUE_ARRAY_SIZE){
return buttonValues[keycode];
} else {
LoggerInterface.loggerEngine.WARNING("Trying to get button state where keycode is undefined (<0 or >400)");
}
return false;
}
}

View File

@ -10,6 +10,7 @@ import com.google.gson.Gson;
import electrosphere.audio.AudioEngine;
import electrosphere.controls.ControlCallback;
import electrosphere.controls.ControlHandler;
import electrosphere.controls.MouseCallback;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityManager;
import electrosphere.game.collision.CollisionEngine;
@ -121,6 +122,7 @@ public class Globals {
public static ControlHandler controlHandler;
public static boolean updateCamera = true;
public static ControlCallback controlCallback;
public static MouseCallback mouseCallback;
//

View File

@ -1,6 +1,7 @@
package electrosphere.renderer;
import electrosphere.controls.ControlCallback;
import electrosphere.controls.MouseCallback;
import electrosphere.entity.CameraEntityUtils;
import electrosphere.entity.Entity;
import electrosphere.entity.EntityDataStrings;
@ -164,6 +165,10 @@ public class RenderingEngine {
Globals.controlCallback = new ControlCallback();
GLFW.glfwSetKeyCallback(Globals.window, Globals.controlCallback);
//set mouse callback
Globals.mouseCallback = new MouseCallback();
GLFW.glfwSetMouseButtonCallback(Globals.window, Globals.mouseCallback);
//get title bar dimensions
// setTitleBarDimensions();