mirror of
https://github.com/Ukendio/jecs.git
synced 2026-02-04 15:15:21 +00:00
Fix bug with ternary operator for component valus that can be false
This commit is contained in:
parent
3dab729df8
commit
7246f3d8a8
1 changed files with 9 additions and 8 deletions
|
|
@ -9,9 +9,8 @@ local ty = require("./types")
|
||||||
local components: { [string]: jecs.Id } = {}
|
local components: { [string]: jecs.Id } = {}
|
||||||
local ct = components
|
local ct = components
|
||||||
|
|
||||||
|
local function networking_send(world: jecs.World)
|
||||||
return function(world: jecs.World)
|
local storages = {} :: { [jecs.Entity]: {[jecs.Entity]: any }}
|
||||||
local storages = {} :: { [jecs.Id]: {[jecs.Id]: any }}
|
|
||||||
local networked_components = {}
|
local networked_components = {}
|
||||||
local networked_pairs = {}
|
local networked_pairs = {}
|
||||||
|
|
||||||
|
|
@ -108,14 +107,14 @@ return function(world: jecs.World)
|
||||||
|
|
||||||
return function(_, dt: number)
|
return function(_, dt: number)
|
||||||
local snapshot_lazy: ty.snapshot
|
local snapshot_lazy: ty.snapshot
|
||||||
local set_ids_lazy: { jecs.Id }
|
local set_ids_lazy: { jecs.Entity }
|
||||||
|
|
||||||
-- In the future maybe it should be requested by the player instead when they
|
-- In the future maybe it should be requested by the player instead when they
|
||||||
-- are ready to receive the replication. Otherwise streaming could be complicated
|
-- are ready to receive the replication. Otherwise streaming could be complicated
|
||||||
-- with intances references being nil.
|
-- with intances references being nil.
|
||||||
for player in players_added do
|
for player in players_added do
|
||||||
if not snapshot_lazy then
|
if not snapshot_lazy then
|
||||||
snapshot_lazy, set_ids_lazy = {}::any, {}
|
snapshot_lazy, set_ids_lazy = {}, {}
|
||||||
|
|
||||||
for component, storage in storages do
|
for component, storage in storages do
|
||||||
local set_values = {}
|
local set_values = {}
|
||||||
|
|
@ -135,7 +134,7 @@ return function(world: jecs.World)
|
||||||
set_n += entities_len
|
set_n += entities_len
|
||||||
end
|
end
|
||||||
|
|
||||||
local set = table.move(set_ids_lazy, 1, set_n, 1, {}::any)
|
local set = table.move(set_ids_lazy, 1, set_n, 1, {})
|
||||||
|
|
||||||
local map = {
|
local map = {
|
||||||
set = if set_n > 0 then set else nil,
|
set = if set_n > 0 then set else nil,
|
||||||
|
|
@ -174,7 +173,7 @@ return function(world: jecs.World)
|
||||||
if v ~= "jecs.Remove" then
|
if v ~= "jecs.Remove" then
|
||||||
set_n += 1
|
set_n += 1
|
||||||
set_ids[set_n] = e
|
set_ids[set_n] = e
|
||||||
set_values[set_n] = v or true
|
set_values[set_n] = if is_tag then 0 else v
|
||||||
elseif world:contains(e) then
|
elseif world:contains(e) then
|
||||||
removed_n += 1
|
removed_n += 1
|
||||||
removed_ids[removed_n] = e
|
removed_ids[removed_n] = e
|
||||||
|
|
@ -216,9 +215,11 @@ return function(world: jecs.World)
|
||||||
snapshot[tostring(component)] = map
|
snapshot[tostring(component)] = map
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if next(snapshot::any) ~= nil then
|
if next(snapshot) ~= nil then
|
||||||
remotes.replication:FireAllClients(snapshot)
|
remotes.replication:FireAllClients(snapshot)
|
||||||
-- print(snapshot)
|
-- print(snapshot)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return networking_send
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue