diff options
author | Robert Clarke <clarke.john.robert@gmail.com> | 2023-02-12 09:44:39 +0100 |
---|---|---|
committer | Robert Clarke <clarke.john.robert@gmail.com> | 2023-02-12 09:44:39 +0100 |
commit | d45323cadee9044d8536f7eb9827a43b36e4bdff (patch) | |
tree | 6e2a8aa1d7d2c7e69df8eb6d5a18524b8e8ffa00 /extension/src/Simulation.hpp | |
parent | e7ee0ddbefa8f6696aa7b5a001b3a04eb046ba0d (diff) |
Everything necessary to register a C++ class with internal state for access within Godot
Diffstat (limited to 'extension/src/Simulation.hpp')
-rw-r--r-- | extension/src/Simulation.hpp | 52 |
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..6ade846 --- /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 { + std::vector<size_t> exampleProvinces; + + //BEGIN BOILERPLATE + GDCLASS(Simulation, godot::Object); + 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 |