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

@@ -16,6 +16,8 @@ DECLARE_BUILD_STAGE(Server)
compileProject.m_szName = "server";
compileProject.files = {
"../shared/game.cpp",
"game.cpp",
"assetmgr.cpp",

View File

@@ -9,7 +9,7 @@
#include "stddef.h"
#include "string.h"
#include "stdlib.h"
#include "engine.h"
#include "game.h"
#include "netprotocol.h"
@@ -56,7 +56,7 @@ void CEntitySystem::RegisterEntityClass( IEntityFactory *pEntityFactory, const c
s_pEntitiesRegistry = pRegistry;
}
CBaseEntity *CEntitySystem::CreateByClassname( const char *szName )
CBaseEntity *CEntitySystem::CreateByClassname( const char *szName, int *pOutputIndex )
{
IEntityFactory *pFactory;
CBaseEntity *pEntity;
@@ -87,6 +87,9 @@ CBaseEntity *CEntitySystem::CreateByClassname( const char *szName )
m_pEntities[iSelectedSlot] = pEntity;
m_nEntityCount++;
if (pOutputIndex)
*pOutputIndex = iSelectedSlot;
EntityClass_t stClassSync = {
MESSAGE_ENTITY_CLASS_SYNC,
iSelectedSlot,

View File

@@ -20,7 +20,7 @@ public:
CEntitySystem();
virtual void RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName );
virtual CBaseEntity *CreateByClassname( const char *szName );
virtual CBaseEntity *CreateByClassname( const char *szName, int *pOutputIndex );
virtual IEntityFactory *GetFactoryByClassname( const char *szName );

View File

@@ -12,23 +12,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_pClientBridge;
INetworkBase *g_pPublicConnection;
INetworkBase *g_pCurrentConnection;
IPhysics *g_pPhysics;
IPhysicsWorld *g_pPhysicsWorld;
class CFunnyGameBridge: public IEngineBridge
{
virtual void Init() override;
@@ -81,9 +64,17 @@ uint32_t NET_ServerCallback( NetCallback_t *pCallback )
g_pCurrentConnection->SendPacket({&stClassSync, sizeof(stClassSync), pCallback->m_ullUserConnection, PACKET_MUST_ARRIVE});
}
int iIndex = -1;
CBaseEntity *pEntity;
pEntity = EntitySystem()->CreateByClassname("player");
pEntity = EntitySystem()->CreateByClassname("player", &iIndex);
pEntity->Spawn();
SetLocalEntity_t stLocalEntity = {
k_EMessage_PlayerSetLocalEntity,
iIndex,
};
if (g_pCurrentConnection)
g_pCurrentConnection->SendPacket({&stLocalEntity, sizeof(stLocalEntity), pCallback->m_ullUserConnection, PACKET_MUST_ARRIVE});
return 1;
}
return 0;
@@ -149,13 +140,29 @@ void NET_ProcessPacket( INetworkBase *pBase )
switch (pPacket->m_eType)
{
case MESSAGE_PLAYER_JOINED:
// online packets don't generate these
if (g_pEngineConstants->m_bIsDedicated)
break;
pBase->RecievePacket();
V_printf("Hi %s\n",pPacket->m_playerJoined.m_szPlayerName);
pEntity = EntitySystem()->CreateByClassname("player");
pEntity->Spawn();
{
// online packets don't generate these
if (g_pEngineConstants->m_bIsDedicated)
break;
pBase->RecievePacket();
int iIndex = -1;
V_printf("Hi %s\n",pPacket->m_playerJoined.m_szPlayerName);
for ( int i = 0; i < 2; i++ )
{
pEntity = EntitySystem()->CreateByClassname("player", &iIndex);
pEntity->Spawn();
}
SetLocalEntity_t stLocalEntity = {
k_EMessage_PlayerSetLocalEntity,
iIndex,
};
if (g_pCurrentConnection)
g_pCurrentConnection->SendPacket({&stLocalEntity, sizeof(stLocalEntity), 0, PACKET_MUST_ARRIVE});
}
return;
default:
break;

View File

@@ -1,19 +1,20 @@
#include "player.h"
#include "game.h"
#include "entitysystem.h"
void CMOBAPlayer::Spawn()
{
CPhysicsProp::Spawn();
SetModel("game/core/models/cube.fmdl");
SetScale(1);
SetThink(Think);
m_fTimer = 0;
};
void CMOBAPlayer::Think( float fDelta )
{
BaseClass::Think(fDelta);
SetScale(1);
CPhysicsProp::Think(fDelta);
};
LINK_ENTITY_TO_CLASS(player, CMOBAPlayer)
@@ -22,7 +23,6 @@ BEGIN_DATADESC(CMOBAPlayer)
END_DATADESC()
IMPLEMENT_SEND_DT(CMOBAPlayer)
NetPropFloat(m_fTimer)
END_SEND_DT()
IMPLEMENT_EMPTY_RECV_DT(CMOBAPlayer)

View File

@@ -1,12 +1,12 @@
#ifndef MILMOBA_PLAYER_H
#define MILMOBA_PLAYER_H
#include "basemodelentity.h"
#include "physicsprop.h"
class CMOBAPlayer: public CBaseModelEntity
class CMOBAPlayer: public CPhysicsProp
{
public:
DECLARE_CLASS(CMOBAPlayer, CBaseModelEntity);
DECLARE_CLASS(CMOBAPlayer, CPhysicsProp);
DECLARE_DATADESC();
DECLARE_SERVERCLASS()

View File

@@ -9,6 +9,7 @@ void CPhysicsProp::Precache()
void CPhysicsProp::Spawn()
{
CBaseEntity::Spawn();
SetThink(Think);
}