aboutsummaryrefslogtreecommitdiff
path: root/src/Support.cpp
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-09-10 00:42:02 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-09-10 00:42:19 +0700
commit5247e298e05a623e001f0be01238a03b61d715b8 (patch)
tree4e67421ee4b7303512675fa80b8db7e1d2ef8836 /src/Support.cpp
parentda79599ad5201f4eebd3edaabbe4b33498de448e (diff)
downloadblackshades-5247e298e05a623e001f0be01238a03b61d715b8.tar.gz
Replace SDL by GLFW
SDL 1 was deprecated. Mouse look and meta control keys are broken as of this commit.
Diffstat (limited to 'src/Support.cpp')
-rw-r--r--src/Support.cpp39
1 files changed, 15 insertions, 24 deletions
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 <fcntl.h>
#include <unistd.h>
-#include <SDL/SDL.h>
+#include <GLFW/glfw3.h>
#include <vorbis/vorbisfile.h>
#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