mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-11-03 18:39:19 +00:00 
			
		
		
		
	Always swap entity
This commit is contained in:
		
							parent
							
								
									6c1793f853
								
							
						
					
					
						commit
						362490d25e
					
				
					 2 changed files with 14 additions and 11 deletions
				
			
		
							
								
								
									
										11
									
								
								jecs.luau
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								jecs.luau
									
									
									
									
									
								
							| 
						 | 
				
			
			@ -2174,7 +2174,7 @@ local function world_new()
 | 
			
		|||
	local function inner_entity_index_try_get_any(entity: number): Record?
 | 
			
		||||
		local r = eindex_sparse_array[ECS_ENTITY_T_LO(entity)]
 | 
			
		||||
 | 
			
		||||
		if not r then
 | 
			
		||||
		if not r or r.dense == 0 then
 | 
			
		||||
			return nil
 | 
			
		||||
		end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -2568,15 +2568,6 @@ local function world_new()
 | 
			
		|||
					dense = index
 | 
			
		||||
				end
 | 
			
		||||
 | 
			
		||||
				local any = eindex_dense_array[dense]
 | 
			
		||||
				if dense <= alive_count then
 | 
			
		||||
					if any ~= entity then
 | 
			
		||||
						error("Entity ID is already in use with a different generation")
 | 
			
		||||
					else
 | 
			
		||||
						return entity
 | 
			
		||||
					end
 | 
			
		||||
				end
 | 
			
		||||
 | 
			
		||||
				local e_swap = eindex_dense_array[dense]
 | 
			
		||||
				local r_swap = inner_entity_index_try_get_any(e_swap :: number) :: Record
 | 
			
		||||
				alive_count += 1
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -885,6 +885,7 @@ TEST("world:each()", function()
 | 
			
		|||
	end
 | 
			
		||||
end)
 | 
			
		||||
 | 
			
		||||
FOCUS()
 | 
			
		||||
TEST("world:range()", function()
 | 
			
		||||
	do CASE "delete outside partitioned range"
 | 
			
		||||
		local server = jecs.world()
 | 
			
		||||
| 
						 | 
				
			
			@ -895,9 +896,20 @@ TEST("world:range()", function()
 | 
			
		|||
 | 
			
		||||
		local e1 = server:entity()
 | 
			
		||||
		CHECK((e1::number)< 1000)
 | 
			
		||||
		server:delete(e1)
 | 
			
		||||
		local e2 = client:entity(e1)
 | 
			
		||||
		CHECK(e2 == e1)
 | 
			
		||||
		client:delete(e1)
 | 
			
		||||
		local A = client:component()
 | 
			
		||||
		client:set(e2, A, true)
 | 
			
		||||
		CHECK(client:get(e2, A))
 | 
			
		||||
		client:delete(e2)
 | 
			
		||||
		local e3 = client:entity()
 | 
			
		||||
		CHECK(ECS_ID(e3::number) == 1000)
 | 
			
		||||
 | 
			
		||||
		local e1v1 = server:entity()
 | 
			
		||||
		local e4 = client:entity(e1v1)
 | 
			
		||||
		CHECK(ECS_ID(e4::number) == e1)
 | 
			
		||||
		CHECK(ECS_GENERATION(e4::number) == 1)
 | 
			
		||||
	end
 | 
			
		||||
	do CASE "under range start"
 | 
			
		||||
		local world = jecs.world()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in a new issue