While the game is between physics updates n and n + 1, what is the current physics update? n or n + 1? Between which two of my items does the game increase this number?
I
think IncrementIteration (in LemGame) deals with advancing the frames. But the physics updates themselves are all handled by UpdateLemmings (LemGame) and Application_Idle (GameWindow).
Meanwhile, we have some progress with this topic - I've figured out how to prevent same-frame assignments!
Yes, this isn't the ideal eventual goal, but it's an improvement over the current behaviour of silently overwriting existing assignments, so it will do for now whilst we look for a way to make the ideal happen.
It turns out that the answer lies with the Replay Manager's handling of assignments, rather than the game itself's handling. The Replay Manager already (thankfully) has a way to check for assignments on past, current and future frames. This check is always looking at the existing replay file into which previously-made assignments have already been written, recorded and stored, whereas the aforementioned fDoneAssignmentThisFrame flag doesn't interact with the replay at all, and so has no way of knowing or responding to this information.
So, you were absolutely correct with this:
Have fewer flags ... Instead, write functions that compute the information on demand from replay content, and from necessary-to-have mutable state (number of the physics update).
Turns out such computations already exist within the codebase, thankfully! It was a case of checking
the Replay Manager itself for an assignment at the current frame. The existing check looks for Assignments
and RR changes, so I duplicated it and made a check for Assignments
only (I previously separated out RR changes for a bugfix elsewhere*, so we now have checks for "both", "only Assigments" and "only RR changes").
It works because, somewhat paradoxically, the game needs a way to look into the future for a change on that frame whilst it's backstepping, because backwards skips go further back before heading towards the target frame at Hyper Speed (what a great sentence that was to type!
![lemcat :lemcat:](https://www.lemmingsforums.net/Smileys/lemmings/lemcat.gif)
). The game itself can only deal with whatever is currently true at that frame, whereas
the Replay Manager holds the key for checking past and future events.
So, the "don't overwrite, but also don't accept new assignments" behaviour
will be present in the next version of SLX (2.4). The "assign fail" sound plays as well, so it's doubly clear that the assignment can't be made (even if it's not obvious why).
Commit 760e513ff implements this.(If we find a way to accept multiple assignments in the meantime, then of course this will be updated again before release).
*I used the same check in order to fix the bug that caused the RR sound to trigger during backwards skips. The sound was triggering because there
had been a change between Frame 0 and Current Frame, so I needed to say "only trigger the sound if there's a change on the
current frame. So, I separated out this part of the code and made a new check accordingly.