@@ -12,7 +12,7 @@ extern "C" {
1212#endif
1313
1414/************************************************
15- * SDL Structures
15+ * SDL Structs
1616 ************************************************/
1717
1818// Color struct (SDL_Color)
@@ -45,6 +45,8 @@ typedef enum {
4545
4646/*************************************************
4747 * SSGE Types
48+ * For events and keyboard structs,
49+ * see the related headers
4850 *************************************************/
4951
5052typedef void (* SSGE_UpdateFunc )(void * );
@@ -53,151 +55,17 @@ typedef void (*SSGE_EventHandler)(SSGE_Event, void *);
5355
5456typedef void (* SSGE_DestroyData )(void * );
5557
56- /*************************************************
57- * SSGE Structures / Enums
58- *************************************************/
59-
60- // Engine struct
61- typedef struct _SSGE_Engine {
62- struct SDL_Window * window ; // The window
63- struct SDL_Renderer * renderer ; // The renderer
64- char * title ; // The title of the window
65- struct SDL_Surface * icon ; // The icon of the window
66- uint16_t width ; // The width of the window
67- uint16_t height ; // The height of the window
68- bool resizable ; // If the window is resizable
69- SSGE_WindowMode fullscreen ; // If the window is in fullscreen
70- uint16_t fps ; // The frames per second
71- uint8_t maxFrameskip ; // Max frameskip, default to 3
72- bool vsync ; // If VSync is enabled
73- uint16_t vsyncRate ; // VSync rate
74- bool isRunning ; // The running state of the engine
75- bool initialized ; // If the `SSGE_Engine` has been initialized
76- } SSGE_Engine ;
77-
78- // Array struct
79- typedef struct _SSGE_Array {
80- void * * array ; // Array of pointers
81- uint32_t size ; // Size of the array
82- uint32_t count ; // Number of elements in the array
83- uint32_t * indexes ; // Pointer to the pile of unused indexes
84- uint32_t idxSize ; // The size of the pile of indexes
85- uint32_t idxCount ; // Number of unused indexes
86- } SSGE_Array ;
87-
88- // Texture struct
89- typedef struct _SSGE_Texture {
90- char * name ; // The name of the texture
91- uint32_t id ; // The id of the texture
92- struct SDL_Texture * texture ; // The SDL_Texture
93- int anchorX ; // Anchor x coordinate (relative to the texture)
94- int anchorY ; // Anchor y coordinate (relative to the texture)
95- SSGE_Array queue ; // Queue of every render call for this texture
96- } SSGE_Texture ;
97-
9858typedef enum _SSGE_AnimationType {
99- SSGE_ANIM_FRAMES = 0 ,
100- SSGE_ANIM_FUNCTION
59+ SSGE_ANIM_FRAMES = 0 , // Animation using frames
60+ SSGE_ANIM_FUNCTION // Animation using a function
10161} SSGE_AnimationType ;
10262
103- // Animation struct
104- typedef struct _SSGE_AnimationState SSGE_AnimationState ;
105- typedef struct _SSGE_Animation {
106- char * name ; // The name of the animation
107- uint32_t id ; // The id of the animation
108- SSGE_AnimationType type ; // The animation type
109- union {
110- struct _SSGE_AnimationData {
111- struct SDL_Texture * * frames ; // An array of the animation frames
112- uint8_t * frametimes ; // Frametime corresponding to each frames
113- uint32_t frameCount ; // The number of animation frames
114- uint32_t currentCount ; // The number of frames the animation currently have
115- uint16_t width ; // The width of the frames
116- uint16_t height ; // The height of the frames
117- int anchorX ; // Anchor x coordinate (relative to the frame)
118- int anchorY ; // Anchor y coordinate (relative to the frame)
119- } data ;
120-
121- /**
122- * The animation function if `type` is `SSGE_ANIM_FUNCTION`.
123- * Must take in an `SSGE_AnimationState` pointer
124- */
125- void (* draw )(SSGE_AnimationState * );
126- };
127- } SSGE_Animation ;
128-
129- // Animation state struct
130- typedef struct _SSGE_AnimationState {
131- SSGE_Animation * animation ; // The animation to track the animation state
132- int x ; // The x coordinate at which the animation is played
133- int y ; // The y coordinate at which the animation is played
134- uint32_t loop ; // Number of loops (0 means play once, -1 means indefinitly)
135- uint32_t currentFrame ; // The index of the current frame
136- uint8_t currentFrameTime ; // Elapsed time spent on the current frame (in frames)
137- bool reversed ; // If the animation is reversed or not
138- bool pingpong ; // If the animation should pingpong (normal -> reversed)
139- bool isPlaying ; // If the animation is playing or not
140- } SSGE_AnimationState ;
141-
14263typedef enum _SSGE_SpriteType {
143- SSGE_SPRITE_NONE = -1U ,
144- SSGE_SPRITE_STATIC = 0 ,
145- SSGE_SPRITE_ANIM
64+ SSGE_SPRITE_NONE = -1U , // No sprite
65+ SSGE_SPRITE_STATIC = 0 , // Single frame sprite
66+ SSGE_SPRITE_ANIM // Animated sprite
14667} SSGE_SpriteType ;
14768
148- // Object struct
149- typedef struct _SSGE_Object {
150- char * name ; // The name of the object
151- uint32_t id ; // The id of the object
152- int x ; // The x coordinate of the object
153- int y ; // The y coordinate of the object
154- uint16_t width ; // The width of the object
155- uint16_t height ; // The height of the object
156- bool hitbox ; // If the object has a hitbox
157- bool hidden ; // If the object is hidden
158- SSGE_SpriteType spriteType ; // If the sprite is animated or static
159- union {
160- struct {
161- SSGE_Texture * texture ; // The texture of the object
162- uint32_t renderDataIdx ; // The index of the render data in the texture render queue
163- } texture ;
164- uint32_t animation ; // The id of the animation state
165- };
166- void * data ; // The data of the object
167- void (* destroyData )(void * ); // The function to be called to destroy the data
168- } SSGE_Object ;
169-
170- // Object template struct
171- typedef struct _SSGE_ObjectTemplate {
172- char * name ; // The name of the template
173- uint32_t id ; // The id of the template
174- uint16_t width ; // The width of the object
175- uint16_t height ; // The height of the object
176- SSGE_SpriteType spriteType ; // If the sprite is animated or static
177- union {
178- SSGE_Texture * texture ; // The texture for the template
179- SSGE_Animation * animation ; // The animation for the template
180- };
181- bool hitbox ; // If objects created from this template have a hitbox
182- } SSGE_ObjectTemplate ;
183-
184- // Tilemap struct
185- typedef struct _SSGE_Tilemap {
186- struct SDL_Texture * texture ; // The texture of the tilemap
187- uint16_t tileWidth ; // The width of the tiles
188- uint16_t tileHeight ; // The height of the tiles
189- uint16_t spacing ; // The spacing between the tiles
190- uint16_t nbRows ; // The number of rows in the tilemap
191- uint16_t nbCols ; // The number of columns in the tilemap
192- } SSGE_Tilemap ;
193-
194- // Tile struct
195- typedef struct _SSGE_Tile {
196- SSGE_Tilemap * tilemap ; // The tilemap of the tile
197- uint16_t row ; // The row of the tile
198- uint16_t col ; // The column of the tile
199- } SSGE_Tile ;
200-
20169typedef enum _SSGE_Anchor {
20270 SSGE_NW ,
20371 SSGE_N ,
@@ -210,18 +78,21 @@ typedef enum _SSGE_Anchor {
21078 SSGE_SE
21179} SSGE_Anchor ;
21280
213- // Font struct
214- typedef struct _SSGE_Font {
215- char * name ; // The name of the font
216- struct _TTF_Font * font ; // The TTF_Font
217- } SSGE_Font ;
218-
219- // Audio struct
220- typedef struct _SSGE_Audio {
221- char * name ; // The name of the audio
222- uint32_t id ; // The id of the audio
223- struct Mix_Chunk * audio ; // The Mix_Chunk
224- } SSGE_Audio ;
81+ typedef struct _SSGE_Engine SSGE_Engine ;
82+ typedef struct _SSGE_Array SSGE_Array ;
83+ typedef struct _SSGE_Texture SSGE_Texture ;
84+
85+ typedef struct _SSGE_AnimationState SSGE_AnimationState ;
86+ typedef struct _SSGE_Animation SSGE_Animation ;
87+ typedef struct _SSGE_AnimationState SSGE_AnimationState ;
88+
89+ typedef struct _SSGE_Object SSGE_Object ;
90+ typedef struct _SSGE_ObjectTemplate SSGE_ObjectTemplate ;
91+ typedef struct _SSGE_Tilemap SSGE_Tilemap ;
92+ typedef struct _SSGE_Tile SSGE_Tile ;
93+
94+ typedef struct _SSGE_Font SSGE_Font ;
95+ typedef struct _SSGE_Audio SSGE_Audio ;
22596
22697#ifdef __cplusplus
22798}
0 commit comments