Skip to content

Commit

Permalink
Merge branch 'main' into use-real-archetypes
Browse files Browse the repository at this point in the history
  • Loading branch information
jackTabsCode authored Oct 3, 2024
2 parents 4fd00c8 + 8811159 commit b6b2c2e
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ jobs:
uses: actions/checkout@v3

- name: Download Matter Build
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4.1.7
with:
name: build
path: build

- name: Download Example Game Build
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4.1.7
with:
name: build-example
path: build-example
Expand Down
3 changes: 2 additions & 1 deletion aftman.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[tools]
wally = "upliftgames/[email protected]"
rojo = "rojo-rbx/[email protected].1"
rojo = "rojo-rbx/[email protected].4"
stylua = "johnnymorganz/[email protected]"
selene = "kampfkarren/[email protected]"
testez = "jacktabscode/[email protected]"
1 change: 1 addition & 0 deletions example/src/shared/start.luau
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ local function start(containers)
end

local loop = Matter.Loop.new(world, state, debugger:getWidgets())
loop:setWorlds({ World = world })

-- Set up hot reloading

Expand Down
21 changes: 12 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,15 @@ function Loop:_sortSystems()
end
end

--[=[
Sets the Worlds to be used by the Loop for deferring commands, and the Debugger for profiling.
@param worlds {World} | {[string]: World} -- An array or dictionary of Worlds to be used by the Loop. If a dictionary is passed, the keys are used as the names of the Worlds for the Debugger.
]=]
function Loop:setWorlds(worlds: { World.World } | { [string]: World.World })
self._worlds = worlds
end

--[=[
Connects to frame events and starts invoking your systems.
Expand Down Expand Up @@ -369,14 +379,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 +409,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
11 changes: 0 additions & 11 deletions lib/debugger/debugger.luau
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")

local hookWidgets = require(script.Parent.hookWidgets)
local World = require(script.Parent.Parent.World)
local EventBridge = require(script.Parent.EventBridge)
local ui = require(script.Parent.ui)
local mouseHighlight = require(script.Parent.mouseHighlight)
Expand Down Expand Up @@ -271,16 +270,6 @@ function Debugger:_enable()
return
end

-- TODO: Find a better way for the user to specify the world.
if not self.debugWorld then
for _, object in self.loop._state do
if getmetatable(object) == World then
self.debugWorld = object
break
end
end
end

self.enabled = true
self.loop.profiling = self.loop.profiling or {}

Expand Down
70 changes: 42 additions & 28 deletions lib/debugger/ui.luau
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local RunService = game:GetService("RunService")
local World = require(script.Parent.Parent.World)
local rollingAverage = require(script.Parent.Parent.rollingAverage)
local World = require(script.Parent.Parent.World)

local function systemName(system)
local systemFn = if type(system) == "table" then system.system else system
Expand Down Expand Up @@ -41,12 +41,17 @@ local function ui(debugger, loop)
})

local objectStack = plasma.useState({})
local worldViewOpen, setWorldViewOpen = plasma.useState(false)
local worldExists = debugger.debugWorld ~= nil
local openWorld, setOpenWorld = plasma.useState()

local debugEntityWorld

for _, world in loop._worlds do
if debugger.hoverEntity and world:contains(debugger.hoverEntity) then
custom.hoverInspect(world, debugger.hoverEntity, custom)
end

if debugger.hoverEntity and worldExists then
if debugger.debugWorld:contains(debugger.hoverEntity) then
custom.hoverInspect(debugger.debugWorld, debugger.hoverEntity, custom)
if debugger.debugEntity and world:contains(debugger.debugEntity) then
debugEntityWorld = world
end
end

Expand Down Expand Up @@ -79,38 +84,47 @@ local function ui(debugger, loop)

local items = {}

for index, object in loop._state do
if type(object) ~= "table" then
continue
end
for index, world in loop._worlds do
local selected = openWorld == world

local isWorld = getmetatable(object) == World
local name = if type(index) == "number" then `World {index}` else index

local selected = (#objectStack > 0 and object == objectStack[#objectStack].value)
or (debugger.debugWorld == object and worldViewOpen)
table.insert(items, {
text = name,
icon = "🌐",
object = world,
selected = selected,
isWorld = true,
})
end

for index, value in loop._state do
if type(value) ~= "table" or getmetatable(value) == World then
continue
end

local name = debugger.loopParameterNames[index]
local defaultName = (if isWorld then "World" else "table") .. " " .. index
local defaultName = if name then name else `table {index}`

local selected = (#objectStack > 0 and value == objectStack[#objectStack].value)

table.insert(items, {
text = if name then name else defaultName,
icon = if isWorld then "🌐" else "{}",
object = object,
text = defaultName,
icon = "{}",
object = value,
selected = selected,
isWorld = isWorld,
isWorld = false,
})
end

local selectedState = custom.selectionList(items):selected()

if selectedState then
if selectedState.isWorld then
if worldViewOpen and debugger.debugWorld == selectedState.object then
debugger.debugWorld = nil
setWorldViewOpen(false)
if openWorld == selectedState.object then
setOpenWorld(nil)
else
debugger.debugWorld = selectedState.object
setWorldViewOpen(true)
setOpenWorld(selectedState.object)
end
else
local previousFirstValue = if objectStack[1] then objectStack[1].value else nil
Expand Down Expand Up @@ -228,16 +242,16 @@ local function ui(debugger, loop)
end)

debugger.parent = custom.container(function()
if debugger.debugWorld and worldViewOpen then
local closed = custom.worldInspect(debugger, objectStack)
if openWorld then
local closed = custom.worldInspect(debugger, openWorld, objectStack)

if closed then
setWorldViewOpen(false)
setOpenWorld(nil)
end
end

if debugger.debugWorld and debugger.debugEntity then
custom.entityInspect(debugger)
if debugEntityWorld and debugger.debugEntity then
custom.entityInspect(debugger, debugEntityWorld)
end

if #objectStack > 0 then
Expand Down
8 changes: 4 additions & 4 deletions lib/debugger/widgets/entityInspect.luau
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ local formatTable = formatTableModule.formatTable
local FormatMode = formatTableModule.FormatMode

return function(plasma)
return plasma.widget(function(debugger)
return plasma.widget(function(debugger, world)
local style = plasma.useStyle()

local closed = plasma
.window({
title = string.format("Entity %d", debugger.debugEntity),
closable = true,
}, function()
if not debugger.debugWorld:contains(debugger.debugEntity) then
if not world:contains(debugger.debugEntity) then
debugger.debugEntity = nil
return
end
Expand All @@ -28,7 +28,7 @@ return function(plasma)

plasma.row(function()
if plasma.button("despawn"):clicked() then
debugger.debugWorld:despawn(debugger.debugEntity)
world:despawn(debugger.debugEntity)
debugger.debugEntity = nil
end
end)
Expand All @@ -39,7 +39,7 @@ return function(plasma)

local items = { { "Component", "Data" } }

for component, data in debugger.debugWorld:_getEntity(debugger.debugEntity) do
for component, data in world:_getEntity(debugger.debugEntity) do
table.insert(items, {
tostring(component),
formatTable(data, FormatMode.Long),
Expand Down
4 changes: 1 addition & 3 deletions lib/debugger/widgets/worldInspect.luau
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ local BY_COMPONENT_NAME = "ComponentName"
local BY_ENTITY_COUNT = "EntityCount"

return function(plasma)
return plasma.widget(function(debugger, objectStack)
return plasma.widget(function(debugger, world, objectStack)
local style = plasma.useStyle()

local world = debugger.debugWorld

local cache, setCache = plasma.useState()

local sortType, setSortType = plasma.useState(BY_COMPONENT_NAME)
Expand Down

0 comments on commit b6b2c2e

Please sign in to comment.