mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-11-04 02:49:18 +00:00 
			
		
		
		
	Handle removal of (*, R) pairs
This commit is contained in:
		
							parent
							
								
									0fea5a259d
								
							
						
					
					
						commit
						3174e8d80b
					
				
					 4 changed files with 31 additions and 2 deletions
				
			
		| 
						 | 
					@ -2,6 +2,14 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Unreleased
 | 
					## Unreleased
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## 0.6.1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Changed
 | 
				
			||||||
 | 
					- Entity types now unions with numbers should allow for easier time casting while not causing regressing previous behaviours
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### Fixed
 | 
				
			||||||
 | 
					- Fixed a critical bug with `(*, R)` pairs not being removed when `R` is deleted
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 0.6.0
 | 
					## 0.6.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Added
 | 
					### Added
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1413,11 +1413,11 @@ local function world_delete(world: ecs_world_t, entity: i53)
 | 
				
			||||||
				for i = tr, tr + tr_count - 1 do
 | 
									for i = tr, tr + tr_count - 1 do
 | 
				
			||||||
					ids[types[i]] = true
 | 
										ids[types[i]] = true
 | 
				
			||||||
				end
 | 
									end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				local n = #entities
 | 
									local n = #entities
 | 
				
			||||||
				table.move(entities, 1, n, count + 1, children)
 | 
									table.move(entities, 1, n, count + 1, children)
 | 
				
			||||||
				count += n
 | 
									count += n
 | 
				
			||||||
			end
 | 
								end
 | 
				
			||||||
 | 
					 | 
				
			||||||
			for _, child in children do
 | 
								for _, child in children do
 | 
				
			||||||
				for id in ids do
 | 
									for id in ids do
 | 
				
			||||||
					world_remove(world, child, id)
 | 
										world_remove(world, child, id)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -289,6 +289,27 @@ TEST("world:contains()", function()
 | 
				
			||||||
end)
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
TEST("world:delete()", function()
 | 
					TEST("world:delete()", function()
 | 
				
			||||||
 | 
						do CASE "remove (*, R) pairs when relationship is invalidated"
 | 
				
			||||||
 | 
							print("-------")
 | 
				
			||||||
 | 
							local world = jecs.world()
 | 
				
			||||||
 | 
							local e1 = world:entity()
 | 
				
			||||||
 | 
							local e2 = world:entity()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							local A = world:component()
 | 
				
			||||||
 | 
							local B = world:component()
 | 
				
			||||||
 | 
							local C = world:component()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							world:add(e1, pair(e2, A))
 | 
				
			||||||
 | 
							world:add(e1, B) -- Some stable component that should not be removed in the process
 | 
				
			||||||
 | 
							world:add(e1, pair(e2, C))
 | 
				
			||||||
 | 
							world:delete(e2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							CHECK(not world:contains(e2))
 | 
				
			||||||
 | 
							CHECK(not world:has(e1, pair(e2, A)))
 | 
				
			||||||
 | 
							CHECK(world:has(e1, B))
 | 
				
			||||||
 | 
							CHECK(not world:has(e1, pair(e2, C)))
 | 
				
			||||||
 | 
							CHECK(world:contains(e1))
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
	do CASE "remove pair when relationship is deleted"
 | 
						do CASE "remove pair when relationship is deleted"
 | 
				
			||||||
		local world = jecs.world()
 | 
							local world = jecs.world()
 | 
				
			||||||
		local e1 = world:entity()
 | 
							local e1 = world:entity()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
[package]
 | 
					[package]
 | 
				
			||||||
name = "ukendio/jecs"
 | 
					name = "ukendio/jecs"
 | 
				
			||||||
version = "0.6.0"
 | 
					version = "0.6.1"
 | 
				
			||||||
registry = "https://github.com/UpliftGames/wally-index"
 | 
					registry = "https://github.com/UpliftGames/wally-index"
 | 
				
			||||||
realm = "shared"
 | 
					realm = "shared"
 | 
				
			||||||
license = "MIT"
 | 
					license = "MIT"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue