Changeset 27c40ce in opengl-game
- Timestamp:
- Sep 12, 2019, 3:29:50 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 7bf5433
- Parents:
- 39278a8
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
consts.hpp
r39278a8 r27c40ce 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 14 20 #endif // _RTWO_CONSTS_H -
game-gui-sdl.cpp
r39278a8 r27c40ce 1 1 #include "game-gui-sdl.hpp" 2 2 3 #include <map> 4 #include <queue> 5 3 6 #include "consts.hpp" 7 8 map<unsigned int, unsigned char> s_keyState; 9 map<unsigned int, bool> s_keyDown; 10 11 using namespace std; 12 13 /* 14 // Temporary to allow the program using this class to receive events other than keyboard events 15 // Remove once I add a better game-gui wrapper for doing that 16 queue<SDL_Event> events; 17 18 queue<MouseEvent> mouseEvents; 19 */ 4 20 5 21 string GameGui_SDL::s_errorMessage; … … 59 75 } 60 76 77 /* 78 void GameGui_SDL::processEvents() { 79 SDL_Event e; 80 81 s_keyState.clear(); 82 while (SDL_PollEvent(&e)) { 83 if (e.type == SDL_KEYDOWN || e.type == SDL_KEYUP) { 84 if (e.type == SDL_KEYDOWN && !e.key.repeat) { 85 s_keyState[e.key.keysym.sym] = RTWO_KEY_EVENT_PRESSED; 86 } else if (e.type == SDL_KEYUP) { 87 s_keyState[e.key.keysym.sym] = RTWO_KEY_EVENT_RELEASED; 88 } else { 89 s_keyState.erase(e.key.keysym.sym); 90 } 91 92 s_keyDown[e.key.keysym.sym] = e.type == SDL_KEYDOWN; 93 } else if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP) { 94 MouseEvent mouseEvent { 0, 0, e.button.x, e.button.y }; 95 96 mouseEvents.push(mouseEvent); 97 } else { 98 events.push(e); 99 } 100 } 101 } 102 103 int GameGui_SDL::pollMouseEvent(MouseEvent* event) { 104 if (mouseEvents.empty()) { 105 return 0; 106 } 107 108 *event = mouseEvents.front(); 109 mouseEvents.pop(); 110 111 return 1; 112 } 113 114 unsigned char GameGui_SDL::getKeyEvent(unsigned int key) { 115 if (s_keyDown.count(key)) { 116 return s_keyState[key]; 117 } else { 118 return RTWO_KEY_EVENT_NONE; 119 } 120 } 121 122 bool GameGui_SDL::isKeyPressed(unsigned int key) { 123 if (s_keyDown.count(key)) { 124 return s_keyDown[key]; 125 } else { 126 return false; 127 } 128 } 129 130 int GameGui_SDL::pollEvent(SDL_Event* event) { 131 if (events.empty()) { 132 return 0; 133 } 134 135 *event = events.front(); 136 events.pop(); 137 138 return 1; 139 } 140 */ 141 61 142 #ifdef GAMEGUI_INCLUDE_VULKAN 62 143 -
game-gui-sdl.hpp
r39278a8 r27c40ce 19 19 void destroyWindow(); 20 20 21 // temporary 22 //int pollEvent(SDL_Event* event); 23 24 /* 25 void processEvents(); 26 27 unsigned char getKeyEvent(unsigned int key); 28 bool isKeyPressed(unsigned int key); 29 30 int pollMouseEvent(MouseEvent* event); 31 */ 32 21 33 #ifdef GAMEGUI_INCLUDE_VULKAN 22 34 bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface); -
game-gui.hpp
r39278a8 r27c40ce 14 14 using namespace std; 15 15 16 /* 17 struct MouseEvent { 18 int button; 19 int action; 20 int x; 21 int y; 22 }; 23 */ 24 16 25 class GameGui { 17 26 public: … … 26 35 virtual void destroyWindow() = 0; 27 36 37 /* 38 virtual void processEvents() = 0; 39 40 virtual int pollMouseEvent(MouseEvent* event) = 0; 41 42 virtual unsigned char getKeyEvent(unsigned int key) = 0; 43 virtual bool isKeyPressed(unsigned int key) = 0; 44 */ 45 28 46 #ifdef GAMEGUI_INCLUDE_VULKAN 29 47 virtual bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) = 0; -
vulkan-game.cpp
r39278a8 r27c40ce 4 4 5 5 #include "consts.hpp" 6 7 #define GAMEGUI_INCLUDE_VULKAN8 #include "game-gui-sdl.hpp"9 6 10 7 using namespace std; … … 22 19 return; 23 20 } 21 22 SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0); 23 SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255); 24 25 SDL_RenderClear(renderer); 26 27 SDL_RenderPresent(renderer); 24 28 25 29 initVulkan(); … … 58 62 void VulkanGame::mainLoop() { 59 63 SDL_Event e; 64 //MouseEvent mouseEvent; 60 65 bool quit = false; 61 66 62 67 while (!quit) { 68 /* 69 gui->processEvents(); 70 71 if (gui->getKeyEvent(SDLK_ESCAPE) == RTWO_KEY_EVENT_PRESSED) { 72 quit = true; 73 } 74 75 while (gui->pollMouseEvent(&mouseEvent)) { 76 cout << "Mouse click detected at (" << mouseEvent.x << ", " << mouseEvent.y << ")" << endl; 77 } 78 */ 79 63 80 while (SDL_PollEvent(&e)) { 64 81 if (e.type == SDL_QUIT) {
Note:
See TracChangeset
for help on using the changeset viewer.