polyadvent

A game engine from scratch in C
git clone git://jb55.com/polyadvent
Log | Files | Refs | README

commit cca2a76abe04ffd902c46d000ffc2b087e5285f7
parent a7be13b51009a4be98599820a03f1dc67144be8f
Author: William Casarin <jb55@jb55.com>
Date:   Sun, 30 Jun 2019 17:02:04 -0700

make model initialization a bit more consistent

Diffstat:
Msrc/model.c | 11++---------
Msrc/resource.c | 5+++++
Msrc/resource.h | 1+
3 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/src/model.c b/src/model.c @@ -23,18 +23,11 @@ struct model *init_model(struct model *model) { return model; } -struct model *new_model(struct model *model) -{ - init_model(model); - null_id(&model->geom_id); - return model; -} - static void initialize_static_models() { for (int i = 0; i < NUM_STATIC_MODELS; i++) { struct model_def *sm = &static_models[i]; assert(sm->id == i); - new_model(&sm->model); + init_model(&sm->model); } static_models_initialized = 1; } @@ -62,7 +55,7 @@ struct model *get_model(enum static_model m) { struct model *model = &static_models[m].model; - if (get_geometry(&model->geom_id)) + if (is_id_allocated(&model->geom_id) && get_geometry(&model->geom_id)) return model; int ok = 0; diff --git a/src/resource.c b/src/resource.c @@ -198,3 +198,8 @@ void destroy_resource(struct resource_manager *r, struct resource_id *id) { &r->ids[id->index+1], sizeof(*r->ids) * r->resource_count); } + +int is_id_allocated(struct resource_id *id) +{ + return (int)id->index != -1; +} diff --git a/src/resource.h b/src/resource.h @@ -29,6 +29,7 @@ struct resource_manager { #define ideq(a, b) ((a)->uuid == (b)->uuid) +int is_id_allocated(struct resource_id *id); void init_id(struct resource_id *id); void *get_resource(struct resource_manager *r, struct resource_id *id); void *get_all_resources(struct resource_manager *, u32 *count, struct resource_id **ids);