Compare commits
3 Commits
51de852ab1
...
5e76c8a382
Author | SHA1 | Date | |
---|---|---|---|
5e76c8a382 | |||
91cf0d25d5 | |||
0eebacc28f |
@ -50,6 +50,15 @@ INCLUDE_DIRECTORIES(engine/)
|
|||||||
SET(EngineSources
|
SET(EngineSources
|
||||||
engine/src/core/ICEApplication.cpp
|
engine/src/core/ICEApplication.cpp
|
||||||
)
|
)
|
||||||
|
IF (WIN32)
|
||||||
|
LIST(APPEND EngineSources
|
||||||
|
engine/src/platform/windows/WindowsPopup.cpp
|
||||||
|
)
|
||||||
|
ELSEIF (UNIX)
|
||||||
|
LIST(APPEND EngineSources
|
||||||
|
engine/src/platform/posix/PosixPopup.cpp
|
||||||
|
)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
SET(PrecompiledHeader "pch.h")
|
SET(PrecompiledHeader "pch.h")
|
||||||
|
|
||||||
|
@ -7,5 +7,6 @@
|
|||||||
|
|
||||||
#include "src/core/Logger.hpp"
|
#include "src/core/Logger.hpp"
|
||||||
#include "src/core/ICEApplication.hpp"
|
#include "src/core/ICEApplication.hpp"
|
||||||
|
#include "src/platform/Platform.hpp"
|
||||||
|
|
||||||
#endif //ICENGINE_HPP
|
#endif //ICENGINE_HPP
|
||||||
|
@ -6,9 +6,12 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <csignal>
|
||||||
#include <cstdarg>
|
#include <cstdarg>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <exception>
|
||||||
|
#include <functional>
|
||||||
|
@ -6,6 +6,29 @@
|
|||||||
#include "pch.hpp"
|
#include "pch.hpp"
|
||||||
|
|
||||||
namespace ICEngine {
|
namespace ICEngine {
|
||||||
|
ICEApplication::TerminationHandler ICEApplication::customHandler = ICEApplication::DefaultTerminationHandler;
|
||||||
|
|
||||||
|
void ICEApplication::SetTerminationHandler(TerminationHandler handler) {
|
||||||
|
if (handler) {
|
||||||
|
customHandler = handler;
|
||||||
|
} else {
|
||||||
|
customHandler = DefaultTerminationHandler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ICEApplication::HandleFatalError(const std::string& message) {
|
||||||
|
if (customHandler) {
|
||||||
|
customHandler(message);
|
||||||
|
} else {
|
||||||
|
DefaultTerminationHandler(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ICEApplication::DefaultTerminationHandler(const std::string& message) {
|
||||||
|
Log::GetCoreLogger()->Log(CRITICAL, __FILE__, __LINE__, __FUNCTION__, message);
|
||||||
|
std::exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
void StartApplication() {
|
void StartApplication() {
|
||||||
Log::Init();
|
Log::Init();
|
||||||
CORE_LOG_TRACE("Starting ICEngine");
|
CORE_LOG_TRACE("Starting ICEngine");
|
||||||
|
@ -4,15 +4,28 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <pch.hpp>
|
||||||
|
#include "Logger.hpp"
|
||||||
|
|
||||||
namespace ICEngine {
|
namespace ICEngine {
|
||||||
class ICEApplication {
|
class ICEApplication {
|
||||||
public:
|
public:
|
||||||
ICEApplication() {}
|
ICEApplication() {}
|
||||||
virtual ~ICEApplication() {}
|
virtual ~ICEApplication() {}
|
||||||
|
|
||||||
virtual void Run() = 0;
|
virtual void Run() = 0;
|
||||||
|
|
||||||
|
using TerminationHandler = std::function<void(const std::string&)>;
|
||||||
|
|
||||||
|
static void SetTerminationHandler(TerminationHandler handler);
|
||||||
|
static void HandleFatalError(const std::string& message);
|
||||||
|
|
||||||
|
private:
|
||||||
|
static TerminationHandler customHandler;
|
||||||
|
static void DefaultTerminationHandler(const std::string& message);
|
||||||
};
|
};
|
||||||
|
|
||||||
void StartApplication(); // Starts the application, managed by the engine.
|
void StartApplication();
|
||||||
|
|
||||||
// Application-specific function that will be defined by the user
|
// Application-specific function that will be defined by the user
|
||||||
extern ICEApplication* CreateICEApplication();
|
extern ICEApplication* CreateICEApplication();
|
||||||
|
@ -174,33 +174,41 @@ namespace ICEngine {
|
|||||||
Log &operator=(const Log &) = delete;
|
Log &operator=(const Log &) = delete;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define CORE_LOG_FATAL(message) \
|
||||||
|
do { \
|
||||||
|
ICEngine::Log::GetCoreLogger()->Log(ICEngine::FATAL, __FILE__, __LINE__, __FUNCTION__, message); \
|
||||||
|
ICEngine::ICEApplication::HandleFatalError(message); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define LOG_FATAL(message) \
|
||||||
|
do { \
|
||||||
|
ICEngine::Log::GetAppLogger()->Log(ICEngine::FATAL, __FILE__, __LINE__, __FUNCTION__, message); \
|
||||||
|
ICEngine::ICEApplication::HandleFatalError(message); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#define CORE_LOG_TRACE(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::TRACE, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
#define CORE_LOG_TRACE(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::TRACE, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
||||||
#define CORE_LOG_DEBUG(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::DEBUG, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
#define CORE_LOG_DEBUG(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::DEBUG, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
||||||
#define CORE_LOG_WARN(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::WARN, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
#define CORE_LOG_WARN(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::WARN, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
||||||
#define CORE_LOG_ERROR(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::ERROR, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
#define CORE_LOG_ERROR(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::ERROR, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
||||||
#define CORE_LOG_CRITICAL(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::CRITICAL, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
#define CORE_LOG_CRITICAL(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::CRITICAL, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
||||||
#define CORE_LOG_FATAL(message, ...) ICEngine::Log::GetCoreLogger()->Log(ICEngine::FATAL, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
|
||||||
|
|
||||||
#define LOG_TRACE(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::TRACE, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
#define LOG_TRACE(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::TRACE, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
||||||
#define LOG_DEBUG(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::DEBUG, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
#define LOG_DEBUG(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::DEBUG, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
||||||
#define LOG_WARN(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::WARN, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
#define LOG_WARN(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::WARN, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
||||||
#define LOG_ERROR(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::ERROR, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
#define LOG_ERROR(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::ERROR, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
||||||
#define LOG_CRITICAL(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::CRITICAL, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
#define LOG_CRITICAL(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::CRITICAL, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
||||||
#define LOG_FATAL(message, ...) ICEngine::Log::GetAppLogger()->Log(ICEngine::FATAL, __FILE__, __LINE__, __FUNCTION__, message, ##__VA_ARGS__)
|
|
||||||
#else
|
#else
|
||||||
#define CORE_LOG_TRACE(message, ...)
|
#define CORE_LOG_TRACE(message, ...)
|
||||||
#define CORE_LOG_DEBUG(message, ...)
|
#define CORE_LOG_DEBUG(message, ...)
|
||||||
#define CORE_LOG_WARN(message, ...)
|
#define CORE_LOG_WARN(message, ...)
|
||||||
#define CORE_LOG_ERROR(message, ...)
|
#define CORE_LOG_ERROR(message, ...)
|
||||||
#define CORE_LOG_CRITICAL(message, ...)
|
#define CORE_LOG_CRITICAL(message, ...)
|
||||||
#define CORE_LOG_FATAL(message, ...)
|
|
||||||
|
|
||||||
#define LOG_TRACE(message, ...)
|
#define LOG_TRACE(message, ...)
|
||||||
#define LOG_DEBUG(message, ...)
|
#define LOG_DEBUG(message, ...)
|
||||||
#define LOG_WARN(message, ...)
|
#define LOG_WARN(message, ...)
|
||||||
#define LOG_ERROR(message, ...)
|
#define LOG_ERROR(message, ...)
|
||||||
#define LOG_CRITICAL(message, ...)
|
#define LOG_CRITICAL(message, ...)
|
||||||
#define LOG_FATAL(message, ...)
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
14
engine/src/platform/Platform.hpp
Normal file
14
engine/src/platform/Platform.hpp
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
//
|
||||||
|
// Created by illyum on 9/20/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <pch.hpp>
|
||||||
|
|
||||||
|
namespace Platform {
|
||||||
|
void ShowPopup(const char *message);
|
||||||
|
void ShowPopup(const char *title, const char *message);
|
||||||
|
void ShowPopup(const std::string &message);
|
||||||
|
void ShowPopup(const std::string &title, const std::string &message);
|
||||||
|
}
|
17
engine/src/platform/posix/PosixPopup.cpp
Normal file
17
engine/src/platform/posix/PosixPopup.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
//
|
||||||
|
// Created by illyum on 9/20/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "../Platform.hpp"
|
||||||
|
#include <pch.hpp>
|
||||||
|
|
||||||
|
namespace Platform {
|
||||||
|
|
||||||
|
void ShowPopup(const char* message) {
|
||||||
|
std::string command = "zenity --info --text=\"";
|
||||||
|
command += message;
|
||||||
|
command += "\"";
|
||||||
|
system(command.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
25
engine/src/platform/windows/WindowsPopup.cpp
Normal file
25
engine/src/platform/windows/WindowsPopup.cpp
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
//
|
||||||
|
// Created by illyum on 9/20/2024.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include <pch.hpp>
|
||||||
|
#include "../Platform.hpp"
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
namespace Platform {
|
||||||
|
void ShowPopup(const char *message) {
|
||||||
|
MessageBoxA(nullptr, message, "ICEngine", MB_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowPopup(const char *title, const char *message) {
|
||||||
|
MessageBoxA(nullptr, message, title, MB_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowPopup(const std::string &message) {
|
||||||
|
MessageBoxA(nullptr, message.c_str(), "ICEngine", MB_OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ShowPopup(const std::string &title, const std::string &message) {
|
||||||
|
MessageBoxA(nullptr, message.c_str(), title.c_str(), MB_OK);
|
||||||
|
}
|
||||||
|
}
|
@ -4,20 +4,21 @@
|
|||||||
|
|
||||||
#include <ICEngine.hpp>
|
#include <ICEngine.hpp>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <src/platform/Platform.hpp>
|
||||||
|
|
||||||
void ShowLogger();
|
void ShowLogger();
|
||||||
|
void CustomTermHandler(const std::string& message);
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
try {
|
// You can set a custom termination handler/function.
|
||||||
ShowLogger();
|
// Make sure you do this before you start the application!!!
|
||||||
ICEngine::StartApplication();
|
ICEngine::ICEApplication::SetTerminationHandler(CustomTermHandler);
|
||||||
} catch (const std::exception& e) {
|
// This is optional
|
||||||
CORE_LOG_FATAL("Unhandled exception: {}", e.what());
|
|
||||||
return -1;
|
// Logger Information
|
||||||
} catch (...) {
|
ShowLogger();
|
||||||
CORE_LOG_FATAL("Unknown fatal error occurred.");
|
|
||||||
return -1;
|
ICEngine::StartApplication();
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,7 +50,10 @@ void ShowLogger() {
|
|||||||
// take ownership of the streams and clean them up when the app
|
// take ownership of the streams and clean them up when the app
|
||||||
// is complete
|
// is complete
|
||||||
ICEngine::Log::GetCoreLogger()->AddSink(std::make_shared<ICEngine::FileSink>("core_logs.txt"));
|
ICEngine::Log::GetCoreLogger()->AddSink(std::make_shared<ICEngine::FileSink>("core_logs.txt"));
|
||||||
|
ICEngine::Log::GetCoreLogger()->AddSink(std::make_shared<ICEngine::ConsoleSink>());
|
||||||
|
|
||||||
ICEngine::Log::GetAppLogger()->AddSink(std::make_shared<ICEngine::FileSink>("app_logs.txt"));
|
ICEngine::Log::GetAppLogger()->AddSink(std::make_shared<ICEngine::FileSink>("app_logs.txt"));
|
||||||
|
ICEngine::Log::GetAppLogger()->AddSink(std::make_shared<ICEngine::ConsoleSink>());
|
||||||
|
|
||||||
// You can log multiple different types with formatting
|
// You can log multiple different types with formatting
|
||||||
int age = 30;
|
int age = 30;
|
||||||
@ -62,7 +66,7 @@ void ShowLogger() {
|
|||||||
CORE_LOG_DEBUG("This is an example of a debug message"); // Logs a debug message, typically used for debugging purposes
|
CORE_LOG_DEBUG("This is an example of a debug message"); // Logs a debug message, typically used for debugging purposes
|
||||||
CORE_LOG_WARN("This is an example of a warn message"); // Logs a warning, indicating a non-critical issue that should be investigated
|
CORE_LOG_WARN("This is an example of a warn message"); // Logs a warning, indicating a non-critical issue that should be investigated
|
||||||
CORE_LOG_ERROR("This is an example of an error message"); // Logs an error, signaling that something has gone wrong but the engine can still run
|
CORE_LOG_ERROR("This is an example of an error message"); // Logs an error, signaling that something has gone wrong but the engine can still run
|
||||||
CORE_LOG_CRITICAL("This is an example of a critical message\n"); // Logs a critical issue, often indicating a major problem in the core system that needs immediate attention.
|
CORE_LOG_CRITICAL("This is an example of a critical message"); // Logs a critical issue, often indicating a major problem in the core system that needs immediate attention.
|
||||||
// CORE_LOG_FATAL: Logs a fatal error that crashes the application. Fatal errors in the core usually lead to dumping information into crash logs
|
// CORE_LOG_FATAL: Logs a fatal error that crashes the application. Fatal errors in the core usually lead to dumping information into crash logs
|
||||||
// and stopping the program. Use with extreme caution and only in situations where the application can't recover
|
// and stopping the program. Use with extreme caution and only in situations where the application can't recover
|
||||||
// CORE_LOG_FATAL("This is an example of a fatal message");
|
// CORE_LOG_FATAL("This is an example of a fatal message");
|
||||||
@ -81,10 +85,21 @@ void ShowLogger() {
|
|||||||
// LOG_FATAL("This is an example of log fatal crash!");
|
// LOG_FATAL("This is an example of log fatal crash!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CustomTermHandler(const std::string& message) {
|
||||||
|
// Perform any other task here, like showing a popup warning indicating something crashed
|
||||||
|
Platform::ShowPopup("Demo App", message);
|
||||||
|
// You don't have to specify a title, it will default to ICEngine
|
||||||
|
// Platform::ShowPopup(message);
|
||||||
|
std::exit(EXIT_FAILURE); // Terminate here if you need to
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class DemoApp : public ICEngine::ICEApplication {
|
class DemoApp : public ICEngine::ICEApplication {
|
||||||
public:
|
public:
|
||||||
void Run() override {
|
void Run() override {
|
||||||
LOG_TRACE("Running demo app!");
|
LOG_TRACE("Running demo app!");
|
||||||
|
CORE_LOG_FATAL("Fatal error"); // This will terminate the application
|
||||||
|
LOG_TRACE("Demo app completed successfully!"); // Therefore this will not run
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user