added main menus, improved shading
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "tier1/commandline.h"
|
||||
|
||||
CUtlVector<CUtlString> engine_CompiledFiles = {
|
||||
"engine/interface.cpp",
|
||||
"engine/console.cpp",
|
||||
"engine/filesystem.cpp",
|
||||
"engine/server.cpp",
|
||||
|
||||
@@ -47,7 +47,12 @@ void CBrushEntity::Think( float fDelta )
|
||||
|
||||
};
|
||||
|
||||
void CBrushEntity::Sync( void *pData, uint32_t nDataSize )
|
||||
void CBrushEntity::SendToServer()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
void CBrushEntity::RecieveFromServer( void *pData, uint32_t nDataSize )
|
||||
{
|
||||
|
||||
};
|
||||
@@ -149,6 +154,9 @@ void CBrushRendering::Init()
|
||||
|
||||
void CBrushRendering::Frame( float fDelta )
|
||||
{
|
||||
g_BrushPipeline->BindData(0, IRenderer::GetCameraMatrix(), 0);
|
||||
g_BrushPipeline->PushBindings();
|
||||
|
||||
IRenderer::ResetState();
|
||||
IRenderer::SetDepthMode(DEPTH_MODE_LESS);
|
||||
IRenderer::BindPipeline(g_BrushPipeline);
|
||||
@@ -160,8 +168,6 @@ void CBrushRendering::Frame( float fDelta )
|
||||
} constants;
|
||||
glm_mat4_identity(constants.i);
|
||||
IRenderer::SetConstants(sizeof(constants), &constants);
|
||||
IRenderer::BindData(0, IRenderer::GetCameraMatrix(), 0);
|
||||
IRenderer::PushBindings();
|
||||
for (auto &v: g_BrushVertices)
|
||||
{
|
||||
IRenderer::Draw(v, 0);
|
||||
|
||||
@@ -1,11 +1,65 @@
|
||||
#include "console.h"
|
||||
#include "fgui/rect.h"
|
||||
#include "fgui/widget.h"
|
||||
#include "fgui/label.h"
|
||||
#include "filesystem.h"
|
||||
#include "rendering.h"
|
||||
#include "tier1/utlstring.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "stdarg.h"
|
||||
|
||||
CUtlVector<ConVar*> g_convars;
|
||||
CUtlVector<ConCommand*> g_commands;
|
||||
|
||||
enum EConsoleMessageType
|
||||
{
|
||||
CONSOLE_MESSAGE_TYPE_MESSAGE,
|
||||
CONSOLE_MESSAGE_TYPE_WARNING,
|
||||
CONSOLE_MESSAGE_TYPE_ERROR,
|
||||
};
|
||||
|
||||
struct ConsoleMessage_t
|
||||
{
|
||||
EConsoleMessageType type;
|
||||
CUtlString szMessage;
|
||||
};
|
||||
|
||||
uint32_t g_nNumConsoleMessages = 0;
|
||||
ConsoleMessage_t g_consoleLog[1024];
|
||||
|
||||
void Msg( const char* message )
|
||||
{
|
||||
printf(message);
|
||||
g_consoleLog[g_nNumConsoleMessages] = {CONSOLE_MESSAGE_TYPE_MESSAGE, message};
|
||||
g_nNumConsoleMessages = (g_nNumConsoleMessages+1)%1024;
|
||||
|
||||
}
|
||||
|
||||
void Warning( const char* message )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Error( const char* message )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IConsole::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void IConsole::Frame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IConsole::Deinit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void IConsole::RegisterVar( ConVar *cvar )
|
||||
{
|
||||
g_convars.AppendTail(cvar);
|
||||
@@ -267,3 +321,63 @@ void IConsole_Exec( int argc, char **argv)
|
||||
}
|
||||
|
||||
ConCommand IConsole_ExecCmd("exec", IConsole_Exec);
|
||||
|
||||
class CConsoleGUI: public CFGUI_Widget
|
||||
{
|
||||
public:
|
||||
CConsoleGUI();
|
||||
virtual void Event( FGUI_Event_t event ) override;
|
||||
virtual void Draw() override;
|
||||
virtual void Frame() override;
|
||||
private:
|
||||
CFGUI_Rect *m_pBackground = 0;
|
||||
CFGUI_Label *m_pLog = 0;
|
||||
};
|
||||
|
||||
bool console_bDrawUI = false;
|
||||
|
||||
CConsoleGUI::CConsoleGUI()
|
||||
{
|
||||
m_pBackground = new CFGUI_Rect();
|
||||
m_pBackground->SetBoxColor(0.13, 0.13, 0.13, 1);
|
||||
m_pBackground->SetSize(200, 200);
|
||||
m_pBackground->SetParent(this);
|
||||
|
||||
m_pLog = new CFGUI_Label();
|
||||
m_pLog->SetFont("fonts/IBMPlexMono-Regular");
|
||||
m_pLog->SetLabel("CONSOLE");
|
||||
m_pLog->SetGlyphSize(24);
|
||||
m_pLog->SetParent(this);
|
||||
};
|
||||
|
||||
void CConsoleGUI::Event( FGUI_Event_t event )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CConsoleGUI::Draw()
|
||||
{
|
||||
SetPosition(20, 20);
|
||||
m_pBackground->SetSize(g_nWindowWidth-40, g_nWindowHeight-40);
|
||||
m_pBackground->SetSize(g_nWindowWidth-40, g_nWindowHeight-40);
|
||||
}
|
||||
|
||||
void CConsoleGUI::Frame()
|
||||
{
|
||||
SetVisibility(console_bDrawUI);
|
||||
}
|
||||
|
||||
void IConsoleUI::Init()
|
||||
{
|
||||
new CConsoleGUI;
|
||||
};
|
||||
|
||||
void IConsoleUI::SetVisibility( bool bIsVisisble )
|
||||
{
|
||||
console_bDrawUI = bIsVisisble;
|
||||
}
|
||||
|
||||
bool IConsoleUI::IsVisibile()
|
||||
{
|
||||
return console_bDrawUI;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
|
||||
#include "fgui/fgui.h"
|
||||
#include "input.h"
|
||||
#include "mainmenu.h"
|
||||
#include "networking.h"
|
||||
#include "tier0/network.h"
|
||||
#include "tier0/platform.h"
|
||||
@@ -99,7 +100,7 @@ void IEngine::Init()
|
||||
}
|
||||
if (!SteamAPI_Init())
|
||||
{
|
||||
V_printf("failed to init steam\n");
|
||||
Plat_FatalErrorFunc("failed to init steam\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -116,12 +117,13 @@ void IEngine::Init()
|
||||
// Init IO
|
||||
IVideo::Init();
|
||||
IInput::Init();
|
||||
IInput::SetMouseMode(MOUSE_MODE_GAME);
|
||||
IInput::SetInputMode(INPUT_MODE_MENU);
|
||||
IFGUI::Init();
|
||||
};
|
||||
|
||||
INetworking::Init();
|
||||
|
||||
|
||||
// load game
|
||||
IServer::LoadGame("funnygame");
|
||||
|
||||
@@ -132,6 +134,10 @@ void IEngine::Init()
|
||||
// execute default config
|
||||
IConsole::AddCommand("exec default.cfg;");
|
||||
IConsole::Execute();
|
||||
|
||||
MainMenu()->Init();
|
||||
|
||||
IConsoleUI::Init();
|
||||
|
||||
};
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -146,6 +152,7 @@ void IEngine::Frame(float fDelta)
|
||||
INetworking::Frame();
|
||||
if (!ICommandLine::CheckParam("-dedicated"))
|
||||
{
|
||||
MainMenu()->Frame();
|
||||
IFGUI::Frame();
|
||||
IVideo::Frame(fDelta);
|
||||
}
|
||||
@@ -156,6 +163,7 @@ void IEngine::Frame(float fDelta)
|
||||
//-----------------------------------------------------------------------------
|
||||
void IEngine::Shutdown()
|
||||
{
|
||||
MainMenu()->Deinit();
|
||||
INetworking::Deinit();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "gamemode.h"
|
||||
#include "engine.h"
|
||||
#include "interface.h"
|
||||
#include "playerstart.h"
|
||||
#include "networking.h"
|
||||
|
||||
@@ -53,10 +54,29 @@ void CGameMode::RoundEnd( void )
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class CGameModeManager: public IGameModeManager
|
||||
{
|
||||
public:
|
||||
virtual void Init( void ) override;
|
||||
virtual void Frame( void ) override;
|
||||
virtual void Deinit( void ) override;
|
||||
|
||||
virtual void StartGameMode( const char *szName ) override;
|
||||
virtual const char *GetCurrentGameMode( void ) override;
|
||||
virtual CGameMode *GetCurrentGameModeClass( void ) override;
|
||||
virtual void RestartCurrentGameMode( void ) override;
|
||||
};
|
||||
|
||||
DECLARE_INTERFACE(GameModeManager, CGameModeManager);
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void IGameModeManager::Init( void )
|
||||
void CGameModeManager::Init( void )
|
||||
{
|
||||
|
||||
}
|
||||
@@ -64,14 +84,22 @@ void IGameModeManager::Init( void )
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void IGameModeManager::Frame( void )
|
||||
void CGameModeManager::Frame( void )
|
||||
{
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGameModeManager::Deinit( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sets gamemode
|
||||
//-----------------------------------------------------------------------------
|
||||
void IGameModeManager::StartGameMode( const char *szName )
|
||||
void CGameModeManager::StartGameMode( const char *szName )
|
||||
{
|
||||
if (pCurrentMode)
|
||||
{
|
||||
@@ -93,7 +121,15 @@ void IGameModeManager::StartGameMode( const char *szName )
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CGameMode *IGameModeManager::GetCurrentGameModeClass( void )
|
||||
const char *CGameModeManager::GetCurrentGameMode( void )
|
||||
{
|
||||
return szCurrentModeName;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
CGameMode *CGameModeManager::GetCurrentGameModeClass( void )
|
||||
{
|
||||
return pCurrentMode;
|
||||
}
|
||||
@@ -101,7 +137,7 @@ CGameMode *IGameModeManager::GetCurrentGameModeClass( void )
|
||||
//-----------------------------------------------------------------------------
|
||||
// Restarts the gamemode
|
||||
//-----------------------------------------------------------------------------
|
||||
void IGameModeManager::RestartCurrentGameMode( void )
|
||||
void CGameModeManager::RestartCurrentGameMode( void )
|
||||
{
|
||||
if (!pCurrentMode)
|
||||
return;
|
||||
|
||||
121
engine/input.cpp
121
engine/input.cpp
@@ -1,5 +1,6 @@
|
||||
#include "input.h"
|
||||
#include "console.h"
|
||||
#include "mainmenu.h"
|
||||
#include "tier0/lib.h"
|
||||
#include "tier1/commandline.h"
|
||||
#include "math3d.h"
|
||||
@@ -109,53 +110,124 @@ EInputKey IInput_StringToKey( char *psz )
|
||||
//-----------------------------------------------------------------------------
|
||||
void IInput::Init( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CUtlVector<EInputMode> g_inputModeStack = {INPUT_MODE_GAME, INPUT_MODE_MENU};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Key event may have different different effects based on current input mode.
|
||||
//
|
||||
// GAME:
|
||||
// Generates command call when pressed the key. eg +forward; -left;
|
||||
// Just to be sure we put ; in the end of the command.
|
||||
// When user releases the key command event is not generated. But if the first
|
||||
// command contains + as first character ( in case of example +forward ), then
|
||||
// it fires -forward
|
||||
//
|
||||
// MENU:
|
||||
// Sends all event to FGUI. KEY_ESCAPE key makes leave the menu and get back to
|
||||
// the game.
|
||||
//
|
||||
// CONSOLE:
|
||||
// Works as permanent input field.
|
||||
//
|
||||
// INPUT FIELD:
|
||||
// Doesn't recieve any events except for KEY_ESCAPE and KEY_ENTER
|
||||
//-----------------------------------------------------------------------------
|
||||
void IInput::KeyEvent( EInputKey key, EKeyEventType event )
|
||||
{
|
||||
if (event == KEY_EVENT_TYPE_DOWN) {
|
||||
IConsole::AddCommand(g_bindings[key]);
|
||||
IConsole::AddCommand(";");
|
||||
}
|
||||
if (event == KEY_EVENT_TYPE_UP)
|
||||
if (event == KEY_EVENT_TYPE_DOWN && key == KEY_ESCAPE)
|
||||
{
|
||||
auto binding = IConsole::ParseCommandLine(g_bindings[key]);
|
||||
if (binding.GetSize()==0)
|
||||
return;
|
||||
if (binding[0].GetSize() == 0)
|
||||
return;
|
||||
if (binding[0][0].GetString()[0] == '+')
|
||||
if (g_inputModeStack.GetSize() == 1)
|
||||
{
|
||||
CUtlString command = binding[0][0];
|
||||
command.GetString()[0] = '-';
|
||||
IConsole::AddCommand(command);
|
||||
g_inputModeStack.AppendTail(INPUT_MODE_MENU);
|
||||
IInput::SetInputMode(INPUT_MODE_MENU);
|
||||
MainMenu()->SetVisibility(true);
|
||||
return;
|
||||
}
|
||||
if (IConsoleUI::IsVisibile())
|
||||
IConsoleUI::SetVisibility(false);
|
||||
IInput::SetInputMode(g_inputModeStack[g_inputModeStack.GetSize()-2]);
|
||||
g_inputModeStack.RemoveTail();
|
||||
|
||||
if (g_inputModeStack[g_inputModeStack.GetSize()-1] != INPUT_MODE_MENU)
|
||||
{
|
||||
V_printf("no menu\n");
|
||||
MainMenu()->SetVisibility(false);
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
if (event == KEY_EVENT_TYPE_DOWN && key == KEY_TILDE)
|
||||
{
|
||||
if (IConsoleUI::IsVisibile())
|
||||
{
|
||||
IInput::SetInputMode(g_inputModeStack[g_inputModeStack.GetSize()-2]);
|
||||
g_inputModeStack.RemoveTail();
|
||||
IConsoleUI::SetVisibility(false);
|
||||
} else
|
||||
{
|
||||
g_inputModeStack.AppendTail(INPUT_MODE_CONSOLE);
|
||||
IInput::SetInputMode(INPUT_MODE_CONSOLE);
|
||||
IConsoleUI::SetVisibility(true);
|
||||
}
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
if (event == KEY_EVENT_TYPE_DOWN && key == KEY_F11)
|
||||
{
|
||||
IConsole::AddCommand("exit;");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (g_inputModeStack[g_inputModeStack.GetSize()-1] == INPUT_MODE_GAME)
|
||||
{
|
||||
if (event == KEY_EVENT_TYPE_DOWN) {
|
||||
IConsole::AddCommand(g_bindings[key]);
|
||||
IConsole::AddCommand(";");
|
||||
}
|
||||
if (event == KEY_EVENT_TYPE_UP)
|
||||
{
|
||||
auto binding = IConsole::ParseCommandLine(g_bindings[key]);
|
||||
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] = '-';
|
||||
IConsole::AddCommand(command);
|
||||
IConsole::AddCommand(";");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (g_inputModeStack[g_inputModeStack.GetSize()-1] == INPUT_MODE_MENU)
|
||||
{
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Axis events for the input devices such as mouse and controller.
|
||||
// Game needs to explicitly support all of the devices.
|
||||
//-----------------------------------------------------------------------------
|
||||
void IInput::AxisEvent( EInputAxis axis, float fValue )
|
||||
{
|
||||
if (axis == AXIS_MOUSE_X || axis == AXIS_MOUSE_Y)
|
||||
if (g_inputModeStack[g_inputModeStack.GetSize()-1] == INPUT_MODE_GAME)
|
||||
{
|
||||
g_bController = false;
|
||||
g_fAxisValues[axis] += fValue*3.09;
|
||||
}
|
||||
if (axis == AXIS_CONTROLLER_PITCH || axis == AXIS_CONTROLLER_YAW)
|
||||
{
|
||||
g_bController = true;
|
||||
g_fAxisModifiers[axis] = fValue*3.09;
|
||||
if (axis == AXIS_MOUSE_X || axis == AXIS_MOUSE_Y)
|
||||
{
|
||||
g_bController = false;
|
||||
g_fAxisValues[axis] += fValue*3.09;
|
||||
}
|
||||
if (axis == AXIS_CONTROLLER_PITCH || axis == AXIS_CONTROLLER_YAW)
|
||||
{
|
||||
g_bController = true;
|
||||
g_fAxisModifiers[axis] = fValue*3.09;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +245,6 @@ void IInput::Frame( void )
|
||||
//-----------------------------------------------------------------------------
|
||||
void IInput::Deinit( void )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
7
engine/interface.cpp
Normal file
7
engine/interface.cpp
Normal file
@@ -0,0 +1,7 @@
|
||||
#include "interface.h"
|
||||
#include "tier0/lib.h"
|
||||
|
||||
|
||||
CInterfaceRegistry::CInterfaceRegistry( const char *szName, InterfaceRegistryFn pfn )
|
||||
{
|
||||
};
|
||||
@@ -115,11 +115,12 @@ void CMeshRendering::Init()
|
||||
|
||||
void CMeshRendering::Frame( float fDelta )
|
||||
{
|
||||
g_MeshPipeline->BindData(0, IRenderer::GetCameraMatrix(), 0);
|
||||
g_MeshPipeline->PushBindings();
|
||||
|
||||
IRenderer::ResetState();
|
||||
IRenderer::SetDepthMode(DEPTH_MODE_LESS);
|
||||
IRenderer::BindPipeline(g_MeshPipeline);
|
||||
IRenderer::BindData(0, IRenderer::GetCameraMatrix(), 0);
|
||||
IRenderer::PushBindings();
|
||||
for (auto &v: g_meshes)
|
||||
{
|
||||
CMeshInstance *pMesh = (CMeshInstance*)v;
|
||||
|
||||
@@ -51,14 +51,16 @@ MTL::PixelFormat g_swapchainFormat;
|
||||
// Other platforms
|
||||
#endif
|
||||
|
||||
void IInput::SetMouseMode( EMouseMode mode )
|
||||
void IInput::SetInputMode( EInputMode mode )
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case MOUSE_MODE_GAME:
|
||||
case INPUT_MODE_GAME:
|
||||
g_currentInputMode = INPUT_MODE_GAME;
|
||||
SDL_SetWindowRelativeMouseMode(g_window, true);
|
||||
return;
|
||||
default:
|
||||
g_currentInputMode = INPUT_MODE_MENU;
|
||||
SDL_SetWindowRelativeMouseMode(g_window, false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ void INetworking::ProcessPacket( void *pData, uint32_t nSize, IIClient *pClient
|
||||
if (IsServer())
|
||||
{
|
||||
if (pClient->pBasePlayer)
|
||||
pClient->pBasePlayer->Sync(pData, nSize);
|
||||
pClient->pBasePlayer->RecieveFromServer(pData, nSize);
|
||||
}
|
||||
for (auto &client: g_clients)
|
||||
{
|
||||
@@ -251,7 +251,7 @@ void INetworking::ProcessPacket( void *pData, uint32_t nSize, IIClient *pClient
|
||||
{
|
||||
if (!client->pBasePlayer)
|
||||
return;
|
||||
client->pBasePlayer->Sync(pData, nSize);
|
||||
client->pBasePlayer->RecieveFromServer(pData, nSize);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -288,7 +288,7 @@ void INetworking::ProcessPacket( void *pData, uint32_t nSize, IIClient *pClient
|
||||
V_printf("PacketGameMode\n");
|
||||
if (nSize != sizeof(PacketGameMode_t))
|
||||
return;
|
||||
IGameModeManager::StartGameMode(pGameModePacket->szName);
|
||||
GameModeManager()->StartGameMode(pGameModePacket->szName);
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
@@ -383,7 +383,7 @@ void INetworking::ClientConnectedCallback( SteamNetConnectionStatusChangedCallba
|
||||
};
|
||||
|
||||
|
||||
IGameModeManager::RestartCurrentGameMode();
|
||||
GameModeManager()->RestartCurrentGameMode();
|
||||
break;
|
||||
case k_ESteamNetworkingConnectionState_ClosedByPeer:
|
||||
case k_ESteamNetworkingConnectionState_ProblemDetectedLocally:
|
||||
|
||||
@@ -60,7 +60,7 @@ void IServer::Think( float fDelta )
|
||||
for (auto &entity: g_entities)
|
||||
{
|
||||
entity->Think(fTickrate);
|
||||
entity->Sync(0, 0);
|
||||
entity->SendToServer();
|
||||
}
|
||||
px_frame(px, fTickrate);
|
||||
INetworking::Frame();
|
||||
|
||||
@@ -9,7 +9,8 @@ public:
|
||||
virtual void ReadParameter( const char *szName, const char *szValue ) override;
|
||||
virtual void Destroy( void ) override;
|
||||
virtual void Think( float fDelta ) override;
|
||||
virtual void Sync( void *pData, uint32_t nDataSize ) override;
|
||||
virtual void SendToServer() override;
|
||||
virtual void RecieveFromServer( void *pData, uint32_t nDataSize ) override;
|
||||
};
|
||||
|
||||
void CLight::Precache()
|
||||
@@ -36,7 +37,12 @@ void CLight::Think( float fDelta )
|
||||
{
|
||||
};
|
||||
|
||||
void CLight::Sync( void *pData, uint32_t nDataSize )
|
||||
void CLight::SendToServer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CLight::RecieveFromServer( void *pData, uint32_t nDataSize )
|
||||
{
|
||||
};
|
||||
|
||||
|
||||
@@ -61,7 +61,12 @@ void CPlayerStart::RoundStart(IIClient *pClient)
|
||||
pClient->pBasePlayer = pOwningPlayer;
|
||||
};
|
||||
|
||||
void CPlayerStart::Sync( void *pData, uint32_t nDataSize )
|
||||
void CPlayerStart::SendToServer()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
void CPlayerStart::RecieveFromServer( void *pData, uint32_t nDataSize )
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
@@ -9,7 +9,8 @@ public:
|
||||
virtual void ReadParameter( const char *szName, const char *szValue ) override;
|
||||
virtual void Destroy( void ) override;
|
||||
virtual void Think( float fDelta ) override;
|
||||
virtual void Sync( void *pData, uint32_t nDataSize ) override;
|
||||
virtual void SendToServer() override;
|
||||
virtual void RecieveFromServer( void *pData, uint32_t nDataSize ) override;
|
||||
};
|
||||
|
||||
void CWorldSpawn::Precache()
|
||||
@@ -37,7 +38,12 @@ void CWorldSpawn::Think( float fDelta )
|
||||
CBrushEntity::Think(fDelta);
|
||||
}
|
||||
|
||||
void CWorldSpawn::Sync( void *pData, uint32_t nDataSize )
|
||||
void CWorldSpawn::SendToServer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CWorldSpawn::RecieveFromServer( void *pData, uint32_t nDataSize )
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
@@ -28,6 +28,7 @@ class CVkImage: public IImage
|
||||
public:
|
||||
vk_image2d_t m_image = {};
|
||||
uint32_t m_usage;
|
||||
VkImageLayout m_currentLayout;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -42,6 +42,7 @@ IImage *g_meshDepth;
|
||||
IImage *g_meshDepthMSAA;
|
||||
IImage *g_meshColor;
|
||||
IImage *g_meshColorMSAA;
|
||||
|
||||
class CVkGraphicsPipeline: public IGraphicsPipeline
|
||||
{
|
||||
public:
|
||||
@@ -55,8 +56,76 @@ public:
|
||||
|
||||
CUtlVector<ShaderInput_t> m_inputs;
|
||||
|
||||
virtual void PushBindings() override;
|
||||
virtual void BindData( uint32_t binding, IBuffer *pBuffer, IImage* pImage) override;
|
||||
};
|
||||
|
||||
void CVkGraphicsPipeline::BindData( uint32_t binding, IBuffer *pBuffer, IImage* pImage)
|
||||
{
|
||||
CVkBuffer* pVkBuffer = (CVkBuffer*)pBuffer;
|
||||
VkDescriptorBufferInfo dbi;
|
||||
for (auto &input: m_inputs)
|
||||
{
|
||||
if (input.binding != binding)
|
||||
continue;
|
||||
|
||||
switch (input.type)
|
||||
{
|
||||
case SHADER_INPUT_TYPE_STORAGE_BUFFER:
|
||||
case SHADER_INPUT_TYPE_UNIFORM_BUFFER:
|
||||
if (!pBuffer)
|
||||
Plat_FatalErrorFunc("pBuffer is NULL\n");
|
||||
if (m_writes[binding].pBufferInfo)
|
||||
V_free((void*)m_writes[binding].pBufferInfo);
|
||||
dbi = {
|
||||
.buffer = pVkBuffer->m_buffer.m_buffer,
|
||||
.offset = 0,
|
||||
.range = pVkBuffer->m_buffer.m_nSize,
|
||||
};
|
||||
m_writes[binding].pBufferInfo = (VkDescriptorBufferInfo*)V_malloc(sizeof(VkDescriptorBufferInfo));
|
||||
V_memcpy((void*)m_writes[binding].pBufferInfo, &dbi, sizeof(VkDescriptorBufferInfo));
|
||||
break;
|
||||
case SHADER_INPUT_TYPE_IMAGE:
|
||||
break;
|
||||
case SHADER_INPUT_TYPE_TLAS:
|
||||
break;
|
||||
case SHADER_INPUT_TYPE_TEXTURES:
|
||||
break;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void CVkGraphicsPipeline::PushBindings()
|
||||
{
|
||||
CUtlVector<VkDescriptorImageInfo> textures;
|
||||
textures.Reserve(g_textures.GetSize());
|
||||
for (ITexture *t: g_textures)
|
||||
{
|
||||
CVkTexture *texture = (CVkTexture*)t;
|
||||
VkDescriptorImageInfo image = {};
|
||||
image.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
image.imageView = texture->image.m_imageView;
|
||||
image.sampler = g_invalidTextureSampler;
|
||||
textures.AppendTail(image);
|
||||
};
|
||||
|
||||
for ( int i = 0; i < m_inputs.GetSize(); i++ )
|
||||
{
|
||||
if (m_inputs[i].type == SHADER_INPUT_TYPE_TEXTURES)
|
||||
{
|
||||
m_writes[i].descriptorCount = textures.GetSize();
|
||||
m_writes[i].pImageInfo = textures.GetData();
|
||||
}
|
||||
}
|
||||
textures[0].sampler = g_invalidTextureSampler;
|
||||
|
||||
vkUpdateDescriptorSets(g_vkDevice, m_writes.GetSize(), m_writes.GetData(), 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
class CVkComputePipeline: public IComputePipeline
|
||||
{
|
||||
public:
|
||||
@@ -146,8 +215,8 @@ void IVulkan::Init()
|
||||
vkGetPhysicalDeviceProperties(g_vkPhysicalDevice, &properties);
|
||||
VkSamplerCreateInfo samplerInfo{};
|
||||
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
|
||||
samplerInfo.magFilter = VK_FILTER_NEAREST;
|
||||
samplerInfo.minFilter = VK_FILTER_NEAREST;
|
||||
samplerInfo.magFilter = VK_FILTER_LINEAR;
|
||||
samplerInfo.minFilter = VK_FILTER_LINEAR;
|
||||
samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
|
||||
@@ -216,7 +285,7 @@ void IVulkan::Frame()
|
||||
|
||||
for (auto &step: g_StepPrepass)
|
||||
step.pPipeline->Frame(0);
|
||||
IRenderer::Barrier(BARRIER_STAGE_TOP, BARRIER_STAGE_COLOR_OUTPUT, {}, {
|
||||
IRenderer::Barrier(BARRIER_STAGE_TOP, BARRIER_STAGE_COLOR_OUTPUT | BARRIER_STAGE_DEPTH_OUTPUT, {}, {
|
||||
{
|
||||
.in = BARRIER_MEMORY_PERMISSIONS_NONE,
|
||||
.out = BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE,
|
||||
@@ -250,17 +319,22 @@ void IVulkan::Frame()
|
||||
step.pPipeline->Frame(0);
|
||||
}
|
||||
IRenderer::End();
|
||||
IRenderer::Barrier(BARRIER_STAGE_COLOR_OUTPUT, BARRIER_STAGE_BOTTOM, {}, {
|
||||
{
|
||||
.in = BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE,
|
||||
.out = BARRIER_MEMORY_PERMISSIONS_COPY_READ,
|
||||
.pImage = g_meshColor,
|
||||
},
|
||||
IRenderer::Barrier(BARRIER_STAGE_DEPTH_OUTPUT, BARRIER_STAGE_BOTTOM, {}, {
|
||||
{
|
||||
.in = BARRIER_MEMORY_PERMISSIONS_DEPTH_WRITE,
|
||||
.out = BARRIER_MEMORY_PERMISSIONS_NONE,
|
||||
.pImage = g_meshDepth,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
IRenderer::Barrier(BARRIER_STAGE_COLOR_OUTPUT, BARRIER_STAGE_BLIT, {}, {
|
||||
{
|
||||
|
||||
.in = BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE,
|
||||
.out = BARRIER_MEMORY_PERMISSIONS_COPY_READ,
|
||||
.pImage = g_meshColor,
|
||||
},
|
||||
{
|
||||
.in = BARRIER_MEMORY_PERMISSIONS_NONE,
|
||||
.out = BARRIER_MEMORY_PERMISSIONS_COPY_WRITE,
|
||||
@@ -290,12 +364,32 @@ void IVulkan::Frame()
|
||||
1, &imageCopyRegion,
|
||||
VK_FILTER_NEAREST
|
||||
);
|
||||
IRenderer::Barrier(BARRIER_STAGE_BLIT, BARRIER_STAGE_COLOR_OUTPUT, {},
|
||||
{
|
||||
{
|
||||
|
||||
.in = BARRIER_MEMORY_PERMISSIONS_COPY_WRITE,
|
||||
.out = BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE | BARRIER_MEMORY_PERMISSIONS_COLOR_READ,
|
||||
.pImage = IRenderer::GetOutputImage(),
|
||||
}
|
||||
}
|
||||
);
|
||||
for (auto &step: g_StepShading)
|
||||
step.pPipeline->Frame(0);
|
||||
for (auto &step: g_StepPostProcessing)
|
||||
step.pPipeline->Frame(0);
|
||||
for (auto &step: g_StepUI)
|
||||
step.pPipeline->Frame(0);
|
||||
step.pPipeline->Frame(0);
|
||||
IRenderer::Barrier(BARRIER_STAGE_COLOR_OUTPUT, BARRIER_STAGE_IMAGE_OUPUT, {},
|
||||
{
|
||||
{
|
||||
|
||||
.in = BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE,
|
||||
.out = 0,
|
||||
.pImage = IRenderer::GetOutputImage(),
|
||||
}
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
void vk_shader_t::Create( const char *szPath, VkShaderStageFlagBits shaderStage )
|
||||
@@ -428,7 +522,14 @@ void vk_tripipeline_t::Create(
|
||||
.primitiveRestartEnable = VK_TRUE,
|
||||
};
|
||||
VkPipelineColorBlendAttachmentState pcbas = {
|
||||
.blendEnable = VK_FALSE,
|
||||
.blendEnable = VK_TRUE,
|
||||
.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA,
|
||||
.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
.colorBlendOp = VK_BLEND_OP_ADD,
|
||||
|
||||
.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE,
|
||||
.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA,
|
||||
.alphaBlendOp = VK_BLEND_OP_ADD,
|
||||
.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT,
|
||||
};
|
||||
|
||||
@@ -873,16 +974,21 @@ void IRenderer::Barrier( uint32_t stageIn, uint32_t stageOut, CUtlVector<BufferB
|
||||
if (stageIn & BARRIER_STAGE_GEOMETRY_SHADER) psfSrc |= VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT;
|
||||
if (stageIn & BARRIER_STAGE_FRAGMENT_SHADER) psfSrc |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
|
||||
if (stageIn & BARRIER_STAGE_COLOR_OUTPUT) psfSrc |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
if (stageIn & BARRIER_STAGE_DEPTH_OUTPUT) psfSrc |= VK_PIPELINE_STAGE_LATE_FRAGMENT_TESTS_BIT;
|
||||
if (stageIn & BARRIER_STAGE_RAY_TRACING_SHADER) psfSrc |= VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR;
|
||||
if (stageIn & BARRIER_STAGE_BOTTOM) psfSrc |= VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||
if (stageIn & BARRIER_STAGE_BLIT) psfSrc |= VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||
if (stageIn & BARRIER_STAGE_COPY) psfSrc |= VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||
if (stageOut & BARRIER_STAGE_TOP) psfDst |= VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||
if (stageOut & BARRIER_STAGE_VERTEX_INPUT) psfDst |= VK_PIPELINE_STAGE_VERTEX_INPUT_BIT;
|
||||
if (stageOut & BARRIER_STAGE_VERTEX_SHADER) psfDst |= VK_PIPELINE_STAGE_VERTEX_SHADER_BIT;
|
||||
if (stageOut & BARRIER_STAGE_GEOMETRY_SHADER) psfDst |= VK_PIPELINE_STAGE_GEOMETRY_SHADER_BIT;
|
||||
if (stageOut & BARRIER_STAGE_FRAGMENT_SHADER) psfDst |= VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT;
|
||||
if (stageOut & BARRIER_STAGE_COLOR_OUTPUT) psfDst |= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
if (stageOut & BARRIER_STAGE_DEPTH_OUTPUT) psfDst |= VK_PIPELINE_STAGE_EARLY_FRAGMENT_TESTS_BIT;
|
||||
if (stageOut & BARRIER_STAGE_RAY_TRACING_SHADER) psfDst |= VK_PIPELINE_STAGE_RAY_TRACING_SHADER_BIT_KHR;
|
||||
if (stageOut & BARRIER_STAGE_BOTTOM) psfDst |= VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||
if (stageOut & BARRIER_STAGE_BLIT) psfDst |= VK_PIPELINE_STAGE_TRANSFER_BIT;
|
||||
if (stageOut & BARRIER_STAGE_IMAGE_OUPUT) psfDst |= VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||
|
||||
CUtlVector<VkImageMemoryBarrier> imb = {};
|
||||
CUtlVector<VkBufferMemoryBarrier> bmb = {};
|
||||
@@ -923,86 +1029,45 @@ void IRenderer::Barrier( uint32_t stageIn, uint32_t stageOut, CUtlVector<BufferB
|
||||
.layerCount = 1,
|
||||
};
|
||||
b.subresourceRange = isr;
|
||||
b.oldLayout = pVkImage->m_currentLayout;
|
||||
if (pVkImage->m_usage == IMAGE_USAGE_COLOR_ATTACHMENT)
|
||||
{
|
||||
b.oldLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
b.newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
|
||||
}
|
||||
if (pVkImage->m_usage == IMAGE_USAGE_DEPTH_ATTACHMENT)
|
||||
{
|
||||
b.oldLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
|
||||
b.newLayout = VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL;
|
||||
}
|
||||
b.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
b.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||
switch (image.in)
|
||||
{
|
||||
case BARRIER_MEMORY_PERMISSIONS_COLOR_READ: b.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT; break;
|
||||
case BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE: b.srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; break;
|
||||
case BARRIER_MEMORY_PERMISSIONS_DEPTH_READ: b.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; break;
|
||||
case BARRIER_MEMORY_PERMISSIONS_DEPTH_WRITE: b.srcAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
switch (image.out)
|
||||
{
|
||||
case BARRIER_MEMORY_PERMISSIONS_COLOR_READ: b.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT; break;
|
||||
case BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE: b.dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT; break;
|
||||
case BARRIER_MEMORY_PERMISSIONS_DEPTH_READ: b.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT; break;
|
||||
case BARRIER_MEMORY_PERMISSIONS_DEPTH_WRITE: b.dstAccessMask = VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT; break;
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
if (image.in & BARRIER_MEMORY_PERMISSIONS_COLOR_READ) b.srcAccessMask |= VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
|
||||
if (image.in & BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE) b.srcAccessMask |= VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
if (image.in & BARRIER_MEMORY_PERMISSIONS_DEPTH_READ) b.srcAccessMask |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
||||
if (image.in & BARRIER_MEMORY_PERMISSIONS_DEPTH_WRITE) b.srcAccessMask |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
||||
if (image.in & BARRIER_MEMORY_PERMISSIONS_COPY_READ) b.srcAccessMask |= VK_ACCESS_TRANSFER_READ_BIT;
|
||||
if (image.in & BARRIER_MEMORY_PERMISSIONS_COPY_WRITE) b.srcAccessMask |= VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
if (image.in & BARRIER_MEMORY_PERMISSIONS_BLIT_READ) b.srcAccessMask |= VK_ACCESS_TRANSFER_READ_BIT;
|
||||
if (image.in & BARRIER_MEMORY_PERMISSIONS_BLIT_WRITE) b.srcAccessMask |= VK_ACCESS_TRANSFER_WRITE_BIT;
|
||||
|
||||
|
||||
if (image.out & BARRIER_MEMORY_PERMISSIONS_COLOR_READ) b.dstAccessMask |= VK_ACCESS_COLOR_ATTACHMENT_READ_BIT;
|
||||
if (image.out & BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE) b.dstAccessMask |= VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
if (image.out & BARRIER_MEMORY_PERMISSIONS_DEPTH_READ) b.dstAccessMask |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_READ_BIT;
|
||||
if (image.out & BARRIER_MEMORY_PERMISSIONS_DEPTH_WRITE) b.dstAccessMask |= VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT;
|
||||
if (image.out & BARRIER_MEMORY_PERMISSIONS_COPY_READ) { b.dstAccessMask |= VK_ACCESS_TRANSFER_READ_BIT; b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; }
|
||||
if (image.out & BARRIER_MEMORY_PERMISSIONS_COPY_WRITE) { b.dstAccessMask |= VK_ACCESS_TRANSFER_WRITE_BIT; b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; }
|
||||
if (image.out & BARRIER_MEMORY_PERMISSIONS_BLIT_READ) { b.dstAccessMask |= VK_ACCESS_TRANSFER_READ_BIT; b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL; }
|
||||
if (image.out & BARRIER_MEMORY_PERMISSIONS_BLIT_WRITE) { b.dstAccessMask |= VK_ACCESS_TRANSFER_WRITE_BIT; b.newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL; }
|
||||
|
||||
if (stageOut & BARRIER_STAGE_IMAGE_OUPUT) b.newLayout = VK_IMAGE_LAYOUT_PRESENT_SRC_KHR;
|
||||
pVkImage->m_currentLayout = b.newLayout;
|
||||
imb.AppendTail(b);
|
||||
}
|
||||
|
||||
vkCmdPipelineBarrier(g_vkCommandBuffer, psfSrc, psfDst, 0, 0, 0, bmb.GetSize(), bmb.GetData(), imb.GetSize(), imb.GetData());
|
||||
}
|
||||
|
||||
void IRenderer::BindData( uint32_t binding, IBuffer *pBuffer, IImage* pImage)
|
||||
{
|
||||
if (!g_pCurrentPipeline)
|
||||
return;
|
||||
if (g_pCurrentPipeline->type == PIPELINE_TYPE_RASTERIZATION)
|
||||
{
|
||||
CVkGraphicsPipeline *pVkPipeline = (CVkGraphicsPipeline*)g_pCurrentPipeline;
|
||||
CVkBuffer* pVkBuffer = (CVkBuffer*)pBuffer;
|
||||
VkDescriptorBufferInfo dbi;
|
||||
for (auto &input: pVkPipeline->m_inputs)
|
||||
{
|
||||
if (input.binding != binding)
|
||||
continue;
|
||||
|
||||
switch (input.type)
|
||||
{
|
||||
case SHADER_INPUT_TYPE_STORAGE_BUFFER:
|
||||
case SHADER_INPUT_TYPE_UNIFORM_BUFFER:
|
||||
if (!pBuffer)
|
||||
Plat_FatalErrorFunc("pBuffer is NULL\n");
|
||||
if (pVkPipeline->m_writes[binding].pBufferInfo)
|
||||
V_free((void*)pVkPipeline->m_writes[binding].pBufferInfo);
|
||||
dbi = {
|
||||
.buffer = pVkBuffer->m_buffer.m_buffer,
|
||||
.offset = 0,
|
||||
.range = pVkBuffer->m_buffer.m_nSize,
|
||||
};
|
||||
pVkPipeline->m_writes[binding].pBufferInfo = (VkDescriptorBufferInfo*)V_malloc(sizeof(VkDescriptorBufferInfo));
|
||||
V_memcpy((void*)pVkPipeline->m_writes[binding].pBufferInfo, &dbi, sizeof(VkDescriptorBufferInfo));
|
||||
break;
|
||||
case SHADER_INPUT_TYPE_IMAGE:
|
||||
break;
|
||||
case SHADER_INPUT_TYPE_TLAS:
|
||||
break;
|
||||
case SHADER_INPUT_TYPE_TEXTURES:
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void IRenderer::BindPipeline( IPipeline *pPipeline )
|
||||
{
|
||||
if (!pPipeline)
|
||||
@@ -1012,44 +1077,10 @@ void IRenderer::BindPipeline( IPipeline *pPipeline )
|
||||
CVkGraphicsPipeline *pVkPipeline = (CVkGraphicsPipeline*)pPipeline;
|
||||
|
||||
vkCmdBindPipeline(g_vkCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pVkPipeline->m_pipeline.m_pipeline);
|
||||
vkCmdBindDescriptorSets(g_vkCommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pVkPipeline->m_pipeline.m_layout, 0, 1, &pVkPipeline->m_descriptorSet, 0, NULL);
|
||||
}
|
||||
g_pCurrentPipeline = pPipeline;
|
||||
}
|
||||
void IRenderer::PushBindings()
|
||||
{
|
||||
|
||||
if (!g_pCurrentPipeline)
|
||||
return;
|
||||
if (g_pCurrentPipeline->type == PIPELINE_TYPE_RASTERIZATION)
|
||||
{
|
||||
CVkGraphicsPipeline *pVkPipeline = (CVkGraphicsPipeline*)g_pCurrentPipeline;
|
||||
|
||||
CUtlVector<VkDescriptorImageInfo> textures;
|
||||
textures.Reserve(g_textures.GetSize());
|
||||
for (ITexture *t: g_textures)
|
||||
{
|
||||
CVkTexture *texture = (CVkTexture*)t;
|
||||
VkDescriptorImageInfo image = {};
|
||||
image.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
image.imageView = texture->image.m_imageView;
|
||||
image.sampler = g_invalidTextureSampler;
|
||||
textures.AppendTail(image);
|
||||
};
|
||||
|
||||
for ( int i = 0; i < pVkPipeline->m_inputs.GetSize(); i++ )
|
||||
{
|
||||
if (pVkPipeline->m_inputs[i].type == SHADER_INPUT_TYPE_TEXTURES)
|
||||
{
|
||||
pVkPipeline->m_writes[i].descriptorCount = textures.GetSize();
|
||||
pVkPipeline->m_writes[i].pImageInfo = textures.GetData();
|
||||
}
|
||||
}
|
||||
textures[0].sampler = g_invalidTextureSampler;
|
||||
|
||||
vkUpdateDescriptorSets(g_vkDevice, pVkPipeline->m_writes.GetSize(), pVkPipeline->m_writes.GetData(), 0, NULL);
|
||||
vkCmdBindDescriptorSets(g_vkCommandBuffer,VK_PIPELINE_BIND_POINT_GRAPHICS, pVkPipeline->m_pipeline.m_layout, 0, 1, &pVkPipeline->m_descriptorSet, 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void IRenderer::Begin( uint32_t nWidth, uint32_t nHeight, CUtlVector<RenderingColorAttachment_t> attachments, RenderingDepthAttachment_t depth )
|
||||
@@ -1257,6 +1288,7 @@ IGraphicsPipeline *IRenderer::CreateGraphicsPipeline(
|
||||
allocInfo.descriptorSetCount = 1;
|
||||
allocInfo.pSetLayouts = &pipeline->m_pipeline.m_descriptorSetLayout;
|
||||
vkAllocateDescriptorSets(g_vkDevice, &allocInfo, &pipeline->m_descriptorSet);
|
||||
V_printf("Created %p\n",pipeline->m_descriptorSet);
|
||||
|
||||
pipeline->m_writes = {};
|
||||
for (auto &input: inputs)
|
||||
|
||||
@@ -204,6 +204,8 @@ EInputKey ISDL_KeyName(SDL_Keycode key)
|
||||
case SDLK_RALT: return KEY_ALT;
|
||||
case SDLK_LALT: return KEY_ALT;
|
||||
case SDLK_SPACE: return KEY_SPACE;
|
||||
|
||||
case SDLK_GRAVE: return KEY_TILDE;
|
||||
|
||||
case SDLK_F1: return KEY_F1;
|
||||
case SDLK_F2: return KEY_F2;
|
||||
@@ -414,15 +416,20 @@ void IVideo::Init()
|
||||
IVulkan::Init();
|
||||
}
|
||||
|
||||
void IInput::SetMouseMode( EMouseMode mode )
|
||||
void IInput::SetInputMode( EInputMode mode )
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case MOUSE_MODE_GAME:
|
||||
case INPUT_MODE_GAME:
|
||||
SDL_SetWindowRelativeMouseMode(g_window, true);
|
||||
return;
|
||||
case INPUT_MODE_MENU:
|
||||
SDL_SetWindowRelativeMouseMode(g_window, false);
|
||||
return;
|
||||
case INPUT_MODE_CONSOLE:
|
||||
SDL_SetWindowRelativeMouseMode(g_window, true);
|
||||
return;
|
||||
default:
|
||||
SDL_SetWindowRelativeMouseMode(g_window, false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,18 +3,23 @@
|
||||
#include "rendering.h"
|
||||
#include "tier1/utlvector.h"
|
||||
#include "fgui/widget.h"
|
||||
#include <cctype>
|
||||
#include "ctype.h"
|
||||
|
||||
float fgui_fRectColor[4];
|
||||
float fgui_fTextColor[4];
|
||||
float fgui_fTextPosition[2];
|
||||
float fgui_fGlyphScale[2];
|
||||
CFont *fgui_pTextFont;
|
||||
|
||||
float fgui_fOffset[2];
|
||||
|
||||
IGraphicsPipeline *fgui_RectPipeline;
|
||||
IGraphicsPipeline *fgui_TextPipeline;
|
||||
IVertexBuffer *fgui_pRectangleBuffer;
|
||||
IVertexBuffer *fgui_pUVRectangleBuffer;
|
||||
|
||||
CUtlVector<CFGUI_Widget*> fgui_widgets;
|
||||
|
||||
void IFGUI::Init( void )
|
||||
{
|
||||
|
||||
@@ -22,14 +27,35 @@ void IFGUI::Init( void )
|
||||
|
||||
void IFGUI::Frame( void )
|
||||
{
|
||||
|
||||
for (auto &widget: fgui_widgets)
|
||||
{
|
||||
widget->Frame();
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Sets offset of the drawn widget
|
||||
//----------------------------------------------------------------------------
|
||||
void IFGUI::AddOffset( float x, float y)
|
||||
{
|
||||
fgui_fOffset[0] += x;
|
||||
fgui_fOffset[1] += y;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Reset offset of the drawn widget
|
||||
//----------------------------------------------------------------------------
|
||||
void IFGUI::ResetOffset()
|
||||
{
|
||||
fgui_fOffset[0] = 0;
|
||||
fgui_fOffset[1] = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Creates new widget in the world
|
||||
//----------------------------------------------------------------------------
|
||||
CUtlVector<CFGUI_Widget*> fgui_widgets;
|
||||
void IFGUI::AppendWidget( CFGUI_Widget *pWidget )
|
||||
{
|
||||
fgui_widgets.AppendTail(pWidget);
|
||||
@@ -81,8 +107,8 @@ void IFGUI::DrawRect( int32_t iPosX, int32_t iPosY, uint32_t uSizeX, uint32_t uS
|
||||
|
||||
constants.nResolution[0] = g_nWindowWidth;
|
||||
constants.nResolution[1] = g_nWindowHeight;
|
||||
constants.nPosition[0] = iPosX;
|
||||
constants.nPosition[1] = iPosY;
|
||||
constants.nPosition[0] = fgui_fOffset[0] + iPosX;
|
||||
constants.nPosition[1] = fgui_fOffset[1] + iPosY;
|
||||
constants.nSize[0] = uSizeX;
|
||||
constants.nSize[1] = uSizeY;
|
||||
for ( int i = 0; i < 4; i++ )
|
||||
@@ -131,6 +157,11 @@ CFont *IFGUI::LoadFont( CUtlString szFontPath )
|
||||
pFont->nGlyphsPerColumn = nElementsHeight;
|
||||
return pFont;
|
||||
}
|
||||
void IFGUI::SetGlyphScale( float x, float y )
|
||||
{
|
||||
fgui_fGlyphScale[0] = x;
|
||||
fgui_fGlyphScale[1] = y;
|
||||
};
|
||||
|
||||
void IFGUI::SetTextFont( CFont *pFont )
|
||||
{
|
||||
@@ -159,7 +190,9 @@ void IFGUI::DrawText( CUtlString psz )
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
IRenderer::BindPipeline(fgui_TextPipeline);
|
||||
|
||||
struct RectConstants_t
|
||||
{
|
||||
uint32_t nResolution[2];
|
||||
@@ -174,10 +207,10 @@ void IFGUI::DrawText( CUtlString psz )
|
||||
|
||||
constants.nResolution[0] = g_nWindowWidth;
|
||||
constants.nResolution[1] = g_nWindowHeight;
|
||||
constants.nPosition[0] = fgui_fTextPosition[0];
|
||||
constants.nPosition[1] = fgui_fTextPosition[1];
|
||||
constants.nSize[0] = fgui_pTextFont->glyphWidth;
|
||||
constants.nSize[1] = fgui_pTextFont->glyphHeight;
|
||||
constants.nPosition[0] = fgui_fOffset[0] + fgui_fTextPosition[0];
|
||||
constants.nPosition[1] = fgui_fOffset[1] + fgui_fTextPosition[1];
|
||||
constants.nSize[0] = fgui_pTextFont->glyphWidth * fgui_fGlyphScale[0];
|
||||
constants.nSize[1] = fgui_pTextFont->glyphHeight * fgui_fGlyphScale[1];
|
||||
constants.fGlyphSize[0] = 1.0 / fgui_pTextFont->nGlyphsPerRow;
|
||||
constants.fGlyphSize[1] = 1.0 / fgui_pTextFont->nGlyphsPerColumn;
|
||||
constants.nFont = ITextureManager::GetTextureID(fgui_pTextFont->pTexture);
|
||||
@@ -191,10 +224,9 @@ void IFGUI::DrawText( CUtlString psz )
|
||||
if (isprint(psz[i]) && !isspace(psz[i]))
|
||||
{
|
||||
IRenderer::SetConstants(sizeof(RectConstants_t), &constants);
|
||||
IRenderer::PushBindings();
|
||||
IRenderer::Draw(fgui_pUVRectangleBuffer, NULL);
|
||||
}
|
||||
constants.nPosition[0] += fgui_pTextFont->glyphWidth;
|
||||
constants.nPosition[0] += constants.nSize[0];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,7 +250,7 @@ void CFGUI_Rendering::Init()
|
||||
48,
|
||||
8,
|
||||
{{0,0,VERTEX_FORMAT_X32Y32}},
|
||||
{IMAGE_FORMAT_R8G8B8A8},
|
||||
{IMAGE_FORMAT_WINDOW},
|
||||
true
|
||||
);
|
||||
fgui_TextPipeline = IRenderer::CreateGraphicsPipeline(
|
||||
@@ -267,13 +299,8 @@ void CFGUI_Rendering::Init()
|
||||
|
||||
void CFGUI_Rendering::Frame( float fDelta )
|
||||
{
|
||||
IRenderer::Barrier(BARRIER_STAGE_TOP, BARRIER_STAGE_COLOR_OUTPUT, {}, {
|
||||
{
|
||||
BARRIER_MEMORY_PERMISSIONS_NONE,
|
||||
BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE,
|
||||
IRenderer::GetOutputImage(),
|
||||
}
|
||||
});
|
||||
fgui_TextPipeline->PushBindings();
|
||||
|
||||
IRenderer::Begin(g_nWindowWidth, g_nWindowHeight, {
|
||||
{
|
||||
IRenderer::GetOutputImage(),
|
||||
@@ -286,16 +313,15 @@ void CFGUI_Rendering::Frame( float fDelta )
|
||||
IRenderer::SetDepthMode(DEPTH_MODE_LESS);
|
||||
for (auto &widget: fgui_widgets)
|
||||
{
|
||||
if (!widget->IsVisible())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
IFGUI::ResetOffset();
|
||||
widget->ComputeOffset();
|
||||
widget->Draw();
|
||||
}
|
||||
IRenderer::End();
|
||||
IRenderer::Barrier(BARRIER_STAGE_COLOR_OUTPUT, BARRIER_STAGE_BOTTOM, {}, {
|
||||
{
|
||||
BARRIER_MEMORY_PERMISSIONS_COLOR_WRITE,
|
||||
BARRIER_MEMORY_PERMISSIONS_NONE,
|
||||
IRenderer::GetOutputImage(),
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
void CFGUI_Rendering::Deinit()
|
||||
|
||||
0
fgui/input_field.cpp
Normal file
0
fgui/input_field.cpp
Normal file
@@ -16,23 +16,32 @@ void CFGUI_Label::SetLabel( CUtlString text )
|
||||
m_szText = text;
|
||||
}
|
||||
|
||||
void CFGUI_Label::SetLabelSize( uint32_t nSize )
|
||||
void CFGUI_Label::SetGlyphSize( uint32_t nSize )
|
||||
{
|
||||
|
||||
if (!m_pFont)
|
||||
return;
|
||||
m_fGlyphScale[1] = (float)nSize/m_pFont->glyphHeight;
|
||||
m_fGlyphScale[0] = m_fGlyphScale[1];
|
||||
}
|
||||
|
||||
void CFGUI_Label::Event( FGUI_Event_t event )
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
void CFGUI_Label::Draw()
|
||||
{
|
||||
IFGUI::SetTextFont(m_pFont);
|
||||
IFGUI::SetTextColor(1, 1, 1, 1);
|
||||
IFGUI::SetGlyphScale(m_fGlyphScale[0], m_fGlyphScale[1]);
|
||||
IFGUI::SetTextPos(m_iPosition[0], m_iPosition[1]);
|
||||
IFGUI::DrawText(m_szText);
|
||||
}
|
||||
|
||||
void CFGUI_Label::Frame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CFGUI_Label::~CFGUI_Label()
|
||||
{
|
||||
|
||||
@@ -19,3 +19,7 @@ void CFGUI_Rect::Draw()
|
||||
IFGUI::DrawRect(m_iPosition[0],m_iPosition[1],m_iSize[0],m_iSize[1]);
|
||||
}
|
||||
|
||||
void CFGUI_Rect::Frame()
|
||||
{
|
||||
|
||||
};
|
||||
|
||||
@@ -25,6 +25,31 @@ void CFGUI_Widget::SetSize( uint32_t nX, uint32_t nY )
|
||||
|
||||
void CFGUI_Widget::SetParent( CFGUI_Widget *pParent )
|
||||
{
|
||||
|
||||
m_pParent = pParent;
|
||||
}
|
||||
|
||||
void CFGUI_Widget::ComputeOffset( void )
|
||||
{
|
||||
CFGUI_Widget *pParent = m_pParent;
|
||||
while (pParent)
|
||||
{
|
||||
IFGUI::AddOffset(pParent->m_iPosition[0], pParent->m_iPosition[1]);
|
||||
pParent = pParent->m_pParent;
|
||||
};
|
||||
}
|
||||
bool CFGUI_Widget::IsVisible( )
|
||||
{
|
||||
CFGUI_Widget *pWidget = this;
|
||||
while (pWidget)
|
||||
{
|
||||
if (!pWidget->m_bIsVisible)
|
||||
return false;
|
||||
pWidget = pWidget->m_pParent;
|
||||
};
|
||||
return true;
|
||||
};
|
||||
|
||||
void CFGUI_Widget::SetVisibility( bool bValue )
|
||||
{
|
||||
m_bIsVisible = bValue;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
bind esc exit;
|
||||
bind f11 exit;
|
||||
bind a +left;
|
||||
bind d +right;
|
||||
bind w +forward;
|
||||
|
||||
@@ -7,9 +7,8 @@ float4 _main(
|
||||
) : SV_TARGET
|
||||
{
|
||||
float dist = SampleTexture(font, (input.uv+glyphPos)*glyphSize).x;
|
||||
float smoothing = 0.2;
|
||||
float alpha = smoothstep(0.5-smoothing, 0.5+smoothing, dist);
|
||||
if (alpha<0.01) discard;
|
||||
return float4(color);
|
||||
float smoothing = 0.4;
|
||||
float alpha = clamp(smoothstep(0.5-smoothing, 0.5+smoothing, dist),0,1);
|
||||
return float4(fontColor.xyz, alpha);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ DECLARE_CONSTANTS()
|
||||
int2 resolution;
|
||||
uint2 size;
|
||||
int2 position;
|
||||
float4 color;
|
||||
float4 fontColor;
|
||||
float2 glyphPos;
|
||||
float2 glyphSize;
|
||||
uint font;
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
|
||||
CUtlVector<CUtlString> client_CompiledFiles = {
|
||||
"game/client/milmoba/player.cpp",
|
||||
"game/client/milmoba/mainmenu.cpp",
|
||||
};
|
||||
|
||||
int client_build()
|
||||
|
||||
90
game/client/milmoba/mainmenu.cpp
Normal file
90
game/client/milmoba/mainmenu.cpp
Normal file
@@ -0,0 +1,90 @@
|
||||
#include "mainmenu.h"
|
||||
#include "fgui/label.h"
|
||||
#include "fgui/rect.h"
|
||||
#include "fgui/widget.h"
|
||||
#include "interface.h"
|
||||
|
||||
class CMOBAMainMenuGUI: public CFGUI_Widget
|
||||
{
|
||||
public:
|
||||
CMOBAMainMenuGUI();
|
||||
virtual void Event( FGUI_Event_t event ) override;
|
||||
virtual void Draw() override;
|
||||
virtual void Frame() override;
|
||||
private:
|
||||
CFGUI_Rect *m_pBackground;
|
||||
CFGUI_Label *m_pGameName;
|
||||
};
|
||||
|
||||
CMOBAMainMenuGUI::CMOBAMainMenuGUI()
|
||||
{
|
||||
SetPosition(0, 0);
|
||||
|
||||
|
||||
m_pBackground = new CFGUI_Rect;
|
||||
m_pBackground->SetParent(this);
|
||||
m_pBackground->SetPosition(90,90);
|
||||
m_pBackground->SetSize(300, 400);
|
||||
m_pBackground->SetBoxColor(0.1, 0.1, 0.1, 1);
|
||||
|
||||
m_pGameName = new CFGUI_Label;
|
||||
m_pGameName->SetParent(this);
|
||||
m_pGameName->SetFont("fonts/IBMPlexMono-Regular");
|
||||
m_pGameName->SetLabel("funnygame");
|
||||
m_pGameName->SetGlyphSize(24);
|
||||
m_pGameName->SetPosition(100, 100);
|
||||
};
|
||||
|
||||
void CMOBAMainMenuGUI::Event( FGUI_Event_t event )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CMOBAMainMenuGUI::Draw()
|
||||
{
|
||||
}
|
||||
|
||||
void CMOBAMainMenuGUI::Frame()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
class CMOBAMainMenu: public IMainMenu
|
||||
{
|
||||
public:
|
||||
virtual void Init() override;
|
||||
virtual void Frame() override;
|
||||
virtual void Deinit() override;
|
||||
|
||||
virtual void SetVisibility( bool bIsVisible ) override;
|
||||
private:
|
||||
CMOBAMainMenuGUI *m_pMainMenu;
|
||||
};
|
||||
|
||||
|
||||
void CMOBAMainMenu::Init()
|
||||
{
|
||||
m_pMainMenu = new CMOBAMainMenuGUI;
|
||||
m_pMainMenu->SetVisibility(true);
|
||||
}
|
||||
|
||||
void CMOBAMainMenu::Frame()
|
||||
{
|
||||
}
|
||||
|
||||
void CMOBAMainMenu::SetVisibility( bool bIsVisible )
|
||||
{
|
||||
m_pMainMenu->SetVisibility(bIsVisible);
|
||||
}
|
||||
|
||||
void CMOBAMainMenu::Deinit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
DECLARE_INTERFACE(MainMenu, CMOBAMainMenu);
|
||||
|
||||
|
||||
|
||||
@@ -16,6 +16,6 @@ DECLARE_GAME_MODE(CTestGameMode, test_gamemode)
|
||||
DLL_EXPORT void IGame_Load()
|
||||
{
|
||||
ILevel::LoadLevel("maps/test_map");
|
||||
IGameModeManager::StartGameMode("test_gamemode");
|
||||
GameModeManager()->StartGameMode("test_gamemode");
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -24,7 +24,8 @@ public:
|
||||
virtual void Destroy( void ) override;
|
||||
virtual void ReadParameter( const char *szName, const char *szValue ) override;
|
||||
virtual void Think( float fDelta ) override;
|
||||
virtual void Sync( void *pData, uint32_t nDataSize ) override;
|
||||
virtual void SendToServer() override;
|
||||
virtual void RecieveFromServer( void *pData, uint32_t nDataSize ) override;
|
||||
|
||||
void Accelerate( void );
|
||||
void AirAccelerate( void );
|
||||
@@ -156,6 +157,16 @@ void CMOBAPlayer::PlayerMove( void )
|
||||
CategorizePosition();
|
||||
}
|
||||
|
||||
struct PlayerMovement_t: public PacketPlayer_t
|
||||
{
|
||||
bool bIsForward;
|
||||
bool bIsBack;
|
||||
bool bIsLeft;
|
||||
bool bIsRight;
|
||||
float fPitch;
|
||||
float fYaw;
|
||||
};
|
||||
|
||||
void CMOBAPlayer::Think( float fDelta )
|
||||
{
|
||||
if (INetworking::IsClient())
|
||||
@@ -173,50 +184,39 @@ void CMOBAPlayer::Think( float fDelta )
|
||||
PlayerMove();
|
||||
};
|
||||
|
||||
void CMOBAPlayer::Sync( void *pData, uint32_t nDataSize )
|
||||
void CMOBAPlayer::SendToServer()
|
||||
{
|
||||
|
||||
struct PlayerMovement_t: public PacketPlayer_t
|
||||
{
|
||||
bool bIsForward;
|
||||
bool bIsBack;
|
||||
bool bIsLeft;
|
||||
bool bIsRight;
|
||||
float fPitch;
|
||||
float fYaw;
|
||||
PlayerMovement_t movement = {
|
||||
.bIsForward = bIsForward,
|
||||
.bIsBack = bIsBack,
|
||||
.bIsLeft = bIsLeft,
|
||||
.bIsRight = bIsRight,
|
||||
.fPitch = fPitch,
|
||||
.fYaw = fYaw,
|
||||
};
|
||||
|
||||
// Send data
|
||||
if ( pData == NULL )
|
||||
movement.type = PACKET_TYPE_PLAYER_MOVEMENT;
|
||||
if (INetworking::IsClient())
|
||||
{
|
||||
PlayerMovement_t movement = {
|
||||
.bIsForward = bIsForward,
|
||||
.bIsBack = bIsBack,
|
||||
.bIsLeft = bIsLeft,
|
||||
.bIsRight = bIsRight,
|
||||
.fPitch = fPitch,
|
||||
.fYaw = fYaw,
|
||||
};
|
||||
movement.type = PACKET_TYPE_PLAYER_MOVEMENT;
|
||||
if (INetworking::IsClient())
|
||||
if (g_localClient->pBasePlayer != this)
|
||||
return;
|
||||
INetworking::SendData(&movement, sizeof(PlayerMovement_t), 0, MESSAGE_MODE_RELIABLE);
|
||||
} else {
|
||||
for (auto &client: g_clients)
|
||||
{
|
||||
if (g_localClient->pBasePlayer != this)
|
||||
return;
|
||||
INetworking::SendData(&movement, sizeof(PlayerMovement_t), 0, MESSAGE_MODE_RELIABLE);
|
||||
} else {
|
||||
for (auto &client: g_clients)
|
||||
if (client->pBasePlayer == this)
|
||||
{
|
||||
if (client->pBasePlayer == this)
|
||||
{
|
||||
movement.playerHandle = client->playerHandle;
|
||||
break;
|
||||
}
|
||||
movement.playerHandle = client->playerHandle;
|
||||
break;
|
||||
}
|
||||
INetworking::SendDataEverybodyExcept(&movement, sizeof(PlayerMovement_t), this, MESSAGE_MODE_RELIABLE);
|
||||
}
|
||||
return;
|
||||
INetworking::SendDataEverybodyExcept(&movement, sizeof(PlayerMovement_t), this, MESSAGE_MODE_RELIABLE);
|
||||
}
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void CMOBAPlayer::RecieveFromServer( void *pData, uint32_t nDataSize )
|
||||
{
|
||||
Packet_t *pPacket = (Packet_t*)pData;
|
||||
if (pPacket->type == PACKET_TYPE_PLAYER_MOVEMENT)
|
||||
{
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "unistd.h"
|
||||
#include "dlfcn.h"
|
||||
#include "libgen.h"
|
||||
#include <dlfcn.h>
|
||||
#ifdef __APPLE__
|
||||
#include <mach-o/dyld.h>
|
||||
#endif
|
||||
@@ -60,12 +61,12 @@ int main( int argc, char **argv ) {
|
||||
#endif
|
||||
if ( !dlopen(szSteamPath, RTLD_NOW ))
|
||||
printf("Failed to open steam\n");
|
||||
pTier0Lib = dlopen(szTier0Path, RTLD_NOW | RTLD_GLOBAL);
|
||||
pTier0Lib = dlopen(szTier0Path, RTLD_LAZY | RTLD_GLOBAL);
|
||||
if ( !pTier0Lib ) {
|
||||
printf("Failed to open libtier0\n");
|
||||
printf("\t%s\n",dlerror());
|
||||
}
|
||||
pEngineLib = dlopen(szEnginePath, RTLD_NOW | RTLD_GLOBAL);
|
||||
pEngineLib = dlopen(szEnginePath, RTLD_LAZY | RTLD_GLOBAL);
|
||||
if ( !pEngineLib ) {
|
||||
printf("Failed to open libengine\n");
|
||||
printf("\t%s\n",dlerror());
|
||||
|
||||
@@ -12,6 +12,7 @@ enum EPredictionMode {
|
||||
PREDICTION_MODE_DESTROYED,
|
||||
PREDICTION_MODE_NONE,
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Base server entity class.
|
||||
// It is updated every 1/tickrate (64) of a second. Does not require special
|
||||
@@ -22,11 +23,36 @@ class CBaseEntity
|
||||
public:
|
||||
CBaseEntity();
|
||||
virtual void Precache() = 0;
|
||||
|
||||
virtual void Spawn( void ) = 0;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
//
|
||||
//---------------------------------------------------------------------
|
||||
virtual void Destroy( void ) = 0;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Reads the parameter from the level file. szName indicates of the
|
||||
// parameter that is sent to be deserialized. szValue is value encoded
|
||||
// as a string.
|
||||
//---------------------------------------------------------------------
|
||||
virtual void ReadParameter( const char *szName, const char *szValue );
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Update at constant rate (+-tickrate times a second).
|
||||
//---------------------------------------------------------------------
|
||||
virtual void Think( float fDelta ) = 0;
|
||||
virtual void Sync( void *pData, uint32_t nDataSize ) = 0;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Used to send data from an actual server.
|
||||
//---------------------------------------------------------------------
|
||||
virtual void SendToServer() = 0;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Used to recieve data from an actual server.
|
||||
//---------------------------------------------------------------------
|
||||
virtual void RecieveFromServer( void *pData, uint32_t nDataSize ) = 0;
|
||||
|
||||
void SetPosition( vec3 position );
|
||||
void SetRotationEuler( vec3 euler );
|
||||
void SetRotationQuat( vec4 quaternion );
|
||||
|
||||
@@ -32,7 +32,8 @@ public:
|
||||
virtual void ReadParameter( const char *szName, const char *szValue ) override;
|
||||
virtual void Destroy( void ) override;
|
||||
virtual void Think( float fDelta ) override;
|
||||
virtual void Sync( void *pData, uint32_t nDataSize ) override;
|
||||
virtual void SendToServer() override;
|
||||
virtual void RecieveFromServer( void *pData, uint32_t nDataSize ) override;
|
||||
|
||||
CUtlVector<Triangle_t> m_mesh;
|
||||
Collider *m_collider;
|
||||
|
||||
@@ -10,9 +10,24 @@ class ConCommand;
|
||||
|
||||
typedef void(*ConCommandFn)(int argc, char **argv);
|
||||
|
||||
interface IConsoleUI
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Frame();
|
||||
static void Deinit();
|
||||
|
||||
static void SetVisibility(bool bIsVisisble);
|
||||
static bool IsVisibile();
|
||||
};
|
||||
|
||||
interface IConsole
|
||||
{
|
||||
public:
|
||||
static void Init();
|
||||
static void Frame();
|
||||
static void Deinit();
|
||||
|
||||
// Variables
|
||||
static void RegisterVar( ConVar *cvar );
|
||||
static void UnRegisterVar( ConVar *cvar );
|
||||
@@ -103,6 +118,9 @@ private:
|
||||
int m_flags;
|
||||
};
|
||||
|
||||
#undef V_printf
|
||||
#define V_printf(...) Msg(CUtlString(__VA_ARGS__).GetString())
|
||||
|
||||
void Msg( const char* message );
|
||||
void Warning( const char* message );
|
||||
void Error( const char* message );
|
||||
|
||||
@@ -31,6 +31,8 @@ public:
|
||||
static void Frame( void );
|
||||
static void AppendWidget( CFGUI_Widget *pWidget );
|
||||
static void DestroyWidget( CFGUI_Widget *pWidget );
|
||||
static void AddOffset( float x, float y);
|
||||
static void ResetOffset();
|
||||
|
||||
static void SetRectColor( float r, float g, float b, float a );
|
||||
static void DrawRect( int32_t iPosX, int32_t iPosY, uint32_t uSizeX, uint32_t uSizeY );
|
||||
@@ -38,6 +40,7 @@ public:
|
||||
static CFont *LoadFont( CUtlString szFontPath );
|
||||
static void SetTextFont( CFont *pFont );
|
||||
static void SetTextPos( float x, float y );
|
||||
static void SetGlyphScale( float x, float y );
|
||||
static void SetTextColor( float r, float g, float b, float a );
|
||||
static void DrawText( CUtlString psz );
|
||||
};
|
||||
|
||||
@@ -10,17 +10,21 @@ public:
|
||||
CFGUI_Label();
|
||||
~CFGUI_Label();
|
||||
|
||||
CUtlString m_szText;
|
||||
float m_fLabelColor[3];
|
||||
|
||||
void SetFont( CUtlString font );
|
||||
void SetColor( float r, float g, float b );
|
||||
void SetLabel( CUtlString text );
|
||||
void SetLabelSize( uint32_t nSize );
|
||||
void SetGlyphSize( uint32_t nSize );
|
||||
void SetGlyphSize( uint32_t nSizeX, uint32_t nSizeY );
|
||||
|
||||
virtual void Event( FGUI_Event_t event ) override;
|
||||
virtual void Draw() override;
|
||||
virtual void Frame() override;
|
||||
|
||||
private:
|
||||
CUtlString m_szText;
|
||||
float m_fLabelColor[3];
|
||||
float m_fGlyphScale[2] = {1,1};
|
||||
CFont *m_pFont;
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ public:
|
||||
|
||||
virtual void Event( FGUI_Event_t event ) override;
|
||||
virtual void Draw() override;
|
||||
virtual void Frame() override;
|
||||
|
||||
float m_fBoxColor[4];
|
||||
};
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "fgui.h"
|
||||
#include <cstdint>
|
||||
|
||||
class CFGUI_Widget
|
||||
{
|
||||
@@ -15,14 +16,18 @@ public:
|
||||
void SetSize( uint32_t nX, uint32_t nY );
|
||||
void SetParent( CFGUI_Widget *pParent );
|
||||
|
||||
void ComputeOffset( );
|
||||
bool IsVisible( );
|
||||
|
||||
virtual void Event( FGUI_Event_t event ) = 0;
|
||||
virtual void Draw() = 0;
|
||||
virtual void Frame() = 0;
|
||||
virtual void SetVisibility( bool bValue );
|
||||
|
||||
static void SetDefaultParent(CFGUI_Widget *pParent);
|
||||
|
||||
int32_t m_iPosition[2];
|
||||
uint32_t m_iSize[2];
|
||||
CFGUI_Widget *m_pParent;
|
||||
CFGUI_Widget *m_pParent = NULL;
|
||||
bool m_bIsVisible = true;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef GAMEMODE_H
|
||||
#define GAMEMODE_H
|
||||
|
||||
#include "interface.h"
|
||||
#include "tier0/platform.h"
|
||||
|
||||
class CGameMode
|
||||
@@ -11,18 +12,17 @@ public:
|
||||
bool bCanPlayerSpawnMidRound;
|
||||
};
|
||||
|
||||
interface IGameModeManager
|
||||
interface IGameModeManager: public IInterface
|
||||
{
|
||||
public:
|
||||
static void Init( void );
|
||||
static void Frame( void );
|
||||
|
||||
static void StartGameMode( const char *szName );
|
||||
static const char *GetCurrentGameMode( void );
|
||||
static CGameMode *GetCurrentGameModeClass( void );
|
||||
static void RestartCurrentGameMode( void );
|
||||
virtual void StartGameMode( const char *szName ) = 0;
|
||||
virtual const char *GetCurrentGameMode( void ) = 0;
|
||||
virtual CGameMode *GetCurrentGameModeClass( void ) = 0;
|
||||
virtual void RestartCurrentGameMode( void ) = 0;
|
||||
};
|
||||
|
||||
extern IGameModeManager *GameModeManager();
|
||||
|
||||
typedef CGameMode*(*GameModeRegistryFn)();
|
||||
class CGameModeRegistry
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define INPUT_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
#include "tier1/utlvector.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Keys include mouse buttons and gamepad buttons as well.
|
||||
@@ -17,6 +18,13 @@ enum EKeyEventType
|
||||
enum EInputKey
|
||||
{
|
||||
KEY_NONE = 0,
|
||||
|
||||
KEY_MOUSE_BUTTON_0,
|
||||
KEY_MOUSE_BUTTON_1,
|
||||
KEY_MOUSE_BUTTON_2,
|
||||
KEY_MOUSE_BUTTON_3,
|
||||
KEY_MOUSE_BUTTON_4,
|
||||
|
||||
KEY_ESCAPE,
|
||||
KEY_TAB,
|
||||
KEY_TILDE,
|
||||
@@ -102,19 +110,23 @@ enum EInputAxis
|
||||
AXIS_NUM_AXIS = AXIS_MAX,
|
||||
};
|
||||
|
||||
enum EMouseMode
|
||||
enum EInputMode
|
||||
{
|
||||
MOUSE_MODE_GAME,
|
||||
MOUSE_MODE_MENU,F
|
||||
INPUT_MODE_GAME,
|
||||
INPUT_MODE_MENU,
|
||||
INPUT_MODE_CONSOLE,
|
||||
INPUT_MODE_INPUT_FIELD,
|
||||
};
|
||||
|
||||
extern CUtlVector<EInputMode> g_inputModeStack;
|
||||
|
||||
interface IInput
|
||||
{
|
||||
public:
|
||||
static void Init( void );
|
||||
static void KeyEvent( EInputKey key, EKeyEventType event );
|
||||
static void AxisEvent( EInputAxis axis, float fValue );
|
||||
static void SetMouseMode( EMouseMode mode );
|
||||
static void SetInputMode( EInputMode mode );
|
||||
static void Frame( void );
|
||||
static void Deinit( void );
|
||||
};
|
||||
|
||||
34
public/interface.h
Normal file
34
public/interface.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef INTERFACE_H
|
||||
#define INTERFACE_H
|
||||
|
||||
#include "tier0/platform.h"
|
||||
|
||||
abstract_class IInterface
|
||||
{
|
||||
public:
|
||||
virtual void Init() = 0;
|
||||
virtual void Frame() = 0;
|
||||
virtual void Deinit() = 0;
|
||||
};
|
||||
|
||||
typedef IInterface*( *InterfaceRegistryFn )( void );
|
||||
|
||||
class CInterfaceRegistry
|
||||
{
|
||||
public:
|
||||
CInterfaceRegistry( const char *szName, InterfaceRegistryFn pfn );
|
||||
};
|
||||
|
||||
|
||||
#define DECLARE_INTERFACE(iface, impl) \
|
||||
IInterface *__interface_alloc_##impl() \
|
||||
{ \
|
||||
return new impl; \
|
||||
}; \
|
||||
CInterfaceRegistry __interface_##name##_registry(#iface, __interface_alloc_##impl); \
|
||||
I##iface *iface() { \
|
||||
static I##iface *pInterface = (I##iface*)__interface_alloc_##impl(); \
|
||||
return pInterface; \
|
||||
}
|
||||
|
||||
#endif
|
||||
18
public/mainmenu.h
Normal file
18
public/mainmenu.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef MAIN_MENU_H
|
||||
#define MAIN_MENU_H
|
||||
|
||||
#include "interface.h"
|
||||
|
||||
interface IMainMenu: public IInterface
|
||||
{
|
||||
public:
|
||||
virtual void Init() override {}
|
||||
virtual void Frame() override {}
|
||||
virtual void Deinit() override {}
|
||||
|
||||
virtual void SetVisibility( bool bIsVisible ) = 0;
|
||||
};
|
||||
|
||||
extern IMainMenu *MainMenu();
|
||||
|
||||
#endif
|
||||
@@ -13,7 +13,8 @@ public:
|
||||
virtual void ReadParameter( const char *szName, const char *szValue ) override;
|
||||
virtual void Destroy( void ) override;
|
||||
virtual void Think( float fDelta ) override;
|
||||
virtual void Sync( void *pData, uint32_t nDataSize ) override;
|
||||
virtual void SendToServer() override;
|
||||
virtual void RecieveFromServer( void *pData, uint32_t nDataSize ) override;
|
||||
virtual void RoundEnd( void );
|
||||
virtual void RoundStart( IIClient *pClient );
|
||||
|
||||
|
||||
@@ -106,6 +106,8 @@ enum EBarrierMemoryPermissions
|
||||
BARRIER_MEMORY_PERMISSIONS_DEPTH_WRITE = 0x100,
|
||||
BARRIER_MEMORY_PERMISSIONS_COPY_READ = 0x200,
|
||||
BARRIER_MEMORY_PERMISSIONS_COPY_WRITE = 0x400,
|
||||
BARRIER_MEMORY_PERMISSIONS_BLIT_READ = 0x800,
|
||||
BARRIER_MEMORY_PERMISSIONS_BLIT_WRITE = 0x1000,
|
||||
};
|
||||
enum EBarrierStage
|
||||
{
|
||||
@@ -114,10 +116,14 @@ enum EBarrierStage
|
||||
BARRIER_STAGE_VERTEX_SHADER = 0x4,
|
||||
BARRIER_STAGE_GEOMETRY_SHADER = 0x8,
|
||||
BARRIER_STAGE_FRAGMENT_SHADER = 0x10,
|
||||
BARRIER_STAGE_COLOR_OUTPUT = 0x20,
|
||||
BARRIER_STAGE_COMPUTE_SHADER = 0x40,
|
||||
BARRIER_STAGE_RAY_TRACING_SHADER = 0x80,
|
||||
BARRIER_STAGE_BOTTOM = 0x100,
|
||||
BARRIER_STAGE_DEPTH_OUTPUT = 0x20,
|
||||
BARRIER_STAGE_COLOR_OUTPUT = 0x40,
|
||||
BARRIER_STAGE_COMPUTE_SHADER = 0x80,
|
||||
BARRIER_STAGE_RAY_TRACING_SHADER = 0x100,
|
||||
BARRIER_STAGE_BOTTOM = 0x200,
|
||||
BARRIER_STAGE_BLIT = 0x400,
|
||||
BARRIER_STAGE_COPY = 0x800,
|
||||
BARRIER_STAGE_IMAGE_OUPUT = 0x1000,
|
||||
};
|
||||
|
||||
enum EAttachmentLoadMode
|
||||
@@ -226,6 +232,8 @@ abstract_class IPipeline
|
||||
{
|
||||
public:
|
||||
EPipelineType type;
|
||||
virtual void PushBindings() = 0;
|
||||
virtual void BindData( uint32_t binding, IBuffer *pBuffer, IImage* pImage) = 0;
|
||||
};
|
||||
typedef IPipeline IGraphicsPipeline;
|
||||
typedef IPipeline IComputePipeline;
|
||||
@@ -258,14 +266,14 @@ public:
|
||||
|
||||
struct BufferBarrier_t
|
||||
{
|
||||
EBarrierMemoryPermissions in;
|
||||
EBarrierMemoryPermissions out;
|
||||
uint32_t in;
|
||||
uint32_t out;
|
||||
IBuffer *pBuffer;
|
||||
};
|
||||
struct ImageBarrier_t
|
||||
{
|
||||
EBarrierMemoryPermissions in;
|
||||
EBarrierMemoryPermissions out;
|
||||
uint32_t in;
|
||||
uint32_t out;
|
||||
IImage *pImage;
|
||||
};
|
||||
|
||||
@@ -316,18 +324,16 @@ public:
|
||||
|
||||
static void SetConstants( uint32_t nSize, void *pData );
|
||||
static void Barrier( uint32_t stageIn, uint32_t stageOut, CUtlVector<BufferBarrier_t> buffers, CUtlVector<ImageBarrier_t> images );
|
||||
static void BindData( uint32_t binding, IBuffer *pBuffer, IImage* pImage);
|
||||
static void BindPipeline( IPipeline *pPipeline );
|
||||
static void PushBindings();
|
||||
|
||||
|
||||
static void Begin( uint32_t nWidth, uint32_t nHeight, CUtlVector<RenderingColorAttachment_t> attachments, RenderingDepthAttachment_t depth );
|
||||
static void ResetState();
|
||||
static void SetDepthMode( EDepthMode mode );
|
||||
static void Draw( IVertexBuffer *pVertex, IIndexBuffer *pIndex );
|
||||
static void End();
|
||||
|
||||
static void Dispatch( uint32_t x, uint32_t y, uint32_t z );
|
||||
static void TraceRays( uint32_t x, uint32_t y, uint32_t z );
|
||||
static void End();
|
||||
|
||||
static IGraphicsPipeline *CreateGraphicsPipeline(
|
||||
CUtlVector<Shader_t> shaders,
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "dirent.h"
|
||||
#include "time.h"
|
||||
#include "signal.h"
|
||||
#include <dlfcn.h>
|
||||
#ifdef __linux__
|
||||
#include "dlfcn.h"
|
||||
#include "execinfo.h"
|
||||
|
||||
Reference in New Issue
Block a user