0

I'm implementing simple Windows game. Here is my game loop, which I've written based on some tutorials found on the Web:

constexpr nanoseconds ms_per_update(500ms);
TimePoint current_time;
TimePoint start_time = Clock::now();
nanoseconds delta_time;
nanoseconds lag(0ms);

while (continueRunning) {

while (PeekMessage(&msg, 0, 0, 0, PM_REMOVE)) {
    TranslateMessage(&msg);
    DispatchMessage(&msg);

    if (WM_QUIT == msg.message) {
        OutputDebugString(L"--- WM_QUIT (WndMain) ---\n");
        continueRunning = false;
    }
}

current_time = Clock::now();
delta_time = duration_cast<std::chrono::nanoseconds>(current_time - start_time);
start_time = current_time;
lag += delta_time;

while (lag >= ms_per_update) {
    Game::Update();
    lag -= ms_per_update;
}

Game::Render();

}

Here are my questions

What really the Update and Render methods should do? Am i right that Update should for e.g. run through all game entities just updating theirs coordinates while the Render should call Render method for every game object which will just draw it on the screen having the position set by Update?

Vaillancourt
  • 16,325
  • 17
  • 55
  • 61
Daros911
  • 101
  • 1

0 Answers0