summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-12-31 01:25:48 +0100
committerAki <please@ignore.pl>2022-12-31 01:25:48 +0100
commit69887f68697fdd4a7e844677155d80e364a2630e (patch)
treed4f2df0b40994086a6b21716dc97792cc50ddefc
parentd5fe107a5cb9a025eeb64a7637134c2c2dfd939c (diff)
downloadkurator-69887f68697fdd4a7e844677155d80e364a2630e.zip
kurator-69887f68697fdd4a7e844677155d80e364a2630e.tar.gz
kurator-69887f68697fdd4a7e844677155d80e364a2630e.tar.bz2
Extracted drawable sub-scene holder to a Frame class
-rw-r--r--kurator/CMakeLists.txt1
-rw-r--r--kurator/src/ScenarioEditor.cpp43
-rw-r--r--kurator/src/ScenarioEditor.h8
-rw-r--r--kurator/src/SceneFrame.cpp73
-rw-r--r--kurator/src/SceneFrame.h29
5 files changed, 116 insertions, 38 deletions
diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt
index 989ab6f..c91d507 100644
--- a/kurator/CMakeLists.txt
+++ b/kurator/CMakeLists.txt
@@ -9,6 +9,7 @@ add_executable(
src/main.cpp
src/ScenarioEditor.cpp
src/SceneBuilder.cpp
+ src/SceneFrame.cpp
src/Session.cpp
src/Skybox.cpp
src/Summary.cpp
diff --git a/kurator/src/ScenarioEditor.cpp b/kurator/src/ScenarioEditor.cpp
index 7025b49..45e594f 100644
--- a/kurator/src/ScenarioEditor.cpp
+++ b/kurator/src/ScenarioEditor.cpp
@@ -19,30 +19,20 @@ namespace kurator
ScenarioEditor::ScenarioEditor(std::shared_ptr<Session> _session) :
session {std::move(_session)},
- buffer {LoadRenderTexture(GetScreenWidth(), GetScreenHeight())},
teams {2},
anvils {3},
warbringers {2},
eclipses {3},
- distance {12000},
- battle {generate()}
+ distance {12000}
{
-}
-
-
-ScenarioEditor::~ScenarioEditor()
-{
- UnloadRenderTexture(buffer);
+ regenerate();
}
void
ScenarioEditor::update(float)
{
- if (IsWindowResized()) {
- UnloadRenderTexture(buffer);
- buffer = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
- }
+ frame.update();
if (ImGui::Begin("Scenario Editor")) {
bool update = false;
update |= ImGui::SliderInt("Teams", &teams, 2, 6);
@@ -51,7 +41,7 @@ ScenarioEditor::update(float)
update |= ImGui::SliderInt("Eclipses", &eclipses, 0, 20);
update |= ImGui::SliderFloat("Distance", &distance, 10000, 20000);
if (update)
- battle = generate();
+ regenerate();
if (ImGui::Button("Start"))
start_battle();
ImGui::SameLine();
@@ -68,21 +58,7 @@ void
ScenarioEditor::draw() const
{
ClearBackground(BLACK);
- if (battle) {
- BeginTextureMode(buffer);
- battle->draw();
- EndTextureMode();
- DrawTextureRec(
- buffer.texture,
- {
- 0,
- static_cast<float>(GetScreenHeight()),
- static_cast<float>(GetScreenWidth()),
- static_cast<float>(-GetScreenHeight())
- },
- {0, 0},
- {255, 255, 255, 150});
- }
+ frame.draw();
}
@@ -90,15 +66,16 @@ void
ScenarioEditor::start_battle()
{
session->push(std::move(battle));
- battle = generate();
+ regenerate();
}
-std::shared_ptr<Scene>
-ScenarioEditor::generate() const
+void
+ScenarioEditor::regenerate()
{
auto scenario = campaign::scenarios::example(teams, anvils, warbringers, eclipses, distance);
- return std::make_shared<Battle>(session, std::move(scenario));
+ battle = std::make_shared<Battle>(session, std::move(scenario));
+ frame.reset(battle);
}
diff --git a/kurator/src/ScenarioEditor.h b/kurator/src/ScenarioEditor.h
index ec83965..cec4783 100644
--- a/kurator/src/ScenarioEditor.h
+++ b/kurator/src/ScenarioEditor.h
@@ -2,9 +2,8 @@
#include <memory>
-#include <raylib.h>
-
#include "Scene.h"
+#include "SceneFrame.h"
#include "Session.h"
@@ -16,20 +15,19 @@ class ScenarioEditor : public Scene
{
public:
explicit ScenarioEditor(std::shared_ptr<Session> _session);
- ~ScenarioEditor();
void update(float dt) override;
void draw() const override;
void start_battle();
private:
- std::shared_ptr<Scene> generate() const;
+ void regenerate();
std::shared_ptr<Session> session;
- RenderTexture2D buffer;
int teams;
int anvils;
int warbringers;
int eclipses;
float distance;
std::shared_ptr<Scene> battle;
+ SceneFrame frame;
};
diff --git a/kurator/src/SceneFrame.cpp b/kurator/src/SceneFrame.cpp
new file mode 100644
index 0000000..ebc781c
--- /dev/null
+++ b/kurator/src/SceneFrame.cpp
@@ -0,0 +1,73 @@
+#include "SceneFrame.h"
+
+#include <memory>
+#include <utility>
+
+#include <raylib.h>
+
+#include "Scene.h"
+
+
+namespace kurator
+{
+
+
+SceneFrame::SceneFrame(std::shared_ptr<Scene> _scene) :
+ scene {std::move(_scene)},
+ buffer {LoadRenderTexture(GetScreenWidth(), GetScreenHeight())}
+{
+}
+
+
+SceneFrame::~SceneFrame()
+{
+ UnloadRenderTexture(buffer);
+}
+
+
+void
+SceneFrame::update()
+{
+ if (IsWindowResized()) {
+ UnloadRenderTexture(buffer);
+ buffer = LoadRenderTexture(GetScreenWidth(), GetScreenHeight());
+ }
+}
+
+
+void
+SceneFrame::draw() const
+{
+ if (!scene)
+ return;
+ BeginTextureMode(buffer);
+ scene->draw();
+ EndTextureMode();
+ DrawTextureRec(
+ buffer.texture,
+ {
+ 0,
+ static_cast<float>(GetScreenHeight()),
+ static_cast<float>(GetScreenWidth()),
+ static_cast<float>(-GetScreenHeight())
+ },
+ {0, 0},
+ {255, 255, 255, 150});
+}
+
+
+void
+SceneFrame::reset(std::shared_ptr<Scene> _scene)
+{
+ scene = std::move(_scene);
+}
+
+
+std::shared_ptr<Scene>
+SceneFrame::view() const
+{
+ return scene;
+}
+
+
+} // namespace kurator
diff --git a/kurator/src/SceneFrame.h b/kurator/src/SceneFrame.h
new file mode 100644
index 0000000..9bc3feb
--- /dev/null
+++ b/kurator/src/SceneFrame.h
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <memory>
+
+#include <raylib.h>
+
+#include "Scene.h"
+
+
+namespace kurator
+{
+
+
+class SceneFrame
+{
+public:
+ explicit SceneFrame(std::shared_ptr<Scene> _scene=nullptr);
+ ~SceneFrame();
+ void update();
+ void draw() const;
+ void reset(std::shared_ptr<Scene> _scene);
+ std::shared_ptr<Scene> view() const;
+private:
+ std::shared_ptr<Scene> scene;
+ RenderTexture2D buffer;
+};
+
+
+} // namespace kurator