work on the stuff on client
This commit is contained in:
BIN
funnyassets/meshes/spot.fmesh_c
Normal file
BIN
funnyassets/meshes/spot.fmesh_c
Normal file
Binary file not shown.
@@ -57,19 +57,16 @@ VS
|
|||||||
PS
|
PS
|
||||||
{
|
{
|
||||||
#include "brdf.hlsl"
|
#include "brdf.hlsl"
|
||||||
|
struct PS_OUTPUT
|
||||||
float4 psMain( PS_INPUT input )
|
|
||||||
{
|
{
|
||||||
|
float4 m_vAlbedo: SV_Target0;
|
||||||
|
}
|
||||||
|
|
||||||
float4 vWorldSpacePosition = input.m_vNormal;
|
PS_OUTPUT psMain( PS_INPUT input )
|
||||||
BRDF_t brdf = {};
|
{
|
||||||
brdf.m_vRayIn = normalize(g_vViewPosition.xyz-input.m_vWorldPosition.xyz);
|
PS_OUTPUT output = {};
|
||||||
brdf.m_vRayOut = normalize(-input.m_vWorldPosition.xyz);
|
output.m_vAlbedo = input.m_vNormal;
|
||||||
brdf.m_vNormal = input.m_vNormal.xyz;
|
return output;
|
||||||
brdf.m_fRoughness = 1;
|
|
||||||
brdf.m_fMetalness = 1;
|
|
||||||
|
|
||||||
return float4(brdf.BurleyDiffuse(), 1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
114
game/client/baseentity.cpp
Normal file
114
game/client/baseentity.cpp
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
//================= Copyright kotofyt, All rights reserved ==================//
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
//
|
||||||
|
//===========================================================================//
|
||||||
|
|
||||||
|
#include "baseentity.h"
|
||||||
|
#include "datamap.h"
|
||||||
|
#include "tier0/lib.h"
|
||||||
|
|
||||||
|
C_BaseEntity::~C_BaseEntity()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
void C_BaseEntity::Precache()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void C_BaseEntity::Spawn()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void C_BaseEntity::SetAbsAngles( float fPitch, float fYaw, float fRoll )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void C_BaseEntity::SetAbsOrigin( Vector origin )
|
||||||
|
{
|
||||||
|
m_vPosition = origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void C_BaseEntity::SetScale( float fScale )
|
||||||
|
{
|
||||||
|
m_vScale.x = fScale;
|
||||||
|
m_vScale.y = fScale;
|
||||||
|
m_vScale.z = fScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QAngle C_BaseEntity::GetAbsAngles( void )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector C_BaseEntity::GetAbsOrigin( void )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float C_BaseEntity::GetScale( void )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void C_BaseEntity::SetThinkImpl( fnThink pfnThink )
|
||||||
|
{
|
||||||
|
m_pfnThink = pfnThink;
|
||||||
|
V_printf("%p\n", pfnThink);
|
||||||
|
}
|
||||||
|
|
||||||
|
void C_BaseEntity::SetNextThink( float fThink )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
typedescription_t *C_BaseEntity::FindDataByName( const char *szName )
|
||||||
|
{
|
||||||
|
datamap_t *pDataMap;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
pDataMap = GetDataMap();
|
||||||
|
|
||||||
|
lookforname:
|
||||||
|
for ( i = 0; i < pDataMap->m_iNumFields; i++ )
|
||||||
|
{
|
||||||
|
if (!V_strcmp(pDataMap->m_pData[i].m_szFieldName, szName))
|
||||||
|
return &pDataMap->m_pData[i];
|
||||||
|
}
|
||||||
|
pDataMap = pDataMap->m_pBase;
|
||||||
|
|
||||||
|
if (pDataMap)
|
||||||
|
goto lookforname;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedescription_t *C_BaseEntity::FindDataByMapName( const char *szName )
|
||||||
|
{
|
||||||
|
datamap_t *pDataMap;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
pDataMap = GetDataMap();
|
||||||
|
|
||||||
|
lookforname:
|
||||||
|
for ( i = 0; i < pDataMap->m_iNumFields; i++ )
|
||||||
|
{
|
||||||
|
if (!V_strcmp(pDataMap->m_pData[i].m_szEditorName, szName))
|
||||||
|
return &pDataMap->m_pData[i];
|
||||||
|
}
|
||||||
|
pDataMap = pDataMap->m_pBase;
|
||||||
|
|
||||||
|
if (pDataMap)
|
||||||
|
goto lookforname;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
BEGIN_DATADESC_NOBASE(C_BaseEntity)
|
||||||
|
DEFINE_KEYFIELD(m_vPosition, FIELD_VECTOR, "origin")
|
||||||
|
DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles")
|
||||||
|
DEFINE_KEYFIELD(m_vScale, FIELD_VECTOR, "scales")
|
||||||
|
END_DATADESC()
|
||||||
81
game/client/baseentity.h
Normal file
81
game/client/baseentity.h
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
//================= Copyright kotofyt, All rights reserved ==================//
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
//
|
||||||
|
//===========================================================================//
|
||||||
|
|
||||||
|
#ifndef BASEENTITY_H
|
||||||
|
#define BASEENTITY_H
|
||||||
|
|
||||||
|
#include "entitysystem.h"
|
||||||
|
#include "datamap.h"
|
||||||
|
#include "cglm/cglm.h"
|
||||||
|
#include "trig.h"
|
||||||
|
|
||||||
|
#define DECLARE_CLASS_NOBASE( className ) \
|
||||||
|
typedef className ThisClass;
|
||||||
|
#define DECLARE_CLASS( className, baseName ) \
|
||||||
|
typedef baseName BaseClass; \
|
||||||
|
typedef className ThisClass;
|
||||||
|
|
||||||
|
#define LINK_ENTITY_TO_CLASS( mapClassName, DLLClassName) \
|
||||||
|
static CEntityFactory<DLLClassName> g_EntityFactory_##mapClassName( #mapClassName );
|
||||||
|
|
||||||
|
class C_BaseEntity;
|
||||||
|
|
||||||
|
class IEntityFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual C_BaseEntity *Create() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
class CEntityFactory : public IEntityFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CEntityFactory( const char *szClassName )
|
||||||
|
{
|
||||||
|
EntitySystem()->RegisterEntityClass(this, szClassName);
|
||||||
|
};
|
||||||
|
virtual C_BaseEntity *Create() {
|
||||||
|
return new T;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class C_BaseEntity;
|
||||||
|
typedef void(C_BaseEntity::*fnThink)( float fTime );
|
||||||
|
class C_BaseEntity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DECLARE_CLASS_NOBASE(C_BaseEntity);
|
||||||
|
DECLARE_DATADESC_NOBASE()
|
||||||
|
|
||||||
|
typedescription_t *FindDataByName( const char *szName );
|
||||||
|
typedescription_t *FindDataByMapName( const char *szName );
|
||||||
|
|
||||||
|
virtual ~C_BaseEntity();
|
||||||
|
virtual void Precache();
|
||||||
|
virtual void Spawn();
|
||||||
|
|
||||||
|
virtual void SetAbsAngles( float fPitch, float fYaw, float fRoll );
|
||||||
|
virtual void SetAbsOrigin( Vector origin );
|
||||||
|
virtual void SetScale( float fScale );
|
||||||
|
|
||||||
|
virtual QAngle GetAbsAngles( void );
|
||||||
|
virtual Vector GetAbsOrigin( void );
|
||||||
|
virtual float GetScale( void );
|
||||||
|
|
||||||
|
#define SetThink(fn) SetThinkImpl((fnThink)&ThisClass::fn)
|
||||||
|
virtual void SetThinkImpl( fnThink pfnThink );
|
||||||
|
virtual void SetNextThink( float fThink );
|
||||||
|
|
||||||
|
fnThink m_pfnThink = NULL;
|
||||||
|
private:
|
||||||
|
Vector m_vPosition;
|
||||||
|
Quat m_vRotation;
|
||||||
|
Vector m_vScale;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -16,8 +16,12 @@ DECLARE_BUILD_STAGE(Client)
|
|||||||
compileProject.files = {
|
compileProject.files = {
|
||||||
"game.cpp",
|
"game.cpp",
|
||||||
"worldrender.cpp",
|
"worldrender.cpp",
|
||||||
|
"baseentity.cpp",
|
||||||
|
"entitysystem.cpp",
|
||||||
|
"milmoba/player.cpp",
|
||||||
};
|
};
|
||||||
compileProject.includeDirectories = {
|
compileProject.includeDirectories = {
|
||||||
|
"../shared",
|
||||||
"../../public",
|
"../../public",
|
||||||
FUNNYSTDLIB"public",
|
FUNNYSTDLIB"public",
|
||||||
EXTERNAL"cglm/include"
|
EXTERNAL"cglm/include"
|
||||||
|
|||||||
120
game/client/entitysystem.cpp
Normal file
120
game/client/entitysystem.cpp
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
//================= Copyright kotofyt, All rights reserved ==================//
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
//
|
||||||
|
//===========================================================================//
|
||||||
|
|
||||||
|
#include "entitysystem.h"
|
||||||
|
#include "baseentity.h"
|
||||||
|
#include "stddef.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
|
||||||
|
CEntitySystem *EntitySystem()
|
||||||
|
{
|
||||||
|
static CEntitySystem s_entitySystem;
|
||||||
|
return &s_entitySystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct EntityRegistry_t
|
||||||
|
{
|
||||||
|
IEntityFactory *m_pFactory;
|
||||||
|
const char *m_szClassName;
|
||||||
|
struct EntityRegistry_t *m_pNext;
|
||||||
|
} *s_pEntitiesRegistry = NULL;
|
||||||
|
|
||||||
|
CEntitySystem::CEntitySystem()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for ( i = 0; i < MAX_EDICTS; i++ )
|
||||||
|
{
|
||||||
|
m_pEntities[i] = NULL;
|
||||||
|
}
|
||||||
|
m_nEntityCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEntitySystem::RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName )
|
||||||
|
{
|
||||||
|
IEntityFactory *pFactory;
|
||||||
|
EntityRegistry_t *pRegistry;
|
||||||
|
|
||||||
|
pFactory = GetFactoryByClassname(szClassName);
|
||||||
|
|
||||||
|
if ( pFactory != NULL )
|
||||||
|
{
|
||||||
|
// Already registered
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pRegistry = new EntityRegistry_t;
|
||||||
|
pRegistry->m_pFactory = pEntityFactory;
|
||||||
|
pRegistry->m_pNext = s_pEntitiesRegistry;
|
||||||
|
pRegistry->m_szClassName = szClassName;
|
||||||
|
s_pEntitiesRegistry = pRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
C_BaseEntity *CEntitySystem::CreateByClassname( const char *szName )
|
||||||
|
{
|
||||||
|
IEntityFactory *pFactory;
|
||||||
|
C_BaseEntity *pEntity;
|
||||||
|
int i;
|
||||||
|
int iSelectedSlot;
|
||||||
|
|
||||||
|
pFactory = GetFactoryByClassname(szName);
|
||||||
|
if ( !pFactory )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// We do not want to have more than MAX_EDICT entities
|
||||||
|
if ( m_nEntityCount >= MAX_EDICTS-1 )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// Search for space
|
||||||
|
// Could be more efficient but nobody cares
|
||||||
|
for ( i = 0; i < MAX_EDICTS; i++ )
|
||||||
|
{
|
||||||
|
if ( m_pEntities[i] == NULL )
|
||||||
|
{
|
||||||
|
iSelectedSlot = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pEntity = pFactory->Create();
|
||||||
|
m_pEntities[iSelectedSlot] = pEntity;
|
||||||
|
m_nEntityCount++;
|
||||||
|
return pEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName )
|
||||||
|
{
|
||||||
|
EntityRegistry_t *pEntity;
|
||||||
|
|
||||||
|
for ( pEntity = s_pEntitiesRegistry; pEntity; pEntity = pEntity->m_pNext )
|
||||||
|
{
|
||||||
|
if (!strcmp(szName, pEntity->m_szClassName))
|
||||||
|
{
|
||||||
|
return pEntity->m_pFactory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CEntitySystem::Think()
|
||||||
|
{
|
||||||
|
C_BaseEntity *pEntity;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for ( i = 0; i < MAX_EDICTS; i++ )
|
||||||
|
{
|
||||||
|
pEntity = m_pEntities[i];
|
||||||
|
if ( pEntity == NULL )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ( !pEntity->m_pfnThink )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
(pEntity->*pEntity->m_pfnThink)(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
33
game/client/entitysystem.h
Normal file
33
game/client/entitysystem.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
//================= Copyright kotofyt, All rights reserved ==================//
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
//
|
||||||
|
//===========================================================================//
|
||||||
|
|
||||||
|
#ifndef ENTITIES_H
|
||||||
|
#define ENTITIES_H
|
||||||
|
|
||||||
|
class IEntityFactory;
|
||||||
|
class C_BaseEntity;
|
||||||
|
|
||||||
|
#define MAX_EDICTS 8192
|
||||||
|
|
||||||
|
class CEntitySystem
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CEntitySystem();
|
||||||
|
|
||||||
|
virtual void RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName );
|
||||||
|
virtual C_BaseEntity *CreateByClassname( const char *szName );
|
||||||
|
|
||||||
|
virtual IEntityFactory *GetFactoryByClassname( const char *szName );
|
||||||
|
|
||||||
|
virtual void Think();
|
||||||
|
private:
|
||||||
|
C_BaseEntity *m_pEntities[MAX_EDICTS];
|
||||||
|
int m_nEntityCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
CEntitySystem *EntitySystem();
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -2,12 +2,17 @@
|
|||||||
#include "materialsystem/imaterialsystem.h"
|
#include "materialsystem/imaterialsystem.h"
|
||||||
#include "enginebridge.h"
|
#include "enginebridge.h"
|
||||||
#include "worldrender.h"
|
#include "worldrender.h"
|
||||||
|
#include "entitysystem.h"
|
||||||
|
#include "baseentity.h"
|
||||||
|
#include "game.h"
|
||||||
#include "cglm/mat4.h"
|
#include "cglm/mat4.h"
|
||||||
#include "cglm/cglm.h"
|
#include "cglm/cglm.h"
|
||||||
|
|
||||||
IFileSystem *filesystem;
|
IFileSystem *filesystem;
|
||||||
IRenderContext *g_pRenderContext;
|
IRenderContext *g_pRenderContext;
|
||||||
IGameWindow *g_pMainWindow;
|
IGameWindow *g_pMainWindow;
|
||||||
|
static CEngineVars s_vars;
|
||||||
|
CEngineVars *g_pEngineVars = &s_vars;
|
||||||
|
|
||||||
class CFunnyGameBridge: public IEngineBridge
|
class CFunnyGameBridge: public IEngineBridge
|
||||||
{
|
{
|
||||||
@@ -16,8 +21,6 @@ class CFunnyGameBridge: public IEngineBridge
|
|||||||
virtual void Frame( float fDelta ) override;
|
virtual void Frame( float fDelta ) override;
|
||||||
virtual void Shutdown() override;
|
virtual void Shutdown() override;
|
||||||
virtual void ConnectInterface( const char *psz, void *pInterface ) override;
|
virtual void ConnectInterface( const char *psz, void *pInterface ) override;
|
||||||
IMeshInstance *m_pMeshInstance;
|
|
||||||
float m_fTime = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
IEngineBridge *EngineBridge()
|
IEngineBridge *EngineBridge()
|
||||||
@@ -30,38 +33,9 @@ EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION
|
|||||||
|
|
||||||
void CFunnyGameBridge::Init()
|
void CFunnyGameBridge::Init()
|
||||||
{
|
{
|
||||||
IVertexBuffer *pBuffer;
|
|
||||||
IBuffer *pDataBuffer;
|
|
||||||
IShader *pShader;
|
|
||||||
IMaterial *pMaterial;
|
|
||||||
g_pWorldRenderer->Init();
|
g_pWorldRenderer->Init();
|
||||||
pShader = g_pRenderContext->CreateShader("game/core/shaders/mesh_raster.shader_c");
|
C_BaseEntity *pEntity = EntitySystem()->CreateByClassname("player");
|
||||||
|
pEntity->Spawn();
|
||||||
IFileHandle *pHandle = filesystem->Open("game/core/meshes/cube.fmesh_c", FILEMODE_READ);
|
|
||||||
float *pData = (float*)V_malloc(filesystem->Size(pHandle));
|
|
||||||
filesystem->Read(pHandle, pData, filesystem->Size(pHandle));
|
|
||||||
pBuffer = g_pRenderContext->CreateVertexBuffer(filesystem->Size(pHandle));
|
|
||||||
pBuffer->Lock();
|
|
||||||
void *pMapped = pBuffer->Map();
|
|
||||||
V_memcpy(pMapped, pData, filesystem->Size(pHandle));
|
|
||||||
pBuffer->Unmap();
|
|
||||||
pBuffer->Unlock();
|
|
||||||
V_free(pData);
|
|
||||||
filesystem->Close(pHandle);
|
|
||||||
|
|
||||||
|
|
||||||
IMesh *pMesh = g_pWorldRenderer->CreateMesh("Triangle");
|
|
||||||
g_pWorldRenderer->SetCameraPosition((Vector){0,0,-20});
|
|
||||||
g_pWorldRenderer->SetCameraRotation((Quat){1,0,0,0});
|
|
||||||
|
|
||||||
pMesh->ConfigureShader(pShader);
|
|
||||||
pShader->Build();
|
|
||||||
pMaterial = g_pRenderContext->CreateMaterial(pShader);
|
|
||||||
|
|
||||||
pMesh->SetVertices(pBuffer);
|
|
||||||
pMesh->SetMaterial(pMaterial);
|
|
||||||
m_pMeshInstance = g_pWorldRenderer->CreateInstance(pMesh);
|
|
||||||
m_pMeshInstance->SetScale({5, 5, 5});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFunnyGameBridge::Tick( float fDelta )
|
void CFunnyGameBridge::Tick( float fDelta )
|
||||||
@@ -70,11 +44,9 @@ void CFunnyGameBridge::Tick( float fDelta )
|
|||||||
|
|
||||||
void CFunnyGameBridge::Frame( float fDelta )
|
void CFunnyGameBridge::Frame( float fDelta )
|
||||||
{
|
{
|
||||||
versor q;
|
g_pEngineVars->m_fTime += fDelta;
|
||||||
m_fTime += fDelta;
|
g_pEngineVars->m_fDeltaTime = fDelta;
|
||||||
glm_euler_zyx_quat((vec3){0,m_fTime, 0}, q);
|
EntitySystem()->Think();
|
||||||
m_pMeshInstance->SetPosition({sin(m_fTime/3)*10,0,0});
|
|
||||||
m_pMeshInstance->SetRotation({q[0], q[1], q[2], q[3]});
|
|
||||||
g_pWorldRenderer->Frame(fDelta);
|
g_pWorldRenderer->Frame(fDelta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,21 +1,15 @@
|
|||||||
#include "baseplayer.h"
|
#include "../baseentity.h"
|
||||||
#include "cglm/affine-pre.h"
|
#include "../worldrender.h"
|
||||||
#include "cglm/mat4.h"
|
#include "materialsystem/imaterialsystem.h"
|
||||||
#include "engine.h"
|
#include "game.h"
|
||||||
#include "rendering.h"
|
|
||||||
#include "input.h"
|
|
||||||
#include "fgui/widget.h"
|
|
||||||
#include "fgui/rect.h"
|
|
||||||
#include "fgui/label.h"
|
|
||||||
#include "mesh.h"
|
|
||||||
|
|
||||||
class C_MOBAPlayer: public C_BaseEntity
|
class C_MOBAPlayer: public C_BaseEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
DECLARE_CLASS(C_MOBAPlayer, C_BaseEntity)
|
||||||
virtual void Precache ( void ) override;
|
virtual void Precache ( void ) override;
|
||||||
virtual void Spawn( void ) override;
|
virtual void Spawn( void ) override;
|
||||||
virtual void Destroy( void ) override;
|
virtual void Think( float fDelta );
|
||||||
virtual void Think( float fDelta ) override;
|
|
||||||
|
|
||||||
IMesh *m_pMesh;
|
IMesh *m_pMesh;
|
||||||
IMeshInstance *m_pMeshInstance;
|
IMeshInstance *m_pMeshInstance;
|
||||||
@@ -23,95 +17,56 @@ public:
|
|||||||
|
|
||||||
void C_MOBAPlayer::Precache()
|
void C_MOBAPlayer::Precache()
|
||||||
{
|
{
|
||||||
|
IVertexBuffer *pBuffer;
|
||||||
|
IBuffer *pDataBuffer;
|
||||||
|
IShader *pShader;
|
||||||
|
IMaterial *pMaterial;
|
||||||
|
g_pWorldRenderer->Init();
|
||||||
|
pShader = g_pRenderContext->CreateShader("game/core/shaders/mesh_raster.shader_c");
|
||||||
|
|
||||||
|
IFileHandle *pHandle = filesystem->Open("game/core/meshes/spot.fmesh_c", FILEMODE_READ);
|
||||||
|
float *pData = (float*)V_malloc(filesystem->Size(pHandle));
|
||||||
|
filesystem->Read(pHandle, pData, filesystem->Size(pHandle));
|
||||||
|
pBuffer = g_pRenderContext->CreateVertexBuffer(filesystem->Size(pHandle));
|
||||||
|
pBuffer->Lock();
|
||||||
|
void *pMapped = pBuffer->Map();
|
||||||
|
V_memcpy(pMapped, pData, filesystem->Size(pHandle));
|
||||||
|
pBuffer->Unmap();
|
||||||
|
pBuffer->Unlock();
|
||||||
|
V_free(pData);
|
||||||
|
filesystem->Close(pHandle);
|
||||||
|
|
||||||
|
|
||||||
|
m_pMesh = g_pWorldRenderer->CreateMesh("game/core/meshes/spot.fmesh_c");
|
||||||
|
g_pWorldRenderer->SetCameraPosition((Vector){0,0,-20});
|
||||||
|
g_pWorldRenderer->SetCameraRotation((Quat){1,0,0,0});
|
||||||
|
|
||||||
|
m_pMesh->ConfigureShader(pShader);
|
||||||
|
pShader->Build();
|
||||||
|
pMaterial = g_pRenderContext->CreateMaterial(pShader);
|
||||||
|
|
||||||
|
m_pMesh->SetVertices(pBuffer);
|
||||||
|
m_pMesh->SetMaterial(pMaterial);
|
||||||
|
m_pMeshInstance = g_pWorldRenderer->CreateInstance(m_pMesh);
|
||||||
|
m_pMeshInstance->SetScale({5, 5, 5});
|
||||||
|
m_pMeshInstance->SetPosition({0,0,0});
|
||||||
|
m_pMeshInstance->SetRotation({1,0,0,0});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void C_MOBAPlayer::Spawn()
|
void C_MOBAPlayer::Spawn()
|
||||||
{
|
{
|
||||||
float cubeVertices[] = {
|
Precache();
|
||||||
// Front face
|
SetThink(Think);
|
||||||
-0.1f, -0.1f, 0.1f, 0, 0,
|
|
||||||
0.1f, -0.1f, 0.1f, 1, 0,
|
|
||||||
0.1f, 0.1f, 0.1f, 1, 1,
|
|
||||||
-0.1f, -0.1f, 0.1f, 0, 0,
|
|
||||||
0.1f, 0.1f, 0.1f, 1, 1,
|
|
||||||
-0.1f, 0.1f, 0.1f, 0, 1,
|
|
||||||
|
|
||||||
// Back face
|
|
||||||
0.1f, -0.1f, -0.1f, 0, 0,
|
|
||||||
-0.1f, -0.1f, -0.1f, 1, 0,
|
|
||||||
-0.1f, 0.1f, -0.1f, 1, 1,
|
|
||||||
0.1f, -0.1f, -0.1f, 0, 0,
|
|
||||||
-0.1f, 0.1f, -0.1f, 1, 1,
|
|
||||||
0.1f, 0.1f, -0.1f, 0, 1,
|
|
||||||
|
|
||||||
// Left face
|
|
||||||
-0.1f, -0.1f, -0.1f, 0, 0,
|
|
||||||
-0.1f, -0.1f, 0.1f, 1, 0,
|
|
||||||
-0.1f, 0.1f, 0.1f, 1, 1,
|
|
||||||
-0.1f, -0.1f, -0.1f, 0, 0,
|
|
||||||
-0.1f, 0.1f, 0.1f, 1, 1,
|
|
||||||
-0.1f, 0.1f, -0.1f, 0, 1,
|
|
||||||
|
|
||||||
// Right face
|
|
||||||
0.1f, -0.1f, 0.1f, 0, 0,
|
|
||||||
0.1f, -0.1f, -0.1f, 1, 0,
|
|
||||||
0.1f, 0.1f, -0.1f, 1, 1,
|
|
||||||
0.1f, -0.1f, 0.1f, 0, 0,
|
|
||||||
0.1f, 0.1f, -0.1f, 1, 1,
|
|
||||||
0.1f, 0.1f, 0.1f, 0, 1,
|
|
||||||
|
|
||||||
// Top face
|
|
||||||
-0.1f, 0.1f, 0.1f, 0, 0,
|
|
||||||
0.1f, 0.1f, 0.1f, 1, 0,
|
|
||||||
0.1f, 0.1f, -0.1f, 1, 1,
|
|
||||||
-0.1f, 0.1f, 0.1f, 0, 0,
|
|
||||||
0.1f, 0.1f, -0.1f, 1, 1,
|
|
||||||
-0.1f, 0.1f, -0.1f, 0, 1,
|
|
||||||
|
|
||||||
// Bottom face
|
|
||||||
-0.1f, -0.1f, -0.1f, 0, 0,
|
|
||||||
0.1f, -0.1f, -0.1f, 1, 0,
|
|
||||||
0.1f, -0.1f, 0.1f, 1, 1,
|
|
||||||
-0.1f, -0.1f, -0.1f, 0, 0,
|
|
||||||
0.1f, -0.1f, 0.1f, 1, 1,
|
|
||||||
-0.1f, -0.1f, 0.1f, 0, 1
|
|
||||||
};
|
|
||||||
|
|
||||||
IVertexBuffer *pVertexBuffer = Renderer()->CreateVertexBuffer(sizeof(cubeVertices));
|
|
||||||
void *pMapping = pVertexBuffer->Map();
|
|
||||||
V_memcpy(pMapping, cubeVertices, sizeof(cubeVertices));
|
|
||||||
pVertexBuffer->Unmap();
|
|
||||||
|
|
||||||
m_pMesh = IMeshRendering::CreateMesh();
|
|
||||||
m_pMesh->SetVertexBuffer(0, pVertexBuffer);
|
|
||||||
m_pMeshInstance = m_pMesh->CreateInstance();
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void C_MOBAPlayer::Destroy()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
void C_MOBAPlayer::Think( float fDelta )
|
void C_MOBAPlayer::Think( float fDelta )
|
||||||
{
|
{
|
||||||
float x = g_fAxisValues[AXIS_MOUSE_X];
|
m_pMeshInstance->SetPosition({0,0,-(float)g_pEngineVars->m_fTime});
|
||||||
float y = g_fAxisValues[AXIS_MOUSE_Y];
|
versor v;
|
||||||
float fPitch = glm_rad(x);
|
glm_euler_zxy_quat((vec3){(float)g_pEngineVars->m_fTime,0,0}, v);
|
||||||
float fYaw = glm_rad(y);
|
m_pMeshInstance->SetRotation({v[0], v[1], v[2], v[3]});
|
||||||
if (g_localClient->pBasePlayer == pEntity)
|
|
||||||
{
|
|
||||||
glm_mat4_identity(g_cameraView);
|
|
||||||
glm_rotate_z(g_cameraView, fYaw, g_cameraView);
|
|
||||||
glm_rotate_y(g_cameraView, fPitch, g_cameraView);
|
|
||||||
g_cameraView[3][0] = pEntity->m_position[0];
|
|
||||||
g_cameraView[3][1] = pEntity->m_position[1];
|
|
||||||
g_cameraView[3][2] = pEntity->m_position[2]+0.7;
|
|
||||||
}
|
|
||||||
mat4 m;
|
|
||||||
glm_mat4_identity(m);
|
|
||||||
m_pMeshInstance->SetMatrix(m);
|
|
||||||
m_pMeshInstance->SetPosition(pEntity->m_position);
|
|
||||||
m_pMeshInstance->Draw();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
LINK_CLIENT_ENTITY(C_MOBAPlayer, CMOBAPlayer)
|
LINK_ENTITY_TO_CLASS(player, C_MOBAPlayer)
|
||||||
|
|
||||||
|
|||||||
0
game/client/modelloader.cpp
Normal file
0
game/client/modelloader.cpp
Normal file
0
game/client/modelloader.h
Normal file
0
game/client/modelloader.h
Normal file
@@ -56,7 +56,6 @@ void CFunnyMesh::SetVertices( IVertexBuffer *pBuffer )
|
|||||||
|
|
||||||
void CFunnyMesh::SetIndicies( IIndexBuffer *pBuffer, EIndexFormat eIndexFormat )
|
void CFunnyMesh::SetIndicies( IIndexBuffer *pBuffer, EIndexFormat eIndexFormat )
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFunnyMesh::SetMaterial( IMaterial *pMaterial )
|
void CFunnyMesh::SetMaterial( IMaterial *pMaterial )
|
||||||
@@ -180,7 +179,7 @@ void CFunnyWorldRenderer::Frame( float fDelta )
|
|||||||
uint32_t uWidth = g_pMainWindow->GetRenderWidth();
|
uint32_t uWidth = g_pMainWindow->GetRenderWidth();
|
||||||
uint32_t uHeight = g_pMainWindow->GetRenderHeight();
|
uint32_t uHeight = g_pMainWindow->GetRenderHeight();
|
||||||
mat4 matCamera;
|
mat4 matCamera;
|
||||||
glm_perspective(glm_rad(60), uWidth/(float)uHeight, 0.01, 100, matCamera);
|
glm_perspective(glm_rad(60), uWidth/(float)uHeight, 0.01, 10000, matCamera);
|
||||||
glm_translate(matCamera, m_vPos);
|
glm_translate(matCamera, m_vPos);
|
||||||
/*
|
/*
|
||||||
V_printf("%f %f %f %f\n", matCamera[0][0], matCamera[0][1], matCamera[0][2], matCamera[0][3]);
|
V_printf("%f %f %f %f\n", matCamera[0][0], matCamera[0][1], matCamera[0][2], matCamera[0][3]);
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
class CBaseEntity;
|
class CBaseEntity;
|
||||||
typedef void(*fnThink)( CBaseEntity *pThis );
|
typedef void(*fnThink)( float fTime );
|
||||||
class CBaseEntity
|
class CBaseEntity
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|||||||
@@ -20,6 +20,8 @@ DECLARE_BUILD_STAGE(Server)
|
|||||||
};
|
};
|
||||||
compileProject.includeDirectories = {
|
compileProject.includeDirectories = {
|
||||||
"../../public",
|
"../../public",
|
||||||
|
".",
|
||||||
|
"../shared",
|
||||||
FUNNYSTDLIB"public",
|
FUNNYSTDLIB"public",
|
||||||
EXTERNAL"cglm/include"
|
EXTERNAL"cglm/include"
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -115,6 +115,6 @@ void CEntitySystem::Think()
|
|||||||
if ( !pEntity->m_pfnThink )
|
if ( !pEntity->m_pfnThink )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
pEntity->m_pfnThink(pEntity);
|
pEntity->m_pfnThink(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
109
game/server/milmoba/baseentity.cpp
Normal file
109
game/server/milmoba/baseentity.cpp
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
//================= Copyright kotofyt, All rights reserved ==================//
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
//
|
||||||
|
//===========================================================================//
|
||||||
|
|
||||||
|
#include "baseentity.h"
|
||||||
|
#include "datamap.h"
|
||||||
|
#include "tier0/lib.h"
|
||||||
|
|
||||||
|
CBaseEntity::~CBaseEntity()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBaseEntity::Spawn()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBaseEntity::SetAbsAngles( float fPitch, float fYaw, float fRoll )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBaseEntity::SetAbsOrigin( Vector origin )
|
||||||
|
{
|
||||||
|
m_vPosition = origin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBaseEntity::SetScale( float fScale )
|
||||||
|
{
|
||||||
|
m_vScale.x = fScale;
|
||||||
|
m_vScale.y = fScale;
|
||||||
|
m_vScale.z = fScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QAngle CBaseEntity::GetAbsAngles( void )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector CBaseEntity::GetAbsOrigin( void )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
float CBaseEntity::GetScale( void )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBaseEntity::SetThink( fnThink pfnThink )
|
||||||
|
{
|
||||||
|
m_pfnThink = pfnThink;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CBaseEntity::SetNextThink( float fThink )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
typedescription_t *CBaseEntity::FindDataByName( const char *szName )
|
||||||
|
{
|
||||||
|
datamap_t *pDataMap;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
pDataMap = GetDataMap();
|
||||||
|
|
||||||
|
lookforname:
|
||||||
|
for ( i = 0; i < pDataMap->m_iNumFields; i++ )
|
||||||
|
{
|
||||||
|
if (!V_strcmp(pDataMap->m_pData[i].m_szFieldName, szName))
|
||||||
|
return &pDataMap->m_pData[i];
|
||||||
|
}
|
||||||
|
pDataMap = pDataMap->m_pBase;
|
||||||
|
|
||||||
|
if (pDataMap)
|
||||||
|
goto lookforname;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedescription_t *CBaseEntity::FindDataByMapName( const char *szName )
|
||||||
|
{
|
||||||
|
datamap_t *pDataMap;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
pDataMap = GetDataMap();
|
||||||
|
|
||||||
|
lookforname:
|
||||||
|
for ( i = 0; i < pDataMap->m_iNumFields; i++ )
|
||||||
|
{
|
||||||
|
if (!V_strcmp(pDataMap->m_pData[i].m_szEditorName, szName))
|
||||||
|
return &pDataMap->m_pData[i];
|
||||||
|
}
|
||||||
|
pDataMap = pDataMap->m_pBase;
|
||||||
|
|
||||||
|
if (pDataMap)
|
||||||
|
goto lookforname;
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
BEGIN_DATADESC_NOBASE(CBaseEntity)
|
||||||
|
DEFINE_KEYFIELD(m_vPosition, FIELD_VECTOR, "origin")
|
||||||
|
DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles")
|
||||||
|
DEFINE_KEYFIELD(m_vScale, FIELD_VECTOR, "scales")
|
||||||
|
END_DATADESC()
|
||||||
79
game/server/milmoba/baseentity.h
Normal file
79
game/server/milmoba/baseentity.h
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
//================= Copyright kotofyt, All rights reserved ==================//
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
//
|
||||||
|
//===========================================================================//
|
||||||
|
|
||||||
|
#ifndef BASEENTITY_H
|
||||||
|
#define BASEENTITY_H
|
||||||
|
|
||||||
|
#include "entitysystem.h"
|
||||||
|
#include "datamap.h"
|
||||||
|
#include "cglm/cglm.h"
|
||||||
|
#include "trig.h"
|
||||||
|
|
||||||
|
#define DECLARE_CLASS_NOBASE( className ) \
|
||||||
|
typedef className ThisClass;
|
||||||
|
#define DECLARE_CLASS( className, baseName ) \
|
||||||
|
typedef baseName BaseClass; \
|
||||||
|
typedef className ThisClass;
|
||||||
|
|
||||||
|
#define LINK_ENTITY_TO_CLASS( mapClassName, DLLClassName) \
|
||||||
|
static CEntityFactory<DLLClassName> g_EntityFactory_##mapClassName( #mapClassName );
|
||||||
|
|
||||||
|
class CBaseEntity;
|
||||||
|
|
||||||
|
class IEntityFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual CBaseEntity *Create() = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
class CEntityFactory : public IEntityFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CEntityFactory( const char *szClassName )
|
||||||
|
{
|
||||||
|
EntitySystem()->RegisterEntityClass(this, szClassName);
|
||||||
|
};
|
||||||
|
virtual CBaseEntity *Create() {
|
||||||
|
return new T;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class CBaseEntity;
|
||||||
|
typedef void(*fnThink)( CBaseEntity *pThis );
|
||||||
|
class CBaseEntity
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DECLARE_CLASS_NOBASE(CBaseEntity);
|
||||||
|
DECLARE_DATADESC_NOBASE()
|
||||||
|
|
||||||
|
typedescription_t *FindDataByName( const char *szName );
|
||||||
|
typedescription_t *FindDataByMapName( const char *szName );
|
||||||
|
|
||||||
|
virtual ~CBaseEntity();
|
||||||
|
virtual void Spawn();
|
||||||
|
|
||||||
|
virtual void SetAbsAngles( float fPitch, float fYaw, float fRoll );
|
||||||
|
virtual void SetAbsOrigin( Vector origin );
|
||||||
|
virtual void SetScale( float fScale );
|
||||||
|
|
||||||
|
virtual QAngle GetAbsAngles( void );
|
||||||
|
virtual Vector GetAbsOrigin( void );
|
||||||
|
virtual float GetScale( void );
|
||||||
|
|
||||||
|
virtual void SetThink( fnThink pfnThink );
|
||||||
|
virtual void SetNextThink( float fThink );
|
||||||
|
|
||||||
|
fnThink m_pfnThink = NULL;
|
||||||
|
private:
|
||||||
|
Vector m_vPosition;
|
||||||
|
Quat m_vRotation;
|
||||||
|
Vector m_vScale;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
44
game/server/milmoba/build.cpp
Normal file
44
game/server/milmoba/build.cpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#include "helper.h"
|
||||||
|
#include "c.h"
|
||||||
|
#include "ld.h"
|
||||||
|
|
||||||
|
#define EXTERNAL "../../external/"
|
||||||
|
#define FUNNYSTDLIB EXTERNAL"funnystdlib/"
|
||||||
|
ADD_DEPENDENCY_BUILD_FILE(tier0, FUNNYSTDLIB"tier0/build.cpp");
|
||||||
|
ADD_DEPENDENCY_BUILD_FILE(tier1, FUNNYSTDLIB"tier1/build.cpp");
|
||||||
|
ADD_DEPENDENCY_BUILD_FILE(tier2, FUNNYSTDLIB"tier2/build.cpp");
|
||||||
|
DECLARE_BUILD_STAGE(Server)
|
||||||
|
{
|
||||||
|
CProject_t compileProject = {};
|
||||||
|
LinkProject_t ldProject = {};
|
||||||
|
|
||||||
|
compileProject.m_szName = "server";
|
||||||
|
compileProject.files = {
|
||||||
|
"game.cpp",
|
||||||
|
"entitysystem.cpp",
|
||||||
|
"baseentity.cpp",
|
||||||
|
};
|
||||||
|
compileProject.includeDirectories = {
|
||||||
|
"../../public",
|
||||||
|
FUNNYSTDLIB"public",
|
||||||
|
EXTERNAL"cglm/include"
|
||||||
|
};
|
||||||
|
compileProject.bFPIC = true;
|
||||||
|
ldProject = ccompiler->Compile(&compileProject);
|
||||||
|
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
|
||||||
|
ldProject.libraryObjects = {
|
||||||
|
GET_PROJECT_LIBRARY(tier0, "tier0"),
|
||||||
|
};
|
||||||
|
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier1, "tier1")});
|
||||||
|
ldProject.objects.AppendTail({GET_PROJECT_LIBRARY(tier2, "tier2")});
|
||||||
|
|
||||||
|
if (ldProject.m_target.kernel & TARGET_KERNEL_WINDOWS_DEVICES)
|
||||||
|
{
|
||||||
|
ldProject.libraries.AppendTail("pthread");
|
||||||
|
};
|
||||||
|
|
||||||
|
CUtlString outputProject = linker->Link(&ldProject);
|
||||||
|
ADD_OUTPUT_OBJECT("server", outputProject);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
97
game/server/milmoba/datamap.h
Normal file
97
game/server/milmoba/datamap.h
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
//================= Copyright kotofyt, All rights reserved ==================//
|
||||||
|
//
|
||||||
|
// Purpose: Valve-styled entity data maps
|
||||||
|
//
|
||||||
|
// Note: This file is insipired by Valve's convention in Source SDK, but it
|
||||||
|
// was written for scratch with compatibility in mind.
|
||||||
|
//
|
||||||
|
//===========================================================================//
|
||||||
|
|
||||||
|
#ifndef DATAMAP_H
|
||||||
|
#define DATAMAP_H
|
||||||
|
#include "stddef.h"
|
||||||
|
|
||||||
|
enum fieldtype_t {
|
||||||
|
FIELD_VOID = 0,
|
||||||
|
FIELD_FLOAT,
|
||||||
|
FIELD_STRING,
|
||||||
|
FIELD_VECTOR2D,
|
||||||
|
FIELD_VECTOR,
|
||||||
|
FIELD_VECTOR4D,
|
||||||
|
FIELD_QUATERNION,
|
||||||
|
FIELD_QUATERNION_QANGLE,
|
||||||
|
FIELD_COLOR255,
|
||||||
|
FIELD_COLOR1,
|
||||||
|
FIELD_INTEGER,
|
||||||
|
FIELD_BOOLEAN,
|
||||||
|
|
||||||
|
FIELD_MATERIAL,
|
||||||
|
FIELD_TEXTURE,
|
||||||
|
FIELD_MODEL,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct typedescription_t
|
||||||
|
{
|
||||||
|
const char *m_szFieldName;
|
||||||
|
const char *m_szEditorName;
|
||||||
|
fieldtype_t m_eFieldType;
|
||||||
|
size_t m_iFieldOffset;
|
||||||
|
unsigned int m_uFieldCount;
|
||||||
|
unsigned short m_uFieldSize;
|
||||||
|
unsigned int m_iFlags;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct datamap_t
|
||||||
|
{
|
||||||
|
struct datamap_t *m_pBase;
|
||||||
|
|
||||||
|
typedescription_t *m_pData;
|
||||||
|
int m_iNumFields;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define DECLARE_DATADESC() \
|
||||||
|
datamap_t *GetBaseMap(); \
|
||||||
|
virtual datamap_t *GetDataMap() override; \
|
||||||
|
virtual datamap_t DataMapInit() override;
|
||||||
|
|
||||||
|
#define DECLARE_DATADESC_NOBASE() \
|
||||||
|
datamap_t *GetBaseMap(); \
|
||||||
|
virtual datamap_t *GetDataMap(); \
|
||||||
|
virtual datamap_t DataMapInit();
|
||||||
|
|
||||||
|
#define BEGIN_DATADESC( className ) \
|
||||||
|
datamap_t *className::GetBaseMap() { return BaseClass::GetDataMap(); } \
|
||||||
|
BEGIN_DATADESC_INTERNAL(className)
|
||||||
|
#define BEGIN_DATADESC_NOBASE( className ) \
|
||||||
|
datamap_t *className::GetBaseMap() { return NULL; } \
|
||||||
|
BEGIN_DATADESC_INTERNAL(className)
|
||||||
|
|
||||||
|
#define BEGIN_DATADESC_INTERNAL( className ) \
|
||||||
|
datamap_t *className::GetDataMap() { static datamap_t s_DataMap = ThisClass::DataMapInit(); return &s_DataMap; } \
|
||||||
|
datamap_t className::DataMapInit() \
|
||||||
|
{ \
|
||||||
|
datamap_t map; \
|
||||||
|
map.m_pBase = ThisClass::GetBaseMap(); \
|
||||||
|
static typedescription_t dataDesc[] \
|
||||||
|
{\
|
||||||
|
|
||||||
|
#define END_DATADESC() \
|
||||||
|
};\
|
||||||
|
map.m_iNumFields = sizeof(dataDesc)/sizeof(typedescription_t); \
|
||||||
|
map.m_pData = dataDesc; \
|
||||||
|
return map; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define IMPLEMENT_NULL_DATADESC( className ) \
|
||||||
|
BEGIN_DATADESC(className) \
|
||||||
|
END_DATADESC()
|
||||||
|
|
||||||
|
#define _class_offsetof( class, var ) ((size_t)&(((class*)0)->var))
|
||||||
|
|
||||||
|
#define _FIELD( name, fieldtype, count, flags, mapname, tolerance) { #name, mapname, fieldtype, _class_offsetof(ThisClass, name), count, sizeof(((ThisClass*)0)->name), flags },
|
||||||
|
#define DEFINE_KEYFIELD( name, fieldtype, mapname ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, mapname, 0)
|
||||||
|
|
||||||
|
#define FTYPEDESC_KEY 0x0004
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
120
game/server/milmoba/entitysystem.cpp
Normal file
120
game/server/milmoba/entitysystem.cpp
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
//================= Copyright kotofyt, All rights reserved ==================//
|
||||||
|
//
|
||||||
|
// Purpose:
|
||||||
|
//
|
||||||
|
//===========================================================================//
|
||||||
|
|
||||||
|
#include "entitysystem.h"
|
||||||
|
#include "baseentity.h"
|
||||||
|
#include "stddef.h"
|
||||||
|
#include "string.h"
|
||||||
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
|
||||||
|
CEntitySystem *EntitySystem()
|
||||||
|
{
|
||||||
|
static CEntitySystem s_entitySystem;
|
||||||
|
return &s_entitySystem;
|
||||||
|
}
|
||||||
|
|
||||||
|
static struct EntityRegistry_t
|
||||||
|
{
|
||||||
|
IEntityFactory *m_pFactory;
|
||||||
|
const char *m_szClassName;
|
||||||
|
struct EntityRegistry_t *m_pNext;
|
||||||
|
} *s_pEntitiesRegistry = NULL;
|
||||||
|
|
||||||
|
CEntitySystem::CEntitySystem()
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
for ( i = 0; i < MAX_EDICTS; i++ )
|
||||||
|
{
|
||||||
|
m_pEntities[i] = NULL;
|
||||||
|
}
|
||||||
|
m_nEntityCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CEntitySystem::RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName )
|
||||||
|
{
|
||||||
|
IEntityFactory *pFactory;
|
||||||
|
EntityRegistry_t *pRegistry;
|
||||||
|
|
||||||
|
pFactory = GetFactoryByClassname(szClassName);
|
||||||
|
|
||||||
|
if ( pFactory != NULL )
|
||||||
|
{
|
||||||
|
// Already registered
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
pRegistry = new EntityRegistry_t;
|
||||||
|
pRegistry->m_pFactory = pEntityFactory;
|
||||||
|
pRegistry->m_pNext = s_pEntitiesRegistry;
|
||||||
|
pRegistry->m_szClassName = szClassName;
|
||||||
|
s_pEntitiesRegistry = pRegistry;
|
||||||
|
}
|
||||||
|
|
||||||
|
CBaseEntity *CEntitySystem::CreateByClassname( const char *szName )
|
||||||
|
{
|
||||||
|
IEntityFactory *pFactory;
|
||||||
|
CBaseEntity *pEntity;
|
||||||
|
int i;
|
||||||
|
int iSelectedSlot;
|
||||||
|
|
||||||
|
pFactory = GetFactoryByClassname(szName);
|
||||||
|
if ( !pFactory )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// We do not want to have more than MAX_EDICT entities
|
||||||
|
if ( m_nEntityCount >= MAX_EDICTS-1 )
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
// Search for space
|
||||||
|
// Could be more efficient but nobody cares
|
||||||
|
for ( i = 0; i < MAX_EDICTS; i++ )
|
||||||
|
{
|
||||||
|
if ( m_pEntities[i] == NULL )
|
||||||
|
{
|
||||||
|
iSelectedSlot = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pEntity = pFactory->Create();
|
||||||
|
m_pEntities[iSelectedSlot] = pEntity;
|
||||||
|
m_nEntityCount++;
|
||||||
|
return pEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
IEntityFactory *CEntitySystem::GetFactoryByClassname( const char *szName )
|
||||||
|
{
|
||||||
|
EntityRegistry_t *pEntity;
|
||||||
|
|
||||||
|
for ( pEntity = s_pEntitiesRegistry; pEntity; pEntity = pEntity->m_pNext )
|
||||||
|
{
|
||||||
|
if (!strcmp(szName, pEntity->m_szClassName))
|
||||||
|
{
|
||||||
|
return pEntity->m_pFactory;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CEntitySystem::Think()
|
||||||
|
{
|
||||||
|
CBaseEntity *pEntity;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for ( i = 0; i < MAX_EDICTS; i++ )
|
||||||
|
{
|
||||||
|
pEntity = m_pEntities[i];
|
||||||
|
if ( pEntity == NULL )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if ( !pEntity->m_pfnThink )
|
||||||
|
continue;
|
||||||
|
|
||||||
|
pEntity->m_pfnThink(pEntity);
|
||||||
|
}
|
||||||
|
}
|
||||||
49
game/server/milmoba/game.cpp
Normal file
49
game/server/milmoba/game.cpp
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
#include "tier2/ifilesystem.h"
|
||||||
|
#include "materialsystem/imaterialsystem.h"
|
||||||
|
#include "enginebridge.h"
|
||||||
|
|
||||||
|
IFileSystem *filesystem;
|
||||||
|
IRenderContext *g_pRenderContext;
|
||||||
|
IGameWindow *g_pMainWindow;
|
||||||
|
|
||||||
|
class CFunnyGameBridge: public IEngineBridge
|
||||||
|
{
|
||||||
|
virtual void Init() override;
|
||||||
|
virtual void Tick( float fDelta ) override;
|
||||||
|
virtual void Frame( float fDelta ) override;
|
||||||
|
virtual void Shutdown() override;
|
||||||
|
virtual void ConnectInterface( const char *psz, void *pInterface ) override;
|
||||||
|
};
|
||||||
|
|
||||||
|
IEngineBridge *EngineBridge()
|
||||||
|
{
|
||||||
|
static CFunnyGameBridge s_bridge;
|
||||||
|
return &s_bridge;
|
||||||
|
}
|
||||||
|
|
||||||
|
EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION)
|
||||||
|
|
||||||
|
void CFunnyGameBridge::Init()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFunnyGameBridge::Tick( float fDelta )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFunnyGameBridge::Frame( float fDelta )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFunnyGameBridge::Shutdown()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#define CONNECT_INTERFACE(szName, pGlobal) if (!V_strcmp(psz, szName)) { pGlobal = (typeof(pGlobal))pInterface; return; }
|
||||||
|
void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface )
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
97
game/shared/datamap.h
Normal file
97
game/shared/datamap.h
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
//================= Copyright kotofyt, All rights reserved ==================//
|
||||||
|
//
|
||||||
|
// Purpose: Valve-styled entity data maps
|
||||||
|
//
|
||||||
|
// Note: This file is insipired by Valve's convention in Source SDK, but it
|
||||||
|
// was written for scratch with compatibility in mind.
|
||||||
|
//
|
||||||
|
//===========================================================================//
|
||||||
|
|
||||||
|
#ifndef DATAMAP_H
|
||||||
|
#define DATAMAP_H
|
||||||
|
#include "stddef.h"
|
||||||
|
|
||||||
|
enum fieldtype_t {
|
||||||
|
FIELD_VOID = 0,
|
||||||
|
FIELD_FLOAT,
|
||||||
|
FIELD_STRING,
|
||||||
|
FIELD_VECTOR2D,
|
||||||
|
FIELD_VECTOR,
|
||||||
|
FIELD_VECTOR4D,
|
||||||
|
FIELD_QUATERNION,
|
||||||
|
FIELD_QUATERNION_QANGLE,
|
||||||
|
FIELD_COLOR255,
|
||||||
|
FIELD_COLOR1,
|
||||||
|
FIELD_INTEGER,
|
||||||
|
FIELD_BOOLEAN,
|
||||||
|
|
||||||
|
FIELD_MATERIAL,
|
||||||
|
FIELD_TEXTURE,
|
||||||
|
FIELD_MODEL,
|
||||||
|
};
|
||||||
|
|
||||||
|
struct typedescription_t
|
||||||
|
{
|
||||||
|
const char *m_szFieldName;
|
||||||
|
const char *m_szEditorName;
|
||||||
|
fieldtype_t m_eFieldType;
|
||||||
|
size_t m_iFieldOffset;
|
||||||
|
unsigned int m_uFieldCount;
|
||||||
|
unsigned short m_uFieldSize;
|
||||||
|
unsigned int m_iFlags;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct datamap_t
|
||||||
|
{
|
||||||
|
struct datamap_t *m_pBase;
|
||||||
|
|
||||||
|
typedescription_t *m_pData;
|
||||||
|
int m_iNumFields;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define DECLARE_DATADESC() \
|
||||||
|
datamap_t *GetBaseMap(); \
|
||||||
|
virtual datamap_t *GetDataMap() override; \
|
||||||
|
virtual datamap_t DataMapInit() override;
|
||||||
|
|
||||||
|
#define DECLARE_DATADESC_NOBASE() \
|
||||||
|
datamap_t *GetBaseMap(); \
|
||||||
|
virtual datamap_t *GetDataMap(); \
|
||||||
|
virtual datamap_t DataMapInit();
|
||||||
|
|
||||||
|
#define BEGIN_DATADESC( className ) \
|
||||||
|
datamap_t *className::GetBaseMap() { return BaseClass::GetDataMap(); } \
|
||||||
|
BEGIN_DATADESC_INTERNAL(className)
|
||||||
|
#define BEGIN_DATADESC_NOBASE( className ) \
|
||||||
|
datamap_t *className::GetBaseMap() { return NULL; } \
|
||||||
|
BEGIN_DATADESC_INTERNAL(className)
|
||||||
|
|
||||||
|
#define BEGIN_DATADESC_INTERNAL( className ) \
|
||||||
|
datamap_t *className::GetDataMap() { static datamap_t s_DataMap = ThisClass::DataMapInit(); return &s_DataMap; } \
|
||||||
|
datamap_t className::DataMapInit() \
|
||||||
|
{ \
|
||||||
|
datamap_t map; \
|
||||||
|
map.m_pBase = ThisClass::GetBaseMap(); \
|
||||||
|
static typedescription_t dataDesc[] \
|
||||||
|
{\
|
||||||
|
|
||||||
|
#define END_DATADESC() \
|
||||||
|
};\
|
||||||
|
map.m_iNumFields = sizeof(dataDesc)/sizeof(typedescription_t); \
|
||||||
|
map.m_pData = dataDesc; \
|
||||||
|
return map; \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define IMPLEMENT_NULL_DATADESC( className ) \
|
||||||
|
BEGIN_DATADESC(className) \
|
||||||
|
END_DATADESC()
|
||||||
|
|
||||||
|
#define _class_offsetof( class, var ) ((size_t)&(((class*)0)->var))
|
||||||
|
|
||||||
|
#define _FIELD( name, fieldtype, count, flags, mapname, tolerance) { #name, mapname, fieldtype, _class_offsetof(ThisClass, name), count, sizeof(((ThisClass*)0)->name), flags },
|
||||||
|
#define DEFINE_KEYFIELD( name, fieldtype, mapname ) _FIELD( name, fieldtype, 1, FTYPEDESC_KEY, mapname, 0)
|
||||||
|
|
||||||
|
#define FTYPEDESC_KEY 0x0004
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
17
game/shared/game.h
Normal file
17
game/shared/game.h
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef GAME_H
|
||||||
|
#define GAME_H
|
||||||
|
#include "tier2/ifilesystem.h"
|
||||||
|
#include "materialsystem/imaterialsystem.h"
|
||||||
|
extern IRenderContext *g_pRenderContext;
|
||||||
|
extern IFileSystem *filesystem;
|
||||||
|
extern IGameWindowManager *g_pWindowManager;
|
||||||
|
|
||||||
|
class CEngineVars
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
double m_fTime;
|
||||||
|
double m_fDeltaTime;
|
||||||
|
};
|
||||||
|
|
||||||
|
extern CEngineVars *g_pEngineVars;
|
||||||
|
#endif
|
||||||
Reference in New Issue
Block a user