jasonchadwick / chronodrifter

Platform puzzler where the direction of time flow can change.
1 stars 0 forks source link

Recognize and optimize repetitive state sequences in the time history stack #38

Open jasonchadwick opened 2 years ago

jasonchadwick commented 2 years ago

Current issue: for objects such as droppers, we save every state because they are all different from previous. But if a player is not interacting with the cube, then the motion exactly repeats itself every spawnInterval seconds. Figure out a way to store this info and only start a new stack entry if something happens differently. Potentially with a period variable in TimeReversibleObject.

Would get complex if we have two droppers whose cubes hit each other - this would have some sort of period as well, but may be much longer. Or we could just ignore this case and optimize for the first case.

This is important when a level is run for any longer than ~1 minute (it starts to get slow).

Alternatively, just limit the stack to 1000 items or something, but this is not ideal.

jasonchadwick commented 2 years ago

Idea: if period is specified, every time we add a new thing to the stack, check the (n - period)'th item on the stack (may want to convert stack to an array for this to be fast - will need to experiment). If they are similar enough (using GetStateDifference), add to a separate list. If this separate list becomes long enough to cover an entire period, delete it all and indicate on the actual stack that we now have an extra repetition of that period. If states diverge before the separate list fills a whole period, add the whole thing to the stack and start over.

jasonchadwick commented 2 years ago

Currently makes level 7 unplayable after only ~60 seconds

jasonchadwick commented 2 years ago

Fixed performance issues by replacing stack with array, but still would be good to implement this to save space - ideally players should never notice that the time history has limited length.