Skip to content

Commit

Permalink
Worlds are explicitly given to Loop by an API
Browse files Browse the repository at this point in the history
  • Loading branch information
jackTabsCode committed Sep 5, 2024
1 parent c3a88a6 commit 1a7b849
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions lib/Loop.luau
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function Loop.new(...)
_skipSystems = {},
_orderedSystemsByEvent = {},
_state = { ... },
_worlds = {},
_stateLength = select("#", ...),
_systemState = {},
_middlewares = {},
Expand Down Expand Up @@ -324,6 +325,13 @@ function Loop:_sortSystems()
end
end

--[=[
Sets the Worlds to be used by the Loop for deferring commands, and the Debugger for profiling.
]=]
function Loop:setWorlds(worlds: { World.World })
self._worlds = worlds
end

--[=[
Connects to frame events and starts invoking your systems.
Expand Down Expand Up @@ -369,14 +377,7 @@ function Loop:begin(events)

local profiling = self.profiling

local worlds: { World.World } = {}
for _, stateArgument in self._state do
if typeof(stateArgument) == "table" and getmetatable(stateArgument) == World then
table.insert(worlds, stateArgument)
end
end

for _, world in worlds do
for _, world in self._worlds do
world:startDeferring()
end

Expand Down Expand Up @@ -406,7 +407,7 @@ function Loop:begin(events)
local thread = coroutine.create(function(...)
fn(...)

for _, world in worlds do
for _, world in self._worlds do
local ok, err = pcall(world.commitCommands, world)
if not ok then
commitFailed = true
Expand Down

0 comments on commit 1a7b849

Please sign in to comment.