r5sdk/r5dev/vphysics/QHull.cpp
Kawe Mazidjatari 611ea6447a Console performance improvements and bug fixes
* Heavily reduced string compares for coloring logs (the left overs require a dedicated hook, this is for the future)
The new method uses a ImVec 4 constant containing the color obtained via a switch case by context, this is then out into the new CConLog structure where the loop in the console will now gather the colors directly from.
Error/Warning use a single constant.

* Fixed bugs in several log locations where the ostringstream was cleared before the emission causing double logs.

* Added global log mutex to log wrappers that lacked those.
2022-05-09 02:20:07 +02:00

56 lines
1.4 KiB
C++

#include "core/stdafx.h"
#include "core/logdef.h"
#include "vphysics/QHull.h"
#include "engine/sys_utils.h"
#ifndef DEDICATED
#include "gameui/IConsole.h"
#endif // !DEDICATED
//-----------------------------------------------------------------------------
// Purpose: qhull error and debug prints
//-----------------------------------------------------------------------------
int HQHull_PrintFunc(const char* fmt, ...)
{
static char buf[1024] = {};
static std::shared_ptr<spdlog::logger> iconsole = spdlog::get("game_console");
static std::shared_ptr<spdlog::logger> wconsole = spdlog::get("win_console");
static std::shared_ptr<spdlog::logger> qhlogger = spdlog::get("qhull_debug_logger");
s_LogMutex.lock();
{/////////////////////////////
va_list args{};
va_start(args, fmt);
vsnprintf(buf, sizeof(buf), fmt, args);
buf[sizeof(buf) - 1] = 0;
va_end(args);
}/////////////////////////////
qhlogger->debug(buf);
wconsole->debug(buf);
#ifndef DEDICATED
iconsole->debug(buf);
g_pIConsole->m_ivConLog.push_back(CConLog(g_spd_sys_w_oss.str(), ImVec4(0.81f, 0.81f, 0.81f, 1.00f)));
g_spd_sys_w_oss.str("");
g_spd_sys_w_oss.clear();
#endif // !DEDICATED
s_LogMutex.unlock();
return NULL;
}
///////////////////////////////////////////////////////////////////////////////
void QHull_Attach()
{
DetourAttach((LPVOID*)&QHull_PrintFunc, &HQHull_PrintFunc);
}
void QHull_Detach()
{
DetourDetach((LPVOID*)&QHull_PrintFunc, &HQHull_PrintFunc);
}