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 | |
parent | 5134bebc19c46e4e07a5ec3af1d3f3d2d17a86dd (diff) |
use OptionalRef instead of pointer references
Diffstat (limited to 'src/crepe/system')
-rw-r--r-- | src/crepe/system/ScriptSystem.cpp | 30 | ||||
-rw-r--r-- | src/crepe/system/ScriptSystem.h | 11 |
2 files changed, 9 insertions, 32 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(); + } } + diff --git a/src/crepe/system/ScriptSystem.h b/src/crepe/system/ScriptSystem.h index 32e1fcd..936e9ca 100644 --- a/src/crepe/system/ScriptSystem.h +++ b/src/crepe/system/ScriptSystem.h @@ -2,8 +2,6 @@ #include "System.h" -#include "../types.h" - namespace crepe { class Script; @@ -25,15 +23,6 @@ public: * the \c BehaviorScript instance. */ void update() override; - -private: - /** - * \brief Aggregate all active \c BehaviorScript components and return a list - * of references to their \c Script instances (utility) - * - * \returns List of active \c Script instances - */ - RefVector<Script> get_scripts() const; }; } // namespace crepe |