Changeset 7bf5433 in opengl-game for game-gui-glfw.cpp


Ignore:
Timestamp:
Sep 12, 2019, 5:23:28 AM (5 years ago)
Author:
Dmitry Portnoy <dmp1488@…>
Branches:
feature/imgui-sdl, master, points-test
Children:
d2f607c
Parents:
27c40ce
Message:

Create a new OpenGLGame project for a refactor of the original OpenGL game to make copying its logic over to the Vulkan implementation easier

File:
1 edited

Legend:

Unmodified
Added
Removed
  • game-gui-glfw.cpp

    r27c40ce r7bf5433  
    11#include "game-gui-glfw.hpp"
     2
     3#include <queue>
    24
    35#include "compiler.hpp"
    46#include "consts.hpp"
    57
    6 const int KEY_STATE_UNCHANGED = -1;
     8int GameGui_GLFW::s_keyState[GLFW_KEY_LAST];
     9bool GameGui_GLFW::s_keyDown[GLFW_KEY_LAST];
     10
     11// queue<MouseEvent> mouseEvents;
    712
    813string GameGui_GLFW::s_errorMessage;
    9 
    10 int GameGui_GLFW::s_keyState[NUM_KEYS];
    11 bool GameGui_GLFW::s_keyDown[NUM_KEYS];
    1214
    1315string& GameGui_GLFW::getError() {
     
    6264   //glfwMakeContextCurrent(window);
    6365
    64    //glfwSetMouseButtonCallback(window, mouse_button_callback);
     66   glfwSetMouseButtonCallback(window, glfw_mouse_button_callback);
    6567   glfwSetKeyCallback(window, glfw_key_callback);
    6668
    67    fill(GameGui_GLFW::s_keyState, GameGui_GLFW::s_keyState + NUM_KEYS, KEY_STATE_UNCHANGED);
     69   // fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE);
     70   // fill(s_keyDown, s_keyDown + GLFW_KEY_LAST, false);
    6871
    6972   return window;
     
    7477   glfwDestroyWindow(window);
    7578}
     79
     80/*
     81void GameGui_GLFW::processEvents() {
     82   fill(s_keyState, s_keyState + GLFW_KEY_LAST, RTWO_KEY_EVENT_NONE);
     83
     84   glfwPollEvents();
     85}
     86
     87unsigned char GameGui_GLFW::getKeyEvent(unsigned int key) {
     88   return s_keyState[key];
     89}
     90
     91bool GameGui_GLFW::isKeyPressed(unsigned int key) {
     92   return s_keyDown[key];
     93}
     94
     95int GameGui_GLFW::pollMouseEvent(MouseEvent* event) {
     96   if (mouseEvents.empty()) {
     97      return 0;
     98   }
     99
     100   *event = mouseEvents.front();
     101   mouseEvents.pop();
     102
     103   return 1;
     104}
     105*/
    76106
    77107#ifdef GAMEGUI_INCLUDE_VULKAN
     
    107137}
    108138
     139void glfw_mouse_button_callback(GLFWwindow* window, int button, int action, int mods) {
     140   double x, y;
     141   glfwGetCursorPos(window, &x, &y);
     142
     143   /*
     144   MouseEvent e { button, action, (int)x, (int)y };
     145
     146   mouseEvents.push(e);
     147   */
     148}
     149
    109150void glfw_key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
    110151   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   }
    111164
    112165   // should be true for GLFW_PRESS and GLFW_REPEAT
    113166   GameGui_GLFW::s_keyDown[key] = (action != GLFW_RELEASE);
     167   */
    114168}
Note: See TracChangeset for help on using the changeset viewer.