Changeset 27c40ce in opengl-game


Ignore:
Timestamp:
Sep 12, 2019, 3:29:50 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
7bf5433
Parents:
39278a8
Message:

Update vulkangame to correctly display a window in Windows and add some commented-out code for a generic system for processing UI events

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • consts.hpp

    r39278a8 r27c40ce  
    1212constexpr unsigned char GUI_FLAGS_WINDOW_FULLSCREEN { 1 << 0 };
    1313
     14/*
     15constexpr unsigned char RTWO_KEY_EVENT_NONE { 0 };
     16constexpr unsigned char RTWO_KEY_EVENT_PRESSED { 1 };
     17constexpr unsigned char RTWO_KEY_EVENT_RELEASED { 2 };
     18*/
     19
    1420#endif // _RTWO_CONSTS_H
  • game-gui-sdl.cpp

    r39278a8 r27c40ce  
    11#include "game-gui-sdl.hpp"
    22
     3#include <map>
     4#include <queue>
     5
    36#include "consts.hpp"
     7
     8map<unsigned int, unsigned char> s_keyState;
     9map<unsigned int, bool> s_keyDown;
     10
     11using 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
     16queue<SDL_Event> events;
     17
     18queue<MouseEvent> mouseEvents;
     19*/
    420
    521string GameGui_SDL::s_errorMessage;
     
    5975}
    6076
     77/*
     78void 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
     103int 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
     114unsigned 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
     122bool 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
     130int 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
    61142#ifdef GAMEGUI_INCLUDE_VULKAN
    62143
  • game-gui-sdl.hpp

    r39278a8 r27c40ce  
    1919      void destroyWindow();
    2020
     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
    2133#ifdef GAMEGUI_INCLUDE_VULKAN
    2234      bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface);
  • game-gui.hpp

    r39278a8 r27c40ce  
    1414using namespace std;
    1515
     16/*
     17struct MouseEvent {
     18   int button;
     19   int action;
     20   int x;
     21   int y;
     22};
     23*/
     24
    1625class GameGui {
    1726   public:
     
    2635      virtual void destroyWindow() = 0;
    2736
     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
    2846#ifdef GAMEGUI_INCLUDE_VULKAN
    2947      virtual bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) = 0;
  • vulkan-game.cpp

    r39278a8 r27c40ce  
    44
    55#include "consts.hpp"
    6 
    7 #define GAMEGUI_INCLUDE_VULKAN
    8 #include "game-gui-sdl.hpp"
    96
    107using namespace std;
     
    2219      return;
    2320   }
     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);
    2428
    2529   initVulkan();
     
    5862void VulkanGame::mainLoop() {
    5963   SDL_Event e;
     64   //MouseEvent mouseEvent;
    6065   bool quit = false;
    6166
    6267   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
    6380      while (SDL_PollEvent(&e)) {
    6481         if (e.type == SDL_QUIT) {
Note: See TracChangeset for help on using the changeset viewer.