mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-11-04 02:49:18 +00:00 
			
		
		
		
	always check OnDelete condition
This commit is contained in:
		
							parent
							
								
									ebc39c8b28
								
							
						
					
					
						commit
						9c09686a69
					
				
					 2 changed files with 23 additions and 9 deletions
				
			
		
							
								
								
									
										15
									
								
								jecs.luau
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								jecs.luau
									
									
									
									
									
								
							| 
						 | 
					@ -714,12 +714,12 @@ local function id_record_ensure(world: World, id: Entity): ComponentRecord
 | 
				
			||||||
		if world_has_one_inline(world, relation, EcsExclusive) then
 | 
							if world_has_one_inline(world, relation, EcsExclusive) then
 | 
				
			||||||
			is_exclusive = true
 | 
								is_exclusive = true
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
	else
 | 
						end
 | 
				
			||||||
		local cleanup_policy = world_target(world, relation, EcsOnDelete, 0)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if cleanup_policy == EcsDelete then
 | 
						local cleanup_policy = world_target(world, relation, EcsOnDelete, 0)
 | 
				
			||||||
			has_delete = true
 | 
					
 | 
				
			||||||
		end
 | 
						if cleanup_policy == EcsDelete then
 | 
				
			||||||
 | 
							has_delete = true
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local on_add, on_change, on_remove = world_get(world,
 | 
						local on_add, on_change, on_remove = world_get(world,
 | 
				
			||||||
| 
						 | 
					@ -2766,7 +2766,7 @@ local function world_new()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if idr then
 | 
							if idr then
 | 
				
			||||||
			local flags = idr.flags
 | 
								local flags = idr.flags
 | 
				
			||||||
			if bit32.btest(flags, ECS_ID_DELETE) then
 | 
								if (bit32.btest(flags, ECS_ID_DELETE) == true) then
 | 
				
			||||||
				for archetype_id in idr.records do
 | 
									for archetype_id in idr.records do
 | 
				
			||||||
					local idr_archetype = archetypes[archetype_id]
 | 
										local idr_archetype = archetypes[archetype_id]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2873,7 +2873,8 @@ local function world_new()
 | 
				
			||||||
		if idr_r then
 | 
							if idr_r then
 | 
				
			||||||
			local archetype_ids = idr_r.records
 | 
								local archetype_ids = idr_r.records
 | 
				
			||||||
			local flags = idr_r.flags
 | 
								local flags = idr_r.flags
 | 
				
			||||||
			if bit32.btest(flags, ECS_ID_DELETE) then
 | 
								local has_delete_policy = bit32.btest(flags, ECS_ID_DELETE)
 | 
				
			||||||
 | 
								if has_delete_policy then
 | 
				
			||||||
				for archetype_id in archetype_ids do
 | 
									for archetype_id in archetype_ids do
 | 
				
			||||||
					local idr_r_archetype = archetypes[archetype_id]
 | 
										local idr_r_archetype = archetypes[archetype_id]
 | 
				
			||||||
					local entities = idr_r_archetype.entities
 | 
										local entities = idr_r_archetype.entities
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -24,6 +24,19 @@ type Id<T=unknown> = jecs.Id<T>
 | 
				
			||||||
local entity_visualiser = require("@tools/entity_visualiser")
 | 
					local entity_visualiser = require("@tools/entity_visualiser")
 | 
				
			||||||
local dwi = entity_visualiser.stringify
 | 
					local dwi = entity_visualiser.stringify
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					TEST("ardi", function()
 | 
				
			||||||
 | 
						local world = jecs.world()
 | 
				
			||||||
 | 
						local r = world:entity()
 | 
				
			||||||
 | 
						world:add(r, jecs.pair(jecs.OnDelete, jecs.Delete))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						local e = world:entity()
 | 
				
			||||||
 | 
						local e1 = world:entity()
 | 
				
			||||||
 | 
						world:add(e, jecs.pair(r, e1))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						world:delete(r)
 | 
				
			||||||
 | 
						CHECK(not world:contains(e))
 | 
				
			||||||
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST("dai", function()
 | 
					TEST("dai", function()
 | 
				
			||||||
	local world = jecs.world()
 | 
						local world = jecs.world()
 | 
				
			||||||
	local C = world:component()
 | 
						local C = world:component()
 | 
				
			||||||
| 
						 | 
					@ -621,9 +634,9 @@ TEST("world:delete()", function()
 | 
				
			||||||
	    world:add(e1, ct)
 | 
						    world:add(e1, ct)
 | 
				
			||||||
	    world:add(e2, jecs.pair(ct, dummy))
 | 
						    world:add(e2, jecs.pair(ct, dummy))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    world:delete(dummy)
 | 
						    -- world:delete(dummy)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    CHECK(world:contains(e2))
 | 
						    -- CHECK(world:contains(e2))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	    world:delete(ct)
 | 
						    world:delete(ct)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue