mirror of
https://github.com/Ukendio/jecs.git
synced 2025-04-25 01:20:04 +00:00
Replication
This commit is contained in:
parent
bf1cc79d54
commit
9d82851373
7 changed files with 26 additions and 38 deletions
|
@ -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"
|
||||
|
|
|
@ -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": {
|
||||
|
@ -57,6 +63,11 @@
|
|||
"$properties": {
|
||||
"RespectFilteringEnabled": true
|
||||
}
|
||||
},
|
||||
"StarterPlayer": {
|
||||
"StarterPlayerScripts": {
|
||||
"$path": "demo/src/StarterPlayer/StarterPlayerScripts"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
local std = require(ReplicatedStorage.std)
|
||||
local world = std.world
|
||||
|
||||
local cts = std.components
|
||||
|
||||
local Model = cts.Model
|
||||
local Transform = cts.Transform
|
||||
|
||||
local function move(dt: number)
|
||||
for _, cf, model in world:query(Transform, Model) do
|
||||
model.PrimaryPart.CFrame = cf
|
||||
end
|
||||
end
|
||||
|
||||
return move
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue