|
@@ -1,3 +1,4 @@
|
|
|
+#define IMPORT_CORE
|
|
|
#include "core/Window.h"
|
|
|
|
|
|
#include <GLFW/glfw3.h>
|
|
@@ -7,7 +8,7 @@
|
|
|
#include <stdio.h>
|
|
|
|
|
|
static bool dummyWindowRunHandler(void*) {
|
|
|
- return !coreWindowShouldClose();
|
|
|
+ return !shouldWindowClose();
|
|
|
}
|
|
|
|
|
|
static void dummyWindowTickHandler(void*) {
|
|
@@ -17,11 +18,11 @@ static void dummyWindowRenderHandler(void*, float) {
|
|
|
}
|
|
|
|
|
|
static GLFWwindow* window = nullptr;
|
|
|
-static CoreIntVector2 size = {0};
|
|
|
+static IntVector2 size = {0};
|
|
|
static bool sizeChanged = false;
|
|
|
-static CoreWindowRunHandler runHandler = dummyWindowRunHandler;
|
|
|
-static CoreWindowTickHandler tickHandler = dummyWindowTickHandler;
|
|
|
-static CoreWindowRenderHandler renderHandler = dummyWindowRenderHandler;
|
|
|
+static WindowRunHandler runHandler = dummyWindowRunHandler;
|
|
|
+static WindowTickHandler tickHandler = dummyWindowTickHandler;
|
|
|
+static WindowRenderHandler renderHandler = dummyWindowRenderHandler;
|
|
|
static void* runHandlerData = nullptr;
|
|
|
static void* tickHandlerData = nullptr;
|
|
|
static void* renderHandlerData = nullptr;
|
|
@@ -56,21 +57,21 @@ typedef struct {
|
|
|
static ButtonData buttons[BUTTONS] = {{.name = "unknown"}};
|
|
|
static size_t buttonIndex = 1;
|
|
|
#define KEYS (GLFW_KEY_LAST + 1)
|
|
|
-static CoreButton keyToButton[KEYS] = {0};
|
|
|
+static Button keyToButton[KEYS] = {0};
|
|
|
#define GAMEPAD_BUTTONS (GLFW_GAMEPAD_BUTTON_LAST + 1)
|
|
|
-static CoreButton gamepadToButton[GAMEPAD_BUTTONS] = {0};
|
|
|
+static Button 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 Button mouseToButton[MOUSE_BUTTONS] = {0};
|
|
|
+static Vector2 lastMousePosition = {0};
|
|
|
+static Vector2 mousePosition = {0};
|
|
|
static int activeController = -1;
|
|
|
static GLFWgamepadstate lastControllerState = {0};
|
|
|
|
|
|
-static void onButton(CoreButton* map, int n, int key, int action) {
|
|
|
+static void onButton(Button* map, int n, int key, int action) {
|
|
|
if(key < 0 || key >= n) {
|
|
|
return;
|
|
|
}
|
|
|
- CoreButton b = map[key];
|
|
|
+ Button b = map[key];
|
|
|
if(b == 0 || b >= buttonIndex) {
|
|
|
return;
|
|
|
}
|
|
@@ -123,7 +124,7 @@ static void onKey(GLFWwindow*, int key, int scancode, int action, int mods) {
|
|
|
}
|
|
|
input.add(codepoint);
|
|
|
for(int i = input.getLength() - 1; i > inputCursor; i--) {
|
|
|
- Core::swap(input[i], input[i - 1]);
|
|
|
+ ::swap(input[i], input[i - 1]);
|
|
|
}
|
|
|
inputCursor++;
|
|
|
}
|
|
@@ -150,7 +151,7 @@ static void onMouseMove(GLFWwindow*, double x, double y) {
|
|
|
mousePosition.data[1] = (float)y;
|
|
|
}
|
|
|
|
|
|
-bool coreWindowOpen(const CoreWindowOptions* o) {
|
|
|
+bool openWindow(const WindowOptions* o) {
|
|
|
if(!glfwInit()) {
|
|
|
CORE_LOG_ERROR("could not initialize GLFW");
|
|
|
return true;
|
|
@@ -167,7 +168,7 @@ bool coreWindowOpen(const CoreWindowOptions* o) {
|
|
|
glfwCreateWindow(o->size.data[0], o->size.data[1], o->name, m, nullptr);
|
|
|
if(window == nullptr) {
|
|
|
CORE_LOG_ERROR("could not create window");
|
|
|
- coreWindowClose();
|
|
|
+ closeWindow();
|
|
|
return true;
|
|
|
}
|
|
|
size = o->size;
|
|
@@ -179,7 +180,7 @@ bool coreWindowOpen(const CoreWindowOptions* o) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
-void coreWindowClose(void) {
|
|
|
+void closeWindow(void) {
|
|
|
if(window != nullptr) {
|
|
|
glfwDestroyWindow(window);
|
|
|
window = nullptr;
|
|
@@ -187,55 +188,55 @@ void coreWindowClose(void) {
|
|
|
glfwTerminate();
|
|
|
}
|
|
|
|
|
|
-void coreWindowShow(void) {
|
|
|
+void showWindow(void) {
|
|
|
glfwShowWindow(window);
|
|
|
}
|
|
|
|
|
|
-void coreWindowTrapCursor(void) {
|
|
|
+void trapWindowCursor(void) {
|
|
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
|
|
}
|
|
|
|
|
|
-void coreWindowFreeCursor(void) {
|
|
|
+void freeWindowCursor(void) {
|
|
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
|
}
|
|
|
|
|
|
-bool coreWindowIsCursorTrapped(void) {
|
|
|
+bool isWindowCursorTrapped(void) {
|
|
|
return glfwGetInputMode(window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED;
|
|
|
}
|
|
|
|
|
|
-const CoreIntVector2* coreWindowGetSize(void) {
|
|
|
+const IntVector2* getWindowSize(void) {
|
|
|
return &size;
|
|
|
}
|
|
|
|
|
|
-bool CoreWindowSizeChanged(void) {
|
|
|
+bool hasWindowSizeChanged(void) {
|
|
|
return sizeChanged;
|
|
|
}
|
|
|
|
|
|
-bool coreWindowShouldClose(void) {
|
|
|
+bool shouldWindowClose(void) {
|
|
|
return glfwWindowShouldClose(window);
|
|
|
}
|
|
|
|
|
|
-void coreWindowRunHandler(CoreWindowRunHandler wr, void* data) {
|
|
|
+void setWindowRunHandler(WindowRunHandler wr, void* data) {
|
|
|
runHandlerData = data;
|
|
|
runHandler = wr == nullptr ? dummyWindowRunHandler : wr;
|
|
|
}
|
|
|
|
|
|
-void coreWindowTickHandler(CoreWindowTickHandler t, void* data) {
|
|
|
+void setWindowTickHandler(WindowTickHandler t, void* data) {
|
|
|
tickHandlerData = data;
|
|
|
tickHandler = t == nullptr ? dummyWindowTickHandler : t;
|
|
|
}
|
|
|
|
|
|
-void coreWindowRenderHandler(CoreWindowRenderHandler r, void* data) {
|
|
|
+void setWindowRenderHandler(WindowRenderHandler r, void* data) {
|
|
|
renderHandlerData = data;
|
|
|
renderHandler = r == nullptr ? dummyWindowRenderHandler : r;
|
|
|
}
|
|
|
|
|
|
-void coreWindowNanosPerTick(i64 nanos) {
|
|
|
+void setWindowNanosPerTick(i64 nanos) {
|
|
|
nanosPerTick = nanos <= 0 ? 1 : nanos;
|
|
|
}
|
|
|
|
|
|
static i64 updateClock(Clock* c) {
|
|
|
- i64 nanos = coreGetNanos();
|
|
|
+ i64 nanos = getNanos();
|
|
|
if(nanos < 0) {
|
|
|
CORE_LOG_WARNING("Cannot get nanos, using default");
|
|
|
nanos = 10000000 + c->last;
|
|
@@ -269,7 +270,7 @@ static void checkGamepad() {
|
|
|
return;
|
|
|
}
|
|
|
for(int i = 0; i <= GLFW_GAMEPAD_BUTTON_LAST; i++) {
|
|
|
- CoreButton b = gamepadToButton[i];
|
|
|
+ Button b = gamepadToButton[i];
|
|
|
if(b == 0 || b >= buttonIndex) {
|
|
|
return;
|
|
|
}
|
|
@@ -318,10 +319,10 @@ static void tick() {
|
|
|
lastMousePosition = mousePosition;
|
|
|
}
|
|
|
|
|
|
-void coreWindowRun(void) {
|
|
|
+void runWindow(void) {
|
|
|
glfwMakeContextCurrent(window);
|
|
|
- tps.last = coreGetNanos();
|
|
|
- fps.last = coreGetNanos();
|
|
|
+ tps.last = getNanos();
|
|
|
+ fps.last = getNanos();
|
|
|
i64 lag = 0;
|
|
|
while(runHandler(runHandlerData)) {
|
|
|
lag += updateClock(&fps);
|
|
@@ -334,11 +335,11 @@ void coreWindowRun(void) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-float coreWindowTicksPerSecond(void) {
|
|
|
+float getWindowTicksPerSecond(void) {
|
|
|
return (1000000000.0f * CLOCK_SIZE) / (float)tps.sum;
|
|
|
}
|
|
|
|
|
|
-float coreWindowFramesPerSecond(void) {
|
|
|
+float getWindowFramesPerSecond(void) {
|
|
|
return (1000000000.0f * CLOCK_SIZE) / (float)fps.sum;
|
|
|
}
|
|
|
|
|
@@ -420,49 +421,49 @@ const List<uint32>& Window::Input::getUnicode() {
|
|
|
return input;
|
|
|
}*/
|
|
|
|
|
|
-CoreButton coreControlsAdd(const char* name) {
|
|
|
+Button coreControlsAdd(const char* name) {
|
|
|
if(buttonIndex >= BUTTONS) {
|
|
|
return 0;
|
|
|
}
|
|
|
- CoreButton b = buttonIndex++;
|
|
|
+ Button b = buttonIndex++;
|
|
|
snprintf(buttons[b].name, sizeof(buttons[b].name), "%s", name);
|
|
|
return b;
|
|
|
}
|
|
|
|
|
|
-void coreControlsBindKey(CoreButton b, int key) {
|
|
|
+void coreControlsBindKey(Button b, int key) {
|
|
|
if(key >= 0 && key < KEYS) {
|
|
|
keyToButton[key] = b;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void coreControlsBindGamepad(CoreButton b, int gamepadButton) {
|
|
|
+void coreControlsBindGamepad(Button b, int gamepadButton) {
|
|
|
if(gamepadButton >= 0 && gamepadButton < GAMEPAD_BUTTONS) {
|
|
|
gamepadToButton[gamepadButton] = b;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void coreControlsBindMouse(CoreButton b, int mouseButton) {
|
|
|
+void coreControlsBindMouse(Button b, int mouseButton) {
|
|
|
if(mouseButton >= 0 && mouseButton < MOUSE_BUTTONS) {
|
|
|
mouseToButton[mouseButton] = b;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-CoreVector2 coreControlsLastMousePosition(void) {
|
|
|
+Vector2 coreControlsLastMousePosition(void) {
|
|
|
return lastMousePosition;
|
|
|
}
|
|
|
|
|
|
-CoreVector2 coreControlsMousePosition(void) {
|
|
|
+Vector2 coreControlsMousePosition(void) {
|
|
|
return mousePosition;
|
|
|
}
|
|
|
|
|
|
-CoreVector2 coreControlsLeftGamepadAxis(void) {
|
|
|
- return (CoreVector2){{lastControllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_X],
|
|
|
- lastControllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_Y]}};
|
|
|
+Vector2 coreControlsLeftGamepadAxis(void) {
|
|
|
+ return (Vector2){{lastControllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_X],
|
|
|
+ lastControllerState.axes[GLFW_GAMEPAD_AXIS_LEFT_Y]}};
|
|
|
}
|
|
|
|
|
|
-CoreVector2 coreControlsRightGamepadAxis(void) {
|
|
|
- return (CoreVector2){{lastControllerState.axes[GLFW_GAMEPAD_AXIS_RIGHT_X],
|
|
|
- lastControllerState.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y]}};
|
|
|
+Vector2 coreControlsRightGamepadAxis(void) {
|
|
|
+ return (Vector2){{lastControllerState.axes[GLFW_GAMEPAD_AXIS_RIGHT_X],
|
|
|
+ lastControllerState.axes[GLFW_GAMEPAD_AXIS_RIGHT_Y]}};
|
|
|
}
|
|
|
|
|
|
float coreControlsLeftGamepadTrigger(void) {
|
|
@@ -473,22 +474,22 @@ float coreControlsRightGamepadTrigger(void) {
|
|
|
return lastControllerState.axes[GLFW_GAMEPAD_AXIS_RIGHT_TRIGGER];
|
|
|
}
|
|
|
|
|
|
-static const ButtonData* getButton(CoreButton id) {
|
|
|
+static const ButtonData* getButton(Button id) {
|
|
|
return buttons + (id >= buttonIndex ? 0 : id);
|
|
|
}
|
|
|
|
|
|
-bool coreControlsDown(CoreButton b) {
|
|
|
+bool coreControlsDown(Button b) {
|
|
|
return getButton(b)->downTime > 0;
|
|
|
}
|
|
|
|
|
|
-int coreControlsDownTime(CoreButton b) {
|
|
|
+int coreControlsDownTime(Button b) {
|
|
|
return getButton(b)->downTime;
|
|
|
}
|
|
|
|
|
|
-bool coreControlsReleased(CoreButton b) {
|
|
|
+bool coreControlsReleased(Button b) {
|
|
|
return getButton(b)->released;
|
|
|
}
|
|
|
|
|
|
-const char* coreControlsName(CoreButton b) {
|
|
|
+const char* coreControlsName(Button b) {
|
|
|
return getButton(b)->name;
|
|
|
}
|