some stuff
This commit is contained in:
@@ -23,6 +23,7 @@ DECLARE_BUILD_STAGE(engine)
|
||||
"localnetwork.cpp",
|
||||
"socketnetwork.cpp",
|
||||
"steamnetwork.cpp",
|
||||
"humandevice.cpp",
|
||||
|
||||
"sv_dll.cpp",
|
||||
"cl_dll.cpp",
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "tier0/platform.h"
|
||||
#include "icvar.h"
|
||||
#include "tier2/ifilesystem.h"
|
||||
#include "ihumandevice.h"
|
||||
|
||||
void CClientGameDLL::Init()
|
||||
{
|
||||
@@ -18,8 +19,9 @@ void CClientGameDLL::Init()
|
||||
CreateInterfaceFn pfnServerFactory = Sys_GetFactory(pLib);
|
||||
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(RENDER_CONTEXT_INTERFACE_VERSION, m_pRenderContext);
|
||||
pEngineBridge->ConnectInterface(HUMAN_DEVICE_MANAGER_INTERFACE_VERSION, g_pHumanDeviceManager);
|
||||
pEngineBridge->ConnectInterface("MainWindow", m_pGameWindow);
|
||||
pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts);
|
||||
pEngineBridge->Init();
|
||||
|
||||
119
engine/cvar.cpp
119
engine/cvar.cpp
@@ -20,7 +20,7 @@ struct ConsoleMessage_t
|
||||
|
||||
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 InsertCommand( const char *psz ) override;
|
||||
|
||||
CUtlVector<ConVar*> m_convars;
|
||||
CUtlVector<ConCommand*> m_commands;
|
||||
};
|
||||
|
||||
IConsole *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()
|
||||
{
|
||||
@@ -207,115 +212,6 @@ void CConsole::InsertCommand( const char *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);
|
||||
filesystem->Read(f, b, b.GetSize());
|
||||
b[b.GetSize()-1] = 0;
|
||||
|
||||
Console()->AddCommand(b);
|
||||
Console()->AddCommand(";");
|
||||
Console()->Execute();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "cl_dll.h"
|
||||
#include "inetworkserver.h"
|
||||
#include "inetworkclient.h"
|
||||
#include "ihumandevice.h"
|
||||
|
||||
#ifdef STEAM
|
||||
#include "steam/steam_api.h"
|
||||
@@ -22,6 +23,14 @@ IGameWindowManager *g_pWindowManager;
|
||||
CServerGameDLL *g_pServerGame;
|
||||
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 )
|
||||
{
|
||||
V_printf("STEAM: %s\n", pszMsg);
|
||||
@@ -67,6 +76,7 @@ extern "C" void FunnyMain( int argc, char **argv )
|
||||
|
||||
pWindow = g_pWindowManager->CreateWindow();
|
||||
pWindow->Init();
|
||||
pWindow->SetKeyCallback(CallKeyEvent);
|
||||
|
||||
g_pRenderContext = (IRenderContext*)pRenderSystemFactory(RENDER_CONTEXT_INTERFACE_VERSION, NULL);
|
||||
g_pRenderContext->SetMainWindowManager(g_pWindowManager);
|
||||
@@ -98,6 +108,7 @@ extern "C" void FunnyMain( int argc, char **argv )
|
||||
double fDelta = fCurrent-fPrevious;
|
||||
fPrevious = fCurrent;
|
||||
|
||||
g_pHumanDeviceManager->Frame();
|
||||
g_pServerGame->m_pBridge->Frame(fDelta);
|
||||
|
||||
if (!stConstants.m_bIsDedicated)
|
||||
|
||||
@@ -1,24 +1,93 @@
|
||||
#include "humandevice.h"
|
||||
#include "ihumandevice.h"
|
||||
#include "tier1/interface.h"
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
class CHumanDeviceManager: public IHumanDeviceManager
|
||||
{
|
||||
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 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 )
|
||||
{
|
||||
m_abIsButtonPressed[eButton] = true;
|
||||
IHumanDeviceInput *pInput = GetCurrentInput();
|
||||
if (pInput)
|
||||
pInput->OnButton(k_EInputDevice_Keyboard, eButton, true);
|
||||
|
||||
}
|
||||
|
||||
void CHumanDeviceManager::SetButtonUnpressed( EInputButton eButton )
|
||||
{
|
||||
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)
|
||||
|
||||
@@ -1,110 +0,0 @@
|
||||
#ifndef KEYBINDINGS_H
|
||||
#define KEYBINDINGS_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
enum EInputButton
|
||||
{
|
||||
k_EInputButton_NONE = 0,
|
||||
|
||||
k_EInputButton_MOUSE_BUTTON_0,
|
||||
k_EInputButton_MOUSE_BUTTON_1,
|
||||
k_EInputButton_MOUSE_BUTTON_2,
|
||||
k_EInputButton_MOUSE_BUTTON_3,
|
||||
k_EInputButton_MOUSE_BUTTON_4,
|
||||
|
||||
k_EInputButton_ESCAPE,
|
||||
k_EInputButton_TAB,
|
||||
k_EInputButton_TILDE,
|
||||
k_EInputButton_CAPSLOCK,
|
||||
k_EInputButton_CONTROL,
|
||||
k_EInputButton_SHIFT,
|
||||
k_EInputButton_WIN,
|
||||
k_EInputButton_ALT,
|
||||
k_EInputButton_SPACE,
|
||||
|
||||
k_EInputButton_BACKSPACE,
|
||||
k_EInputButton_LBRACKET,
|
||||
k_EInputButton_RBRACKET,
|
||||
k_EInputButton_BACKSLASH,
|
||||
k_EInputButton_SEMICOLON,
|
||||
k_EInputButton_APOSTROPHE,
|
||||
k_EInputButton_SLASH,
|
||||
k_EInputButton_ENTER,
|
||||
|
||||
k_EInputButton_F1,
|
||||
k_EInputButton_F2,
|
||||
k_EInputButton_F3,
|
||||
k_EInputButton_F4,
|
||||
k_EInputButton_F5,
|
||||
k_EInputButton_F6,
|
||||
k_EInputButton_F7,
|
||||
k_EInputButton_F8,
|
||||
k_EInputButton_F9,
|
||||
k_EInputButton_F10,
|
||||
k_EInputButton_F11,
|
||||
k_EInputButton_F12,
|
||||
|
||||
k_EInputButton_1,
|
||||
k_EInputButton_2,
|
||||
k_EInputButton_3,
|
||||
k_EInputButton_4,
|
||||
k_EInputButton_5,
|
||||
k_EInputButton_6,
|
||||
k_EInputButton_7,
|
||||
k_EInputButton_8,
|
||||
k_EInputButton_9,
|
||||
k_EInputButton_0,
|
||||
|
||||
k_EInputButton_A,
|
||||
k_EInputButton_B,
|
||||
k_EInputButton_C,
|
||||
k_EInputButton_D,
|
||||
k_EInputButton_E,
|
||||
k_EInputButton_F,
|
||||
k_EInputButton_G,
|
||||
k_EInputButton_H,
|
||||
k_EInputButton_I,
|
||||
k_EInputButton_J,
|
||||
k_EInputButton_K,
|
||||
k_EInputButton_L,
|
||||
k_EInputButton_M,
|
||||
k_EInputButton_N,
|
||||
k_EInputButton_O,
|
||||
k_EInputButton_P,
|
||||
k_EInputButton_Q,
|
||||
k_EInputButton_R,
|
||||
k_EInputButton_S,
|
||||
k_EInputButton_T,
|
||||
k_EInputButton_U,
|
||||
k_EInputButton_V,
|
||||
k_EInputButton_W,
|
||||
k_EInputButton_X,
|
||||
k_EInputButton_Y,
|
||||
k_EInputButton_Z,
|
||||
k_EInputButton_MAX,
|
||||
k_EInputButton_Count = k_EInputButton_MAX - 1,
|
||||
};
|
||||
|
||||
enum EInputType
|
||||
{
|
||||
k_EInput_Game,
|
||||
k_EInput_Menu,
|
||||
k_EInput_InputBox,
|
||||
};
|
||||
|
||||
abstract_class IHumanDeviceManager
|
||||
{
|
||||
public:
|
||||
virtual void SetDefaultInputType( EInputType eType ) = 0;
|
||||
virtual void PushInputType( EInputType eType ) = 0;
|
||||
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
|
||||
@@ -6,19 +6,11 @@
|
||||
|
||||
void CServerGameDLL::Init()
|
||||
{
|
||||
void *pLib;
|
||||
|
||||
#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);
|
||||
CreateInterfaceFn pfnServerFactory = Sys_GetFactory("server");
|
||||
IEngineBridge *pEngineBridge = (IEngineBridge*)pfnServerFactory(ENGINE_BRIDGE_INTERFACE_VERSION, NULL);
|
||||
pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
||||
pEngineBridge->ConnectInterface("EngineConstants", m_pEngineConsts);
|
||||
pEngineBridge->ConnectInterface(FILESYSTEM_INTERFACE_VERSION, filesystem);
|
||||
pEngineBridge->Init();
|
||||
m_pBridge = pEngineBridge;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user