summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-12-16 01:40:09 +0100
committerAki <please@ignore.pl>2022-12-16 01:40:09 +0100
commit1482c7dbe3dd7de66ccffee9596dd42e12698b04 (patch)
tree35f087dd07fcb2a35b66e2d5d03878acc9fcccb9
parentd599de1ffc38f8c7f17b454fdf6eb3aaf320c89e (diff)
downloadkurator-1482c7dbe3dd7de66ccffee9596dd42e12698b04.zip
kurator-1482c7dbe3dd7de66ccffee9596dd42e12698b04.tar.gz
kurator-1482c7dbe3dd7de66ccffee9596dd42e12698b04.tar.bz2
Replaced standard output with simplistic EventLog container and scene
-rw-r--r--kurator/CMakeLists.txt1
-rw-r--r--kurator/src/Battle.cpp13
-rw-r--r--kurator/src/Battle.h2
-rw-r--r--kurator/src/EventLog.h14
-rw-r--r--kurator/src/Log.cpp61
-rw-r--r--kurator/src/Log.h26
-rw-r--r--stats/include/kurator/stats/BaseLog.h28
-rw-r--r--stats/include/kurator/stats/BaseLog.inl.h33
8 files changed, 168 insertions, 10 deletions
diff --git a/kurator/CMakeLists.txt b/kurator/CMakeLists.txt
index 2a46ef9..d085f07 100644
--- a/kurator/CMakeLists.txt
+++ b/kurator/CMakeLists.txt
@@ -4,6 +4,7 @@ add_executable(
src/Battle.cpp
src/colors.cpp
src/ForceBalance.cpp
+ src/Log.cpp
src/main.cpp
src/Session.cpp
src/Skybox.cpp
diff --git a/kurator/src/Battle.cpp b/kurator/src/Battle.cpp
index a77b57e..b7893da 100644
--- a/kurator/src/Battle.cpp
+++ b/kurator/src/Battle.cpp
@@ -2,7 +2,6 @@
#include <algorithm>
#include <cmath>
-#include <iostream>
#include <memory>
#include <string>
#include <utility>
@@ -20,8 +19,8 @@
#include "colors.h"
#include "components.h"
+#include "Log.h"
#include "Session.h"
-#include "Title.h"
namespace kurator
@@ -72,7 +71,7 @@ Battle::update(const float dt)
}
balance.update(registry);
if (IsKeyPressed(KEY_SPACE))
- session->set(std::make_shared<Title>(session));
+ session->set(std::make_shared<Log>(session, log));
}
@@ -140,13 +139,7 @@ Battle::on_hit(const sim::Hit& hit)
void
Battle::on_ship_left(const stats::ShipLeft& event)
{
- std::cout
- << event.time
- << "\tShip " << (event.destroyed ? "destroyed" : "left") << ": "
- << event.ship.id
- << " team "
- << event.team
- << std::endl;
+ log.push_back(event);
}
diff --git a/kurator/src/Battle.h b/kurator/src/Battle.h
index 9080219..009f9c3 100644
--- a/kurator/src/Battle.h
+++ b/kurator/src/Battle.h
@@ -6,6 +6,7 @@
#include <kurator/sim/events.h>
#include <kurator/stats/events.h>
+#include "EventLog.h"
#include "ForceBalance.h"
#include "Scene.h"
#include "Session.h"
@@ -28,6 +29,7 @@ private:
std::shared_ptr<Session> session;
std::unique_ptr<sim::Battle> battle;
ForceBalance balance;
+ EventLog log;
};
diff --git a/kurator/src/EventLog.h b/kurator/src/EventLog.h
new file mode 100644
index 0000000..c676814
--- /dev/null
+++ b/kurator/src/EventLog.h
@@ -0,0 +1,14 @@
+#pragma once
+
+#include <kurator/stats/BaseLog.h>
+#include <kurator/stats/events.h>
+
+
+namespace kurator
+{
+
+
+using EventLog = stats::BaseLog<stats::ShipLeft>;
+
+
+} // namespace kurator
diff --git a/kurator/src/Log.cpp b/kurator/src/Log.cpp
new file mode 100644
index 0000000..6ef2833
--- /dev/null
+++ b/kurator/src/Log.cpp
@@ -0,0 +1,61 @@
+#include "Log.h"
+
+#include <memory>
+#include <utility>
+
+#include <raylib.h>
+
+#include <kurator/stats/events.h>
+
+#include "EventLog.h"
+#include "Session.h"
+#include "Title.h"
+
+
+namespace kurator
+{
+
+
+struct Dumper
+{
+ const int x;
+ int y;
+ const int width;
+ void operator()(const stats::ShipLeft& event);
+};
+
+
+Log::Log(std::shared_ptr<Session> _session, EventLog _events) :
+ session {std::move(_session)},
+ events {std::move(_events)}
+{
+}
+
+
+void
+Log::update(const float)
+{
+ if (IsKeyPressed(KEY_SPACE))
+ session->set(std::make_shared<Title>(session));
+}
+
+
+void
+Log::draw() const
+{
+ ClearBackground(BLACK);
+ const int width = GetScreenWidth() / 2;
+ events.for_each(Dumper{width / 2, 10, width});
+}
+
+
+void
+Dumper::operator()(const stats::ShipLeft& event)
+{
+ DrawRectangle(x - 2, y - 2, width + 4, 24, DARKGRAY);
+ DrawText(TextFormat("%3.1f (%d) destroyed", event.time, event.ship.id), x, y, 20, WHITE);
+ y += 25;
+}
+
+
+} // namespace kurator
diff --git a/kurator/src/Log.h b/kurator/src/Log.h
new file mode 100644
index 0000000..2fabccf
--- /dev/null
+++ b/kurator/src/Log.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <memory>
+
+#include "EventLog.h"
+#include "Session.h"
+#include "Scene.h"
+
+
+namespace kurator
+{
+
+
+class Log : public Scene
+{
+public:
+ Log(std::shared_ptr<Session> _session, EventLog _events);
+ void update(float dt) override;
+ void draw() const override;
+private:
+ std::shared_ptr<Session> session;
+ EventLog events;
+};
+
+
+} // namespace kurator
diff --git a/stats/include/kurator/stats/BaseLog.h b/stats/include/kurator/stats/BaseLog.h
new file mode 100644
index 0000000..142b2f2
--- /dev/null
+++ b/stats/include/kurator/stats/BaseLog.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <variant>
+#include <vector>
+
+
+namespace kurator
+{
+namespace stats
+{
+
+
+template<typename... Events>
+class BaseLog
+{
+public:
+ template<typename Event> void push_back(Event event);
+ template<typename Visitor> void for_each(Visitor visitor) const;
+private:
+ std::vector<std::variant<Events...>> events;
+};
+
+
+} // namespace stats
+} // namespace kurator
+
+
+#include "BaseLog.inl.h"
diff --git a/stats/include/kurator/stats/BaseLog.inl.h b/stats/include/kurator/stats/BaseLog.inl.h
new file mode 100644
index 0000000..288f105
--- /dev/null
+++ b/stats/include/kurator/stats/BaseLog.inl.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include <utility>
+#include <variant>
+
+
+namespace kurator
+{
+namespace stats
+{
+
+
+template<typename... Events>
+template<typename Event>
+void
+BaseLog<Events...>::push_back(Event event)
+{
+ events.push_back(std::move(event));
+}
+
+
+template<typename... Events>
+template<typename Visitor>
+void
+BaseLog<Events...>::for_each(Visitor visitor) const
+{
+ for (const auto& event : events)
+ std::visit(visitor, event);
+}
+
+
+} // namespace stats
+} // namespace kurator