Skip to content

Commit 3f095cd

Browse files
committed
Added bg draw function, move structs defs to src
1 parent 7853ef0 commit 3f095cd

File tree

15 files changed

+244
-210
lines changed

15 files changed

+244
-210
lines changed

_windows/bin/SSGE.dll

512 Bytes
Binary file not shown.

_windows/lib/libSSGE.a

192 Bytes
Binary file not shown.

example/_windows/SSGE.dll

512 Bytes
Binary file not shown.

example/_windows/lib/libSSGE.a

216 Bytes
Binary file not shown.

example/_windows/tictactoe.exe

0 Bytes
Binary file not shown.

example/src/tictactoe.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main(int argc, char *argv[]) {
4343
// Run the engine
4444
SSGE_Audio_Play(start, -1);
4545

46-
SSGE_Run((SSGE_UpdateFunc)update, (SSGE_DrawFunc)draw, (SSGE_EventHandler)event_handler, &game);
46+
SSGE_Run((SSGE_UpdateFunc)update, NULL, (SSGE_DrawFunc)draw, (SSGE_EventHandler)event_handler, &game);
4747

4848
// Quit the engine
4949
SSGE_Quit();

include/SSGE/SSGE.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,15 @@ SSGEAPI void SSGE_Quit();
4343

4444
/**
4545
* Run the engine
46-
* \param update The update function
47-
* \param draw The draw function
48-
* \param eventHandler The event handler function
49-
* \param data The `void *` to pass to the functions (update, draw, eventHandler)
46+
* \param update The update function, can be `NULL`
47+
* \param background The function to draw the background, can be `NULL`
48+
* \param draw The draw function, can be `NULL`
49+
* \param eventHandler The event handler function, can be `NULL`
50+
* \param data The `void *` to pass to the functions (update, background, draw, eventHandler), can be `NULL`
5051
* \warning The engine runs in an infinite loop until the window is closed
51-
* \note The order of execution is as follows: Event handling, Update, (Clear screen), Draw
52+
* \note The order of execution is as follows: Event handling, Update, (Clear screen), (Object Rendering), Draw
5253
*/
53-
SSGEAPI void SSGE_Run(SSGE_UpdateFunc update, SSGE_DrawFunc draw, SSGE_EventHandler eventHandler, void *data);
54+
SSGEAPI void SSGE_Run(SSGE_UpdateFunc update, SSGE_DrawFunc background, SSGE_DrawFunc draw, SSGE_EventHandler eventHandler, void *data);
5455

5556
// Window functions
5657

include/SSGE/SSGE_texture.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "SSGE/SSGE_config.h"
55
#include "SSGE/SSGE_types.h"
66

7+
78
#ifdef __cplusplus
89
extern "C" {
910
#endif

include/SSGE/SSGE_types.h

Lines changed: 23 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5052
typedef void (*SSGE_UpdateFunc)(void *);
@@ -53,151 +55,17 @@ typedef void (*SSGE_EventHandler)(SSGE_Event, void *);
5355

5456
typedef 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-
9858
typedef 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-
14263
typedef 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-
20169
typedef 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
}

makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,32 @@ OBJ_STATIC = $(subst src,$(OSDIR)/build_static,$(patsubst %.c, %.o, $(SRC)))
1616

1717
INCLUDE = -I include
1818
LIB = -L $(OSDIR)/lib -lSDL2main -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer
19-
EXTRA = -Werror -Wall -O3 -flto=auto -fPIC -DSSGE_BUILD
19+
EXTRA = -Werror -Wall -flto=auto -DSSGE_BUILD
20+
OFLAG ?= -O3
2021

2122
# Build mode: release, cpuSpecific
2223
BUILD_MODE ?= release
2324
ifeq ($(BUILD_MODE),cpuSpecific)
24-
OPTIMIZE = -march=native -mtune=native
25+
CPU_OPTIMIZE = -march=native -mtune=native
2526
else
26-
OPTIMIZE = -O3 -mtune=generic
27+
CPU_OPTIMIZE = -mtune=generic
2728
endif
2829

2930
all: create_dirs static dll
31+
@echo "Build mode: $(BUILD_MODE) (= $(CPU_OPTIMIZE)), O-flag: $(OFLAG)"
3032
@echo Static library: $(STATIC_BUILD)
3133
@echo Dynamic library: $(DLL_BUILD)
3234
@echo Imp. library: $(IMPLIB_BUILD)
3335

3436
remake: clean all
3537

3638
$(OSDIR)/build/%.o: src/%.c
37-
@echo [DYNAMIC] Compiling $*.c...
38-
@gcc $(INCLUDE) -c src/$*.c -o $(OSDIR)/build/$*.o $(EXTRA) $(OPTIMIZE)
39+
@echo "[DYNAMIC] Compiling $*.c..."
40+
@gcc $(INCLUDE) -c src/$*.c -o $(OSDIR)/build/$*.o $(EXTRA) $(OFLAG) $(CPU_OPTIMIZE) -fPIC
3941

4042
$(OSDIR)/build_static/%.o: src/%.c
41-
@echo [STATIC] Compiling $*.c...
42-
@gcc $(INCLUDE) -c src/$*.c -o $(OSDIR)/build_static/$*.o $(EXTRA) $(OPTIMIZE) -DSSGE_STATIC -static
43+
@echo "[STATIC] Compiling $*.c..."
44+
@gcc $(INCLUDE) -c src/$*.c -o $(OSDIR)/build_static/$*.o $(EXTRA) $(OFLAG) $(CPU_OPTIMIZE) -DSSGE_STATIC -static
4345

4446
clean:
4547
@echo Cleaning up...

0 commit comments

Comments
 (0)