lots of updates
This commit is contained in:
@@ -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
109
game/server/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/baseentity.h
Normal file
79
game/server/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/build.cpp
Normal file
44
game/server/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/datamap.h
Normal file
97
game/server/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/entitysystem.cpp
Normal file
120
game/server/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);
|
||||
}
|
||||
}
|
||||
33
game/server/entitysystem.h
Normal file
33
game/server/entitysystem.h
Normal 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
|
||||
@@ -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
1
game/server/scene.cpp
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
4
game/server/scene.h
Normal file
4
game/server/scene.h
Normal file
@@ -0,0 +1,4 @@
|
||||
#ifndef GAME_SCENE_H
|
||||
#define GAME_SCENE_H
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user