mirror of
https://github.com/BlackMATov/evolved.lua.git
synced 2025-12-13 19:48:00 +07:00
simplify api
This commit is contained in:
@@ -1,32 +1,32 @@
|
|||||||
local evo = require 'evolved.evolved'
|
local evo = require 'evolved.evolved'
|
||||||
|
|
||||||
local singles = {
|
local singles = {
|
||||||
delta_time = evo.singles.create(0.016),
|
delta_time = evo.singles.single(0.016),
|
||||||
}
|
}
|
||||||
|
|
||||||
local fragments = {
|
local fragments = {
|
||||||
position = evo.registry.create_entity(),
|
position = evo.registry.entity(),
|
||||||
velocity = evo.registry.create_entity(),
|
velocity = evo.registry.entity(),
|
||||||
}
|
}
|
||||||
|
|
||||||
local queries = {
|
local queries = {
|
||||||
bodies = evo.registry.create_query(
|
bodies = evo.registry.query(
|
||||||
fragments.position,
|
fragments.position,
|
||||||
fragments.velocity),
|
fragments.velocity),
|
||||||
}
|
}
|
||||||
|
|
||||||
do
|
do
|
||||||
local entity = evo.registry.create_entity()
|
local entity = evo.registry.entity()
|
||||||
local position = evo.vectors.vector2(512, 50)
|
local position = evo.vectors.vector2(512, 50)
|
||||||
local velocity = evo.vectors.vector2(math.random(-20, 20), 20)
|
local velocity = evo.vectors.vector2(math.random(-20, 20), 20)
|
||||||
evo.registry.insert_component(entity, fragments.position, position)
|
evo.registry.insert(entity, fragments.position, position)
|
||||||
evo.registry.insert_component(entity, fragments.velocity, velocity)
|
evo.registry.insert(entity, fragments.velocity, velocity)
|
||||||
end
|
end
|
||||||
|
|
||||||
do
|
do
|
||||||
local dt = evo.singles.get(singles.delta_time)
|
local dt = evo.singles.get(singles.delta_time)
|
||||||
|
|
||||||
for chunk in evo.registry.execute_query(queries.bodies) do
|
for chunk in evo.registry.execute(queries.bodies) do
|
||||||
local ps = chunk.components[fragments.position]
|
local ps = chunk.components[fragments.position]
|
||||||
local vs = chunk.components[fragments.velocity]
|
local vs = chunk.components[fragments.velocity]
|
||||||
|
|
||||||
|
|||||||
@@ -17,57 +17,57 @@ evolved_chunk_mt.__index = evolved_chunk_mt
|
|||||||
|
|
||||||
---@return evolved.entity
|
---@return evolved.entity
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function registry.create_entity() end
|
function registry.entity() end
|
||||||
|
|
||||||
---@param entity evolved.entity
|
---@param entity evolved.entity
|
||||||
function registry.destroy_entity(entity) end
|
function registry.destroy(entity) end
|
||||||
|
|
||||||
---@param entity evolved.entity
|
---@param entity evolved.entity
|
||||||
---@param fragment evolved.entity
|
---@param fragment evolved.entity
|
||||||
---@return any
|
---@return any
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function registry.get_component(entity, fragment) end
|
function registry.get(entity, fragment) end
|
||||||
|
|
||||||
---@param entity evolved.entity
|
---@param entity evolved.entity
|
||||||
---@param fragment evolved.entity
|
---@param fragment evolved.entity
|
||||||
---@return boolean
|
---@return boolean
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function registry.has_component(entity, fragment) end
|
function registry.has(entity, fragment) end
|
||||||
|
|
||||||
---@param entity evolved.entity
|
---@param entity evolved.entity
|
||||||
---@param ... evolved.entity
|
---@param ... evolved.entity
|
||||||
---@return boolean
|
---@return boolean
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function registry.has_all_components(entity, ...) end
|
function registry.has_all(entity, ...) end
|
||||||
|
|
||||||
---@param entity evolved.entity
|
---@param entity evolved.entity
|
||||||
---@param ... evolved.entity
|
---@param ... evolved.entity
|
||||||
---@return boolean
|
---@return boolean
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function registry.has_any_components(entity, ...) end
|
function registry.has_any(entity, ...) end
|
||||||
|
|
||||||
---@param entity evolved.entity
|
---@param entity evolved.entity
|
||||||
---@param fragment evolved.entity
|
---@param fragment evolved.entity
|
||||||
---@param component any
|
---@param component any
|
||||||
function registry.assign_component(entity, fragment, component) end
|
function registry.assign(entity, fragment, component) end
|
||||||
|
|
||||||
---@param entity evolved.entity
|
---@param entity evolved.entity
|
||||||
---@param fragment evolved.entity
|
---@param fragment evolved.entity
|
||||||
---@param component any
|
---@param component any
|
||||||
function registry.insert_component(entity, fragment, component) end
|
function registry.insert(entity, fragment, component) end
|
||||||
|
|
||||||
---@param entity evolved.entity
|
---@param entity evolved.entity
|
||||||
---@param fragment evolved.entity
|
---@param fragment evolved.entity
|
||||||
function registry.remove_component(entity, fragment) end
|
function registry.remove(entity, fragment) end
|
||||||
|
|
||||||
---@param ... evolved.entity
|
---@param ... evolved.entity
|
||||||
---@return evolved.query
|
---@return evolved.query
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function registry.create_query(...) end
|
function registry.query(...) end
|
||||||
|
|
||||||
---@param query evolved.query
|
---@param query evolved.query
|
||||||
---@return fun(): evolved.chunk?
|
---@return fun(): evolved.chunk?
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function registry.execute_query(query) end
|
function registry.execute(query) end
|
||||||
|
|
||||||
return registry
|
return registry
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ local singles = {}
|
|||||||
---@param component any
|
---@param component any
|
||||||
---@return evolved.entity
|
---@return evolved.entity
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function singles.create(component)
|
function singles.single(component)
|
||||||
local single = registry.create_entity()
|
local single = registry.entity()
|
||||||
registry.insert_component(single, single, component)
|
registry.insert(single, single, component)
|
||||||
return single
|
return single
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -16,20 +16,20 @@ end
|
|||||||
---@return any
|
---@return any
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function singles.get(single)
|
function singles.get(single)
|
||||||
return registry.get_component(single, single)
|
return registry.get(single, single)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param single evolved.entity
|
---@param single evolved.entity
|
||||||
---@return boolean
|
---@return boolean
|
||||||
---@nodiscard
|
---@nodiscard
|
||||||
function singles.has(single)
|
function singles.has(single)
|
||||||
return registry.has_component(single, single)
|
return registry.has(single, single)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param single evolved.entity
|
---@param single evolved.entity
|
||||||
---@param component any
|
---@param component any
|
||||||
function singles.assign(single, component)
|
function singles.assign(single, component)
|
||||||
registry.assign_component(single, single, component)
|
registry.assign(single, single, component)
|
||||||
end
|
end
|
||||||
|
|
||||||
return singles
|
return singles
|
||||||
|
|||||||
Reference in New Issue
Block a user