work on world
This commit is contained in:
@@ -195,6 +195,7 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
if (!bHasBeenCreated)
|
||||
return hPhysics;
|
||||
FunnyPhysics_t *pPhysics = m_physics.GetObjectPtr(hPhysics);
|
||||
*pPhysics = {};
|
||||
|
||||
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||
if (!pHandle)
|
||||
@@ -225,10 +226,14 @@ HFunnyPhysics CAssetManager::LoadPhysics( const char *szName )
|
||||
return 0;
|
||||
}
|
||||
CUtlString szType = pTypeValue->GetStringValue();
|
||||
V_printf("%s\n", szType.GetString());
|
||||
if (szType == "Sphere")
|
||||
{
|
||||
pPhysics->m_hShape = g_pPhysics->CreateBall({1.0});
|
||||
}
|
||||
if (szType == "Triangles")
|
||||
{
|
||||
}
|
||||
|
||||
return hPhysics;
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ lookforname:
|
||||
BEGIN_DATADESC_NOBASE(CBaseEntity)
|
||||
DEFINE_KEYFIELD(m_vPosition, FIELD_FLOAT3, "origin")
|
||||
DEFINE_KEYFIELD(m_vRotation, FIELD_QUATERNION, "angles")
|
||||
DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scales")
|
||||
DEFINE_KEYFIELD(m_vScale, FIELD_FLOAT3, "scale")
|
||||
END_DATADESC()
|
||||
|
||||
IMPLEMENT_SEND_DT_NOBASE(CBaseEntity)
|
||||
|
||||
@@ -81,9 +81,9 @@ public:
|
||||
const char *m_szClassName;
|
||||
uint64_t m_ullOwner;
|
||||
private:
|
||||
Vector m_vPosition;
|
||||
Quat m_vRotation;
|
||||
Vector m_vScale;
|
||||
Vector m_vPosition = {};
|
||||
Quat m_vRotation = {};
|
||||
Vector m_vScale = {1,1,1};
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -1,6 +1,37 @@
|
||||
#include "basemodelentity.h"
|
||||
#include "game.h"
|
||||
|
||||
void CBaseModelEntity::Spawn()
|
||||
{
|
||||
SetThink(Think);
|
||||
}
|
||||
|
||||
void CBaseModelEntity::SetModel( const char *szName )
|
||||
{
|
||||
V_memset(m_szModel, 0, 256);
|
||||
V_strncpy(m_szModel, szName, 255);
|
||||
}
|
||||
|
||||
void CBaseModelEntity::OnModelChanged( const char *szName )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CBaseModelEntity::Think( float fDelta )
|
||||
{
|
||||
if (V_strncmp(m_szModel, m_szCurrentModel, 256))
|
||||
{
|
||||
V_memset(m_szCurrentModel, 0, 256);
|
||||
V_strncpy(m_szCurrentModel, m_szModel, 255);
|
||||
OnModelChanged(m_szCurrentModel);
|
||||
}
|
||||
}
|
||||
|
||||
IMPLEMENT_SEND_DT(CBaseModelEntity)
|
||||
NetPropString(m_szModel)
|
||||
END_RECV_DT()
|
||||
IMPLEMENT_EMPTY_RECV_DT(CBaseModelEntity)
|
||||
|
||||
BEGIN_DATADESC(CBaseModelEntity)
|
||||
DEFINE_KEYFIELD(m_szModel, FIELD_STRING, "model")
|
||||
END_DATADESC()
|
||||
|
||||
@@ -10,7 +10,15 @@ class CBaseModelEntity: public CBaseEntity
|
||||
public:
|
||||
|
||||
DECLARE_CLASS(CBaseModelEntity, CBaseEntity);
|
||||
DECLARE_DATADESC()
|
||||
DECLARE_SERVERCLASS()
|
||||
virtual void Spawn() override;
|
||||
virtual void SetModel( const char *szName );
|
||||
virtual void OnModelChanged( const char *szName );
|
||||
virtual void Think( float fDelta );
|
||||
private:
|
||||
char m_szCurrentModel[256] = {};
|
||||
char m_szModel[256] = {};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -21,6 +21,7 @@ DECLARE_BUILD_STAGE(Server)
|
||||
|
||||
"game.cpp",
|
||||
"assetmgr.cpp",
|
||||
"worldsystem.cpp",
|
||||
|
||||
"entitysystem.cpp",
|
||||
"baseentity.cpp",
|
||||
|
||||
@@ -262,6 +262,8 @@ void CEntitySystem::NetSendThink( INetworkBase *pBase )
|
||||
V_memcpy(pcCurrentData,
|
||||
pNetMap->m_pFields[u].m_uOffset+(char*)pEntity,
|
||||
pNetMap->m_pFields[u].m_uSize);
|
||||
//if (pNetMap->m_pFields[u].m_eType == FIELD_STRING)
|
||||
//V_printf("v: %s %u\n", pcCurrentData, pNetMap->m_pFields[u].m_uSize);
|
||||
pcCurrentData += (pNetMap->m_pFields[u].m_uSize+7) & ~7;
|
||||
x++;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
#include "baseentity.h"
|
||||
#include "enginebridge.h"
|
||||
#include "game.h"
|
||||
#include "inetworkserver.h"
|
||||
#include "netprotocol.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "iphysics.h"
|
||||
#include "worldsystem.h"
|
||||
#ifdef STEAM
|
||||
#include "steam/isteamgameserver.h"
|
||||
#include "steam/steam_gameserver.h"
|
||||
@@ -91,9 +90,12 @@ void CFunnyGameBridge::Init()
|
||||
if (g_pEngineConstants->m_bIsSteam)
|
||||
{
|
||||
SteamErrMsg err = { 0 };
|
||||
if (SteamGameServer_InitEx(INADDR_ANY, FUNNY_SECURE_PORT, FUNNY_QUERY_PORT, eServerModeAuthentication, "0.0.0.0", &err));
|
||||
if (!SteamGameServer())
|
||||
{
|
||||
V_printf("SteamGameServer_InitEx: %s\n", err);
|
||||
if (SteamGameServer_InitEx(INADDR_ANY, FUNNY_SECURE_PORT, FUNNY_QUERY_PORT, eServerModeAuthentication, "0.0.0.0", &err))
|
||||
{
|
||||
V_printf("SteamGameServer_InitEx: %s\n", err);
|
||||
}
|
||||
}
|
||||
SteamNetworkingUtils()->InitRelayNetworkAccess();
|
||||
}
|
||||
@@ -118,6 +120,8 @@ void CFunnyGameBridge::Init()
|
||||
CreateInterfaceFn fnPhysicsFactory = Sys_GetFactory("RapierPhysics");
|
||||
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
|
||||
g_pPhysicsWorld = g_pPhysics->CreateWorld();
|
||||
|
||||
g_pWorldSystem->LoadMap("game/core/maps/test/test.fmap");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,12 +11,19 @@ void CPhysicsProp::Spawn()
|
||||
{
|
||||
CBaseEntity::Spawn();
|
||||
SetThink(Think);
|
||||
|
||||
V_printf("hi\n");
|
||||
}
|
||||
|
||||
void CPhysicsProp::Think( float fDelta )
|
||||
{
|
||||
BaseClass::SetAbsOrigin(m_pBody->GetPosition());
|
||||
BaseClass::SetAbsAngles(m_pBody->GetRotation());
|
||||
BaseClass::Think(fDelta);
|
||||
if (m_pBody)
|
||||
{
|
||||
BaseClass::SetAbsOrigin(m_pBody->GetPosition());
|
||||
BaseClass::SetAbsAngles(m_pBody->GetRotation());
|
||||
}
|
||||
V_printf("%f %f %f\n", GetAbsOrigin().x, GetAbsOrigin().y, GetAbsOrigin().z);
|
||||
}
|
||||
|
||||
void CPhysicsProp::SetAbsAngles( Quat vQuat )
|
||||
@@ -42,7 +49,7 @@ void CPhysicsProp::SetAbsOrigin( Vector origin )
|
||||
m_pBody->SetPosition(m_pBody->GetPosition());
|
||||
}
|
||||
|
||||
void CPhysicsProp::SetModel( const char *szName )
|
||||
void CPhysicsProp::OnModelChanged( const char *szName )
|
||||
{
|
||||
if (m_hModel)
|
||||
{
|
||||
@@ -65,3 +72,4 @@ void CPhysicsProp::DisableMovement()
|
||||
|
||||
}
|
||||
|
||||
LINK_ENTITY_TO_CLASS(prop_physics, CPhysicsProp)
|
||||
|
||||
@@ -16,12 +16,13 @@ public:
|
||||
virtual void SetAbsQAngles( float fPitch, float fYaw, float fRoll ) override;
|
||||
virtual void SetAbsOrigin( Vector origin ) override;
|
||||
|
||||
virtual void SetModel( const char *szName ) override;
|
||||
virtual void OnModelChanged( const char *szName ) override;
|
||||
virtual void EnableMovement();
|
||||
virtual void DisableMovement();
|
||||
|
||||
void Think( float fDelta );
|
||||
private:
|
||||
EPhysicsBodyType m_ePhysicsType;
|
||||
HFunnyModel m_hModel = 0;
|
||||
FunnyModel_t *m_pModel = NULL;
|
||||
FunnyPhysics_t *m_pPhysics = NULL;
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
#include "worldsystem.h"
|
||||
#include "game.h"
|
||||
#include "entitysystem.h"
|
||||
#include "baseentity.h"
|
||||
#include "netprotocol.h"
|
||||
|
||||
void CWorldSystem::LoadEntity( IJSONValue *pObject )
|
||||
{
|
||||
if (pObject->GetType() != JSON_PARAMETER_OBJECT)
|
||||
return;
|
||||
IJSONObject *pObjectRoot = pObject->GetObject();
|
||||
|
||||
const char *szClassName = NULL;
|
||||
|
||||
for ( int i = 0; i < pObjectRoot->GetCount(); i++)
|
||||
{
|
||||
if (V_strcmp(pObjectRoot->GetParameterName(i),"classname"))
|
||||
continue;
|
||||
|
||||
IJSONValue *pValue = pObjectRoot->GetParameter(i);
|
||||
if (pValue->GetType() != JSON_PARAMETER_STRING)
|
||||
{
|
||||
V_printf("classname must be a string\n");
|
||||
break;
|
||||
}
|
||||
szClassName = pValue->GetStringValue();
|
||||
break;
|
||||
}
|
||||
if (szClassName == NULL)
|
||||
return;
|
||||
CBaseEntity *pEntity = EntitySystem()->CreateByClassname(szClassName, NULL);
|
||||
if (!pEntity)
|
||||
return;
|
||||
for ( int i = 0; i < pObjectRoot->GetCount(); i++)
|
||||
{
|
||||
if (!V_strcmp(pObjectRoot->GetParameterName(i),"classname"))
|
||||
continue;
|
||||
|
||||
|
||||
IJSONValue *pValue = pObjectRoot->GetParameter(i);
|
||||
typedescription_t *pDataMap = pEntity->FindDataByMapName(pObjectRoot->GetParameterName(i));
|
||||
if (!pDataMap)
|
||||
continue;
|
||||
union {
|
||||
void *pData;
|
||||
float *pfData;
|
||||
Vector *pvData;
|
||||
char *pcData;
|
||||
};
|
||||
pData = (char*)pEntity+pDataMap->m_iFieldOffset;
|
||||
switch (pDataMap->m_eFieldType)
|
||||
{
|
||||
case FIELD_STRING:
|
||||
if (pValue->GetType() != JSON_PARAMETER_STRING)
|
||||
continue;
|
||||
V_strncpy(pcData, pValue->GetStringValue(), pDataMap->m_uFieldSize);
|
||||
V_printf("loading %s %u\n", pValue->GetStringValue(), pDataMap->m_uFieldSize);
|
||||
continue;
|
||||
case FIELD_FLOAT3:
|
||||
if (pValue->GetType() != JSON_PARAMETER_ARRAY)
|
||||
continue;
|
||||
if (pValue->GetArray()->GetCount() == 3)
|
||||
{
|
||||
if ( pValue->GetArray()->GetParameter(0)->GetType()
|
||||
== JSON_PARAMETER_NUMBER )
|
||||
pvData->x = pValue->GetArray()->GetParameter(0)->GetNumberValue();
|
||||
if ( pValue->GetArray()->GetParameter(1)->GetType()
|
||||
== JSON_PARAMETER_NUMBER )
|
||||
pvData->y = pValue->GetArray()->GetParameter(1)->GetNumberValue();
|
||||
if ( pValue->GetArray()->GetParameter(2)->GetType()
|
||||
== JSON_PARAMETER_NUMBER )
|
||||
pvData->z = pValue->GetArray()->GetParameter(2)->GetNumberValue();
|
||||
|
||||
}
|
||||
continue;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
pEntity->Spawn();
|
||||
}
|
||||
|
||||
bool CWorldSystem::LoadMap( const char *szName )
|
||||
{
|
||||
V_printf("Loading %s\n", szName);
|
||||
// unload the map
|
||||
|
||||
IFileHandle *pHandle = filesystem->Open(szName, FILEMODE_READ);
|
||||
if (!pHandle)
|
||||
return 0;
|
||||
|
||||
CUtlString szProperties = filesystem->ReadString(pHandle);
|
||||
IJSONValue *pRoot = JSONManager()->ReadString(szProperties);
|
||||
filesystem->Close(pHandle);
|
||||
|
||||
if (!pRoot)
|
||||
return 0;
|
||||
|
||||
|
||||
// can't fail at this point
|
||||
|
||||
|
||||
|
||||
switch (pRoot->GetType())
|
||||
{
|
||||
case JSON_PARAMETER_ARRAY:
|
||||
{
|
||||
for ( uint32_t u = 0; u < pRoot->GetArray()->GetCount(); u++ )
|
||||
{
|
||||
IJSONValue *pObjectValue = pRoot->GetArray()->GetParameter(u);
|
||||
if ( !pObjectValue )
|
||||
continue;
|
||||
LoadEntity(pObjectValue);
|
||||
}
|
||||
JSONManager()->FreeValue(pRoot);
|
||||
return 1;
|
||||
}
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
static CWorldSystem s_worldSystem;
|
||||
CWorldSystem *g_pWorldSystem = &s_worldSystem;
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef WORLD_SYSTEM_H
|
||||
#define WORLD_SYSTEM_H
|
||||
|
||||
#include "assetmgr.h"
|
||||
#include "tier2/fileformats/json.h"
|
||||
|
||||
class CWorldSystem
|
||||
{
|
||||
public:
|
||||
virtual bool LoadMap( const char *szName );
|
||||
private:
|
||||
virtual void LoadEntity( IJSONValue *pObject);
|
||||
};
|
||||
extern CWorldSystem *g_pWorldSystem;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user