Changeset c61323a in opengl-game for game-gui-glfw.cpp


Ignore:
Timestamp:
Sep 13, 2019, 2:51:30 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
1fcca9e
Parents:
f6521fb
Message:

Implement processEvents() and pollEvent() for GameGui_GLFW and re-implement the main loop in opengl-game using those functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • game-gui-glfw.cpp

    rf6521fb rc61323a  
    11#include "game-gui-glfw.hpp"
    2 
    3 #include <queue>
    42
    53#include "compiler.hpp"
    64#include "consts.hpp"
    75
    8 int GameGui_GLFW::s_keyState[GLFW_KEY_LAST];
    9 bool GameGui_GLFW::s_keyDown[GLFW_KEY_LAST];
    10 
    11 // queue<MouseEvent> mouseEvents;
    12 
     6queue<UIEvent> GameGui_GLFW::s_events;
    137string GameGui_GLFW::s_errorMessage;
    148
     
    3226
    3327void* GameGui_GLFW::createWindow(const string& title, int width, int height, bool fullscreen) {
    34    GLFWwindow* window = nullptr;
    3528   GLFWmonitor* mon = nullptr;
    3629
     
    6255
    6356   window = glfwCreateWindow(windowWidth, windowHeight, title.c_str(), mon, nullptr);
    64    //glfwMakeContextCurrent(window);
    6557
    6658   glfwSetMouseButtonCallback(window, glfw_mouse_button_callback);
    6759   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);
    7160
    7261   return window;
     
    7867}
    7968
    80 /*
    8169void GameGui_GLFW::processEvents() {
    82    fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE);
     70   glfwPollEvents();
    8371
    84    glfwPollEvents();
     72   if (glfwWindowShouldClose(window)) {
     73      UIEvent e;
     74      e.type = UI_EVENT_QUIT;
     75
     76      s_events.push(e);
     77   }
    8578}
    8679
    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()) {
     80int GameGui_GLFW::pollEvent(UIEvent* event) {
     81   if (s_events.empty()) {
    9782      return 0;
    9883   }
    9984
    100    *event = mouseEvents.front();
    101    mouseEvents.pop();
     85   *event = s_events.front();
     86   s_events.pop();
    10287
    10388   return 1;
    10489}
    105 */
    10690
    10791#ifdef GAMEGUI_INCLUDE_VULKAN
     
    149133
    150134void 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;
    164138
    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);
    168140}
Note: See TracChangeset for help on using the changeset viewer.