diff options
| author | navewindre <boneyaard@gmail.com> | 2025-09-03 20:10:09 +0200 |
|---|---|---|
| committer | navewindre <boneyaard@gmail.com> | 2025-09-03 20:10:09 +0200 |
| commit | f8b92ce3aa08b1445c9f956d8166830946562d12 (patch) | |
| tree | 94e63a5aec9f8f52b577f56799e0c9201fd976a5 /src/game/object.h | |
a
Diffstat (limited to 'src/game/object.h')
| -rw-r--r-- | src/game/object.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/game/object.h b/src/game/object.h new file mode 100644 index 0000000..8191ab7 --- /dev/null +++ b/src/game/object.h @@ -0,0 +1,73 @@ +#pragma once +#include "../util/allocator.h" +#include "../util/vector.h" +#include "../util/fnv.h" + +typedef void ( *OBJECT_DEINIT_FN )( struct OBJECT* obj ); +inline const char* obj_classid_to_name( U32 classid ); + +enum ObjectClass_t { + OBJCLASS_NONE = 0, + OBJCLASS_WORLD, + OBJCLASS_TRIGGER, + OBJCLASS_PLAYER, + OBJCLASS_BASENPC, +}; + +static const char* OBJCLASS_NAMES[] = { + "none (invalid - FIXME)", + "world", + "trigger", + "player", + "base_npc", +}; + +// todo: come up with a good way to make these static +struct OBJECT_PROP { + OBJECT_PROP( const char* name, void* value, U32 size, LIST<OBJECT_PROP*>* list, void* parent ) { + this->name = name; + this->size = size; + this->hash = fnv1a( name ); + this->offset = (U32)( (U8*)value - (U8*)parent ); + list->push( this ); + } + + const char* name; + FNV1A hash; + U32 offset; + U32 size; +}; + +#define OBJVAR( type, name ) \ + type name; \ + OBJECT_PROP __##name##_props{ #name, (void*)&name, sizeof(type), &this->props, this } + +#define OBJVAR_STR( name, len ) \ + char name##[len]; \ + OBJECT_PROP __##name##_props{ #name, (void*)name, len, &this->props, this } + +struct OBJECT { + static const U32 CLASSID = OBJCLASS_NONE; + + U32 classid; + U8 keeponlevel{}; + char name[64]; + + OBJECT* parent; + LIST<OBJECT*> children{}; + LIST<OBJECT_PROP*> props{}; + OBJECT_DEINIT_FN deinit_fn{}; + + OBJVAR( VEC3, pos ); + OBJVAR( VEC3, rot ); + OBJVAR( I32, idx ); +}; + +inline const char* obj_classid_to_name( U32 classid ) { + if( classid > (sizeof(OBJCLASS_NAMES) / sizeof(OBJCLASS_NAMES[0])) ) { + dlog( "obj_classid_to_name() : invalid classid passed (%d)", classid ); + return "INVALIDCLASSID"; + } + + return OBJCLASS_NAMES[classid]; +} |
