SP3-15 Tools #13

Merged
direnbharwani merged 2 commits from SP3-15-Tools into main 2022-09-14 19:29:12 +08:00
6 changed files with 180 additions and 22 deletions

View File

@ -6,6 +6,8 @@
#include "Scenes/SBEditorScene.h"
#endif // SHEDITOR
#include "Tools/SHLogger.h"
#include <chrono>
#include <ratio>
#include <ctime>
@ -21,6 +23,7 @@ namespace Sandbox
_In_ INT nCmdShow
)
{
SHLOG_TITLE("Initialising SBApplication")
window.Create(hInstance, hPrevInstance, lpCmdLine, nCmdShow);

View File

@ -34,8 +34,6 @@ INT WINAPI wWinMain
//ShowWindow(::GetConsoleWindow(), SW_HIDE);
#endif
SHLOG_INFO("sup")
SHADE::SHEngine::Run<Sandbox::SBApplication>(hInstance, hPrevInstance, lpCmdLine, nCmdShow);
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
}

View File

@ -174,6 +174,7 @@
<ClInclude Include="src\Graphics\Windowing\Surface\SHVkSurface.h" />
<ClInclude Include="src\Math\SHMath.h" />
<ClInclude Include="src\Math\SHMathHelpers.h" />
<ClInclude Include="src\Math\SHMathHelpers.hpp" />
<ClInclude Include="src\Math\SHMatrix.h" />
<ClInclude Include="src\Math\SHQuaternion.h" />
<ClInclude Include="src\Math\Vector\SHVec2.h" />

View File

@ -382,6 +382,7 @@
<ClInclude Include="src\Tools\SHUtilities.h">
<Filter>Tools</Filter>
</ClInclude>
<ClInclude Include="src\Math\SHMathHelpers.hpp" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\ECS_Base\Components\SHComponent.cpp">

View File

@ -211,6 +211,143 @@ namespace SHADE
sinks[1]->set_pattern(verbosePattern + "%v"); // File Sink
}
void SHLogger::LogInfo(const std::string& msg) noexcept
{
SHLOG_INFO(msg)
}
void SHLogger::LogVerboseInfo(const std::string& msg, const std::source_location& src) noexcept
{
const bool SHOW_SRC_FILE = configFlags & (1U << 3);
const bool SHOW_SRC_LINE = configFlags & (1U << 4);
std::stringstream ss;
ss << "[";
if (SHOW_SRC_FILE)
{
ss << std::filesystem::path(src.file_name()).filename().string() << ", ";
if (SHOW_SRC_LINE)
{
ss << src.line() << ", ";
}
}
ss << src.function_name() << "] " << msg;
SHLOG_INFO(ss.str())
}
void SHLogger::LogWarning(const std::string& msg) noexcept
{
SHLOG_WARNING(msg)
}
void SHLogger::LogVerboseWarning(const std::string& msg, const std::source_location& src) noexcept
{
const bool SHOW_SRC_FILE = configFlags & (1U << 3);
const bool SHOW_SRC_LINE = configFlags & (1U << 4);
std::stringstream ss;
ss << "[";
if (SHOW_SRC_FILE)
{
ss << std::filesystem::path(src.file_name()).filename().string() << ", ";
if (SHOW_SRC_LINE)
{
ss << src.line() << ", ";
}
}
ss << src.function_name() << "] " << msg;
SHLOG_WARNING(ss.str())
}
void SHLogger::LogError(const std::string& msg) noexcept
{
SHLOG_ERROR(msg)
}
void SHLogger::LogVerboseError(const std::string& msg, const std::source_location& src) noexcept
{
const bool SHOW_SRC_FILE = configFlags & (1U << 3);
const bool SHOW_SRC_LINE = configFlags & (1U << 4);
std::stringstream ss;
ss << "[";
if (SHOW_SRC_FILE)
{
ss << std::filesystem::path(src.file_name()).filename().string() << ", ";
if (SHOW_SRC_LINE)
{
ss << src.line() << ", ";
}
}
ss << src.function_name() << "] " << msg;
SHLOG_ERROR(ss.str())
}
void SHLogger::LogCritical(const std::string& msg) noexcept
{
SHLOG_CRITICAL(msg)
}
void SHLogger::LogVerboseCritical(const std::string& msg, const std::source_location& src) noexcept
{
const bool SHOW_SRC_FILE = configFlags & (1U << 3);
const bool SHOW_SRC_LINE = configFlags & (1U << 4);
std::stringstream ss;
ss << "[";
if (SHOW_SRC_FILE)
{
ss << std::filesystem::path(src.file_name()).filename().string() << ", ";
if (SHOW_SRC_LINE)
{
ss << src.line() << ", ";
}
}
ss << src.function_name() << "] " << msg;
SHLOG_CRITICAL(ss.str())
}
void SHLogger::LogFloor() noexcept
{
SHLOG_FLOOR()
}
#ifdef _DEBUG
void SHLogger::LogTrace(const std::string& msg) noexcept
{
SHLOG_TRACE(msg)
}
void SHLogger::LogVerboseTrace(const std::string& msg, const std::source_location& src) noexcept
{
const bool SHOW_SRC_FILE = configFlags & (1U << 3);
const bool SHOW_SRC_LINE = configFlags & (1U << 4);
std::stringstream ss;
ss << "[";
if (SHOW_SRC_FILE)
{
ss << std::filesystem::path(src.file_name()).filename().string() << ", ";
if (SHOW_SRC_LINE)
{
ss << src.line() << ", ";
}
}
ss << src.function_name() << "] " << msg;
SHLOG_TRACE(ss.str())
}
#endif
/*-----------------------------------------------------------------------------------*/
/* Private Function Member Definitions */
/*-----------------------------------------------------------------------------------*/

View File

@ -12,6 +12,7 @@
#include <string_view>
#include <filesystem>
#include <source_location>
#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE
#include <spdlog/spdlog.h>
@ -70,33 +71,33 @@ namespace SHADE
/* Getter Functions */
/*---------------------------------------------------------------------------------*/
[[nodiscard]] static const std::string& GetTrivialPattern () noexcept { return trivialPattern; }
[[nodiscard]] static const std::string& GetVerbosePattern () noexcept { return verbosePattern; }
[[nodiscard]] static const std::string& GetTrivialPattern () noexcept { return trivialPattern; }
[[nodiscard]] static const std::string& GetVerbosePattern () noexcept { return verbosePattern; }
/*---------------------------------------------------------------------------------*/
/* Setter Functions */
/*---------------------------------------------------------------------------------*/
static void SetTrivialPattern (const std::string& pattern) noexcept { trivialPattern = pattern; }
static void SetVerbosePattern (const std::string& pattern) noexcept { verbosePattern = pattern; }
static void SetTrivialPattern (const std::string& pattern) noexcept { trivialPattern = pattern; }
static void SetVerbosePattern (const std::string& pattern) noexcept { verbosePattern = pattern; }
static void SetConfig (const Config& config) noexcept;
static void SetConfig (const Config& config) noexcept;
static void SetShowTime (bool showTime) noexcept;
static void SetShowDate (bool showDate) noexcept;
static void SetShowFunctionFileName (bool showFunctionFileName) noexcept;
static void SetShowFunctionLineNumber (bool showFunctionLineNumber) noexcept;
static void SetShowTime (bool showTime) noexcept;
static void SetShowDate (bool showDate) noexcept;
static void SetShowFunctionFileName (bool showFunctionFileName) noexcept;
static void SetShowFunctionLineNumber (bool showFunctionLineNumber) noexcept;
static void SetClockFormat (ClockFormat newClockFormat) noexcept;
static void SetDateFormat (DateFormat newDateFormat) noexcept;
static void SetClockFormat (ClockFormat newClockFormat) noexcept;
static void SetDateFormat (DateFormat newDateFormat) noexcept;
static void SetFileName (const std::string& logFileName) noexcept;
static void SetDirectoryPath (const std::filesystem::path& logDirectoryPath) noexcept;
static void SetFileName (const std::string& logFileName) noexcept;
static void SetDirectoryPath (const std::filesystem::path& logDirectoryPath) noexcept;
static void SetFlushTime (int seconds) noexcept;
static void SetFlushTime (size_t seconds) noexcept { spdlog::flush_every(std::chrono::seconds(seconds)); }
static void SetFlushTime (int seconds) noexcept;
static void SetFlushTime (size_t seconds) noexcept { spdlog::flush_every(std::chrono::seconds(seconds)); }
/*---------------------------------------------------------------------------------*/
/* Function Members */
@ -107,16 +108,33 @@ namespace SHADE
* @param[in] config The configuration parameters for the logger.
*/
static void Initialise (const Config& config = Config{});
static void Shutdown () noexcept;
static void Shutdown () noexcept;
/**
* @brief The next message logged by the logger will be set to follow the trivial pattern.
*/
static void UseTrivialPattern () noexcept;
static void UseTrivialPattern () noexcept;
/**
* @brief The next message logged by the logger will be set to follow the verbose pattern.
*/
static void UseVerbosePattern () noexcept;
static void UseVerbosePattern () noexcept;
/// Logging Functions to interface with C++/CLI.
static void LogInfo (const std::string& msg) noexcept;
static void LogVerboseInfo (const std::string& msg, const std::source_location& src= std::source_location::current()) noexcept;
static void LogWarning (const std::string& msg) noexcept;
static void LogVerboseWarning (const std::string& msg, const std::source_location& src = std::source_location::current()) noexcept;
static void LogError (const std::string& msg) noexcept;
static void LogVerboseError (const std::string& msg, const std::source_location& src = std::source_location::current()) noexcept;
static void LogCritical (const std::string& msg) noexcept;
static void LogVerboseCritical (const std::string& msg, const std::source_location& src = std::source_location::current()) noexcept;
static void LogFloor () noexcept;
#ifdef _DEBUG
static void LogTrace (const std::string& msg) noexcept;
static void LogVerboseTrace (const std::string& msg, const std::source_location& src = std::source_location::current()) noexcept;
#endif
private:
/*---------------------------------------------------------------------------------*/