Compare commits
No commits in common. "1015569263590d779aee943417b57e7214a082c7" and "24f4fb3841c9fd9d4c349c9945c283003fb4a9b8" have entirely different histories.
1015569263
...
24f4fb3841
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,4 +3,4 @@ cmake-build-debug/
|
|||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
# Build folders
|
# Build folders
|
||||||
build*/
|
*build/
|
||||||
|
@ -36,19 +36,15 @@ SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${ARCH_DIR}/lib)
|
|||||||
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${ARCH_DIR}/lib)
|
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${ARCH_DIR}/lib)
|
||||||
|
|
||||||
IF (MSVC)
|
IF (MSVC)
|
||||||
IF (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
|
|
||||||
ADD_COMPILE_OPTIONS(/W4 /WX)
|
ADD_COMPILE_OPTIONS(/W4 /WX)
|
||||||
ENDIF ()
|
|
||||||
ELSE ()
|
ELSE ()
|
||||||
IF (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
|
|
||||||
ADD_COMPILE_OPTIONS(-Wall -Wextra -Werror -Wpedantic)
|
ADD_COMPILE_OPTIONS(-Wall -Wextra -Werror -Wpedantic)
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
ENDIF ()
|
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(engine/)
|
INCLUDE_DIRECTORIES(engine/)
|
||||||
|
|
||||||
SET(EngineSources
|
SET(EngineSources
|
||||||
engine/src/core/ICEApplication.cpp
|
engine/src/core/test.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
SET(PrecompiledHeader "pch.h")
|
SET(PrecompiledHeader "pch.h")
|
||||||
|
@ -6,6 +6,5 @@
|
|||||||
#define ICENGINE_HPP
|
#define ICENGINE_HPP
|
||||||
|
|
||||||
#include "src/core/Logger.hpp"
|
#include "src/core/Logger.hpp"
|
||||||
#include "src/core/ICEApplication.hpp"
|
|
||||||
|
|
||||||
#endif //ICENGINE_HPP
|
#endif //ICENGINE_HPP
|
||||||
|
@ -8,6 +8,5 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <utility>
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by illyum on 9/15/2024.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "ICEngine.hpp"
|
|
||||||
#include "pch.hpp"
|
|
||||||
|
|
||||||
namespace ICEngine {
|
|
||||||
void StartApplication() {
|
|
||||||
Log::Init();
|
|
||||||
CORE_LOG_TRACE("Starting ICEngine");
|
|
||||||
|
|
||||||
ICEApplication* app = CreateICEApplication();
|
|
||||||
if (app) {
|
|
||||||
CORE_LOG_TRACE("Starting User Application");
|
|
||||||
app->Run();
|
|
||||||
delete app;
|
|
||||||
} else {
|
|
||||||
CORE_LOG_FATAL("Could not start User Application");
|
|
||||||
}
|
|
||||||
|
|
||||||
CORE_LOG_TRACE("Shutting down ICEngine");
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,19 +0,0 @@
|
|||||||
//
|
|
||||||
// Created by illyum on 9/15/2024.
|
|
||||||
//
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
namespace ICEngine {
|
|
||||||
class ICEApplication {
|
|
||||||
public:
|
|
||||||
ICEApplication() {}
|
|
||||||
virtual ~ICEApplication() {}
|
|
||||||
virtual void Run() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
void StartApplication(); // Starts the application, managed by the engine.
|
|
||||||
|
|
||||||
// Application-specific function that will be defined by the user
|
|
||||||
extern ICEApplication* CreateICEApplication();
|
|
||||||
}
|
|
@ -7,6 +7,7 @@
|
|||||||
#include <pch.hpp>
|
#include <pch.hpp>
|
||||||
|
|
||||||
namespace ICEngine {
|
namespace ICEngine {
|
||||||
|
|
||||||
enum LogLevel {
|
enum LogLevel {
|
||||||
OFF = 0,
|
OFF = 0,
|
||||||
TRACE,
|
TRACE,
|
||||||
@ -21,10 +22,9 @@ namespace ICEngine {
|
|||||||
private:
|
private:
|
||||||
Logger(const char *name, std::ostream *stream) : name(name) {
|
Logger(const char *name, std::ostream *stream) : name(name) {
|
||||||
if (stream) {
|
if (stream) {
|
||||||
streams.push_back(std::unique_ptr<std::ostream>(stream));
|
streams.push_back(stream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
friend class Log;
|
friend class Log;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -32,27 +32,26 @@ namespace ICEngine {
|
|||||||
this->level = level;
|
this->level = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AddStream(std::unique_ptr<std::ostream> stream) {
|
void AddStream(std::ostream * stream) {
|
||||||
this->streams.push_back(std::move(stream));
|
this->streams.push_back(stream);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename... Args>
|
template<typename... Args>
|
||||||
void Log(LogLevel level, const char *file, int line, const char *func, const std::string &formatStr,
|
void Log(LogLevel level, const char *file, int line, const char *func, const std::string &formatStr, Args &&... args) {
|
||||||
Args &&... args) {
|
|
||||||
// TODO: Create a crash handler and manage fatal messages separately (creates crashdump)
|
// TODO: Create a crash handler and manage fatal messages separately (creates crashdump)
|
||||||
// TODO: Allow user to create their own class that inherits Fatal Handler so they can implement it themselves
|
// TODO: Allow user to create their own class that inherits Fatal Handler so they can implement it themselves
|
||||||
if (level < this->level) return;
|
if (level < this->level) return;
|
||||||
std::string formattedMessage = format(formatStr, std::forward<Args>(args)...);
|
std::string formattedMessage = format(formatStr, std::forward<Args>(args)...);
|
||||||
std::string logMessage = formatMessage(level, file, line, func, formattedMessage);
|
std::string logMessage = formatMessage(level, file, line, func, formattedMessage);
|
||||||
|
|
||||||
for (const auto &stream: streams) {
|
for (auto stream: streams) {
|
||||||
(*stream) << logMessage << std::endl;
|
(*stream) << logMessage << std::endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char *name;
|
const char *name;
|
||||||
std::vector<std::unique_ptr<std::ostream> > streams;
|
std::vector<std::ostream *> streams;
|
||||||
LogLevel level = DEBUG;
|
LogLevel level = DEBUG;
|
||||||
|
|
||||||
static const char *levelToString(LogLevel level) {
|
static const char *levelToString(LogLevel level) {
|
||||||
@ -96,8 +95,7 @@ namespace ICEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
void formatHelper(std::ostringstream &oss, const std::string &formatStr, T &&firstArg,
|
void formatHelper(std::ostringstream &oss, const std::string &formatStr, T &&firstArg, Args&&... remainingArgs) {
|
||||||
Args &&... remainingArgs) {
|
|
||||||
size_t pos = formatStr.find("{}");
|
size_t pos = formatStr.find("{}");
|
||||||
if (pos != std::string::npos) {
|
if (pos != std::string::npos) {
|
||||||
oss << formatStr.substr(0, pos) << std::forward<T>(firstArg);
|
oss << formatStr.substr(0, pos) << std::forward<T>(firstArg);
|
||||||
@ -107,14 +105,13 @@ namespace ICEngine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string formatMessage(LogLevel level, const char *file, int line, const char *func,
|
// Formats the log message with metadata (timestamp, file, line, etc.)
|
||||||
const std::string &message) {
|
std::string formatMessage(LogLevel level, const char *file, int line, const char *func, const std::string &message) {
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << getCurrentTime() << " ";
|
oss << getCurrentTime() << " ";
|
||||||
oss << truncateFilePath(file) << ":" << line << ":" << func << " ";
|
oss << truncateFilePath(file) << ":" << line << ":" << func << " ";
|
||||||
oss << "[" << name << "] ";
|
oss << "[" << levelToString(level) << "] ";
|
||||||
oss << "[" << levelToString(level) << "]: ";
|
oss << "[" << name << "]: " << message;
|
||||||
oss << message;
|
|
||||||
return oss.str();
|
return oss.str();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -122,16 +119,8 @@ namespace ICEngine {
|
|||||||
class Log {
|
class Log {
|
||||||
public:
|
public:
|
||||||
static void Init() {
|
static void Init() {
|
||||||
static bool isInitialized = false;
|
|
||||||
if (isInitialized) {
|
|
||||||
GetCoreLogger()->Log(WARN, __FILE__, __LINE__, __FUNCTION__,
|
|
||||||
"Logger already initialized. Skipping re-initialization.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
GetCoreLogger();
|
GetCoreLogger();
|
||||||
GetAppLogger();
|
GetAppLogger();
|
||||||
|
|
||||||
isInitialized = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::shared_ptr<Logger> &GetCoreLogger() {
|
static std::shared_ptr<Logger> &GetCoreLogger() {
|
||||||
@ -146,9 +135,7 @@ namespace ICEngine {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
Log() = delete;
|
Log() = delete;
|
||||||
|
|
||||||
Log(const Log &) = delete;
|
Log(const Log &) = delete;
|
||||||
|
|
||||||
Log &operator=(const Log &) = delete;
|
Log &operator=(const Log &) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ void ShowLogger();
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
ShowLogger();
|
ShowLogger();
|
||||||
ICEngine::StartApplication();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -35,15 +34,11 @@ void ShowLogger() {
|
|||||||
// You can have multiple log streams, ie console + file etc
|
// You can have multiple log streams, ie console + file etc
|
||||||
// You do not need to have the same streams for each logger
|
// You do not need to have the same streams for each logger
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
// Create file streams and transfer ownership to the logger
|
std::ofstream coreFileStream("core_logs.txt");
|
||||||
// You need to create a unique pointer, because the logger will
|
std::ofstream appFileStream("app_logs.txt");
|
||||||
// take ownership of the streams and clean them up when the app
|
|
||||||
// is complete
|
|
||||||
auto coreFileStream = std::make_unique<std::ofstream>("core_logs.txt");
|
|
||||||
auto appFileStream = std::make_unique<std::ofstream>("app_logs.txt");
|
|
||||||
|
|
||||||
ICEngine::Log::GetCoreLogger()->AddStream(std::move(coreFileStream));
|
ICEngine::Log::GetCoreLogger()->AddStream(&coreFileStream);
|
||||||
ICEngine::Log::GetAppLogger()->AddStream(std::move(appFileStream));
|
ICEngine::Log::GetAppLogger()->AddStream(&appFileStream);
|
||||||
|
|
||||||
// You can log multiple different types with formatting
|
// You can log multiple different types with formatting
|
||||||
int age = 30;
|
int age = 30;
|
||||||
@ -74,14 +69,3 @@ void ShowLogger() {
|
|||||||
// The Fatal Handler provides a mechanism for handling unrecoverable errors gracefully, allowing you to define how the application reacts to fatal crashes
|
// The Fatal Handler provides a mechanism for handling unrecoverable errors gracefully, allowing you to define how the application reacts to fatal crashes
|
||||||
// LOG_FATAL("This is an example of log fatal crash!");
|
// LOG_FATAL("This is an example of log fatal crash!");
|
||||||
}
|
}
|
||||||
|
|
||||||
class DemoApp : public ICEngine::ICEApplication {
|
|
||||||
public:
|
|
||||||
void Run() override {
|
|
||||||
LOG_TRACE("Running demo app!");
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ICEngine::ICEApplication* ICEngine::CreateICEApplication() {
|
|
||||||
return new DemoApp();
|
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user