Compare commits

...

3 Commits

Author SHA1 Message Date
d0a926302e add simple world setup 2026-03-15 23:08:59 +09:00
ecc036df36 Add Concord wrapper 2026-03-15 01:39:02 +09:00
975d133bae fix lappy and pool luals 2026-03-15 01:30:47 +09:00
13 changed files with 393 additions and 27 deletions

View File

@ -67,7 +67,7 @@ end
---@param name? string for debug purposes ---@param name? string for debug purposes
---@param max? number pool max size ---@param max? number pool max size
---@param efn? fun(...):boolean equal Function ---@param efn? fun(...):boolean equal Function
---@return Pool self -- ---@return Pool self
function pool:new(fn, rfn, name, max, efn) function pool:new(fn, rfn, name, max, efn)
-- local self = setmetatable({}, pool) -- local self = setmetatable({}, pool)
self.active = {} self.active = {}
@ -77,7 +77,6 @@ function pool:new(fn, rfn, name, max, efn)
self.efn = efn or defaultEqual self.efn = efn or defaultEqual
self.max = max > 0 and max or nil self.max = max > 0 and max or nil
self.name = name or "pool" self.name = name or "pool"
return self
end end
--- put entity to pool --- put entity to pool

View File

@ -1,45 +1,37 @@
local mode = { local world = {
require("src.modes.racing"), require("src.world.race")(),
require("src.modes.raising_sim") require("src.world.train")()
}; };
local actor = require("src.entities.shared.actor") local world_i = 1
local player = actor.load("player")
local source_cls = require("wrapper.lappy.new.source")
local source = source_cls.obj
local mode_i = 1
function love.load() function love.load()
source:load_to("asset/audio/bgm/Ensemble.mp3", "asset/audio/bgm/Ensemble.mp3", "stream") world[world_i]:load()
source:load_from("asset/audio/bgm/Ensemble.mp3"):play()
mode[mode_i].load(player)
end end
function love.update(dt) function love.update(dt)
mode[mode_i].update(dt) world[world_i]:update(dt)
end end
function love.draw() function love.draw()
mode[mode_i].draw() world[world_i]:draw()
end end
function love.keyreleased(key, scancode) function love.keyreleased(key, scancode)
if (key == "right") then if (key == "right") then
mode_i = mode_i + 1 world_i = world_i + 1
if (mode_i > 2) then if (world_i > 2) then
mode_i = 1 world_i = 1
end end
mode[mode_i].load(player) world[world_i]:reload()
end end
mode[mode_i].keyreleased(key, scancode) world[world_i]:keyreleased(key, scancode)
end end
function love.keypressed(key, scancode, isrepeat) function love.keypressed(key, scancode, isrepeat)
mode[mode_i].keypressed(key, scancode, isrepeat) world[world_i]:keypressed(key, scancode, isrepeat)
end end
function love.mousereleased(x, y, button, istouch, presses) function love.mousereleased(x, y, button, istouch, presses)
mode[mode_i].mousereleased(x, y, button, istouch, presses) world[world_i]:mousereleased(x, y, button, istouch, presses)
end end

View File

@ -0,0 +1,11 @@
local components = {}
components.dict = {
debug_label = "debug_label",
}
function components.debug_label (c, label)
c.data = label
end
return components

View File

@ -0,0 +1,23 @@
local vm = require("lib.vornmath")
local components = {}
components.dict = {
position = "position",
scale = "scale",
rotation = "rotation"
}
function components.position (c, x, y, z)
c.data = vm.vec3(x or 0, y or 0, z or 0)
end
function components.scale (c, sx, sy, sz)
c.data = vm.vec3(sx or 1, sy or 1, sz or 1)
end
function components.rotation (c, rx, ry, rz)
c.data = vm.vec3(rx or 0, ry or 0, rz or 0)
end
return components

View File

@ -0,0 +1,48 @@
local system_constructor = require("wrapper.Concord.system")
local debug_label = require("src.world.common.component.debug_label")
local transform = require("src.world.common.component.transform")
local system = {}
system.__index = system
system.pool = {
pool = {
debug_label.dict.debug_label,
transform.dict.position
}
}
system.components = {
[debug_label.dict.debug_label] = debug_label.debug_label,
[transform.dict.position] = transform.position
}
function system.new()
local new_system = system_constructor.new("debug_world_draw", system.pool)
if (new_system) then
for k, v in pairs(system) do
new_system[k] = v
end
return new_system
else
return nil
end
end
local function draw(text, x, y)
love.graphics.push()
love.graphics.print(text, x, y)
love.graphics.pop()
end
function system:draw()
for _, e in ipairs(self.pool) do
local text = e[debug_label.dict.debug_label].data
local x = e[transform.dict.position].data[1]
local y = e[transform.dict.position].data[2]
draw(text, x, y)
end
end
return system

View File

@ -0,0 +1,14 @@
local debug_world_draw = require("src.world.common.system.debug_world_draw")
local template = {}
template.default_data = {
position = {0, 0},
label = "debug"
}
function template.assembleDebug(e, data)
e:give(debug_world_draw.pool.pool[1], data.label)
e:give(debug_world_draw.pool.pool[2], data.position[1], data.position[2])
end
return template

View File

@ -0,0 +1,29 @@
local reap = require("lib.reap")
local BASE = reap.base_path(...)
local world = require("wrapper.Concord.world")
local debug_entity = require("src.world.common.template.debug_entity")
local wrapper = world:extend()
function wrapper:new()
wrapper.super.new(self, BASE, ".race")
end
function wrapper:load(_args)
wrapper.super.load(self, {
"src/world/common/system/"
}, {
{
assemblage = debug_entity.assembleDebug,
data = {
position = {0, 0},
label = "race world"
}
}
})
end
return wrapper

View File

@ -0,0 +1,29 @@
local reap = require("lib.reap")
local BASE = reap.base_path(...)
local world = require("wrapper.Concord.world")
local debug_entity = require("src.world.common.template.debug_entity")
local wrapper = world:extend()
function wrapper:new()
wrapper.super.new(self, BASE, ".train")
end
function wrapper:load(_args)
wrapper.super.load(self, {
"src/world/common/system/"
}, {
{
assemblage = debug_entity.assembleDebug,
data = {
position = {0, 0},
label = "train world"
}
}
})
end
return wrapper

View File

@ -0,0 +1,37 @@
local Concord = require("lib.Concord")
-- Modules
local Entity = Concord.entity
local Component = Concord.component
local System = Concord.system
local World = Concord.world
-- Containers
local Components = Concord.components
local constructor = {}
function constructor.default_component_lambda(c, data)
c.data = data
end
--- build component ecs component
---@param name string
---@param lambda? function(c, data)
function constructor.component(name, lambda)
local ok, value = Components.try(name)
if not ok then
return Component(name, lambda or constructor.default_component_lambda)
end
end
--- build component ecs state
---@param name string
function constructor.state(name)
local ok, value = Components.try(name)
if not ok then
return Component(name)
end
end
return constructor

View File

@ -0,0 +1,91 @@
local format = string.format
local reap = require("lib.reap")
local BASE = reap.base_path(...)
local component_builder = require(format("%s.component", BASE))
local Concord = require("lib.Concord")
-- Modules
local Entity = Concord.entity
local Component = Concord.component
local System = Concord.system
local World = Concord.world
-- Containers
local Components = Concord.components
local constructor = {}
--- build entity ecs
function constructor.new(system)
if (type(system) == "table") then
local e = Entity()
for _, s in pairs(system) do
for c, f in pairs(s.components) do
if (type(c) == "string") then
component_builder.component(c, f)
else
component_builder.state(f)
end
end
end
return e
elseif (system == nil) then
return Entity()
else
return nil
end
end
--- ensure component
---@param entity any
---@param name string
function constructor.ensure(entity, name, ...)
if (#{...} == 0) then
component_builder.state(name)
entity:ensure(name)
else
component_builder.component(name)
entity:ensure(name, ...)
end
end
--- give component
---@param entity any
---@param name string
function constructor.give(entity, name, ...)
if (#{...} == 0) then
component_builder.state(name)
entity:give(name)
else
component_builder.component(name)
entity:give(name, ...)
end
end
function constructor.remove(entity, name)
if Components.has(name) == false then
return false, nil
else
if entity:has(name) then
local data = entity[name]
entity:remove(name)
return true, data
else
return false, nil
end
end
end
function constructor.destroy(entity)
local all_c = entity:getComponents()
for c_id, c in ipairs(all_c) do
entity:remove(c)
print("destroy", c_id, c)
end
entity:destroy()
end
return constructor

View File

@ -0,0 +1,84 @@
local insert = table.insert
local Concord = require("lib.Concord")
-- Modules
local Entity = Concord.entity
local Component = Concord.component
local System = Concord.system
local World = Concord.world
-- Containers
local Components = Concord.components
local constructor = {}
constructor.systems = {}
local function is_component_complete(pool)
local is_complete = true
for _, v in pairs(pool) do
for _, c in ipairs(v) do
if (Components.has(c) == false) then
is_complete = false
break
end
end
if (not is_complete) then
break
end
end
return is_complete
end
function constructor.new(name, pool)
if (constructor.systems[name]) then
return constructor.systems[name]
else
if (type(pool) == "table") then
if (is_component_complete(pool)) then
local self = System(pool)
self.name = name
constructor.systems[name] = self
return self
else
return nil
end
else
error("new system register error. pool and wrapper should be a table.")
return nil
end
end
end
function constructor.add(world, path)
local namespace = {}
if (type(path) == "string") then
Concord.utils.loadNamespace(path, namespace)
else
for k,v in pairs(path) do
if type(v) == "string" then
local new_namespace = {}
Concord.utils.loadNamespace(v, new_namespace)
for l, w in pairs(new_namespace) do
namespace[l] = w
end
else
insert(namespace, v)
end
end
end
for k,v in pairs(namespace) do
local new_sys = v.new()
if (new_sys == nil) then
else
if not world:hasSystem(new_sys) then
world:addSystems(new_sys)
end
end
end
end
return constructor

View File

@ -1,12 +1,12 @@
local format = string.format local format = string.format
local reap = require("libs.reap") local reap = require("lib.reap")
local BASE = reap.base_path(...) local BASE = reap.base_path(...)
local component_builder = require(format("%s.component", BASE)) local component_builder = require(format("%s.component", BASE))
local entity_builder = require(format("%s.entity", BASE)) local entity_builder = require(format("%s.entity", BASE))
local Concord = require("libs.Concord") local Concord = require("lib.Concord")
-- Modules -- Modules
local Entity = Concord.entity local Entity = Concord.entity
@ -20,6 +20,7 @@ local wrapper = main_wrapper:extend()
function wrapper:new(path, name) function wrapper:new(path, name)
wrapper.super.new(self, path, name) wrapper.super.new(self, path, name)
self.is_loaded = false
self.world = World() self.world = World()
end end
@ -56,9 +57,17 @@ end
function wrapper:load(system_paths, entities_data) function wrapper:load(system_paths, entities_data)
load_systems(self.world, system_paths) load_systems(self.world, system_paths)
load_entities(self.world, entities_data) load_entities(self.world, entities_data)
self.is_loaded = true
self.world:emit("load") self.world:emit("load")
end end
function wrapper:reload(system_paths, entities_data)
if not self.is_loaded then
self:load(system_paths, entities_data)
end
self.world:emit("reload")
end
function wrapper:draw() function wrapper:draw()
self.world:emit("draw") self.world:emit("draw")
end end

View File

@ -1,4 +1,4 @@
local classic = require "lib.classic" local classic = require "lib.classic.classic"
---@class lappy.world : lib.classic.class ---@class lappy.world : lib.classic.class
local wrapper = classic:extend() local wrapper = classic:extend()