From 7f04b61736d8276a5b061b814bd66e0db8297b7d Mon Sep 17 00:00:00 2001 From: Marrub Date: Thu, 28 Sep 2017 13:52:02 -0400 Subject: [PATCH] Replace G_ObjDef_LoadFunc with G_ObjDef_AddType --- src/g_objdef.c | 55 +++++++++++++++++++++++++------------------------- src/g_objdef.h | 9 ++++----- src/main.c | 2 +- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/src/g_objdef.c b/src/g_objdef.c index 14b9c5c..e1ca20d 100644 --- a/src/g_objdef.c +++ b/src/g_objdef.c @@ -1,5 +1,5 @@ // Copyright © 2017 Project Golan, all rights reserved. -#include "g_object.h" +#include "g_objdef.h" #include "m_tokbuf.h" #include "m_str.h" @@ -12,12 +12,12 @@ #include #include -#define G_ofmap_GetKey(o) ( (o)->name) -#define G_ofmap_GetNext(o) (&(o)->next) -#define G_ofmap_GetPrev(o) (&(o)->prev) -#define G_ofmap_HashObj(o) ( (o)->keyhash) -#define G_ofmap_HashKey(k) (M_StrHash(k)) -#define G_ofmap_KeyCmp(l, r) (strcmp(l, r)) +#define G_otmap_GetKey(o) ( (o)->name) +#define G_otmap_GetNext(o) (&(o)->next) +#define G_otmap_GetPrev(o) (&(o)->prev) +#define G_otmap_HashObj(o) ( (o)->keyhash) +#define G_otmap_HashKey(k) (M_StrHash(k)) +#define G_otmap_KeyCmp(l, r) (strcmp(l, r)) #define G_etmap_GetKey(o) ( (o)->name) #define G_etmap_GetNext(o) (&(o)->next) @@ -57,7 +57,7 @@ static struct G_odarg G_ObjDef_getArgs (struct G_dodst *st, char const *arg); // Types ---------------------------------------------------------------------| -GDCC_HashMap_Decl(G_ofmap, char const *, struct G_ofdcl) +GDCC_HashMap_Decl(G_otmap, char const *, struct G_otdcl) GDCC_HashMap_Decl(G_etmap, char const *, struct G_etdcl) GDCC_HashMap_Decl(G_frmap, char const *, struct G_frdcl) GDCC_HashMap_Decl(G_anmap, char const *, struct G_andcl) @@ -94,21 +94,21 @@ typedef struct G_odarg int argc; } G_odarg; -typedef struct G_ofdcl +typedef struct G_otdcl { - unsigned extm; + mword subt; + mword extm; DGE_CallbackType fptr; char const *name; size_t keyhash; - struct G_ofdcl *next, **prev; -} G_ofdcl; + struct G_otdcl *next, **prev; +} G_otdcl; typedef struct G_etdcl { G_entty type; G_anims anim; M_Vec_decl(struct G_manim, anims); - char name[32]; size_t keyhash; struct G_etdcl *next, **prev; @@ -140,19 +140,19 @@ typedef struct G_manim // Static Objects ------------------------------------------------------------| -static G_ofmap G_objfuncs; +static G_otmap G_objtypes; static G_etmap G_enttypes; static G_frmap G_frametab; static G_anmap G_animsmap; -M_Vec_defn(G_ofdcl, G_ofvec, static); +M_Vec_defn(G_otdcl, G_otvec, static); M_Vec_defn(G_etdcl, G_etvec, static); M_Vec_defn(G_frdcl, G_frvec, static); M_Vec_defn(G_andcl, G_anvec, static); // Static Functions ----------------------------------------------------------| -GDCC_HashMap_Defn(G_ofmap, char const *, G_ofdcl) +GDCC_HashMap_Defn(G_otmap, char const *, G_otdcl) GDCC_HashMap_Defn(G_etmap, char const *, G_etdcl) GDCC_HashMap_Defn(G_frmap, char const *, G_frdcl) GDCC_HashMap_Defn(G_anmap, char const *, G_andcl) @@ -267,12 +267,13 @@ static void G_ObjDef_getEntAnim(G_dodst *st, G_etdcl *decl) // static void G_ObjDef_getEntProp(G_dodst *st, G_entty *type, char const *id) { - if(strcmp(id, "task") == 0) + if(strcmp(id, "subtype") == 0) { - G_ofdcl *fn = G_objfuncs.find(st->expect(tok_identi, "function")->textV); - if(!fn) st->throw("invalid function name"); - type->ext = fn->extm; - type->task = fn->fptr; + G_otdcl *ot = G_objtypes.find(st->expect(tok_identi, "subtype")->textV); + if(!ot) st->throw("invalid subtype name"); + type->subtype = ot->subt; + type->ext = ot->extm; + type->task = ot->fptr; } else if(strcmp(id, "size") == 0) { @@ -481,7 +482,7 @@ static void G_ObjDef_parseEntDef(G_dodst *st) // void G_ObjDef_Init(void) { - G_ofmap_ctor(&G_objfuncs, 16, 16); + G_otmap_ctor(&G_objtypes, 16, 16); G_etmap_ctor(&G_enttypes, 16, 16); G_frmap_ctor(&G_frametab, 16, 16); G_anmap_ctor(&G_animsmap, 16, 16); @@ -536,13 +537,13 @@ done: } // -// G_ObjDef_LoadFunc +// G_ObjDef_AddType // -void G_ObjDef_LoadFunc(char const *name, unsigned ext, DGE_CallbackType fptr) +void G_ObjDef_AddType(char const *name, mword subtype, mword ext, DGE_CallbackType fptr) { - M_Vec_grow(G_ofvec, 1); - G_ofvecV[G_ofvecC] = (G_ofdcl){ext, fptr, name, M_StrHash(name)}; - G_objfuncs.insert(&M_Vec_next(G_ofvec)); + M_Vec_grow(G_otvec, 1); + G_otvecV[G_otvecC] = (G_otdcl){subtype, ext, fptr, name, M_StrHash(name)}; + G_objtypes.insert(&M_Vec_next(G_otvec)); } // diff --git a/src/g_objdef.h b/src/g_objdef.h index 612234e..397bea1 100644 --- a/src/g_objdef.h +++ b/src/g_objdef.h @@ -17,14 +17,12 @@ (th).sx = (type)->sx; \ (th).sy = (type)->sy; \ (th).sz = (type)->sz; \ + (th).subtype = (type)->subtype; \ } while(0) #define G_ObjDef_createTask(type, ...) \ (DGE_Task_Create(0, (type)->task, __VA_ARGS__)) -#define G_ObjDef_loadFunc(ext, fn) \ - G_ObjDef_LoadFunc(#fn, ext, (DGE_CallbackType)fn) - // Extern Functions ----------------------------------------------------------| struct G_entty const *G_ObjDef_GetType(char const *name); @@ -54,14 +52,15 @@ typedef struct G_entty // Entity Type fixed mass; fixed rsx, rsy; fixed sx, sy, sz; + mword subtype; + mword ext; DGE_CallbackType task; - unsigned ext; } G_entty; // Extern Functions ----------------------------------------------------------| void G_ObjDef_Init(void); void G_ObjDef_Load(char const *fname); -void G_ObjDef_LoadFunc(char const *name, unsigned ext, DGE_CallbackType fptr); +void G_ObjDef_AddType(char const *name, mword subtype, mword ext, DGE_CallbackType fptr); #endif diff --git a/src/main.c b/src/main.c index 5f29d51..4851cf0 100644 --- a/src/main.c +++ b/src/main.c @@ -28,7 +28,7 @@ void GInit(char const *resdecl) printf("Loading object function table...\n"); G_ObjDef_Init(); - G_ObjDef_loadFunc(G_Player_propC, G_Player_Think); + G_ObjDef_AddType("Player", subtype_player, G_Player_propC, (DGE_CallbackType)G_Player_Think); printf("Loading object definitions...\n"); G_ObjDef_Load("objdefs.dod");