-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issues with unreliable batching methods #19
Comments
In terms of unreliable batching, there are a few problems.
-- Client.luau
-- A function to deep copy tables
-- (taken from Sleitnick's RbxUtil)
local function Copy<T>(t: T, deep: boolean?): T
if not deep then
return (table.clone(t :: any) :: any) :: T
end
local function DeepCopy(tbl: { any })
local tCopy = table.clone(tbl)
for k, v in tCopy do
if type(v) == "table" then
tCopy[k] = DeepCopy(v)
end
end
return tCopy
end
return DeepCopy(t :: any) :: T
end
local function SendUnreliable(id: string, args: { any }) -- Player parameter is removed here
if not Outgoing.Unreliable[id] then
Outgoing.Unreliable[id] = {}
end
local OutgoingMimic = Copy(Outgoing.Unreliable, true) -- Perform a deep copy of the outgoing table
-- Originally, inserting to the table would have duplicated data,
-- but deep copying it makes a true separate copy that we can use to measure.
table.insert(OutgoingMimic[id], args)
local PacketSize = RemotePacketSizeCounter.GetPacketSize({
RunContext = "Client",
RemoteType = "RemoteEvent",
PacketData = { OutgoingMimic },
})
if PacketSize >= 840 then
Unreliable:FireServer({ [id] = { args } })
else
table.insert(Outgoing.Unreliable[id], args)
end
end
This should solve any client-sided problems coming from using unreliable events while still incorporating batching.
-- From Server.luau
local function SendUnreliable(player: Player, id: string, args: { any })
local OutgoingForPlayer = Outgoing[player]
if not OutgoingForPlayer then
CreateOutgoingForPlayer(player)
end
-- Update the variable. This was included within the `SendReliable`
-- function, but may have been overlooked here.
OutgoingForPlayer = Outgoing[player]
if not OutgoingForPlayer.Unreliable[id] then
OutgoingForPlayer.Unreliable[id] = {}
end
local OutgoingMimic = Copy(OutgoingForPlayer.Unreliable, true) -- Reusing the deep copy function
table.insert(OutgoingMimic[id], args)
local PacketSize = RemotePacketSizeCounter.GetPacketSize({
RunContext = "Server",
RemoteType = "RemoteEvent",
PacketData = { OutgoingMimic },
})
if PacketSize >= 840 then
Unreliable:FireClient(player, { [id] = { args } })
else
table.insert(OutgoingForPlayer.Unreliable[id], args)
end
end
This should also resolve the related issue of batching and eliminate a bug where the |
Problems arise when using unreliable events, suspected when batching
The text was updated successfully, but these errors were encountered: