Skip to content

Commit

Permalink
Revert "Add a test task with some other debug stuff"
Browse files Browse the repository at this point in the history
This reverts commit cc440f3.
  • Loading branch information
lL1l1 committed Dec 21, 2024
1 parent b5509fa commit 8fb4df9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 206 deletions.
105 changes: 0 additions & 105 deletions lua/sim/tasks/TestTask.lua

This file was deleted.

89 changes: 0 additions & 89 deletions lua/sim/units/components/DebugUnitComponent.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,67 +22,6 @@

local DebugComponent = import("/lua/shared/components/DebugComponent.lua").DebugComponent

---@type UnitState[]
local possibleUnitStates = {
"Immobile",
"Moving",
"Attacking",
"Guarding",
"Building",
"Upgrading",
"WaitingForTransport",
"TransportLoading",
"TransportUnloading",
"MovingDown",
"MovingUp",
"Patrolling",
"Busy",
"Attached",
"BeingReclaimed",
"Repairing",
"Diving",
"Surfacing",
"Teleporting",
"Ferrying",
"WaitForFerry",
"AssistMoving",
"PathFinding",
"ProblemGettingToGoal",
"NeedToTerminateTask",
"Capturing",
"BeingCaptured",
"Reclaiming",
"AssistingCommander",
"Refueling",
"GuardBusy",
"ForceSpeedThrough",
"UnSelectable",
"DoNotTarget",
"LandingOnPlatform",
"CannotFindPlaceToLand",
"BeingUpgraded",
"Enhancing",
"BeingBuilt",
"NoReclaim",
"NoCost",
"BlockCommandQueue",
"MakingAttackRun",
"HoldingPattern",
"SiloBuildingAmmo",
}

---@param unit Unit
---@return UnitState[] currentStates # Can be empty
local function GetStatesOfUnit(unit)
local currentStates = {}
for _, possibleState in possibleUnitStates do
if unit:IsUnitState(possibleState) then
table.insert(currentStates, possibleState)
end
end
return currentStates
end

---@class DebugUnitComponent : DebugComponent
DebugUnitComponent = Class(DebugComponent) {

Expand Down Expand Up @@ -179,32 +118,4 @@ DebugUnitComponent = Class(DebugComponent) {
local blueprint = self.Blueprint
DrawCircle(self:GetPosition(), math.max(blueprint.SizeX, blueprint.SizeY, blueprint.SizeZ), color)
end,

---@param self DebugUnitComponent | Unit
DebugPrintCurrentStates = function(self)
self:DebugLog(string.format("States at tick %d: %s", GetGameTick(), table.concat(GetStatesOfUnit(self), ', ')))
end,

---@param self DebugUnitComponent | Unit
DebugToggleTrackingStateChanges = function(self)
if not self.StateChangeTracker then
self.StateChangeTracker = self.Trash:Add(ForkThread(function()
local oldStatesHashed = {}
while true do
local newStates = GetStatesOfUnit(self)
local newStatesHashed = table.hash(GetStatesOfUnit(self))
for _, state in possibleUnitStates do
if newStatesHashed[state] ~= oldStatesHashed[state] then
self:DebugLog(string.format("New states at tick %d: %s", GetGameTick(), table.concat(newStates, ', ')))
end
end
oldStatesHashed = newStatesHashed
WaitTicks(1)
end
end))
else
KillThread(self.StateChangeTracker)
self.StateChangeTracker = nil
end
end,
}
15 changes: 3 additions & 12 deletions lua/system/repr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -182,12 +182,7 @@ function Inspector:getId(v)
if not id then
local tv = type(v)
id = (ids[tv] or 0) + 1
ids[tv] = id
if tv == "function" then
local info = debug.getinfo(v, "S")
id = fmt("%s %s(%d)", id, DiskToLocal(string.sub(info.source, 2)), info.linedefined)
end
ids[v] = id
ids[v], ids[tv] = id, id
end
return tostring(id)
end
Expand Down Expand Up @@ -228,11 +223,7 @@ function Inspector:putValue(v)
puts(buf, "]")
end
puts(buf, ' = ')
if k == "__index" and tostring(t[k]) == tostring(t) then
puts(buf, string.format("{...} -- %s (%g bytes)", tostring(t), debug.allocatedsize(t)))
else
self:putValue(t[k])
end
self:putValue(t[k])
end
end

Expand All @@ -258,7 +249,7 @@ function Inspector:putValue(v)
end

else
puts(buf, fmt('<%s %s>', tv, self:getId(v)))
puts(buf, fmt('<%s %d>', tv, self:getId(v)))
end
end

Expand Down

0 comments on commit 8fb4df9

Please sign in to comment.