mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-10-31 01:09:16 +00:00 
			
		
		
		
	Add back multret ;C
This commit is contained in:
		
							parent
							
								
									7c6184daae
								
							
						
					
					
						commit
						3175d5e94c
					
				
					 2 changed files with 89 additions and 4 deletions
				
			
		|  | @ -364,7 +364,55 @@ local function world_parent(world: World, entity: i53) | ||||||
| 	return world_target(world, entity, EcsChildOf) | 	return world_target(world, entity, EcsChildOf) | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| local function world_get(world: World, entity: i53, id: i53) | local world_get: (world: World, entityId: i53, a: i53, b: i53?, c: i53?, d: i53?, e: i53?) -> (...any) | ||||||
|  | do | ||||||
|  |     -- Keeping the function as small as possible to enable inlining | ||||||
|  |     local records | ||||||
|  |     local columns | ||||||
|  |     local row | ||||||
|  | 
 | ||||||
|  |     local function fetch(id) | ||||||
|  |     	local tr = records[id] | ||||||
|  | 
 | ||||||
|  |     	if not tr then | ||||||
|  |     		return nil | ||||||
|  |     	end | ||||||
|  | 
 | ||||||
|  |     	return columns[tr.column][row] | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     function world_get(world: World, entity: i53, a: i53, b: i53?, c: i53?, d: i53?, e: i53?): ...any | ||||||
|  |     	local record = world.entityIndex.sparse[entity] | ||||||
|  |     	if not record then | ||||||
|  |     		return nil | ||||||
|  |     	end | ||||||
|  | 
 | ||||||
|  |     	local archetype = record.archetype | ||||||
|  |     	if not archetype then | ||||||
|  |     	   return nil | ||||||
|  |     	end | ||||||
|  | 
 | ||||||
|  |     	records = archetype.records | ||||||
|  |     	columns = archetype.columns | ||||||
|  |     	row = record.row | ||||||
|  | 
 | ||||||
|  |     	local va = fetch(a) | ||||||
|  | 
 | ||||||
|  |     	if not b then | ||||||
|  |     		return va | ||||||
|  |     	elseif not c then | ||||||
|  |     		return va, fetch(b) | ||||||
|  |     	elseif not d then | ||||||
|  |             return va, fetch(b), fetch(c) | ||||||
|  |     	elseif not e then | ||||||
|  |             return va, fetch(b), fetch(c), fetch(d) | ||||||
|  |     	else | ||||||
|  |     		error("args exceeded") | ||||||
|  |     	end | ||||||
|  |     end | ||||||
|  | end | ||||||
|  | 
 | ||||||
|  | local function world_get_one_inline(world: World, entity: i53, id: i53) | ||||||
|    	local record = world.entityIndex.sparse[entity] |    	local record = world.entityIndex.sparse[entity] | ||||||
|    	if not record then |    	if not record then | ||||||
|   		return nil |   		return nil | ||||||
|  | @ -379,11 +427,10 @@ local function world_get(world: World, entity: i53, id: i53) | ||||||
|     if not tr then |     if not tr then | ||||||
|         return nil |         return nil | ||||||
|     end |     end | ||||||
| 
 |  | ||||||
|    	return archetype.columns[tr.column][record.row] |    	return archetype.columns[tr.column][record.row] | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| local function world_has(world: World, entity: i53, id: i53): boolean | local function world_has_one_inline(world: World, entity: i53, id: i53): boolean | ||||||
|    	local record = world.entityIndex.sparse[entity] |    	local record = world.entityIndex.sparse[entity] | ||||||
|    	if not record then |    	if not record then | ||||||
|   		return false |   		return false | ||||||
|  | @ -397,6 +444,28 @@ local function world_has(world: World, entity: i53, id: i53): boolean | ||||||
|     return archetype.records[id] ~= nil |     return archetype.records[id] ~= nil | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
|  | local function world_has(world: World, entity: number, ...: i53): boolean | ||||||
|  |    	local record = world.entityIndex.sparse[entity] | ||||||
|  |    	if not record then | ||||||
|  |   		return false | ||||||
|  |    	end | ||||||
|  | 
 | ||||||
|  |    	local archetype = record.archetype | ||||||
|  |    	if not archetype then | ||||||
|  | 	   return false | ||||||
|  |    	end | ||||||
|  | 
 | ||||||
|  |     local records = archetype.records | ||||||
|  | 
 | ||||||
|  |     for i = 1, select("#", ...) do | ||||||
|  |         if not records[select(i, ...)] then | ||||||
|  |             return false | ||||||
|  |         end | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     return true | ||||||
|  | end | ||||||
|  | 
 | ||||||
| local function archetype_ensure(world: World, types, prev): Archetype | local function archetype_ensure(world: World, types, prev): Archetype | ||||||
| 	if #types < 1 then | 	if #types < 1 then | ||||||
| 		return world.ROOT_ARCHETYPE | 		return world.ROOT_ARCHETYPE | ||||||
|  | @ -467,7 +536,7 @@ local function archetype_traverse_add(world: World, id: i53, from: Archetype): A | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| local function invoke_hook(world: World, hook_id: number, id: i53, entity: i53, data: any?) | local function invoke_hook(world: World, hook_id: number, id: i53, entity: i53, data: any?) | ||||||
|     local hook = world_get(world, id, hook_id) |     local hook = world_get_one_inline(world, id, hook_id) | ||||||
|     if hook then |     if hook then | ||||||
|         hook(entity, data) |         hook(entity, data) | ||||||
|     end |     end | ||||||
|  |  | ||||||
|  | @ -698,6 +698,22 @@ TEST("world:has()", function() | ||||||
| 
 | 
 | ||||||
|         CHECK(world:has(e, Tag)) |         CHECK(world:has(e, Tag)) | ||||||
|     end |     end | ||||||
|  | 
 | ||||||
|  |     do CASE "should return false when missing one tag" | ||||||
|  |         local world = jecs.World.new() | ||||||
|  | 
 | ||||||
|  |         local A = world:component() | ||||||
|  |         local B = world:component() | ||||||
|  |         local C = world:component() | ||||||
|  |         local D = world:component() | ||||||
|  | 
 | ||||||
|  |         local e = world:entity() | ||||||
|  |         world:add(e, A) | ||||||
|  |         world:add(e, C) | ||||||
|  |         world:add(e, D) | ||||||
|  | 
 | ||||||
|  |         CHECK(world:has(e, A, B, C, D) == false) | ||||||
|  |     end | ||||||
| end) | end) | ||||||
| 
 | 
 | ||||||
| TEST("world:component()", function() | TEST("world:component()", function() | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue