Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
engineMain.cpp
Go to the documentation of this file.
1
2
3#include "config.h"
4
5#include "engineMain.h"
6
9
10namespace Divide {
11
12ErrorCode Engine::init(const int argc, char** argv)
13{
14 _app = std::make_unique<Application>();
16
17 // Start our application based on XML configuration.
18 // If it fails to start, it should automatically clear up all of its data
19 const ErrorCode errorCode = _app->start("config.xml", argc, argv);
20
21 if ( errorCode != ErrorCode::NO_ERR)
22 {
23 // If any error occurred, close the application as details should already be logged
24 Console::errorfn(LOCALE_STR("GENERIC_ERROR"), TypeUtil::ErrorCodeToString( errorCode ) );
25 }
26
27 return errorCode;
28}
29
30ErrorCode Engine::run(const int argc, char** argv)
31{
32 ErrorCode errorCode = PlatformInit( argc, argv );
33 if ( errorCode != ErrorCode::NO_ERR)
34 {
35 return errorCode;
36 }
37
38
39 //Win32: SetProcessDpiAwareness
41
42 // Read language table
43 errorCode = Locale::Init();
44 if ( errorCode == ErrorCode::NO_ERR )
45 {
47
49
50 U64 restartCount = 0u;
51 do
52 {
53 U64 stepCount = 0u;
54
55 const auto startTime = std::chrono::high_resolution_clock::now();
56
57 // Start the engine
58 errorCode = init( argc, argv );
59 if (errorCode == ErrorCode::NO_ERR)
60 {
61 // Step the entire application
62 while ( (result = _app->step()) == AppStepResult::OK )
63 {
64 ++stepCount;
65 }
66 }
67
69 _app->stop(result);
70 _app.reset();
71
72 Console::printfn("Engine shutdown request : {}\nDivide engine shutdown after {} engine steps and {} restart(s). Total time: {} seconds.",
74 stepCount,
75 restartCount,
76 std::chrono::duration_cast<std::chrono::seconds>(std::chrono::high_resolution_clock::now() - startTime).count());
77
78 ++restartCount;
79
80 } while (errorCode == ErrorCode::NO_ERR && (result == AppStepResult::RESTART || result == AppStepResult::RESTART_CLEAR_CACHE));
81
83 }
84
85 if ( !PlatformClose() )
86 {
88 }
89
90 return errorCode;
91}
92
93}
#define LOCALE_STR(X)
Definition: Localization.h:91
char * argv[]
Definition: main.cpp:8
ErrorCode Init(const char *newLanguage=DEFAULT_LANG)
Reset everything and load the specified language file.
void Clear() noexcept
clear the language table
void RegisterApp(Application *app)
Definition: Profiler.cpp:37
void Initialise()
Definition: Profiler.cpp:42
const char * ErrorCodeToString(const ErrorCode err) noexcept
Definition: ErrorCodes.h:122
const char * AppStepResultToString(const AppStepResult err) noexcept
Definition: Application.h:89
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
AppStepResult
Definition: Application.h:61
void EnforceDPIScaling() noexcept
ErrorCode PlatformInit(int argc, char **argv)
bool PlatformClose()
uint64_t U64
static NO_INLINE void errorfn(const char *format, T &&... args)
static NO_INLINE void printfn(const char *format, T &&... args)
ErrorCode run(const int argc, char **argv)
Definition: engineMain.cpp:30
ErrorCode init(int argc, char **argv)
Definition: engineMain.cpp:12
Application_uptr _app
Definition: engineMain.h:46