init
This commit is contained in:
87
public/baseentity.h
Normal file
87
public/baseentity.h
Normal file
@@ -0,0 +1,87 @@
|
||||
#ifndef ENTITY_H
|
||||
#define ENTITY_H
|
||||
|
||||
#include "tier1/utlvector.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:
|
||||
C_BaseEntity *pClientEntity;
|
||||
|
||||
virtual void Precache() = 0;
|
||||
virtual void Spawn( void ) = 0;
|
||||
virtual void Destroy( void ) = 0;
|
||||
virtual void Think( float fDelta ) = 0;
|
||||
};
|
||||
|
||||
extern CUtlSelfReferencingVector<CBaseEntity*> g_entities;
|
||||
|
||||
typedef CBaseEntity*(*EntityRegistryFn)( void );
|
||||
typedef C_BaseEntity*(*ClientEntityRegistryFn)( void );
|
||||
|
||||
class 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;
|
||||
};
|
||||
|
||||
extern CUtlVector<CEntityRegistry*> g_RegisteredEntities;
|
||||
|
||||
|
||||
#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;
|
||||
};
|
||||
|
||||
class 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); \
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user