aboutsummaryrefslogtreecommitdiff
path: root/extension/src/Simulation.hpp
diff options
context:
space:
mode:
author ClarkeCode <33846391+ClarkeCode@users.noreply.github.com>2023-02-13 17:04:22 +0100
committer GitHub <noreply@github.com>2023-02-13 17:04:22 +0100
commit6a0158e625eaffbae0f214620a1d728728934033 (patch)
treec3af6ac753b8b3c177d1e9a41e94017c1c2afbd0 /extension/src/Simulation.hpp
parentc0d8a4ac3723021c95da9674c3bc0eea511ee3a0 (diff)
parenta4f213bf923b79674b8dcef4c35f0f79329ffc80 (diff)
Merge pull request #8 from OpenVic2Project/dev-trailblazing-cpp
Exploration of uniting Godot UI with Stateful C++ Objects via GDExtension
Diffstat (limited to 'extension/src/Simulation.hpp')
-rw-r--r--extension/src/Simulation.hpp52
1 files changed, 52 insertions, 0 deletions
diff --git a/extension/src/Simulation.hpp b/extension/src/Simulation.hpp
new file mode 100644
index 0000000..e16f34b
--- /dev/null
+++ b/extension/src/Simulation.hpp
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <godot_cpp/classes/object.hpp>
+#include <godot_cpp/core/class_db.hpp>
+#include <godot_cpp/variant/utility_functions.hpp>
+#include <vector>
+
+namespace OpenVic2 {
+ class Simulation : public godot::Object {
+ GDCLASS(Simulation, godot::Object)
+ std::vector<size_t> exampleProvinces;
+
+ //BEGIN BOILERPLATE
+ static Simulation* _simulation;
+
+ protected:
+ static void _bind_methods() {
+ godot::ClassDB::bind_method(godot::D_METHOD("conductSimulationStep"), &Simulation::conductSimulationStep);
+ godot::ClassDB::bind_method(godot::D_METHOD("queryProvinceSize"), &Simulation::queryProvinceSize);
+ }
+
+ public:
+ inline static Simulation* get_singleton() { return _simulation; }
+
+ inline Simulation() {
+ ERR_FAIL_COND(_simulation != nullptr);
+ _simulation = this;
+
+ exampleProvinces.resize(10, 1);
+ }
+ inline ~Simulation() {
+ ERR_FAIL_COND(_simulation != this);
+ _simulation = nullptr;
+ }
+ //END BOILERPLATE
+
+ inline void conductSimulationStep() {
+ for (size_t x = 0; x < exampleProvinces.size(); x++) {
+ exampleProvinces[x] += (x + 1);
+ }
+ }
+
+ inline size_t queryProvinceSize(size_t provinceID) {
+ if (provinceID >= exampleProvinces.size()) {
+ return 0;
+ }
+ return exampleProvinces[provinceID];
+ }
+ };
+
+ Simulation* Simulation::_simulation = nullptr;
+} \ No newline at end of file