Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What you should do is first to read and understand the "fixed time-step" game loop (Here's a good explanation: <a href="http://www.gaffer.org/game-physics/fix-your-timestep" rel="nofollow noreferrer">http://www.gaffer.org/game-physics/fix-your-timestep</a>).</p> <p>Then what you do is to keep a list of list of pairs of frame counter and action. STL example:</p> <pre class="lang-c++ prettyprint-override"><code>std::list&lt;std::list&lt;std::pair&lt;unsigned long, Action&gt; &gt; &gt; state; </code></pre> <p>Or maybe a vector of lists of pairs. To create the state, for every action (player interaction) you store the frame number and what action is performed, most likely you'd get the best results if action simply was "key &lt;X> pressed" or "key &lt;X> released":</p> <pre class="lang-c++ prettyprint-override"><code>state.back().push_back(std::make_pair(currentFrame, VK_LEFT | KEY_PRESSED)); </code></pre> <p>To play back the previous states, you'd have to reset the frame counter every time the player activates the time machine and then iterate through the state list for each previous state and see if any matches the current frame. If there is, perform the action for that state. To optimize you could keep a list of iterators to where you are in each previous state-list. Here's some <em>pseudo-code</em> for that:</p> <pre class="lang-c++ prettyprint-override"><code>typedef std::list&lt;std::pair&lt;unsigned long, Action&gt; &gt; StateList; std::list&lt;StateList::iterator&gt; stateIteratorList; // foreach(it in stateIteratorList) { if(it-&gt;first == currentFrame) { performAction(it-&gt;second); ++it; } } </code></pre> <p>I hope you get the idea...</p> <p>Separate threads would simply complicate the matter greatly, this way you get the same result every time, which you cannot guarantee by using separate threads (can't really see how that would be implemented) or a non-fixed time-step game loop.</p> <p>When it comes to graphics API, I'd go with SDL as it's probably the easiest thing to get you started. You can always use OpenGL from SDL later on if you want to go 3D.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload