Queries also provide entity_id
This commit is contained in:
		
							parent
							
								
									d1bafb4c46
								
							
						
					
					
						commit
						27cf20fac3
					
				
					 3 changed files with 8 additions and 12 deletions
				
			
		|  | @ -2,8 +2,8 @@ | ||||||
| #define CATCH_CONFIG_MAIN | #define CATCH_CONFIG_MAIN | ||||||
| #include <catch2/catch_all.hpp> | #include <catch2/catch_all.hpp> | ||||||
| 
 | 
 | ||||||
| #include "../zecsy.hpp" |  | ||||||
| #include "../system_scheduler.hpp" | #include "../system_scheduler.hpp" | ||||||
|  | #include "../zecsy.hpp" | ||||||
| 
 | 
 | ||||||
| using namespace zecsy; | using namespace zecsy; | ||||||
| 
 | 
 | ||||||
|  | @ -193,7 +193,7 @@ TEST_CASE("Create a simple system that processes entities with a specific " | ||||||
|      * Really wanna deduce it to w.query([](Component&){}), |      * Really wanna deduce it to w.query([](Component&){}), | ||||||
|      * but I have some troubles with it |      * but I have some troubles with it | ||||||
|      */ |      */ | ||||||
|     w.query<Component>([](Component& c) { c.value++; }); |     w.query<Component>([](entity_id e, Component& c) { c.value++; }); | ||||||
| 
 | 
 | ||||||
|     REQUIRE(w.get<Component>(e0).value == 1); |     REQUIRE(w.get<Component>(e0).value == 1); | ||||||
|     REQUIRE(w.get<Component>(e1).value == 21); |     REQUIRE(w.get<Component>(e1).value == 21); | ||||||
|  | @ -223,20 +223,16 @@ TEST_CASE("Test a systems ability to query and process only entities with a " | ||||||
|     auto e2 = w.make_entity(); |     auto e2 = w.make_entity(); | ||||||
|     w.set(e2, C1{}); |     w.set(e2, C1{}); | ||||||
| 
 | 
 | ||||||
|     int count = 0; |  | ||||||
| 
 |  | ||||||
|     REQUIRE(w.get<C0>(e0).value == 0); |     REQUIRE(w.get<C0>(e0).value == 0); | ||||||
|     REQUIRE(w.get<C1>(e0).value == 10); |     REQUIRE(w.get<C1>(e0).value == 10); | ||||||
| 
 | 
 | ||||||
|     w.query<C0, C1>([&count](C0& c0, C1& c1) |     w.query<C0, C1>([e0](entity_id e, C0& c0, C1& c1) | ||||||
|     { |     { | ||||||
|  |         REQUIRE(e == e0); | ||||||
|         c0.value++; |         c0.value++; | ||||||
|         c1.value++; |         c1.value++; | ||||||
|         count++; |  | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     REQUIRE(count == 1); |  | ||||||
| 
 |  | ||||||
|     REQUIRE(w.get<C0>(e0).value == 1); |     REQUIRE(w.get<C0>(e0).value == 1); | ||||||
|     REQUIRE(w.get<C1>(e0).value == 11); |     REQUIRE(w.get<C1>(e0).value == 11); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -63,7 +63,7 @@ namespace zecsy | ||||||
|         void remove(entity_id e); |         void remove(entity_id e); | ||||||
| 
 | 
 | ||||||
|         template<Component... T> |         template<Component... T> | ||||||
|         void query(std::invocable<T&...> auto&& system); |         void query(std::invocable<entity_id, T&...> auto&& system); | ||||||
| 
 | 
 | ||||||
|     private: |     private: | ||||||
|         using comp_id = size_t; |         using comp_id = size_t; | ||||||
|  | @ -228,13 +228,13 @@ namespace zecsy | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     template<Component... T> |     template<Component... T> | ||||||
|     inline void world::query(std::invocable<T&...> auto&& system) |     inline void world::query(std::invocable<entity_id, T&...> auto&& system) | ||||||
|     { |     { | ||||||
|         for(auto e: alive_entities) |         for(auto e: alive_entities) | ||||||
|         { |         { | ||||||
|             if((has<T...>(e))) |             if((has<T...>(e))) | ||||||
|             { |             { | ||||||
|                 system(get<T>(e)...); |                 system(e, get<T>(e)...); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue