diff options
author | Max-001 <80035972+Max-001@users.noreply.github.com> | 2024-10-02 12:35:01 +0200 |
---|---|---|
committer | Max-001 <80035972+Max-001@users.noreply.github.com> | 2024-10-02 12:35:01 +0200 |
commit | e409986d9a21ca96ee0b491826eb0008ff6ab8e0 (patch) | |
tree | 89f04830a0e3727f53e15b4ebff70a95add40c30 /mwe/ecs-homemade/src | |
parent | aedbb8b82f13d8b390419e59cea098ea73295df5 (diff) |
Changed componentsManager to allow mutliple componts of the same type for one entity (id)
Diffstat (limited to 'mwe/ecs-homemade/src')
-rw-r--r-- | mwe/ecs-homemade/src/main.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/mwe/ecs-homemade/src/main.cpp b/mwe/ecs-homemade/src/main.cpp index 3dd082f..73f710b 100644 --- a/mwe/ecs-homemade/src/main.cpp +++ b/mwe/ecs-homemade/src/main.cpp @@ -10,22 +10,22 @@ int main() { GameObject gameObect0(0, "Name: 0", "Tag: 0", 0); //Entity 0 GameObject gameObect1(1, "Name: 1", "Tag: 1", 1); //Entity 1 - Sprite sprite0; - Rigidbody rigidbody0(1, 2, 3); - gameObect0.AddComponent<Sprite>(&sprite0); //Add a sprite to entity0 - gameObect0.AddComponent<Rigidbody>(&rigidbody0); //Also add a rigidbody to entity0 + //Sprite sprite0; + //Rigidbody rigidbody0(1, 2, 3); + gameObect0.AddComponent<Sprite>(); //Add a sprite to entity0 + gameObect0.AddComponent<Rigidbody>(1, 2, 3); //Also add a rigidbody to entity0 - Rigidbody rigidbody1(4, 5, 6); - gameObect1.AddComponent<Rigidbody>(&rigidbody1); //Only add a rigidbody to entity1 + //Rigidbody rigidbody1(4, 5, 6); + gameObect1.AddComponent<Rigidbody>(4, 5, 6); //Only add a rigidbody to entity1 //The entities are now initialized //Now I will demonstrate some ways of retreiving/getting components - Rigidbody* rigidbodyOfEntity0 = ComponentManager::GetInstance().GetComponent<Rigidbody>(gameObect0.mId); //Get the pointer to the Rigidbody component of entity 0 - std::cout << "rigidbodyOfEntity0: " << rigidbodyOfEntity0->mMass << " " << rigidbodyOfEntity0->mGravityScale << " " << rigidbodyOfEntity0->mBodyType << std::endl; + std::vector<std::reference_wrapper<Rigidbody>> rigidbodyOfEntity0 = ComponentManager::GetInstance().GetComponentsOfID<Rigidbody>(gameObect0.mId); //Get the pointer to the Rigidbody component of entity 0 + std::cout << "rigidbodyOfEntity0: " << rigidbodyOfEntity0[0].get().mMass << " " << rigidbodyOfEntity0[0].get().mGravityScale << " " << rigidbodyOfEntity0[0].get().mBodyType << std::endl; std::cout << std::endl; - std::vector<std::uint32_t> rigidbodyIDs = ComponentManager::GetInstance().GetAllComponentIDs<Rigidbody>(); //Get all the IDs that have a Rigidbody component + /*std::vector<std::uint32_t> rigidbodyIDs = ComponentManager::GetInstance().GetAllComponentIDs<Rigidbody>(); //Get all the IDs that have a Rigidbody component for(std::uint32_t ID : rigidbodyIDs) { std::cout << "Rigidbody ID: " << ID << std::endl; } @@ -35,5 +35,5 @@ int main() { for(Rigidbody* rigidbody : rigidbodyComponents) { std::cout << "rigidbody: " << rigidbody->mMass << " " << rigidbody->mGravityScale << " " << rigidbody->mBodyType << std::endl; } - std::cout << std::endl; + std::cout << std::endl;*/ } |