2024-09-15 01:37:29 -06:00
//
// Created by illyum on 9/15/2024.
//
2024-09-15 02:31:13 -06:00
# include <ICEngine.hpp>
2024-09-15 04:33:23 -06:00
# include <fstream>
2024-09-20 10:45:08 -06:00
# include <src/platform/Platform.hpp>
2024-09-15 04:33:23 -06:00
void ShowLogger ( ) ;
2024-09-20 11:08:49 -06:00
void CustomTermHandler ( const std : : string & message ) ;
2024-09-15 01:37:29 -06:00
int main ( ) {
2024-09-20 10:45:08 -06:00
// You can set a custom termination handler/function.
// Make sure you do this before you start the application!!!
ICEngine : : ICEApplication : : SetTerminationHandler ( CustomTermHandler ) ;
// This is optional
// Logger Information
ShowLogger ( ) ;
ICEngine : : StartApplication ( ) ;
2024-09-15 04:33:23 -06:00
return 0 ;
}
2024-09-20 04:53:33 -06:00
2024-09-15 04:33:23 -06:00
void ShowLogger ( ) {
// The logger needs to be initialized before you can use it.
// This will be done by the engine, NEVER the user.
ICEngine : : Log : : Init ( ) ;
// Before using the logger macros, you may want to configure logging options such as log levels and output streams.
// By default, the logger outputs to std::cout, but you can add more streams (e.g., files) or set the log level as needed.
// Logging Levels:
// - OFF
// - TRACE
// - DEBUG
// - WARN
// - ERROR
// - CRITICAL
// - FATAL
ICEngine : : Log : : GetCoreLogger ( ) - > SetLevel ( ICEngine : : TRACE ) ;
ICEngine : : Log : : GetAppLogger ( ) - > SetLevel ( ICEngine : : TRACE ) ;
// You can have multiple log streams, ie console + file etc
// You do not need to have the same streams for each logger
2024-09-20 11:08:49 -06:00
# include <fstream>
2024-09-16 23:28:09 -06:00
// Create file streams and transfer ownership to the logger
// You need to create a unique pointer, because the logger will
// take ownership of the streams and clean them up when the app
// is complete
2024-09-20 04:53:33 -06:00
ICEngine : : Log : : GetCoreLogger ( ) - > AddSink ( std : : make_shared < ICEngine : : FileSink > ( " core_logs.txt " ) ) ;
2024-09-20 10:45:08 -06:00
ICEngine : : Log : : GetCoreLogger ( ) - > AddSink ( std : : make_shared < ICEngine : : ConsoleSink > ( ) ) ;
2024-09-20 11:08:49 -06:00
2024-09-20 04:53:33 -06:00
ICEngine : : Log : : GetAppLogger ( ) - > AddSink ( std : : make_shared < ICEngine : : FileSink > ( " app_logs.txt " ) ) ;
2024-09-20 10:45:08 -06:00
ICEngine : : Log : : GetAppLogger ( ) - > AddSink ( std : : make_shared < ICEngine : : ConsoleSink > ( ) ) ;
2024-09-15 04:33:23 -06:00
// You can log multiple different types with formatting
int age = 30 ;
std : : string module = " Network " ;
// CORE logger is intended for internal engine or core-level logging
// In most cases, you won't need to use CORE logging in game/application code,
2024-09-15 04:37:03 -06:00
// but it's available for engine-level diagnostics if necessary
2024-09-20 11:08:49 -06:00
CORE_LOG_TRACE ( " Initializing {} with age {} " , module , age ) ;
// Logs a trace-level message, useful for very detailed information
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_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 " ) ;
// Logs a critical issue, often indicating a major problem in the core system that needs immediate attention.
2024-09-15 04:33:23 -06:00
// 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
// CORE_LOG_FATAL("This is an example of a fatal message");
// These macros are designed for logging from your game or application code
// They allow you to monitor application flow, errors, and warnings from the perspective of the game logic or app layer
2024-09-20 11:08:49 -06:00
LOG_TRACE ( " App took longer to respond than expected: {} seconds " , 2.34 ) ;
// Logs a trace message, ideal for fine-grained, verbose debugging details
LOG_DEBUG ( " This is an example of a debug message " ) ;
// Logs a debug message, typically used to help trace the execution during development
LOG_WARN ( " This is an example of a warn message " ) ;
// Logs a warning, indicating something unexpected happened, but the application can continue running
LOG_ERROR ( " This is an example of an error message " ) ;
// Logs an error, signaling that an issue occurred that may require attention but is not catastrophic
LOG_CRITICAL ( " This is an example of a critical message " ) ;
// Logs a critical message, suggesting something very wrong happened, but the program may still attempt to run
2024-09-15 04:33:23 -06:00
// LOG_FATAL: Logs a fatal error in the application layer. This will trigger the Fatal Handler, which you can override
// 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!");
2024-09-16 23:28:09 -06:00
}
2024-09-20 11:08:49 -06:00
void CustomTermHandler ( const std : : string & message ) {
2024-09-20 10:45:08 -06:00
// 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
}
2024-09-16 23:28:09 -06:00
class DemoApp : public ICEngine : : ICEApplication {
public :
void Run ( ) override {
LOG_TRACE ( " Running demo app! " ) ;
2024-09-20 10:45:08 -06:00
CORE_LOG_FATAL ( " Fatal error " ) ; // This will terminate the application
LOG_TRACE ( " Demo app completed successfully! " ) ; // Therefore this will not run
2024-09-16 23:28:09 -06:00
}
} ;
2024-09-20 11:08:49 -06:00
ICEngine : : ICEApplication * ICEngine : : CreateICEApplication ( ) {
2024-09-16 23:28:09 -06:00
return new DemoApp ( ) ;
}