Dynamic sprite engine with per-frame VRAM tile streaming. More...
#include <snes.h>Functions | |
| int | main (void) |
| Entry point: dynamic sprite engine demo with four animated sprites. | |
Variables | |
| static u16 | frame0 |
| Animation frame index for sprite 0 (0-23, wraps at 24) | |
| static u16 | frame1 |
| Animation frame index for sprite 1 (0-23, wraps at 24) | |
| static u16 | frame2 |
| Animation frame index for sprite 2 (0-23, wraps at 24) | |
| static u16 | frame3 |
| Animation frame index for sprite 3 (0-23, wraps at 24) | |
| static u8 | frame_counter |
| Global frame counter for animation timing. | |
| u8 | spr16_properpal [] |
| 16-color palette for the 16x16 sprites | |
| u8 | spr16_tiles [] |
| ROM source for the 16x16 sprite sheet tile data. | |
| static const s16 | xpos [4] = {64, 112, 160, 208} |
| X positions for the four sprites displayed in a horizontal row. | |
Dynamic sprite engine with per-frame VRAM tile streaming.
Demonstrates the OpenSNES dynamic sprite engine, which uploads only the currently-needed sprite tiles to VRAM each frame instead of pre-loading the entire sprite sheet. This trades VBlank DMA bandwidth for VRAM space, allowing many unique animation frames without exhausting the 32KB OBJ VRAM region.
Four 16x16 sprites are animated simultaneously. Each sprite's tile data is streamed from ROM to VRAM via oamDynamicDraw() — the engine queues dirty tiles and the NMI handler auto-flushes the queue every VBlank within the DMA budget.
| int main | ( | void | ) |
Entry point: dynamic sprite engine demo with four animated sprites.
Initializes the dynamic sprite system, which streams sprite tiles from ROM to VRAM on demand each frame. Four 16x16 sprites are placed in a row, each cycling through 24 animation frames with an 8-frame delay.
The dynamic sprite pipeline per frame:
This approach trades VBlank DMA time for VRAM conservation: instead of pre-loading all 24 frames (24 x 4 tiles x 32 bytes = 3KB per sprite), only the 4 active tiles per sprite are in VRAM at any time.
< Priority 3 = in front of all BGs
< Force initial tile upload
< Point to ROM tile source
|
static |
Animation frame index for sprite 0 (0-23, wraps at 24)
|
static |
Animation frame index for sprite 1 (0-23, wraps at 24)
|
static |
Animation frame index for sprite 2 (0-23, wraps at 24)
|
static |
Animation frame index for sprite 3 (0-23, wraps at 24)
|
static |
Global frame counter for animation timing.
Counts from 0 to 7, advancing sprite animation every 8th frame (8/60 = 133ms). Using a shared counter keeps all four sprites synchronized.
|
extern |
16-color palette for the 16x16 sprites
|
extern |
ROM source for the 16x16 sprite sheet tile data.
Contains all 24 animation frames laid out sequentially. The dynamic sprite engine reads individual frames from this ROM data and DMAs only the currently-needed tiles to VRAM each frame, conserving OBJ VRAM space.
|
static |
X positions for the four sprites displayed in a horizontal row.
Static const arrays are placed in ROM (SUPERFREE section) by the compiler. The sprites are evenly spaced across the 256-pixel screen width.