some stuff

This commit is contained in:
2026-03-05 21:25:59 +02:00
parent 2da75ebdd8
commit 99f68e655f
41 changed files with 706 additions and 324 deletions

View File

@@ -81,6 +81,8 @@ private:
Vector m_vPosition;
Quat m_vRotation;
Vector m_vScale;
uint64_t m_uSlot;
};
#endif

View File

@@ -15,6 +15,8 @@ DECLARE_BUILD_STAGE(Client)
compileProject.m_szName = "client";
compileProject.files = {
"../shared/game.cpp",
"game.cpp",
"baseentity.cpp",

View File

@@ -10,6 +10,8 @@
#include "string.h"
#include "stdlib.h"
#include "netprotocol.h"
CEntitySystem *EntitySystem()
{
@@ -155,7 +157,96 @@ void CEntitySystem::Think()
}
}
static void *UTIL_GetNetMapData(C_BaseEntity *pEntity, netmap_t *pMap, uint32_t uIndex )
{
netmap_t *pCurrentMap = pMap;
uint32_t uCurrentIndex = uIndex;
searchIndex:
if (uCurrentIndex >= pCurrentMap->m_uFieldCount || pCurrentMap->m_pBase )
{
uCurrentIndex -= pCurrentMap->m_uFieldCount;
pCurrentMap = pCurrentMap->m_pBase;
if (!pCurrentMap)
return NULL;
goto searchIndex;
}
return (char*)pEntity+pCurrentMap->m_pFields[uCurrentIndex].m_uOffset;
}
static C_BaseEntity *s_pLocalEntity;
void CEntitySystem::NetRecvPacket( NetPacket_t *pPacket )
{
PlayerPacket_t *pPlayerPacket = (PlayerPacket_t*)pPacket->pData;
C_BaseEntity *pEntity;
switch (pPlayerPacket->m_eType)
{
case MESSAGE_ENTITY_CLASS_SYNC:
V_printf("MESSAGE_ENTITY_CLASS_SYNC: %u = %s\n",
(uint32_t)pPlayerPacket->m_entityClass.m_uIndex,
pPlayerPacket->m_entityClass.m_szEntityName);
pEntity = CreateByClassnameWithIndex(
(char*)pPlayerPacket->m_entityClass.m_szEntityName,
pPlayerPacket->m_entityClass.m_uIndex
);
if (pEntity == NULL)
break;
pEntity->Spawn();
break;
case MESSAGE_ENTITY_DATA_SYNC:
pEntity = m_pEntities[pPlayerPacket->m_entityData.m_uIndex];
if (pEntity == NULL)
break;
union {
void *pData;
char *pcCurrentData;
EntityDataSyncValue_t *pcSyncValue;
};
pData = pPlayerPacket;
pcCurrentData += sizeof(EntityDataSync_t);
// too bad
// this shall be reworked
for ( uint32_t u = 0; u < pPlayerPacket->m_entityData.m_uCount; u++ )
{
uint32_t uVariableSize = pcSyncValue->m_uVariableSize;
void *pValueData = (float*)UTIL_GetNetMapData(
pEntity,
pEntity->GetRecvMap(),
pcSyncValue->m_uVariableIndex);
pcCurrentData += sizeof(EntityDataSyncValue_t);
if (pValueData)
V_memcpy(pValueData, pcCurrentData, uVariableSize);
pcCurrentData += (uVariableSize+7) & ~7;
}
break;
case k_EMessage_PlayerSetLocalEntity:
V_printf("k_EMessage_PlayerSetLocalEntity: %u\n",(uint32_t)pPlayerPacket->m_setLocalEntity.m_uIndex);
if (pPlayerPacket->m_setLocalEntity.m_uIndex > MAX_EDICTS)
break;
s_pLocalEntity = m_pEntities[pPlayerPacket->m_setLocalEntity.m_uIndex];
default:
break;
}
}
void CEntitySystem::NetSendThink()
{
}
C_BaseEntity **CEntitySystem::GetEntities()
{
return m_pEntities;
};
C_BaseEntity *UTIL_GetLocalPlayer()
{
return s_pLocalEntity;
}

View File

@@ -8,6 +8,7 @@
#define ENTITIES_H
#include "stdint.h"
#include "networkbase.h"
class IEntityFactory;
class C_BaseEntity;
@@ -29,6 +30,10 @@ public:
virtual void DestroyEntityByPtr( C_BaseEntity *pEntity );
virtual void Think();
virtual void NetRecvPacket( NetPacket_t *pPacket );
virtual void NetSendThink();
virtual C_BaseEntity **GetEntities();
private:
C_BaseEntity *m_pEntities[MAX_EDICTS];
@@ -37,4 +42,6 @@ private:
CEntitySystem *EntitySystem();
C_BaseEntity *UTIL_GetLocalPlayer();
#endif

View File

@@ -15,21 +15,6 @@
#include "steam/steam_gameserver.h"
#endif
IFileSystem *filesystem;
IRenderContext *g_pRenderContext;
IGameWindow *g_pMainWindow;
static CEngineVars s_vars;
CEngineVars *g_pEngineVars = &s_vars;
EngineConsts_t *g_pEngineConstants;
INetworkBase *g_pServerBridge;
INetworkBase *g_pServerConnection;
IPhysics *g_pPhysics;
IPhysicsWorld *g_pPhysicsWorld;
class CFunnyGameBridge: public IEngineBridge
{
virtual void Init() override;
@@ -44,6 +29,35 @@ class CFunnyGameBridge: public IEngineBridge
};
class CFunnyInput: public IHumanDeviceInput
{
virtual EInputType GetInputType() override { return k_EInput_Game; };
virtual void OnGameButton( EInputDeviceType eDevice, EInputButton eScancode, bool bIsPressed ) override;
virtual void OnGameAxis( EInputDeviceType eDevice, EInputAxis eAxis, float fValue) override;
virtual void OnGameAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fValue ) override;
virtual void OnButton( EInputDeviceType eDevice, EInputButton eScancode, bool bIsPressed ) override {};
virtual void OnAxis( EInputDeviceType eDevice, EInputAxis eAxis, float fValue) override {};
virtual void OnAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fValue ) override {};
virtual void OnTextWriteUTF8( uint32_t uCode ) override {};
};
void CFunnyInput::OnGameButton( EInputDeviceType eDevice, EInputButton eScancode, bool bIsPressed )
{
}
void CFunnyInput::OnGameAxis( EInputDeviceType eDevice, EInputAxis eAxis, float fValue)
{
}
void CFunnyInput::OnGameAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fValue )
{
}
IEngineBridge *EngineBridge()
{
static CFunnyGameBridge s_bridge;
@@ -52,6 +66,7 @@ IEngineBridge *EngineBridge()
EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION)
static CFunnyInput s_mainInput;
void CFunnyGameBridge::Init()
{
@@ -79,30 +94,14 @@ void CFunnyGameBridge::Init()
CreateInterfaceFn fnPhysicsFactory = Sys_GetFactory("RapierPhysics");
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
g_pPhysicsWorld = g_pPhysics->CreateWorld();
g_pHumanDeviceManager->SetDefaultInput(&s_mainInput);
}
void CFunnyGameBridge::Tick( float fDelta )
{
}
void *ENT_GetNetMapData(C_BaseEntity *pEntity, netmap_t *pMap, uint32_t uIndex )
{
netmap_t *pCurrentMap = pMap;
uint32_t uCurrentIndex = uIndex;
searchIndex:
if (uCurrentIndex >= pCurrentMap->m_uFieldCount)
{
if (!pCurrentMap->m_uFieldCount)
return NULL;
uCurrentIndex -= pCurrentMap->m_uFieldCount;
pCurrentMap = pCurrentMap->m_pBase;
if (!pCurrentMap)
return NULL;
goto searchIndex;
}
return (char*)pEntity+pCurrentMap->m_pFields[uCurrentIndex].m_uOffset;
}
void CFunnyGameBridge::TryToConnectToServer()
{
@@ -111,27 +110,25 @@ void CFunnyGameBridge::TryToConnectToServer()
{
if (m_bIsConnectedToSteamRelay != 0 )
return;
if ( SteamNetworkingUtils()->GetRelayNetworkStatus(NULL) == k_ESteamNetworkingAvailability_Current)
if ( SteamNetworkingUtils()->GetRelayNetworkStatus(NULL) != k_ESteamNetworkingAvailability_Current)
return;
m_bIsConnectedToSteamRelay = 1;
if (!CommandLine()->ParamValue("-steam-connect"))
return;
V_printf("%llu\n", SteamUser()->GetSteamID().ConvertToUint64());
char *pEnd = NULL;
uint64_t uValue = strtoull(CommandLine()->ParamValue("-steam-connect"), &pEnd, 10);
g_pServerConnection = g_pEngineConstants->ConnectSteamServer(uValue, FUNNY_SECURE_PORT);
if (g_pServerConnection)
{
m_bIsConnectedToSteamRelay = 1;
V_printf("%llu\n", SteamUser()->GetSteamID().ConvertToUint64());
if (CommandLine()->ParamValue("-steam-connect"))
{
char *pEnd = NULL;
uint64_t uValue = strtoull(CommandLine()->ParamValue("-steam-connect"), &pEnd, 10);
g_pServerConnection = g_pEngineConstants->ConnectSteamServer(uValue, FUNNY_SECURE_PORT);
if (g_pServerConnection)
{
m_bIsConnectedToServer = true;
C_BaseEntity **ppEntities = EntitySystem()->GetEntities();
for ( int i = 0; i < MAX_EDICTS; i++ )
{
EntitySystem()->DestroyEntityByIndex(i);
}
}
return;
m_bIsConnectedToServer = true;
C_BaseEntity **ppEntities = EntitySystem()->GetEntities();
for ( int i = 0; i < MAX_EDICTS; i++ )
{
EntitySystem()->DestroyEntityByIndex(i);
}
}
return;
}
#endif
}
@@ -158,53 +155,19 @@ void CFunnyGameBridge::Frame( float fDelta )
while ( pCurrentServer->BHasUpdates() )
{
NetPacket_t packet = pCurrentServer->PeekPacket();
// discard it
if (packet.uSize < sizeof (EMessageType))
continue;
PlayerPacket_t *pPacket = (PlayerPacket_t*)packet.pData;
C_BaseEntity *pEntity;
switch (pPacket->m_eType)
{
case MESSAGE_ENTITY_CLASS_SYNC:
V_printf("MESSAGE_ENTITY_CLASS_SYNC: %u = %s\n", (uint32_t)pPacket->m_entityClass.m_uIndex, pPacket->m_entityClass.m_szEntityName);
pEntity = EntitySystem()->CreateByClassnameWithIndex(
(char*)pPacket->m_entityClass.m_szEntityName, pPacket->m_entityClass.m_uIndex
);
if (pEntity == NULL)
{
pCurrentServer->RecievePacket();
continue;
}
pEntity->Spawn();
pCurrentServer->RecievePacket();
break;
case MESSAGE_ENTITY_DATA_SYNC:
pEntity = EntitySystem()->GetEntities()[pPacket->m_entityData.m_uIndex];
if (pEntity == NULL)
{
pCurrentServer->RecievePacket();
continue;
}
union {
void *pData;
char *pcCurrentData;
EntityDataSyncValue_t *pcSyncValue;
};
pData = pPacket;
pcCurrentData += sizeof(EntityDataSync_t);
for ( uint32_t u = 0; u < pPacket->m_entityData.m_uCount; u++ )
{
uint32_t uVariableSize = pcSyncValue->m_uVariableSize;
void *pValueData = (float*)ENT_GetNetMapData(
pEntity,
pEntity->GetRecvMap(),
pcSyncValue->m_uVariableIndex);
pcCurrentData += sizeof(EntityDataSyncValue_t);
if (pValueData)
V_memcpy(pValueData, pcCurrentData, uVariableSize);
pcCurrentData += (uVariableSize+7) & ~7;
}
case k_EMessage_PlayerSetLocalEntity:
EntitySystem()->NetRecvPacket(&packet);
pCurrentServer->RecievePacket();
break;
default:
@@ -227,8 +190,9 @@ 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(FILESYSTEM_INTERFACE_VERSION, filesystem);
CONNECT_INTERFACE(RENDER_CONTEXT_INTERFACE_VERSION, g_pRenderContext);
CONNECT_INTERFACE(HUMAN_DEVICE_MANAGER_INTERFACE_VERSION, g_pHumanDeviceManager);
CONNECT_INTERFACE("MainWindow", g_pMainWindow);
CONNECT_INTERFACE("EngineConstants", g_pEngineConstants);
}

View File

@@ -1,6 +1,7 @@
#include "player.h"
#include "cglm/cglm.h"
#include "assetmgr.h"
#include "game.h"
void C_MOBAPlayer::Precache()
{
@@ -12,12 +13,19 @@ void C_MOBAPlayer::Spawn()
{
BaseClass::Spawn();
SetThink(Think);
g_pWorldRenderer->SetCameraPosition({0, 0, -20});
};
void C_MOBAPlayer::Think( float fDelta )
{
BaseClass::Think(fDelta);
C_MOBAPlayer *pEntity = (C_MOBAPlayer*)UTIL_GetLocalPlayer();
if (pEntity == this)
{
Vector vCameraPos = GetAbsOrigin();
vCameraPos.z -= 20;
g_pWorldRenderer->SetCameraPosition(vCameraPos);
}
};
LINK_ENTITY_TO_CLASS(player, C_MOBAPlayer)
@@ -26,7 +34,21 @@ BEGIN_DATADESC(C_MOBAPlayer)
END_DATADESC()
IMPLEMENT_RECV_DT(C_MOBAPlayer)
NetPropFloat(m_fTimer),
END_RECV_DT()
IMPLEMENT_EMPTY_SEND_DT(C_MOBAPlayer)
static void IN_ForwardDown( int c, char **v ) {
}
static ConCommand startforward("+forward", IN_ForwardDown);
static void IN_ForwardUp( int c, char **v ) {
C_MOBAPlayer *pEntity = (C_MOBAPlayer*)UTIL_GetLocalPlayer();
if (pEntity)
{
}
}
static ConCommand endforward("-forward", IN_ForwardUp);

View File

@@ -15,7 +15,6 @@ public:
virtual void Spawn( void ) override;
void Think( float fDelta );
float m_fTimer;
int m_bIsShooting;
float m_fFBWalkingDirection;
float m_fLRWalkingDirection;

View File

@@ -1,10 +1,10 @@
#include "worldrender.h"
#include "tier1/utlstring.h"
#include "engine.h"
#include "cglm/cglm.h"
#include "cglm/quat.h"
#include "cglm/mat4.h"
#include "game.h"
struct ViewBuffer_t
{