Khaz wrote:I wonder... Has anybody ever programmed a game that deliberately detects and avoids slowdown?
I believe Sonic the Hedgehog attempts to avoid rendering the screen to "catch up" during lag frames. (It does some other things too. See
this page under lag.) I'm sure there are many others, but that's the one I know offhand. My game on NES detects lag frames and skips the vblank wait for the next frame if a lag frame is detected to avoid running at 30 FPS in those cases. (There are certain tasks you can get done before you
have to wait.) However, I'm not sure about that behavior. Initially, it just always skipped the wait for vblank on lag frames, but then the game basically just got stuck on the wait loop before the things you have to do
rather than what was supposed to be the main loop. It's a weird thing in general. If I just rearrange the logic with a single wait before the "need" things, I'd have exactly the same 30 FPS slowdown I'm trying to avoid with a slightly different order of game logic and no lag reduction. *shrug*
As far as enemies and the camera, if your game doesn't require require enemies to be respawn, just don't respawn them. For a Gunstar Heroes type thing, constantly spawning things is a different case. And in that case, I don't think the camera really affects that type of spawning.
I'm not sure how to handle when things go off screen, whether to disable them or despawn them completely, or just ignore collisions... One way or the other, constantly comparing everything to the screen/player position to see if it should be active or not sounds like a lot of extra processing on its own.
My game doesn't have a lot of wiggle room as far as what collision info is "loaded" offscreen. I currently disable an enemy if it travels "far" offscreen. If it remains offscreen for X frames, it's despawned.
The problem with disabling completely if you can do things like fire a lot of shots offscreen. They'll get frozen. Then you walk a bit closer, and some poor enemy that was also frozen out there will take like 12 bullets at once. (This is a common exploit in the original version of Spelunky.) Or you throw a ball and it travels offscreen while airborne. The player waits, walks after it to find it hasn't landed during the wait time when it should have.
And comparing things to the player or camera position isn't a lot of processing at all. It's maybe two subtractions per frame per object. (If absolutevalue(enemypos-cameramiddle) > 256, despawn.) You could do it with an AND and a CMP too depending on what distance you choose.