diff --git a/maps/base.gmf9 b/maps/base.gmf9 index e44d305..6b6ee5b 100644 --- a/maps/base.gmf9 +++ b/maps/base.gmf9 @@ -1,9 +1,9 @@ // Copyright © 2017 Project Golan, all rights reserved. -{0 Player -200 250 0} -{0 Sector -450 -330 510 660 -16 96} // center -{0 Sector -450 -355 510 25 64 96} // top -{0 Sector -450 330 510 25 64 96} // bottom -{0 Sector -475 -355 25 710 64 96} // left -{0 Sector 60 -355 25 710 64 96} // right +{0 Player -200 250 16} +{0 Sector -450 -330 510 660 0 96} // center +{0 Sector -450 -355 510 25 64 96} // top +{0 Sector -450 330 510 25 64 96} // bottom +{0 Sector -475 -355 25 710 64 96} // left +{0 Sector 60 -355 25 710 64 96} // right // EOF diff --git a/src/g_objdef.c b/src/g_objdef.c index 1de97b5..14b9c5c 100644 --- a/src/g_objdef.c +++ b/src/g_objdef.c @@ -96,6 +96,7 @@ typedef struct G_odarg typedef struct G_ofdcl { + unsigned extm; DGE_CallbackType fptr; char const *name; size_t keyhash; @@ -270,6 +271,7 @@ static void G_ObjDef_getEntProp(G_dodst *st, G_entty *type, char const *id) { 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; } else if(strcmp(id, "size") == 0) @@ -536,10 +538,10 @@ done: // // G_ObjDef_LoadFunc // -void G_ObjDef_LoadFunc(char const *name, DGE_CallbackType fptr) +void G_ObjDef_LoadFunc(char const *name, unsigned ext, DGE_CallbackType fptr) { M_Vec_grow(G_ofvec, 1); - G_ofvecV[G_ofvecC] = (G_ofdcl){fptr, name, M_StrHash(name)}; + G_ofvecV[G_ofvecC] = (G_ofdcl){ext, fptr, name, M_StrHash(name)}; G_objfuncs.insert(&M_Vec_next(G_ofvec)); } diff --git a/src/g_objdef.h b/src/g_objdef.h new file mode 100644 index 0000000..612234e --- /dev/null +++ b/src/g_objdef.h @@ -0,0 +1,67 @@ +// Copyright © 2017 Project Golan, all rights reserved. +#ifndef g_objdef_h +#define g_objdef_h + +#include "m_types.h" + +#include + +#define G_ObjDef_setupEntity(type, th) \ + do { \ + (th).sprite = (type)->sprite; \ + (th).health = (type)->health; \ + (th).friction = (type)->friction; \ + (th).mass = (type)->mass; \ + (th).rsx = (type)->rsx; \ + (th).rsy = (type)->rsy; \ + (th).sx = (type)->sx; \ + (th).sy = (type)->sy; \ + (th).sz = (type)->sz; \ + } 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); +struct G_anima const *G_ObjDef_GetAnim(struct G_entty const *type, char const *name); + +// Types ---------------------------------------------------------------------| + +typedef struct G_frame // Frame +{ + integ time; + M_texid sprite; +} G_frame; + +typedef struct G_anima // Animation +{ + G_frame *frame; + msize count; +} G_anima; + +typedef struct G_entty // Entity Type +{ + __prop getAnim {call: G_ObjDef_GetAnim(this)} + + M_texid sprite; + integ health; + lfrac friction; + fixed mass; + fixed rsx, rsy; + fixed sx, sy, sz; + 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); + +#endif diff --git a/src/g_object.c b/src/g_object.c index 31b9cbc..2c4c72b 100644 --- a/src/g_object.c +++ b/src/g_object.c @@ -14,7 +14,9 @@ // void G_Entity_Create(G_mfdat *info) { - DGE_Entity ent = {DGE_Entity_Create(0)}; + G_entty const *type = G_ObjDef_GetType(info->ent.name); + + DGE_Entity ent = {DGE_Entity_Create(type ? type->ext : 0)}; ent.x = info->ent.x; ent.y = info->ent.y; @@ -24,10 +26,9 @@ void G_Entity_Create(G_mfdat *info) ent.mass = 1; ent.friction = 0.875ulr; - G_entty const *type; - if((type = G_ObjDef_GetType(info->ent.name))) { + if(type) { G_ObjDef_setupEntity(type, ent); - G_ObjDef_createTask (type, ent); + G_ObjDef_createTask (type, ent.id); } } diff --git a/src/g_object.h b/src/g_object.h index 9f9bff5..bf3757a 100644 --- a/src/g_object.h +++ b/src/g_object.h @@ -2,70 +2,53 @@ #ifndef g_object_h #define g_object_h -#include "m_types.h" +#include "g_objdef.h" #include -#include -#include +#define G_propMemOfs(ofs, t, name) \ + __prop name {__get: DGE_Object_MemberGet(t, ->id, ofs), \ + __set: DGE_Object_MemberSet(t, ->id, ofs)} -#define G_ObjDef_setupEntity(type, th) \ - do { \ - (th).sprite = (type)->sprite; \ - (th).health = (type)->health; \ - (th).friction = (type)->friction; \ - (th).mass = (type)->mass; \ - (th).rsx = (type)->rsx; \ - (th).rsy = (type)->rsy; \ - (th).sx = (type)->sx; \ - (th).sy = (type)->sy; \ - (th).sz = (type)->sz; \ - } while(0) +#define G_propMemExt(base, ofs, t, name) \ + G_propMemOfs(DGE_OME_##base + (ofs), t, name) -#define G_ObjDef_createTask(type, ...) \ - (DGE_Task_Create(0, (type)->task, __VA_ARGS__)) +#define G_Entity_propMem(ofs, t, name) \ + G_propMemExt(Entity, ofs, t, name) -#define G_ObjDef_loadFunc(fn) G_ObjDef_LoadFunc(#fn, (DGE_CallbackType)fn) - -// Extern Functions ----------------------------------------------------------| - -struct G_entty const *G_ObjDef_GetType(char const *name); -struct G_anima const *G_ObjDef_GetAnim(struct G_entty const *type, char const *name); +#define G_Entity_props() DGE_EntityProps() // Types ---------------------------------------------------------------------| -typedef struct G_frame // Frame +enum { - integ time; - M_texid sprite; -} G_frame; + G_Player_ammo, + G_Player_propN +}; -typedef struct G_anima // Animation +typedef struct G_entit // Entity { - G_frame *frame; - msize count; -} G_anima; + int id; -typedef struct G_entty // Entity Type + G_Entity_props() +} G_entit; + +#define G_Player_props() G_Entity_props() \ + G_Entity_propMem(G_Player_ammo, unsigned, ammo) +typedef struct G_playr // Player { - __prop getAnim {call: G_ObjDef_GetAnim(this)} + int id; - M_texid sprite; - integ health; - lfrac friction; - fixed mass; - fixed rsx, rsy; - fixed sx, sy, sz; - DGE_CallbackType task; -} G_entty; + G_Player_props() +} G_playr; + +// Extern Objects ------------------------------------------------------------| + +extern int G_Player_Count; // Extern Functions ----------------------------------------------------------| -void G_ObjDef_Init(void); -void G_ObjDef_Load(char const *fname); -void G_ObjDef_LoadFunc(char const *name, DGE_CallbackType fptr); - -DGE_Callback void G_Player_Think(DGE_Entity ent); +DGE_Callback void G_Player_Think(unsigned id); void G_Entity_Create(union G_mfdat *info); void G_Sector_Create(union G_mfdat *info); diff --git a/src/g_player.c b/src/g_player.c index 31cba89..e1e52c7 100644 --- a/src/g_player.c +++ b/src/g_player.c @@ -7,14 +7,18 @@ #include #include +// Extern Objects ------------------------------------------------------------| + +int G_Player_Count = 1; + // Static Functions ----------------------------------------------------------| // // G_Player_applyVelocity // -static void G_Player_applyVelocity(DGE_Entity ent) +static void G_Player_applyVelocity(G_playr th) { - DGE_Point2R ax = DGE_Input_GetAxis(1); + DGE_Point3R ax = DGE_Input_GetAxis(1); accum vx = (accum)ax.x, vy = (accum)ax.y; float mag = sqrtf(vx * vx + vy * vy); @@ -23,8 +27,8 @@ static void G_Player_applyVelocity(DGE_Entity ent) sincosf(ang, &s, &c); - ent.vx = ent.vx + c * mag * 5; - ent.vy = ent.vy - s * mag * 5; + th.vx = th.vx + c * mag * 5; + th.vy = th.vy - s * mag * 5; // TODO: apply animation based on X velocity here } @@ -35,21 +39,18 @@ static void G_Player_applyVelocity(DGE_Entity ent) // G_Player_Think // DGE_Callback -void G_Player_Think(DGE_Entity ent) +void G_Player_Think(unsigned id) { - DGE_Object_RefAdd(ent.id); + DGE_Object_RefAdd(id); - for(;;) + for(G_playr th = {id}; th.health > 0;) { - if(ent.health <= 0) - break; - - G_Player_applyVelocity(ent); + G_Player_applyVelocity(th); DGE_Task_Sleep(0, 1); } - DGE_Object_RefSub(ent.id); + DGE_Object_RefSub(id); } // EOF diff --git a/src/main.c b/src/main.c index 2203cc1..d51919b 100644 --- a/src/main.c +++ b/src/main.c @@ -27,7 +27,7 @@ void GInit(char const *resdecl) printf("Loading object function table...\n"); G_ObjDef_Init(); - G_ObjDef_loadFunc(G_Player_Think); + G_ObjDef_loadFunc(G_Player_propN, G_Player_Think); printf("Loading object definitions...\n"); G_ObjDef_Load("objdefs.dod");