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

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