Tools: rename NETCONSOLE define to _TOOLS

Rename since this would actually be used for all tools. Also moved 'plat_time.cpp' to tier0 so anything could compile it.
This commit is contained in:
Kawe Mazidjatari 2024-01-12 00:25:19 +01:00
parent 057ccd3f86
commit 078c241a0d
9 changed files with 69 additions and 49 deletions

View File

@ -20,7 +20,7 @@ void SpdLog_Init(const bool bAnsiColor)
return;
}
#ifndef NETCONSOLE
#ifndef _TOOLS
g_LogSessionUUID = CreateUUID();
g_LogSessionDirectory = fmt::format("platform\\logs\\{:s}", g_LogSessionUUID);
/************************
@ -33,16 +33,16 @@ void SpdLog_Init(const bool bAnsiColor)
g_ImGuiLogger->set_pattern("%v");
g_ImGuiLogger->set_level(spdlog::level::trace);
}
#endif // !NETCONSOLE
#endif // !_TOOLS
/************************
* WINDOWS LOGGER SETUP *
************************/
{
#ifdef NETCONSOLE
#ifdef _TOOLS
g_TermLogger = spdlog::default_logger();
#else
g_TermLogger = spdlog::stdout_logger_mt("win_console");
#endif // NETCONSOLE
#endif // _TOOLS
// Determine if user wants ansi-color logging in the terminal.
if (bAnsiColor)
@ -57,10 +57,10 @@ void SpdLog_Init(const bool bAnsiColor)
//g_TermLogger->set_level(spdlog::level::trace);
}
#ifndef NETCONSOLE
#ifndef _TOOLS
spdlog::set_default_logger(g_TermLogger); // Set as default.
SpdLog_Create();
#endif // !NETCONSOLE
#endif // !_TOOLS
spdlog::set_level(spdlog::level::trace);
bInitialized = true;

View File

@ -9,13 +9,13 @@
#ifndef CLIENT_DLL
#include "engine/server/sv_rcon.h"
#endif // !CLIENT_DLL
#ifndef NETCONSOLE
#ifndef _TOOLS
#include "vscript/languages/squirrel_re/include/sqstdaux.h"
#endif // !NETCONSOLE
#endif // !_TOOLS
static const std::regex s_AnsiRowRegex("\\\033\\[.*?m");
std::mutex g_LogMutex;
#if !defined (DEDICATED) && !defined (NETCONSOLE)
#if !defined (DEDICATED) && !defined (_TOOLS)
ImVec4 CheckForWarnings(LogType_t type, eDLL_T context, const ImVec4& defaultCol)
{
ImVec4 color = defaultCol;
@ -67,7 +67,7 @@ ImVec4 GetColorForContext(LogType_t type, eDLL_T context)
return CheckForWarnings(type, context, ImVec4(0.81f, 0.81f, 0.81f, 1.00f));
}
}
#endif // !DEDICATED && !NETCONSOLE
#endif // !DEDICATED && !_TOOLS
const char* GetContextNameByIndex(eDLL_T context, const bool ansiColor = false)
{
@ -150,18 +150,18 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
const char* pszContext = GetContextNameByIndex(context, bUseColor);
message.append(pszContext);
#if !defined (DEDICATED) && !defined (NETCONSOLE)
#if !defined (DEDICATED) && !defined (_TOOLS)
ImVec4 overlayColor = GetColorForContext(logType, context);
eDLL_T overlayContext = context;
#endif // !DEDICATED && !NETCONSOLE
#endif // !DEDICATED && !_TOOLS
#if !defined (NETCONSOLE)
#if !defined (_TOOLS)
bool bSquirrel = false;
bool bWarning = false;
bool bError = false;
#else
NOTE_UNUSED(pszLogger);
#endif // !NETCONSOLE
#endif // !_TOOLS
//-------------------------------------------------------------------------
// Setup logger and context
@ -169,24 +169,24 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
switch (logType)
{
case LogType_t::LOG_WARNING:
#if !defined (DEDICATED) && !defined (NETCONSOLE)
#if !defined (DEDICATED) && !defined (_TOOLS)
overlayContext = eDLL_T::SYSTEM_WARNING;
#endif // !DEDICATED && !NETCONSOLE
#endif // !DEDICATED && !_TOOLS
if (bUseColor)
{
message.append(g_svYellowF);
}
break;
case LogType_t::LOG_ERROR:
#if !defined (DEDICATED) && !defined (NETCONSOLE)
#if !defined (DEDICATED) && !defined (_TOOLS)
overlayContext = eDLL_T::SYSTEM_ERROR;
#endif // !DEDICATED && !NETCONSOLE
#endif // !DEDICATED && !_TOOLS
if (bUseColor)
{
message.append(g_svRedF);
}
break;
#ifndef NETCONSOLE
#ifndef _TOOLS
case LogType_t::SQ_INFO:
bSquirrel = true;
break;
@ -198,7 +198,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
bSquirrel = true;
bWarning = true;
break;
#endif // !NETCONSOLE
#endif // !_TOOLS
default:
break;
}
@ -211,7 +211,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
const string formatted = FormatV(pszFormat, argsCopy);
va_end(argsCopy);
#ifndef NETCONSOLE
#ifndef _TOOLS
//-------------------------------------------------------------------------
// Colorize script warnings and errors
//-------------------------------------------------------------------------
@ -253,7 +253,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
message.append(g_svYellowF);
}
}
#endif // !NETCONSOLE
#endif // !_TOOLS
message.append(formatted);
//-------------------------------------------------------------------------
@ -271,7 +271,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
}
}
#ifndef NETCONSOLE
#ifndef _TOOLS
// Output is always logged to the file.
std::shared_ptr<spdlog::logger> ntlogger = spdlog::get(pszLogger); // <-- Obtain by 'pszLogger'.
assert(ntlogger.get() != nullptr);
@ -307,7 +307,7 @@ void EngineLoggerSink(LogType_t logType, LogLevel_t logLevel, eDLL_T context,
g_LogStream.clear();
#endif // !DEDICATED
#endif // !NETCONSOLE
#endif // !_TOOLS
if (exitCode) // Terminate the process if an exit code was passed.
{

View File

@ -6,7 +6,7 @@
#include "core/stdafx.h"
#include "engine/net.h"
#ifndef NETCONSOLE
#ifndef _TOOLS
#include "tier1/cvar.h"
#include "mathlib/color.h"
#include "net.h"
@ -15,9 +15,9 @@
#include "server/server.h"
#include "client/client.h"
#endif // !CLIENT_DLL
#endif // !NETCONSOLE
#endif // !_TOOLS
#ifndef NETCONSOLE
#ifndef _TOOLS
//-----------------------------------------------------------------------------
// Purpose: hook and log the receive datagram
// Input : iSocket -
@ -190,7 +190,7 @@ bool NET_ReadMessageType(int* outType, bf_read* buffer)
return !buffer->IsOverflowed();
}
#endif // !NETCONSOLE
#endif // !_TOOLS
//-----------------------------------------------------------------------------
// Purpose: returns the WSA error code
@ -294,7 +294,7 @@ const char* NET_ErrorString(int iCode)
}
}
#ifndef NETCONSOLE
#ifndef _TOOLS
///////////////////////////////////////////////////////////////////////////////
void VNet::Detour(const bool bAttach) const
{
@ -310,4 +310,4 @@ netadr_t* g_pNetAdr = nullptr;
netkey_t* g_pNetKey = nullptr;
double* g_pNetTime = nullptr;
#endif // !NETCONSOLE
#endif // !_TOOLS

View File

@ -1,6 +1,6 @@
#pragma once
#ifndef NETCONSOLE
#ifndef _TOOLS
#include "engine/net_chan.h"
#include "tier1/lzss.h"
#define MAX_STREAMS 2
@ -79,6 +79,6 @@ class VNet : public IDetour
virtual void Detour(const bool bAttach) const;
};
///////////////////////////////////////////////////////////////////////////////
#endif // !NETCONSOLE
#endif // !_TOOLS
const char* NET_ErrorString(int iCode);

View File

@ -6,13 +6,13 @@ start_sources()
add_sources( SOURCE_GROUP "Core"
"netconsole.cpp"
"netconsole.h"
"plat_time.cpp"
"${ENGINE_SOURCE_DIR}/core/logdef.cpp"
"${ENGINE_SOURCE_DIR}/core/logdef.h"
"${ENGINE_SOURCE_DIR}/core/logger.cpp"
"${ENGINE_SOURCE_DIR}/core/logger.h"
"${ENGINE_SOURCE_DIR}/core/termutil.cpp"
"${ENGINE_SOURCE_DIR}/core/termutil.h"
"${ENGINE_SOURCE_DIR}/tier0/plat_time.cpp"
)
add_sources( SOURCE_GROUP "Engine"
@ -40,7 +40,7 @@ set_target_properties( ${PROJECT_NAME} PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "$(ProjectDir)../../../${BUILD_OUTPUT_DIR}/bin/"
)
target_compile_definitions( ${PROJECT_NAME} PRIVATE
"NETCONSOLE"
"_TOOLS"
)
target_link_libraries( ${PROJECT_NAME} PRIVATE
"tier0"

View File

@ -8,14 +8,14 @@
#include "tier0/dbg.h"
#include "tier0/platform.h"
#ifndef NETCONSOLE
#ifndef _TOOLS
#include "tier0/threadtools.h"
#include "tier0/commandline.h"
#if defined( _X360 )
#include "xbox/xbox_console.h"
#endif
#endif // !NETCONSOLE
#endif // !_TOOLS
CoreMsgVCallbackSink_t g_CoreMsgVCallback = nullptr;
@ -24,7 +24,7 @@ CoreMsgVCallbackSink_t g_CoreMsgVCallback = nullptr;
//-----------------------------------------------------------------------------
bool HushAsserts()
{
#if defined (DBGFLAG_ASSERT) && !defined (NETCONSOLE)
#if defined (DBGFLAG_ASSERT) && !defined (_TOOLS)
static bool s_bHushAsserts = !!CommandLine()->FindParm("-hushasserts");
return s_bHushAsserts;
#else
@ -222,3 +222,17 @@ void DevWarning(eDLL_T context, const char* fmt, ...)
va_end(args);
}
#endif // !DBGFLAG_STRINGS_STRIP
//-----------------------------------------------------------------------------
// Purpose: Print engine and SDK errors, and exit process
// Input : context -
// code -
// *fmt - ... -
//-----------------------------------------------------------------------------
void Plat_FatalError(eDLL_T context, const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
CoreMsgV(LogType_t::LOG_ERROR, LogLevel_t::LEVEL_NOTIFY, context, "sdk(error)", fmt, args, EXIT_FAILURE);
va_end(args);
}

View File

@ -1,3 +1,9 @@
//=============================================================================//
//
// Purpose: Static platform time utilities
// ----------------------------------------------------------------------------
// NOTE: use this for standalone/tools projects
//=============================================================================//
#include "core/stdafx.h"
static LARGE_INTEGER g_PerformanceFrequency;
@ -78,11 +84,11 @@ uint64 Plat_USTime()
return (uint64)((CurrentTime.QuadPart - g_ClockStart.QuadPart) * g_PerformanceCounterToUS);
}
#ifdef NETCONSOLE
#ifdef _TOOLS
#define TIMER_FORMAT "(%.3f) "
#else
#define TIMER_FORMAT "[%.3f] "
#endif // NETCONSOLE
#endif // _TOOLS
const char* Plat_GetProcessUpTime()
{

View File

@ -6,9 +6,9 @@
#include <tier1/NetAdr.h>
#include <tier2/socketcreator.h>
#ifndef NETCONSOLE
#ifndef _TOOLS
#include <engine/sys_utils.h>
#endif // !NETCONSOLE
#endif // !_TOOLS
#include <engine/net.h>
//-----------------------------------------------------------------------------

View File

@ -5,7 +5,7 @@
//=============================================================================//
#include "core/stdafx.h"
#ifndef NETCONSOLE
#ifndef _TOOLS
#include "core/init.h"
#include "core/logdef.h"
#include "tier0/frametask.h"
@ -13,7 +13,7 @@
#ifndef DEDICATED
#include "windows/id3dx.h"
#endif // !DEDICATED
#endif // !NETCONSOLE
#endif // !_TOOLS
#include "windows/system.h"
#include "windows/console.h"
@ -80,7 +80,7 @@ void FlashConsoleBackground(int nFlashCount, int nFlashInterval, COLORREF color)
//-----------------------------------------------------------------------------
void Console_Init(const bool bAnsiColor)
{
#ifndef NETCONSOLE
#ifndef _TOOLS
///////////////////////////////////////////////////////////////////////////
// Create the console window
if (AllocConsole() == FALSE)
@ -107,7 +107,7 @@ void Console_Init(const bool bAnsiColor)
{
CloseHandle(hThread);
}
#endif // !NETCONSOLE
#endif // !_TOOLS
HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD dwMode = NULL;
@ -128,9 +128,9 @@ void Console_Init(const bool bAnsiColor)
AnsiColors_Init();
}
#ifndef NETCONSOLE
#ifndef _TOOLS
SetConsoleCtrlHandler(ConsoleHandlerRoutine, true);
#endif // !NETCONSOLE
#endif // !_TOOLS
}
//-----------------------------------------------------------------------------
@ -147,7 +147,7 @@ void Console_Shutdown()
}
}
#ifndef NETCONSOLE
#ifndef _TOOLS
//#############################################################################
// CONSOLE WORKER
//#############################################################################
@ -169,4 +169,4 @@ DWORD __stdcall ProcessConsoleWorker(LPVOID)
}
return NULL;
}
#endif // !NETCONSOLE
#endif // !_TOOLS