Unify the library on an akgl_ namespace

This commit is contained in:
2026-05-06 23:18:42 -04:00
parent f416cb5dee
commit 359ae23414
46 changed files with 1327 additions and 1270 deletions

View File

@@ -1,9 +1,9 @@
#ifndef _SDL_GAMECONTROLLERDB_H_
#define _SDL_GAMECONTROLLERDB_H_
// Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Wed May 6 11:52:34 AM EDT 2026
// Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Thu May 7 10:00:08 PM EDT 2026
#define SDL_GAMECONTROLLER_DB_LEN 2225
#define AKGL_SDL_GAMECONTROLLER_DB_LEN 2225
const char *SDL_GAMECONTROLLER_DB[] = {
"03000000300f00000a01000000000000,3 In 1 Conversion Box,a:b2,b:b1,back:b9,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b6,leftstick:b10,lefttrigger:b4,leftx:a0,lefty:a1,rightshoulder:b7,rightstick:b11,righttrigger:b5,rightx:a3,righty:a2,start:b8,x:b3,y:b0,platform:Windows",

View File

@@ -1,65 +1,65 @@
#ifndef _ACTOR_H_
#define _ACTOR_H_
#ifndef _AKGL_ACTOR_H_
#define _AKGL_ACTOR_H_
#include "character.h"
// ---- LOW WORD STATUSES ----
#define ACTOR_STATE_FACE_DOWN 1 << 0 // 1 0000 0000 0000 0001
#define ACTOR_STATE_FACE_LEFT 1 << 1 // 2 0000 0000 0000 0010
#define ACTOR_STATE_FACE_RIGHT 1 << 2 // 4 0000 0000 0000 0100
#define ACTOR_STATE_FACE_UP 1 << 3 // 8 0000 0000 0000 1000
#define ACTOR_STATE_ALIVE 1 << 4 // 16 0000 0000 0001 0000
#define ACTOR_STATE_DYING 1 << 5 // 32 0000 0000 0010 0000
#define ACTOR_STATE_DEAD 1 << 6 // 64 0000 0000 0100 0000
#define ACTOR_STATE_MOVING_LEFT 1 << 7 // 128 0000 0000 1000 0000
#define ACTOR_STATE_MOVING_RIGHT 1 << 8 // 256 0000 0001 0000 0000
#define ACTOR_STATE_MOVING_UP 1 << 9 // 512 0000 0010 0000 0000
#define ACTOR_STATE_MOVING_DOWN 1 << 10 // 1024 0000 0100 0000 0000
#define ACTOR_STATE_UNDEFINED_11 1 << 11 // 2048 0000 1000 0000 0000
#define ACTOR_STATE_UNDEFINED_12 1 << 12 // 4096 0001 0000 0000 0000
#define ACTOR_STATE_UNDEFINED_13 1 << 13 // 8192 0010 0000 0000 0000
#define ACTOR_STATE_UNDEFINED_14 1 << 14 // 16384 0100 0000 0000 0000
#define ACTOR_STATE_UNDEFINED_15 1 << 15 // 32768 1000 0000 0000 0000
#define AKGL_ACTOR_STATE_FACE_DOWN 1 << 0 // 1 0000 0000 0000 0001
#define AKGL_ACTOR_STATE_FACE_LEFT 1 << 1 // 2 0000 0000 0000 0010
#define AKGL_ACTOR_STATE_FACE_RIGHT 1 << 2 // 4 0000 0000 0000 0100
#define AKGL_ACTOR_STATE_FACE_UP 1 << 3 // 8 0000 0000 0000 1000
#define AKGL_ACTOR_STATE_ALIVE 1 << 4 // 16 0000 0000 0001 0000
#define AKGL_ACTOR_STATE_DYING 1 << 5 // 32 0000 0000 0010 0000
#define AKGL_ACTOR_STATE_DEAD 1 << 6 // 64 0000 0000 0100 0000
#define AKGL_ACTOR_STATE_MOVING_LEFT 1 << 7 // 128 0000 0000 1000 0000
#define AKGL_ACTOR_STATE_MOVING_RIGHT 1 << 8 // 256 0000 0001 0000 0000
#define AKGL_ACTOR_STATE_MOVING_UP 1 << 9 // 512 0000 0010 0000 0000
#define AKGL_ACTOR_STATE_MOVING_DOWN 1 << 10 // 1024 0000 0100 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_11 1 << 11 // 2048 0000 1000 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_12 1 << 12 // 4096 0001 0000 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_13 1 << 13 // 8192 0010 0000 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_14 1 << 14 // 16384 0100 0000 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_15 1 << 15 // 32768 1000 0000 0000 0000
// ----- HIGH WORD STATUSES -----
#define ACTOR_STATE_UNDEFINED_16 1 << 16 // 65536 0000 0000 0000 0001
#define ACTOR_STATE_UNDEFINED_17 1 << 17 // 131072 0000 0000 0000 0010
#define ACTOR_STATE_UNDEFINED_18 1 << 18 // 262144 0000 0000 0000 0100
#define ACTOR_STATE_UNDEFINED_19 1 << 19 // 524288 0000 0000 0000 1000
#define ACTOR_STATE_UNDEFINED_20 1 << 20 // 1048576 0000 0000 0001 0000
#define ACTOR_STATE_UNDEFINED_21 1 << 21 // 2097152 0000 0000 0010 0000
#define ACTOR_STATE_UNDEFINED_22 1 << 22 // 4194304 0000 0000 0100 0000
#define ACTOR_STATE_UNDEFINED_23 1 << 23 // 8388608 0000 0000 1000 0000
#define ACTOR_STATE_UNDEFINED_24 1 << 24 // 16777216 0000 0001 0000 0000
#define ACTOR_STATE_UNDEFINED_25 1 << 25 // 33554432 0000 0010 0000 0000
#define ACTOR_STATE_UNDEFINED_26 1 << 26 // 67108864 0000 0100 0000 0000
#define ACTOR_STATE_UNDEFINED_27 1 << 27 // 134217728 0000 1000 0000 0000
#define ACTOR_STATE_UNDEFINED_28 1 << 28 // 268435456 0001 0000 0000 0000
#define ACTOR_STATE_UNDEFINED_29 1 << 29 // 536870912 0010 0000 0000 0000
#define ACTOR_STATE_UNDEFINED_30 1 << 30 // 1073741824 0100 0000 0000 0000
#define ACTOR_STATE_UNDEFINED_31 1 << 31 // 2147483648 1000 0000 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_16 1 << 16 // 65536 0000 0000 0000 0001
#define AKGL_ACTOR_STATE_UNDEFINED_17 1 << 17 // 131072 0000 0000 0000 0010
#define AKGL_ACTOR_STATE_UNDEFINED_18 1 << 18 // 262144 0000 0000 0000 0100
#define AKGL_ACTOR_STATE_UNDEFINED_19 1 << 19 // 524288 0000 0000 0000 1000
#define AKGL_ACTOR_STATE_UNDEFINED_20 1 << 20 // 1048576 0000 0000 0001 0000
#define AKGL_ACTOR_STATE_UNDEFINED_21 1 << 21 // 2097152 0000 0000 0010 0000
#define AKGL_ACTOR_STATE_UNDEFINED_22 1 << 22 // 4194304 0000 0000 0100 0000
#define AKGL_ACTOR_STATE_UNDEFINED_23 1 << 23 // 8388608 0000 0000 1000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_24 1 << 24 // 16777216 0000 0001 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_25 1 << 25 // 33554432 0000 0010 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_26 1 << 26 // 67108864 0000 0100 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_27 1 << 27 // 134217728 0000 1000 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_28 1 << 28 // 268435456 0001 0000 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_29 1 << 29 // 536870912 0010 0000 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_30 1 << 30 // 1073741824 0100 0000 0000 0000
#define AKGL_ACTOR_STATE_UNDEFINED_31 1 << 31 // 2147483648 1000 0000 0000 0000
#define ACTOR_MAX_STATES 32
#define AKGL_ACTOR_MAX_STATES 32
// This is an array of strings equal to actor states from 1-32.
// This is built by a utility script and not kept in git, see
// the Makefile for lib_src/actor_state_string_names.c
extern char *ACTOR_STATE_STRING_NAMES[ACTOR_MAX_STATES+1];
extern char *AKGL_ACTOR_STATE_STRING_NAMES[AKGL_ACTOR_MAX_STATES+1];
#define ACTOR_STATE_FACE_ALL (ACTOR_STATE_FACE_DOWN | ACTOR_STATE_FACE_LEFT | ACTOR_STATE_FACE_RIGHT | ACTOR_STATE_FACE_UP)
#define ACTOR_STATE_MOVING_ALL (ACTOR_STATE_MOVING_LEFT | ACTOR_STATE_MOVING_RIGHT | ACTOR_STATE_MOVING_UP | ACTOR_STATE_MOVING_DOWN)
#define AKGL_ACTOR_STATE_FACE_ALL (AKGL_ACTOR_STATE_FACE_DOWN | AKGL_ACTOR_STATE_FACE_LEFT | AKGL_ACTOR_STATE_FACE_RIGHT | AKGL_ACTOR_STATE_FACE_UP)
#define AKGL_ACTOR_STATE_MOVING_ALL (AKGL_ACTOR_STATE_MOVING_LEFT | AKGL_ACTOR_STATE_MOVING_RIGHT | AKGL_ACTOR_STATE_MOVING_UP | AKGL_ACTOR_STATE_MOVING_DOWN)
#define ACTOR_MAX_NAME_LENGTH 128
#define ACTOR_MAX_CHILDREN 8
#define AKGL_ACTOR_MAX_NAME_LENGTH 128
#define AKGL_ACTOR_MAX_CHILDREN 8
#define MAX_HEAP_ACTOR 64
#define AKGL_MAX_HEAP_ACTOR 64
typedef struct actor {
typedef struct akgl_Actor {
int refcount;
char name[ACTOR_MAX_NAME_LENGTH];
character *basechar;
char name[AKGL_ACTOR_MAX_NAME_LENGTH];
akgl_Character *basechar;
int curSpriteFrameId;
SDL_Time curSpriteFrameTimer;
bool curSpriteReversing;
@@ -71,35 +71,34 @@ typedef struct actor {
SDL_Time logictimer;
float x;
float y;
struct actor *children[ACTOR_MAX_CHILDREN];
struct actor *parent;
akerr_ErrorContext AKERR_NOIGNORE *(*updatefunc)(struct actor *obj);
akerr_ErrorContext AKERR_NOIGNORE *(*renderfunc)(struct actor *obj, SDL_Renderer *renderer);
akerr_ErrorContext AKERR_NOIGNORE *(*facefunc)(struct actor *obj);
akerr_ErrorContext AKERR_NOIGNORE *(*movementlogicfunc)(struct actor *obj, SDL_Time curtimems);
akerr_ErrorContext AKERR_NOIGNORE *(*changeframefunc)(struct actor *obj, sprite *curSprite, SDL_Time curtimems);
akerr_ErrorContext AKERR_NOIGNORE *(*addchild)(struct actor *obj, struct actor *child);
} actor;
struct akgl_Actor *children[AKGL_ACTOR_MAX_CHILDREN];
struct akgl_Actor *parent;
akerr_ErrorContext AKERR_NOIGNORE *(*updatefunc)(struct akgl_Actor *obj);
akerr_ErrorContext AKERR_NOIGNORE *(*renderfunc)(struct akgl_Actor *obj, SDL_Renderer *renderer);
akerr_ErrorContext AKERR_NOIGNORE *(*facefunc)(struct akgl_Actor *obj);
akerr_ErrorContext AKERR_NOIGNORE *(*movementlogicfunc)(struct akgl_Actor *obj, SDL_Time curtimems);
akerr_ErrorContext AKERR_NOIGNORE *(*changeframefunc)(struct akgl_Actor *obj, akgl_Sprite *curSprite, SDL_Time curtimems);
akerr_ErrorContext AKERR_NOIGNORE *(*addchild)(struct akgl_Actor *obj, struct akgl_Actor *child);
} akgl_Actor;
akerr_ErrorContext AKERR_NOIGNORE *actor_initialize(actor *obj, char *name);
akerr_ErrorContext AKERR_NOIGNORE *actor_set_character(actor *obj, char *basecharname);
akerr_ErrorContext AKERR_NOIGNORE *actor_render(actor *obj, SDL_Renderer *renderer);
akerr_ErrorContext AKERR_NOIGNORE *actor_update(actor *obj);
akerr_ErrorContext AKERR_NOIGNORE *actor_logic_movement(actor *obj, SDL_Time curtimems);
akerr_ErrorContext AKERR_NOIGNORE *actor_logic_changeframe(actor *obj, sprite *curSprite, SDL_Time curtimems);
akerr_ErrorContext AKERR_NOIGNORE *actor_automatic_face(actor *obj);
akerr_ErrorContext AKERR_NOIGNORE *actor_add_child(actor *obj, actor *child);
akerr_ErrorContext AKERR_NOIGNORE *akgl_actor_initialize(akgl_Actor *obj, char *name);
akerr_ErrorContext AKERR_NOIGNORE *akgl_actor_set_character(akgl_Actor *obj, char *basecharname);
akerr_ErrorContext AKERR_NOIGNORE *akgl_actor_render(akgl_Actor *obj, SDL_Renderer *renderer);
akerr_ErrorContext AKERR_NOIGNORE *akgl_actor_update(akgl_Actor *obj);
akerr_ErrorContext AKERR_NOIGNORE *akgl_actor_logic_movement(akgl_Actor *obj, SDL_Time curtimems);
akerr_ErrorContext AKERR_NOIGNORE *akgl_actor_logic_changeframe(akgl_Actor *obj, akgl_Sprite *curSprite, SDL_Time curtimems);
akerr_ErrorContext AKERR_NOIGNORE *akgl_actor_automatic_face(akgl_Actor *obj);
akerr_ErrorContext AKERR_NOIGNORE *akgl_actor_add_child(akgl_Actor *obj, akgl_Actor *child);
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_left_on(actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_left_off(actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_right_on(actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_right_off(actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_up_on(actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_up_off(actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_down_on(actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *SDL3GActor_cmhf_down_off(actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_left_on(akgl_Actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_left_off(akgl_Actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_right_on(akgl_Actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_right_off(akgl_Actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_up_on(akgl_Actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_up_off(akgl_Actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_down_on(akgl_Actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_Actor_cmhf_down_off(akgl_Actor *obj, SDL_Event *event);
void akgl_registry_iterate_actor(void *userdata, SDL_PropertiesID registry, const char *name);
void registry_iterate_actor(void *userdata, SDL_PropertiesID registry, const char *name);
#endif // _ACTOR_H_
#endif // _AKGL_ACTOR_H_

View File

@@ -3,6 +3,6 @@
#include <akerror.h>
akerr_ErrorContext AKERR_NOIGNORE *load_start_bgm(char *fname);
akerr_ErrorContext AKERR_NOIGNORE *akgl_load_start_bgm(char *fname);
#endif //_ASSETS_H_

View File

@@ -1,31 +1,31 @@
#ifndef _CHARACTER_H_
#define _CHARACTER_H_
#ifndef _AKGL_CHARACTER_H_
#define _AKGL_CHARACTER_H_
#include <SDL3/SDL_properties.h>
#include "sprite.h"
#define SPRITE_MAX_CHARACTER_NAME_LENGTH 128
#define MAX_HEAP_CHARACTER 256
#define AKGL_SPRITE_MAX_CHARACTER_NAME_LENGTH 128
#define AKGL_MAX_HEAP_CHARACTER 256
typedef struct character {
typedef struct akgl_Character {
int refcount;
char name[SPRITE_MAX_CHARACTER_NAME_LENGTH];
char name[AKGL_SPRITE_MAX_CHARACTER_NAME_LENGTH];
SDL_PropertiesID state_sprites;
akerr_ErrorContext AKERR_NOIGNORE *(*sprite_add)(struct character *, sprite *, int);
akerr_ErrorContext AKERR_NOIGNORE *(*sprite_get)(struct character *, int, sprite **);
akerr_ErrorContext AKERR_NOIGNORE *(*sprite_add)(struct akgl_Character *, akgl_Sprite *, int);
akerr_ErrorContext AKERR_NOIGNORE *(*sprite_get)(struct akgl_Character *, int, akgl_Sprite **);
long int movementspeed;
float vx;
float vy;
} character;
} akgl_Character;
akerr_ErrorContext AKERR_NOIGNORE *character_initialize(character *basechar, char *name);
akerr_ErrorContext AKERR_NOIGNORE *character_sprite_add(character *basechar, sprite *ref, int state);
akerr_ErrorContext AKERR_NOIGNORE *character_sprite_get(character *basechar, int state, sprite **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_character_initialize(akgl_Character *basechar, char *name);
akerr_ErrorContext AKERR_NOIGNORE *akgl_character_sprite_add(akgl_Character *basechar, akgl_Sprite *ref, int state);
akerr_ErrorContext AKERR_NOIGNORE *akgl_character_sprite_get(akgl_Character *basechar, int state, akgl_Sprite **dest);
// This is an SDL iterator so we can't return our error state from it.
void character_state_sprites_iterate(void *userdata, SDL_PropertiesID props, const char *name);
void akgl_character_state_sprites_iterate(void *userdata, SDL_PropertiesID props, const char *name);
akerr_ErrorContext AKERR_NOIGNORE *character_load_json(char *filename);
akerr_ErrorContext AKERR_NOIGNORE *akgl_character_load_json(char *filename);
#endif // _CHARACTER_H_
#endif // _AKGL_CHARACTER_H_

View File

@@ -4,8 +4,8 @@
#include <SDL3/SDL.h>
#include <akerror.h>
#define MAX_CONTROL_MAPS 8
#define MAX_CONTROLS 32
#define AKGL_MAX_CONTROL_MAPS 8
#define AKGL_MAX_CONTROLS 32
typedef struct {
Uint32 event_on;
@@ -15,30 +15,30 @@ typedef struct {
Uint8 axis;
Uint8 axis_range_min;
Uint8 axis_range_max;
akerr_ErrorContext AKERR_NOIGNORE *(*handler_on)(actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *(*handler_off)(actor *obj, SDL_Event *event);
} SDL3GControl;
akerr_ErrorContext AKERR_NOIGNORE *(*handler_on)(akgl_Actor *obj, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *(*handler_off)(akgl_Actor *obj, SDL_Event *event);
} akgl_Control;
typedef struct {
actor *target;
akgl_Actor *target;
int nextMap;
SDL3GControl controls[MAX_CONTROLS];
akgl_Control controls[AKGL_MAX_CONTROLS];
SDL_KeyboardID kbid;
SDL_JoystickID jsid;
SDL_MouseID mouseid;
SDL_PenID penid;
} SDL3GControlMap;
} akgl_ControlMap;
extern SDL3GControlMap GAME_ControlMaps[MAX_CONTROL_MAPS];
extern akgl_ControlMap GAME_ControlMaps[AKGL_MAX_CONTROL_MAPS];
akerr_ErrorContext AKERR_NOIGNORE *controller_handle_event(void *appstate, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_handle_event(void *appstate, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *controller_handle_button_down(void *appstate, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *controller_handle_button_up(void *appstate, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *controller_handle_added(void *appstate, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *controller_handle_removed(void *appstate, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_handle_button_down(void *appstate, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_handle_button_up(void *appstate, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_handle_added(void *appstate, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_handle_removed(void *appstate, SDL_Event *event);
akerr_ErrorContext AKERR_NOIGNORE *SDL3G_controller_pushmap(int controlmapid, SDL3GControl *control);
akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_pushmap(int controlmapid, akgl_Control *control);
akerr_ErrorContext AKERR_NOIGNORE *SDL3G_controller_default(int controlmapid, char *actorname, int kbid, int jsid);
akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_default(int controlmapid, char *actorname, int kbid, int jsid);
#endif // _CONTROLLER_H_

View File

@@ -1,6 +1,6 @@
#ifndef _DRAW_H_
#define _DRAW_H_
void GAME_draw_background(int w, int h);
void akgl_draw_background(int w, int h);
#endif //_DRAW_H_

View File

@@ -1,6 +1,6 @@
#ifndef _ERROR_H_
#define _ERROR_H_
#define AKERR_SDL AKERR_LAST_ERRNO_VALUE + 1
#define AKGL_ERR_SDL AKERR_LAST_ERRNO_VALUE + 1
#endif // _ERROR_H_

View File

@@ -1,14 +1,14 @@
#ifndef _GAME_H_
#define _GAME_H_
#ifndef _AKGL_GAME_H_
#define _AKGL_GAME_H_
#include <SDL3_mixer/SDL_mixer.h>
#include "tilemap.h"
#define GAME_AUDIO_TRACK_BGM 1
#define GAME_AUDIO_MAX_TRACKS 64
#define AKGL_GAME_AUDIO_TRACK_BGM 1
#define AKGL_GAME_AUDIO_MAX_TRACKS 64
#define TIME_ONESEC_NS 1000000000
#define TIME_ONESEC_MS 1000000
#define AKGL_TIME_ONESEC_NS 1000000000
#define AKGL_TIME_ONESEC_MS 1000000
/* ==================== GAME STATE VARIABLES =================== */
@@ -16,11 +16,11 @@ typedef struct {
float w;
float h;
SDL_Texture *texture;
} GAME_frame;
} akgl_Frame;
typedef struct {
int flags;
} GameState;
} akgl_GameState;
typedef struct {
char name[256];
@@ -28,30 +28,30 @@ typedef struct {
char uri[256];
int screenwidth;
int screenheight;
GameState state;
akgl_GameState state;
int fps;
SDL_Time gameStartTime;
SDL_Time lastIterTime;
SDL_Time lastFPSTime;
int framesSinceUpdate;
MIX_Mixer *mixer;
MIX_Track *tracks[GAME_AUDIO_MAX_TRACKS];
} Game;
MIX_Track *tracks[AKGL_GAME_AUDIO_MAX_TRACKS];
} akgl_Game;
extern SDL_Window *window;
extern SDL_Renderer *renderer;
extern tilemap gamemap;
extern akgl_Tilemap gamemap;
extern MIX_Audio *bgm;
extern SDL_FRect camera;
extern Game game;
extern akgl_Game game;
#define BITMASK_HAS(x, y) (x & y) == y
#define BITMASK_ADD(x, y) x |= y
#define BITMASK_DEL(x, y) x &= ~(y)
#define BITMASK_CLEAR(x) x = 0;
#define AKGL_BITMASK_HAS(x, y) (x & y) == y
#define AKGL_BITMASK_ADD(x, y) x |= y
#define AKGL_BITMASK_DEL(x, y) x &= ~(y)
#define AKGL_BITMASK_CLEAR(x) x = 0;
akerr_ErrorContext AKERR_NOIGNORE *GAME_init();
void GAME_updateFPS();
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init();
void akgl_game_updateFPS();
#endif //_GAME_H_
#endif //_AKGL_GAME_H_

View File

@@ -1,5 +1,5 @@
#ifndef _HEAP_H_
#define _HEAP_H_
#ifndef _AKGL_HEAP_H_
#define _AKGL_HEAP_H_
#include "sprite.h"
#include "actor.h"
@@ -7,29 +7,29 @@
#include "staticstring.h"
#include <akerror.h>
#define MAX_HEAP_ACTOR 64
#define MAX_HEAP_SPRITE (MAX_HEAP_ACTOR * 16)
#define MAX_HEAP_SPRITESHEET MAX_HEAP_SPRITE
#define MAX_HEAP_CHARACTER 256
#define MAX_HEAP_STRING 256
#define AKGL_MAX_HEAP_ACTOR 64
#define AKGL_MAX_HEAP_SPRITE (AKGL_MAX_HEAP_ACTOR * 16)
#define AKGL_MAX_HEAP_SPRITESHEET AKGL_MAX_HEAP_SPRITE
#define AKGL_MAX_HEAP_CHARACTER 256
#define AKGL_MAX_HEAP_STRING 256
extern actor HEAP_ACTOR[MAX_HEAP_ACTOR];
extern sprite HEAP_SPRITE[MAX_HEAP_SPRITE];
extern spritesheet HEAP_SPRITESHEET[MAX_HEAP_SPRITESHEET];
extern character HEAP_CHARACTER[MAX_HEAP_CHARACTER];
extern string HEAP_STRING[MAX_HEAP_STRING];
extern akgl_Actor HEAP_ACTOR[AKGL_MAX_HEAP_ACTOR];
extern akgl_Sprite HEAP_SPRITE[AKGL_MAX_HEAP_SPRITE];
extern akgl_SpriteSheet HEAP_SPRITESHEET[AKGL_MAX_HEAP_SPRITESHEET];
extern akgl_Character HEAP_CHARACTER[AKGL_MAX_HEAP_CHARACTER];
extern akgl_String HEAP_STRING[AKGL_MAX_HEAP_STRING];
akerr_ErrorContext AKERR_NOIGNORE *heap_init();
akerr_ErrorContext AKERR_NOIGNORE *heap_next_actor(actor **dest);
akerr_ErrorContext AKERR_NOIGNORE *heap_next_sprite(sprite **dest);
akerr_ErrorContext AKERR_NOIGNORE *heap_next_spritesheet(spritesheet **dest);
akerr_ErrorContext AKERR_NOIGNORE *heap_next_character(character **dest);
akerr_ErrorContext AKERR_NOIGNORE *heap_next_string(string **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_init();
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_next_actor(akgl_Actor **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_next_sprite(akgl_Sprite **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_next_spritesheet(akgl_SpriteSheet **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_next_character(akgl_Character **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_next_string(akgl_String **dest);
akerr_ErrorContext AKERR_NOIGNORE *heap_release_actor(actor *ptr);
akerr_ErrorContext AKERR_NOIGNORE *heap_release_sprite(sprite *ptr);
akerr_ErrorContext AKERR_NOIGNORE *heap_release_spritesheet(spritesheet *ptr);
akerr_ErrorContext AKERR_NOIGNORE *heap_release_character(character *ptr);
akerr_ErrorContext AKERR_NOIGNORE *heap_release_string(string *ptr);
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_release_actor(akgl_Actor *ptr);
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_release_sprite(akgl_Sprite *ptr);
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_release_spritesheet(akgl_SpriteSheet *ptr);
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_release_character(akgl_Character *ptr);
akerr_ErrorContext AKERR_NOIGNORE *akgl_heap_release_string(akgl_String *ptr);
#endif //_HEAP_H_
#endif //_AKGL_HEAP_H_

View File

@@ -1,43 +1,43 @@
#ifndef _ITERATOR_H_
#define _ITERATOR_H_
#ifndef _AKGL_ITERATOR_H_
#define _AKGL_ITERATOR_H_
typedef struct {
int flags;
int layerid;
} iterator;
} akgl_Iterator;
#define ITERATOR_OP_UPDATE 1 // 1
#define ITERATOR_OP_RENDER 1 << 1 // 2
#define ITERATOR_OP_RELEASE 1 << 2 // 4
#define ITERATOR_OP_LAYERMASK 1 << 3 // 8
#define ITERATOR_OP_UNDEFINED_4 1 << 4 // 16
#define ITERATOR_OP_UNDEFINED_5 1 << 5 // 32
#define ITERATOR_OP_UNDEFINED_6 1 << 6 // 64
#define ITERATOR_OP_UNDEFINED_7 1 << 7 // 128
#define ITERATOR_OP_UNDEFINED_8 1 << 8 // 256
#define ITERATOR_OP_UNDEFINED_9 1 << 9 // 512
#define ITERATOR_OP_UNDEFINED_10 1 << 10 // 1024
#define ITERATOR_OP_UNDEFINED_11 1 << 11 // 2048
#define ITERATOR_OP_UNDEFINED_12 1 << 12 // 4096
#define ITERATOR_OP_UNDEFINED_13 1 << 13 // 8192
#define ITERATOR_OP_UNDEFINED_14 1 << 14 // 16384
#define ITERATOR_OP_UNDEFINED_15 1 << 15 // 32768
#define ITERATOR_OP_UNDEFINED_16 1 << 16 // 65536
#define ITERATOR_OP_UNDEFINED_17 1 << 17 // 131072
#define ITERATOR_OP_UNDEFINED_18 1 << 18 // 262144
#define ITERATOR_OP_UNDEFINED_19 1 << 19 // 524288
#define ITERATOR_OP_UNDEFINED_20 1 << 20 // 1048576
#define ITERATOR_OP_UNDEFINED_21 1 << 21 // 2097152
#define ITERATOR_OP_UNDEFINED_22 1 << 22 // 4194304
#define ITERATOR_OP_UNDEFINED_23 1 << 23 // 8388608
#define ITERATOR_OP_UNDEFINED_24 1 << 24 // 16777216
#define ITERATOR_OP_UNDEFINED_25 1 << 25 // 33554432
#define ITERATOR_OP_UNDEFINED_26 1 << 26 // 67108864
#define ITERATOR_OP_UNDEFINED_27 1 << 27 // 134217728
#define ITERATOR_OP_UNDEFINED_28 1 << 28 // 268435456
#define ITERATOR_OP_UNDEFINED_29 1 << 29 // 536870912
#define ITERATOR_OP_UNDEFINED_30 1 << 30 // 1073741824
#define ITERATOR_OP_UNDEFINED_31 1 << 31 // 2147483648
#define AKGL_ITERATOR_OP_UPDATE 1 // 1
#define AKGL_ITERATOR_OP_RENDER 1 << 1 // 2
#define AKGL_ITERATOR_OP_RELEASE 1 << 2 // 4
#define AKGL_ITERATOR_OP_LAYERMASK 1 << 3 // 8
#define AKGL_ITERATOR_OP_UNDEFINED_4 1 << 4 // 16
#define AKGL_ITERATOR_OP_UNDEFINED_5 1 << 5 // 32
#define AKGL_ITERATOR_OP_UNDEFINED_6 1 << 6 // 64
#define AKGL_ITERATOR_OP_UNDEFINED_7 1 << 7 // 128
#define AKGL_ITERATOR_OP_UNDEFINED_8 1 << 8 // 256
#define AKGL_ITERATOR_OP_UNDEFINED_9 1 << 9 // 512
#define AKGL_ITERATOR_OP_UNDEFINED_10 1 << 10 // 1024
#define AKGL_ITERATOR_OP_UNDEFINED_11 1 << 11 // 2048
#define AKGL_ITERATOR_OP_UNDEFINED_12 1 << 12 // 4096
#define AKGL_ITERATOR_OP_UNDEFINED_13 1 << 13 // 8192
#define AKGL_ITERATOR_OP_UNDEFINED_14 1 << 14 // 16384
#define AKGL_ITERATOR_OP_UNDEFINED_15 1 << 15 // 32768
#define AKGL_ITERATOR_OP_UNDEFINED_16 1 << 16 // 65536
#define AKGL_ITERATOR_OP_UNDEFINED_17 1 << 17 // 131072
#define AKGL_ITERATOR_OP_UNDEFINED_18 1 << 18 // 262144
#define AKGL_ITERATOR_OP_UNDEFINED_19 1 << 19 // 524288
#define AKGL_ITERATOR_OP_UNDEFINED_20 1 << 20 // 1048576
#define AKGL_ITERATOR_OP_UNDEFINED_21 1 << 21 // 2097152
#define AKGL_ITERATOR_OP_UNDEFINED_22 1 << 22 // 4194304
#define AKGL_ITERATOR_OP_UNDEFINED_23 1 << 23 // 8388608
#define AKGL_ITERATOR_OP_UNDEFINED_24 1 << 24 // 16777216
#define AKGL_ITERATOR_OP_UNDEFINED_25 1 << 25 // 33554432
#define AKGL_ITERATOR_OP_UNDEFINED_26 1 << 26 // 67108864
#define AKGL_ITERATOR_OP_UNDEFINED_27 1 << 27 // 134217728
#define AKGL_ITERATOR_OP_UNDEFINED_28 1 << 28 // 268435456
#define AKGL_ITERATOR_OP_UNDEFINED_29 1 << 29 // 536870912
#define AKGL_ITERATOR_OP_UNDEFINED_30 1 << 30 // 1073741824
#define AKGL_ITERATOR_OP_UNDEFINED_31 1 << 31 // 2147483648
#endif // _ITERATOR_H_
#endif // _AKGL_ITERATOR_H_

View File

@@ -4,14 +4,14 @@
#include <akerror.h>
#include "staticstring.h"
akerr_ErrorContext AKERR_NOIGNORE *get_json_object_value(json_t *obj, char *key, json_t **dest);
akerr_ErrorContext AKERR_NOIGNORE *get_json_boolean_value(json_t *obj, char *key, bool *dest);
akerr_ErrorContext AKERR_NOIGNORE *get_json_integer_value(json_t *obj, char *key, int *dest);
akerr_ErrorContext AKERR_NOIGNORE *get_json_number_value(json_t *obj, char *key, float *dest);
akerr_ErrorContext AKERR_NOIGNORE *get_json_string_value(json_t *obj, char *key, string **dest);
akerr_ErrorContext AKERR_NOIGNORE *get_json_array_value(json_t *obj, char *key, json_t **dest);
akerr_ErrorContext AKERR_NOIGNORE *get_json_array_index_object(json_t *array, int index, json_t **dest);
akerr_ErrorContext AKERR_NOIGNORE *get_json_array_index_integer(json_t *array, int index, int *dest);
akerr_ErrorContext AKERR_NOIGNORE *get_json_array_index_string(json_t *array, int index, string **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_object_value(json_t *obj, char *key, json_t **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_boolean_value(json_t *obj, char *key, bool *dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_integer_value(json_t *obj, char *key, int *dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_number_value(json_t *obj, char *key, float *dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_string_value(json_t *obj, char *key, akgl_String **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_array_value(json_t *obj, char *key, json_t **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_array_index_object(json_t *array, int index, json_t **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_array_index_integer(json_t *array, int index, int *dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_array_index_string(json_t *array, int index, akgl_String **dest);
#endif // _JSON_HELPERS_H_

View File

@@ -3,22 +3,22 @@
#include "error.h"
extern SDL_PropertiesID REGISTRY_ACTOR;
extern SDL_PropertiesID REGISTRY_SPRITE;
extern SDL_PropertiesID REGISTRY_SPRITESHEET;
extern SDL_PropertiesID REGISTRY_CHARACTER;
extern SDL_PropertiesID REGISTRY_ACTOR_STATE_STRINGS;
extern SDL_PropertiesID REGISTRY_FONT;
extern SDL_PropertiesID REGISTRY_MUSIC;
extern SDL_PropertiesID AKGL_REGISTRY_ACTOR;
extern SDL_PropertiesID AKGL_REGISTRY_SPRITE;
extern SDL_PropertiesID AKGL_AKGL_REGISTRY_SPRITESHEET;
extern SDL_PropertiesID AKGL_REGISTRY_CHARACTER;
extern SDL_PropertiesID AKGL_AKGL_REGISTRY_ACTOR_STATE_STRINGS;
extern SDL_PropertiesID AKGL_REGISTRY_FONT;
extern SDL_PropertiesID AKGL_REGISTRY_MUSIC;
akerr_ErrorContext AKERR_NOIGNORE *registry_init();
akerr_ErrorContext AKERR_NOIGNORE *registry_init_music();
akerr_ErrorContext AKERR_NOIGNORE *registry_init_font();
akerr_ErrorContext AKERR_NOIGNORE *registry_init_actor();
akerr_ErrorContext AKERR_NOIGNORE *registry_init_sprite();
akerr_ErrorContext AKERR_NOIGNORE *registry_init_spritesheet();
akerr_ErrorContext AKERR_NOIGNORE *registry_init_character();
akerr_ErrorContext AKERR_NOIGNORE *registry_init_actor_state_strings();
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init();
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init_music();
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init_font();
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init_actor();
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init_sprite();
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init_spritesheet();
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init_character();
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init_actor_state_strings();
#endif //_REGISTRY_H_

View File

@@ -1,44 +1,44 @@
#ifndef _SPRITE_H_
#define _SPRITE_H_
#ifndef _AKGL_SPRITE_H_
#define _AKGL_SPRITE_H_
#include <SDL3/SDL_properties.h>
#include <SDL3/SDL.h>
#include <akerror.h>
#define SPRITE_MAX_FRAMES 16
#define SPRITE_MAX_NAME_LENGTH 128
#define SPRITE_MAX_REGISTRY_SIZE 1024
#define SPRITE_SHEET_MAX_FILENAME_LENGTH 512
#define AKGL_SPRITE_MAX_FRAMES 16
#define AKGL_SPRITE_MAX_NAME_LENGTH 128
#define AKGL_SPRITE_MAX_REGISTRY_SIZE 1024
#define AKGL_SPRITE_SHEET_MAX_FILENAME_LENGTH 512
#define MAX_HEAP_SPRITE (MAX_HEAP_ACTOR * 16)
#define MAX_HEAP_SPRITESHEET MAX_HEAP_SPRITE
#define AKGL_MAX_HEAP_SPRITE (AKGL_MAX_HEAP_ACTOR * 16)
#define AKGL_MAX_HEAP_SPRITESHEET AKGL_MAX_HEAP_SPRITE
typedef struct {
int refcount;
SDL_Texture *texture;
char name[SPRITE_SHEET_MAX_FILENAME_LENGTH];
char name[AKGL_SPRITE_SHEET_MAX_FILENAME_LENGTH];
int sprite_w;
int sprite_h;
} spritesheet;
} akgl_SpriteSheet;
typedef struct {
int refcount;
spritesheet *sheet;
int frameids[SPRITE_MAX_FRAMES]; // which IDs on the spritesheet belong to our frames
akgl_SpriteSheet *sheet;
int frameids[AKGL_SPRITE_MAX_FRAMES]; // which IDs on the spritesheet belong to our frames
int frames; // how many frames are in this animation
int width;
int height;
long int speed; // how many milliseconds a given sprite frame should be visible before cycling
bool loop; // when this sprite is done playing, it should immediately start again
bool loopReverse; // when this sprite is done playing, it should go in reverse order through its frames
char name[SPRITE_MAX_NAME_LENGTH];
} sprite;
char name[AKGL_SPRITE_MAX_NAME_LENGTH];
} akgl_Sprite;
// initializes a new sprite to use the given sheet and otherwise sets to zero
akerr_ErrorContext AKERR_NOIGNORE *sprite_initialize(sprite *spr, char *name, spritesheet *sheet);
akerr_ErrorContext AKERR_NOIGNORE *akgl_sprite_initialize(akgl_Sprite *spr, char *name, akgl_SpriteSheet *sheet);
// loads a given image file into a new spritesheet
akerr_ErrorContext AKERR_NOIGNORE *spritesheet_initialize(spritesheet *sheet, int sprite_w, int sprite_h, char *filename);
akerr_ErrorContext AKERR_NOIGNORE *sprite_load_json(char *filename);
akerr_ErrorContext AKERR_NOIGNORE *akgl_spritesheet_initialize(akgl_SpriteSheet *sheet, int sprite_w, int sprite_h, char *filename);
akerr_ErrorContext AKERR_NOIGNORE *akgl_sprite_load_json(char *filename);
#endif //_SPRITE_H_
#endif //_AKGL_SPRITE_H_

View File

@@ -4,14 +4,14 @@
#include "string.h"
#include <akerror.h>
#define MAX_STRING_LENGTH 256
#define AKGL_MAX_STRING_LENGTH 256
typedef struct
{
int refcount;
char data[MAX_STRING_LENGTH];
} string;
char data[AKGL_MAX_STRING_LENGTH];
} akgl_String;
akerr_ErrorContext AKERR_NOIGNORE *string_initialize(string *obj, char *init);
akerr_ErrorContext AKERR_NOIGNORE *akgl_string_initialize(akgl_String *obj, char *init);
#endif //_STRING_H_

View File

@@ -3,7 +3,7 @@
#include <SDL3_ttf/SDL_ttf.h>
akerr_ErrorContext AKERR_NOIGNORE *text_loadFont(char *name, char *filepath, int size);
akerr_ErrorContext AKERR_NOIGNORE *text_renderTextAt(TTF_Font *font, char *text, SDL_Color color, int wraplength, int x, int y);
akerr_ErrorContext AKERR_NOIGNORE *akgl_text_loadfont(char *name, char *filepath, int size);
akerr_ErrorContext AKERR_NOIGNORE *akgl_text_rendertextat(TTF_Font *font, char *text, SDL_Color color, int wraplength, int x, int y);
#endif // _TEXT_H_

View File

@@ -5,20 +5,20 @@
#include "staticstring.h"
#include <jansson.h>
#define TILEMAP_MAX_WIDTH 512
#define TILEMAP_MAX_HEIGHT 512
#define TILEMAP_MAX_LAYERS 16
#define TILEMAP_MAX_TILESETS 16
#define TILEMAP_MAX_TILES_PER_IMAGE 65536
#define TILEMAP_MAX_TILESET_NAME_SIZE 512
#define TILEMAP_MAX_TILESET_FILENAME_SIZE 512
#define TILEMAP_MAX_OBJECT_NAME_SIZE 512
#define TILEMAP_MAX_OBJECTS_PER_LAYER 128
#define AKGL_TILEMAP_MAX_WIDTH 512
#define AKGL_TILEMAP_MAX_HEIGHT 512
#define AKGL_TILEMAP_MAX_LAYERS 16
#define AKGL_TILEMAP_MAX_TILESETS 16
#define AKGL_TILEMAP_MAX_TILES_PER_IMAGE 65536
#define AKGL_TILEMAP_MAX_TILESET_NAME_SIZE 512
#define AKGL_TILEMAP_MAX_TILESET_FILENAME_SIZE 512
#define AKGL_TILEMAP_MAX_OBJECT_NAME_SIZE 512
#define AKGL_TILEMAP_MAX_OBJECTS_PER_LAYER 128
#define TILEMAP_OBJECT_TYPE_ACTOR 1
#define AKGL_TILEMAP_OBJECT_TYPE_ACTOR 1
#define TILEMAP_LAYER_TYPE_TILES 1
#define TILEMAP_LAYER_TYPE_OBJECTS 2
#define AKGL_TILEMAP_LAYER_TYPE_TILES 1
#define AKGL_TILEMAP_LAYER_TYPE_OBJECTS 2
typedef struct {
float x;
@@ -30,9 +30,9 @@ typedef struct {
int rotation;
int type;
bool visible;
actor *actorptr;
char name[TILEMAP_MAX_OBJECT_NAME_SIZE];
} tilemap_object;
akgl_Actor *actorptr;
char name[AKGL_TILEMAP_MAX_OBJECT_NAME_SIZE];
} akgl_TilemapObject;
typedef struct {
short type;
@@ -43,17 +43,17 @@ typedef struct {
int x;
int y;
int id;
int data[TILEMAP_MAX_WIDTH * TILEMAP_MAX_HEIGHT];
tilemap_object objects[TILEMAP_MAX_OBJECTS_PER_LAYER];
} tilemap_layer;
int data[AKGL_TILEMAP_MAX_WIDTH * AKGL_TILEMAP_MAX_HEIGHT];
akgl_TilemapObject objects[AKGL_TILEMAP_MAX_OBJECTS_PER_LAYER];
} akgl_TilemapLayer;
typedef struct {
int columns;
int firstgid;
char imagefilename[TILEMAP_MAX_TILESET_FILENAME_SIZE];
char imagefilename[AKGL_TILEMAP_MAX_TILESET_FILENAME_SIZE];
int imageheight;
int imagewidth;
char name[TILEMAP_MAX_TILESET_NAME_SIZE];
char name[AKGL_TILEMAP_MAX_TILESET_NAME_SIZE];
SDL_Texture *texture;
// Use this as a lookup table instead of storing tiles
// in individual textures to blit them from a single
@@ -64,18 +64,18 @@ typedef struct {
// and have 1728 tiles. Set B may start at firstgid 1729 and
// have 1728 more tiles. This means Set B has 1728 empty
// tile_offsets[] entries before firstgid 1729 because of the
// way tilemap_load_tilesets() works. This is really inefficient
// way akgl_tilemap_load_tilesets() works. This is really inefficient
// and should be improved in the future, and will eventually
// lead to premature exhaustion of TILEMAP_MAX_TILES_PER_IMAGE
// lead to premature exhaustion of AKGL_TILEMAP_MAX_TILES_PER_IMAGE
// because set D or E may only have 64 tiles but they may be
// at the upper end of the array bound already because of this.
int tile_offsets[TILEMAP_MAX_TILES_PER_IMAGE][2];
int tile_offsets[AKGL_TILEMAP_MAX_TILES_PER_IMAGE][2];
int tilecount;
int tileheight;
int tilewidth;
int spacing;
int margin;
} tileset;
} akgl_Tileset;
typedef struct {
int tilewidth;
@@ -85,28 +85,28 @@ typedef struct {
int numlayers;
int orientation; // 0 = orthogonal, 1 = isometric
int numtilesets;
tileset tilesets[TILEMAP_MAX_TILESETS];
tilemap_layer layers[TILEMAP_MAX_LAYERS];
} tilemap;
akgl_Tileset tilesets[AKGL_TILEMAP_MAX_TILESETS];
akgl_TilemapLayer layers[AKGL_TILEMAP_MAX_LAYERS];
} akgl_Tilemap;
akerr_ErrorContext AKERR_NOIGNORE *tilemap_load(char *fname, tilemap *dest);
akerr_ErrorContext AKERR_NOIGNORE *tilemap_draw(SDL_Renderer *renderer, tilemap *dest, SDL_FRect *viewport, int layeridx);
akerr_ErrorContext AKERR_NOIGNORE *tilemap_draw_tileset(SDL_Renderer *renderer, tilemap *dest, int tilesetidx);
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_load(char *fname, akgl_Tilemap *dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_draw(SDL_Renderer *renderer, akgl_Tilemap *dest, SDL_FRect *viewport, int layeridx);
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_draw_tileset(SDL_Renderer *renderer, akgl_Tilemap *dest, int tilesetidx);
/*
* These functions are part of the internal API and should not be called by the user.
* They are only exposed here for unit testing.
*/
akerr_ErrorContext AKERR_NOIGNORE *get_json_tilemap_property(json_t *obj, char *key, char *type, json_t **dest);
akerr_ErrorContext AKERR_NOIGNORE *get_json_properties_string(json_t *obj, char *key, string **dest);
akerr_ErrorContext AKERR_NOIGNORE *get_json_properties_integer(json_t *obj, char *key, int *dest);
akerr_ErrorContext AKERR_NOIGNORE *tilemap_compute_tileset_offsets(tilemap *dest, int tilesetidx);
akerr_ErrorContext AKERR_NOIGNORE *tilemap_load_layer_objects(tilemap *dest, json_t *root, int layerid);
akerr_ErrorContext AKERR_NOIGNORE *tilemap_load_layer_tile(tilemap *dest, json_t *root, int layerid);
akerr_ErrorContext AKERR_NOIGNORE *tilemap_load_layers(tilemap *dest, json_t *root);
akerr_ErrorContext AKERR_NOIGNORE *tilemap_load_tilesets_each(json_t *tileset, tilemap *dest, int tsidx);
akerr_ErrorContext AKERR_NOIGNORE *tilemap_load_tilesets(tilemap *dest, json_t *root);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_tilemap_property(json_t *obj, char *key, char *type, json_t **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_properties_string(json_t *obj, char *key, akgl_String **dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_properties_integer(json_t *obj, char *key, int *dest);
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_compute_tileset_offsets(akgl_Tilemap *dest, int tilesetidx);
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_load_layer_objects(akgl_Tilemap *dest, json_t *root, int layerid);
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_load_layer_tile(akgl_Tilemap *dest, json_t *root, int layerid);
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_load_layers(akgl_Tilemap *dest, json_t *root);
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_load_tilesets_each(json_t *tileset, akgl_Tilemap *dest, int tsidx);
akerr_ErrorContext AKERR_NOIGNORE *akgl_tilemap_load_tilesets(akgl_Tilemap *dest, json_t *root);
#endif //_TILEMAP_H_

View File

@@ -16,14 +16,14 @@ typedef struct RectanglePoints {
point bottomright;
} RectanglePoints;
#define COLLIDE_RECTANGLES(r1x, r1y, r1w, r1h, r2x, r2y, r2w, r2h) ((r1x < (r2x + r2w)) || ((r1x + r1w) > r2x)
#define AKGL_COLLIDE_RECTANGLES(r1x, r1y, r1w, r1h, r2x, r2y, r2w, r2h) ((r1x < (r2x + r2w)) || ((r1x + r1w) > r2x)
akerr_ErrorContext AKERR_NOIGNORE *rectangle_points(RectanglePoints *dest, SDL_FRect *rect);
akerr_ErrorContext AKERR_NOIGNORE *collide_point_rectangle(point *p, RectanglePoints *r, bool *collide);
akerr_ErrorContext AKERR_NOIGNORE *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide);
akerr_ErrorContext AKERR_NOIGNORE *akgl_rectangle_points(RectanglePoints *dest, SDL_FRect *rect);
akerr_ErrorContext AKERR_NOIGNORE *akgl_collide_point_rectangle(point *p, RectanglePoints *r, bool *collide);
akerr_ErrorContext AKERR_NOIGNORE *akgl_collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide);
// These are REALLY slow routines that are only useful in testing harnesses
akerr_ErrorContext AKERR_NOIGNORE *compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2);
akerr_ErrorContext AKERR_NOIGNORE *render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y, int w, int h, char *writeout);
akerr_ErrorContext AKERR_NOIGNORE *akgl_compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2);
akerr_ErrorContext AKERR_NOIGNORE *akgl_render_and_compare(SDL_Texture *t1, SDL_Texture *t2, int x, int y, int w, int h, char *writeout);
#endif // _UTIL_H_