Extract the error library out into libsdlerror, extract the game library out into libsdl3game, link against them
This commit is contained in:
@@ -1,92 +0,0 @@
|
||||
#ifndef _ACTOR_H_
|
||||
#define _ACTOR_H_
|
||||
|
||||
#include "character.h"
|
||||
|
||||
#define ACTOR_STATE_FACE_DOWN 1 << 0 // 1
|
||||
#define ACTOR_STATE_FACE_LEFT 1 << 1 // 2
|
||||
#define ACTOR_STATE_FACE_RIGHT 1 << 2 // 4
|
||||
#define ACTOR_STATE_FACE_UP 1 << 3 // 8
|
||||
#define ACTOR_STATE_ALIVE 1 << 4 // 16
|
||||
#define ACTOR_STATE_DYING 1 << 5 // 32
|
||||
#define ACTOR_STATE_DEAD 1 << 6 // 64
|
||||
#define ACTOR_STATE_MOVING_LEFT 1 << 7 // 128
|
||||
#define ACTOR_STATE_MOVING_RIGHT 1 << 8 // 256
|
||||
#define ACTOR_STATE_MOVING_UP 1 << 9 // 512
|
||||
#define ACTOR_STATE_MOVING_DOWN 1 << 10 // 1024
|
||||
#define ACTOR_STATE_UNDEFINED_11 1 << 11 // 2048
|
||||
#define ACTOR_STATE_UNDEFINED_12 1 << 12 // 4096
|
||||
#define ACTOR_STATE_UNDEFINED_13 1 << 13 // 8192
|
||||
#define ACTOR_STATE_UNDEFINED_14 1 << 14 // 16384
|
||||
#define ACTOR_STATE_UNDEFINED_15 1 << 15 // 32768
|
||||
#define ACTOR_STATE_UNDEFINED_16 1 << 16 // 65536
|
||||
#define ACTOR_STATE_UNDEFINED_17 1 << 17 // 131072
|
||||
#define ACTOR_STATE_UNDEFINED_18 1 << 18 // 262144
|
||||
#define ACTOR_STATE_UNDEFINED_19 1 << 19 // 524288
|
||||
#define ACTOR_STATE_UNDEFINED_20 1 << 20 // 1048576
|
||||
#define ACTOR_STATE_UNDEFINED_21 1 << 21 // 2097152
|
||||
#define ACTOR_STATE_UNDEFINED_22 1 << 22 // 4194304
|
||||
#define ACTOR_STATE_UNDEFINED_23 1 << 23 // 8388608
|
||||
#define ACTOR_STATE_UNDEFINED_24 1 << 24 // 16777216
|
||||
#define ACTOR_STATE_UNDEFINED_25 1 << 25 // 33554432
|
||||
#define ACTOR_STATE_UNDEFINED_26 1 << 26 // 67108864
|
||||
#define ACTOR_STATE_UNDEFINED_27 1 << 27 // 134217728
|
||||
#define ACTOR_STATE_UNDEFINED_28 1 << 28 // 268435456
|
||||
#define ACTOR_STATE_UNDEFINED_29 1 << 29 // 536870912
|
||||
#define ACTOR_STATE_UNDEFINED_30 1 << 30 // 1073741824
|
||||
#define ACTOR_STATE_UNDEFINED_31 1 << 31 // 2147483648
|
||||
|
||||
#define 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];
|
||||
|
||||
#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 ACTOR_MAX_NAME_LENGTH 128
|
||||
#define ACTOR_MAX_CHILDREN 8
|
||||
|
||||
#define MAX_HEAP_ACTOR 64
|
||||
|
||||
typedef struct actor {
|
||||
int refcount;
|
||||
char name[ACTOR_MAX_NAME_LENGTH];
|
||||
character *basechar;
|
||||
int curSpriteFrameId;
|
||||
SDL_Time curSpriteFrameTimer;
|
||||
bool curSpriteReversing;
|
||||
int layer;
|
||||
b2BodyId physicsId;
|
||||
b2Polygon physicsBox;
|
||||
int state;
|
||||
bool movement_controls_face;
|
||||
void *actorData;
|
||||
bool visible;
|
||||
int logictimer;
|
||||
float x;
|
||||
float y;
|
||||
struct actor *children[ACTOR_MAX_CHILDREN];
|
||||
struct actor *parent;
|
||||
ErrorContext ERROR_NOIGNORE *(*updatefunc)(struct actor *obj);
|
||||
ErrorContext ERROR_NOIGNORE *(*renderfunc)(struct actor *obj, SDL_Renderer *renderer);
|
||||
ErrorContext ERROR_NOIGNORE *(*facefunc)(struct actor *obj);
|
||||
ErrorContext ERROR_NOIGNORE *(*movementlogicfunc)(struct actor *obj, SDL_Time curtimems);
|
||||
ErrorContext ERROR_NOIGNORE *(*changeframefunc)(struct actor *obj, sprite *curSprite, SDL_Time curtimems);
|
||||
ErrorContext ERROR_NOIGNORE *(*addchild)(struct actor *obj, struct actor *child);
|
||||
} actor;
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *actor_initialize(actor *obj, char *name);
|
||||
ErrorContext ERROR_NOIGNORE *actor_set_character(actor *obj, char *basecharname);
|
||||
ErrorContext ERROR_NOIGNORE *actor_render(actor *obj, SDL_Renderer *renderer);
|
||||
ErrorContext ERROR_NOIGNORE *actor_update(actor *obj);
|
||||
ErrorContext ERROR_NOIGNORE *actor_logic_movement(actor *obj, SDL_Time curtimems);
|
||||
ErrorContext ERROR_NOIGNORE *actor_logic_changeframe(actor *obj, sprite *curSprite, SDL_Time curtimems);
|
||||
ErrorContext ERROR_NOIGNORE *actor_automatic_face(actor *obj);
|
||||
ErrorContext ERROR_NOIGNORE *actor_add_child(actor *obj, actor *child);
|
||||
|
||||
void registry_iterate_actor(void *userdata, SDL_PropertiesID registry, const char *name);
|
||||
|
||||
#endif // _ACTOR_H_
|
||||
@@ -1,8 +0,0 @@
|
||||
#ifndef _ASSETS_H_
|
||||
#define _ASSETS_H_
|
||||
|
||||
#include "error.h"
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *load_start_bgm(char *fname);
|
||||
|
||||
#endif //_ASSETS_H_
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef _CHARACTER_H_
|
||||
#define _CHARACTER_H_
|
||||
|
||||
#include <SDL3/SDL_properties.h>
|
||||
#include "sprite.h"
|
||||
|
||||
#define SPRITE_MAX_CHARACTER_NAME_LENGTH 128
|
||||
#define MAX_HEAP_CHARACTER 256
|
||||
|
||||
typedef struct character {
|
||||
int refcount;
|
||||
char name[SPRITE_MAX_CHARACTER_NAME_LENGTH];
|
||||
SDL_PropertiesID state_sprites;
|
||||
ErrorContext ERROR_NOIGNORE *(*sprite_add)(struct character *, sprite *, int);
|
||||
ErrorContext ERROR_NOIGNORE *(*sprite_get)(struct character *, int, sprite **);
|
||||
int movementspeed;
|
||||
float vx;
|
||||
float vy;
|
||||
} character;
|
||||
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *character_initialize(character *basechar, char *name);
|
||||
ErrorContext ERROR_NOIGNORE *character_sprite_add(character *basechar, sprite *ref, int state);
|
||||
ErrorContext ERROR_NOIGNORE *character_sprite_get(character *basechar, int state, 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);
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *character_load_json(char *filename);
|
||||
|
||||
#endif // _CHARACTER_H_
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef _DRAW_H_
|
||||
#define _DRAW_H_
|
||||
|
||||
void GAME_draw_background(int w, int h);
|
||||
|
||||
#endif //_DRAW_H_
|
||||
238
include/error.h
238
include/error.h
@@ -1,238 +0,0 @@
|
||||
#ifndef _ERROR_H_
|
||||
#define _ERROR_H_
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define MAX_ERROR_CONTEXT_STRING_LENGTH 1024
|
||||
#define MAX_ERROR_FNAME_LENGTH 256
|
||||
#define MAX_ERROR_FUNCTION_LENGTH 128
|
||||
#define MAX_ERROR_STACKTRACE_BUF_LENGTH 2048
|
||||
|
||||
#define ERR_NULLPOINTER 1
|
||||
#define ERR_OUTOFBOUNDS 2
|
||||
#define ERR_SDL 3
|
||||
#define ERR_ATTRIBUTE 4
|
||||
#define ERR_TYPE 5
|
||||
#define ERR_KEY 6
|
||||
#define ERR_HEAP 7
|
||||
#define ERR_INDEX 8
|
||||
#define ERR_FORMAT 9
|
||||
#define ERR_IO 10
|
||||
#define ERR_REGISTRY 11
|
||||
#define ERR_VALUE 12
|
||||
#define ERR_BEHAVIOR 13
|
||||
#define ERR_RELATIONSHIP 14
|
||||
|
||||
extern char *__ERROR_NAMES[];
|
||||
|
||||
#define MAX_HEAP_ERROR 128
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char message[MAX_ERROR_CONTEXT_STRING_LENGTH];
|
||||
int heapid;
|
||||
int status;
|
||||
bool handled;
|
||||
int refcount;
|
||||
char fname[MAX_ERROR_FNAME_LENGTH];
|
||||
char function[MAX_ERROR_FNAME_LENGTH];
|
||||
int lineno;
|
||||
bool reported;
|
||||
char stacktracebuf[MAX_ERROR_STACKTRACE_BUF_LENGTH];
|
||||
char *stacktracebufptr;
|
||||
} ErrorContext;
|
||||
|
||||
#define ERROR_NOIGNORE __attribute__((warn_unused_result))
|
||||
|
||||
typedef void (*ErrorUnhandledErrorHandler)(ErrorContext *errctx);
|
||||
|
||||
extern ErrorContext HEAP_ERROR[MAX_HEAP_ERROR];
|
||||
extern ErrorUnhandledErrorHandler error_handler_unhandled_error;
|
||||
extern ErrorContext *__error_last_ignored;
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *heap_release_error(ErrorContext *ptr);
|
||||
ErrorContext ERROR_NOIGNORE *heap_next_error();
|
||||
char *error_name_for_status(int status);
|
||||
void error_init();
|
||||
void error_default_handler_unhandled_error(ErrorContext *ptr);
|
||||
|
||||
#define LOG_ERROR_WITH_MESSAGE(__err_context, __err_message) \
|
||||
SDL_Log("%s%s:%s:%d: %s %d (%s): %s", (char *)&__err_context->stacktracebuf, (char *)__FILE__, (char *)__func__, __LINE__, __err_message, __err_context->status, error_name_for_status(__err_context->status), __err_context->message); \
|
||||
|
||||
#define LOG_ERROR(__err_context) \
|
||||
LOG_ERROR_WITH_MESSAGE(__err_context, "");
|
||||
|
||||
#define RELEASE_ERROR(__err_context) \
|
||||
if ( __err_context != NULL ) { \
|
||||
__err_context = heap_release_error(__err_context); \
|
||||
}
|
||||
|
||||
#define PREPARE_ERROR(__err_context) \
|
||||
error_init(); \
|
||||
ErrorContext __attribute__ ((unused)) *__err_context = NULL;
|
||||
|
||||
#define ENSURE_ERROR_READY(__err_context) \
|
||||
if ( __err_context == NULL ) { \
|
||||
__err_context = heap_next_error(); \
|
||||
if ( __err_context == NULL ) { \
|
||||
SDL_Log("%s:%s:%d: Unable to pull an ErrorContext from the heap!", __FILE__, (char *)__func__, __LINE__); \
|
||||
exit(1); \
|
||||
} \
|
||||
} \
|
||||
__err_context->refcount += 1;
|
||||
|
||||
/*
|
||||
* Failure and success methods for functions that return ErrorContext *
|
||||
*/
|
||||
|
||||
#define FAIL_ZERO_RETURN(__err_context, __x, __err, __message, ...) \
|
||||
if ( __x == 0 ) { \
|
||||
FAIL(__err_context, __err, __message, ##__VA_ARGS__); \
|
||||
return __err_context; \
|
||||
}
|
||||
|
||||
#define FAIL_NONZERO_RETURN(__err_context, __x, __err, __message, ...) \
|
||||
if ( __x != 0 ) { \
|
||||
FAIL(__err_context, __err, __message, ##__VA_ARGS__); \
|
||||
return __err_context; \
|
||||
}
|
||||
|
||||
#define FAIL_RETURN(__err_context, __err, __message, ...) \
|
||||
FAIL(__err_context, __err, __message, ##__VA_ARGS__); \
|
||||
return __err_context;
|
||||
|
||||
#define SUCCEED_RETURN(__err_context) \
|
||||
RELEASE_ERROR(__err_context); \
|
||||
return NULL;
|
||||
|
||||
/*
|
||||
* Failure and success methods for use inside of ATTEMPT() blocks
|
||||
*/
|
||||
|
||||
#define FAIL_ZERO_BREAK(__err_context, __x, __err, __message, ...) \
|
||||
if ( __x == 0 ) { \
|
||||
FAIL(__err_context, __err, __message, ##__VA_ARGS__); \
|
||||
break; \
|
||||
}
|
||||
|
||||
#define FAIL_NONZERO_BREAK(__err_context, __x, __err, __message, ...) \
|
||||
if ( __x != 0 ) { \
|
||||
FAIL(__err_context, __err, __message, ##__VA_ARGS__); \
|
||||
break; \
|
||||
}
|
||||
|
||||
#define FAIL_BREAK(__err_context, __err_, __message, ...) \
|
||||
FAIL(__err_context, __err_, __message, ##__VA_ARGS__); \
|
||||
break;
|
||||
|
||||
#define SUCCEED_BREAK(__err_context) \
|
||||
SUCCEED(__err_context); \
|
||||
break;
|
||||
|
||||
/*
|
||||
* General failure and success methods
|
||||
*/
|
||||
|
||||
#define FAIL(__err_context, __err, __message, ...) \
|
||||
ENSURE_ERROR_READY(__err_context); \
|
||||
__err_context->status = __err; \
|
||||
snprintf((char *)__err_context->fname, MAX_ERROR_FNAME_LENGTH, __FILE__); \
|
||||
snprintf((char *)__err_context->function, MAX_ERROR_FUNCTION_LENGTH, __func__); \
|
||||
__err_context->lineno = __LINE__; \
|
||||
snprintf((char *)__err_context->message, MAX_ERROR_CONTEXT_STRING_LENGTH, __message, ## __VA_ARGS__); \
|
||||
__err_context->stacktracebufptr += sprintf(__err_context->stacktracebufptr, "%s:%s:%d: %d (%s) : %s\n", (char *)__err_context->fname, (char *)__err_context->function, __err_context->lineno, __err_context->status, error_name_for_status(__err_context->status), __err_context->message);
|
||||
|
||||
|
||||
#define SUCCEED(__err_context) \
|
||||
ENSURE_ERROR_READY(__err_context); \
|
||||
__err_context->status = 0;
|
||||
|
||||
/*
|
||||
* Defines for the ATTEMPT/CATCH/CLEANUP/PROCESS/HANDLE/FINISH process
|
||||
*/
|
||||
|
||||
#define ATTEMPT \
|
||||
switch ( 0 ) { \
|
||||
case 0: \
|
||||
|
||||
#define DETECT(__err_context, __stmt) \
|
||||
__stmt; \
|
||||
if ( __err_context != NULL ) { \
|
||||
__err_context->stacktracebufptr += sprintf(__err_context->stacktracebufptr, "%s:%s:%d: Detected error %d from heap (refcount %d)\n", (char *)__FILE__, (char *)__func__, __LINE__, __err_context->heapid, __err_context->refcount); \
|
||||
if ( __err_context->status != 0 ) { \
|
||||
__err_context->stacktracebufptr += sprintf(__err_context->stacktracebufptr, "%s:%s:%d\n", (char *)__FILE__, (char *)__func__, __LINE__); \
|
||||
break; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define CATCH(__err_context, __stmt) \
|
||||
DETECT(__err_context, __err_context = __stmt);
|
||||
|
||||
#define IGNORE(__stmt) \
|
||||
__error_last_ignored = __stmt; \
|
||||
if ( __error_last_ignored != NULL ) { \
|
||||
LOG_ERROR_WITH_MESSAGE(__error_last_ignored, "** IGNORED ERROR **"); \
|
||||
}
|
||||
|
||||
#define CLEANUP \
|
||||
};
|
||||
|
||||
#define PROCESS(__err_context) \
|
||||
if ( __err_context != NULL ) { \
|
||||
switch ( __err_context->status ) { \
|
||||
case 0: \
|
||||
__err_context->handled = true;
|
||||
|
||||
#define HANDLE(__err_context, __err_status) \
|
||||
break; \
|
||||
case __err_status: \
|
||||
__err_context->stacktracebufptr = (char *)&__err_context->stacktracebuf; \
|
||||
__err_context->handled = true;
|
||||
|
||||
#define HANDLE_GROUP(__err_context, __err_status) \
|
||||
case __err_status: \
|
||||
__err_context->stacktracebufptr = (char *)&__err_context->stacktracebuf; \
|
||||
__err_context->handled = true;
|
||||
|
||||
#define HANDLE_DEFAULT(__err_context) \
|
||||
break; \
|
||||
default: \
|
||||
__err_context->stacktracebufptr = (char *)&__err_context->stacktracebuf; \
|
||||
__err_context->handled = true;
|
||||
|
||||
#define FINISH(__err_context, __pass_up) \
|
||||
}; \
|
||||
}; \
|
||||
if ( __err_context != NULL ) { \
|
||||
if ( __err_context->handled == false && __pass_up == true ) { \
|
||||
__err_context->stacktracebufptr += sprintf(__err_context->stacktracebufptr, "%s:%s:%d\n", (char *)__FILE__, (char *)__func__, __LINE__); \
|
||||
return __err_context; \
|
||||
} \
|
||||
} \
|
||||
RELEASE_ERROR(__err_context);
|
||||
|
||||
#define FINISH_NORETURN(__err_context) \
|
||||
}; \
|
||||
}; \
|
||||
if ( __err_context != NULL ) { \
|
||||
if ( __err_context->handled == false ) { \
|
||||
LOG_ERROR_WITH_MESSAGE(__err_context, "Unhandled Error"); \
|
||||
error_handler_unhandled_error(__err_context); \
|
||||
} \
|
||||
} \
|
||||
RELEASE_ERROR(__err_context);
|
||||
|
||||
#define CATCH_AND_RETURN(__err_context, __stmt) \
|
||||
ATTEMPT { \
|
||||
CATCH(__err_context, __stmt); \
|
||||
} CLEANUP { \
|
||||
} PROCESS(__err_context) { \
|
||||
} FINISH(__err_context, true);
|
||||
|
||||
|
||||
#endif // _ERROR_H_
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef _GAME_H_
|
||||
#define _GAME_H_
|
||||
|
||||
#include <SDL3_mixer/SDL_mixer.h>
|
||||
#include "tilemap.h"
|
||||
|
||||
/* ==================== GAME STATE VARIABLES =================== */
|
||||
|
||||
typedef struct {
|
||||
float w;
|
||||
float h;
|
||||
SDL_Texture *texture;
|
||||
} GAME_frame;
|
||||
|
||||
typedef struct {
|
||||
int flags;
|
||||
} GameState;
|
||||
|
||||
extern SDL_Window *window;
|
||||
extern SDL_Renderer *renderer;
|
||||
extern GAME_frame ball;
|
||||
extern GAME_frame paddle1;
|
||||
extern GAME_frame paddle2;
|
||||
extern GAME_frame table;
|
||||
extern tilemap gamemap;
|
||||
extern Mix_Music *bgm;
|
||||
extern SDL_FRect camera;
|
||||
extern GameState gamestate;
|
||||
|
||||
#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;
|
||||
|
||||
#endif //_GAME_H_
|
||||
@@ -1,12 +0,0 @@
|
||||
#ifndef _GAMEPAD_H_
|
||||
#define _GAMEPAD_H_
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
#include "error.h"
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *gamepad_handle_button_down(void *appstate, SDL_Event *event);
|
||||
ErrorContext ERROR_NOIGNORE *gamepad_handle_button_up(void *appstate, SDL_Event *event);
|
||||
ErrorContext ERROR_NOIGNORE *gamepad_handle_added(void *appstate, SDL_Event *event);
|
||||
ErrorContext ERROR_NOIGNORE *gamepad_handle_removed(void *appstate, SDL_Event *event);
|
||||
|
||||
#endif // _GAMEPAD_H_
|
||||
@@ -1,35 +0,0 @@
|
||||
#ifndef _HEAP_H_
|
||||
#define _HEAP_H_
|
||||
|
||||
#include "sprite.h"
|
||||
#include "actor.h"
|
||||
#include "character.h"
|
||||
#include "staticstring.h"
|
||||
#include "error.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
|
||||
|
||||
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];
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *heap_init();
|
||||
ErrorContext ERROR_NOIGNORE *heap_next_actor(actor **dest);
|
||||
ErrorContext ERROR_NOIGNORE *heap_next_sprite(sprite **dest);
|
||||
ErrorContext ERROR_NOIGNORE *heap_next_spritesheet(spritesheet **dest);
|
||||
ErrorContext ERROR_NOIGNORE *heap_next_character(character **dest);
|
||||
ErrorContext ERROR_NOIGNORE *heap_next_string(string **dest);
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *heap_release_actor(actor *ptr);
|
||||
ErrorContext ERROR_NOIGNORE *heap_release_sprite(sprite *ptr);
|
||||
ErrorContext ERROR_NOIGNORE *heap_release_spritesheet(spritesheet *ptr);
|
||||
ErrorContext ERROR_NOIGNORE *heap_release_character(character *ptr);
|
||||
ErrorContext ERROR_NOIGNORE *heap_release_string(string *ptr);
|
||||
|
||||
#endif //_HEAP_H_
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef _ITERATOR_H_
|
||||
#define _ITERATOR_H_
|
||||
|
||||
typedef struct {
|
||||
int flags;
|
||||
int layerid;
|
||||
} 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
|
||||
|
||||
|
||||
#endif // _ITERATOR_H_
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef _JSON_HELPERS_H_
|
||||
#define _JSON_HELPERS_H_
|
||||
|
||||
#include "error.h"
|
||||
#include "staticstring.h"
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *get_json_object_value(json_t *obj, char *key, json_t **dest);
|
||||
ErrorContext ERROR_NOIGNORE *get_json_boolean_value(json_t *obj, char *key, bool *dest);
|
||||
ErrorContext ERROR_NOIGNORE *get_json_integer_value(json_t *obj, char *key, int *dest);
|
||||
ErrorContext ERROR_NOIGNORE *get_json_number_value(json_t *obj, char *key, float *dest);
|
||||
ErrorContext ERROR_NOIGNORE *get_json_string_value(json_t *obj, char *key, string **dest);
|
||||
ErrorContext ERROR_NOIGNORE *get_json_array_value(json_t *obj, char *key, json_t **dest);
|
||||
ErrorContext ERROR_NOIGNORE *get_json_array_index_object(json_t *array, int index, json_t **dest);
|
||||
ErrorContext ERROR_NOIGNORE *get_json_array_index_integer(json_t *array, int index, int *dest);
|
||||
ErrorContext ERROR_NOIGNORE *get_json_array_index_string(json_t *array, int index, string **dest);
|
||||
|
||||
#endif // _JSON_HELPERS_H_
|
||||
@@ -1,28 +0,0 @@
|
||||
#ifndef _PHYSICS_H_
|
||||
#define _PHYSICS_H_
|
||||
|
||||
// Box2D works in (meters, kilograms, seconds). Our game works in pixels.
|
||||
// We have a scaling factor of 0.1 (100 pixels = 1 meter).
|
||||
#define PHYSICS_SCREEN_SCALE(x) (x * 0.1)
|
||||
#define SCREEN_PHYSICS_SCALE(x) (x * 10)
|
||||
|
||||
extern b2WorldDef physicsWorldDef;
|
||||
extern b2WorldId physicsWorldId;
|
||||
extern b2BodyDef physicsGroundBodyDef;
|
||||
extern b2BodyId physicsGroundBodyId;
|
||||
extern b2Polygon physicsGroundBox;
|
||||
extern b2ShapeDef physicsGroundShapeDef;
|
||||
extern b2BodyDef physicsBallBodyDef;
|
||||
extern b2BodyId physicsBallBodyId;
|
||||
extern b2Polygon physicsBallBodyBox;
|
||||
extern b2ShapeDef physicsBallShapeDef;
|
||||
|
||||
// Should do this more intelligently at some point -
|
||||
// https://gafferongames.com/post/fix_your_timestep/
|
||||
|
||||
extern float physicsTimeStep;
|
||||
extern int physicsSubStepCount;
|
||||
|
||||
void GAME_init_physics(void);
|
||||
|
||||
#endif //_PHYSICS_H_
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef _REGISTRY_H_
|
||||
#define _REGISTRY_H_
|
||||
|
||||
#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;
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *registry_init();
|
||||
ErrorContext ERROR_NOIGNORE *registry_init_actor();
|
||||
ErrorContext ERROR_NOIGNORE *registry_init_sprite();
|
||||
ErrorContext ERROR_NOIGNORE *registry_init_spritesheet();
|
||||
ErrorContext ERROR_NOIGNORE *registry_init_character();
|
||||
ErrorContext ERROR_NOIGNORE *registry_init_actor_state_strings();
|
||||
|
||||
|
||||
#endif //_REGISTRY_H_
|
||||
@@ -1,44 +0,0 @@
|
||||
#ifndef _SPRITE_H_
|
||||
#define _SPRITE_H_
|
||||
|
||||
#include <box2d/box2d.h>
|
||||
#include <SDL3/SDL_properties.h>
|
||||
#include "error.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 MAX_HEAP_SPRITE (MAX_HEAP_ACTOR * 16)
|
||||
#define MAX_HEAP_SPRITESHEET MAX_HEAP_SPRITE
|
||||
|
||||
typedef struct {
|
||||
int refcount;
|
||||
SDL_Texture *texture;
|
||||
char name[SPRITE_SHEET_MAX_FILENAME_LENGTH];
|
||||
int sprite_w;
|
||||
int sprite_h;
|
||||
} spritesheet;
|
||||
|
||||
typedef struct {
|
||||
int refcount;
|
||||
spritesheet *sheet;
|
||||
int frameids[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;
|
||||
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;
|
||||
|
||||
// initializes a new sprite to use the given sheet and otherwise sets to zero
|
||||
ErrorContext ERROR_NOIGNORE *sprite_initialize(sprite *spr, char *name, spritesheet *sheet);
|
||||
// loads a given image file into a new spritesheet
|
||||
ErrorContext ERROR_NOIGNORE *spritesheet_initialize(spritesheet *sheet, int sprite_w, int sprite_h, char *filename);
|
||||
ErrorContext ERROR_NOIGNORE *sprite_load_json(char *filename);
|
||||
|
||||
#endif //_SPRITE_H_
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef _STRING_H_
|
||||
#define _STRING_H_
|
||||
|
||||
#include "string.h"
|
||||
#include "error.h"
|
||||
|
||||
#define MAX_STRING_LENGTH 256
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int refcount;
|
||||
char data[MAX_STRING_LENGTH];
|
||||
} string;
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *string_initialize(string *obj, char *init);
|
||||
|
||||
#endif //_STRING_H_
|
||||
@@ -1,112 +0,0 @@
|
||||
#ifndef _TILEMAP_H_
|
||||
#define _TILEMAP_H_
|
||||
|
||||
#include "actor.h"
|
||||
#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 TILEMAP_OBJECT_TYPE_ACTOR 1
|
||||
|
||||
#define TILEMAP_LAYER_TYPE_TILES 1
|
||||
#define 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;
|
||||
actor *actorptr;
|
||||
char name[TILEMAP_MAX_OBJECT_NAME_SIZE];
|
||||
} tilemap_object;
|
||||
|
||||
typedef struct {
|
||||
short type;
|
||||
float opacity;
|
||||
bool visible;
|
||||
int height;
|
||||
int width;
|
||||
int x;
|
||||
int y;
|
||||
int id;
|
||||
int data[TILEMAP_MAX_WIDTH * TILEMAP_MAX_HEIGHT];
|
||||
tilemap_object objects[TILEMAP_MAX_OBJECTS_PER_LAYER];
|
||||
} tilemap_layer;
|
||||
|
||||
typedef struct {
|
||||
int columns;
|
||||
int firstgid;
|
||||
char imagefilename[TILEMAP_MAX_TILESET_FILENAME_SIZE];
|
||||
int imageheight;
|
||||
int imagewidth;
|
||||
char name[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 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
|
||||
// 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 tilecount;
|
||||
int tileheight;
|
||||
int tilewidth;
|
||||
int spacing;
|
||||
int margin;
|
||||
} tileset;
|
||||
|
||||
typedef struct {
|
||||
int tilewidth;
|
||||
int tileheight;
|
||||
int width;
|
||||
int height;
|
||||
int numlayers;
|
||||
int orientation; // 0 = orthogonal, 1 = isometric
|
||||
int numtilesets;
|
||||
tileset tilesets[TILEMAP_MAX_TILESETS];
|
||||
tilemap_layer layers[TILEMAP_MAX_LAYERS];
|
||||
} tilemap;
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *tilemap_load(char *fname, tilemap *dest);
|
||||
ErrorContext ERROR_NOIGNORE *tilemap_draw(SDL_Renderer *renderer, tilemap *dest, SDL_FRect *viewport, int layeridx);
|
||||
ErrorContext ERROR_NOIGNORE *tilemap_draw_tileset(SDL_Renderer *renderer, 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.
|
||||
*/
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *get_json_tilemap_property(json_t *obj, char *key, char *type, json_t **dest);
|
||||
ErrorContext ERROR_NOIGNORE *get_json_properties_string(json_t *obj, char *key, string **dest);
|
||||
ErrorContext ERROR_NOIGNORE *get_json_properties_integer(json_t *obj, char *key, int *dest);
|
||||
ErrorContext ERROR_NOIGNORE *tilemap_compute_tileset_offsets(tilemap *dest, int tilesetidx);
|
||||
ErrorContext ERROR_NOIGNORE *tilemap_load_layer_objects(tilemap *dest, json_t *root, int layerid);
|
||||
ErrorContext ERROR_NOIGNORE *tilemap_load_layer_tile(tilemap *dest, json_t *root, int layerid);
|
||||
ErrorContext ERROR_NOIGNORE *tilemap_load_layers(tilemap *dest, json_t *root);
|
||||
ErrorContext ERROR_NOIGNORE *tilemap_load_tilesets_each(json_t *tileset, tilemap *dest, int tsidx);
|
||||
ErrorContext ERROR_NOIGNORE *tilemap_load_tilesets(tilemap *dest, json_t *root);
|
||||
|
||||
|
||||
#endif //_TILEMAP_H_
|
||||
@@ -1,29 +0,0 @@
|
||||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
|
||||
#include "error.h"
|
||||
|
||||
typedef struct point {
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
} point;
|
||||
|
||||
typedef struct RectanglePoints {
|
||||
point topleft;
|
||||
point topright;
|
||||
point bottomleft;
|
||||
point bottomright;
|
||||
} RectanglePoints;
|
||||
|
||||
#define COLLIDE_RECTANGLES(r1x, r1y, r1w, r1h, r2x, r2y, r2w, r2h) ((r1x < (r2x + r2w)) || ((r1x + r1w) > r2x)
|
||||
|
||||
ErrorContext ERROR_NOIGNORE *rectangle_points(RectanglePoints *dest, SDL_FRect *rect);
|
||||
ErrorContext ERROR_NOIGNORE *collide_point_rectangle(point *p, RectanglePoints *r, bool *collide);
|
||||
ErrorContext ERROR_NOIGNORE *collide_rectangles(SDL_FRect *r1, SDL_FRect *r2, bool *collide);
|
||||
|
||||
// These are REALLY slow routines that are only useful in testing harnesses
|
||||
ErrorContext ERROR_NOIGNORE *compare_sdl_surfaces(SDL_Surface *s1, SDL_Surface *s2);
|
||||
ErrorContext ERROR_NOIGNORE *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