|
|
|
|
@ -9,8 +9,12 @@
|
|
|
|
|
#include "core.h"
|
|
|
|
|
#include "version.h"
|
|
|
|
|
|
|
|
|
|
// Run modes
|
|
|
|
|
#include <tester/tester.h>
|
|
|
|
|
|
|
|
|
|
// Sub Systems
|
|
|
|
|
#include <window/window.h>
|
|
|
|
|
#include <graphics/image.h>
|
|
|
|
|
#include <graphics/opengl/glGraphics.h>
|
|
|
|
|
#include <graphics/gui/gui.h>
|
|
|
|
|
#include <graphics/gui/logGui.h>
|
|
|
|
|
@ -20,7 +24,7 @@ namespace lunarium
|
|
|
|
|
Core* Core::mpInstance = nullptr;
|
|
|
|
|
Core::Core()
|
|
|
|
|
: mbIsInit(false), mpArgs(nullptr), mpWindow(nullptr), mpGraphics(nullptr), mpInput(nullptr),
|
|
|
|
|
mGUI(GUI::GetInstance())
|
|
|
|
|
mGUI(GUI::GetInstance()), mbMidRender(false), mbMidTextureRender(false), mpRunMode(nullptr)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
@ -35,6 +39,9 @@ namespace lunarium
|
|
|
|
|
return *mpInstance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
// SHUTDOWN
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
void Core::Shutdown()
|
|
|
|
|
{
|
|
|
|
|
if (!mpInstance)
|
|
|
|
|
@ -42,6 +49,7 @@ namespace lunarium
|
|
|
|
|
|
|
|
|
|
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Lunarium is shutting down!");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Shutdown subsystems
|
|
|
|
|
LogGui::FreeInstance();
|
|
|
|
|
GUI::GetInstance().Shutdown();
|
|
|
|
|
@ -62,12 +70,19 @@ namespace lunarium
|
|
|
|
|
delete mpInstance->mpArgs;
|
|
|
|
|
mpInstance->mpArgs = nullptr;
|
|
|
|
|
|
|
|
|
|
mpInstance->mpRunMode->Shutdown();
|
|
|
|
|
delete mpInstance->mpRunMode;
|
|
|
|
|
mpInstance->mpRunMode = nullptr;
|
|
|
|
|
|
|
|
|
|
mpInstance->mbIsInit = false;
|
|
|
|
|
delete mpInstance;
|
|
|
|
|
mpInstance = nullptr;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
// INITIALIZATION
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
void Core::Initialize(int argc, char** argv)
|
|
|
|
|
{
|
|
|
|
|
// Setup the log system
|
|
|
|
|
@ -107,6 +122,23 @@ namespace lunarium
|
|
|
|
|
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Loaded state file: lunarium_state.xml");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// RUN MODE
|
|
|
|
|
const char* types[] = { "game", "editor", "test"};
|
|
|
|
|
Logger::Log(LogCategory::CORE, LogLevel::INFO, "Running in mode: %s", types[mState.Mode]);
|
|
|
|
|
if (RunMode::MODE_TEST == mState.Mode)
|
|
|
|
|
{
|
|
|
|
|
mpRunMode = new Tester;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Initialize the Run Mode
|
|
|
|
|
result = mpRunMode->Initialize();
|
|
|
|
|
if (Failed(result))
|
|
|
|
|
{
|
|
|
|
|
Logger::Log(LogCategory::CORE, LogLevel::FATAL_ERROR,
|
|
|
|
|
"Could not initialize the Run Mode: %s", result.Description);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Parse command line args -- None right now
|
|
|
|
|
std::vector<Args::SwitchDesc> sd;
|
|
|
|
|
mpArgs = new Args(argc, argv, '-', sd);
|
|
|
|
|
@ -180,9 +212,11 @@ namespace lunarium
|
|
|
|
|
return mState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
// GAME LOOP
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
|
|
|
void Core::RunGameLoop()
|
|
|
|
|
{
|
|
|
|
|
//glfwSetInputMode(mpWindow->GetWindow(), GLFW_STICKY_KEYS, GLFW_TRUE);
|
|
|
|
|
mFrameCounter.Reset();
|
|
|
|
|
|
|
|
|
|
// TODO: Init frame counter
|
|
|
|
|
@ -211,42 +245,57 @@ namespace lunarium
|
|
|
|
|
LogGui::GetInstance().SetShow(!LogGui::GetInstance().IsShown());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DEBUG: Graphics testing
|
|
|
|
|
static int width = 500;
|
|
|
|
|
if (mpInput->IsKeyDown(KeyCode::LEFT))
|
|
|
|
|
{
|
|
|
|
|
width -= 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mpInput->IsKeyDown(KeyCode::RIGHT))
|
|
|
|
|
{
|
|
|
|
|
width += 10;
|
|
|
|
|
}
|
|
|
|
|
// TODO: Send input events
|
|
|
|
|
|
|
|
|
|
// Update game state
|
|
|
|
|
|
|
|
|
|
mpGraphics->BeginDraw(RenderTarget::RT_IMAGE);
|
|
|
|
|
// Update game state
|
|
|
|
|
mpRunMode->OnTick(mFrameCounter.GetFrameData().LastFrameTime);
|
|
|
|
|
|
|
|
|
|
// DEBUG: Graphics tests
|
|
|
|
|
mpGraphics->DrawFilledEllipse(glm::vec2(600, 300), glm::vec2(100, 150), Color(1.0f, 0.0f, 1.0f, 1.0f), 100);
|
|
|
|
|
mpGraphics->DrawString("This is a test of the text renderer!", Rectangle(100, 200, width, 300),
|
|
|
|
|
Color(0.0f, 1.0f, 1.0f, 1.0f), 0.5f, mpGraphics->DefaultFont());
|
|
|
|
|
Image* pImage = mpGraphics->EndDraw();
|
|
|
|
|
|
|
|
|
|
// Render
|
|
|
|
|
if (mbMidTextureRender)
|
|
|
|
|
{
|
|
|
|
|
Logger::Log(LogCategory::CORE, LogLevel::WARNING, "Render to texture was not ended!");
|
|
|
|
|
EndRenderToTexture();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mGUI.NewFrame();
|
|
|
|
|
mpGraphics->BeginDraw();
|
|
|
|
|
mbMidRender = true;
|
|
|
|
|
|
|
|
|
|
// DEBUG: Render test ImGUI window
|
|
|
|
|
// mGUI.ShowDemoWindow();
|
|
|
|
|
LogGui::GetInstance().Show();
|
|
|
|
|
|
|
|
|
|
mpGraphics->DrawImage(*pImage, glm::vec2(0.0f, 0.0f), Color(1.0f, 1.0f, 1.0f, 1.0f));
|
|
|
|
|
mpRunMode->OnRender();
|
|
|
|
|
|
|
|
|
|
mGUI.EndFrame();
|
|
|
|
|
mpGraphics->EndDraw();
|
|
|
|
|
mbMidRender = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// delete pImage;
|
|
|
|
|
OpRes Core::BeginRenderToTexture()
|
|
|
|
|
{
|
|
|
|
|
if (mbMidRender)
|
|
|
|
|
{
|
|
|
|
|
return OpRes::Fail("Can not switch render targets in the middle of rendering");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mbMidTextureRender = true;
|
|
|
|
|
mpGraphics->BeginDraw(RenderTarget::RT_IMAGE);
|
|
|
|
|
return OpRes::OK();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Image* Core::EndRenderToTexture()
|
|
|
|
|
{
|
|
|
|
|
if (!mbMidTextureRender)
|
|
|
|
|
{
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mbMidTextureRender = false;
|
|
|
|
|
return mpGraphics->EndDraw();
|
|
|
|
|
}
|
|
|
|
|
}
|