aboutsummaryrefslogtreecommitdiff
path: root/mwe/ecs-homemade/src/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'mwe/ecs-homemade/src/main.cpp')
-rw-r--r--mwe/ecs-homemade/src/main.cpp20
1 files changed, 8 insertions, 12 deletions
diff --git a/mwe/ecs-homemade/src/main.cpp b/mwe/ecs-homemade/src/main.cpp
index 73f710b..f72a044 100644
--- a/mwe/ecs-homemade/src/main.cpp
+++ b/mwe/ecs-homemade/src/main.cpp
@@ -14,6 +14,7 @@ int main() {
//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
+ gameObect0.AddComponent<Rigidbody>(3, 2, 1); //Add a second rigidbody to entity0
//Rigidbody rigidbody1(4, 5, 6);
gameObect1.AddComponent<Rigidbody>(4, 5, 6); //Only add a rigidbody to entity1
@@ -21,19 +22,14 @@ int main() {
//The entities are now initialized
//Now I will demonstrate some ways of retreiving/getting components
- 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
- for(std::uint32_t ID : rigidbodyIDs) {
- std::cout << "Rigidbody ID: " << ID << std::endl;
+ std::vector<std::reference_wrapper<Rigidbody>> rigidbodyOfEntity0 = ComponentManager::GetInstance().GetComponentsByID<Rigidbody>(gameObect0.mId); //Get the pointer to the Rigidbody component of entity 0
+ for(Rigidbody& rigidbodyEntity0 : rigidbodyOfEntity0) {
+ std::cout << "rigidbodyOfEntity0: " << rigidbodyEntity0.mMass << " " << rigidbodyEntity0.mGravityScale << " " << rigidbodyEntity0.mBodyType << std::endl;
+ std::cout << std::endl;
}
- std::cout << std::endl;
- std::vector<Rigidbody*> rigidbodyComponents = ComponentManager::GetInstance().GetAllComponentPointer<Rigidbody>(); //Get all the pointers to the Rigidbody component(s)
- for(Rigidbody* rigidbody : rigidbodyComponents) {
- std::cout << "rigidbody: " << rigidbody->mMass << " " << rigidbody->mGravityScale << " " << rigidbody->mBodyType << std::endl;
+ std::vector<std::pair<std::reference_wrapper<Rigidbody>, std::uint32_t>> rigidBodies = ComponentManager::GetInstance().GetComponentsByType<Rigidbody>();
+ for(auto& [rigidbody, id] : rigidBodies) {
+ std::cout << "Rigidbody of id: " << id << ": " << rigidbody.get().mMass << " " << rigidbody.get().mGravityScale << " " << rigidbody.get().mBodyType << std::endl;
}
- std::cout << std::endl;*/
}