sgdk
|
00001 00012 #ifndef _SPRITE_ENG_H_ 00013 #define _SPRITE_ENG_H_ 00014 00015 #include "vdp_tile.h" 00016 #include "vdp_spr.h" 00017 #include "pal.h" 00018 00019 00024 #define COLLISION_TYPE_NONE 0 00025 00029 #define COLLISION_TYPE_BOX 1 00030 00034 #define COLLISION_TYPE_CIRCLE 2 00035 00041 #define SPR_FLAG_INSERT_HEAD 0x4000 00042 00048 #define SPR_FLAG_DISABLE_DELAYED_FRAME_UPDATE 0x2000 00049 00053 #define SPR_FLAG_AUTO_VRAM_ALLOC 0x1000 00054 00058 #define SPR_FLAG_AUTO_SPRITE_ALLOC 0x0800 00059 00063 #define SPR_FLAG_AUTO_TILE_UPLOAD 0x0400 00064 00068 #define SPR_FLAG_AUTO_VISIBILITY 0x0200 00069 00075 #define SPR_FLAG_FAST_AUTO_VISIBILITY 0x0100 00076 00081 #define SPR_FLAG_MASK (SPR_FLAG_INSERT_HEAD | SPR_FLAG_DISABLE_DELAYED_FRAME_UPDATE | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_SPRITE_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD | SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_FAST_AUTO_VISIBILITY) 00082 00087 #define SPR_MIN_DEPTH (-0x8000) 00088 00092 #define SPR_MAX_DEPTH 0x7FFF 00093 00098 typedef enum 00099 { 00100 VISIBLE, 00101 HIDDEN, 00102 AUTO_FAST, 00103 AUTO_SLOW, 00104 } SpriteVisibility; 00105 00119 typedef struct 00120 { 00121 s8 x; 00122 s8 y; 00123 u8 w; 00124 u8 h; 00125 } BoxCollision; 00126 00138 typedef struct 00139 { 00140 s8 x; 00141 s8 y; 00142 u16 ray; 00143 } CircleCollision; 00144 00165 typedef struct _collision 00166 { 00167 u8 typeHit; 00168 u8 typeAttack; 00169 union 00170 { 00171 BoxCollision box; 00172 CircleCollision circle; 00173 } hit; 00174 union 00175 { 00176 BoxCollision box; 00177 CircleCollision circle; 00178 } attack; 00179 } Collision; 00180 00198 typedef struct 00199 { 00200 u8 numTile; 00201 u8 offsetY; // respect VDP sprite field order 00202 u8 offsetYFlip; 00203 u8 size; 00204 u8 offsetX; 00205 u8 offsetXFlip; 00206 } FrameVDPSprite; 00207 00223 typedef struct 00224 { 00225 u8 numSprite; 00226 u8 timer; 00227 TileSet* tileset; // TODO: have a tileset per VDP sprite --> probably not a good idea performance wise 00228 Collision* collision; // Require many DMA queue operations and fast DMA flush as well, also bring extra computing in calculating delayed update 00229 FrameVDPSprite frameVDPSprites[]; 00230 } AnimationFrame; 00231 00243 typedef struct 00244 { 00245 u8 numFrame; 00246 u8 loop; 00247 AnimationFrame** frames; 00248 } Animation; 00249 00271 typedef struct 00272 { 00273 u16 w; 00274 u16 h; 00275 Palette* palette; 00276 u16 numAnimation; 00277 Animation** animations; 00278 u16 maxNumTile; 00279 u16 maxNumSprite; 00280 } SpriteDefinition; 00281 00331 typedef struct Sprite 00332 { 00333 u16 status; 00334 u16 visibility; 00335 const SpriteDefinition* definition; 00336 void (*onFrameChange)(struct Sprite* sprite); 00337 Animation* animation; 00338 AnimationFrame* frame; 00339 s16 animInd; 00340 s16 frameInd; 00341 u16 timer; 00342 s16 x; 00343 s16 y; 00344 s16 depth; 00345 u16 attribut; 00346 u16 VDPSpriteIndex; 00347 VDPSprite* lastVDPSprite; 00348 u16 lastNumSprite; 00349 s16 spriteToHide; 00350 u32 data; 00351 struct Sprite* prev; 00352 struct Sprite* next; 00353 } Sprite; 00354 00366 typedef void FrameChangeCallback(Sprite* sprite); 00367 00371 extern Sprite* spritesBank; 00375 extern Sprite* firstSprite; 00379 extern Sprite* lastSprite; 00383 extern u16 spriteVramSize; 00384 00385 00396 void SPR_init(); 00411 void SPR_initEx(u16 vramSize); 00419 void SPR_end(); 00424 bool SPR_isInitialized(); 00425 00432 void SPR_reset(); 00433 00483 Sprite* SPR_addSpriteEx(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut, u16 spriteIndex, u16 flag); 00508 Sprite* SPR_addSprite(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut); 00556 Sprite* SPR_addSpriteExSafe(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut, u16 spriteIndex, u16 flag); 00579 Sprite* SPR_addSpriteSafe(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut); 00580 00592 void SPR_releaseSprite(Sprite* sprite); 00597 u16 SPR_getNumActiveSprite(); 00602 void SPR_defragVRAM(); 00631 u16** SPR_loadAllFrames(const SpriteDefinition* sprDef, u16 index, u16* totalNumTile); 00632 00647 bool SPR_setDefinition(Sprite* sprite, const SpriteDefinition* spriteDef); 00652 s16 SPR_getPositionX(Sprite* sprite); 00657 s16 SPR_getPositionY(Sprite* sprite); 00669 void SPR_setPosition(Sprite* sprite, s16 x, s16 y); 00679 void SPR_setHFlip(Sprite* sprite, u16 value); 00689 void SPR_setVFlip(Sprite* sprite, u16 value); 00699 void SPR_setPalette(Sprite* sprite, u16 value); 00709 void SPR_setPriority(Sprite* sprite, u16 value); 00714 void SPR_setPriorityAttribut(Sprite* sprite, u16 value); 00727 void SPR_setDepth(Sprite* sprite, s16 value); 00732 void SPR_setZ(Sprite* sprite, s16 value); 00736 void SPR_setAlwaysOnTop(Sprite* sprite, u16 value); 00748 void SPR_setAnimAndFrame(Sprite* sprite, s16 anim, s16 frame); 00758 void SPR_setAnim(Sprite* sprite, s16 anim); 00768 void SPR_setFrame(Sprite* sprite, s16 frame); 00776 void SPR_nextFrame(Sprite* sprite); 00777 00792 bool SPR_setVRAMTileIndex(Sprite* sprite, s16 value); 00810 bool SPR_setSpriteTableIndex(Sprite* sprite, s16 value); 00821 void SPR_setAutoTileUpload(Sprite* sprite, bool value); 00834 void SPR_setDelayedFrameUpdate(Sprite* sprite, bool value); 00850 void SPR_setFrameChangeCallback(Sprite* sprite, FrameChangeCallback* callback); 00851 00870 SpriteVisibility SPR_getVisibility(Sprite* sprite); 00888 bool SPR_isVisible(Sprite* sprite, bool recompute); 00889 00913 void SPR_setVisibility(Sprite* sprite, SpriteVisibility value); 00917 void SPR_setAlwaysVisible(Sprite* sprite, u16 value); 00921 void SPR_setNeverVisible(Sprite* sprite, u16 value); 00925 bool SPR_computeVisibility(Sprite* sprite); 00926 00934 void SPR_clear(); 00944 void SPR_update(); 00945 00950 void SPR_logProfil(); 00955 void SPR_logSprites(); 00956 00957 00958 #endif // _SPRITE_ENG_H_