mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-11-03 18:39:19 +00:00 
			
		
		
		
	Merge branch 'main' of https://github.com/Ukendio/jecs into Add-Cached-Queries
This commit is contained in:
		
						commit
						1ae0587b54
					
				
					 2 changed files with 19 additions and 5 deletions
				
			
		| 
						 | 
				
			
			@ -170,7 +170,7 @@ local function _STRIP_GENERATION(e: i53): i24
 | 
			
		|||
end
 | 
			
		||||
 | 
			
		||||
local function ECS_PAIR(pred: i53, obj: i53): i53
 | 
			
		||||
	return ECS_COMBINE(ECS_ENTITY_T_LO(obj), ECS_ENTITY_T_LO(pred)) + FLAGS_ADD(--[[isPair]] true) :: i53
 | 
			
		||||
	return ECS_COMBINE(ECS_ENTITY_T_LO(pred), ECS_ENTITY_T_LO(obj)) + FLAGS_ADD(--[[isPair]] true) :: i53
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function entity_index_try_get_any(entity_index: EntityIndex, entity: number): Record?
 | 
			
		||||
| 
						 | 
				
			
			@ -244,12 +244,12 @@ end
 | 
			
		|||
 | 
			
		||||
-- ECS_PAIR_FIRST, gets the relationship target / obj / HIGH bits
 | 
			
		||||
local function ecs_pair_first(world, e)
 | 
			
		||||
	return entity_index_get_alive(world.entity_index, ECS_ENTITY_T_HI(e))
 | 
			
		||||
	return entity_index_get_alive(world.entity_index, ECS_ENTITY_T_LO(e))
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
-- ECS_PAIR_SECOND gets the relationship / pred / LOW bits
 | 
			
		||||
local function ecs_pair_second(world, e)
 | 
			
		||||
	return entity_index_get_alive(world.entity_index, ECS_ENTITY_T_LO(e))
 | 
			
		||||
	return entity_index_get_alive(world.entity_index, ECS_ENTITY_T_HI(e))
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
local function query_match(query, archetype: Archetype)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -59,6 +59,7 @@ local function debug_world_inspect(world: World)
 | 
			
		|||
		records = records,
 | 
			
		||||
		row = row,
 | 
			
		||||
		tuple = tuple,
 | 
			
		||||
		columns = columns
 | 
			
		||||
	}
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -1208,25 +1209,38 @@ TEST("world:delete", function()
 | 
			
		|||
end)
 | 
			
		||||
 | 
			
		||||
TEST("world:target", function()
 | 
			
		||||
	do
 | 
			
		||||
		CASE("nth index")
 | 
			
		||||
	do CASE("nth index")
 | 
			
		||||
		local world = world_new()
 | 
			
		||||
		local A = world:component()
 | 
			
		||||
		world:set(A, jecs.Name, "A")
 | 
			
		||||
		local B = world:component()
 | 
			
		||||
		world:set(B, jecs.Name, "B")
 | 
			
		||||
		local C = world:component()
 | 
			
		||||
		world:set(C, jecs.Name, "C")
 | 
			
		||||
		local D = world:component()
 | 
			
		||||
		world:set(D, jecs.Name, "D")
 | 
			
		||||
		local E = world:component()
 | 
			
		||||
		world:set(E, jecs.Name, "E")
 | 
			
		||||
		local e = world:entity()
 | 
			
		||||
 | 
			
		||||
		world:add(e, pair(A, B))
 | 
			
		||||
		world:add(e, pair(A, C))
 | 
			
		||||
		world:add(e, pair(A, D))
 | 
			
		||||
		world:add(e, pair(A, E))
 | 
			
		||||
		world:add(e, pair(B, C))
 | 
			
		||||
		world:add(e, pair(B, D))
 | 
			
		||||
		world:add(e, pair(C, D))
 | 
			
		||||
 | 
			
		||||
		CHECK(pair(A, B) < pair(A, C))
 | 
			
		||||
		CHECK(pair(A, E) < pair(B, C))
 | 
			
		||||
 | 
			
		||||
		local records = debug_world_inspect(world).records(e)
 | 
			
		||||
		CHECK(jecs.pair_first(world, pair(B, C)) == B)
 | 
			
		||||
		CHECK(records[pair(B, C)].column > records[pair(A, E)].column)
 | 
			
		||||
		CHECK(world:target(e, A, 0) == B)
 | 
			
		||||
		CHECK(world:target(e, A, 1) == C)
 | 
			
		||||
		CHECK(world:target(e, A, 2) == D)
 | 
			
		||||
		CHECK(world:target(e, A, 3) == E)
 | 
			
		||||
		CHECK(world:target(e, B, 0) == C)
 | 
			
		||||
		CHECK(world:target(e, B, 1) == D)
 | 
			
		||||
		CHECK(world:target(e, C, 0) == D)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue