fixed windows builds
This commit is contained in:
@@ -3,13 +3,12 @@
|
||||
#include "fgui/widget.h"
|
||||
#include "fgui/label.h"
|
||||
#include "filesystem.h"
|
||||
#include "interface.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
|
||||
{
|
||||
@@ -24,14 +23,9 @@ struct ConsoleMessage_t
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
@@ -45,32 +39,60 @@ void Error( const char* message )
|
||||
|
||||
}
|
||||
|
||||
void IConsole::Init()
|
||||
interface CConsole: public IConsole
|
||||
{
|
||||
public:
|
||||
virtual void Init() override;
|
||||
virtual void Frame() override;
|
||||
virtual void Deinit() override;
|
||||
|
||||
// Variables
|
||||
virtual void RegisterVar( ConVar *cvar ) override;
|
||||
virtual void UnRegisterVar( ConVar *cvar ) override;
|
||||
virtual ConVar *FindVar( const char *pName ) override;
|
||||
|
||||
// Commands
|
||||
virtual void RegisterCommand( ConCommand *cvar ) override;
|
||||
virtual void UnRegisterCommand( ConCommand *cvar ) override;
|
||||
virtual ConCommand *FindCommand( const char *pName ) override;
|
||||
|
||||
// Command buffer
|
||||
virtual void Execute( void ) override;
|
||||
virtual void ExecuteArguments( CUtlVector<CUtlString> &args ) override;
|
||||
virtual CUtlVector<CUtlVector<CUtlString>> ParseCommandLine( CUtlString psz ) override;
|
||||
|
||||
virtual void AddCommand( const char *psz ) override;
|
||||
virtual void InsertCommand( const char *psz ) override;
|
||||
};
|
||||
|
||||
DECLARE_ENGINE_INTERFACE(Console, CConsole)
|
||||
|
||||
void CConsole::Init()
|
||||
{
|
||||
}
|
||||
|
||||
void IConsole::Frame()
|
||||
void CConsole::Frame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void IConsole::Deinit()
|
||||
void CConsole::Deinit()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void IConsole::RegisterVar( ConVar *cvar )
|
||||
void CConsole::RegisterVar( ConVar *cvar )
|
||||
{
|
||||
g_convars.AppendTail(cvar);
|
||||
m_convars.AppendTail(cvar);
|
||||
}
|
||||
void IConsole::UnRegisterVar( ConVar *cvar )
|
||||
void CConsole::UnRegisterVar( ConVar *cvar )
|
||||
{
|
||||
|
||||
}
|
||||
ConVar *IConsole::FindVar( const char *pName )
|
||||
ConVar *CConsole::FindVar( const char *pName )
|
||||
{
|
||||
for (auto &var: g_convars)
|
||||
for (auto &var: m_convars)
|
||||
{
|
||||
if (!V_strcmp(var->GetName(), pName))
|
||||
return var;
|
||||
@@ -78,17 +100,17 @@ ConVar *IConsole::FindVar( const char *pName )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void IConsole::RegisterCommand( ConCommand *cvar )
|
||||
void CConsole::RegisterCommand( ConCommand *cvar )
|
||||
{
|
||||
g_commands.AppendTail(cvar);
|
||||
m_commands.AppendTail(cvar);
|
||||
}
|
||||
void IConsole::UnRegisterCommand( ConCommand *cvar )
|
||||
void CConsole::UnRegisterCommand( ConCommand *cvar )
|
||||
{
|
||||
|
||||
}
|
||||
ConCommand *IConsole::FindCommand( const char *pName )
|
||||
ConCommand *CConsole::FindCommand( const char *pName )
|
||||
{
|
||||
for (auto &var: g_commands)
|
||||
for (auto &var: m_commands)
|
||||
{
|
||||
if (!V_strcmp(var->GetName(), pName))
|
||||
return var;
|
||||
@@ -98,14 +120,14 @@ ConCommand *IConsole::FindCommand( const char *pName )
|
||||
CUtlString g_commandBuffer;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Executes arguments from IConsole::Execute
|
||||
// Executes arguments from CConsole::Execute
|
||||
//-----------------------------------------------------------------------------
|
||||
void IConsole::Execute2( CUtlVector<CUtlString> &args )
|
||||
void CConsole::ExecuteArguments( CUtlVector<CUtlString> &args )
|
||||
{
|
||||
if (args.GetSize()<1)
|
||||
return;
|
||||
|
||||
ConCommand *cmd = IConsole::FindCommand(args[0]);
|
||||
ConCommand *cmd = CConsole::FindCommand(args[0]);
|
||||
if (!cmd)
|
||||
{
|
||||
V_printf("%s not found\n", args[0].GetString());
|
||||
@@ -119,20 +141,20 @@ void IConsole::Execute2( CUtlVector<CUtlString> &args )
|
||||
(cmd->GetCallback())(args.GetSize(), strbuffer);
|
||||
}
|
||||
|
||||
void IConsole::Execute( void )
|
||||
void CConsole::Execute( void )
|
||||
{
|
||||
CUtlVector<CUtlVector<CUtlString>> commands = ParseCommandLine(g_commandBuffer);
|
||||
g_commandBuffer = 0;
|
||||
for (auto &command: commands)
|
||||
{
|
||||
IConsole::Execute2(command);
|
||||
ExecuteArguments(command);
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Parses command buffer.
|
||||
//-----------------------------------------------------------------------------
|
||||
CUtlVector<CUtlVector<CUtlString>> IConsole::ParseCommandLine( CUtlString psz )
|
||||
CUtlVector<CUtlVector<CUtlString>> CConsole::ParseCommandLine( CUtlString psz )
|
||||
{
|
||||
CUtlVector<CUtlString> arguments;
|
||||
CUtlVector<CUtlVector<CUtlString>> commands;
|
||||
@@ -182,12 +204,12 @@ CUtlVector<CUtlVector<CUtlString>> IConsole::ParseCommandLine( CUtlString psz )
|
||||
return commands;
|
||||
}
|
||||
|
||||
void IConsole::AddCommand( const char *psz )
|
||||
void CConsole::AddCommand( const char *psz )
|
||||
{
|
||||
g_commandBuffer.AppendTail(psz);
|
||||
}
|
||||
|
||||
void IConsole::InsertCommand( const char *psz )
|
||||
void CConsole::InsertCommand( const char *psz )
|
||||
{
|
||||
g_commandBuffer.AppendHead(psz);
|
||||
};
|
||||
@@ -210,7 +232,7 @@ ConVar::ConVar( const char *pName, const char *pDefaultValue, int flags,
|
||||
m_szValue = pDefaultValue;
|
||||
m_fValue = V_atof(pDefaultValue);
|
||||
m_nValue = V_atoi(pDefaultValue);
|
||||
IConsole::RegisterVar(this);
|
||||
Console()->RegisterVar(this);
|
||||
}
|
||||
|
||||
bool ConVar::IsFlagSet( int flag )
|
||||
@@ -287,7 +309,7 @@ ConCommand::ConCommand(const char *pName, ConCommandFn callback,
|
||||
m_szName = pName;
|
||||
m_callback = callback;
|
||||
m_flags = flags;
|
||||
IConsole::RegisterCommand(this);
|
||||
Console()->RegisterCommand(this);
|
||||
};
|
||||
const char *ConCommand::GetHelpText( void )
|
||||
{
|
||||
@@ -309,15 +331,15 @@ void IConsole_Exec( int argc, char **argv)
|
||||
if (argc != 2)
|
||||
return;
|
||||
|
||||
FileHandle_t f = IFileSystem::Open(argv[1], IFILE_READ);
|
||||
FileHandle_t f = FileSystem()->Open(argv[1], IFILE_READ);
|
||||
if (!f)
|
||||
return;
|
||||
CUtlBuffer<char> b(IFileSystem::Size(f)+1);
|
||||
IFileSystem::Read(f, b, b.GetSize());
|
||||
b[IFileSystem::Size(f)] = 0;
|
||||
IConsole::AddCommand(b);
|
||||
IConsole::AddCommand(";");
|
||||
IConsole::Execute();
|
||||
CUtlBuffer<char> b(FileSystem()->Size(f)+1);
|
||||
FileSystem()->Read(f, b, b.GetSize());
|
||||
b[FileSystem()->Size(f)] = 0;
|
||||
Console()->AddCommand(b);
|
||||
Console()->AddCommand(";");
|
||||
Console()->Execute();
|
||||
}
|
||||
|
||||
ConCommand IConsole_ExecCmd("exec", IConsole_Exec);
|
||||
@@ -341,11 +363,13 @@ CConsoleGUI::CConsoleGUI()
|
||||
m_pBackground = new CFGUI_Rect();
|
||||
m_pBackground->SetBoxColor(0.13, 0.13, 0.13, 1);
|
||||
m_pBackground->SetSize(200, 200);
|
||||
m_pBackground->SetPosition(0, 0);
|
||||
m_pBackground->SetParent(this);
|
||||
|
||||
m_pLog = new CFGUI_Label();
|
||||
m_pLog->SetFont("fonts/IBMPlexMono-Regular");
|
||||
m_pLog->SetLabel("CONSOLE");
|
||||
m_pLog->SetPosition(0, 0);
|
||||
m_pLog->SetGlyphSize(24);
|
||||
m_pLog->SetParent(this);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user