some stuff
This commit is contained in:
@@ -23,6 +23,7 @@ DECLARE_BUILD_STAGE(engine)
|
|||||||
"localnetwork.cpp",
|
"localnetwork.cpp",
|
||||||
"socketnetwork.cpp",
|
"socketnetwork.cpp",
|
||||||
"steamnetwork.cpp",
|
"steamnetwork.cpp",
|
||||||
|
"humandevice.cpp",
|
||||||
|
|
||||||
"sv_dll.cpp",
|
"sv_dll.cpp",
|
||||||
"cl_dll.cpp",
|
"cl_dll.cpp",
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "tier0/platform.h"
|
#include "tier0/platform.h"
|
||||||
#include "icvar.h"
|
#include "icvar.h"
|
||||||
#include "tier2/ifilesystem.h"
|
#include "tier2/ifilesystem.h"
|
||||||
|
#include "ihumandevice.h"
|
||||||
|
|
||||||
void CClientGameDLL::Init()
|
void CClientGameDLL::Init()
|
||||||
{
|
{
|
||||||
@@ -18,8 +19,9 @@ void CClientGameDLL::Init()
|
|||||||
CreateInterfaceFn pfnServerFactory = Sys_GetFactory(pLib);
|
CreateInterfaceFn pfnServerFactory = Sys_GetFactory(pLib);
|
||||||
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
|
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
|
||||||
|
|
||||||
pEngineBridge->ConnectInterface(RENDER_CONTEXT_INTERFACE_VERSION, m_pRenderContext);
|
|
||||||
pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
||||||
|
pEngineBridge->ConnectInterface(RENDER_CONTEXT_INTERFACE_VERSION, m_pRenderContext);
|
||||||
|
pEngineBridge->ConnectInterface(HUMAN_DEVICE_MANAGER_INTERFACE_VERSION, g_pHumanDeviceManager);
|
||||||
pEngineBridge->ConnectInterface("MainWindow", m_pGameWindow);
|
pEngineBridge->ConnectInterface("MainWindow", m_pGameWindow);
|
||||||
pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts);
|
pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts);
|
||||||
pEngineBridge->Init();
|
pEngineBridge->Init();
|
||||||
|
|||||||
119
engine/cvar.cpp
119
engine/cvar.cpp
@@ -20,7 +20,7 @@ struct ConsoleMessage_t
|
|||||||
|
|
||||||
void Msg( const char* message )
|
void Msg( const char* message )
|
||||||
{
|
{
|
||||||
printf(message);
|
printf("%s\n", message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,13 +57,18 @@ public:
|
|||||||
|
|
||||||
virtual void AddCommand( const char *psz ) override;
|
virtual void AddCommand( const char *psz ) override;
|
||||||
virtual void InsertCommand( const char *psz ) override;
|
virtual void InsertCommand( const char *psz ) override;
|
||||||
|
|
||||||
|
CUtlVector<ConVar*> m_convars;
|
||||||
|
CUtlVector<ConCommand*> m_commands;
|
||||||
};
|
};
|
||||||
|
|
||||||
IConsole *Console()
|
IConsole *Console()
|
||||||
{
|
{
|
||||||
static CConsole s_console;
|
static CConsole s_console;
|
||||||
return &s_console;
|
IConsole *pConsole = &s_console;
|
||||||
|
return pConsole;
|
||||||
}
|
}
|
||||||
|
EXPOSE_INTERFACE_FN(Console, IConsole, CONSOLE_INTERFACE_VERSION);
|
||||||
|
|
||||||
void CConsole::Init()
|
void CConsole::Init()
|
||||||
{
|
{
|
||||||
@@ -207,115 +212,6 @@ void CConsole::InsertCommand( const char *psz )
|
|||||||
g_commandBuffer.AppendHead(psz);
|
g_commandBuffer.AppendHead(psz);
|
||||||
};
|
};
|
||||||
|
|
||||||
ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags )
|
|
||||||
: ConVar(pName, pDefaultValue, flags, 0)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags,
|
|
||||||
const char *pHelpString )
|
|
||||||
: ConVar(pName, pDefaultValue, flags, pHelpString, 0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags,
|
|
||||||
const char *pHelpString, ConCommandFn callback )
|
|
||||||
{
|
|
||||||
m_szName = pName;
|
|
||||||
m_flags = flags;
|
|
||||||
m_szValue = pDefaultValue;
|
|
||||||
m_fValue = V_atof(pDefaultValue);
|
|
||||||
m_nValue = V_atoi(pDefaultValue);
|
|
||||||
Console()->RegisterVar(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool ConVar::IsFlagSet( int flag )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
const char *ConVar::GetHelpText( void )
|
|
||||||
{
|
|
||||||
return m_szHelpString;
|
|
||||||
}
|
|
||||||
bool ConVar::IsRegistered( void )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
const char *ConVar::GetName( void )
|
|
||||||
{
|
|
||||||
return m_szName;
|
|
||||||
}
|
|
||||||
void ConVar::AddFlags( int flags )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
bool ConVar::IsCommand( void )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConVar::InstallChangeCallback( ConCommandFn )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
float ConVar::GetFloat( void )
|
|
||||||
{
|
|
||||||
return m_fValue;
|
|
||||||
}
|
|
||||||
int ConVar::GetInt( void )
|
|
||||||
{
|
|
||||||
return m_nValue;
|
|
||||||
}
|
|
||||||
bool ConVar::GetBool( void )
|
|
||||||
{
|
|
||||||
return m_nValue;
|
|
||||||
}
|
|
||||||
const char *ConVar::GetString( void )
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConVar::SetValue( const char *szValue )
|
|
||||||
{
|
|
||||||
if (!szValue)
|
|
||||||
return;
|
|
||||||
m_szValue = szValue;
|
|
||||||
m_fValue = V_atof(szValue);
|
|
||||||
m_nValue = V_atoi(szValue);
|
|
||||||
}
|
|
||||||
void ConVar::SetValue( float fValue )
|
|
||||||
{
|
|
||||||
m_fValue = fValue;
|
|
||||||
m_nValue = fValue;
|
|
||||||
m_szValue = CUtlString("%f\n",fValue);
|
|
||||||
}
|
|
||||||
void ConVar::SetValue( int iValue )
|
|
||||||
{
|
|
||||||
m_fValue = iValue;
|
|
||||||
m_nValue = iValue;
|
|
||||||
m_szValue = CUtlString("%i\n",iValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
ConCommand::ConCommand(const char *pName, ConCommandFn callback,
|
|
||||||
const char *pHelpString, int flags)
|
|
||||||
{
|
|
||||||
m_szName = pName;
|
|
||||||
m_callback = callback;
|
|
||||||
m_flags = flags;
|
|
||||||
Console()->RegisterCommand(this);
|
|
||||||
};
|
|
||||||
const char *ConCommand::GetHelpText( void )
|
|
||||||
{
|
|
||||||
return m_szHelpString;
|
|
||||||
}
|
|
||||||
const char *ConCommand::GetName( void )
|
|
||||||
{
|
|
||||||
return m_szName;
|
|
||||||
}
|
|
||||||
ConCommandFn ConCommand::GetCallback( void )
|
|
||||||
{
|
|
||||||
return m_callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -330,6 +226,7 @@ void IConsole_Exec( int argc, char **argv)
|
|||||||
CUtlBuffer<char> b(filesystem->Size(f)+1);
|
CUtlBuffer<char> b(filesystem->Size(f)+1);
|
||||||
filesystem->Read(f, b, b.GetSize());
|
filesystem->Read(f, b, b.GetSize());
|
||||||
b[b.GetSize()-1] = 0;
|
b[b.GetSize()-1] = 0;
|
||||||
|
|
||||||
Console()->AddCommand(b);
|
Console()->AddCommand(b);
|
||||||
Console()->AddCommand(";");
|
Console()->AddCommand(";");
|
||||||
Console()->Execute();
|
Console()->Execute();
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "cl_dll.h"
|
#include "cl_dll.h"
|
||||||
#include "inetworkserver.h"
|
#include "inetworkserver.h"
|
||||||
#include "inetworkclient.h"
|
#include "inetworkclient.h"
|
||||||
|
#include "ihumandevice.h"
|
||||||
|
|
||||||
#ifdef STEAM
|
#ifdef STEAM
|
||||||
#include "steam/steam_api.h"
|
#include "steam/steam_api.h"
|
||||||
@@ -22,6 +23,14 @@ IGameWindowManager *g_pWindowManager;
|
|||||||
CServerGameDLL *g_pServerGame;
|
CServerGameDLL *g_pServerGame;
|
||||||
CClientGameDLL *g_pClientGame;
|
CClientGameDLL *g_pClientGame;
|
||||||
|
|
||||||
|
static void CallKeyEvent( EInputDeviceType eDevice, EInputButton eButton, bool bIsPressed )
|
||||||
|
{
|
||||||
|
if (bIsPressed)
|
||||||
|
g_pHumanDeviceManager->SetButtonPressed(eButton);
|
||||||
|
else
|
||||||
|
g_pHumanDeviceManager->SetButtonUnpressed(eButton);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" void __cdecl SteamAPIDebug( ESteamNetworkingSocketsDebugOutputType nType, const char *pszMsg )
|
extern "C" void __cdecl SteamAPIDebug( ESteamNetworkingSocketsDebugOutputType nType, const char *pszMsg )
|
||||||
{
|
{
|
||||||
V_printf("STEAM: %s\n", pszMsg);
|
V_printf("STEAM: %s\n", pszMsg);
|
||||||
@@ -67,6 +76,7 @@ extern "C" void FunnyMain( int argc, char **argv )
|
|||||||
|
|
||||||
pWindow = g_pWindowManager->CreateWindow();
|
pWindow = g_pWindowManager->CreateWindow();
|
||||||
pWindow->Init();
|
pWindow->Init();
|
||||||
|
pWindow->SetKeyCallback(CallKeyEvent);
|
||||||
|
|
||||||
g_pRenderContext = (IRenderContext*)pRenderSystemFactory(RENDER_CONTEXT_INTERFACE_VERSION, NULL);
|
g_pRenderContext = (IRenderContext*)pRenderSystemFactory(RENDER_CONTEXT_INTERFACE_VERSION, NULL);
|
||||||
g_pRenderContext->SetMainWindowManager(g_pWindowManager);
|
g_pRenderContext->SetMainWindowManager(g_pWindowManager);
|
||||||
@@ -98,6 +108,7 @@ extern "C" void FunnyMain( int argc, char **argv )
|
|||||||
double fDelta = fCurrent-fPrevious;
|
double fDelta = fCurrent-fPrevious;
|
||||||
fPrevious = fCurrent;
|
fPrevious = fCurrent;
|
||||||
|
|
||||||
|
g_pHumanDeviceManager->Frame();
|
||||||
g_pServerGame->m_pBridge->Frame(fDelta);
|
g_pServerGame->m_pBridge->Frame(fDelta);
|
||||||
|
|
||||||
if (!stConstants.m_bIsDedicated)
|
if (!stConstants.m_bIsDedicated)
|
||||||
|
|||||||
@@ -1,24 +1,93 @@
|
|||||||
#include "humandevice.h"
|
#include "ihumandevice.h"
|
||||||
#include "tier1/interface.h"
|
#include "tier1/interface.h"
|
||||||
|
#include "tier1/utlvector.h"
|
||||||
|
|
||||||
class CHumanDeviceManager: public IHumanDeviceManager
|
class CHumanDeviceManager: public IHumanDeviceManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
virtual void Frame() override;
|
||||||
|
|
||||||
|
virtual void SetDefaultInput( IHumanDeviceInput *pInput ) override;
|
||||||
|
virtual void PushInput( IHumanDeviceInput *pInput ) override;
|
||||||
|
virtual void PopInput() override;
|
||||||
|
virtual IHumanDeviceInput *GetCurrentInput() override;
|
||||||
|
|
||||||
virtual void SetButtonPressed( EInputButton eButton ) override;
|
virtual void SetButtonPressed( EInputButton eButton ) override;
|
||||||
virtual void SetButtonUnpressed( EInputButton eButton ) override;
|
virtual void SetButtonUnpressed( EInputButton eButton ) override;
|
||||||
|
|
||||||
bool m_abIsButtonPressed[k_EInputButton_Count];
|
virtual void WriteUTF8( uint32_t uCode ) override;
|
||||||
|
|
||||||
|
bool m_abIsButtonPressed[k_EInputButton_Count] = {};
|
||||||
|
bool m_abWasButtonPressed[k_EInputButton_Count] = {};
|
||||||
|
CUtlVector<IHumanDeviceInput*> m_apInputStack;
|
||||||
|
IHumanDeviceInput *m_pDefaultInput;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
CHumanDeviceManager s_manager;
|
||||||
|
IHumanDeviceManager *g_pHumanDeviceManager = &s_manager;
|
||||||
|
|
||||||
|
void CHumanDeviceManager::Frame()
|
||||||
|
{
|
||||||
|
IHumanDeviceInput *pInput = GetCurrentInput();
|
||||||
|
if (pInput)
|
||||||
|
{
|
||||||
|
for ( int i = 0; i < k_EInputButton_Count; i++ )
|
||||||
|
{
|
||||||
|
if (m_abIsButtonPressed[i] == m_abWasButtonPressed[i])
|
||||||
|
continue;
|
||||||
|
pInput->OnGameButton(k_EInputDevice_Keyboard,
|
||||||
|
(EInputButton)i, m_abIsButtonPressed[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
V_memcpy(m_abWasButtonPressed, m_abIsButtonPressed, sizeof(m_abIsButtonPressed));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CHumanDeviceManager::SetDefaultInput( IHumanDeviceInput *pInput )
|
||||||
|
{
|
||||||
|
m_pDefaultInput = pInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHumanDeviceManager::PushInput( IHumanDeviceInput *pInput )
|
||||||
|
{
|
||||||
|
m_apInputStack.AppendTail(pInput);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHumanDeviceManager::PopInput()
|
||||||
|
{
|
||||||
|
m_apInputStack.RemoveTail();
|
||||||
|
}
|
||||||
|
|
||||||
|
IHumanDeviceInput *CHumanDeviceManager::GetCurrentInput()
|
||||||
|
{
|
||||||
|
if (m_apInputStack.GetSize() == 0)
|
||||||
|
return m_pDefaultInput;
|
||||||
|
return m_apInputStack[m_apInputStack.GetSize()-1];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void CHumanDeviceManager::SetButtonPressed( EInputButton eButton )
|
void CHumanDeviceManager::SetButtonPressed( EInputButton eButton )
|
||||||
{
|
{
|
||||||
m_abIsButtonPressed[eButton] = true;
|
m_abIsButtonPressed[eButton] = true;
|
||||||
|
IHumanDeviceInput *pInput = GetCurrentInput();
|
||||||
|
if (pInput)
|
||||||
|
pInput->OnButton(k_EInputDevice_Keyboard, eButton, true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CHumanDeviceManager::SetButtonUnpressed( EInputButton eButton )
|
void CHumanDeviceManager::SetButtonUnpressed( EInputButton eButton )
|
||||||
{
|
{
|
||||||
m_abIsButtonPressed[eButton] = false;
|
m_abIsButtonPressed[eButton] = false;
|
||||||
|
IHumanDeviceInput *pInput = GetCurrentInput();
|
||||||
|
if (pInput)
|
||||||
|
pInput->OnButton(k_EInputDevice_Keyboard, eButton, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CHumanDeviceManager::WriteUTF8( uint32_t uCode )
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
EXPOSE_INTERFACE_GLOBALVAR(CHumanDeviceManager, IHumanDeviceManager, HUMAN_DEVICE_MANAGER_INTERFACE_VERSION, g_pHumanDeviceManager)
|
EXPOSE_INTERFACE_GLOBALVAR(CHumanDeviceManager, IHumanDeviceManager, HUMAN_DEVICE_MANAGER_INTERFACE_VERSION, g_pHumanDeviceManager)
|
||||||
|
|||||||
@@ -6,19 +6,11 @@
|
|||||||
|
|
||||||
void CServerGameDLL::Init()
|
void CServerGameDLL::Init()
|
||||||
{
|
{
|
||||||
void *pLib;
|
CreateInterfaceFn pfnServerFactory = Sys_GetFactory("server");
|
||||||
|
|
||||||
#ifdef __linux
|
|
||||||
pLib = Plat_LoadLibrary("libserver.so");
|
|
||||||
#endif
|
|
||||||
if (!pLib)
|
|
||||||
Plat_FatalErrorFunc("Failed to load server library\n");
|
|
||||||
m_pLibrary = pLib;
|
|
||||||
|
|
||||||
CreateInterfaceFn pfnServerFactory = Sys_GetFactory(pLib);
|
|
||||||
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
|
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
|
||||||
pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
||||||
pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts);
|
pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts);
|
||||||
|
pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
||||||
pEngineBridge->Init();
|
pEngineBridge->Init();
|
||||||
m_pBridge = pEngineBridge;
|
m_pBridge = pEngineBridge;
|
||||||
}
|
}
|
||||||
|
|||||||
2
external/GameNetworkingSockets
vendored
2
external/GameNetworkingSockets
vendored
Submodule external/GameNetworkingSockets updated: 517fff0cf6...725e273c74
2
external/SDL
vendored
2
external/SDL
vendored
Submodule external/SDL updated: 77f4a8e2b8...7c11a8cb9f
2
external/Vulkan-Headers
vendored
2
external/Vulkan-Headers
vendored
Submodule external/Vulkan-Headers updated: ad9ce1235e...2e0a6e699e
2
external/Vulkan-Utility-Libraries
vendored
2
external/Vulkan-Utility-Libraries
vendored
Submodule external/Vulkan-Utility-Libraries updated: 738ec97a3f...4f4c0b6c61
2
external/VulkanMemoryAllocator
vendored
2
external/VulkanMemoryAllocator
vendored
Submodule external/VulkanMemoryAllocator updated: e722e57c89...f0969e908b
2
external/cglm
vendored
2
external/cglm
vendored
Submodule external/cglm updated: 83d5b2c973...a886d6e170
2
external/slang
vendored
2
external/slang
vendored
Submodule external/slang updated: 6128e511c7...5d775e2829
2
external/stb
vendored
2
external/stb
vendored
Submodule external/stb updated: f1c79c0282...802cd454f2
2
external/volk
vendored
2
external/volk
vendored
Submodule external/volk updated: 87f4f07894...d64d20b4ea
2
external/xtool
vendored
2
external/xtool
vendored
Submodule external/xtool updated: f12a84e960...22655f3e70
@@ -81,6 +81,8 @@ private:
|
|||||||
Vector m_vPosition;
|
Vector m_vPosition;
|
||||||
Quat m_vRotation;
|
Quat m_vRotation;
|
||||||
Vector m_vScale;
|
Vector m_vScale;
|
||||||
|
|
||||||
|
uint64_t m_uSlot;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ DECLARE_BUILD_STAGE(Client)
|
|||||||
|
|
||||||
compileProject.m_szName = "client";
|
compileProject.m_szName = "client";
|
||||||
compileProject.files = {
|
compileProject.files = {
|
||||||
|
"../shared/game.cpp",
|
||||||
|
|
||||||
"game.cpp",
|
"game.cpp",
|
||||||
|
|
||||||
"baseentity.cpp",
|
"baseentity.cpp",
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
|
|
||||||
|
#include "netprotocol.h"
|
||||||
|
|
||||||
|
|
||||||
CEntitySystem *EntitySystem()
|
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()
|
C_BaseEntity **CEntitySystem::GetEntities()
|
||||||
{
|
{
|
||||||
return m_pEntities;
|
return m_pEntities;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
C_BaseEntity *UTIL_GetLocalPlayer()
|
||||||
|
{
|
||||||
|
return s_pLocalEntity;
|
||||||
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
#define ENTITIES_H
|
#define ENTITIES_H
|
||||||
|
|
||||||
#include "stdint.h"
|
#include "stdint.h"
|
||||||
|
#include "networkbase.h"
|
||||||
|
|
||||||
class IEntityFactory;
|
class IEntityFactory;
|
||||||
class C_BaseEntity;
|
class C_BaseEntity;
|
||||||
@@ -29,6 +30,10 @@ public:
|
|||||||
virtual void DestroyEntityByPtr( C_BaseEntity *pEntity );
|
virtual void DestroyEntityByPtr( C_BaseEntity *pEntity );
|
||||||
|
|
||||||
virtual void Think();
|
virtual void Think();
|
||||||
|
|
||||||
|
virtual void NetRecvPacket( NetPacket_t *pPacket );
|
||||||
|
virtual void NetSendThink();
|
||||||
|
|
||||||
virtual C_BaseEntity **GetEntities();
|
virtual C_BaseEntity **GetEntities();
|
||||||
private:
|
private:
|
||||||
C_BaseEntity *m_pEntities[MAX_EDICTS];
|
C_BaseEntity *m_pEntities[MAX_EDICTS];
|
||||||
@@ -37,4 +42,6 @@ private:
|
|||||||
|
|
||||||
CEntitySystem *EntitySystem();
|
CEntitySystem *EntitySystem();
|
||||||
|
|
||||||
|
C_BaseEntity *UTIL_GetLocalPlayer();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -15,21 +15,6 @@
|
|||||||
#include "steam/steam_gameserver.h"
|
#include "steam/steam_gameserver.h"
|
||||||
#endif
|
#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
|
class CFunnyGameBridge: public IEngineBridge
|
||||||
{
|
{
|
||||||
virtual void Init() override;
|
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()
|
IEngineBridge *EngineBridge()
|
||||||
{
|
{
|
||||||
static CFunnyGameBridge s_bridge;
|
static CFunnyGameBridge s_bridge;
|
||||||
@@ -52,6 +66,7 @@ IEngineBridge *EngineBridge()
|
|||||||
|
|
||||||
EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION)
|
EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION)
|
||||||
|
|
||||||
|
static CFunnyInput s_mainInput;
|
||||||
|
|
||||||
void CFunnyGameBridge::Init()
|
void CFunnyGameBridge::Init()
|
||||||
{
|
{
|
||||||
@@ -79,30 +94,14 @@ void CFunnyGameBridge::Init()
|
|||||||
CreateInterfaceFn fnPhysicsFactory = Sys_GetFactory("RapierPhysics");
|
CreateInterfaceFn fnPhysicsFactory = Sys_GetFactory("RapierPhysics");
|
||||||
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
|
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
|
||||||
g_pPhysicsWorld = g_pPhysics->CreateWorld();
|
g_pPhysicsWorld = g_pPhysics->CreateWorld();
|
||||||
|
|
||||||
|
g_pHumanDeviceManager->SetDefaultInput(&s_mainInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFunnyGameBridge::Tick( float fDelta )
|
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()
|
void CFunnyGameBridge::TryToConnectToServer()
|
||||||
{
|
{
|
||||||
@@ -111,27 +110,25 @@ void CFunnyGameBridge::TryToConnectToServer()
|
|||||||
{
|
{
|
||||||
if (m_bIsConnectedToSteamRelay != 0 )
|
if (m_bIsConnectedToSteamRelay != 0 )
|
||||||
return;
|
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;
|
m_bIsConnectedToServer = true;
|
||||||
V_printf("%llu\n", SteamUser()->GetSteamID().ConvertToUint64());
|
C_BaseEntity **ppEntities = EntitySystem()->GetEntities();
|
||||||
if (CommandLine()->ParamValue("-steam-connect"))
|
for ( int i = 0; i < MAX_EDICTS; i++ )
|
||||||
{
|
{
|
||||||
char *pEnd = NULL;
|
EntitySystem()->DestroyEntityByIndex(i);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -158,53 +155,19 @@ void CFunnyGameBridge::Frame( float fDelta )
|
|||||||
while ( pCurrentServer->BHasUpdates() )
|
while ( pCurrentServer->BHasUpdates() )
|
||||||
{
|
{
|
||||||
NetPacket_t packet = pCurrentServer->PeekPacket();
|
NetPacket_t packet = pCurrentServer->PeekPacket();
|
||||||
|
|
||||||
// discard it
|
// discard it
|
||||||
if (packet.uSize < sizeof (EMessageType))
|
if (packet.uSize < sizeof (EMessageType))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
PlayerPacket_t *pPacket = (PlayerPacket_t*)packet.pData;
|
PlayerPacket_t *pPacket = (PlayerPacket_t*)packet.pData;
|
||||||
C_BaseEntity *pEntity;
|
C_BaseEntity *pEntity;
|
||||||
switch (pPacket->m_eType)
|
switch (pPacket->m_eType)
|
||||||
{
|
{
|
||||||
case MESSAGE_ENTITY_CLASS_SYNC:
|
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:
|
case MESSAGE_ENTITY_DATA_SYNC:
|
||||||
pEntity = EntitySystem()->GetEntities()[pPacket->m_entityData.m_uIndex];
|
case k_EMessage_PlayerSetLocalEntity:
|
||||||
if (pEntity == NULL)
|
EntitySystem()->NetRecvPacket(&packet);
|
||||||
{
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
pCurrentServer->RecievePacket();
|
pCurrentServer->RecievePacket();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@@ -227,8 +190,9 @@ void CFunnyGameBridge::Shutdown()
|
|||||||
#define CONNECT_INTERFACE(szName, pGlobal) if (!V_strcmp(psz, szName)) { pGlobal = (typeof(pGlobal))pInterface; return; }
|
#define CONNECT_INTERFACE(szName, pGlobal) if (!V_strcmp(psz, szName)) { pGlobal = (typeof(pGlobal))pInterface; return; }
|
||||||
void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface )
|
void CFunnyGameBridge::ConnectInterface( const char *psz, void *pInterface )
|
||||||
{
|
{
|
||||||
CONNECT_INTERFACE(RENDER_CONTEXT_INTERFACE_VERSION, g_pRenderContext);
|
|
||||||
CONNECT_INTERFACE(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
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("MainWindow", g_pMainWindow);
|
||||||
CONNECT_INTERFACE("EngineConstants", g_pEngineConstants);
|
CONNECT_INTERFACE("EngineConstants", g_pEngineConstants);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "cglm/cglm.h"
|
#include "cglm/cglm.h"
|
||||||
#include "assetmgr.h"
|
#include "assetmgr.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
void C_MOBAPlayer::Precache()
|
void C_MOBAPlayer::Precache()
|
||||||
{
|
{
|
||||||
@@ -12,12 +13,19 @@ void C_MOBAPlayer::Spawn()
|
|||||||
{
|
{
|
||||||
BaseClass::Spawn();
|
BaseClass::Spawn();
|
||||||
SetThink(Think);
|
SetThink(Think);
|
||||||
g_pWorldRenderer->SetCameraPosition({0, 0, -20});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void C_MOBAPlayer::Think( float fDelta )
|
void C_MOBAPlayer::Think( float fDelta )
|
||||||
{
|
{
|
||||||
|
|
||||||
BaseClass::Think(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)
|
LINK_ENTITY_TO_CLASS(player, C_MOBAPlayer)
|
||||||
@@ -26,7 +34,21 @@ BEGIN_DATADESC(C_MOBAPlayer)
|
|||||||
END_DATADESC()
|
END_DATADESC()
|
||||||
|
|
||||||
IMPLEMENT_RECV_DT(C_MOBAPlayer)
|
IMPLEMENT_RECV_DT(C_MOBAPlayer)
|
||||||
NetPropFloat(m_fTimer),
|
|
||||||
END_RECV_DT()
|
END_RECV_DT()
|
||||||
IMPLEMENT_EMPTY_SEND_DT(C_MOBAPlayer)
|
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);
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ public:
|
|||||||
virtual void Spawn( void ) override;
|
virtual void Spawn( void ) override;
|
||||||
void Think( float fDelta );
|
void Think( float fDelta );
|
||||||
|
|
||||||
float m_fTimer;
|
|
||||||
int m_bIsShooting;
|
int m_bIsShooting;
|
||||||
float m_fFBWalkingDirection;
|
float m_fFBWalkingDirection;
|
||||||
float m_fLRWalkingDirection;
|
float m_fLRWalkingDirection;
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
|
||||||
#include "worldrender.h"
|
#include "worldrender.h"
|
||||||
#include "tier1/utlstring.h"
|
#include "tier1/utlstring.h"
|
||||||
#include "engine.h"
|
|
||||||
#include "cglm/cglm.h"
|
#include "cglm/cglm.h"
|
||||||
#include "cglm/quat.h"
|
#include "cglm/quat.h"
|
||||||
#include "cglm/mat4.h"
|
#include "cglm/mat4.h"
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
struct ViewBuffer_t
|
struct ViewBuffer_t
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ DECLARE_BUILD_STAGE(Server)
|
|||||||
|
|
||||||
compileProject.m_szName = "server";
|
compileProject.m_szName = "server";
|
||||||
compileProject.files = {
|
compileProject.files = {
|
||||||
|
"../shared/game.cpp",
|
||||||
|
|
||||||
"game.cpp",
|
"game.cpp",
|
||||||
"assetmgr.cpp",
|
"assetmgr.cpp",
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "stddef.h"
|
#include "stddef.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "stdlib.h"
|
#include "stdlib.h"
|
||||||
#include "engine.h"
|
#include "game.h"
|
||||||
#include "netprotocol.h"
|
#include "netprotocol.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -56,7 +56,7 @@ void CEntitySystem::RegisterEntityClass( IEntityFactory *pEntityFactory, const c
|
|||||||
s_pEntitiesRegistry = pRegistry;
|
s_pEntitiesRegistry = pRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBaseEntity *CEntitySystem::CreateByClassname( const char *szName )
|
CBaseEntity *CEntitySystem::CreateByClassname( const char *szName, int *pOutputIndex )
|
||||||
{
|
{
|
||||||
IEntityFactory *pFactory;
|
IEntityFactory *pFactory;
|
||||||
CBaseEntity *pEntity;
|
CBaseEntity *pEntity;
|
||||||
@@ -87,6 +87,9 @@ CBaseEntity *CEntitySystem::CreateByClassname( const char *szName )
|
|||||||
m_pEntities[iSelectedSlot] = pEntity;
|
m_pEntities[iSelectedSlot] = pEntity;
|
||||||
m_nEntityCount++;
|
m_nEntityCount++;
|
||||||
|
|
||||||
|
if (pOutputIndex)
|
||||||
|
*pOutputIndex = iSelectedSlot;
|
||||||
|
|
||||||
EntityClass_t stClassSync = {
|
EntityClass_t stClassSync = {
|
||||||
MESSAGE_ENTITY_CLASS_SYNC,
|
MESSAGE_ENTITY_CLASS_SYNC,
|
||||||
iSelectedSlot,
|
iSelectedSlot,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public:
|
|||||||
CEntitySystem();
|
CEntitySystem();
|
||||||
|
|
||||||
virtual void RegisterEntityClass( IEntityFactory *pEntityFactory, const char *szClassName );
|
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 );
|
virtual IEntityFactory *GetFactoryByClassname( const char *szName );
|
||||||
|
|
||||||
|
|||||||
@@ -12,23 +12,6 @@
|
|||||||
#include "steam/steam_gameserver.h"
|
#include "steam/steam_gameserver.h"
|
||||||
#endif
|
#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
|
class CFunnyGameBridge: public IEngineBridge
|
||||||
{
|
{
|
||||||
virtual void Init() override;
|
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});
|
g_pCurrentConnection->SendPacket({&stClassSync, sizeof(stClassSync), pCallback->m_ullUserConnection, PACKET_MUST_ARRIVE});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int iIndex = -1;
|
||||||
CBaseEntity *pEntity;
|
CBaseEntity *pEntity;
|
||||||
pEntity = EntitySystem()->CreateByClassname("player");
|
pEntity = EntitySystem()->CreateByClassname("player", &iIndex);
|
||||||
pEntity->Spawn();
|
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 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@@ -149,13 +140,29 @@ void NET_ProcessPacket( INetworkBase *pBase )
|
|||||||
switch (pPacket->m_eType)
|
switch (pPacket->m_eType)
|
||||||
{
|
{
|
||||||
case MESSAGE_PLAYER_JOINED:
|
case MESSAGE_PLAYER_JOINED:
|
||||||
// online packets don't generate these
|
{
|
||||||
if (g_pEngineConstants->m_bIsDedicated)
|
|
||||||
break;
|
// online packets don't generate these
|
||||||
pBase->RecievePacket();
|
if (g_pEngineConstants->m_bIsDedicated)
|
||||||
V_printf("Hi %s\n",pPacket->m_playerJoined.m_szPlayerName);
|
break;
|
||||||
pEntity = EntitySystem()->CreateByClassname("player");
|
|
||||||
pEntity->Spawn();
|
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;
|
return;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,19 +1,20 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "entitysystem.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void CMOBAPlayer::Spawn()
|
void CMOBAPlayer::Spawn()
|
||||||
{
|
{
|
||||||
|
CPhysicsProp::Spawn();
|
||||||
SetModel("game/core/models/cube.fmdl");
|
SetModel("game/core/models/cube.fmdl");
|
||||||
|
SetScale(1);
|
||||||
SetThink(Think);
|
SetThink(Think);
|
||||||
m_fTimer = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void CMOBAPlayer::Think( float fDelta )
|
void CMOBAPlayer::Think( float fDelta )
|
||||||
{
|
{
|
||||||
BaseClass::Think(fDelta);
|
CPhysicsProp::Think(fDelta);
|
||||||
SetScale(1);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
LINK_ENTITY_TO_CLASS(player, CMOBAPlayer)
|
LINK_ENTITY_TO_CLASS(player, CMOBAPlayer)
|
||||||
@@ -22,7 +23,6 @@ BEGIN_DATADESC(CMOBAPlayer)
|
|||||||
END_DATADESC()
|
END_DATADESC()
|
||||||
|
|
||||||
IMPLEMENT_SEND_DT(CMOBAPlayer)
|
IMPLEMENT_SEND_DT(CMOBAPlayer)
|
||||||
NetPropFloat(m_fTimer)
|
|
||||||
END_SEND_DT()
|
END_SEND_DT()
|
||||||
|
|
||||||
IMPLEMENT_EMPTY_RECV_DT(CMOBAPlayer)
|
IMPLEMENT_EMPTY_RECV_DT(CMOBAPlayer)
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
#ifndef MILMOBA_PLAYER_H
|
#ifndef MILMOBA_PLAYER_H
|
||||||
#define MILMOBA_PLAYER_H
|
#define MILMOBA_PLAYER_H
|
||||||
|
|
||||||
#include "basemodelentity.h"
|
#include "physicsprop.h"
|
||||||
|
|
||||||
class CMOBAPlayer: public CBaseModelEntity
|
class CMOBAPlayer: public CPhysicsProp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DECLARE_CLASS(CMOBAPlayer, CBaseModelEntity);
|
DECLARE_CLASS(CMOBAPlayer, CPhysicsProp);
|
||||||
DECLARE_DATADESC();
|
DECLARE_DATADESC();
|
||||||
DECLARE_SERVERCLASS()
|
DECLARE_SERVERCLASS()
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ void CPhysicsProp::Precache()
|
|||||||
|
|
||||||
void CPhysicsProp::Spawn()
|
void CPhysicsProp::Spawn()
|
||||||
{
|
{
|
||||||
|
CBaseEntity::Spawn();
|
||||||
SetThink(Think);
|
SetThink(Think);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
#ifndef ENGINE_H
|
|
||||||
#define ENGINE_H
|
|
||||||
|
|
||||||
#include "tier2/ifilesystem.h"
|
|
||||||
#include "materialsystem/imaterialsystem.h"
|
|
||||||
#include "materialsystem/igamewindow.h"
|
|
||||||
#include "networkbase.h"
|
|
||||||
|
|
||||||
struct EngineConsts_t
|
|
||||||
{
|
|
||||||
bool m_bIsDedicated;
|
|
||||||
bool m_bIsSteam;
|
|
||||||
INetworkBase *(LaunchLocalBridge)(uint16_t uPort);
|
|
||||||
INetworkBase *(LaunchServer)(uint16_t uPort);
|
|
||||||
INetworkBase *(ConnectLocalBridge)(uint16_t uPort);
|
|
||||||
INetworkBase *(ConnectSteamServer)(uint64_t uServer, uint16_t uPort);
|
|
||||||
};
|
|
||||||
|
|
||||||
extern IFileSystem *filesystem;
|
|
||||||
extern IRenderContext *g_pRenderContext;
|
|
||||||
extern IGameWindow *g_pMainWindow;
|
|
||||||
extern EngineConsts_t *g_pEngineConstants;
|
|
||||||
extern INetworkBase *g_pServerBridge;
|
|
||||||
extern INetworkBase *g_pClientBridge;
|
|
||||||
extern INetworkBase *g_pPublicConnection;
|
|
||||||
extern INetworkBase *g_pCurrentConnection;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
40
game/shared/game.cpp
Normal file
40
game/shared/game.cpp
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
#include "game.h"
|
||||||
|
|
||||||
|
IFileSystem *filesystem;
|
||||||
|
IRenderContext *g_pRenderContext;
|
||||||
|
IGameWindow *g_pMainWindow;
|
||||||
|
|
||||||
|
IHumanDeviceManager *g_pHumanDeviceManager;
|
||||||
|
|
||||||
|
INetworkBase *g_pServerBridge;
|
||||||
|
INetworkBase *g_pClientBridge;
|
||||||
|
INetworkBase *g_pServerConnection;
|
||||||
|
|
||||||
|
INetworkBase *g_pPublicConnection;
|
||||||
|
INetworkBase *g_pCurrentConnection;
|
||||||
|
|
||||||
|
|
||||||
|
static CEngineVars s_vars;
|
||||||
|
CEngineVars *g_pEngineVars = &s_vars;
|
||||||
|
EngineConsts_t *g_pEngineConstants;
|
||||||
|
|
||||||
|
IPhysics *g_pPhysics;
|
||||||
|
IPhysicsWorld *g_pPhysicsWorld;
|
||||||
|
|
||||||
|
CreateInterfaceFn GetEngineFactory()
|
||||||
|
{
|
||||||
|
return Sys_GetFactory("engine");
|
||||||
|
};
|
||||||
|
|
||||||
|
// we need it to run before everything else
|
||||||
|
static IConsole *s_pConsole =
|
||||||
|
(IConsole*)GetEngineFactory()(CONSOLE_INTERFACE_VERSION, NULL);
|
||||||
|
IConsole *g_pConsole = s_pConsole;
|
||||||
|
EXPOSE_INTERFACE_GLOBALVAR(IConsole, IConsole, CONSOLE_INTERFACE_VERSION, g_pConsole)
|
||||||
|
|
||||||
|
IConsole *Console()
|
||||||
|
{
|
||||||
|
static IConsole *s_pConsole =
|
||||||
|
(IConsole*)GetEngineFactory()(CONSOLE_INTERFACE_VERSION, NULL);
|
||||||
|
return s_pConsole;
|
||||||
|
}
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
#ifndef GAME_H
|
#ifndef GAME_H
|
||||||
#define GAME_H
|
#define GAME_H
|
||||||
|
|
||||||
#include "tier2/ifilesystem.h"
|
#include "tier2/ifilesystem.h"
|
||||||
|
#include "enginebridge.h"
|
||||||
|
#include "icvar.h"
|
||||||
#include "materialsystem/imaterialsystem.h"
|
#include "materialsystem/imaterialsystem.h"
|
||||||
|
#include "materialsystem/igamewindow.h"
|
||||||
|
#include "networkbase.h"
|
||||||
#include "iphysics.h"
|
#include "iphysics.h"
|
||||||
extern IRenderContext *g_pRenderContext;
|
#include "ihumandevice.h"
|
||||||
extern IFileSystem *filesystem;
|
|
||||||
extern IGameWindowManager *g_pWindowManager;
|
|
||||||
|
|
||||||
class CEngineVars
|
class CEngineVars
|
||||||
{
|
{
|
||||||
@@ -14,7 +17,24 @@ public:
|
|||||||
double m_fDeltaTime;
|
double m_fDeltaTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern IFileSystem *filesystem;
|
||||||
|
|
||||||
|
|
||||||
|
extern IRenderContext *g_pRenderContext;
|
||||||
|
extern IGameWindow *g_pMainWindow;
|
||||||
|
|
||||||
|
|
||||||
|
extern INetworkBase *g_pServerBridge;
|
||||||
|
extern INetworkBase *g_pClientBridge;
|
||||||
|
|
||||||
|
extern INetworkBase *g_pServerConnection;
|
||||||
|
extern INetworkBase *g_pPublicConnection;
|
||||||
|
extern INetworkBase *g_pCurrentConnection;
|
||||||
|
|
||||||
|
|
||||||
extern CEngineVars *g_pEngineVars;
|
extern CEngineVars *g_pEngineVars;
|
||||||
|
extern EngineConsts_t *g_pEngineConstants;
|
||||||
|
|
||||||
|
|
||||||
extern IPhysics *g_pPhysics;
|
extern IPhysics *g_pPhysics;
|
||||||
extern IPhysicsWorld *g_pPhysicsWorld;
|
extern IPhysicsWorld *g_pPhysicsWorld;
|
||||||
@@ -22,4 +42,11 @@ extern IPhysicsWorld *g_pPhysicsWorld;
|
|||||||
#define FUNNY_SECURE_PORT 27015
|
#define FUNNY_SECURE_PORT 27015
|
||||||
#define FUNNY_QUERY_PORT 27016
|
#define FUNNY_QUERY_PORT 27016
|
||||||
|
|
||||||
|
#define CON_COMMAND( name, description ) \
|
||||||
|
static void name( int c, char **v ); \
|
||||||
|
static ConCommand name##_command(#name, name, description); \
|
||||||
|
static void name( int c, char **v ) \
|
||||||
|
|
||||||
|
CreateInterfaceFn GetEngineFactory();
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -23,6 +23,8 @@ enum EMessageType: uint32_t
|
|||||||
MESSAGE_PLAYER_LEFT,
|
MESSAGE_PLAYER_LEFT,
|
||||||
MESSAGE_ENTITY_CLASS_SYNC,
|
MESSAGE_ENTITY_CLASS_SYNC,
|
||||||
MESSAGE_ENTITY_DATA_SYNC,
|
MESSAGE_ENTITY_DATA_SYNC,
|
||||||
|
|
||||||
|
k_EMessage_PlayerSetLocalEntity,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PlayerJoined_t
|
struct PlayerJoined_t
|
||||||
@@ -53,7 +55,7 @@ struct EntityClass_t
|
|||||||
struct EntityDataSync_t
|
struct EntityDataSync_t
|
||||||
{
|
{
|
||||||
EMessageType m_eType;
|
EMessageType m_eType;
|
||||||
CNetworkUInt32 m_uIndex;
|
CNetworkUInt32 m_uIndex;
|
||||||
CNetworkUInt32 m_uCount;
|
CNetworkUInt32 m_uCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -63,6 +65,12 @@ struct EntityDataSyncValue_t
|
|||||||
CNetworkUInt32 m_uVariableSize;
|
CNetworkUInt32 m_uVariableSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct SetLocalEntity_t
|
||||||
|
{
|
||||||
|
EMessageType m_eType;
|
||||||
|
CNetworkUInt32 m_uIndex;
|
||||||
|
};
|
||||||
|
|
||||||
union PlayerPacket_t
|
union PlayerPacket_t
|
||||||
{
|
{
|
||||||
EMessageType m_eType;
|
EMessageType m_eType;
|
||||||
@@ -71,6 +79,7 @@ union PlayerPacket_t
|
|||||||
PlayerLeft_t m_playerLeft;
|
PlayerLeft_t m_playerLeft;
|
||||||
EntityClass_t m_entityClass;
|
EntityClass_t m_entityClass;
|
||||||
EntityDataSync_t m_entityData;
|
EntityDataSync_t m_entityData;
|
||||||
|
SetLocalEntity_t m_setLocalEntity;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -25,11 +25,17 @@ public:
|
|||||||
virtual void SetOutputImage( IImage *pImage ) override;
|
virtual void SetOutputImage( IImage *pImage ) override;
|
||||||
virtual IImage *GetOutputImage() override;
|
virtual IImage *GetOutputImage() override;
|
||||||
|
|
||||||
|
virtual void SetKeyCallback( KeyCallbackFn fn ) override;
|
||||||
|
virtual void SetAxisCallback( AxisCallbackFn fn ) override;
|
||||||
|
|
||||||
virtual void *CreateVulkanSurface( void *pInstance ) override;
|
virtual void *CreateVulkanSurface( void *pInstance ) override;
|
||||||
virtual void DestroyVulkanSurface( void *pInstance ) override;
|
virtual void DestroyVulkanSurface( void *pInstance ) override;
|
||||||
|
|
||||||
SDL_WindowID WindowID();
|
SDL_WindowID WindowID();
|
||||||
|
|
||||||
|
KeyCallbackFn m_fnKeyCallback;
|
||||||
|
AxisCallbackFn m_fnAxisCallback;
|
||||||
|
|
||||||
bool m_bWindowSizeUpdated;
|
bool m_bWindowSizeUpdated;
|
||||||
uint32_t m_uRenderWidth;
|
uint32_t m_uRenderWidth;
|
||||||
uint32_t m_uRenderHeight;
|
uint32_t m_uRenderHeight;
|
||||||
@@ -87,6 +93,16 @@ IImage *CSDLGameWindow::GetOutputImage()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void CSDLGameWindow::SetKeyCallback( KeyCallbackFn fn )
|
||||||
|
{
|
||||||
|
m_fnKeyCallback = fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSDLGameWindow::SetAxisCallback( AxisCallbackFn fn )
|
||||||
|
{
|
||||||
|
m_fnAxisCallback = fn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void *CSDLGameWindow::CreateVulkanSurface( void *pInstance )
|
void *CSDLGameWindow::CreateVulkanSurface( void *pInstance )
|
||||||
{
|
{
|
||||||
@@ -98,6 +114,7 @@ void CSDLGameWindow::DestroyVulkanSurface( void *pInstance )
|
|||||||
{
|
{
|
||||||
SDL_Vulkan_DestroySurface((VkInstance)pInstance, (VkSurfaceKHR)m_hSurface, NULL);
|
SDL_Vulkan_DestroySurface((VkInstance)pInstance, (VkSurfaceKHR)m_hSurface, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_WindowID CSDLGameWindow::WindowID()
|
SDL_WindowID CSDLGameWindow::WindowID()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -132,6 +149,76 @@ void CSDLGameWindowManager::Init()
|
|||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_GAMEPAD))
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS | SDL_INIT_GAMEPAD))
|
||||||
Plat_FatalErrorFunc("SDL_Init: %s\n", SDL_GetError());
|
Plat_FatalErrorFunc("SDL_Init: %s\n", SDL_GetError());
|
||||||
}
|
}
|
||||||
|
static EInputButton GetKeyButton( SDL_Keycode eCode )
|
||||||
|
{
|
||||||
|
switch(eCode)
|
||||||
|
{
|
||||||
|
case SDLK_ESCAPE: return k_EInputButton_ESCAPE;
|
||||||
|
case SDLK_TAB: return k_EInputButton_TAB;
|
||||||
|
case SDLK_RETURN: return k_EInputButton_ENTER;
|
||||||
|
case SDLK_RCTRL: return k_EInputButton_CONTROL;
|
||||||
|
case SDLK_LCTRL: return k_EInputButton_CONTROL;
|
||||||
|
case SDLK_RSHIFT: return k_EInputButton_SHIFT;
|
||||||
|
case SDLK_LSHIFT: return k_EInputButton_SHIFT;
|
||||||
|
case SDLK_RALT: return k_EInputButton_ALT;
|
||||||
|
case SDLK_LALT: return k_EInputButton_ALT;
|
||||||
|
case SDLK_SPACE: return k_EInputButton_SPACE;
|
||||||
|
|
||||||
|
case SDLK_GRAVE: return k_EInputButton_TILDE;
|
||||||
|
|
||||||
|
case SDLK_F1: return k_EInputButton_F1;
|
||||||
|
case SDLK_F2: return k_EInputButton_F2;
|
||||||
|
case SDLK_F3: return k_EInputButton_F3;
|
||||||
|
case SDLK_F4: return k_EInputButton_F4;
|
||||||
|
case SDLK_F5: return k_EInputButton_F5;
|
||||||
|
case SDLK_F6: return k_EInputButton_F6;
|
||||||
|
case SDLK_F7: return k_EInputButton_F7;
|
||||||
|
case SDLK_F8: return k_EInputButton_F8;
|
||||||
|
case SDLK_F9: return k_EInputButton_F9;
|
||||||
|
case SDLK_F10: return k_EInputButton_F10;
|
||||||
|
case SDLK_F11: return k_EInputButton_F11;
|
||||||
|
case SDLK_F12: return k_EInputButton_F12;
|
||||||
|
|
||||||
|
case SDLK_1: return k_EInputButton_1;
|
||||||
|
case SDLK_2: return k_EInputButton_2;
|
||||||
|
case SDLK_3: return k_EInputButton_3;
|
||||||
|
case SDLK_4: return k_EInputButton_4;
|
||||||
|
case SDLK_5: return k_EInputButton_5;
|
||||||
|
case SDLK_6: return k_EInputButton_6;
|
||||||
|
case SDLK_7: return k_EInputButton_7;
|
||||||
|
case SDLK_8: return k_EInputButton_8;
|
||||||
|
case SDLK_9: return k_EInputButton_9;
|
||||||
|
case SDLK_0: return k_EInputButton_0;
|
||||||
|
|
||||||
|
case SDLK_A: return k_EInputButton_A;
|
||||||
|
case SDLK_B: return k_EInputButton_B;
|
||||||
|
case SDLK_C: return k_EInputButton_C;
|
||||||
|
case SDLK_D: return k_EInputButton_D;
|
||||||
|
case SDLK_E: return k_EInputButton_E;
|
||||||
|
case SDLK_F: return k_EInputButton_F;
|
||||||
|
case SDLK_G: return k_EInputButton_G;
|
||||||
|
case SDLK_H: return k_EInputButton_H;
|
||||||
|
case SDLK_I: return k_EInputButton_I;
|
||||||
|
case SDLK_J: return k_EInputButton_J;
|
||||||
|
case SDLK_K: return k_EInputButton_K;
|
||||||
|
case SDLK_L: return k_EInputButton_L;
|
||||||
|
case SDLK_M: return k_EInputButton_M;
|
||||||
|
case SDLK_N: return k_EInputButton_N;
|
||||||
|
case SDLK_O: return k_EInputButton_O;
|
||||||
|
case SDLK_P: return k_EInputButton_P;
|
||||||
|
case SDLK_Q: return k_EInputButton_Q;
|
||||||
|
case SDLK_R: return k_EInputButton_R;
|
||||||
|
case SDLK_S: return k_EInputButton_S;
|
||||||
|
case SDLK_T: return k_EInputButton_T;
|
||||||
|
case SDLK_U: return k_EInputButton_U;
|
||||||
|
case SDLK_V: return k_EInputButton_V;
|
||||||
|
case SDLK_W: return k_EInputButton_W;
|
||||||
|
case SDLK_X: return k_EInputButton_X;
|
||||||
|
case SDLK_Y: return k_EInputButton_Y;
|
||||||
|
case SDLK_Z: return k_EInputButton_Z;
|
||||||
|
}
|
||||||
|
return k_EInputButton_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
void CSDLGameWindowManager::Frame( float fDelta )
|
void CSDLGameWindowManager::Frame( float fDelta )
|
||||||
{
|
{
|
||||||
@@ -159,6 +246,28 @@ void CSDLGameWindowManager::Frame( float fDelta )
|
|||||||
pWindow->m_uRenderWidth = event.window.data1;
|
pWindow->m_uRenderWidth = event.window.data1;
|
||||||
pWindow->m_uRenderHeight = event.window.data2;
|
pWindow->m_uRenderHeight = event.window.data2;
|
||||||
break;
|
break;
|
||||||
|
case SDL_EVENT_KEY_UP:
|
||||||
|
for (auto a: m_pWindows)
|
||||||
|
{
|
||||||
|
if (a->WindowID() != event.window.windowID)
|
||||||
|
break;
|
||||||
|
pWindow = a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (pWindow->m_fnKeyCallback)
|
||||||
|
pWindow->m_fnKeyCallback(k_EInputDevice_Keyboard, GetKeyButton(event.key.key), false);
|
||||||
|
break;
|
||||||
|
case SDL_EVENT_KEY_DOWN:
|
||||||
|
for (auto a: m_pWindows)
|
||||||
|
{
|
||||||
|
if (a->WindowID() != event.window.windowID)
|
||||||
|
break;
|
||||||
|
pWindow = a;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (pWindow->m_fnKeyCallback)
|
||||||
|
pWindow->m_fnKeyCallback(k_EInputDevice_Keyboard, GetKeyButton(event.key.key), true);
|
||||||
|
break;
|
||||||
case SDL_EVENT_QUIT:
|
case SDL_EVENT_QUIT:
|
||||||
Plat_Exit(0);
|
Plat_Exit(0);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
#include "gamesystem.h"
|
#include "gamesystem.h"
|
||||||
#include "networkbase.h"
|
#include "networkbase.h"
|
||||||
|
#include "icvar.h"
|
||||||
|
#include "tier1/interface.h"
|
||||||
|
|
||||||
struct EngineConsts_t
|
struct EngineConsts_t
|
||||||
{
|
{
|
||||||
|
|||||||
118
public/icvar.h
118
public/icvar.h
@@ -5,6 +5,7 @@
|
|||||||
#include "tier0/platform.h"
|
#include "tier0/platform.h"
|
||||||
#include "tier1/utlstring.h"
|
#include "tier1/utlstring.h"
|
||||||
#include "tier1/utlvector.h"
|
#include "tier1/utlvector.h"
|
||||||
|
#include "tier1/interface.h"
|
||||||
|
|
||||||
class ConVar;
|
class ConVar;
|
||||||
class ConCommand;
|
class ConCommand;
|
||||||
@@ -32,12 +33,10 @@ public:
|
|||||||
|
|
||||||
virtual void AddCommand( const char *psz ) = 0;
|
virtual void AddCommand( const char *psz ) = 0;
|
||||||
virtual void InsertCommand( const char *psz ) = 0;
|
virtual void InsertCommand( const char *psz ) = 0;
|
||||||
|
|
||||||
CUtlVector<ConVar*> m_convars;
|
|
||||||
CUtlVector<ConCommand*> m_commands;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
IConsole *Console();
|
IConsole *Console();
|
||||||
|
#define CONSOLE_INTERFACE_VERSION "Console001"
|
||||||
|
|
||||||
|
|
||||||
#define FCVAR_NONE 0
|
#define FCVAR_NONE 0
|
||||||
@@ -91,6 +90,92 @@ private:
|
|||||||
int m_flags;
|
int m_flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags )
|
||||||
|
: ConVar(pName, pDefaultValue, flags, 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
inline ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||||
|
const char *pHelpString )
|
||||||
|
: ConVar(pName, pDefaultValue, flags, pHelpString, 0)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
inline ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||||
|
const char *pHelpString, ConCommandFn callback )
|
||||||
|
{
|
||||||
|
m_szName = pName;
|
||||||
|
m_flags = flags;
|
||||||
|
SetValue(pDefaultValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool ConVar::IsFlagSet( int flag )
|
||||||
|
{
|
||||||
|
return (m_flags & flag) > 0;
|
||||||
|
}
|
||||||
|
inline const char *ConVar::GetHelpText( void )
|
||||||
|
{
|
||||||
|
return m_szHelpString;
|
||||||
|
}
|
||||||
|
inline bool ConVar::IsRegistered( void )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
inline const char *ConVar::GetName( void )
|
||||||
|
{
|
||||||
|
return m_szName;
|
||||||
|
}
|
||||||
|
inline void ConVar::AddFlags( int flags )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
inline bool ConVar::IsCommand( void )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void ConVar::InstallChangeCallback( ConCommandFn )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inline float ConVar::GetFloat( void )
|
||||||
|
{
|
||||||
|
return m_fValue;
|
||||||
|
}
|
||||||
|
inline int ConVar::GetInt( void )
|
||||||
|
{
|
||||||
|
return m_nValue;
|
||||||
|
}
|
||||||
|
inline bool ConVar::GetBool( void )
|
||||||
|
{
|
||||||
|
return m_nValue;
|
||||||
|
}
|
||||||
|
inline const char *ConVar::GetString( void )
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void ConVar::SetValue( const char *szValue )
|
||||||
|
{
|
||||||
|
if (!szValue)
|
||||||
|
return;
|
||||||
|
m_szValue = szValue;
|
||||||
|
m_fValue = V_atof(szValue);
|
||||||
|
m_nValue = V_atoi(szValue);
|
||||||
|
}
|
||||||
|
inline void ConVar::SetValue( float fValue )
|
||||||
|
{
|
||||||
|
m_fValue = fValue;
|
||||||
|
m_nValue = fValue;
|
||||||
|
m_szValue = CUtlString("%f\n",fValue);
|
||||||
|
}
|
||||||
|
inline void ConVar::SetValue( int iValue )
|
||||||
|
{
|
||||||
|
m_fValue = iValue;
|
||||||
|
m_nValue = iValue;
|
||||||
|
m_szValue = CUtlString("%i\n",iValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class ConCommand
|
class ConCommand
|
||||||
{
|
{
|
||||||
@@ -109,11 +194,28 @@ private:
|
|||||||
int m_flags;
|
int m_flags;
|
||||||
};
|
};
|
||||||
|
|
||||||
#undef V_printf
|
inline ConCommand::ConCommand(const char *pName, ConCommandFn callback,
|
||||||
#define V_printf(...) Msg(CUtlString(__VA_ARGS__).GetString())
|
const char *pHelpString, int flags)
|
||||||
|
{
|
||||||
|
m_szName = pName;
|
||||||
|
m_callback = callback;
|
||||||
|
m_flags = flags;
|
||||||
|
Console()->RegisterCommand(this);
|
||||||
|
};
|
||||||
|
|
||||||
void Msg( const char* message );
|
inline const char *ConCommand::GetHelpText( void )
|
||||||
void Warning( const char* message );
|
{
|
||||||
void Error( const char* message );
|
return m_szHelpString;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline const char *ConCommand::GetName( void )
|
||||||
|
{
|
||||||
|
return m_szName;
|
||||||
|
}
|
||||||
|
|
||||||
|
inline ConCommandFn ConCommand::GetCallback( void )
|
||||||
|
{
|
||||||
|
return m_callback;
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
44
public/ihumandevice.h
Normal file
44
public/ihumandevice.h
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
#ifndef KEYBINDINGS_H
|
||||||
|
#define KEYBINDINGS_H
|
||||||
|
|
||||||
|
#include "tier0/platform.h"
|
||||||
|
#include "materialsystem/humandevice_enums.h"
|
||||||
|
|
||||||
|
|
||||||
|
abstract_class IHumanDeviceInput
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual EInputType GetInputType() = 0;
|
||||||
|
|
||||||
|
virtual void OnGameButton( EInputDeviceType eDevice, EInputButton eScancode, bool bIsPressed ) = 0;
|
||||||
|
virtual void OnGameAxis( EInputDeviceType eDevice, EInputAxis eAxis, float fValue) = 0;
|
||||||
|
virtual void OnGameAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fValue ) = 0;
|
||||||
|
|
||||||
|
virtual void OnButton( EInputDeviceType eDevice, EInputButton eScancode, bool bIsPressed ) = 0;
|
||||||
|
virtual void OnAxis( EInputDeviceType eDevice, EInputAxis eAxis, float fValue) = 0;
|
||||||
|
virtual void OnAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fValue ) = 0;
|
||||||
|
|
||||||
|
virtual void OnTextWriteUTF8( uint32_t uCode ) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
abstract_class IHumanDeviceManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void Frame() = 0;
|
||||||
|
|
||||||
|
virtual void SetDefaultInput( IHumanDeviceInput *pInput ) = 0;
|
||||||
|
virtual void PushInput( IHumanDeviceInput *pInput ) = 0;
|
||||||
|
virtual void PopInput() = 0;
|
||||||
|
virtual IHumanDeviceInput *GetCurrentInput() = 0;
|
||||||
|
|
||||||
|
virtual void SetButtonPressed( EInputButton eButton ) = 0;
|
||||||
|
virtual void SetButtonUnpressed( EInputButton eButton ) = 0;
|
||||||
|
|
||||||
|
virtual void WriteUTF8( uint32_t uCode ) = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
#define HUMAN_DEVICE_MANAGER_INTERFACE_VERSION "HumanDeviceMgr001"
|
||||||
|
|
||||||
|
extern IHumanDeviceManager *g_pHumanDeviceManager;
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -1,17 +1,16 @@
|
|||||||
#ifndef KEYBINDINGS_H
|
#ifndef HD_ENUMS_H
|
||||||
#define KEYBINDINGS_H
|
#define HD_ENUMS_H
|
||||||
|
|
||||||
#include "tier0/platform.h"
|
enum EInputButton
|
||||||
|
|
||||||
enum EInputButton
|
|
||||||
{
|
{
|
||||||
k_EInputButton_NONE = 0,
|
k_EInputButton_NONE = 0,
|
||||||
|
|
||||||
k_EInputButton_MOUSE_BUTTON_0,
|
k_EInputButton_Mouse_Left,
|
||||||
k_EInputButton_MOUSE_BUTTON_1,
|
k_EInputButton_Mouse_Right,
|
||||||
k_EInputButton_MOUSE_BUTTON_2,
|
k_EInputButton_Mouse_3,
|
||||||
k_EInputButton_MOUSE_BUTTON_3,
|
k_EInputButton_Mouse_4,
|
||||||
k_EInputButton_MOUSE_BUTTON_4,
|
k_EInputButton_Mouse_ScrollUp,
|
||||||
|
k_EInputButton_Mouse_ScrollDown,
|
||||||
|
|
||||||
k_EInputButton_ESCAPE,
|
k_EInputButton_ESCAPE,
|
||||||
k_EInputButton_TAB,
|
k_EInputButton_TAB,
|
||||||
@@ -86,6 +85,12 @@ enum EInputButton
|
|||||||
k_EInputButton_Count = k_EInputButton_MAX - 1,
|
k_EInputButton_Count = k_EInputButton_MAX - 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum EInputAxis
|
||||||
|
{
|
||||||
|
k_EInputAxis_MouseX,
|
||||||
|
k_EInputAxis_MouseY,
|
||||||
|
};
|
||||||
|
|
||||||
enum EInputType
|
enum EInputType
|
||||||
{
|
{
|
||||||
k_EInput_Game,
|
k_EInput_Game,
|
||||||
@@ -93,18 +98,11 @@ enum EInputType
|
|||||||
k_EInput_InputBox,
|
k_EInput_InputBox,
|
||||||
};
|
};
|
||||||
|
|
||||||
abstract_class IHumanDeviceManager
|
enum EInputDeviceType
|
||||||
{
|
{
|
||||||
public:
|
k_EInputDevice_Keyboard,
|
||||||
virtual void SetDefaultInputType( EInputType eType ) = 0;
|
k_EInputDevice_Mouse,
|
||||||
virtual void PushInputType( EInputType eType ) = 0;
|
k_EInputDevice_Gamepad,
|
||||||
virtual void PopInputType() = 0;
|
|
||||||
virtual void SetButtonPressed( EInputButton eButton ) = 0;
|
|
||||||
virtual void SetButtonUnpressed( EInputButton eButton ) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define HUMAN_DEVICE_MANAGER_INTERFACE_VERSION "HumanDeviceMgr001"
|
|
||||||
|
|
||||||
extern IHumanDeviceManager *g_pHumanDeviceManager;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -3,6 +3,10 @@
|
|||||||
|
|
||||||
#include "tier0/platform.h"
|
#include "tier0/platform.h"
|
||||||
#include "tier2/iappsystem.h"
|
#include "tier2/iappsystem.h"
|
||||||
|
#include "materialsystem/humandevice_enums.h"
|
||||||
|
|
||||||
|
typedef void ( *KeyCallbackFn )( EInputDeviceType eDevice, EInputButton eButton, bool bIsPressed );
|
||||||
|
typedef void ( *AxisCallbackFn )( EInputDeviceType eDevice, EInputAxis eAxis, float fd );
|
||||||
|
|
||||||
class IImage;
|
class IImage;
|
||||||
abstract_class IGameWindow: public IAppSystem
|
abstract_class IGameWindow: public IAppSystem
|
||||||
@@ -17,6 +21,9 @@ public:
|
|||||||
virtual void SetOutputImage( IImage *pImage ) = 0;
|
virtual void SetOutputImage( IImage *pImage ) = 0;
|
||||||
virtual IImage *GetOutputImage() = 0;
|
virtual IImage *GetOutputImage() = 0;
|
||||||
|
|
||||||
|
virtual void SetKeyCallback( KeyCallbackFn fn ) = 0;
|
||||||
|
virtual void SetAxisCallback( AxisCallbackFn fn ) = 0;
|
||||||
|
|
||||||
virtual void *CreateVulkanSurface( void *pInstance ) = 0;
|
virtual void *CreateVulkanSurface( void *pInstance ) = 0;
|
||||||
virtual void DestroyVulkanSurface( void *pInstance ) = 0;
|
virtual void DestroyVulkanSurface( void *pInstance ) = 0;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user