|
@@ -17,7 +17,7 @@ static void dummyWindowRenderHandler(void*, float) {
|
|
|
}
|
|
|
|
|
|
static GLFWwindow* window = nullptr;
|
|
|
-static CoreIntVector2 size = {0, 0};
|
|
|
+static CoreIntVector2 size = {0};
|
|
|
static bool sizeChanged = false;
|
|
|
static CoreWindowRunHandler runHandler = dummyWindowRunHandler;
|
|
|
static CoreWindowTickHandler tickHandler = dummyWindowTickHandler;
|
|
@@ -53,23 +53,25 @@ typedef struct {
|
|
|
int controllerDown;
|
|
|
} ButtonData;
|
|
|
#define BUTTONS 100
|
|
|
-static ButtonData buttons[BUTTONS] = {0};
|
|
|
-static size_t buttonIndex = 0;
|
|
|
-static CoreHashMap keyToButtonId = {0}; // int -> CoreButton
|
|
|
-static CoreHashMap gamepadToButtonId = {0}; // int -> CoreButton
|
|
|
-static CoreHashMap mouseToButtonId = {0}; // int -> CoreButton
|
|
|
+static ButtonData buttons[BUTTONS] = {{.name = "unknown"}};
|
|
|
+static size_t buttonIndex = 1;
|
|
|
+#define KEYS (GLFW_KEY_LAST + 1)
|
|
|
+static CoreButton keyToButton[KEYS] = {0};
|
|
|
+#define GAMEPAD_BUTTONS (GLFW_GAMEPAD_BUTTON_LAST + 1)
|
|
|
+static CoreButton gamepadToButton[GAMEPAD_BUTTONS] = {0};
|
|
|
+#define MOUSE_BUTTONS (GLFW_MOUSE_BUTTON_LAST + 1)
|
|
|
+static CoreButton mouseToButton[MOUSE_BUTTONS] = {0};
|
|
|
static CoreVector2 lastMousePosition = {0};
|
|
|
static CoreVector2 mousePosition = {0};
|
|
|
static int activeController = -1;
|
|
|
static GLFWgamepadstate lastControllerState = {0};
|
|
|
|
|
|
-static void onButton(CoreHashMap* map, int key, int action) {
|
|
|
- CoreButton* bp = coreHashMapSearch(map, int, key, CoreButton);
|
|
|
- if(bp == nullptr) {
|
|
|
+static void onButton(CoreButton* map, int n, int key, int action) {
|
|
|
+ if(key < 0 || key >= n) {
|
|
|
return;
|
|
|
}
|
|
|
- CoreButton b = *bp;
|
|
|
- if(b >= buttonIndex) {
|
|
|
+ CoreButton b = map[key];
|
|
|
+ if(b == 0 || b >= buttonIndex) {
|
|
|
return;
|
|
|
}
|
|
|
if(action == GLFW_RELEASE) {
|
|
@@ -112,7 +114,7 @@ static void onKey(GLFWwindow*, int key, int scancode, int action, int mods) {
|
|
|
// if(inputActive) {
|
|
|
// handleInputKey(key, action);
|
|
|
// }
|
|
|
- onButton(&keyToButtonId, key, action);
|
|
|
+ onButton(keyToButton, KEYS, key, action);
|
|
|
}
|
|
|
|
|
|
/*static void addUnicode(uint32 codepoint) {
|
|
@@ -140,7 +142,7 @@ static void onResize(GLFWwindow*, int width, int height) {
|
|
|
|
|
|
static void onMouse(GLFWwindow*, int button, int action, int mods) {
|
|
|
(void)mods;
|
|
|
- onButton(&mouseToButtonId, button, action);
|
|
|
+ onButton(mouseToButton, MOUSE_BUTTONS, button, action);
|
|
|
}
|
|
|
|
|
|
static void onMouseMove(GLFWwindow*, double x, double y) {
|
|
@@ -174,7 +176,6 @@ bool coreWindowOpen(const CoreWindowOptions* o) {
|
|
|
glfwSetFramebufferSizeCallback(window, onResize);
|
|
|
glfwSetMouseButtonCallback(window, onMouse);
|
|
|
glfwSetCursorPosCallback(window, onMouseMove);
|
|
|
-
|
|
|
return false;
|
|
|
}
|
|
|
|
|
@@ -268,13 +269,8 @@ static void checkGamepad() {
|
|
|
return;
|
|
|
}
|
|
|
for(int i = 0; i <= GLFW_GAMEPAD_BUTTON_LAST; i++) {
|
|
|
- CoreButton* bp =
|
|
|
- coreHashMapSearch(&gamepadToButtonId, int, i, CoreButton);
|
|
|
- if(bp == nullptr) {
|
|
|
- return;
|
|
|
- }
|
|
|
- CoreButton b = *bp;
|
|
|
- if(b >= buttonIndex) {
|
|
|
+ CoreButton b = gamepadToButton[i];
|
|
|
+ if(b == 0 || b >= buttonIndex) {
|
|
|
return;
|
|
|
}
|
|
|
if(!lastControllerState.buttons[i] && state.buttons[i]) {
|
|
@@ -424,21 +420,7 @@ const List<uint32>& Window::Input::getUnicode() {
|
|
|
return input;
|
|
|
}*/
|
|
|
|
|
|
-void coreInitButton(void) {
|
|
|
- coreButtonAdd("unknown");
|
|
|
- coreInitHashMap(&keyToButtonId, sizeof(int), sizeof(CoreButton));
|
|
|
- coreInitHashMap(&gamepadToButtonId, sizeof(int), sizeof(CoreButton));
|
|
|
- coreInitHashMap(&mouseToButtonId, sizeof(int), sizeof(CoreButton));
|
|
|
-}
|
|
|
-
|
|
|
-void coreDestroyButton(void) {
|
|
|
- buttonIndex = 0;
|
|
|
- coreDestroyHashMap(&keyToButtonId);
|
|
|
- coreDestroyHashMap(&gamepadToButtonId);
|
|
|
- coreDestroyHashMap(&mouseToButtonId);
|
|
|
-}
|
|
|
-
|
|
|
-CoreButton coreButtonAdd(const char* name) {
|
|
|
+CoreButton coreControlsAdd(const char* name) {
|
|
|
if(buttonIndex >= BUTTONS) {
|
|
|
return 0;
|
|
|
}
|
|
@@ -447,41 +429,47 @@ CoreButton coreButtonAdd(const char* name) {
|
|
|
return b;
|
|
|
}
|
|
|
|
|
|
-void coreButtonBindKey(CoreButton b, int key) {
|
|
|
- coreHashMapPut(&keyToButtonId, int, key, CoreButton, b);
|
|
|
+void coreControlsBindKey(CoreButton b, int key) {
|
|
|
+ if(key >= 0 && key < KEYS) {
|
|
|
+ keyToButton[key] = b;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-void coreButtonBindGamepad(CoreButton b, int gamepadButton) {
|
|
|
- coreHashMapPut(&gamepadToButtonId, int, gamepadButton, CoreButton, b);
|
|
|
+void coreControlsBindGamepad(CoreButton b, int gamepadButton) {
|
|
|
+ if(gamepadButton >= 0 && gamepadButton < GAMEPAD_BUTTONS) {
|
|
|
+ gamepadToButton[gamepadButton] = b;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-void coreButtonBindMouse(CoreButton b, int mouseButton) {
|
|
|
- coreHashMapPut(&mouseToButtonId, int, mouseButton, CoreButton, b);
|
|
|
+void coreControlsBindMouse(CoreButton b, int mouseButton) {
|
|
|
+ if(mouseButton >= 0 && mouseButton < MOUSE_BUTTONS) {
|
|
|
+ mouseToButton[mouseButton] = b;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-CoreVector2 coreButtonLastMousePosition(void) {
|
|
|
+CoreVector2 coreControlsLastMousePosition(void) {
|
|
|
return lastMousePosition;
|
|
|
}
|
|
|
|
|
|
-CoreVector2 coreButtonMousePosition(void) {
|
|
|
+CoreVector2 coreControlsMousePosition(void) {
|
|
|
return mousePosition;
|
|
|
}
|
|
|
|
|
|
-CoreVector2 coreButtonLeftGamepadAxis(void) {
|
|
|
- return (CoreVector2){lastControllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_X],
|
|
|
- lastControllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_Y]};
|
|
|
+CoreVector2 coreControlsLeftGamepadAxis(void) {
|
|
|
+ return (CoreVector2){{lastControllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_X],
|
|
|
+ lastControllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_Y]}};
|
|
|
}
|
|
|
|
|
|
-CoreVector2 coreButtonRightGamepadAxis(void) {
|
|
|
- return (CoreVector2){lastControllerState.axes[GLFW_GAMEPAD_AXIS_RIGHT_X],
|
|
|
- lastControllerState.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y]};
|
|
|
+CoreVector2 coreControlsRightGamepadAxis(void) {
|
|
|
+ return (CoreVector2){{lastControllerState.axes[GLFW_GAMEPAD_AXIS_RIGHT_X],
|
|
|
+ lastControllerState.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y]}};
|
|
|
}
|
|
|
|
|
|
-float coreButtonLeftGamepadTrigger(void) {
|
|
|
+float coreControlsLeftGamepadTrigger(void) {
|
|
|
return lastControllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_TRIGGER];
|
|
|
}
|
|
|
|
|
|
-float coreButtonRightGamepadTrigger(void) {
|
|
|
+float coreControlsRightGamepadTrigger(void) {
|
|
|
return lastControllerState.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER];
|
|
|
}
|
|
|
|
|
@@ -489,18 +477,18 @@ static const ButtonData* getButton(CoreButton id) {
|
|
|
return buttons + (id >= buttonIndex ? 0 : id);
|
|
|
}
|
|
|
|
|
|
-bool coreButtonDown(CoreButton b) {
|
|
|
+bool coreControlsDown(CoreButton b) {
|
|
|
return getButton(b)->downTime > 0;
|
|
|
}
|
|
|
|
|
|
-int coreButtonDownTime(CoreButton b) {
|
|
|
+int coreControlsDownTime(CoreButton b) {
|
|
|
return getButton(b)->downTime;
|
|
|
}
|
|
|
|
|
|
-bool coreButtonReleased(CoreButton b) {
|
|
|
+bool coreControlsReleased(CoreButton b) {
|
|
|
return getButton(b)->released;
|
|
|
}
|
|
|
|
|
|
-const char* coreButtonName(CoreButton b) {
|
|
|
+const char* coreControlsName(CoreButton b) {
|
|
|
return getButton(b)->name;
|
|
|
}
|