lots of updates

This commit is contained in:
2026-02-19 00:39:20 +02:00
parent 898bf90504
commit 4dd2e13c48
53 changed files with 1495 additions and 250 deletions

View File

@@ -1,38 +0,0 @@
#include "helper.h"
#include "c.h"
#include "ld.h"
#include "tier1/utlstring.h"
#include "tier1/commandline.h"
CUtlVector<CUtlString> client_CompiledFiles = {
};
DECLARE_BUILD_STAGE(client)
{
CProject_t compileProject = {};
LinkProject_t ldProject = {};
compileProject.m_szName = "client";
compileProject.files = client_CompiledFiles;
compileProject.includeDirectories = all_IncludeDirectories;
compileProject.bFPIC = true;
ldProject = ccompiler->Compile(&compileProject);
if (bStaticBuild)
ldProject.linkType = ELINK_STATIC_LIBRARY;
else
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
CUtlString outputProject = linker->Link(&ldProject);
/*
if (!bStaticBuild)
{
filesystem2->MakeDirectory(CUtlString("%s/funnygame/bin",szOutputDir.GetString()));
filesystem2->CopyFile(CUtlString("%s/funnygame/bin", szOutputDir.GetString()), outputProject);
} else {
client_lib = outputProject;
}
*/
return 0;
};

43
game/client/build.cpp Normal file
View File

@@ -0,0 +1,43 @@
#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(Client)
{
CProject_t compileProject = {};
LinkProject_t ldProject = {};
compileProject.m_szName = "client";
compileProject.files = {
"game.cpp",
"worldrender.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("client", outputProject);
return 0;
}

12
game/client/engine.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef ENGINE_H
#define ENGINE_H
#include "tier2/ifilesystem.h"
#include "materialsystem/imaterialsystem.h"
#include "materialsystem/igamewindow.h"
extern IFileSystem *filesystem;
extern IRenderContext *g_pRenderContext;
extern IGameWindow *g_pMainWindow;
#endif

94
game/client/game.cpp Normal file
View File

@@ -0,0 +1,94 @@
#include "tier2/ifilesystem.h"
#include "materialsystem/imaterialsystem.h"
#include "enginebridge.h"
#include "worldrender.h"
#include "cglm/mat4.h"
#include "cglm/cglm.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()
{
IVertexBuffer *pBuffer;
IBuffer *pDataBuffer;
IShader *pShader;
IMaterial *pMaterial;
g_pWorldRenderer->Init();
pShader = g_pRenderContext->CreateShader("game/core/shaders/mesh_raster.shader_c");
float cubeVertices[][3] = {
{-1, -1, 1}, { 1, -1, 1}, { 1, 1, 1},
{-1, -1, 1}, { 1, 1, 1}, {-1, 1, 1},
{-1, -1, -1}, {-1, 1, -1}, { 1, 1, -1},
{-1, -1, -1}, { 1, 1, -1}, { 1, -1, -1},
{-1, -1, -1}, {-1, -1, 1}, {-1, 1, 1},
{-1, -1, -1}, {-1, 1, 1}, {-1, 1, -1},
{ 1, -1, -1}, { 1, 1, -1}, { 1, 1, 1},
{ 1, -1, -1}, { 1, 1, 1}, { 1, -1, 1},
{-1, 1, -1}, {-1, 1, 1}, { 1, 1, 1},
{-1, 1, -1}, { 1, 1, 1}, { 1, 1, -1},
{-1, -1, -1}, { 1, -1, -1}, { 1, -1, 1},
{-1, -1, -1}, { 1, -1, 1}, {-1, -1, 1}
};
pBuffer = g_pRenderContext->CreateVertexBuffer(sizeof(cubeVertices));
pBuffer->Lock();
void *pMapped = pBuffer->Map();
V_memcpy(pMapped, cubeVertices, sizeof(cubeVertices));
pBuffer->Unmap();
pBuffer->Unlock();
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);
IMeshInstance *pMeshInstance = g_pWorldRenderer->CreateInstance(pMesh);
pMeshInstance->SetPosition({1,1,1});
}
void CFunnyGameBridge::Tick( float fDelta )
{
}
void CFunnyGameBridge::Frame( float fDelta )
{
g_pWorldRenderer->Frame(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 )
{
CONNECT_INTERFACE(RENDER_CONTEXT_INTERFACE_VERSION, g_pRenderContext);
CONNECT_INTERFACE("MainWindow", g_pMainWindow);
}

269
game/client/worldrender.cpp Normal file
View File

@@ -0,0 +1,269 @@
#include "worldrender.h"
#include "tier1/utlstring.h"
#include "engine.h"
#include "cglm/cglm.h"
#include "cglm/quat.h"
#include "cglm/mat4.h"
struct ViewBuffer_t
{
mat4 m_matCameraProjection;
};
struct PerMeshData_t
{
mat4 m_matTranslation;
};
class CFunnyMeshInstance;
class CFunnyMesh: public IMesh
{
public:
virtual void ConfigureShader( IShader *pShader ) override;
virtual void SetVertices( IVertexBuffer *pBuffer ) override;
virtual void SetIndicies( IIndexBuffer *pBuffer, EIndexFormat eIndexFormat ) override;
virtual void SetMaterial( IMaterial *pMaterial ) override;
CUtlString m_szName;
CUtlVector<CFunnyMeshInstance*> m_instances;
IMaterial *m_pMaterial;
IVertexBuffer *m_pVertexBuffer;
};
void CFunnyMesh::ConfigureShader( IShader *pShader )
{
pShader->AddLayout(0, 12);
pShader->AddAttribute(0, 0, VERTEX_FORMAT_XYZ32_SFLOAT, 0);
// color
pShader->AddOutputImage(0, IMAGE_FORMAT_RGBA8_UNORM);
pShader->SetDepthImage(IMAGE_FORMAT_D32_SFLOAT);
}
void CFunnyMesh::SetVertices( IVertexBuffer *pBuffer )
{
m_pVertexBuffer = pBuffer;
}
void CFunnyMesh::SetIndicies( IIndexBuffer *pBuffer, EIndexFormat eIndexFormat )
{
}
void CFunnyMesh::SetMaterial( IMaterial *pMaterial )
{
m_pMaterial = pMaterial;
}
class CFunnyMeshInstance: public IMeshInstance
{
public:
virtual void SetPosition( Vector vPosition ) override;
virtual void SetRotation( Quat vRotation ) override;
virtual void SetScale( Vector vScale ) override;
virtual void Frame();
PerMeshData_t m_data = {};
Quat m_vRotation = {};
Vector m_vPosition = {};
Vector m_vScale = {};
};
void CFunnyMeshInstance::SetPosition( Vector vPosition )
{
m_vPosition = vPosition;
}
void CFunnyMeshInstance::SetRotation( Quat vRotation )
{
m_vRotation = vRotation;
}
void CFunnyMeshInstance::SetScale( Vector vScale )
{
m_vScale = vScale;
}
void CFunnyMeshInstance::Frame()
{
glm_mat4_identity(m_data.m_matTranslation);
}
class CFunnyWorldRenderer: public IWorldRenderer
{
public:
virtual void Init() override;
virtual void Tick( float fDelta ) override;
virtual void Frame( float fDelta ) override;
virtual void Shutdown() override;
virtual void SetCameraRotation( Quat vRotation ) override;
virtual void SetCameraPosition( Vector vPosition ) override;
virtual IMesh *CreateMesh( const char *szName ) override;
virtual IMeshInstance *CreateInstance( IMesh *pMesh ) override;
private:
CUtlVector<CFunnyMesh*> m_pMeshes;
IImage *m_pOutputImage = NULL;
IImage *m_pDepthImage = NULL;
IRenderCommandList *m_pRasterCommandList = NULL;
IBuffer *m_pViewBuffer;
ViewBuffer_t *m_pViewBufferData;
vec3 m_vPos;
versor m_vRot;
};
static CFunnyWorldRenderer s_renderer;
IWorldRenderer *g_pWorldRenderer = &s_renderer;
void CFunnyWorldRenderer::Init()
{
m_pOutputImage = g_pRenderContext->CreateRenderTarget(
100,
100,
IMAGE_FORMAT_RGBA8_UNORM,
MULTISAMPLE_TYPE_NONE
);
m_pDepthImage = g_pRenderContext->CreateRenderTarget(
100,
100,
IMAGE_FORMAT_D32_SFLOAT,
MULTISAMPLE_TYPE_NONE
);
g_pMainWindow->SetOutputImage(m_pOutputImage);
m_pRasterCommandList = g_pRenderContext->CreateCommandList();
m_pViewBuffer = g_pRenderContext->CreateConstantBuffer(sizeof(ViewBuffer_t));
}
void CFunnyWorldRenderer::Tick( float fDelta )
{
}
void CFunnyWorldRenderer::Frame( float fDelta )
{
uint32_t uWidth = g_pMainWindow->GetRenderWidth();
uint32_t uHeight = g_pMainWindow->GetRenderHeight();
mat4 matCamera;
glm_perspective(glm_rad(60), uWidth/(float)uHeight, 0.01, 100, matCamera);
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[1][0], matCamera[1][1], matCamera[1][2], matCamera[1][3]);
V_printf("%f %f %f %f\n", matCamera[2][0], matCamera[2][1], matCamera[2][2], matCamera[2][3]);
V_printf("%f %f %f %f\n", matCamera[3][0], matCamera[3][1], matCamera[3][2], matCamera[3][3]);
*/
m_pViewBufferData = (ViewBuffer_t*)m_pViewBuffer->Map();
m_pViewBuffer->Lock();
V_memcpy(m_pViewBufferData, matCamera, sizeof(matCamera));
m_pViewBuffer->Unlock();
m_pViewBuffer->Unmap();
if (g_pMainWindow->BRenderSizeUpdated())
{
g_pRenderContext->DestroyImage(m_pOutputImage);
m_pOutputImage = g_pRenderContext->CreateRenderTarget(
g_pMainWindow->GetRenderWidth(),
g_pMainWindow->GetRenderHeight(),
IMAGE_FORMAT_RGBA8_UNORM,
MULTISAMPLE_TYPE_NONE);
g_pRenderContext->DestroyImage(m_pOutputImage);
m_pDepthImage = g_pRenderContext->CreateRenderTarget(
g_pMainWindow->GetRenderWidth(),
g_pMainWindow->GetRenderHeight(),
IMAGE_FORMAT_D32_SFLOAT,
MULTISAMPLE_TYPE_NONE);
g_pMainWindow->SetOutputImage(m_pOutputImage);
}
m_pRasterCommandList->StartRecording();
m_pRasterCommandList->SetRenderResolution(uWidth, uHeight);
m_pRasterCommandList->SetRenderTarget(0, m_pOutputImage);
m_pRasterCommandList->SetDepthTarget(m_pDepthImage);
m_pRasterCommandList->SetViewport(0, 0, uWidth, uHeight, 0, 1);
m_pRasterCommandList->SetScissors(0, 0, uWidth, uHeight);
m_pRasterCommandList->SetClearColor(0, 0, 0, 0, 0);
m_pRasterCommandList->SetClearDepth(1);
for ( auto mesh: m_pMeshes)
{
if (mesh->m_instances.GetSize()==0)
continue;
CUtlVector<PerMeshData_t> data = {};
data.Reserve(mesh->m_instances.GetSize());
for ( auto instance: mesh->m_instances )
{
instance->Frame();
data.AppendTail(instance->m_data);
}
IBuffer *pDataBuffer = g_pRenderContext->CreateStorageBuffer(data.GetSize()*sizeof(PerMeshData_t));
pDataBuffer->Lock();
void *pData = pDataBuffer->Map();
for ( uint32_t i = 0; i < mesh->m_instances.GetSize(); i++ )
{
V_memcpy(&((PerMeshData_t*)pData)[i], &mesh->m_instances[i]->m_data, sizeof(PerMeshData_t));
}
pDataBuffer->Unmap();
pDataBuffer->Unlock();
mesh->m_pMaterial->VSSetConstantsBuffer(0, m_pViewBuffer);
mesh->m_pMaterial->VSSetConstantsBuffer(1, pDataBuffer);
g_pRenderContext->DestroyBuffer(pDataBuffer);
}
for ( auto mesh: m_pMeshes)
{
if (mesh->m_instances.GetSize()==0)
continue;
m_pRasterCommandList->SetMaterial(mesh->m_pMaterial);
m_pRasterCommandList->SetVertexBuffer(0, mesh->m_pVertexBuffer);
m_pRasterCommandList->DrawPrimitives(mesh->m_pVertexBuffer->GetSize()/12, 0, mesh->m_instances.GetSize(), 0);
}
m_pRasterCommandList->EndRecording();
g_pRenderContext->SubmitCommandList(m_pRasterCommandList);
}
void CFunnyWorldRenderer::Shutdown()
{
}
void CFunnyWorldRenderer::SetCameraRotation( Quat vRotation )
{
m_vRot[0] = vRotation.x;
m_vRot[1] = vRotation.y;
m_vRot[2] = vRotation.z;
m_vRot[3] = vRotation.w;
}
void CFunnyWorldRenderer::SetCameraPosition( Vector vPosition )
{
m_vPos[0] = vPosition.x;
m_vPos[1] = vPosition.y;
m_vPos[2] = vPosition.z;
}
IMesh *CFunnyWorldRenderer::CreateMesh( const char *szName )
{
CFunnyMesh *pMesh = new CFunnyMesh;
pMesh->m_szName = szName;
m_pMeshes.AppendTail(pMesh);
return pMesh;
}
IMeshInstance *CFunnyWorldRenderer::CreateInstance( IMesh *pMesh )
{
CFunnyMesh *pFunnyMesh = (CFunnyMesh*)pMesh;
CFunnyMeshInstance *pInstance = new CFunnyMeshInstance;
pFunnyMesh->m_instances.AppendTail(pInstance);
return pInstance;
}

40
game/client/worldrender.h Normal file
View File

@@ -0,0 +1,40 @@
#ifndef WORLD_RENDER_H
#define WORLD_RENDER_H
#include "tier0/platform.h"
#include "gamesystem.h"
#include "trig.h"
#include "materialsystem/imaterialsystem.h"
abstract_class IMesh
{
public:
virtual void ConfigureShader( IShader *pShader ) = 0;
virtual void SetVertices( IVertexBuffer *pBuffer ) = 0;
virtual void SetIndicies( IIndexBuffer *pBuffer, EIndexFormat eIndexFormat ) = 0;
virtual void SetMaterial( IMaterial *pMaterial ) = 0;
};
abstract_class IMeshInstance
{
public:
virtual void SetPosition( Vector vPosition ) = 0;
virtual void SetRotation( Quat vRotation ) = 0;
virtual void SetScale( Vector vScale ) = 0;
};
abstract_class IWorldRenderer: public IGameSystem
{
public:
virtual void SetCameraRotation( Quat vRotation ) = 0;
virtual void SetCameraPosition( Vector vPosition ) = 0;
virtual IMesh *CreateMesh( const char *szName ) = 0;
virtual IMeshInstance *CreateInstance( IMesh *pMesh ) = 0;
};
extern IWorldRenderer *g_pWorldRenderer;
#endif

View File

@@ -1,38 +0,0 @@
#include "helper.h"
#include "c.h"
#include "ld.h"
#include "tier1/utlstring.h"
#include "tier1/commandline.h"
CUtlVector<CUtlString> server_CompiledFiles = {
"game/server/game.cpp",
"game/server/milmoba/player.cpp",
};
DECLARE_BUILD_STAGE(server)
{
CProject_t compileProject = {};
LinkProject_t ldProject = {};
compileProject.m_szName = "server";
compileProject.files = server_CompiledFiles;
compileProject.includeDirectories = all_IncludeDirectories;
compileProject.bFPIC = true;
ldProject = ccompiler->Compile(&compileProject);
if (bStaticBuild)
ldProject.linkType = ELINK_STATIC_LIBRARY;
else
ldProject.linkType = ELINK_DYNAMIC_LIBRARY;
CUtlString outputProject = linker->Link(&ldProject);
if (!bStaticBuild)
{
filesystem2->MakeDirectory(CUtlString("%s/funnygame/bin",szOutputDir.GetString()));
filesystem2->CopyFile(CUtlString("%s/funnygame/bin", szOutputDir.GetString()), outputProject);
} else {
server_lib = outputProject;
}
return 0;
};

109
game/server/baseentity.cpp Normal file
View 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/baseentity.h Normal file
View 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/build.cpp Normal file
View 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/datamap.h Normal file
View 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

View 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);
}
}

View File

@@ -0,0 +1,33 @@
//================= Copyright kotofyt, All rights reserved ==================//
//
// Purpose:
//
//===========================================================================//
#ifndef ENTITIES_H
#define ENTITIES_H
class IEntityFactory;
class CBaseEntity;
#define MAX_EDICTS 8192
class CEntitySystem
{
public:
CEntitySystem();
virtual void RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName );
virtual CBaseEntity *CreateByClassname( const char *szName );
virtual IEntityFactory *GetFactoryByClassname( const char *szName );
virtual void Think();
private:
CBaseEntity *m_pEntities[MAX_EDICTS];
int m_nEntityCount;
};
CEntitySystem *EntitySystem();
#endif

View File

@@ -1 +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 )
{
}

1
game/server/scene.cpp Normal file
View File

@@ -0,0 +1 @@

4
game/server/scene.h Normal file
View File

@@ -0,0 +1,4 @@
#ifndef GAME_SCENE_H
#define GAME_SCENE_H
#endif