Rename library to AKGL (AKLabs Game Library)
This commit is contained in:
2235
include/akgl/SDL_GameControllerDB.h
Normal file
2235
include/akgl/SDL_GameControllerDB.h
Normal file
File diff suppressed because it is too large
Load Diff
104
include/akgl/actor.h
Normal file
104
include/akgl/actor.h
Normal file
@@ -0,0 +1,104 @@
|
||||
#ifndef _AKGL_ACTOR_H_
|
||||
#define _AKGL_ACTOR_H_
|
||||
|
||||
#include "character.h"
|
||||
|
||||
// ---- LOW WORD STATUSES ----
|
||||
|
||||
#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 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 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 *AKGL_ACTOR_STATE_STRING_NAMES[AKGL_ACTOR_MAX_STATES+1];
|
||||
|
||||
#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 AKGL_ACTOR_MAX_NAME_LENGTH 128
|
||||
#define AKGL_ACTOR_MAX_CHILDREN 8
|
||||
|
||||
#define AKGL_MAX_HEAP_ACTOR 64
|
||||
|
||||
typedef struct akgl_Actor {
|
||||
int refcount;
|
||||
char name[AKGL_ACTOR_MAX_NAME_LENGTH];
|
||||
akgl_Character *basechar;
|
||||
int curSpriteFrameId;
|
||||
SDL_Time curSpriteFrameTimer;
|
||||
bool curSpriteReversing;
|
||||
int layer;
|
||||
int state;
|
||||
bool movement_controls_face;
|
||||
void *actorData;
|
||||
bool visible;
|
||||
SDL_Time logictimer;
|
||||
float x;
|
||||
float y;
|
||||
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 *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 *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);
|
||||
|
||||
#endif // _AKGL_ACTOR_H_
|
||||
8
include/akgl/assets.h
Normal file
8
include/akgl/assets.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef _ASSETS_H_
|
||||
#define _ASSETS_H_
|
||||
|
||||
#include <akerror.h>
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_load_start_bgm(char *fname);
|
||||
|
||||
#endif //_ASSETS_H_
|
||||
31
include/akgl/character.h
Normal file
31
include/akgl/character.h
Normal file
@@ -0,0 +1,31 @@
|
||||
#ifndef _AKGL_CHARACTER_H_
|
||||
#define _AKGL_CHARACTER_H_
|
||||
|
||||
#include <SDL3/SDL_properties.h>
|
||||
#include "sprite.h"
|
||||
|
||||
#define AKGL_SPRITE_MAX_CHARACTER_NAME_LENGTH 128
|
||||
#define AKGL_MAX_HEAP_CHARACTER 256
|
||||
|
||||
typedef struct akgl_Character {
|
||||
int refcount;
|
||||
char name[AKGL_SPRITE_MAX_CHARACTER_NAME_LENGTH];
|
||||
SDL_PropertiesID state_sprites;
|
||||
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;
|
||||
} akgl_Character;
|
||||
|
||||
|
||||
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 akgl_character_state_sprites_iterate(void *userdata, SDL_PropertiesID props, const char *name);
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_character_load_json(char *filename);
|
||||
|
||||
#endif // _AKGL_CHARACTER_H_
|
||||
44
include/akgl/controller.h
Normal file
44
include/akgl/controller.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef _CONTROLLER_H_
|
||||
#define _CONTROLLER_H_
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <akerror.h>
|
||||
|
||||
#define AKGL_MAX_CONTROL_MAPS 8
|
||||
#define AKGL_MAX_CONTROLS 32
|
||||
|
||||
typedef struct {
|
||||
Uint32 event_on;
|
||||
Uint32 event_off;
|
||||
Uint8 button;
|
||||
SDL_Keycode key;
|
||||
Uint8 axis;
|
||||
Uint8 axis_range_min;
|
||||
Uint8 axis_range_max;
|
||||
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 {
|
||||
akgl_Actor *target;
|
||||
int nextMap;
|
||||
akgl_Control controls[AKGL_MAX_CONTROLS];
|
||||
SDL_KeyboardID kbid;
|
||||
SDL_JoystickID jsid;
|
||||
SDL_MouseID mouseid;
|
||||
SDL_PenID penid;
|
||||
} akgl_ControlMap;
|
||||
|
||||
extern akgl_ControlMap GAME_ControlMaps[AKGL_MAX_CONTROL_MAPS];
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_handle_event(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 *akgl_controller_pushmap(int controlmapid, akgl_Control *control);
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_controller_default(int controlmapid, char *actorname, int kbid, int jsid);
|
||||
#endif // _CONTROLLER_H_
|
||||
6
include/akgl/draw.h
Normal file
6
include/akgl/draw.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _DRAW_H_
|
||||
#define _DRAW_H_
|
||||
|
||||
void akgl_draw_background(int w, int h);
|
||||
|
||||
#endif //_DRAW_H_
|
||||
6
include/akgl/error.h
Normal file
6
include/akgl/error.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef _ERROR_H_
|
||||
#define _ERROR_H_
|
||||
|
||||
#define AKGL_ERR_SDL AKERR_LAST_ERRNO_VALUE + 1
|
||||
|
||||
#endif // _ERROR_H_
|
||||
57
include/akgl/game.h
Normal file
57
include/akgl/game.h
Normal file
@@ -0,0 +1,57 @@
|
||||
#ifndef _AKGL_GAME_H_
|
||||
#define _AKGL_GAME_H_
|
||||
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
#include "tilemap.h"
|
||||
|
||||
#define AKGL_GAME_AUDIO_TRACK_BGM 1
|
||||
#define AKGL_GAME_AUDIO_MAX_TRACKS 64
|
||||
|
||||
#define AKGL_TIME_ONESEC_NS 1000000000
|
||||
#define AKGL_TIME_ONESEC_MS 1000000
|
||||
|
||||
/* ==================== GAME STATE VARIABLES =================== */
|
||||
|
||||
typedef struct {
|
||||
float w;
|
||||
float h;
|
||||
SDL_Texture *texture;
|
||||
} akgl_Frame;
|
||||
|
||||
typedef struct {
|
||||
int flags;
|
||||
} akgl_GameState;
|
||||
|
||||
typedef struct {
|
||||
char name[256];
|
||||
char version[32];
|
||||
char uri[256];
|
||||
int screenwidth;
|
||||
int screenheight;
|
||||
akgl_GameState state;
|
||||
int fps;
|
||||
SDL_Time gameStartTime;
|
||||
SDL_Time lastIterTime;
|
||||
SDL_Time lastFPSTime;
|
||||
int framesSinceUpdate;
|
||||
MIX_Mixer *mixer;
|
||||
MIX_Track *tracks[AKGL_GAME_AUDIO_MAX_TRACKS];
|
||||
} akgl_Game;
|
||||
|
||||
|
||||
extern SDL_Window *window;
|
||||
extern SDL_Renderer *renderer;
|
||||
extern akgl_Tilemap gamemap;
|
||||
extern MIX_Audio *bgm;
|
||||
extern SDL_FRect camera;
|
||||
extern akgl_Game game;
|
||||
|
||||
#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 *akgl_game_init();
|
||||
void akgl_game_updateFPS();
|
||||
|
||||
#endif //_AKGL_GAME_H_
|
||||
35
include/akgl/heap.h
Normal file
35
include/akgl/heap.h
Normal file
@@ -0,0 +1,35 @@
|
||||
#ifndef _AKGL_HEAP_H_
|
||||
#define _AKGL_HEAP_H_
|
||||
|
||||
#include "sprite.h"
|
||||
#include "actor.h"
|
||||
#include "character.h"
|
||||
#include "staticstring.h"
|
||||
#include <akerror.h>
|
||||
|
||||
#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 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 *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 *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 //_AKGL_HEAP_H_
|
||||
43
include/akgl/iterator.h
Normal file
43
include/akgl/iterator.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef _AKGL_ITERATOR_H_
|
||||
#define _AKGL_ITERATOR_H_
|
||||
|
||||
typedef struct {
|
||||
int flags;
|
||||
int layerid;
|
||||
} akgl_Iterator;
|
||||
|
||||
#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 // _AKGL_ITERATOR_H_
|
||||
17
include/akgl/json_helpers.h
Normal file
17
include/akgl/json_helpers.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef _JSON_HELPERS_H_
|
||||
#define _JSON_HELPERS_H_
|
||||
|
||||
#include <akerror.h>
|
||||
#include "staticstring.h"
|
||||
|
||||
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_
|
||||
24
include/akgl/registry.h
Normal file
24
include/akgl/registry.h
Normal file
@@ -0,0 +1,24 @@
|
||||
#ifndef _REGISTRY_H_
|
||||
#define _REGISTRY_H_
|
||||
|
||||
#include "error.h"
|
||||
|
||||
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 *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_
|
||||
44
include/akgl/sprite.h
Normal file
44
include/akgl/sprite.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef _AKGL_SPRITE_H_
|
||||
#define _AKGL_SPRITE_H_
|
||||
|
||||
#include <SDL3/SDL_properties.h>
|
||||
#include <SDL3/SDL.h>
|
||||
#include <akerror.h>
|
||||
|
||||
|
||||
#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 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[AKGL_SPRITE_SHEET_MAX_FILENAME_LENGTH];
|
||||
int sprite_w;
|
||||
int sprite_h;
|
||||
} akgl_SpriteSheet;
|
||||
|
||||
typedef struct {
|
||||
int refcount;
|
||||
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[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 *akgl_sprite_initialize(akgl_Sprite *spr, char *name, akgl_SpriteSheet *sheet);
|
||||
// loads a given image file into a new spritesheet
|
||||
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 //_AKGL_SPRITE_H_
|
||||
17
include/akgl/staticstring.h
Normal file
17
include/akgl/staticstring.h
Normal file
@@ -0,0 +1,17 @@
|
||||
#ifndef _STRING_H_
|
||||
#define _STRING_H_
|
||||
|
||||
#include "string.h"
|
||||
#include <akerror.h>
|
||||
|
||||
#define AKGL_MAX_STRING_LENGTH 256
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int refcount;
|
||||
char data[AKGL_MAX_STRING_LENGTH];
|
||||
} akgl_String;
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_string_initialize(akgl_String *obj, char *init);
|
||||
|
||||
#endif //_STRING_H_
|
||||
9
include/akgl/text.h
Normal file
9
include/akgl/text.h
Normal file
@@ -0,0 +1,9 @@
|
||||
#ifndef _TEXT_H_
|
||||
#define _TEXT_H_
|
||||
|
||||
#include <SDL3_ttf/SDL_ttf.h>
|
||||
|
||||
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_
|
||||
112
include/akgl/tilemap.h
Normal file
112
include/akgl/tilemap.h
Normal file
@@ -0,0 +1,112 @@
|
||||
#ifndef _TILEMAP_H_
|
||||
#define _TILEMAP_H_
|
||||
|
||||
#include "actor.h"
|
||||
#include "staticstring.h"
|
||||
#include <jansson.h>
|
||||
|
||||
#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 AKGL_TILEMAP_OBJECT_TYPE_ACTOR 1
|
||||
|
||||
#define AKGL_TILEMAP_LAYER_TYPE_TILES 1
|
||||
#define AKGL_TILEMAP_LAYER_TYPE_OBJECTS 2
|
||||
|
||||
typedef struct {
|
||||
float x;
|
||||
float y;
|
||||
int gid;
|
||||
int id;
|
||||
int height;
|
||||
int width;
|
||||
int rotation;
|
||||
int type;
|
||||
bool visible;
|
||||
akgl_Actor *actorptr;
|
||||
char name[AKGL_TILEMAP_MAX_OBJECT_NAME_SIZE];
|
||||
} akgl_TilemapObject;
|
||||
|
||||
typedef struct {
|
||||
short type;
|
||||
float opacity;
|
||||
bool visible;
|
||||
int height;
|
||||
int width;
|
||||
int x;
|
||||
int y;
|
||||
int id;
|
||||
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[AKGL_TILEMAP_MAX_TILESET_FILENAME_SIZE];
|
||||
int imageheight;
|
||||
int imagewidth;
|
||||
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
|
||||
// texture at runtime
|
||||
// FIXME: This is probably not very efficient. For a map
|
||||
// with a single tileset it makes sense. For a map with
|
||||
// multiple tilesets you may have set A start at firstgid 1
|
||||
// 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 akgl_tilemap_load_tilesets() works. This is really inefficient
|
||||
// and should be improved in the future, and will eventually
|
||||
// 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[AKGL_TILEMAP_MAX_TILES_PER_IMAGE][2];
|
||||
int tilecount;
|
||||
int tileheight;
|
||||
int tilewidth;
|
||||
int spacing;
|
||||
int margin;
|
||||
} akgl_Tileset;
|
||||
|
||||
typedef struct {
|
||||
int tilewidth;
|
||||
int tileheight;
|
||||
int width;
|
||||
int height;
|
||||
int numlayers;
|
||||
int orientation; // 0 = orthogonal, 1 = isometric
|
||||
int numtilesets;
|
||||
akgl_Tileset tilesets[AKGL_TILEMAP_MAX_TILESETS];
|
||||
akgl_TilemapLayer layers[AKGL_TILEMAP_MAX_LAYERS];
|
||||
} akgl_Tilemap;
|
||||
|
||||
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 *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_
|
||||
29
include/akgl/util.h
Normal file
29
include/akgl/util.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
|
||||
#include <akerror.h>
|
||||
|
||||
typedef struct point {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
} point;
|
||||
|
||||
typedef struct RectanglePoints {
|
||||
point topleft;
|
||||
point topright;
|
||||
point bottomleft;
|
||||
point bottomright;
|
||||
} RectanglePoints;
|
||||
|
||||
#define AKGL_COLLIDE_RECTANGLES(r1x, r1y, r1w, r1h, r2x, r2y, r2w, r2h) ((r1x < (r2x + r2w)) || ((r1x + r1w) > r2x)
|
||||
|
||||
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 *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_
|
||||
Reference in New Issue
Block a user