Rolling Pixels: Looping Fiasco

<p>This &lsquo;sprint&rsquo; was a good one! This branch of work was about having a turn-based loop separated from the game&rsquo;s render loop. I could see early on that trying to operate the game&#39;s turn-based rules from the render loop had problems. A quick Google search revealed agreement but no leads on solutions. &nbsp;I might have been lazy about this; I found a solid&nbsp;<a href="https://journal.stuffwithstuff.com/2014/07/15/a-turn-based-game-loop/" rel="noopener ugc nofollow" target="_blank">article by Bob Nystrom</a>&nbsp;late in my search after I made some decisions. I have the player selecting, clicking, and dragging, adding to a turn queue until &ldquo;End Turn&rdquo; is selected. That gets the non-rendering Turn Loop going. Game objects that can act push their turns to the action turn queue (a priority queue), and then the turn loop runs through the queue of commands executing them. Right now, they just make each game object fire off an animation, all at the same time!! LMAO! I needed a &ldquo;finished my turn&rdquo; event to pace the commands. There&rsquo;s still one call dependent on the render update loop, but I feel like I got 95% there. Refactoring may provide another look at why or making it better.</p> <p>Right now, I got:<br /> 1. The player sends actions to an ActionHandler queue.<br /> 2. The player ends the turn, and other game objects that can act send actions to the ActionHandler.<br /> 3. The ActionHandler sorts the queue right now by an int field called&nbsp;<em>actionOrder</em>&nbsp;in the commands. This is a random number for now.<br /> 4. It runs through the queue executing game object action/commands, waiting for an&nbsp;<em>ActionFinished</em>&nbsp;event before moving to the next command.</p> <p>Commands have logic to process the action and signal the game object&rsquo;s animation for the action. The animation event relies on the traditional render update loop to kick it off. I think this is OK, where it belongs.</p> <p><a href="https://madjay.medium.com/rolling-pixels-looping-fiasco-ce1d13d88ba1"><strong>Visit Now</strong></a></p>