From e2c27d8c99a71e5d94ffe49027ec13afeb74b021 Mon Sep 17 00:00:00 2001 From: Loek Le Blansch Date: Wed, 20 Nov 2024 14:59:34 +0100 Subject: replace more vector> with RefVector --- src/crepe/api/GameObject.cpp | 6 ++---- src/crepe/api/Script.h | 2 +- src/crepe/api/Script.hpp | 5 ++--- src/crepe/system/AnimatorSystem.cpp | 5 +---- src/crepe/system/ParticleSystem.cpp | 3 +-- src/crepe/system/PhysicsSystem.cpp | 6 ++---- src/crepe/system/RenderSystem.cpp | 13 +++++-------- src/crepe/system/RenderSystem.h | 3 +-- src/crepe/system/ScriptSystem.cpp | 13 +++++-------- src/crepe/system/ScriptSystem.h | 6 +++--- 10 files changed, 23 insertions(+), 39 deletions(-) diff --git a/src/crepe/api/GameObject.cpp b/src/crepe/api/GameObject.cpp index 287e81d..4874426 100644 --- a/src/crepe/api/GameObject.cpp +++ b/src/crepe/api/GameObject.cpp @@ -23,12 +23,10 @@ void GameObject::set_parent(const GameObject & parent) { ComponentManager & mgr = this->component_manager; // Set parent on own Metadata component - vector> this_metadata - = mgr.get_components_by_id(this->id); + RefVector this_metadata = mgr.get_components_by_id(this->id); this_metadata.at(0).get().parent = parent.id; // Add own id to children list of parent's Metadata component - vector> parent_metadata - = mgr.get_components_by_id(parent.id); + RefVector parent_metadata = mgr.get_components_by_id(parent.id); parent_metadata.at(0).get().children.push_back(this->id); } diff --git a/src/crepe/api/Script.h b/src/crepe/api/Script.h index 2b70379..839d937 100644 --- a/src/crepe/api/Script.h +++ b/src/crepe/api/Script.h @@ -62,7 +62,7 @@ protected: * \returns List of component references */ template - std::vector> get_components() const; + RefVector get_components() const; protected: // NOTE: Script must have a constructor without arguments so the game programmer doesn't need diff --git a/src/crepe/api/Script.hpp b/src/crepe/api/Script.hpp index a064a90..a85d814 100644 --- a/src/crepe/api/Script.hpp +++ b/src/crepe/api/Script.hpp @@ -10,7 +10,7 @@ namespace crepe { template T & Script::get_component() const { using namespace std; - vector> all_components = this->get_components(); + RefVector all_components = this->get_components(); if (all_components.size() < 1) throw runtime_error( format("Script: no component found with type = {}", typeid(T).name())); @@ -19,9 +19,8 @@ T & Script::get_component() const { } template -std::vector> Script::get_components() const { +RefVector Script::get_components() const { auto & mgr = *this->component_manager_ref; - return mgr.get_components_by_id(this->game_object_id); } diff --git a/src/crepe/system/AnimatorSystem.cpp b/src/crepe/system/AnimatorSystem.cpp index 9d18873..676e485 100644 --- a/src/crepe/system/AnimatorSystem.cpp +++ b/src/crepe/system/AnimatorSystem.cpp @@ -1,6 +1,4 @@ #include -#include -#include #include "api/Animator.h" #include "facade/SDLContext.h" @@ -13,8 +11,7 @@ using namespace crepe; void AnimatorSystem::update() { ComponentManager & mgr = this->component_manager; - std::vector> animations - = mgr.get_components_by_type(); + RefVector animations = mgr.get_components_by_type(); uint64_t tick = SDLContext::get_instance().get_ticks(); for (Animator & a : animations) { diff --git a/src/crepe/system/ParticleSystem.cpp b/src/crepe/system/ParticleSystem.cpp index 7316309..fcf7522 100644 --- a/src/crepe/system/ParticleSystem.cpp +++ b/src/crepe/system/ParticleSystem.cpp @@ -14,8 +14,7 @@ using namespace crepe; void ParticleSystem::update() { // Get all emitters ComponentManager & mgr = this->component_manager; - std::vector> emitters - = mgr.get_components_by_type(); + RefVector emitters = mgr.get_components_by_type(); for (ParticleEmitter & emitter : emitters) { // Get transform linked to emitter diff --git a/src/crepe/system/PhysicsSystem.cpp b/src/crepe/system/PhysicsSystem.cpp index 4a7dbfb..bcde431 100644 --- a/src/crepe/system/PhysicsSystem.cpp +++ b/src/crepe/system/PhysicsSystem.cpp @@ -12,10 +12,8 @@ using namespace crepe; void PhysicsSystem::update() { ComponentManager & mgr = this->component_manager; - std::vector> rigidbodies - = mgr.get_components_by_type(); - std::vector> transforms - = mgr.get_components_by_type(); + RefVector rigidbodies = mgr.get_components_by_type(); + RefVector transforms = mgr.get_components_by_type(); double gravity = Config::get_instance().physics.gravity; for (Rigidbody & rigidbody : rigidbodies) { diff --git a/src/crepe/system/RenderSystem.cpp b/src/crepe/system/RenderSystem.cpp index 96c5f27..7ee03e5 100644 --- a/src/crepe/system/RenderSystem.cpp +++ b/src/crepe/system/RenderSystem.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -20,7 +19,7 @@ void RenderSystem::present_screen() { this->context.present_screen(); } void RenderSystem::update_camera() { ComponentManager & mgr = this->component_manager; - std::vector> cameras = mgr.get_components_by_type(); + RefVector cameras = mgr.get_components_by_type(); if (cameras.size() == 0) throw std::runtime_error("No cameras in current scene"); @@ -37,10 +36,8 @@ bool sorting_comparison(const Sprite & a, const Sprite & b) { return false; } -std::vector> -RenderSystem::sort(std::vector> & objs) { - - std::vector> sorted_objs(objs); +RefVector RenderSystem::sort(RefVector & objs) { + RefVector sorted_objs(objs); std::sort(sorted_objs.begin(), sorted_objs.end(), sorting_comparison); return sorted_objs; @@ -48,8 +45,8 @@ RenderSystem::sort(std::vector> & objs) { void RenderSystem::render_sprites() { ComponentManager & mgr = this->component_manager; - vector> sprites = mgr.get_components_by_type(); - vector> sorted_sprites = this->sort(sprites); + RefVector sprites = mgr.get_components_by_type(); + RefVector sorted_sprites = this->sort(sprites); for (const Sprite & sprite : sorted_sprites) { auto transforms = mgr.get_components_by_id(sprite.game_object_id); diff --git a/src/crepe/system/RenderSystem.h b/src/crepe/system/RenderSystem.h index 57b9c73..40978ae 100644 --- a/src/crepe/system/RenderSystem.h +++ b/src/crepe/system/RenderSystem.h @@ -47,8 +47,7 @@ private: * \param objs the vector that will do a sorting algorithm on * \return returns a sorted reference vector */ - std::vector> - sort(std::vector> & objs); + RefVector sort(RefVector & objs); /** * \todo Include color handling for sprites. diff --git a/src/crepe/system/ScriptSystem.cpp b/src/crepe/system/ScriptSystem.cpp index c4d724c..c33309c 100644 --- a/src/crepe/system/ScriptSystem.cpp +++ b/src/crepe/system/ScriptSystem.cpp @@ -1,6 +1,4 @@ -#include #include -#include #include "../ComponentManager.h" #include "../api/BehaviorScript.h" @@ -14,7 +12,7 @@ using namespace crepe; void ScriptSystem::update() { dbg_trace(); - forward_list> scripts = this->get_scripts(); + RefVector