Changeset 5081b9a in opengl-game


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

Files:
3 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      }
  • sdl-game.hpp

    re469aed r5081b9a  
    122122      // TODO: Make a separate singleton Timer class
    123123      time_point<steady_clock> startTime;
    124       float fpsStartTime, curTime;
     124      float fpsStartTime, curTime, prevTime, elapsedTime;
    125125
    126126      int frameCount;
  • vulkan-game.cpp

    re469aed r5081b9a  
    661661
    662662         ImGui_ImplSDL2_ProcessEvent(&sdlEvent);
    663          if (io.WantCaptureMouse &&
    664                (e.type == UI_EVENT_MOUSEBUTTONDOWN || e.type == UI_EVENT_MOUSEBUTTONUP || e.type == UI_EVENT_UNKNOWN)) {
    665             if (sdlEvent.type == SDL_MOUSEWHEEL || sdlEvent.type == SDL_MOUSEBUTTONDOWN || sdlEvent.type == SDL_MOUSEBUTTONUP) {
     663         if ((e.type == UI_EVENT_MOUSEBUTTONDOWN || e.type == UI_EVENT_MOUSEBUTTONUP || e.type == UI_EVENT_UNKNOWN) &&
     664             io.WantCaptureMouse) {
     665            if (sdlEvent.type == SDL_MOUSEWHEEL || sdlEvent.type == SDL_MOUSEBUTTONDOWN ||
     666               sdlEvent.type == SDL_MOUSEBUTTONUP) {
    666667               continue;
    667668            }
    668669         }
    669          if (io.WantCaptureKeyboard &&
    670                (e.type == UI_EVENT_KEYDOWN || e.type == UI_EVENT_KEYUP)) {
     670         if ((e.type == UI_EVENT_KEYDOWN || e.type == UI_EVENT_KEYUP) && io.WantCaptureKeyboard) {
    671671            if (sdlEvent.type == SDL_KEYDOWN || sdlEvent.type == SDL_KEYUP) {
    672672               continue;
     
    681681               cout << "Quit event detected" << endl;
    682682               done = true;
    683                break;
    684             case UI_EVENT_WINDOW:
    685                cout << "Window event detected" << endl;
    686                // Currently unused
    687683               break;
    688684            case UI_EVENT_WINDOWRESIZE:
     
    764760               }
    765761               break;
     762            case UI_EVENT_WINDOW:
    766763            case UI_EVENT_MOUSEBUTTONDOWN:
    767764            case UI_EVENT_MOUSEBUTTONUP:
    768765            case UI_EVENT_MOUSEMOTION:
    769766               break;
     767            case UI_EVENT_UNHANDLED:
     768               cout << "Unhandled event type: 0x" << hex << sdlEvent.type << dec << endl;
     769               break;
    770770            case UI_EVENT_UNKNOWN:
    771                //cout << "Unknown event type: 0x" << hex << e.unknown.eventType << dec << endl;
     771            default:
     772               cout << "Unknown event type: 0x" << hex << sdlEvent.type << dec << endl;
    772773               break;
    773             default:
    774                cout << "Unhandled UI event: " << e.type << endl;
    775774         }
    776775
     
    15741573
    15751574   for (size_t i = 0; i < swapChainImageCount; i++) {
    1576       if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &imageAcquiredSemaphores[i]) != VK_SUCCESS) {
    1577          throw runtime_error("failed to create image acquired sempahore for a frame!");
    1578       }
    1579 
    1580       if (vkCreateSemaphore(device, &semaphoreInfo, nullptr, &renderCompleteSemaphores[i]) != VK_SUCCESS) {
    1581          throw runtime_error("failed to create render complete sempahore for a frame!");
    1582       }
    1583 
    1584       if (vkCreateFence(device, &fenceInfo, nullptr, &inFlightFences[i]) != VK_SUCCESS) {
    1585          throw runtime_error("failed to create fence for a frame!");
    1586       }
     1575      VKUTIL_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreInfo, nullptr, &imageAcquiredSemaphores[i]),
     1576         "failed to create image acquired sempahore for a frame!");
     1577
     1578      VKUTIL_CHECK_RESULT(vkCreateSemaphore(device, &semaphoreInfo, nullptr, &renderCompleteSemaphores[i]),
     1579         "failed to create render complete sempahore for a frame!");
     1580
     1581      VKUTIL_CHECK_RESULT(vkCreateFence(device, &fenceInfo, nullptr, &inFlightFences[i]),
     1582         "failed to create fence for a frame!");
    15871583   }
    15881584}
Note: See TracChangeset for help on using the changeset viewer.