Changeset 5081b9a in opengl-game for sdl-game.cpp


Ignore:
Timestamp:
Apr 7, 2021, 2:29:16 AM (4 years ago)
Author:
Dmitry Portnoy <dportnoy@…>
Branches:
feature/imgui-sdl
Children:
db2d995
Parents:
e469aed
git-author:
Dmitry Portnoy <dportnoy@…> (04/07/21 02:25:11)
git-committer:
Dmitry Portnoy <dportnoy@…> (04/07/21 02:29:16)
Message:

Add prevTime and elapsedTime to SDLGame and refactor the event-handling code a little bit

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sdl-game.cpp

    re469aed r5081b9a  
    196196   while (!done) {
    197197
     198      prevTime = curTime;
    198199      curTime = duration<float, seconds::period>(steady_clock::now() - startTime).count();
     200      elapsedTime = curTime - prevTime;
    199201
    200202      if (curTime - fpsStartTime >= 1.0f) {
     
    215217
    216218         ImGui_ImplSDL2_ProcessEvent(&sdlEvent);
    217          if (io.WantCaptureMouse &&
    218             (e.type == UI_EVENT_MOUSEBUTTONDOWN || e.type == UI_EVENT_MOUSEBUTTONUP || e.type == UI_EVENT_UNKNOWN)) {
    219             if (sdlEvent.type == SDL_MOUSEWHEEL || sdlEvent.type == SDL_MOUSEBUTTONDOWN || sdlEvent.type == SDL_MOUSEBUTTONUP) {
     219         if ((e.type == UI_EVENT_MOUSEBUTTONDOWN || e.type == UI_EVENT_MOUSEBUTTONUP || e.type == UI_EVENT_UNKNOWN) &&
     220             io.WantCaptureMouse) {
     221            if (sdlEvent.type == SDL_MOUSEWHEEL || sdlEvent.type == SDL_MOUSEBUTTONDOWN ||
     222                sdlEvent.type == SDL_MOUSEBUTTONUP) {
    220223               continue;
    221224            }
    222225         }
    223          if (io.WantCaptureKeyboard &&
    224             (e.type == UI_EVENT_KEYDOWN || e.type == UI_EVENT_KEYUP)) {
     226         if ((e.type == UI_EVENT_KEYDOWN || e.type == UI_EVENT_KEYUP) && io.WantCaptureKeyboard) {
    225227            if (sdlEvent.type == SDL_KEYDOWN || sdlEvent.type == SDL_KEYUP) {
    226228               continue;
     
    232234
    233235         switch (e.type) {
    234          case UI_EVENT_MOUSEMOTION:
    235             // Currently unused
    236             break;
    237          case UI_EVENT_WINDOW:
    238             // Currently unused
    239             break;
    240          case UI_EVENT_QUIT:
    241             cout << "Quit event detected" << endl;
    242             done = true;
    243             break;
    244          case UI_EVENT_UNHANDLED:
    245             cout << "Unhandled event type: 0x" << hex << sdlEvent.type << dec << endl;
    246             break;
    247          case UI_EVENT_UNKNOWN:
    248          default:
    249             cout << "Unknown event type: 0x" << hex << sdlEvent.type << dec << endl;
    250             break;
     236            case UI_EVENT_QUIT:
     237               cout << "Quit event detected" << endl;
     238               done = true;
     239               break;
     240            case UI_EVENT_WINDOWRESIZE:
     241               cout << "Window resize event detected" << endl;
     242               shouldRecreateSwapChain = true;
     243               break;
     244            case UI_EVENT_KEYUP:
     245               // START UNREVIEWED SECTION
     246               // END UNREVIEWED SECTION
     247               break;
     248            case UI_EVENT_WINDOW:
     249            case UI_EVENT_MOUSEBUTTONDOWN:
     250            case UI_EVENT_MOUSEBUTTONUP:
     251            case UI_EVENT_MOUSEMOTION:
     252               break;
     253            case UI_EVENT_UNHANDLED:
     254               cout << "Unhandled event type: 0x" << hex << sdlEvent.type << dec << endl;
     255               break;
     256            case UI_EVENT_UNKNOWN:
     257            default:
     258               cout << "Unknown event type: 0x" << hex << sdlEvent.type << dec << endl;
     259               break;
    251260         }
    252261      }
Note: See TracChangeset for help on using the changeset viewer.