added keybinds
This commit is contained in:
@@ -18,6 +18,7 @@ DECLARE_BUILD_STAGE(Client)
|
||||
"../shared/game.cpp",
|
||||
|
||||
"game.cpp",
|
||||
"userinput.cpp",
|
||||
|
||||
"baseentity.cpp",
|
||||
"basemodelentity.cpp",
|
||||
|
||||
@@ -6,10 +6,8 @@
|
||||
#include "entitysystem.h"
|
||||
#include "baseentity.h"
|
||||
#include "game.h"
|
||||
#include "cglm/mat4.h"
|
||||
#include "cglm/cglm.h"
|
||||
#include "inetworkclient.h"
|
||||
#include "netprotocol.h"
|
||||
#include "userinput.h"
|
||||
#ifdef STEAM
|
||||
#include "steam/isteamgameserver.h"
|
||||
#include "steam/steam_gameserver.h"
|
||||
@@ -29,34 +27,6 @@ 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()
|
||||
{
|
||||
@@ -66,10 +36,12 @@ IEngineBridge *EngineBridge()
|
||||
|
||||
EXPOSE_INTERFACE_FN(EngineBridge, IEngineBridge, ENGINE_BRIDGE_INTERFACE_VERSION)
|
||||
|
||||
static CFunnyInput s_mainInput;
|
||||
|
||||
void CFunnyGameBridge::Init()
|
||||
{
|
||||
Console()->AddCommand("exec game/core/default.cfg\n");
|
||||
Console()->Execute();
|
||||
|
||||
g_pWorldRenderer->Init();
|
||||
#ifdef STEAM
|
||||
if (g_pEngineConstants->m_bIsSteam)
|
||||
@@ -95,7 +67,7 @@ void CFunnyGameBridge::Init()
|
||||
g_pPhysics = (IPhysics*)fnPhysicsFactory(PHYSICS_INTERFACE_VERSION, NULL);
|
||||
g_pPhysicsWorld = g_pPhysics->CreateWorld();
|
||||
|
||||
g_pHumanDeviceManager->SetDefaultInput(&s_mainInput);
|
||||
g_pHumanDeviceManager->SetDefaultInput(g_pMainInput);
|
||||
}
|
||||
|
||||
void CFunnyGameBridge::Tick( float fDelta )
|
||||
|
||||
@@ -13,19 +13,21 @@ void C_MOBAPlayer::Spawn()
|
||||
{
|
||||
BaseClass::Spawn();
|
||||
SetThink(Think);
|
||||
SetScale(1);
|
||||
};
|
||||
|
||||
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;
|
||||
vCameraPos.z += -20;
|
||||
g_pWorldRenderer->SetCameraPosition(vCameraPos);
|
||||
|
||||
}
|
||||
BaseClass::Think(fDelta);
|
||||
};
|
||||
|
||||
LINK_ENTITY_TO_CLASS(player, C_MOBAPlayer)
|
||||
@@ -39,16 +41,12 @@ IMPLEMENT_EMPTY_SEND_DT(C_MOBAPlayer)
|
||||
|
||||
|
||||
static void IN_ForwardDown( int c, char **v ) {
|
||||
V_printf("+forward\n");
|
||||
|
||||
}
|
||||
static ConCommand startforward("+forward", IN_ForwardDown);
|
||||
|
||||
static void IN_ForwardUp( int c, char **v ) {
|
||||
C_MOBAPlayer *pEntity = (C_MOBAPlayer*)UTIL_GetLocalPlayer();
|
||||
if (pEntity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
V_printf("-forward\n");
|
||||
}
|
||||
static ConCommand endforward("-forward", IN_ForwardUp);
|
||||
|
||||
168
game/client/userinput.cpp
Normal file
168
game/client/userinput.cpp
Normal file
@@ -0,0 +1,168 @@
|
||||
#include "userinput.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "game.h"
|
||||
|
||||
class CFunnyInput: public IHumanDeviceInput
|
||||
{
|
||||
public:
|
||||
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 {};
|
||||
|
||||
CUtlString m_aszBindings[k_EInputButton_Count];
|
||||
};
|
||||
|
||||
static CFunnyInput s_mainInput;
|
||||
IHumanDeviceInput *g_pMainInput = &s_mainInput;
|
||||
|
||||
void CFunnyInput::OnGameButton( EInputDeviceType eDevice, EInputButton eScancode, bool bIsPressed )
|
||||
{
|
||||
if (bIsPressed)
|
||||
{
|
||||
Console()->AddCommand(m_aszBindings[eScancode]);
|
||||
Console()->AddCommand("\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
auto binding = Console()->ParseCommandLine(m_aszBindings[eScancode]);
|
||||
if (binding.GetSize()==0)
|
||||
return;
|
||||
if (binding[0].GetSize() == 0)
|
||||
return;
|
||||
if (binding[0][0].GetString()[0] == '+')
|
||||
{
|
||||
CUtlString &command = binding[0][0];
|
||||
command.GetString()[0] = '-';
|
||||
}
|
||||
Console()->AddCommand(binding[0][0]);
|
||||
Console()->AddCommand("\n");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void CFunnyInput::OnGameAxis( EInputDeviceType eDevice, EInputAxis eAxis, float fValue)
|
||||
{
|
||||
|
||||
}
|
||||
void CFunnyInput::OnGameAxisDiff( EInputDeviceType eDevice, EInputAxis eAxis, float fValue )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct KeyName_t {
|
||||
const char *szName;
|
||||
EInputButton eKey;
|
||||
};
|
||||
|
||||
static KeyName_t s_keys[] = {
|
||||
|
||||
{"ESCAPE",k_EInputButton_ESCAPE},
|
||||
{"ESC",k_EInputButton_ESCAPE},
|
||||
{"TAB",k_EInputButton_TAB},
|
||||
{"ENTER",k_EInputButton_ENTER},
|
||||
{"CTRL",k_EInputButton_CONTROL},
|
||||
{"CONTROL",k_EInputButton_CONTROL},
|
||||
{"SHIFT",k_EInputButton_SHIFT},
|
||||
{"ALT",k_EInputButton_ALT},
|
||||
{"SPACE",k_EInputButton_SPACE},
|
||||
|
||||
{"BACKSPACE",k_EInputButton_BACKSPACE},
|
||||
{"[",k_EInputButton_LBRACKET},
|
||||
{"]",k_EInputButton_RBRACKET},
|
||||
{"{",k_EInputButton_LBRACKET},
|
||||
{"}",k_EInputButton_RBRACKET},
|
||||
{"\\",k_EInputButton_BACKSLASH},
|
||||
{";",k_EInputButton_SEMICOLON},
|
||||
{":",k_EInputButton_SEMICOLON},
|
||||
{"\'",k_EInputButton_APOSTROPHE},
|
||||
{"\"",k_EInputButton_APOSTROPHE},
|
||||
|
||||
{"F1",k_EInputButton_F1},
|
||||
{"F2",k_EInputButton_F2},
|
||||
{"F3",k_EInputButton_F3},
|
||||
{"F4",k_EInputButton_F4},
|
||||
{"F5",k_EInputButton_F5},
|
||||
{"F6",k_EInputButton_F6},
|
||||
{"F7",k_EInputButton_F7},
|
||||
{"F8",k_EInputButton_F8},
|
||||
{"F9",k_EInputButton_F9},
|
||||
{"F10",k_EInputButton_F10},
|
||||
{"F11",k_EInputButton_F11},
|
||||
{"F12",k_EInputButton_F12},
|
||||
|
||||
{"1",k_EInputButton_1},
|
||||
{"2",k_EInputButton_2},
|
||||
{"3",k_EInputButton_3},
|
||||
{"4",k_EInputButton_4},
|
||||
{"5",k_EInputButton_5},
|
||||
{"6",k_EInputButton_6},
|
||||
{"7",k_EInputButton_7},
|
||||
{"8",k_EInputButton_8},
|
||||
{"9",k_EInputButton_9},
|
||||
{"0",k_EInputButton_0},
|
||||
|
||||
{"A",k_EInputButton_A},
|
||||
{"B",k_EInputButton_B},
|
||||
{"C",k_EInputButton_C},
|
||||
{"D",k_EInputButton_D},
|
||||
{"E",k_EInputButton_E},
|
||||
{"F",k_EInputButton_F},
|
||||
{"G",k_EInputButton_G},
|
||||
{"H",k_EInputButton_H},
|
||||
{"I",k_EInputButton_I},
|
||||
{"J",k_EInputButton_J},
|
||||
{"K",k_EInputButton_K},
|
||||
{"L",k_EInputButton_L},
|
||||
{"M",k_EInputButton_M},
|
||||
{"N",k_EInputButton_N},
|
||||
{"O",k_EInputButton_O},
|
||||
{"P",k_EInputButton_P},
|
||||
{"Q",k_EInputButton_Q},
|
||||
{"R",k_EInputButton_R},
|
||||
{"S",k_EInputButton_S},
|
||||
{"T",k_EInputButton_T},
|
||||
{"U",k_EInputButton_U},
|
||||
{"V",k_EInputButton_V},
|
||||
{"W",k_EInputButton_W},
|
||||
{"X",k_EInputButton_X},
|
||||
{"Y",k_EInputButton_Y},
|
||||
{"Z",k_EInputButton_Z},
|
||||
};
|
||||
|
||||
static EInputButton GetStringAsKey( char *psz )
|
||||
{
|
||||
for (uint32_t i = 0; i<sizeof(s_keys)/sizeof(KeyName_t); i++)
|
||||
{
|
||||
if (!V_stricmp(s_keys[i].szName, psz))
|
||||
return s_keys[i].eKey;
|
||||
};
|
||||
return k_EInputButton_NONE;
|
||||
};
|
||||
|
||||
CON_COMMAND(bind, "Allows to run a command when button is pressed")
|
||||
{
|
||||
if (c == 1)
|
||||
return;
|
||||
if (c == 2)
|
||||
return;
|
||||
EInputButton key = GetStringAsKey(v[1]);
|
||||
if (key == k_EInputButton_NONE)
|
||||
return;
|
||||
|
||||
s_mainInput.m_aszBindings[key] = 0;
|
||||
for ( int i = 2; i<c; i++ )
|
||||
{
|
||||
s_mainInput.m_aszBindings[key].AppendTail(v[i]);
|
||||
s_mainInput.m_aszBindings[key].AppendTail(" ");
|
||||
}
|
||||
}
|
||||
8
game/client/userinput.h
Normal file
8
game/client/userinput.h
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
#ifndef USER_INPUT_H
|
||||
#define USER_INPUT_H
|
||||
#include "ihumandevice.h"
|
||||
|
||||
extern IHumanDeviceInput *g_pMainInput;
|
||||
|
||||
#endif
|
||||
@@ -103,6 +103,7 @@ void CFunnyMeshInstance::Frame()
|
||||
v[2] = m_vScale.z;
|
||||
glm_scale_make(m, v);
|
||||
glm_mat4_mul(m_data.m_matTranslation, m, m_data.m_matTranslation);
|
||||
glm_mat4_inv(m_data.m_matTranslation, m_data.m_matTranslation);
|
||||
m_data.m_uAlbedo = 1;
|
||||
}
|
||||
|
||||
@@ -217,8 +218,12 @@ void CFunnyWorldRenderer::Frame( float fDelta )
|
||||
uint32_t uWidth = g_pMainWindow->GetRenderWidth();
|
||||
uint32_t uHeight = g_pMainWindow->GetRenderHeight();
|
||||
mat4 matCamera;
|
||||
mat4 matCamera2;
|
||||
glm_mat4_identity(matCamera);
|
||||
glm_mat4_identity(matCamera2);
|
||||
glm_translate(matCamera2, m_vPos);
|
||||
glm_perspective(glm_rad(60), uWidth/(float)uHeight, 0.01, 10000, matCamera);
|
||||
glm_translate(matCamera, m_vPos);
|
||||
glm_mul(matCamera, matCamera2, matCamera);
|
||||
/*
|
||||
V_printf("%f %f %f %f\n", matCamera[0][0], matCamera[0][1], matCamera[0][2], matCamera[0][3]);
|
||||
V_printf("%f %f %f %f\n", matCamera[1][0], matCamera[1][1], matCamera[1][2], matCamera[1][3]);
|
||||
|
||||
Reference in New Issue
Block a user