sgdk
sprite_eng.h
Go to the documentation of this file.
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_VISIBILITY                0x1000
00054 
00058 #define SPR_FLAG_FAST_AUTO_VISIBILITY           0x0800
00059 
00063 #define SPR_FLAG_AUTO_VRAM_ALLOC                0x0400
00064 
00068 #define SPR_FLAG_AUTO_SPRITE_ALLOC              0x0200
00069 
00073 #define SPR_FLAG_AUTO_TILE_UPLOAD               0x0100
00074 
00078 #define SPR_FLAG_MASK                           (SPR_FLAG_DISABLE_DELAYED_FRAME_UPDATE | SPR_FLAG_AUTO_VISIBILITY | SPR_FLAG_FAST_AUTO_VISIBILITY | SPR_FLAG_AUTO_VRAM_ALLOC | SPR_FLAG_AUTO_SPRITE_ALLOC | SPR_FLAG_AUTO_TILE_UPLOAD)
00079 
00084 #define SPR_MIN_DEPTH       (-0x8000)
00085 
00089 #define SPR_MAX_DEPTH       0x7FFF
00090 
00095 typedef enum
00096 {
00097     VISIBLE,        
00098     HIDDEN,         
00099     AUTO_FAST,      
00100     AUTO_SLOW,      
00101 } SpriteVisibility;
00102 
00103 
00117 typedef struct
00118 {
00119     s8 x;
00120     s8 y;
00121     u8 w;
00122     u8 h;
00123 } BoxCollision;
00124 
00136 typedef struct
00137 {
00138     s8 x;
00139     s8 y;
00140     u16 ray;
00141 } CircleCollision;
00142 
00163 typedef struct _collision
00164 {
00165     u8 typeHit;
00166     u8 typeAttack;
00167     union
00168     {
00169         BoxCollision box;
00170         CircleCollision circle;
00171     } hit;
00172     union
00173     {
00174         BoxCollision box;
00175         CircleCollision circle;
00176     } attack;
00177 } Collision;
00178 
00192 typedef struct
00193 {
00194     u8 numTile;
00195     s8 offsetY;          // respect VDP sprite field order
00196     u8 size;
00197     s8 offsetX;
00198 }  FrameVDPSprite;
00199 
00209 typedef struct
00210 {
00211     FrameVDPSprite** frameVDPSprites;
00212     Collision* collision;
00213 } FrameInfo;
00214 
00232 typedef struct
00233 {
00234     u8 numSprite;               // we use u8 to not waste ROM space
00235     u8 w;
00236     u8 h;
00237     u8 timer;
00238     FrameInfo frameInfos[4];
00239     TileSet* tileset;           // TODO: have a tileset per VDP sprite (when rescomp will be optimized for better LZ4W compression)
00240 } AnimationFrame;
00241 
00257 typedef struct
00258 {
00259     u16 numFrame;
00260     AnimationFrame** frames;
00261     u16 length;
00262     u8* sequence;
00263     s16 loop;
00264 } Animation;
00265 
00283 typedef struct
00284 {
00285     Palette* palette;
00286     u16 numAnimation;
00287     Animation** animations;
00288     u16 maxNumTile;
00289     u16 maxNumSprite;
00290 } SpriteDefinition;
00291 
00339 typedef struct _Sprite
00340 {
00341     u16 status;
00342     u16 visibility;
00343     const SpriteDefinition* definition;
00344     void (*onFrameChange)(struct _Sprite* sprite);
00345     Animation* animation;
00346     AnimationFrame* frame;
00347     FrameInfo* frameInfo;
00348     s16 animInd;
00349     s16 frameInd;
00350     s16 seqInd;
00351     u16 timer;
00352     s16 x;
00353     s16 y;
00354     s16 depth;
00355     u16 attribut;
00356     u16 VDPSpriteIndex;
00357     VDPSprite* lastVDPSprite;
00358     u16 lastNumSprite;
00359     u16 spriteToHide;
00360     u32 data;
00361     struct _Sprite* prev;
00362     struct _Sprite* next;
00363 } Sprite;
00364 
00376 typedef void FrameChangeCallback(Sprite* sprite);
00377 
00381 extern u16 spriteVramSize;
00382 
00394 void SPR_init();
00410 void SPR_initEx(u16 vramSize);
00418 void SPR_end();
00423 bool SPR_isInitialized();
00424 
00431 void SPR_reset();
00432 
00482 Sprite* SPR_addSpriteEx(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut, u16 spriteIndex, u16 flag);
00507 Sprite* SPR_addSprite(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut);
00555 Sprite* SPR_addSpriteExSafe(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut, u16 spriteIndex, u16 flag);
00578 Sprite* SPR_addSpriteSafe(const SpriteDefinition* spriteDef, s16 x, s16 y, u16 attribut);
00579 
00591 void SPR_releaseSprite(Sprite* sprite);
00596 u16 SPR_getNumActiveSprite();
00601 void SPR_defragVRAM();
00630 u16** SPR_loadAllFrames(const SpriteDefinition* sprDef, u16 index, u16* totalNumTile);
00631 
00646 bool SPR_setDefinition(Sprite* sprite, const SpriteDefinition* spriteDef);
00658 void SPR_setPosition(Sprite* sprite, s16 x, s16 y);
00668 void SPR_setHFlip(Sprite* sprite, u16 value);
00678 void SPR_setVFlip(Sprite* sprite, u16 value);
00688 void SPR_setPalette(Sprite* sprite, u16 value);
00698 void SPR_setPriorityAttribut(Sprite* sprite, u16 value);
00711 void SPR_setDepth(Sprite* sprite, s16 value);
00716 void SPR_setZ(Sprite* sprite, s16 value);
00720 void SPR_setAlwaysOnTop(Sprite* sprite, u16 value);
00732 void SPR_setAnimAndFrame(Sprite* sprite, s16 anim, s16 frame);
00742 void SPR_setAnim(Sprite* sprite, s16 anim);
00752 void SPR_setFrame(Sprite* sprite, s16 frame);
00760 void SPR_nextFrame(Sprite* sprite);
00761 
00776 bool SPR_setVRAMTileIndex(Sprite* sprite, s16 value);
00794 bool SPR_setSpriteTableIndex(Sprite* sprite, s16 value);
00805 void SPR_setAutoTileUpload(Sprite* sprite, bool value);
00818 void SPR_setDelayedFrameUpdate(Sprite* sprite, bool value);
00834 void SPR_setFrameChangeCallback(Sprite* sprite, FrameChangeCallback* callback);
00835 
00849 void SPR_setVisibility(Sprite* sprite, SpriteVisibility value);
00853 void SPR_setAlwaysVisible(Sprite* sprite, u16 value);
00857 void SPR_setNeverVisible(Sprite* sprite, u16 value);
00872 bool SPR_computeVisibility(Sprite* sprite);
00873 
00874 // /**
00875 // *  \brief
00876 // *      Test if specified sprites are in collision.
00877 // *
00878 // *  \param sprite1
00879 // *      first sprite.
00880 // *  \param sprite2
00881 // *      second sprite.
00882 // *  \return
00883 // *      TRUE if sprite1 and sprite2 are in collision, FALSE otherwise.
00884 // */
00885 //u16 SPR_testCollision(Sprite* sprite1, Sprite* sprite2);
00886 
00894 void SPR_clear();
00904 void SPR_update();
00905 
00910 void SPR_logProfil();
00915 void SPR_logSprites();
00916 
00917 
00918 #endif // _SPRITE_ENG_H_
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Defines