sgdk
|
00001 00012 #if LEGACY_SPRITE_ENGINE 00013 00014 #ifndef _SPRITE_ENG_LEGACY_H_ 00015 #define _SPRITE_ENG_LEGACY_H_ 00016 00017 #include "vdp_tile.h" 00018 #include "vdp_spr.h" 00019 #include "pal.h" 00020 #include "pool.h" 00021 00022 00027 #define COLLISION_TYPE_NONE 0 00028 00032 #define COLLISION_TYPE_BOX 1 00033 00037 #define COLLISION_TYPE_CIRCLE 2 00038 00044 #define SPR_FLAG_INSERT_HEAD 0x4000 00045 00051 #define SPR_FLAG_DISABLE_DELAYED_FRAME_UPDATE 0x2000 00052 00056 #define SPR_FLAG_AUTO_VRAM_ALLOC 0x1000 00057 00061 #define SPR_FLAG_AUTO_SPRITE_ALLOC 0x0800 00062 00066 #define SPR_FLAG_AUTO_TILE_UPLOAD 0x0400 00067 00071 #define SPR_FLAG_AUTO_VISIBILITY 0x0200 00072 00078 #define SPR_FLAG_FAST_AUTO_VISIBILITY 0x0100 00079 00084 #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) 00085 00090 #define SPR_MIN_DEPTH (-0x8000) 00091 00095 #define SPR_MAX_DEPTH 0x7FFF 00096 00101 typedef enum 00102 { 00103 VISIBLE, 00104 HIDDEN, 00105 AUTO_FAST, 00106 AUTO_SLOW, 00107 } SpriteVisibility; 00108 00122 typedef struct 00123 { 00124 s8 x; 00125 s8 y; 00126 u8 w; 00127 u8 h; 00128 } BoxCollision; 00129 00141 typedef struct 00142 { 00143 s8 x; 00144 s8 y; 00145 u16 ray; 00146 } CircleCollision; 00147 00168 typedef struct _collision 00169 { 00170 u8 typeHit; 00171 u8 typeAttack; 00172 union 00173 { 00174 BoxCollision box; 00175 CircleCollision circle; 00176 } hit; 00177 union 00178 { 00179 BoxCollision box; 00180 CircleCollision circle; 00181 } attack; 00182 } Collision; 00183 00201 typedef struct 00202 { 00203 u8 offsetY; // respect VDP sprite field order, may help 00204 u8 offsetYFlip; 00205 u8 size; 00206 u8 offsetX; 00207 u8 offsetXFlip; 00208 u8 numTile; 00209 } FrameVDPSprite; 00210 00226 typedef struct 00227 { 00228 u8 numSprite; 00229 u8 timer; 00230 TileSet* tileset; // TODO: have a tileset per VDP sprite --> probably not a good idea performance wise 00231 Collision* collision; // Require many DMA queue operations and fast DMA flush as well, also bring extra computing in calculating delayed update 00232 FrameVDPSprite frameVDPSprites[]; 00233 } AnimationFrame; 00234 00246 typedef struct 00247 { 00248 u8 numFrame; 00249 u8 loop; 00250 AnimationFrame** frames; 00251 } Animation; 00252 00274 typedef struct 00275 { 00276 u16 w; 00277 u16 h; 00278 Palette* palette; 00279 u16 numAnimation; 00280 Animation** animations; 00281 u16 maxNumTile; 00282 u16 maxNumSprite; 00283 } SpriteDefinition; 00284 00334 typedef struct Sprite 00335 { 00336 u16 status; 00337 u16 visibility; 00338 const SpriteDefinition* definition; 00339 void (*onFrameChange)(struct Sprite* sprite); 00340 Animation* animation; 00341 AnimationFrame* frame; 00342 s16 animInd; 00343 s16 frameInd; 00344 u16 timer; 00345 s16 x; 00346 s16 y; 00347 s16 depth; 00348 u16 attribut; 00349 u16 VDPSpriteIndex; 00350 VDPSprite* lastVDPSprite; 00351 u16 lastNumSprite; 00352 s16 spriteToHide; 00353 u32 data; 00354 struct Sprite* prev; 00355 struct Sprite* next; 00356 } Sprite; 00357 00369 typedef void FrameChangeCallback(Sprite* sprite); 00370 00374 extern Pool* spritesPool; 00378 extern Sprite* firstSprite; 00382 extern Sprite* lastSprite; 00386 extern u16 spriteVramSize; 00387 00388 00399 void SPR_init(void); 00414 void SPR_initEx(u16 vramSize); 00422 void SPR_end(void); 00427 bool SPR_isInitialized(void); 00428 00435 void SPR_reset(void); 00436 00486 Sprite* SPR_addSpriteEx(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut, u16 spriteIndex, u16 flag); 00511 Sprite* SPR_addSprite(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut); 00559 Sprite* SPR_addSpriteExSafe(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut, u16 spriteIndex, u16 flag); 00582 Sprite* SPR_addSpriteSafe(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut); 00583 00595 void SPR_releaseSprite(Sprite* sprite); 00600 u16 SPR_getNumActiveSprite(void); 00605 void SPR_defragVRAM(void); 00634 u16** SPR_loadAllFrames(const SpriteDefinition* sprDef, u16 index, u16* totalNumTile); 00635 00650 bool SPR_setDefinition(Sprite* sprite, const SpriteDefinition* spriteDef); 00655 s16 SPR_getPositionX(Sprite* sprite); 00660 s16 SPR_getPositionY(Sprite* sprite); 00672 void SPR_setPosition(Sprite* sprite, s16 x, s16 y); 00682 void SPR_setHFlip(Sprite* sprite, bool value); 00692 void SPR_setVFlip(Sprite* sprite, bool value); 00702 void SPR_setPalette(Sprite* sprite, u16 value); 00712 void SPR_setPriority(Sprite* sprite, bool value); 00717 #define SPR_setPriorityAttribut(sprite, value) _Pragma("GCC error \"This method is deprecated, use SPR_setPriority(..) instead.\"") 00718 00730 void SPR_setDepth(Sprite* sprite, s16 value); 00735 void SPR_setZ(Sprite* sprite, s16 value); 00746 void SPR_setAlwaysOnTop(Sprite* sprite); 00758 void SPR_setAnimAndFrame(Sprite* sprite, s16 anim, s16 frame); 00768 void SPR_setAnim(Sprite* sprite, s16 anim); 00778 void SPR_setFrame(Sprite* sprite, s16 frame); 00786 void SPR_nextFrame(Sprite* sprite); 00787 00802 bool SPR_setVRAMTileIndex(Sprite* sprite, s16 value); 00820 bool SPR_setSpriteTableIndex(Sprite* sprite, s16 value); 00831 void SPR_setAutoTileUpload(Sprite* sprite, bool value); 00844 void SPR_setDelayedFrameUpdate(Sprite* sprite, bool value); 00860 void SPR_setFrameChangeCallback(Sprite* sprite, FrameChangeCallback* callback); 00861 00880 SpriteVisibility SPR_getVisibility(Sprite* sprite); 00898 bool SPR_isVisible(Sprite* sprite, bool recompute); 00899 00923 void SPR_setVisibility(Sprite* sprite, SpriteVisibility value); 00927 #define SPR_setAlwaysVisible(sprite, value) _Pragma("GCC error \"This method is deprecated, use SPR_setVisibility(..) instead.\"") 00928 00931 #define SPR_setNeverVisible(sprite, value) _Pragma("GCC error \"This method is deprecated, use SPR_setVisibility(..) instead.\"") 00932 00935 #define SPR_computeVisibility(sprite) _Pragma("GCC error \"This method is deprecated, use SPR_isVisible(sprite, TRUE) instead.\"") 00936 00944 void SPR_clear(void); 00954 void SPR_update(void); 00955 00960 void SPR_logProfil(void); 00965 void SPR_logSprites(void); 00966 00967 00968 #endif // _SPRITE_ENG_LEGACY_H_ 00969 00970 #endif