Skip to content

Commit

Permalink
remove unreliable batching
Browse files Browse the repository at this point in the history
  • Loading branch information
jackdotink committed Feb 18, 2024
1 parent f430a9f commit 9ceac4c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 61 deletions.
37 changes: 9 additions & 28 deletions lib/Net/Client.luau
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,11 @@ local ListenerMap: { [string]: ({ any }) -> () } = {}
local CallMap: { [string]: thread } = {}
local Outgoing: {
Reliable: { [string]: { { any } } },
Unreliable: { [string]: { { any } } },
Call: { [string]: { { any } } },
} =
{
Reliable = {},
Unreliable = {},
Call = {},
}
} = {
Reliable = {},
Call = {},
}

local function SendReliableEvent(EventId: string, CallList: { any })
if not Outgoing.Reliable[EventId] then
Expand All @@ -26,11 +23,7 @@ local function SendReliableEvent(EventId: string, CallList: { any })
end

local function SendUnreliableEvent(EventId: string, CallList: { any })
if not Outgoing.Unreliable[EventId] then
Outgoing.Unreliable[EventId] = {}
end

table.insert(Outgoing.Unreliable[EventId], CallList)
UnreliableRemote:FireServer(EventId, CallList)
end

local function SetListener(EventId: string, Callback: ({ any }) -> ())
Expand Down Expand Up @@ -74,17 +67,11 @@ local function Start()
end
end)

UnreliableRemote.OnClientEvent:Connect(function(IncomingFireSection)
if IncomingFireSection then
for EventId, CallList in IncomingFireSection do
local Listener = ListenerMap[EventId]
UnreliableRemote.OnClientEvent:Connect(function(IncomingEventId, IncomingArgs)
local Listener = ListenerMap[IncomingEventId]

if Listener then
for _, Call in CallList do
Listener(Call)
end
end
end
if Listener then
Listener(IncomingArgs)
end
end)

Expand All @@ -95,12 +82,6 @@ local function Start()
Outgoing.Reliable = {}
Outgoing.Call = {}
end

if next(Outgoing.Unreliable) then
UnreliableRemote:FireServer(Outgoing.Unreliable)

Outgoing.Unreliable = {}
end
end)
end

Expand Down
40 changes: 7 additions & 33 deletions lib/Net/Server.luau
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ local ListenerMap: { [string]: (Player, { any }) -> () } = {}
local OutgoingMap: {
[Player]: {
Reliable: { [string]: { { any } } },
Unreliable: { [string]: { { any } } },
CallReturn: { [string]: { any } },
},
} =
{}
} = {}

local function SendReliableEvent(Player: Player, EventId: string, Args: { any })
if not OutgoingMap[Player] then
OutgoingMap[Player] = {
Reliable = {},
Unreliable = {},
CallReturn = {},
}
end
Expand All @@ -36,19 +33,7 @@ local function SendReliableEvent(Player: Player, EventId: string, Args: { any })
end

local function SendUnreliableEvent(Player: Player, EventId: string, Args: { any })
if not OutgoingMap[Player] then
OutgoingMap[Player] = {
Reliable = {},
Unreliable = {},
CallReturn = {},
}
end

if not OutgoingMap[Player].Unreliable[EventId] then
OutgoingMap[Player].Unreliable[EventId] = {}
end

table.insert(OutgoingMap[Player].Unreliable[EventId], Args)
UnreliableRemote:FireClient(Player, EventId, Args)
end

local function SetListener(EventId: string, Callback: (Player, { any }) -> ())
Expand All @@ -59,7 +44,6 @@ local function SendCallReturn(Player: Player, CallId: string, Args: { any })
if not OutgoingMap[Player] then
OutgoingMap[Player] = {
Reliable = {},
Unreliable = {},
CallReturn = {},
}
end
Expand Down Expand Up @@ -104,18 +88,12 @@ local function Start()
end
end)

UnreliableRemote.OnServerEvent:Connect(function(Player, IncomingFireSection)
local FireSectionValid, FireSection = FireSectionCheck(IncomingFireSection)
UnreliableRemote.OnServerEvent:Connect(function(Player, IncomingEventId, IncomingArgs)
if type(IncomingEventId) == "string" and type(IncomingArgs) == "table" then
local Callback = ListenerMap[IncomingEventId]

if FireSectionValid then
for EventId, CallList in FireSection do
local Callback = ListenerMap[EventId]

if Callback then
for _, Call in CallList do
Callback(Player, Call)
end
end
if Callback then
Callback(Player, IncomingArgs)
end
end
end)
Expand All @@ -126,10 +104,6 @@ local function Start()
ReliableRemote:FireClient(Player, Outgoing.Reliable, Outgoing.CallReturn)
end

if next(Outgoing.Unreliable) then
UnreliableRemote:FireClient(Player, Outgoing.Unreliable)
end

OutgoingMap[Player] = nil
end
end)
Expand Down

0 comments on commit 9ceac4c

Please sign in to comment.