Changeset f6521fb in opengl-game
- Timestamp:
- Sep 13, 2019, 1:30:24 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- c61323a
- Parents:
- 203ab1b
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-glfw.hpp
r203ab1b rf6521fb 47 47 48 48 int windowWidth, windowHeight; 49 static queue<UIEvent> s_events; 49 50 }; 50 51 -
game-gui-sdl.cpp
r203ab1b rf6521fb 5 5 6 6 #include "consts.hpp" 7 8 map<unsigned int, unsigned char> s_keyState;9 map<unsigned int, bool> s_keyDown;10 7 11 8 using namespace std; … … 81 78 } 82 79 83 /*84 80 void GameGui_SDL::processEvents() { 81 } 82 83 int GameGui_SDL::pollEvent(UIEvent* event) { 85 84 SDL_Event e; 86 85 87 s_keyState.clear(); 88 while (SDL_PollEvent(&e)) { 89 if (e.type == SDL_KEYDOWN || e.type == SDL_KEYUP) { 90 if (e.type == SDL_KEYDOWN && !e.key.repeat) { 91 s_keyState[e.key.keysym.sym] = RTWO_KEY_EVENT_PRESSED; 92 } else if (e.type == SDL_KEYUP) { 93 s_keyState[e.key.keysym.sym] = RTWO_KEY_EVENT_RELEASED; 94 } else { 95 s_keyState.erase(e.key.keysym.sym); 96 } 86 /* The trackpad on OSX triggers both SDL_MOUSE and SDL_FINGER events, so just treat them both 87 * as mouse events since this game isn't targeting mobile devices 88 */ 97 89 98 s_keyDown[e.key.keysym.sym] = e.type == SDL_KEYDOWN; 99 } else if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP) { 100 MouseEvent mouseEvent { 0, 0, e.button.x, e.button.y }; 90 if (SDL_PollEvent(&e)) { 91 switch(e.type) { 92 case SDL_QUIT: 93 event->type = UI_EVENT_QUIT; 94 break; 95 case SDL_WINDOWEVENT: 96 event->type = UI_EVENT_WINDOW; 97 break; 98 case SDL_KEYUP: 99 case SDL_KEYDOWN: 100 event->type = UI_EVENT_KEY; 101 event->key.keycode = e.key.keysym.scancode; 102 break; 103 case SDL_MOUSEBUTTONDOWN: 104 case SDL_FINGERDOWN: 105 event->type = UI_EVENT_MOUSEBUTTONDOWN; 106 break; 107 case SDL_MOUSEBUTTONUP: 108 case SDL_FINGERUP: 109 event->type = UI_EVENT_MOUSEBUTTONUP; 110 break; 111 case SDL_MOUSEMOTION: 112 case SDL_FINGERMOTION: 113 event->type = UI_EVENT_MOUSEMOTION; 114 break; 115 // Ignore the following events 116 case SDL_AUDIODEVICEADDED: 117 case SDL_AUDIODEVICEREMOVED: 118 event = nullptr; 119 return 0; 120 break; 121 default: 122 cout << "Unknown event type: 0x" << hex << e.type << dec << endl; 123 event = nullptr; 124 return 0; 125 } 101 126 102 mouseEvents.push(mouseEvent); 103 } else { 104 events.push(e); 105 } 106 } 107 } 108 109 int GameGui_SDL::pollMouseEvent(MouseEvent* event) { 110 if (mouseEvents.empty()) { 111 return 0; 127 return 1; 112 128 } 113 129 114 *event = mouseEvents.front(); 115 mouseEvents.pop(); 116 117 return 1; 130 event = nullptr; 131 return 0; 118 132 } 119 120 unsigned char GameGui_SDL::getKeyEvent(unsigned int key) {121 if (s_keyDown.count(key)) {122 return s_keyState[key];123 } else {124 return RTWO_KEY_EVENT_NONE;125 }126 }127 128 bool GameGui_SDL::isKeyPressed(unsigned int key) {129 if (s_keyDown.count(key)) {130 return s_keyDown[key];131 } else {132 return false;133 }134 }135 136 int GameGui_SDL::pollEvent(SDL_Event* event) {137 if (events.empty()) {138 return 0;139 }140 141 *event = events.front();142 events.pop();143 144 return 1;145 }146 */147 133 148 134 #ifdef GAMEGUI_INCLUDE_VULKAN -
game-gui-sdl.hpp
r203ab1b rf6521fb 18 18 void* createWindow(const string& title, int width, int height, bool fullscreen); 19 19 void destroyWindow(); 20 21 void processEvents(); 22 int pollEvent(UIEvent* event); 20 23 21 24 // temporary -
game-gui.hpp
r203ab1b rf6521fb 5 5 #include <vector> 6 6 7 // TODO: Remove the line below once the couts in the game-gui-* files are moved 8 #include <iostream> 9 7 10 #ifdef GAMEGUI_INCLUDE_VULKAN 8 11 #include <vulkan/vulkan.h> 9 12 #endif 10 13 11 // TODO: Remove the line below once the couts in the game-gui-* files are moved 12 #include <iostream> 14 using namespace std; 13 15 14 using namespace std; 16 enum EventType { 17 UI_EVENT_QUIT, 18 UI_EVENT_WINDOW, 19 UI_EVENT_KEY, 20 UI_EVENT_MOUSEBUTTONDOWN, 21 UI_EVENT_MOUSEBUTTONUP, 22 UI_EVENT_MOUSEMOTION 23 }; 24 25 struct WindowEvent { 26 EventType type; 27 }; 28 29 struct KeyEvent { 30 EventType type; 31 unsigned int keycode; 32 }; 33 34 struct MouseEvent { 35 EventType type; 36 }; 37 38 union UIEvent { 39 EventType type; 40 WindowEvent window; 41 KeyEvent key; 42 MouseEvent mouse; 43 }; 15 44 16 45 /* … … 35 64 virtual void destroyWindow() = 0; 36 65 66 virtual void processEvents() = 0; 67 virtual int pollEvent(UIEvent* event) = 0; 68 37 69 /* 38 70 virtual void processEvents() = 0; -
vulkan-game.cpp
r203ab1b rf6521fb 61 61 62 62 void VulkanGame::mainLoop() { 63 SDL_Event e; 64 //MouseEvent mouseEvent; 63 UIEvent e; 65 64 bool quit = false; 66 65 67 66 while (!quit) { 68 /*69 67 gui->processEvents(); 70 68 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 80 while (SDL_PollEvent(&e)) { 81 if (e.type == SDL_QUIT) { 82 quit = true; 83 } 84 if (e.type == SDL_KEYDOWN) { 85 quit = true; 86 } 87 if (e.type == SDL_MOUSEBUTTONDOWN) { 88 quit = true; 69 while (gui->pollEvent(&e)) { 70 switch(e.type) { 71 case UI_EVENT_QUIT: 72 cout << "Quit event detected" << endl; 73 quit = true; 74 break; 75 case UI_EVENT_WINDOW: 76 cout << "Window event detected" << endl; 77 // Currently unused 78 break; 79 case UI_EVENT_KEY: 80 if (e.key.keycode == SDL_SCANCODE_ESCAPE) { 81 quit = true; 82 } else { 83 cout << "Key event detected" << endl; 84 } 85 break; 86 case UI_EVENT_MOUSEBUTTONDOWN: 87 cout << "Mouse button down event detected" << endl; 88 break; 89 case UI_EVENT_MOUSEBUTTONUP: 90 cout << "Mouse button up event detected" << endl; 91 break; 92 case UI_EVENT_MOUSEMOTION: 93 break; 89 94 } 90 95 }
Note:
See TracChangeset
for help on using the changeset viewer.