#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* 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 children{}; LIST 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]; }