mirror of
https://github.com/Ukendio/jecs.git
synced 2025-11-14 15:32:53 +00:00
Compare commits
No commits in common. "07593a4b99366c07446838743832cb0cb2abee9a" and "57e653fa78bfd838ef4a5ad0734449579cf740ef" have entirely different histories.
07593a4b99
...
57e653fa78
3 changed files with 121 additions and 73 deletions
|
|
@ -2,9 +2,12 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
local jecs = require(ReplicatedStorage.ecs)
|
local jecs = require(ReplicatedStorage.ecs)
|
||||||
local schedule = require(ReplicatedStorage.schedule)
|
local schedule = require(ReplicatedStorage.schedule)
|
||||||
|
|
||||||
local heartbeat = schedule(world,
|
local SYSTEM = schedule.SYSTEM
|
||||||
systems.entities_delete,
|
local RUN = schedule.RUN
|
||||||
systems.replication
|
require(ReplicatedStorage.components)
|
||||||
)
|
local world = jecs.world()
|
||||||
|
|
||||||
game:GetService("RunService").Heartbeat:Connect(heartbeat)
|
local systems = ReplicatedStorage.systems
|
||||||
|
SYSTEM(world, systems.receive_replication)
|
||||||
|
SYSTEM(world, systems.entities_delete)
|
||||||
|
RUN(world)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
--!strict
|
|
||||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
local jabby = require(ReplicatedStorage.Packages.jabby)
|
local jabby = require(ReplicatedStorage.Packages.jabby)
|
||||||
local ct = require(ReplicatedStorage.components)
|
|
||||||
local jecs = require(ReplicatedStorage.ecs)
|
local jecs = require(ReplicatedStorage.ecs)
|
||||||
|
|
||||||
jabby.set_check_function(function(player) return true end)
|
jabby.set_check_function(function() return true end)
|
||||||
|
|
||||||
local scheduler = jabby.scheduler.create()
|
local scheduler = jabby.scheduler.create("jabby scheduler")
|
||||||
|
|
||||||
jabby.register({
|
jabby.register({
|
||||||
applet = jabby.applets.scheduler,
|
applet = jabby.applets.scheduler,
|
||||||
|
|
@ -14,78 +12,125 @@ jabby.register({
|
||||||
configuration = {
|
configuration = {
|
||||||
scheduler = scheduler,
|
scheduler = scheduler,
|
||||||
},
|
},
|
||||||
}::any)
|
})
|
||||||
|
|
||||||
local ContextActionService = game:GetService("ContextActionService")
|
local ContextActionService = game:GetService("ContextActionService")
|
||||||
|
|
||||||
local function create_widget(_, state: Enum.UserInputState): Enum.ContextActionResult
|
local function create_widget(_, state: Enum.UserInputState)
|
||||||
local client = jabby.obtain_client()
|
local client = jabby.obtain_client()
|
||||||
if state ~= Enum.UserInputState.Begin then
|
if state ~= Enum.UserInputState.Begin then return end
|
||||||
return Enum.ContextActionResult.Pass
|
client.spawn_app(client.apps.home, nil)
|
||||||
end
|
|
||||||
client.spawn_app(client.apps.home::any, nil)
|
|
||||||
return Enum.ContextActionResult.Sink
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local RunService = game:GetService("RunService")
|
local RunService = game:GetService("RunService")
|
||||||
|
|
||||||
local function schedule(world, ...)
|
local System = jecs.component() :: jecs.Id<{
|
||||||
local function get_entity_from_part(part: BasePart): (jecs.Entity<any>?, PVInstance?)
|
fn: () -> (),
|
||||||
for id, model in world:query(ct.Renderable) do
|
name: string,
|
||||||
if not part:IsDescendantOf(model) then continue end
|
}>
|
||||||
return id, model
|
local DependsOn = jecs.component()
|
||||||
end
|
local Phase = jecs.tag()
|
||||||
return nil, nil
|
local Event = jecs.component() :: jecs.Id<RBXScriptSignal>
|
||||||
|
|
||||||
|
local pair = jecs.pair
|
||||||
|
|
||||||
|
local types = require(ReplicatedStorage.types)
|
||||||
|
|
||||||
|
local function ECS_PHASE(world, after: types.Entity)
|
||||||
|
local phase = world:entity()
|
||||||
|
world:add(phase, Phase)
|
||||||
|
if after then
|
||||||
|
local dependency = pair(DependsOn, after)
|
||||||
|
world:add(phase, dependency)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return phase
|
||||||
|
end
|
||||||
|
|
||||||
|
local Heartbeat = jecs.tag()
|
||||||
|
jecs.meta(Heartbeat, Phase)
|
||||||
|
jecs.meta(Heartbeat, Event, RunService.Heartbeat)
|
||||||
|
|
||||||
|
local PreSimulation = jecs.tag()
|
||||||
|
jecs.meta(PreSimulation, Phase)
|
||||||
|
jecs.meta(PreSimulation, Event, RunService.PreSimulation)
|
||||||
|
|
||||||
|
local PreAnimation = jecs.tag()
|
||||||
|
jecs.meta(PreAnimation, Phase)
|
||||||
|
jecs.meta(PreAnimation, Event, RunService.PreAnimation)
|
||||||
|
|
||||||
|
local PreRender = jecs.tag()
|
||||||
|
jecs.meta(PreRender, Phase)
|
||||||
|
jecs.meta(PreRender, Event, RunService.PreRender)
|
||||||
|
|
||||||
|
local function ECS_SYSTEM(world: types.World, mod: ModuleScript, phase: types.Entity?)
|
||||||
|
local system = world:entity()
|
||||||
|
local p = phase or Heartbeat
|
||||||
|
local fn = require(mod) :: (...any) -> ()
|
||||||
|
world:set(system, System, {
|
||||||
|
fn = fn(world, 0) or fn,
|
||||||
|
name = mod.Name,
|
||||||
|
})
|
||||||
|
|
||||||
|
local depends_on = DependsOn :: jecs.Entity
|
||||||
|
world:add(system, pair(depends_on, p))
|
||||||
|
end
|
||||||
|
local function find_systems_w_phase(world: types.World, systems, phase: types.Entity)
|
||||||
|
local phase_name = world:get(phase, jecs.Name) :: string
|
||||||
|
for _, s in world:query(System):with(pair(DependsOn, phase)) do
|
||||||
|
table.insert(systems, {
|
||||||
|
id = scheduler:register_system({
|
||||||
|
phase = phase_name,
|
||||||
|
name = s.name,
|
||||||
|
}),
|
||||||
|
fn = s.fn
|
||||||
|
})
|
||||||
|
end
|
||||||
|
for after in world:query(Phase, pair(DependsOn, phase)) do
|
||||||
|
find_systems_w_phase(world, systems, after)
|
||||||
|
end
|
||||||
|
return systems
|
||||||
|
end
|
||||||
|
|
||||||
|
local function ECS_RUN(world: types.World)
|
||||||
|
|
||||||
jabby.register({
|
jabby.register({
|
||||||
applet = jabby.applets.world,
|
applet = jabby.applets.world,
|
||||||
name = "World",
|
name = "MyWorld",
|
||||||
configuration = {
|
configuration = {
|
||||||
world = world,
|
world = world,
|
||||||
get_entity_from_part = get_entity_from_part,
|
|
||||||
},
|
},
|
||||||
}::any)
|
})
|
||||||
|
|
||||||
local systems = { ... }
|
|
||||||
|
|
||||||
local function systems_load(mod: ModuleScript, ...)
|
|
||||||
local fn = require(mod) :: (...any) -> ()
|
|
||||||
local system = fn(...) or fn
|
|
||||||
|
|
||||||
local system_id = scheduler:register_system({
|
|
||||||
name = mod.Name,
|
|
||||||
module = mod,
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
system = system,
|
|
||||||
id = system_id
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
for i, mod in systems do
|
|
||||||
systems[i] = systems_load(mod, world, 0)
|
|
||||||
end
|
|
||||||
|
|
||||||
if RunService:IsClient() then
|
if RunService:IsClient() then
|
||||||
ContextActionService:BindAction(
|
ContextActionService:BindAction("Open Jabby Home", create_widget, false, Enum.KeyCode.F4)
|
||||||
"Open Jabby Home",
|
|
||||||
create_widget,
|
|
||||||
false,
|
|
||||||
Enum.KeyCode.F4
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return function(dt: number, input: InputObject?)
|
for phase, event in world:query(Event, Phase) do
|
||||||
for i, config in systems do
|
local systems = find_systems_w_phase(world, {}, phase)
|
||||||
-- config.system(world, dt, input)
|
event:Connect(function(...)
|
||||||
local system = config.system
|
for _, system in systems do
|
||||||
local id = config.id
|
scheduler:run(system.id, system.fn, world, ...)
|
||||||
scheduler:run(id, system,
|
end
|
||||||
world, dt, input)
|
end)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return schedule
|
return {
|
||||||
|
PHASE = ECS_PHASE,
|
||||||
|
SYSTEM = ECS_SYSTEM,
|
||||||
|
RUN = ECS_RUN,
|
||||||
|
phases = {
|
||||||
|
Heartbeat = Heartbeat,
|
||||||
|
PreSimulation = PreSimulation,
|
||||||
|
PreAnimation = PreAnimation,
|
||||||
|
PreRender = PreRender
|
||||||
|
},
|
||||||
|
components = {
|
||||||
|
System = System,
|
||||||
|
DependsOn = DependsOn,
|
||||||
|
Phase = Phase,
|
||||||
|
Event = Event,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,19 +3,19 @@ local ServerScriptService = game:GetService("ServerScriptService")
|
||||||
local jecs = require(ReplicatedStorage.ecs)
|
local jecs = require(ReplicatedStorage.ecs)
|
||||||
local schedule = require(ReplicatedStorage.schedule)
|
local schedule = require(ReplicatedStorage.schedule)
|
||||||
|
|
||||||
|
local SYSTEM = schedule.SYSTEM
|
||||||
|
local RUN = schedule.RUN
|
||||||
|
|
||||||
require(ReplicatedStorage.components)
|
require(ReplicatedStorage.components)
|
||||||
local world = jecs.world()
|
local world = jecs.world()
|
||||||
|
|
||||||
local systems = ServerScriptService.systems
|
local systems = ServerScriptService.systems
|
||||||
|
|
||||||
local heartbeat = schedule(world,
|
SYSTEM(world, systems.replication)
|
||||||
systems.players_added,
|
SYSTEM(world, systems.players_added)
|
||||||
systems.poison_hurts,
|
SYSTEM(world, systems.poison_hurts)
|
||||||
systems.health_regen,
|
SYSTEM(world, systems.health_regen)
|
||||||
systems.lifetimes_expire,
|
SYSTEM(world, systems.lifetimes_expire)
|
||||||
systems.life_is_painful,
|
SYSTEM(world, systems.life_is_painful)
|
||||||
systems.entities_delete,
|
SYSTEM(world, ReplicatedStorage.systems.entities_delete)
|
||||||
systems.replication
|
RUN(world, 0)
|
||||||
)
|
|
||||||
|
|
||||||
game:GetService("RunService").Heartbeat:Connect(heartbeat)
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue