From 5247e298e05a623e001f0be01238a03b61d715b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Gia=20Phong?= Date: Fri, 10 Sep 2021 00:42:02 +0700 Subject: Replace SDL by GLFW SDL 1 was deprecated. Mouse look and meta control keys are broken as of this commit. --- src/Support.cpp | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) (limited to 'src/Support.cpp') diff --git a/src/Support.cpp b/src/Support.cpp index 33794d9..4703b14 100644 --- a/src/Support.cpp +++ b/src/Support.cpp @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include "Support.h" @@ -21,38 +21,23 @@ int Random() #endif } -void Microseconds(UnsignedWide *microTickCount) -{ - /* NOTE: hi isn't used in BS, so it's not implemented here */ - /* TODO: does game need microsecond precision? */ - microTickCount->hi = 0; - microTickCount->lo = SDL_GetTicks() * 1000; -} - void GetMouse(Point *p) { - int x; - int y; - - SDL_GetMouseState(&x, &y); - - p->h = x; - p->v = y; + double xpos, ypos; + glfwGetCursorPos(glfwGetCurrentContext(), &xpos, &ypos); + p->h = xpos; + p->v = ypos; } void GetMouseRel(Point *p) { - int x; - int y; - - SDL_GetRelativeMouseState(&x, &y); - - p->h = x; - p->v = y; + return GetMouse(p); } + int Button(void) { - return (SDL_GetMouseState(NULL, NULL) & SDL_BUTTON(1)); + auto window = glfwGetCurrentContext(); + return glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS; } void MoveMouse(int xcoord, int ycoord, Point *mouseloc) @@ -61,6 +46,12 @@ void MoveMouse(int xcoord, int ycoord, Point *mouseloc) GetMouse(mouseloc); } +bool IsKeyDown(int key) +{ + auto window = glfwGetCurrentContext(); + return glfwGetKey(window, key) == GLFW_PRESS; +} + #ifndef O_BINARY #define O_BINARY 0 #endif -- cgit v1.2.3