diff --git a/app/village/village_initializer.cpp b/app/village/village_initializer.cpp new file mode 100644 index 0000000..e752d6e --- /dev/null +++ b/app/village/village_initializer.cpp @@ -0,0 +1,37 @@ +#include "village_initializer.h" + +void VillageInitializer::allocate_controller() { + ERR_FAIL_COND(_controller); + + _controller = new VillageController(); +} +void VillageInitializer::free_controller() { + if (_controller) { + delete _controller; + _controller = nullptr; + } +} + +void VillageInitializer::allocate_model() { + ERR_FAIL_COND(_model); + + _model = new VillageModel(); +} +void VillageInitializer::free_model() { + if (_model) { + delete _model; + _model = nullptr; + } +} + +void VillageInitializer::allocate_all() { + allocate_model(); + allocate_controller(); +} +void VillageInitializer::free_all() { + free_controller(); + free_model(); +} + +VillageController *VillageInitializer::_controller = nullptr; +VillageModel *VillageInitializer::_model = nullptr; \ No newline at end of file diff --git a/app/village/village_initializer.h b/app/village/village_initializer.h new file mode 100644 index 0000000..32df18d --- /dev/null +++ b/app/village/village_initializer.h @@ -0,0 +1,23 @@ +#ifndef VILLAGE_INITIALIZER_H +#define VILLAGE_INITIALIZER_H + +#include "village_model.h" +#include "village_controller.h" + +class VillageInitializer { +public: + static void allocate_controller(); + static void free_controller(); + + static void allocate_model(); + static void free_model(); + + static void allocate_all(); + static void free_all(); + +protected: + static VillageController *_controller; + static VillageModel *_model; +}; + +#endif \ No newline at end of file