mirror of
				https://github.com/Ukendio/jecs.git
				synced 2025-11-03 18:39:19 +00:00 
			
		
		
		
	Low foot print ids
This commit is contained in:
		
							parent
							
								
									63f40a22c0
								
							
						
					
					
						commit
						818dfdd216
					
				
					 2 changed files with 32 additions and 26 deletions
				
			
		
							
								
								
									
										56
									
								
								lib/init.lua
									
									
									
									
									
								
							
							
						
						
									
										56
									
								
								lib/init.lua
									
									
									
									
									
								
							| 
						 | 
					@ -100,49 +100,52 @@ local function ECS_COMBINE(source: number, target: number): i53
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function ECS_IS_PAIR(e: number)
 | 
					local function ECS_IS_PAIR(e: number)
 | 
				
			||||||
	return (e % 2 ^ 4) // FLAGS_PAIR ~= 0
 | 
						if e > ECS_ENTITY_MASK then
 | 
				
			||||||
 | 
							return (e % 2 ^ 4) // FLAGS_PAIR ~= 0
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						return false
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- HIGH 24 bits LOW 24 bits
 | 
					-- HIGH 24 bits LOW 24 bits
 | 
				
			||||||
local function ECS_GENERATION(e: i53)
 | 
					local function ECS_GENERATION(e: i53)
 | 
				
			||||||
	e = e // 0x10
 | 
						if e > ECS_ENTITY_MASK then
 | 
				
			||||||
	return e % ECS_GENERATION_MASK
 | 
							e = e // 0x10
 | 
				
			||||||
 | 
							return e % ECS_GENERATION_MASK
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						return 0
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function ECS_GENERATION_INC(e: i53)
 | 
					local function ECS_GENERATION_INC(e: i53)
 | 
				
			||||||
	local flags = e // 0x10
 | 
						if e > ECS_ENTITY_MASK then
 | 
				
			||||||
	local id = flags // ECS_ENTITY_MASK
 | 
							local flags = e // 0x10
 | 
				
			||||||
	local generation = flags % ECS_GENERATION_MASK
 | 
							local id = flags // ECS_ENTITY_MASK
 | 
				
			||||||
 | 
							local generation = flags % ECS_GENERATION_MASK
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return ECS_COMBINE(id, generation + 1) + flags
 | 
							return ECS_COMBINE(id, generation + 1) + flags
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						return ECS_COMBINE(e, 1)
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- FIRST gets the high ID
 | 
					-- FIRST gets the high ID
 | 
				
			||||||
local function ECS_ENTITY_T_HI(e: i53): i24
 | 
					local function ECS_ENTITY_T_HI(e: i53): i24
 | 
				
			||||||
	e = e // 0x10
 | 
						if e > ECS_ENTITY_MASK then
 | 
				
			||||||
	return e % ECS_ENTITY_MASK
 | 
							e = e // 0x10
 | 
				
			||||||
 | 
							return e % ECS_ENTITY_MASK
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						return e
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- SECOND
 | 
					-- SECOND
 | 
				
			||||||
local function ECS_ENTITY_T_LO(e: i53)
 | 
					local function ECS_ENTITY_T_LO(e: i53)
 | 
				
			||||||
	e = e // 0x10
 | 
						if e > ECS_ENTITY_MASK then
 | 
				
			||||||
	return e // ECS_ENTITY_MASK
 | 
							e = e // 0x10
 | 
				
			||||||
 | 
							return e // ECS_ENTITY_MASK
 | 
				
			||||||
 | 
						end
 | 
				
			||||||
 | 
						return e
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function ECS_PAIR(pred: i53, obj: i53): i53
 | 
					local function ECS_PAIR(pred: i53, obj: i53): i53
 | 
				
			||||||
	local first
 | 
						return ECS_COMBINE(ECS_ENTITY_T_LO(obj), ECS_ENTITY_T_LO(pred)) + addFlags(--[[isPair]] true)
 | 
				
			||||||
	local second: number = WILDCARD
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if pred == WILDCARD then
 | 
					 | 
				
			||||||
		first = obj
 | 
					 | 
				
			||||||
	elseif obj == WILDCARD then
 | 
					 | 
				
			||||||
		first = pred
 | 
					 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
		first = obj
 | 
					 | 
				
			||||||
		second = ECS_ENTITY_T_LO(pred)
 | 
					 | 
				
			||||||
	end
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return ECS_COMBINE(ECS_ENTITY_T_LO(first), second) + addFlags(--[[isPair]] true)
 | 
					 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function getAlive(entityIndex: EntityIndex, id: i24)
 | 
					local function getAlive(entityIndex: EntityIndex, id: i24)
 | 
				
			||||||
| 
						 | 
					@ -161,7 +164,8 @@ local function ECS_PAIR_OBJECT(entityIndex, e)
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
local function nextEntityId(entityIndex, index: i24): i53
 | 
					local function nextEntityId(entityIndex, index: i24): i53
 | 
				
			||||||
	local id = ECS_COMBINE(index, 0)
 | 
						--local id = ECS_COMBINE(index, 0)
 | 
				
			||||||
 | 
						local id = index
 | 
				
			||||||
	entityIndex.sparse[id] = {
 | 
						entityIndex.sparse[id] = {
 | 
				
			||||||
		dense = index,
 | 
							dense = index,
 | 
				
			||||||
	} :: Record
 | 
						} :: Record
 | 
				
			||||||
| 
						 | 
					@ -372,6 +376,7 @@ function World.target(world: World, entity: i53, relation: i24): i24?
 | 
				
			||||||
	if not archetype then
 | 
						if not archetype then
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	local componentRecord = world.componentIndex[ECS_PAIR(relation, WILDCARD)]
 | 
						local componentRecord = world.componentIndex[ECS_PAIR(relation, WILDCARD)]
 | 
				
			||||||
	if not componentRecord then
 | 
						if not componentRecord then
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
| 
						 | 
					@ -822,6 +827,7 @@ function World.__iter(world: World): () -> (number?, unknown?)
 | 
				
			||||||
		if not lastEntity then
 | 
							if not lastEntity then
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		end
 | 
							end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		last = lastEntity
 | 
							last = lastEntity
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		local record = sparse[entityId]
 | 
							local record = sparse[entityId]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -208,6 +208,7 @@ TEST("world", function()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		local pair = ECS_PAIR(e2, e3)
 | 
							local pair = ECS_PAIR(e2, e3)
 | 
				
			||||||
		CHECK(IS_PAIR(pair) == true)
 | 
							CHECK(IS_PAIR(pair) == true)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		CHECK(ECS_PAIR_RELATION(world.entityIndex, pair) == e2)
 | 
							CHECK(ECS_PAIR_RELATION(world.entityIndex, pair) == e2)
 | 
				
			||||||
		CHECK(ECS_PAIR_OBJECT(world.entityIndex, pair) == e3)
 | 
							CHECK(ECS_PAIR_OBJECT(world.entityIndex, pair) == e3)
 | 
				
			||||||
	end
 | 
						end
 | 
				
			||||||
| 
						 | 
					@ -350,4 +351,3 @@ TEST("world", function()
 | 
				
			||||||
end)
 | 
					end)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
FINISH()
 | 
					FINISH()
 | 
				
			||||||
 | 
					 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue