Skip to content

Commit

Permalink
Replication
Browse files Browse the repository at this point in the history
  • Loading branch information
Ukendio committed Aug 7, 2024
1 parent bf1cc79 commit 9d82851
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 38 deletions.
1 change: 1 addition & 0 deletions aftman.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ rojo = "rojo-rbx/rojo@7.4.1"
stylua = "johnnymorganz/stylua@0.19.1"
selene = "kampfkarren/selene@0.26.1"
wally-patch-package = "Barocena/wally-patch-package@1.2.1"
Blink = "1Axen/Blink@0.14.1"
13 changes: 12 additions & 1 deletion demo.project.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,17 @@
"$path": "demo/src/ReplicatedStorage",
"ecs": {
"$path": "src"
},
"net": {
"$path": "demo/net/client.luau"
}
},
"ServerScriptService": {
"$className": "ServerScriptService",
"$path": "demo/src/ServerScriptService"
"$path": "demo/src/ServerScriptService",
"net": {
"$path": "demo/net/server.luau"
}
},
"Workspace": {
"$properties": {
Expand Down Expand Up @@ -57,6 +63,11 @@
"$properties": {
"RespectFilteringEnabled": true
}
},
"StarterPlayer": {
"StarterPlayerScripts": {
"$path": "demo/src/StarterPlayer/StarterPlayerScripts"
}
}
}
}
3 changes: 2 additions & 1 deletion demo/src/ReplicatedStorage/std/handle.luau
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ type Handle = {
has: (self: Handle, id: jecs.Entity) -> boolean,
get: <T>(self: Handle, id: jecs.Entity<T>) -> T?,
add: <T>(self: Handle, id: jecs.Entity<T>) -> Handle,
set: <T>(self: Handle, id: jecs.Entity<T>, value: T) -> Handle
set: <T>(self: Handle, id: jecs.Entity<T>, value: T) -> Handle,
id: (self: Handle?) -> jecs.Entity
}

local handle: (e: jecs.Entity) -> Handle
Expand Down
1 change: 1 addition & 0 deletions demo/src/ReplicatedStorage/std/world.luau
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local jecs = require(game:GetService("ReplicatedStorage").ecs)
export type World = jecs.WorldShim

-- I like the idea of only having the world be a singleton.
return jecs.World.new()
10 changes: 4 additions & 6 deletions demo/src/ServerScriptService/systems/mobsMove.luau
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local blink = require(game:GetService("ServerScriptService").net)
local jecs = require(ReplicatedStorage.ecs)
local pair = jecs.pair
local __ = jecs.Wildcard
Expand All @@ -10,19 +10,16 @@ local world = std.world
local cts = std.components

local Mob = cts.Mob
local Model = cts.Model
local Transform = cts.Transform
local Velocity = cts.Velocity
local Target = cts.Target
local Player = cts.Player
local Character = cts.Character
print("client Model", cts.Model)

local function mobsMove(dt: number)
local players = world:query(Character):with(Player)

for mob, cf, v in world:query(Transform, Velocity)
:with(Mob, Model)
do
for mob, cf, v in world:query(Transform, Velocity):with(Mob) do
local p = cf.Position

local target
Expand All @@ -45,6 +42,7 @@ local function mobsMove(dt: number)

local moving = CFrame.new(p + (target - p).Unit * dt * v)
world:set(mob, Transform, moving)
blink.UpdateTransform.FireAll(mob, moving)
end
end

Expand Down
17 changes: 0 additions & 17 deletions demo/src/ServerScriptService/systems/move.luau

This file was deleted.

19 changes: 6 additions & 13 deletions demo/src/ServerScriptService/systems/spawnMobs.luau
Original file line number Diff line number Diff line change
@@ -1,36 +1,29 @@
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 Model = cts.Model
local Transform = cts.Transform
local Velocity = cts.Velocity

local throttle = interval(5)

local function spawnMobs(world: std.World)
local function spawnMobs()
if throttle() then
local p = Vector3.new(0, 5, 0)
local cf = CFrame.new(p)
local v = 5
local part = Instance.new("Part")
part.Anchored = true
part.CanCollide = false
part.BrickColor = BrickColor.Blue()
part.Size = Vector3.one * 5
local model = Instance.new("Model")
part.Parent = model
model.PrimaryPart = part
model.Parent = workspace

ref()
local id = ref()
:set(Velocity, v)
:set(Transform, cf)
:set(Model, model)
:add(Mob)
.id()

blink.SpawnMob.FireAll(id, cf, v)
end
end

Expand Down

0 comments on commit 9d82851

Please sign in to comment.