aboutsummaryrefslogtreecommitdiff
path: root/mwe
diff options
context:
space:
mode:
authorMax-001 <80035972+Max-001@users.noreply.github.com>2024-10-05 12:36:26 +0200
committerMax-001 <80035972+Max-001@users.noreply.github.com>2024-10-05 12:36:26 +0200
commit765550bce8a81c6f0c79c0083b14ef68e0c900b2 (patch)
tree125a816a17d78bb8d68915b801d93e0083b660ba /mwe
parenta5fa49f39473a8d2dc535145cb34866967ec10ab (diff)
Removed the std::pair to improve test
Diffstat (limited to 'mwe')
-rw-r--r--mwe/ecs-homemade/inc/ComponentManager.h2
-rw-r--r--mwe/ecs-homemade/inc/ComponentManager.hpp10
-rw-r--r--mwe/ecs-homemade/src/main.cpp14
3 files changed, 13 insertions, 13 deletions
diff --git a/mwe/ecs-homemade/inc/ComponentManager.h b/mwe/ecs-homemade/inc/ComponentManager.h
index 893aa56..1a58b01 100644
--- a/mwe/ecs-homemade/inc/ComponentManager.h
+++ b/mwe/ecs-homemade/inc/ComponentManager.h
@@ -29,7 +29,7 @@ public:
template <typename T>
std::vector<std::reference_wrapper<T>> GetComponentsByID(std::uint32_t id) const; //Get a vector<> of all components at specific type and id
template <typename T>
- std::vector<std::pair<std::reference_wrapper<T>, std::uint32_t>> GetComponentsByType() const; //Get a vector<> of all components of a specific type
+ std::vector<std::reference_wrapper<T>> GetComponentsByType() const; //Get a vector<> of all components of a specific type
private:
static ComponentManager mInstance; //Singleton
diff --git a/mwe/ecs-homemade/inc/ComponentManager.hpp b/mwe/ecs-homemade/inc/ComponentManager.hpp
index 53dfddd..720ee79 100644
--- a/mwe/ecs-homemade/inc/ComponentManager.hpp
+++ b/mwe/ecs-homemade/inc/ComponentManager.hpp
@@ -61,11 +61,11 @@ std::vector<std::reference_wrapper<T>> ComponentManager::GetComponentsByID(std::
}
template <typename T>
-std::vector<std::pair<std::reference_wrapper<T>, std::uint32_t>> ComponentManager::GetComponentsByType() const {
+std::vector<std::reference_wrapper<T>> ComponentManager::GetComponentsByType() const {
std::type_index type = typeid(T); //Determine the type of T (this is used as the key of the unordered_map<>)
- std::vector<std::pair<std::reference_wrapper<T>, std::uint32_t>> componentVector; //Create an empty vector<>
- std::uint32_t id = 0; //Set the id to 0 (the id will also be stored in the returned vector<>)
+ std::vector<std::reference_wrapper<T>> componentVector; //Create an empty vector<>
+ //std::uint32_t id = 0; //Set the id to 0 (the id will also be stored in the returned vector<>)
if (mComponents.find(type) != mComponents.end()) { //Find the type (in the unordered_map<>)
@@ -76,11 +76,11 @@ std::vector<std::pair<std::reference_wrapper<T>, std::uint32_t>> ComponentManage
T* castedComponent = static_cast<T*>(componentPtr.get()); //Cast the unique_ptr to a raw pointer
if (castedComponent) { //Ensure that the cast was successful
- componentVector.emplace_back(std::ref(*castedComponent), id); //Pair the dereferenced raw pointer and the id and add it to the vector<>
+ componentVector.emplace_back(std::ref(*castedComponent)); //Pair the dereferenced raw pointer and the id and add it to the vector<>
}
}
- ++id; //Increase the id (the id will also be stored in the returned vector<>)
+ //++id; //Increase the id (the id will also be stored in the returned vector<>)
}
}
diff --git a/mwe/ecs-homemade/src/main.cpp b/mwe/ecs-homemade/src/main.cpp
index c78e085..41f7d6d 100644
--- a/mwe/ecs-homemade/src/main.cpp
+++ b/mwe/ecs-homemade/src/main.cpp
@@ -24,20 +24,20 @@ int main() {
//This is what systems would do:
- std::vector<std::pair<std::reference_wrapper<Sprite>, std::uint32_t>> sprites = ComponentManager::GetInstance().GetComponentsByType<Sprite>();
- for(auto& [sprite, id] : sprites) {
+ std::vector<std::reference_wrapper<Sprite>> sprites = ComponentManager::GetInstance().GetComponentsByType<Sprite>();
+ for(Sprite& sprite : sprites) {
//std::cout << sprite.get().mPath << std::endl;
}
//std::cout << std::endl;
- std::vector<std::pair<std::reference_wrapper<Rigidbody>, std::uint32_t>> rigidBodies = ComponentManager::GetInstance().GetComponentsByType<Rigidbody>();
- for(auto& [rigidbody, id] : rigidBodies) {
+ std::vector<std::reference_wrapper<Rigidbody>> rigidBodies = ComponentManager::GetInstance().GetComponentsByType<Rigidbody>();
+ for(Rigidbody& rigidbody : rigidBodies) {
//std::cout << rigidbody.get().mMass << " " << rigidbody.get().mGravityScale << " " << rigidbody.get().mBodyType << std::endl;
}
//std::cout << std::endl;
-
- std::vector<std::pair<std::reference_wrapper<Colider>, std::uint32_t>> coliders = ComponentManager::GetInstance().GetComponentsByType<Colider>();
- for(auto& [colider, id] : coliders) {
+
+ std::vector<std::reference_wrapper<Colider>> coliders = ComponentManager::GetInstance().GetComponentsByType<Colider>();
+ for(Colider& colider : coliders) {
//std::cout << colider.get().mSize << std::endl;
}