Changeset c61323a in opengl-game
- Timestamp:
- Sep 13, 2019, 2:51:30 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 1fcca9e
- Parents:
- f6521fb
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
consts.hpp
rf6521fb rc61323a 12 12 constexpr unsigned char GUI_FLAGS_WINDOW_FULLSCREEN { 1 << 0 }; 13 13 14 /*15 constexpr unsigned char RTWO_KEY_EVENT_NONE { 0 };16 constexpr unsigned char RTWO_KEY_EVENT_PRESSED { 1 };17 constexpr unsigned char RTWO_KEY_EVENT_RELEASED { 2 };18 */19 20 14 #endif // _RTWO_CONSTS_H -
game-gui-glfw.cpp
rf6521fb rc61323a 1 1 #include "game-gui-glfw.hpp" 2 3 #include <queue>4 2 5 3 #include "compiler.hpp" 6 4 #include "consts.hpp" 7 5 8 int GameGui_GLFW::s_keyState[GLFW_KEY_LAST]; 9 bool GameGui_GLFW::s_keyDown[GLFW_KEY_LAST]; 10 11 // queue<MouseEvent> mouseEvents; 12 6 queue<UIEvent> GameGui_GLFW::s_events; 13 7 string GameGui_GLFW::s_errorMessage; 14 8 … … 32 26 33 27 void* GameGui_GLFW::createWindow(const string& title, int width, int height, bool fullscreen) { 34 GLFWwindow* window = nullptr;35 28 GLFWmonitor* mon = nullptr; 36 29 … … 62 55 63 56 window = glfwCreateWindow(windowWidth, windowHeight, title.c_str(), mon, nullptr); 64 //glfwMakeContextCurrent(window);65 57 66 58 glfwSetMouseButtonCallback(window, glfw_mouse_button_callback); 67 59 glfwSetKeyCallback(window, glfw_key_callback); 68 69 // fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE);70 // fill(s_keyDown, s_keyDown + GLFW_KEY_LAST, false);71 60 72 61 return window; … … 78 67 } 79 68 80 /*81 69 void GameGui_GLFW::processEvents() { 82 fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE);70 glfwPollEvents(); 83 71 84 glfwPollEvents(); 72 if (glfwWindowShouldClose(window)) { 73 UIEvent e; 74 e.type = UI_EVENT_QUIT; 75 76 s_events.push(e); 77 } 85 78 } 86 79 87 unsigned char GameGui_GLFW::getKeyEvent(unsigned int key) { 88 return s_keyState[key]; 89 } 90 91 bool GameGui_GLFW::isKeyPressed(unsigned int key) { 92 return s_keyDown[key]; 93 } 94 95 int GameGui_GLFW::pollMouseEvent(MouseEvent* event) { 96 if (mouseEvents.empty()) { 80 int GameGui_GLFW::pollEvent(UIEvent* event) { 81 if (s_events.empty()) { 97 82 return 0; 98 83 } 99 84 100 *event = mouseEvents.front();101 mouseEvents.pop();85 *event = s_events.front(); 86 s_events.pop(); 102 87 103 88 return 1; 104 89 } 105 */106 90 107 91 #ifdef GAMEGUI_INCLUDE_VULKAN … … 149 133 150 134 void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { 151 GameGui_GLFW::s_keyState[key] = action; 152 /* 153 switch(action) { 154 case GLFW_PRESS: 155 s_keyState[key] = RTWO_KEY_EVENT_PRESSED; 156 break; 157 case GLFW_RELEASE: 158 s_keyState[key] = RTWO_KEY_EVENT_RELEASED; 159 break; 160 default: 161 s_keyState[key] = RTWO_KEY_EVENT_NONE; 162 break; 163 } 135 UIEvent e; 136 e.type = UI_EVENT_KEY; 137 e.key.keycode = key; 164 138 165 // should be true for GLFW_PRESS and GLFW_REPEAT 166 GameGui_GLFW::s_keyDown[key] = (action != GLFW_RELEASE); 167 */ 139 GameGui_GLFW::s_events.push(e); 168 140 } -
game-gui-glfw.hpp
rf6521fb rc61323a 1 1 #ifndef _GAME_GUI_GLFW_H 2 2 #define _GAME_GUI_GLFW_H 3 4 #include <queue> 3 5 4 6 #include "game-gui.hpp" … … 14 16 static string s_errorMessage; // Has to be public so that glfw_error_callback can access it 15 17 16 // Both have to be public so that glfw_key_callback can access them 17 // TODO: Implement a more generic public api over this to get the key state 18 static int s_keyState[GLFW_KEY_LAST]; 19 static bool s_keyDown[GLFW_KEY_LAST]; 18 // Has to be public so that glfw_key_callback can access it 19 static queue<UIEvent> s_events; 20 20 21 21 string& getError(); … … 27 27 void destroyWindow(); 28 28 29 /*30 29 void processEvents(); 31 32 unsigned char getKeyEvent(unsigned int key); 33 bool isKeyPressed(unsigned int key); 34 35 int pollMouseEvent(MouseEvent* event); 36 */ 30 int pollEvent(UIEvent* event); 37 31 38 32 #ifdef GAMEGUI_INCLUDE_VULKAN … … 47 41 48 42 int windowWidth, windowHeight; 49 static queue<UIEvent> s_events;50 43 }; 51 44 -
game-gui-sdl.cpp
rf6521fb rc61323a 7 7 8 8 using namespace std; 9 10 /*11 // Temporary to allow the program using this class to receive events other than keyboard events12 // Remove once I add a better game-gui wrapper for doing that13 queue<SDL_Event> events;14 15 queue<MouseEvent> mouseEvents;16 */17 9 18 10 string GameGui_SDL::s_errorMessage; … … 116 108 case SDL_AUDIODEVICEADDED: 117 109 case SDL_AUDIODEVICEREMOVED: 110 case SDL_TEXTEDITING: // TODO: Research this one later 118 111 event = nullptr; 119 112 return 0; -
game-gui-sdl.hpp
rf6521fb rc61323a 22 22 int pollEvent(UIEvent* event); 23 23 24 // temporary25 //int pollEvent(SDL_Event* event);26 27 /*28 void processEvents();29 30 unsigned char getKeyEvent(unsigned int key);31 bool isKeyPressed(unsigned int key);32 33 int pollMouseEvent(MouseEvent* event);34 */35 36 24 #ifdef GAMEGUI_INCLUDE_VULKAN 37 25 bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface); -
opengl-game.cpp
rf6521fb rc61323a 57 57 58 58 void OpenGLGame::mainLoop() { 59 //MouseEvent e; 59 UIEvent e; 60 bool quit = false; 60 61 61 while (!glfwWindowShouldClose(window)) { 62 /* 62 while (!quit) { 63 63 gui->processEvents(); 64 64 65 if (gui->getKeyEvent(GLFW_KEY_ESCAPE) == RTWO_KEY_EVENT_PRESSED) { 66 glfwSetWindowShouldClose(window, 1); 67 } 68 69 while (gui->pollMouseEvent(&e)) { 70 cout << "Mouse click detected at (" << e.x << ", " << e.y << ")" << endl; 71 } 72 */ 73 74 glfwPollEvents(); 75 76 if (GameGui_GLFW::s_keyState[GLFW_KEY_ESCAPE] == GLFW_PRESS) { 77 glfwSetWindowShouldClose(window, 1); 65 while (gui->pollEvent(&e)) { 66 switch (e.type) { 67 case UI_EVENT_QUIT: 68 cout << "Quit event detected" << endl; 69 quit = true; 70 break; 71 case UI_EVENT_KEY: 72 if (e.key.keycode == GLFW_KEY_ESCAPE) { 73 quit = true; 74 } else { 75 cout << "Key event detected" << endl; 76 } 77 break; 78 default: 79 cout << "Unhandled UI event: " << e.type << endl; 80 } 78 81 } 79 82 -
vulkan-game.cpp
rf6521fb rc61323a 92 92 case UI_EVENT_MOUSEMOTION: 93 93 break; 94 default: 95 cout << "Unhandled UI event: " << e.type << endl; 94 96 } 95 97 }
Note:
See TracChangeset
for help on using the changeset viewer.