aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system/ScriptSystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/system/ScriptSystem.cpp')
-rw-r--r--src/crepe/system/ScriptSystem.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp
index c33309c..ed0c7cc 100644
--- a/src/crepe/system/ScriptSystem.cpp
+++ b/src/crepe/system/ScriptSystem.cpp
@@ -1,41 +1,41 @@
-#include <functional>
-
-#include "../ComponentManager.h"
#include "../api/BehaviorScript.h"
#include "../api/Script.h"
+#include "../manager/ComponentManager.h"
#include "ScriptSystem.h"
using namespace std;
using namespace crepe;
-void ScriptSystem::update() {
- dbg_trace();
-
- RefVector<Script> scripts = this->get_scripts();
+void ScriptSystem::fixed_update() {
+ LoopTimerManager & timer = this->mediator.loop_timer;
+ duration_t delta_time = timer.get_scaled_fixed_delta_time();
+ this->update(&Script::fixed_update, delta_time);
+}
- for (auto & script_ref : scripts) {
- Script & script = script_ref.get();
- if (!script.initialized) {
- script.init();
- script.initialized = true;
- }
- script.update();
- }
+void ScriptSystem::frame_update() {
+ LoopTimerManager & timer = this->mediator.loop_timer;
+ duration_t delta_time = timer.get_delta_time();
+ this->update(&Script::frame_update, delta_time);
}
-RefVector<Script> ScriptSystem::get_scripts() const {
- RefVector<Script> scripts = {};
- ComponentManager & mgr = this->component_manager;
+void ScriptSystem::update(
+ void (Script::*update_function)(duration_t), const duration_t & delta_time
+) {
+ ComponentManager & mgr = this->mediator.component_manager;
RefVector<BehaviorScript> behavior_scripts = mgr.get_components_by_type<BehaviorScript>();
- for (auto behavior_script_ref : behavior_scripts) {
- BehaviorScript & behavior_script = behavior_script_ref.get();
+ for (BehaviorScript & behavior_script : behavior_scripts) {
if (!behavior_script.active) continue;
+
Script * script = behavior_script.script.get();
if (script == nullptr) continue;
- scripts.push_back(*script);
- }
- return scripts;
+ if (!script->initialized) {
+ script->init();
+ script->initialized = true;
+ }
+
+ (*script.*update_function)(delta_time);
+ }
}