Dynamic sprite engine: per-frame VRAM tile streaming, single sprites and metasprites.
More...
|
| static void | animStep (void) |
| | One frame of the animated scene: a step every 8 frames, then the draws.
|
| static void | changeObjSize (void) |
| | Reinitialize sprite engine and upload all tiles during force blank.
|
| static void | drawSprites (void) |
| | Draw metasprites for the current OBJSEL configuration.
|
| static void | drawText (void) |
| | Draw the configuration menu text.
|
| static void | enterAnimScene (void) |
| | The four animated 16x16 sprites: the engine, the palette, the sprites' state and their first draw; the screen comes on at the end.
|
| static void | enterMetaScene (void) |
| | The metasprite scene: Mode 0, the text menu on BG1, the heroes' palette; changeObjSize() configures the engine and draws them.
|
| int | main (void) |
| | Entry point: the animated sprites at boot, SELECT to the metasprites and back.
|
| static void | metaStep (void) |
| | One frame of the metasprite scene: UP/DOWN pick the size pair.
|
Dynamic sprite engine: per-frame VRAM tile streaming, single sprites and metasprites.
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.
SELECT switches to the next step of the same engine: a metasprite — a character made of several OBJ — drawn with oamMetaDrawDyn(), its sub-sprites' tiles streamed the same way, under the three OBJSEL size pairs (8/16, 8/32, 16/32) chosen with UP/DOWN. SELECT again comes back. (The metasprite scene was the dynamic_metasprite example, ported from PVSnesLib's DynamicEngineMetaSprite.)
- SNES Concepts
- Dynamic VRAM tile streaming to conserve OBJ VRAM space
- Batched VBlank DMA for sprite tile uploads
- Multiple independently-animated sprites sharing a tile pool
- oambuffer[] structure for sprite state management
- MetaspriteItem arrays defining a character's sub-sprite layout, and the size class (OBJ_SMALL / OBJ_LARGE) of the OBJSEL pair it is drawn with
- OBJSEL size pairs, switched at run time with oamDynamicInit()
- What to Observe
- Four 16x16 sprites displayed in a row, each animating through a 24-frame cycle with an 8-frame delay between advances
- No input required; the animation runs continuously
- SELECT: two hero characters; UP/DOWN switch between the 3 OBJSEL size pairs (the menu cursor ">" shows which); the characters change size
- Modules Used
- console, sprite, sprite_dynamic, sprite_dynamic_meta, sprite_lut, dma, background, text, input
- See also
- sprite.h, dma.h, video.h
| const s16 xpos[4] = {64, 112, 160, 208} |
|
static |
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.
16-color palette for the 16x16 sprites
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.