metasprites.h (4218B)
1/** @file sms/metasprites.h 2 3 # Metasprite support 4 5 A metasprite is a larger sprite made up from a 6 collection of smaller individual hardware sprites. 7 Different frames of the same metasprites can share 8 tile data. 9 10 The api supports metasprites in both 11 @ref SPRITES_8x8 and @ref SPRITES_8x16 mode. If 12 8x16 mode is used then the height of the metasprite 13 must be a multiple of 16. 14 15 The origin (pivot) for the metasprite is not required 16 to be in the upper left-hand corner as with regular 17 hardware sprites. 18 19 Use the @ref utility_png2asset tool to convert single 20 or multiple frames of graphics into metasprite 21 structured data for use with the ...metasprite...() 22 functions. 23 24 # Metasprites composed of variable numbers of sprites 25 26 When using png2asset, it's common for the output of 27 different frames to be composed of different numbers 28 of hardware sprites (since it's trying to create each 29 frame as efficiently as possible). Due to that, it's 30 good practice to clear out (hide) unused sprites in the 31 shadow_OAM that have been set by previous frames. 32*/ 33 34#ifndef _METASPRITES_H_INCLUDE 35#define _METASPRITES_H_INCLUDE 36 37#include <sms/hardware.h> 38#include <types.h> 39#include <stdint.h> 40 41/** Metasprite sub-item structure 42 @param dy (int8_t) Y coordinate of the sprite relative to the metasprite origin (pivot) 43 @param dx (int8_t) X coordinate of the sprite relative to the metasprite origin (pivot) 44 @param dtile (uint8_t) Start tile relative to the metasprites own set of tiles 45 46 Metasprites are built from multiple metasprite_t items (one for each sub-sprite) 47 and a pool of tiles they reference. If a metasprite has multiple frames then each 48 frame will be built from some number of metasprite_t items (which may vary based 49 on how many sprites are required for that particular frame). 50 51 A metasprite frame is terminated with a {metasprite_end} entry. 52*/ 53typedef struct metasprite_t { 54 int8_t dy, dx; 55 uint8_t dtile; 56} metasprite_t; 57 58#define metasprite_end -128 59#define METASPR_ITEM(dy,dx,dt,a) {(dy),(dx),(dt)} 60#define METASPR_TERM {metasprite_end} 61 62extern const void * __current_metasprite; 63extern uint8_t __current_base_tile; 64extern uint8_t __render_shadow_OAM; 65 66 67static uint8_t __move_metasprite(uint8_t id, uint8_t x, uint8_t y) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); 68static void __hide_metasprite(uint8_t id) Z88DK_FASTCALL PRESERVES_REGS(iyh, iyl); 69 70/** 71 * Hides all hardware sprites in range from <= X < to 72 * @param from start OAM index 73 * @param to finish OAM index 74 */ 75void hide_sprites_range(UINT8 from, UINT8 to) Z88DK_CALLEE PRESERVES_REGS(iyh, iyl); 76 77/** Moves metasprite to the absolute position x and y 78 79 @param metasprite Pointer to the first struct of the metasprite (for the desired frame) 80 @param base_tile Number of the first tile where the metasprite's tiles start 81 @param base_sprite Number of the first hardware sprite to be used by the metasprite 82 @param x Absolute x coordinate of the sprite 83 @param y Absolute y coordinate of the sprite 84 85 Moves __metasprite__ to the absolute position __x__ and __y__ 86 (with __no flip__ on the X or Y axis). Hardware sprites are 87 allocated starting from __base_sprite__, using tiles 88 starting from __base_tile__. 89 90 Sets: 91 \li __current_metasprite = metasprite; 92 \li __current_base_tile = base_tile; 93 94 @return Number of hardware sprites used to draw this metasprite 95 */ 96inline uint8_t move_metasprite(const metasprite_t * metasprite, uint8_t base_tile, uint8_t base_sprite, uint8_t x, uint8_t y) { 97 __current_metasprite = metasprite; 98 __current_base_tile = base_tile; 99 return __move_metasprite(base_sprite, x, y); 100} 101 102/** Hides a metasprite from the screen 103 104 @param metasprite Pointer to first struct of the desired metasprite frame 105 @param base_sprite Number of hardware sprite to start with 106 107 Sets: 108 \li __current_metasprite = metasprite; 109 110 **/ 111inline void hide_metasprite(const metasprite_t * metasprite, uint8_t base_sprite) { 112 __current_metasprite = metasprite; 113 __hide_metasprite(base_sprite); 114} 115 116#endif