93 lines
1.7 KiB
C++
93 lines
1.7 KiB
C++
#ifndef ENTITY_H
|
|
#define ENTITY_H
|
|
|
|
#include "engine.h"
|
|
#include "tier1/utlvector.h"
|
|
#include "cglm/cglm.h"
|
|
|
|
class CBaseEntity;
|
|
class C_BaseEntity;
|
|
|
|
struct Triangle_t
|
|
{
|
|
float location[9];
|
|
float uv[6];
|
|
float normal[9];
|
|
uint32_t texture;
|
|
};
|
|
|
|
/* server entities */
|
|
|
|
class CBaseEntity
|
|
{
|
|
public:
|
|
CBaseEntity();
|
|
virtual void Precache() = 0;
|
|
virtual void Spawn( void ) = 0;
|
|
virtual void Destroy( void ) = 0;
|
|
virtual void Think( float fDelta ) = 0;
|
|
|
|
C_BaseEntity *pClientEntity;
|
|
mat4 m_matrix;
|
|
};
|
|
|
|
|
|
typedef CBaseEntity*(*EntityRegistryFn)( void );
|
|
typedef C_BaseEntity*(*ClientEntityRegistryFn)( void );
|
|
|
|
interface CEntityRegistry
|
|
{
|
|
public:
|
|
CEntityRegistry( const char *szName, const char *szClass, EntityRegistryFn pfn );
|
|
|
|
const char *m_szName;
|
|
const char *m_szClass;
|
|
EntityRegistryFn m_pfn;
|
|
ClientEntityRegistryFn m_pClientfn;
|
|
};
|
|
|
|
|
|
|
|
#define DECLARE_ENTITY(name, class) \
|
|
CBaseEntity *__entity_alloc_##name() \
|
|
{ \
|
|
return new class; \
|
|
}; \
|
|
CEntityRegistry __entity_##name##_registry(#name, #class, __entity_alloc_##name); \
|
|
|
|
/* client entities */
|
|
|
|
|
|
class C_BaseEntity
|
|
{
|
|
public:
|
|
CBaseEntity *pEntity;
|
|
|
|
virtual void Precache() = 0;
|
|
virtual void Spawn( void ) = 0;
|
|
virtual void Destroy( void ) = 0;
|
|
/* happens every frame instead of tick */
|
|
virtual void Think( float fDelta ) = 0;
|
|
private:
|
|
};
|
|
|
|
interface C_EntityRegistry
|
|
{
|
|
public:
|
|
C_EntityRegistry( const char *pName, ClientEntityRegistryFn pfn );
|
|
};
|
|
|
|
#define LINK_CLIENT_ENTITY(client, server) \
|
|
C_BaseEntity *__c_entity_alloc_##server() \
|
|
{ \
|
|
return new client; \
|
|
}; \
|
|
C_EntityRegistry __c_entity_##server##_registry(#server, __c_entity_alloc_##server); \
|
|
|
|
|
|
extern CUtlSelfReferencingVector<CBaseEntity*> g_entities;
|
|
extern CUtlVector<CEntityRegistry*> g_RegisteredEntities;
|
|
|
|
|
|
#endif
|