Merge system files

This commit is contained in:
Ukendio 2024-09-09 03:38:47 +02:00
parent 8c28cab792
commit 411138e1f7
7 changed files with 51 additions and 143 deletions

View file

@ -1,76 +0,0 @@
{
"name": "demo",
"tree": {
"$className": "DataModel",
"ReplicatedStorage": {
"$className": "ReplicatedStorage",
"$path": "demo/src/ReplicatedStorage",
"ecs": {
"$path": "src"
},
"net": {
"$path": "demo/net/client.luau"
},
"Packages": {
"$path": "demo/Packages"
}
},
"ServerScriptService": {
"$className": "ServerScriptService",
"$path": "demo/src/ServerScriptService",
"net": {
"$path": "demo/net/server.luau"
}
},
"Workspace": {
"$properties": {
"FilteringEnabled": true
},
"Baseplate": {
"$className": "Part",
"$properties": {
"Anchored": true,
"Color": [
0.38823,
0.37254,
0.38823
],
"Locked": true,
"Position": [
0,
-10,
0
],
"Size": [
512,
20,
512
]
}
}
},
"Lighting": {
"$properties": {
"Ambient": [
0,
0,
0
],
"Brightness": 2,
"GlobalShadows": true,
"Outlines": false,
"Technology": "Voxel"
}
},
"SoundService": {
"$properties": {
"RespectFilteringEnabled": true
}
},
"StarterPlayer": {
"StarterPlayerScripts": {
"$path": "demo/src/StarterPlayer/StarterPlayerScripts"
}
}
}
}

View file

@ -8,6 +8,9 @@ local jecs = require(ReplicatedStorage.ecs)
local __ = jecs.Wildcard
local std = require(ReplicatedStorage.std)
local ref = std.ref
local interval = std.interval
local world: std.World = std.world
local cts = std.components
@ -48,7 +51,28 @@ local function mobsMove(dt: number)
end
end
return function(scheduler: std.Scheduler)
return scheduler.systems.new(mobsMove,
scheduler.phases.Heartbeat)
local throttle = interval(5)
local function spawnMobs()
if throttle() then
local p = Vector3.new(0, 5, 0)
local cf = CFrame.new(p)
local v = 5
local id = ref()
:set(Velocity, v)
:set(Transform, { new = cf })
:add(Mob)
.id()
blink.SpawnMob.FireAll(id, cf, v)
end
end
return function(scheduler: std.Scheduler)
local phases = scheduler.phases
local system_new = scheduler.systems.new
system_new(mobsMove, phases.Heartbeat)
system_new(spawnMobs, phases.Heartbeat)
end

View file

@ -40,6 +40,7 @@ local function players()
end
return function(scheduler: std.Scheduler)
return scheduler.systems.new(players,
scheduler.phases.Heartbeat)
local phases = scheduler.phases
local system_new = scheduler.systems.new
system_new(players, phases.Heartbeat)
end

View file

@ -1,33 +0,0 @@
local std = require(game:GetService("ReplicatedStorage").std)
local blink = require(game:GetService("ServerScriptService").net)
local ref = std.ref
local interval = std.interval
local cts = std.components
local Mob = cts.Mob
local Transform = cts.Transform
local Velocity = cts.Velocity
local throttle = interval(5)
local function spawnMobs()
if throttle() then
local p = Vector3.new(0, 5, 0)
local cf = CFrame.new(p)
local v = 5
local id = ref()
:set(Velocity, v)
:set(Transform, { new = cf })
:add(Mob)
.id()
blink.SpawnMob.FireAll(id, cf, v)
end
end
return function(scheduler: std.Scheduler)
return scheduler.systems.new(spawnMobs,
scheduler.phases.Heartbeat)
end

View file

@ -1,7 +1,8 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local blink = require(ReplicatedStorage.net)
local std = require(ReplicatedStorage.std)
local world = std.world
local ref = std.ref
local cts = std.components
@ -19,7 +20,20 @@ local function move(dt: number)
end
end
return function(scheduler: std.Scheduler)
return scheduler.systems.new(move,
scheduler.phases.RenderStepped)
local function syncTransforms()
for _, id, cf in blink.UpdateTransform.Iter() do
local e = ref("server-"..id)
local transform = e:get(cts.Transform)
if not transform then
continue
end
transform.new = cf
end
end
return function(scheduler: std.Scheduler)
local phases = scheduler.phases
local system_new = scheduler.systems.new
system_new(move, phases.Heartbeat)
system_new(syncTransforms, phases.RenderStepped)
end

View file

@ -25,6 +25,7 @@ local function syncMobs()
end
return function(scheduler: std.Scheduler)
return scheduler.systems.new(syncMobs,
scheduler.phases.RenderStepped)
local phases = scheduler.phases
local system_new = scheduler.systems.new
system_new(syncMobs, phases.RenderStepped)
end

View file

@ -1,23 +0,0 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local blink = require(ReplicatedStorage.net)
local std = require(ReplicatedStorage.std)
local ref = std.ref
local world = std.world
local cts = std.components
local function syncTransforms()
for _, id, cf in blink.UpdateTransform.Iter() do
local e = ref("server-"..id)
local transform = e:get(cts.Transform)
if not transform then
continue
end
transform.new = cf
end
end
return function(scheduler: std.Scheduler)
return scheduler.systems.new(syncTransforms,
scheduler.phases.RenderStepped)
end