Lifecycle - earok/scorpion-editor-demos GitHub Wiki

Code in the Scorpion Engine is executed in a specific order every frame.

Render Cycle

The render cycle is run every single frame, including when the gameplay is paused and when a main panel is loaded instead of a level.

  1. Controls are read.
  2. Top and bottom panels are updated.
  3. If the main panel is loaded, the main panel updates.
  4. If no level is loaded, or a main panel is loaded, this routine finishes here.
  5. If the game is running ahead of time (if a vblank wasn't triggered for the last frame), the routine pauses here until that completes.
  6. Tiles are rendered (Amiga).
  7. Actor Render cycle:
    1. Actors that are locked to parents or the screen are repositioned.
    2. Actors are then rendered as BOBs or Sprites depending on the system and configuration.
  8. The foreground tiles are redrawn if any overlap actors (Amiga).
  9. Palettes are faded in or out (Mega Drive and NeoGeo).
  10. Scroll memory is set (Mega Drive).
  11. Tiles are rendered (Mega Drive, NeoGeo).
  12. The current frame is ready to be rendered. Additional operations to display everything on the screen is done during the vblank.

Planned changes:

  1. Routine pausing to catch up should happen at the start before Controls are read.
  2. Tile rendering should happen at the same time on all three platforms.
  3. Amiga palettes should also be faded in or out here, not in the vblank.

Play Cycle

The play cycle only executes when the game is unpaused, when there is no main panel loaded and when a level is loaded.

  1. Commands (from the Project Tab) are processed.
  2. The level ontimer events are processed.
  3. If there's a talkpad panel, the talkpad is dismissed.
  4. If the camera is auto scrolling, the scroll is applied now.
  5. If any unspawned actors are close enough to the camera, they're spawned. now
  6. Actor Update cycle:
    1. If an actor has attack code, this is executed.
    2. If the actor is a player, block overlaps are checked.
    3. If the actor is a player, event overlaps are checked.
    4. The actor's ontimer counts down and is executed if timer has expired.
    5. If the actor is being pushed, this happens now.
    6. The actor's move code is executed now.
    7. If the actor is standing on a moving platform, the actor is repositioned.
    8. If the actor is autoscrolling, it scrolls with the level now.
    9. If the actor is set to repeat animation events, all events from the current frame are repeated.
    10. The actor's animation is updated.
    11. If the actor has out-of-screen code, this is executed now.
    12. The actor's final position in the frame is recorded for collision purposes
    13. If the actor is out of position in regards to the ZBuffer, the ZBuffer is flagged as out of order.
  7. Collision events are processed.
  8. Melee events are processed.
  9. If the ZBuffer is out of order, the ZBuffer is now re-sorted.
  10. If the camera is following an actor, the camera moves.
  11. Tile animations are updated (the actual rendering happens in the Render Cycle).
  12. Block animations are updated (the actual rendering happens in the Render Cycle).
  13. Blink Timer is updated.
  14. Parallax position is updated.

Planned changes:

  1. Out of screen code should be executed before the animation is updated.
  2. Melee events should be processed before collision events.

Vertical Blank

The Vertical Blank (which executes 50 times a second PAL and 60 times a second NTSC) has almost no shared code between the three platforms, so they're described separately here.

Amiga

  1. Joysticks (CD32 Pads) are read.
  2. Panels are flipped to the front buffer.
  3. If the game hasn't finished updating (such as this being an odd numbered frame on a 25HZ game), sprite and scroll interpolations are applied.
  4. If the copper lists need to be regenerated (such as a panel being loaded or unloaded), the setup is done now.
  5. The level bitmap is scrolled.
  6. Hardware sprites are rendered.
  7. Fade in or out on the palette is applied.
  8. Any final changes to the copper lists are done now.

Mega Drive

  1. DMA protection is applied (XGM driver only).
  2. Scroll tables are DMA transferred from 68K RAM to VRAM.
  3. If the display needs to be regenerated (from panels being loaded or unloaded) this is done now.
  4. Patterns are DMA tranferred from ROM to VRAM.
  5. The sprite table is DMA transferred from 68K RAM to VRAM.
  6. Tiles that are flagged as dirty (such as animated blocks) are redrawn now.
  7. Panels are refreshed.
  8. Audio drivers are refreshed.

Changes planned:

  1. Panel refresh should be done in Render Cycle, like it is on Amiga.
  2. Tiles flagged as dirty should be redrawn at the top of the Render Cycle.

NeoGeo

  1. Internal watchdog and NeoGeo BIOS calls
  2. Level tile sprites are positioned and rendered
  3. Regular actor sprites are rendered
  4. Background sprites (behind level tiles) are rendered
  5. Tiles that are flagged as dirty (such as animated blocks) are redrawn now.
  6. Panels are refreshed.
  7. Audio drivers are refreshed.

Changes planned:

  1. Panel refresh should be done in Render Cycle, like it is on Amiga.
  2. Tiles flagged as dirty should be redrawn at the top of the Render Cycle.