mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 01:20:04 +00:00
Add jabby to demo
This commit is contained in:
parent
f5a8fc2192
commit
e7bbf08713
4 changed files with 46 additions and 20 deletions
|
@ -10,6 +10,9 @@
|
||||||
},
|
},
|
||||||
"net": {
|
"net": {
|
||||||
"$path": "demo/net/client.luau"
|
"$path": "demo/net/client.luau"
|
||||||
|
},
|
||||||
|
"Packages": {
|
||||||
|
"$path": "demo/Packages"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ServerScriptService": {
|
"ServerScriptService": {
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
--!native
|
--!native
|
||||||
--!optimize 2
|
--!optimize 2
|
||||||
local jecs = require(game:GetService("ReplicatedStorage").ecs)
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
|
local jabby = require(ReplicatedStorage.Packages.jabby)
|
||||||
|
local jecs = require(ReplicatedStorage.ecs)
|
||||||
|
local components = require(ReplicatedStorage.std.components)
|
||||||
local pair = jecs.pair
|
local pair = jecs.pair
|
||||||
type World = jecs.World
|
type World = jecs.World
|
||||||
type Entity<T=nil> = jecs.Entity<T>
|
type Entity<T=nil> = jecs.Entity<T>
|
||||||
|
@ -48,6 +51,7 @@ export type Scheduler = {
|
||||||
|
|
||||||
local scheduler_new: (w: World) -> Scheduler
|
local scheduler_new: (w: World) -> Scheduler
|
||||||
|
|
||||||
|
|
||||||
do
|
do
|
||||||
local world
|
local world
|
||||||
local Disabled
|
local Disabled
|
||||||
|
@ -57,6 +61,8 @@ do
|
||||||
local Event
|
local Event
|
||||||
local Name
|
local Name
|
||||||
|
|
||||||
|
local scheduler
|
||||||
|
|
||||||
local RenderStepped
|
local RenderStepped
|
||||||
local Heartbeat
|
local Heartbeat
|
||||||
local PreAnimation
|
local PreAnimation
|
||||||
|
@ -84,21 +90,7 @@ do
|
||||||
|
|
||||||
debug.profilebegin(event_name)
|
debug.profilebegin(event_name)
|
||||||
for _, sys in systems do
|
for _, sys in systems do
|
||||||
system = sys
|
scheduler:run(sys.id, sys.system, dt)
|
||||||
|
|
||||||
local didNotYield, why = xpcall(function()
|
|
||||||
for _ in run do end
|
|
||||||
end, debug.traceback)
|
|
||||||
|
|
||||||
if didNotYield then
|
|
||||||
continue
|
|
||||||
end
|
|
||||||
|
|
||||||
if string.find(why, "thread is not yieldable") then
|
|
||||||
panic("Not allowed to yield in the systems.")
|
|
||||||
else
|
|
||||||
panic(why)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
debug.profileend()
|
debug.profileend()
|
||||||
end
|
end
|
||||||
|
@ -108,8 +100,15 @@ do
|
||||||
end
|
end
|
||||||
|
|
||||||
local function scheduler_collect_systems_under_phase_recursive(systems, phase)
|
local function scheduler_collect_systems_under_phase_recursive(systems, phase)
|
||||||
|
local phase_name = world:get(phase, Name)
|
||||||
for _, system in world:query(System):with(pair(DependsOn, phase)) do
|
for _, system in world:query(System):with(pair(DependsOn, phase)) do
|
||||||
table.insert(systems, system)
|
table.insert(systems, {
|
||||||
|
id = scheduler:register_system({
|
||||||
|
name = system.name,
|
||||||
|
phase = phase_name
|
||||||
|
}),
|
||||||
|
system = system.callback
|
||||||
|
})
|
||||||
end
|
end
|
||||||
for after in world:query(Phase):with(pair(DependsOn, phase)) do
|
for after in world:query(Phase):with(pair(DependsOn, phase)) do
|
||||||
scheduler_collect_systems_under_phase_recursive(systems, after)
|
scheduler_collect_systems_under_phase_recursive(systems, after)
|
||||||
|
@ -123,11 +122,11 @@ do
|
||||||
end
|
end
|
||||||
|
|
||||||
local function scheduler_collect_systems_all()
|
local function scheduler_collect_systems_all()
|
||||||
local systems = {}
|
local events = {}
|
||||||
for phase, event in world:query(Event):with(Phase) do
|
for phase, event in world:query(Event):with(Phase) do
|
||||||
systems[event] = scheduler_collect_systems_under_event(phase)
|
events[event] = scheduler_collect_systems_under_event(phase)
|
||||||
end
|
end
|
||||||
return systems
|
return events
|
||||||
end
|
end
|
||||||
|
|
||||||
local function scheduler_phase_new(after)
|
local function scheduler_phase_new(after)
|
||||||
|
@ -153,6 +152,7 @@ do
|
||||||
Phase = world:component()
|
Phase = world:component()
|
||||||
DependsOn = world:component()
|
DependsOn = world:component()
|
||||||
Event = world:component()
|
Event = world:component()
|
||||||
|
Name = world:component()
|
||||||
|
|
||||||
RenderStepped = world:component()
|
RenderStepped = world:component()
|
||||||
Heartbeat = world:component()
|
Heartbeat = world:component()
|
||||||
|
@ -166,6 +166,7 @@ do
|
||||||
end
|
end
|
||||||
|
|
||||||
world:add(Heartbeat, Phase)
|
world:add(Heartbeat, Phase)
|
||||||
|
world:set(Heartbeat, Name)
|
||||||
world:set(Heartbeat, Event, RunService.Heartbeat)
|
world:set(Heartbeat, Event, RunService.Heartbeat)
|
||||||
|
|
||||||
world:add(PreSimulation, Phase)
|
world:add(PreSimulation, Phase)
|
||||||
|
@ -174,6 +175,22 @@ do
|
||||||
world:add(PreAnimation, Phase)
|
world:add(PreAnimation, Phase)
|
||||||
world:set(PreAnimation, Event, RunService.PreAnimation)
|
world:set(PreAnimation, Event, RunService.PreAnimation)
|
||||||
|
|
||||||
|
jabby.public.updated = true
|
||||||
|
table.insert(jabby.public, {
|
||||||
|
class_name = "World",
|
||||||
|
name = "MyWorld",
|
||||||
|
world = world,
|
||||||
|
debug = Name,
|
||||||
|
entities = {}
|
||||||
|
})
|
||||||
|
for name, component in components do
|
||||||
|
world:set(component, Name, name)
|
||||||
|
print(Name, name)
|
||||||
|
end
|
||||||
|
|
||||||
|
scheduler = jabby.scheduler.create("scheduler")
|
||||||
|
|
||||||
|
table.insert(jabby.public, scheduler)
|
||||||
return {
|
return {
|
||||||
phase = scheduler_phase_new,
|
phase = scheduler_phase_new,
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||||
local std = require(ReplicatedStorage.std)
|
local std = require(ReplicatedStorage.std)
|
||||||
|
local components = std.components
|
||||||
|
local world = std.world
|
||||||
|
|
||||||
local scheduler = std.Scheduler
|
local scheduler = std.Scheduler
|
||||||
for _, module in script.Parent.systems:GetChildren() do
|
for _, module in script.Parent.systems:GetChildren() do
|
||||||
require(module)(scheduler)
|
require(module)(scheduler)
|
||||||
|
|
|
@ -7,3 +7,6 @@ end
|
||||||
local events = scheduler.collect.all()
|
local events = scheduler.collect.all()
|
||||||
|
|
||||||
scheduler.systems.begin(events)
|
scheduler.systems.begin(events)
|
||||||
|
local jabby = require(ReplicatedStorage.Packages.jabby)
|
||||||
|
local client = jabby.obtain_client()
|
||||||
|
client.spawn_app(client.apps.home)
|
||||||
|
|
Loading…
Reference in a new issue