feat: renamed LevelSpawnFn to DeserializeFn
This commit is contained in:
parent
630f60af94
commit
b641589188
|
@ -6,7 +6,7 @@
|
|||
#include "variant.h"
|
||||
#include "ctype.h"
|
||||
|
||||
static Dictionary internal_spawn_functions = {
|
||||
static Dictionary internal_deserializers = {
|
||||
.list = { .data = NULL, .len = 0, .cap = 0, .element_size = 0 },
|
||||
.element_size = 0
|
||||
};
|
||||
|
@ -17,22 +17,22 @@ static int is_colon(int c) { return c == ':'; }
|
|||
static int ends_parameter(int c) { return c == '}' || c == ','; }
|
||||
|
||||
int level_init() {
|
||||
internal_spawn_functions = dictionary_from_type(LevelSpawnFn);
|
||||
internal_deserializers = dictionary_from_type(DeserializeFn);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int level_clean() {
|
||||
dictionary_empty(&internal_spawn_functions);
|
||||
dictionary_empty(&internal_deserializers);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int level_register_spawner(const char* object_tag, LevelSpawnFn spawn_function) {
|
||||
dictionary_set_value(LevelSpawnFn, &internal_spawn_functions, object_tag, spawn_function);
|
||||
int level_register_spawner(const char* object_tag, DeserializeFn spawn_function) {
|
||||
dictionary_set_value(DeserializeFn, &internal_deserializers, object_tag, spawn_function);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline
|
||||
void spawn_object(LevelSpawnFn spawner, Dictionary* args) {
|
||||
void spawn_object(DeserializeFn spawner, Dictionary* args) {
|
||||
BehaviourEntity entity = spawner(args);
|
||||
game_world_add_entity(entity);
|
||||
if(TC_MIRRORS(entity, PhysicsEntity))
|
||||
|
@ -140,7 +140,7 @@ int level_parse_file(FILE* fp) {
|
|||
char buffer[length];
|
||||
char* obj_tag = NULL;
|
||||
Dictionary args = dictionary_new(sizeof(Variant));
|
||||
LevelSpawnFn spawner = NULL;
|
||||
DeserializeFn spawner = NULL;
|
||||
do {
|
||||
// read the next line of the level file
|
||||
length = get_until(fp, buffer, sizeof(buffer)-1, is_open_bracket);
|
||||
|
@ -152,7 +152,7 @@ int level_parse_file(FILE* fp) {
|
|||
obj_tag[length - start] = '\0';
|
||||
strncpy(obj_tag, buffer + start, length - start);
|
||||
// find the spawn function
|
||||
if(dictionary_try_get(&internal_spawn_functions, obj_tag, &spawner)) {
|
||||
if(dictionary_try_get(&internal_deserializers, obj_tag, &spawner)) {
|
||||
// load arguments from file and spawn object
|
||||
load_args(fp, &args, buffer, sizeof(buffer));
|
||||
spawn_object(spawner, &args);
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
#include "behaviour_entity.h"
|
||||
#include "dictionary.h"
|
||||
|
||||
typedef BehaviourEntity(*LevelSpawnFn)(Dictionary* args);
|
||||
typedef BehaviourEntity(*DeserializeFn)(Dictionary* args);
|
||||
|
||||
extern int level_init();
|
||||
extern int level_clean();
|
||||
|
||||
extern int level_register_spawner(const char* object_tag, LevelSpawnFn spawn_function);
|
||||
extern int level_register_spawner(const char* object_tag, DeserializeFn spawn_function);
|
||||
|
||||
extern int level_parse_file(FILE* level);
|
||||
extern int level_load_file(const char* path);
|
||||
|
|
Loading…
Reference in a new issue