Exported libsdl3game from the sdl3-gametest demo project
This commit is contained in:
77
src/registry.c
Normal file
77
src/registry.c
Normal file
@@ -0,0 +1,77 @@
|
||||
#include <SDL3/SDL.h>
|
||||
#include <sdlerror.h>
|
||||
|
||||
#include "sprite.h"
|
||||
#include "registry.h"
|
||||
#include "iterator.h"
|
||||
#include "actor.h"
|
||||
|
||||
SDL_PropertiesID REGISTRY_ACTOR;
|
||||
SDL_PropertiesID REGISTRY_ACTOR_STATE_STRINGS;
|
||||
SDL_PropertiesID REGISTRY_SPRITE;
|
||||
SDL_PropertiesID REGISTRY_SPRITESHEET;
|
||||
SDL_PropertiesID REGISTRY_CHARACTER;
|
||||
|
||||
ErrorContext *registry_init()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
ATTEMPT {
|
||||
CATCH(errctx, registry_init_spritesheet());
|
||||
CATCH(errctx, registry_init_sprite());
|
||||
CATCH(errctx, registry_init_character());
|
||||
CATCH(errctx, registry_init_actor());
|
||||
CATCH(errctx, registry_init_actor_state_strings());
|
||||
} CLEANUP {
|
||||
} PROCESS(errctx) {
|
||||
} FINISH(errctx, true);
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *registry_init_actor()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
REGISTRY_ACTOR = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_ACTOR, ERR_NULLPOINTER, "Error initializing actor registry");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *registry_init_actor_state_strings()
|
||||
{
|
||||
int i = 0;
|
||||
int flag = 0;
|
||||
PREPARE_ERROR(errctx);
|
||||
REGISTRY_ACTOR_STATE_STRINGS = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_ACTOR_STATE_STRINGS, ERR_NULLPOINTER, "Error initializing actor state strings registry");
|
||||
for ( i = 0 ; i < ACTOR_MAX_STATES; i++ ) {
|
||||
flag = (1 << i);
|
||||
SDL_SetNumberProperty(
|
||||
REGISTRY_ACTOR_STATE_STRINGS,
|
||||
ACTOR_STATE_STRING_NAMES[i],
|
||||
flag);
|
||||
}
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *registry_init_sprite()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
REGISTRY_SPRITE = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_SPRITE, ERR_NULLPOINTER, "Error initializing sprite registry");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *registry_init_spritesheet()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
REGISTRY_SPRITESHEET = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_SPRITESHEET, ERR_NULLPOINTER, "Error initializing spritesheet registry");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
|
||||
ErrorContext *registry_init_character()
|
||||
{
|
||||
PREPARE_ERROR(errctx);
|
||||
REGISTRY_CHARACTER = SDL_CreateProperties();
|
||||
FAIL_ZERO_RETURN(errctx, REGISTRY_CHARACTER, ERR_NULLPOINTER, "Error initializing character registry");
|
||||
SUCCEED_RETURN(errctx);
|
||||
}
|
||||
Reference in New Issue
Block a user