Skip to content

Commit

Permalink
Rework demo
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Dec 26, 2024
1 parent 2e29046 commit 97fe913
Show file tree
Hide file tree
Showing 17 changed files with 290 additions and 448 deletions.
14 changes: 6 additions & 8 deletions demo/src/ReplicatedStorage/start.luau
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local jabby = require(ReplicatedStorage.Packages.jabby)
local std = require(ReplicatedStorage.std)
local Scheduler = std.Scheduler
local world = std.world
local std = ReplicatedStorage.std
local scheduler = require(std.scheduler)
local world = require(std.world)

local function start(modules)
local scheduler = Scheduler.new(world, require(ReplicatedStorage.std.components))
for _, module in modules do
require(module)(scheduler)
require(module)
end
local events = scheduler.collect.all()
scheduler.systems.begin(events)

local events = scheduler.COLLECT()
scheduler.BEGIN(events)
jabby.set_check_function(function(player)
return true
end)
Expand Down
10 changes: 5 additions & 5 deletions demo/src/ReplicatedStorage/std/bt.luau
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

-- original author @centau

local SUCCESS = 0
local FAILURE = 1
local RUNNING = 2
local FAILURE = -1
local RUNNING = 0
local SUCCESS = 1

local function SEQUENCE(nodes)
return function(...)
for _, node in nodes do
local status = node(...)
if status == FAILURE or status == RUNNING then
if status <= RUNNING then
return status
end
end
Expand All @@ -23,7 +23,7 @@ local function FALLBACK(nodes)
return function(...)
for _, node in nodes do
local status = node(...)
if status == SUCCESS or status == RUNNING then
if status > FAILURE then
return status
end
end
Expand Down
6 changes: 5 additions & 1 deletion demo/src/ReplicatedStorage/std/components.luau
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local components: {
Model: Entity<Model>,
Player: Entity,
Target: Entity,
Transform: Entity<CFrame>,
Transform: Entity<{ new: CFrame, old: CFrame }>,
Velocity: Entity<number>,
Previous: Entity,
} =
Expand All @@ -23,4 +23,8 @@ local components: {
Previous = world:component(),
}

for name, component in components :: {[string]: jecs.Entity} do
world:set(component, jecs.Name, name)
end

return table.freeze(components)
11 changes: 0 additions & 11 deletions demo/src/ReplicatedStorage/std/ctx.luau

This file was deleted.

56 changes: 0 additions & 56 deletions demo/src/ReplicatedStorage/std/handle.luau

This file was deleted.

32 changes: 0 additions & 32 deletions demo/src/ReplicatedStorage/std/hooks.luau

This file was deleted.

25 changes: 0 additions & 25 deletions demo/src/ReplicatedStorage/std/init.luau

This file was deleted.

2 changes: 1 addition & 1 deletion demo/src/ReplicatedStorage/std/interval.luau
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ local function interval(s)
return throttle
end

return interval
return interval
14 changes: 14 additions & 0 deletions demo/src/ReplicatedStorage/std/phases.luau
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
local std = game:GetService("ReplicatedStorage").std
local Players = game:GetService("Players")

local scheduler = require(std.scheduler)
local PHASE = scheduler.PHASE

return {
PlayerAdded = PHASE({
event = Players.PlayerAdded
}),
PlayerRemoved = PHASE({
event = Players.PlayerRemoving
})
}
14 changes: 8 additions & 6 deletions demo/src/ReplicatedStorage/std/ref.luau
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
local handle = require(script.Parent.handle)
local world = require(script.Parent.world)
local refs = {}
local jecs = require(game:GetService("ReplicatedStorage").ecs)
local refs: {[any]: jecs.Entity} = {}

local function fini(key)
local function fini(key): () -> ()
return function()
refs[key] = nil
end
end

local function ref(key): (handle.Handle, (() -> ())?)
local function noop() end

local function ref(key): (jecs.Entity, () -> ())
if not key then
return handle(world:entity())
return world:entity(), noop
end
local e = refs[key]
if not e then
e = world:entity()
refs[key] = e
end
-- Cannot cache handles because they will get invalidated
return handle(e), fini(key)
return e, fini(key)
end

return ref
31 changes: 0 additions & 31 deletions demo/src/ReplicatedStorage/std/registry.luau

This file was deleted.

Loading

0 comments on commit 97fe913

Please sign in to comment.