Fixed a bug in akgl_heap_next_string, made screen width and height load from properties, not on the game object
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
#ifndef _SDL_GAMECONTROLLERDB_H_
|
||||
#define _SDL_GAMECONTROLLERDB_H_
|
||||
|
||||
// Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Tue May 12 09:37:37 PM EDT 2026
|
||||
// Taken from https://raw.githubusercontent.com/mdqinc/SDL_GameControllerDB/refs/heads/master/gamecontrollerdb.txt on Wed May 13 04:53:27 AM EDT 2026
|
||||
|
||||
#define AKGL_SDL_GAMECONTROLLER_DB_LEN 2228
|
||||
|
||||
|
||||
@@ -31,8 +31,6 @@ typedef struct {
|
||||
char version[32];
|
||||
char name[256];
|
||||
char uri[256];
|
||||
int16_t screenwidth;
|
||||
int16_t screenheight;
|
||||
akgl_GameState state;
|
||||
int16_t fps;
|
||||
SDL_Time gameStartTime;
|
||||
@@ -56,6 +54,7 @@ extern akgl_Game game;
|
||||
#define AKGL_BITMASK_CLEAR(x) x = 0;
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init();
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init_screen();
|
||||
void akgl_game_updateFPS();
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_save(char *fpath);
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_load(char *fpath);
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef _REGISTRY_H_
|
||||
#define _REGISTRY_H_
|
||||
|
||||
#include "error.h"
|
||||
#include <akgl/error.h>
|
||||
#include <akgl/staticstring.h>
|
||||
|
||||
extern SDL_PropertiesID AKGL_REGISTRY_ACTOR;
|
||||
extern SDL_PropertiesID AKGL_REGISTRY_SPRITE;
|
||||
@@ -22,6 +23,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init_character();
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init_properties();
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_load_properties(char *fname);
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_init_actor_state_strings();
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_set_property(char *name, char *value);
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_property(char *name, akgl_String **dest, char *def);
|
||||
|
||||
#endif //_REGISTRY_H_
|
||||
|
||||
38
src/game.c
38
src/game.c
@@ -32,6 +32,9 @@ akgl_Game game;
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init()
|
||||
{
|
||||
int screenwidth = 0;
|
||||
int screenheight = 0;
|
||||
|
||||
int i = 0;
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
@@ -75,30 +78,49 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init()
|
||||
FAIL_ZERO_RETURN(errctx, 0, AKGL_ERR_SDL, "%s", SDL_GetError());
|
||||
}
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init_screen()
|
||||
{
|
||||
akgl_String *width = NULL;
|
||||
akgl_String *height = NULL;
|
||||
int screenwidth;
|
||||
int screenheight;
|
||||
|
||||
PREPARE_ERROR(e);
|
||||
|
||||
PASS(e, akgl_get_property("game.screenwidth", &width, "0"));
|
||||
PASS(e, akgl_get_property("game.screenheight", &height, "0"));
|
||||
PASS(e, aksl_atoi(width->data, &screenwidth));
|
||||
PASS(e, aksl_atoi(height->data, &screenheight));
|
||||
SDL_Log("Initializing screen (%sx%s = %dx%d)", width->data, height->data, screenwidth, screenheight);
|
||||
PASS(e, akgl_heap_release_string(width));
|
||||
PASS(e, akgl_heap_release_string(height));
|
||||
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
SDL_CreateWindowAndRenderer(game.uri, game.screenwidth, game.screenheight, 0, &window, &renderer),
|
||||
e,
|
||||
SDL_CreateWindowAndRenderer(game.uri, screenwidth, screenheight, 0, &window, &renderer),
|
||||
AKGL_ERR_SDL,
|
||||
"Couldn't create window/renderer: %s",
|
||||
SDL_GetError());
|
||||
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
e,
|
||||
MIX_Init(),
|
||||
AKGL_ERR_SDL,
|
||||
"Couldn't initialize audio: %s",
|
||||
SDL_GetError());
|
||||
akgl_mixer = MIX_CreateMixerDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, 0);
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
e,
|
||||
akgl_mixer,
|
||||
AKGL_ERR_SDL,
|
||||
"Unable to create mixer device: %s",
|
||||
SDL_GetError());
|
||||
|
||||
FAIL_ZERO_RETURN(
|
||||
errctx,
|
||||
e,
|
||||
TTF_Init(),
|
||||
AKGL_ERR_SDL,
|
||||
"Couldn't initialize front engine: %s",
|
||||
@@ -106,9 +128,9 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_game_init()
|
||||
|
||||
camera.x = 0;
|
||||
camera.y = 0;
|
||||
camera.w = game.screenwidth;
|
||||
camera.h = game.screenheight;
|
||||
SUCCEED(errctx);
|
||||
camera.w = screenwidth;
|
||||
camera.h = screenheight;
|
||||
SUCCEED(e);
|
||||
}
|
||||
|
||||
void akgl_game_updateFPS()
|
||||
|
||||
@@ -98,6 +98,7 @@ akerr_ErrorContext *akgl_heap_next_string(akgl_String **dest)
|
||||
continue;
|
||||
}
|
||||
*dest = &HEAP_STRING[i];
|
||||
HEAP_STRING[i].refcount += 1;
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
FAIL_RETURN(errctx, AKERR_HEAP, "Unable to find unused string on the heap");
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <akerror.h>
|
||||
#include <jansson.h>
|
||||
|
||||
#include <akstdlib.h>
|
||||
#include <akgl/heap.h>
|
||||
#include <akgl/sprite.h>
|
||||
#include <akgl/registry.h>
|
||||
@@ -141,6 +142,7 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_load_properties(char *fname)
|
||||
CATCH(errctx, akgl_heap_next_string(&tmpstr));
|
||||
CATCH(errctx, akgl_get_json_string_value(props, (char *)pkey, &tmpstr));
|
||||
SDL_SetStringProperty(AKGL_REGISTRY_PROPERTIES, pkey, tmpstr->data);
|
||||
SDL_Log("Set property %s = %s", pkey, tmpstr->data);
|
||||
CATCH(errctx, akgl_heap_release_string(tmpstr));
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
@@ -149,3 +151,34 @@ akerr_ErrorContext AKERR_NOIGNORE *akgl_registry_load_properties(char *fname)
|
||||
SDL_Log("Properties loaded");
|
||||
SUCCEED(errctx);
|
||||
}
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_set_property(char *name, char *src)
|
||||
{
|
||||
PREPARE_ERROR(e);
|
||||
FAIL_ZERO_RETURN(e, name, AKERR_NULLPOINTER, "NULL char *");
|
||||
FAIL_ZERO_RETURN(e, src, AKERR_NULLPOINTER, "NULL char *");
|
||||
SDL_SetStringProperty(AKGL_REGISTRY_PROPERTIES, name, src);
|
||||
SUCCEED_RETURN(e);
|
||||
}
|
||||
|
||||
akerr_ErrorContext AKERR_NOIGNORE *akgl_get_property(char *name, akgl_String **dest, char *def)
|
||||
{
|
||||
PREPARE_ERROR(e);
|
||||
FAIL_ZERO_RETURN(e, name, AKERR_NULLPOINTER, "NULL char *");
|
||||
FAIL_ZERO_RETURN(e, dest, AKERR_NULLPOINTER, "NULL akgl_String *");
|
||||
ATTEMPT {
|
||||
if ( *dest == NULL ) {
|
||||
CATCH(e, akgl_heap_next_string(dest));
|
||||
}
|
||||
CATCH(e,
|
||||
aksl_memcpy(
|
||||
(*dest)->data,
|
||||
(void *)SDL_GetStringProperty(AKGL_REGISTRY_PROPERTIES, (const char *)name, (const char *)def),
|
||||
AKGL_MAX_STRING_LENGTH)
|
||||
);
|
||||
} CLEANUP {
|
||||
} PROCESS(e) {
|
||||
} FINISH(e, true);
|
||||
SUCCEED_RETURN(e);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user