You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
lunarium_OLD/src/core/core.cpp

93 lines
2.5 KiB
C++

/******************************************************************************
* File - core.cpp
* Author - Joey Pollack
* Date - 2021/08/30 (y/m/d)
* Mod Date - 2021/08/30 (y/m/d)
* Description - The Core Engine Class. Manages the engine components.
******************************************************************************/
#include "core.h"
#include "Version.h"
namespace lunarium
{
Core* Core::mpInstance = nullptr;
Core::Core()
: mbIsInit(false), mpArgs(nullptr)
{
}
Core& Core::GetInstance()
{
if (!mpInstance)
{
mpInstance = new Core;
}
return *mpInstance;
}
void Core::Shutdown()
{
if (!mpInstance)
return;
// Shutdown subsystems
delete mpInstance->mpArgs;
mpInstance->mpArgs = nullptr;
delete mpInstance;
mpInstance = nullptr;
}
void Core::Initialize(int argc, char** argv, std::vector<LogListener*>& listeners)
{
// Setup the log system and add any listeners
mpLog = Logger::GetInstance();
mMasterLogFile.open("Element2D_Master.log", std::ios_base::app);
mMasterLogFile << "\n\n";
mErrorLogFile.open("Element2D_Errors.log", std::ios_base::app);
mErrorLogFile << "\n\n";
if (mMasterLogFile.is_open())
mpLog->AddListener(new FileListener(mMasterLogFile));
if (mErrorLogFile.is_open())
mpLog->AddListener(new FileListener(mErrorLogFile, LogLevel::ERROR | LogLevel::FATAL_ERROR));
for (unsigned i = 0; i < listeners.size(); i++)
{
mpLog->AddListener(listeners[i]);
}
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Running Lunarium version %s", Version::GetVersion().ToString().c_str());
// Attempt to load the engine state file. This file should be placed in the same directory as the lunarium program.
mpLog->Log(LogCategory::CORE, LogLevel::INFO, "Attempting to load state file: lunarium_state.xml");
if (Failed(State::CreateFromFile("lunarium_state.xml", mState)))
{
Logger::Log(LogCategory::CORE, LogLevel::WARNING, "Unable to load state file: lunarium_state.xml. Loading default state.");
mState = State::CreateDefault();
}
// Parse command line args -- None right now
std::vector<Args::SwitchDesc> sd;
mpArgs = new Args(argc, argv, '-', sd);
}
bool Core::IsInit() const
{
return mbIsInit;
}
const State& Core::GetState() const
{
return mState;
}
}