CyberEngineMkIII
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
CYBCore.cpp
Go to the documentation of this file.
1 
3 #include "CYB.hpp"
4 
5 //The engine has several components it needs to start before even thinking about the initial unit
6 
7 /*
8  . Memory Pools: It needs 2 to start
9  The main engine heap
10  The logger heap
11  . Activate the logger
12  . Create the core and have it parse the command line. Wrap it with error processing
13  . Lock the engine heap and call into the unit to retrieve the function pointers
14  . Activate Steam DRM
15  . Lock the mutex if necessary
16  . Start the ThreadPool
17  . Set the engine language
18  . Activate the console
19  . Replace our icon with the unit's
20  . Activate the unit's memory pool
21 
22 */
23 
25 thread_local unsigned long long CYB::Engine::Core::FThreadID(0);
26 
27 CYB::Engine::Core::Core(const unsigned int ANumArguments, const oschar_t* const* const AArguments) :
28  Singleton<Core>(true),
29  FEngineInformation(Parameters::CreateEngineInformation()),
30  FThreadCounter(0),
31  FLogger(FConsole),
32  FHeap(Parameters::ENGINE_HEAP_INITIAL_COMMIT_SIZE),
33  FEngineContext(FHeap, FLogger, true),
34  FCommandLine(ANumArguments, AArguments)
35 {
37  static_cast<void>(ANumArguments);
38  static_cast<void>(AArguments);
39 }
40 
42  FLogger.Log(API::String::Static(u8"Core shutdown"), Logger::Level::DEV);
43 }
44 
46  return *FSingleton;
47 }
48 
49 void CYB::Engine::Core::Run(const unsigned int ANumArguments, const oschar_t* const* const AArguments) noexcept {
50  try {
51  Core CyberEngineMarkIII(ANumArguments, AArguments);
52  }
53  catch (...) {}
55 }
56 
58  return *FCurrentContext;
59 }
60 
61 void CYB::Engine::Core::SetCurrentContext(Context& ANewContext) noexcept {
62  FCurrentContext = &ANewContext;
63 }
64 
65 void CYB::Engine::Core::DefaultContext(void) noexcept {
66  FEngineContext.MakeCurrent();
67 }
68 
69 CYB::Engine::Core& CYB::Core(void) noexcept {
70  return Engine::Core::GetCore();
71 }
72 
73 unsigned long long CYB::Engine::Core::ThreadID(void) noexcept {
74  if (FThreadID == 0)
75  FThreadID = FThreadCounter.fetch_add(1, std::memory_order_relaxed) + 1;
76  return FThreadID;
77 }
Core(const unsigned int ANumArguments, const oschar_t *const *const AArguments)
Constructs the engine components.
Definition: CYBCore.cpp:27
Context & CurrentContext(void) noexcept
Get the current Context.
Definition: CYBCore.cpp:57
An instance of this object is the entirety of the engine.
Definition: CYBCore.hpp:11
static Process GetSelf(void) noexcept
Get's the Process representing the current execution.
Definition: CYBProcess.cpp:12
void Terminate(void)
Terminates the Process with exit code 0.
Logger FLogger
The engine's primary Logger.
Definition: CYBCore.hpp:26
A string pointing to unchanging data in the stack above it or the data segment. Must have UTF-8 encod...
Definition: StaticString.hpp:7
void DefaultContext(void) noexcept
Set the current Context to FEngineContext.
Definition: CYBCore.cpp:65
void SetCurrentContext(Context &ANewContext) noexcept
Set the current Context.
Definition: CYBCore.cpp:61
Compilation configuration variables.
static thread_local unsigned long long FThreadID
ID of the checking thread.
Definition: CYBCore.hpp:15
~Core()
Cleans up the engine and terminates the process.
Definition: CYBCore.cpp:41
void Log(const API::String::CStyle &AMessage, const Level ALevel) finaloverride
Log a message. Will be written to a text file on the Path returned by CurrentLog. ...
Definition: CYBLogger.cpp:197
Implements the engine level functions for API::Interop::Contexts.
Definition: CYBInterop.hpp:41
Precompiled header for inter-engine operations.
A class for creating static singletons.
Definition: Singleton.hpp:10
Engine::Core & Core(void) noexcept
Retrieve the Core singleton.
Definition: CYBCore.cpp:69
unsigned long long ThreadID(void) noexcept
Possibly assign and return the current thread's serial ID for this execution.
Definition: CYBCore.cpp:73
static void Run(const unsigned int ANumArguments, const oschar_t *const *const AArguments) noexcept
Runs the engine and self terminates.
Definition: CYBCore.cpp:49
static Core & GetCore(void) noexcept
Retrieve the Core singleton.
Definition: CYBCore.cpp:45
Debug messages, enabled/disabled by default in engine debug/release builds respectively.
static thread_local Context * FCurrentContext
The current Context in use.
Definition: CYBCore.hpp:14