diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-21 10:52:22 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-21 10:52:22 +0100 |
commit | db66bb4babb19e8a86d5c61281c8b94469729d03 (patch) | |
tree | 83c25f47797c7bd8e06d15412a9859599788569a /src/crepe/system/ScriptSystem.cpp | |
parent | 5134bebc19c46e4e07a5ec3af1d3f3d2d17a86dd (diff) |
use OptionalRef instead of pointer references
Diffstat (limited to 'src/crepe/system/ScriptSystem.cpp')
-rw-r--r-- | src/crepe/system/ScriptSystem.cpp | 30 |
1 files changed, 9 insertions, 21 deletions
diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index c33309c..d54bbc9 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -1,5 +1,3 @@ -#include <functional> - #include "../ComponentManager.h" #include "../api/BehaviorScript.h" #include "../api/Script.h" @@ -12,30 +10,20 @@ using namespace crepe; void ScriptSystem::update() { dbg_trace(); - RefVector<Script> scripts = this->get_scripts(); - - for (auto & script_ref : scripts) { - Script & script = script_ref.get(); - if (!script.initialized) { - script.init(); - script.initialized = true; - } - script.update(); - } -} - -RefVector<Script> ScriptSystem::get_scripts() const { - RefVector<Script> scripts = {}; ComponentManager & mgr = this->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(); + } } + |