mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-11-03 18:39:19 +00:00 
			
		
		
		
	Allow creating an entity with a non-zero generation below range
This commit is contained in:
		
							parent
							
								
									7b253e1c2a
								
							
						
					
					
						commit
						c3853023d0
					
				
					 2 changed files with 26 additions and 18 deletions
				
			
		
							
								
								
									
										19
									
								
								jecs.luau
									
									
									
									
									
								
							
							
						
						
									
										19
									
								
								jecs.luau
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -2574,8 +2574,6 @@ local function world_new()
 | 
			
		|||
				if not dense or r.dense == 0 then
 | 
			
		||||
					r.dense = index
 | 
			
		||||
					dense = index
 | 
			
		||||
					local any = eindex_dense_array[dense]
 | 
			
		||||
					if any == entity then
 | 
			
		||||
					local e_swap = eindex_dense_array[dense]
 | 
			
		||||
					local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2586,7 +2584,6 @@ local function world_new()
 | 
			
		|||
 | 
			
		||||
					eindex_dense_array[dense] = e_swap
 | 
			
		||||
					eindex_dense_array[alive_count] = entity
 | 
			
		||||
					end
 | 
			
		||||
					return entity
 | 
			
		||||
				end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3093,6 +3090,13 @@ return {
 | 
			
		|||
 | 
			
		||||
	pair = (ECS_PAIR :: any) :: <P, O>(first: Id<P>, second: Id<O>) -> Pair<P, O>,
 | 
			
		||||
 | 
			
		||||
	IS_PAIR = (ECS_IS_PAIR :: any) :: <P, O>(pair: Pair<P, O>) -> boolean,
 | 
			
		||||
	ECS_PAIR_FIRST = ECS_PAIR_FIRST :: <P, O>(pair: Pair<P, O>) -> Id<P>,
 | 
			
		||||
	ECS_PAIR_SECOND = ECS_PAIR_SECOND :: <P, O>(pair: Pair<P, O>) -> Id<O>,
 | 
			
		||||
	pair_first = (ecs_pair_first :: any) :: <P, O>(world: World, pair: Pair<P, O>) -> Id<P>,
 | 
			
		||||
	pair_second = (ecs_pair_second :: any) :: <P, O>(world: World, pair: Pair<P, O>) -> Id<O>,
 | 
			
		||||
	entity_index_get_alive = entity_index_get_alive,
 | 
			
		||||
 | 
			
		||||
	-- Inwards facing API for testing
 | 
			
		||||
	ECS_ID = ECS_ENTITY_T_LO,
 | 
			
		||||
	ECS_GENERATION_INC = ECS_GENERATION_INC,
 | 
			
		||||
| 
						 | 
				
			
			@ -3100,13 +3104,8 @@ return {
 | 
			
		|||
	ECS_ID_IS_WILDCARD = ECS_ID_IS_WILDCARD,
 | 
			
		||||
	ECS_ID_DELETE = ECS_ID_DELETE,
 | 
			
		||||
	ECS_META_RESET = ECS_META_RESET,
 | 
			
		||||
 | 
			
		||||
	IS_PAIR = (ECS_IS_PAIR :: any) :: <P, O>(pair: Pair<P, O>) -> boolean,
 | 
			
		||||
	ECS_PAIR_FIRST = ECS_PAIR_FIRST :: <P, O>(pair: Pair<P, O>) -> Id<P>,
 | 
			
		||||
	ECS_PAIR_SECOND = ECS_PAIR_SECOND :: <P, O>(pair: Pair<P, O>) -> Id<O>,
 | 
			
		||||
	pair_first = (ecs_pair_first :: any) :: <P, O>(world: World, pair: Pair<P, O>) -> Id<P>,
 | 
			
		||||
	pair_second = (ecs_pair_second :: any) :: <P, O>(world: World, pair: Pair<P, O>) -> Id<O>,
 | 
			
		||||
	entity_index_get_alive = entity_index_get_alive,
 | 
			
		||||
	ECS_COMBINE = ECS_COMBINE,
 | 
			
		||||
	ECS_ENTITY_MASK = ECS_ENTITY_MASK,
 | 
			
		||||
 | 
			
		||||
	archetype_append_to_records = archetype_append_to_records,
 | 
			
		||||
	id_record_ensure = id_record_ensure,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,6 +24,15 @@ type Id<T=unknown> = jecs.Id<T>
 | 
			
		|||
local entity_visualiser = require("@tools/entity_visualiser")
 | 
			
		||||
local dwi = entity_visualiser.stringify
 | 
			
		||||
 | 
			
		||||
TEST("another axen banger", function()
 | 
			
		||||
	-- taken from jecs.luau
 | 
			
		||||
	local world = jecs.world()
 | 
			
		||||
	world:range(2000, 3000)
 | 
			
		||||
 | 
			
		||||
	local e0v1_id = jecs.ECS_COMBINE(1000, 1) -- id can be both within or outside the world's range
 | 
			
		||||
	local e0v1 = world:entity(e0v1_id)
 | 
			
		||||
	assert(world:contains(e0v1)) -- fails
 | 
			
		||||
end)
 | 
			
		||||
TEST("Ensure archetype edges get cleaned", function()
 | 
			
		||||
	local A = jecs.component()
 | 
			
		||||
	local B = jecs.component()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue