0
\$\begingroup\$

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?

\$\endgroup\$
4
  • \$\begingroup\$ Welcome to Game Development! "Am i right that [...]" Yes. There is not much of a question in this post, you answer your question yourself. \$\endgroup\$
    – Vaillancourt
    Commented Jan 5, 2021 at 20:02
  • \$\begingroup\$ @Vaillancourt Ok, thx:-) \$\endgroup\$
    – Daros911
    Commented Jan 5, 2021 at 20:08
  • 1
    \$\begingroup\$ Check the game-loop for more stuff on game loops, notably, this one has resurfaced lately. \$\endgroup\$
    – Vaillancourt
    Commented Jan 5, 2021 at 20:12
  • \$\begingroup\$ @Vaillancourt Ok, Thx again:-) \$\endgroup\$
    – Daros911
    Commented Jan 5, 2021 at 20:43

0

You must log in to answer this question.

Browse other questions tagged .