Skip to content

Commit

Permalink
Extend debugging functionality for units, projectiles and weapons (FA…
Browse files Browse the repository at this point in the history
  • Loading branch information
Garanas authored Jul 28, 2024
1 parent 4cac141 commit 2158d74
Show file tree
Hide file tree
Showing 13 changed files with 468 additions and 13 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/deploy-faf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,15 @@ jobs:
uses: actions/checkout@v4
with:
repository: FAForever/fa
ref: develop
ref: master

# Disable debugging statements
- name: Update references
run: |
sed -i 's/EnabledSpewing = true,/EnabledSpewing = false,/' "/lua/shared/components/DebugComponent.lua"
sed -i 's/EnabledLogging = true,/EnabledLogging = false,/' "/lua/shared/components/DebugComponent.lua"
sed -i 's/EnabledWarnings = true,/EnabledWarnings = false,/' "/lua/shared/components/DebugComponent.lua"
sed -i 's/EnabledDrawing = true,/EnabledDrawing = false,/' "/lua/shared/components/DebugComponent.lua"
# Update the deploy/faf branch, we force push here because
# we're not interested in fixing conflicts
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/deploy-fafbeta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ jobs:
repository: FAForever/fa
ref: develop

# Disable debugging statements
#
# You can overwrite these adjustments by setting up a `Debug` folder
- name: Update references
run: |
sed -i 's/EnabledDrawing = true,/EnabledDrawing = false,/' "/lua/shared/components/DebugComponent.lua"
# Update the deploy/fafbeta branch, we force push here because
# we're not interested in fixing conflicts
- name: Update deploy/fafbeta
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/deploy-fafdevelop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ jobs:
repository: FAForever/fa
ref: develop

# Disable debugging statements
#
# You can overwrite these adjustments by setting up a `Debug` folder
- name: Update references
run: |
sed -i 's/EnabledDrawing = true,/EnabledDrawing = false,/' "/lua/shared/components/DebugComponent.lua"
# Update the deploy/fafdevelop branch, we force push here because
# we're not interested in fixing conflicts
- name: Update deploy/fafdevelop
Expand Down
6 changes: 5 additions & 1 deletion docs/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ All three branches originate from the `develop` branch, which is the default bra

## Deployment procedures for the FAF game type

The following (manual) stepz are relevant to create a valid deployment to the FAF game type.
The following (manual) steps are relevant to create a valid deployment to the FAF game type.

- (1) Update the game version in [mod_info.lua](https://github.com/FAForever/fa/blob/c36404675c7a95cda20fe867d78bd1c01c7df103/mod_info.lua) and [version.lua](https://github.com/FAForever/fa/blob/c36404675c7a95cda20fe867d78bd1c01c7df103/lua/version.lua).
- (2) Update the game executable. This needs to be done by a server administrator. This is only required when there are changes to the executable.
- (3) Update the changelog in [changelog.md](/changelog) and [changelogData.lua](https://github.com/FAForever/fa/blob/c36404675c7a95cda20fe867d78bd1c01c7df103/lua/ui/lobby/changelogData.lua).
- (4) Update the game version in [changelogData.lua](https://github.com/FAForever/fa/blob/c36404675c7a95cda20fe867d78bd1c01c7df103/lua/ui/lobby/changelogData.lua).
- (5) Push everything that you want to release to the [master](https://github.com/FAForever/fa/tree/master) branch.
- (6) Use the [Deploy to FAF Workflow](https://github.com/FAForever/fa/actions/workflows/deploy-faf.yaml) to perform the deployment.

The last step allows us to systematically post process what we deploy. You can learn more about this by inspecting the workflow file.

## Automated deployments

Expand Down
5 changes: 4 additions & 1 deletion init_fafbeta.lua
Original file line number Diff line number Diff line change
Expand Up @@ -640,4 +640,7 @@ MountDirectory(SHGetFolderPath('LOCAL_APPDATA') .. 'Gas Powered Games/Supreme Co
MountDirectory(fa_path .. "/movies", '/movies')
MountDirectory(fa_path .. "/sounds", '/sounds')
MountDirectory(fa_path .. "/maps", '/maps')
MountDirectory(fa_path .. "/fonts", '/fonts')
MountDirectory(fa_path .. "/fonts", '/fonts')

-- Allows developers to embed code to debug a replay
table.insert(path, 1, { dir = InitFileDir .. '\\..\\Debug', mountpoint = '/' })
4 changes: 2 additions & 2 deletions init_fafdevelop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -642,5 +642,5 @@ MountDirectory(fa_path .. "/sounds", '/sounds')
MountDirectory(fa_path .. "/maps", '/maps')
MountDirectory(fa_path .. "/fonts", '/fonts')

-- Please do not delete these lines. This is necessary for testing.
table.insert(path, 1, { dir = InitFileDir .. '\\..\\DevData', mountpoint = '/' })
-- Allows developers to embed code to debug a replay
table.insert(path, 1, { dir = InitFileDir .. '\\..\\Debug', mountpoint = '/' })
30 changes: 30 additions & 0 deletions lua/shared/components/DebugComponent.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--******************************************************************************************************
--** Copyright (c) 2024 Willem 'Jip' Wijnia
--**
--** Permission is hereby granted, free of charge, to any person obtaining a copy
--** of this software and associated documentation files (the "Software"), to deal
--** in the Software without restriction, including without limitation the rights
--** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
--** copies of the Software, and to permit persons to whom the Software is
--** furnished to do so, subject to the following conditions:
--**
--** The above copyright notice and this permission notice shall be included in all
--** copies or substantial portions of the Software.
--**
--** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
--** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
--** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
--** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
--** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
--** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
--** SOFTWARE.
--******************************************************************************************************

---@class DebugComponent
DebugComponent = ClassSimple {
EnabledSpewing = true,
EnabledLogging = true,
EnabledWarnings = true,
EnabledErrors = true,
EnabledDrawing = true,
}
6 changes: 4 additions & 2 deletions lua/sim/Projectile.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ local CreateEmitterAtBone = CreateEmitterAtBone
local CreateEmitterAtEntity = CreateEmitterAtEntity
local EntityCategoryContains = EntityCategoryContains

local DebugProjectileComponent = import("/lua/sim/projectiles/components/DebugProjectileComponent.lua").DebugProjectileComponent

local ProjectileMethods = moho.projectile_methods
local ProjectileMethodsCreateChildProjectile = ProjectileMethods.CreateChildProjectile
local ProjectileMethodsGetMaxZigZag = ProjectileMethods.GetMaxZigZag
Expand Down Expand Up @@ -82,7 +84,7 @@ local OnImpactPreviousZ = 0

local VectorCached = Vector(0, 0, 0)

---@class Projectile : moho.projectile_methods, InternalObject
---@class Projectile : moho.projectile_methods, InternalObject, DebugProjectileComponent
---@field Blueprint ProjectileBlueprint
---@field Army number
---@field Trash TrashBag
Expand All @@ -93,7 +95,7 @@ local VectorCached = Vector(0, 0, 0)
---@field IsRedirected? boolean
---@field InnerRing? NukeAOE
---@field OuterRing? NukeAOE
Projectile = ClassProjectile(ProjectileMethods) {
Projectile = ClassProjectile(ProjectileMethods, DebugProjectileComponent) {
IsProjectile = true,
DestroyOnImpact = true,
FxImpactTrajectoryAligned = true,
Expand Down
9 changes: 5 additions & 4 deletions lua/sim/Unit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ local TransportShield = import("/lua/shield.lua").TransportShield
local Weapon = import("/lua/sim/weapon.lua").Weapon
local IntelComponent = import('/lua/defaultcomponents.lua').IntelComponent
local VeterancyComponent = import('/lua/defaultcomponents.lua').VeterancyComponent
local DebugUnitComponent = import("/lua/sim/units/components/DebugUnitComponent.lua").DebugUnitComponent

local GetBlueprintCaptureCost = import('/lua/shared/captureCost.lua').GetBlueprintCaptureCost

Expand Down Expand Up @@ -112,7 +113,7 @@ SyncMeta = {
local cUnit = moho.unit_methods
local cUnitGetBuildRate = cUnit.GetBuildRate

---@class Unit : moho.unit_methods, InternalObject, IntelComponent, VeterancyComponent, AIUnitProperties, UnitBuffFields
---@class Unit : moho.unit_methods, InternalObject, IntelComponent, VeterancyComponent, AIUnitProperties, UnitBuffFields, DebugUnitComponent
---@field CDRHome? LocationType
---@field AIManagerIdentifier? string
---@field Repairers table<EntityId, Unit>
Expand Down Expand Up @@ -145,7 +146,7 @@ local cUnitGetBuildRate = cUnit.GetBuildRate
---@field ReclaimTimeMultiplier? number
---@field CaptureTimeMultiplier? number
---@field PlatoonHandle? Platoon
Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent) {
Unit = ClassUnit(moho.unit_methods, IntelComponent, VeterancyComponent, DebugUnitComponent) {

IsUnit = true,
Weapons = {},
Expand Down Expand Up @@ -5440,12 +5441,12 @@ local EntityGetEntityId = _G.moho.entity_methods.GetEntityId
local UnitGetCurrentLayer = _G.moho.unit_methods.GetCurrentLayer
local UnitGetUnitId = _G.moho.unit_methods.GetUnitId

---@class DummyUnit : moho.unit_methods
---@class DummyUnit : moho.unit_methods, DebugUnitComponent
---@field EntityId EntityId
---@field Army Army
---@field Layer Layer
---@field Blueprint UnitBlueprint
DummyUnit = ClassDummyUnit(moho.unit_methods) {
DummyUnit = ClassDummyUnit(moho.unit_methods, DebugUnitComponent) {

IsUnit = true,

Expand Down
131 changes: 131 additions & 0 deletions lua/sim/projectiles/components/DebugProjectileComponent.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
--******************************************************************************************************
--** Copyright (c) 2024 Willem 'Jip' Wijnia
--**
--** Permission is hereby granted, free of charge, to any person obtaining a copy
--** of this software and associated documentation files (the "Software"), to deal
--** in the Software without restriction, including without limitation the rights
--** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
--** copies of the Software, and to permit persons to whom the Software is
--** furnished to do so, subject to the following conditions:
--**
--** The above copyright notice and this permission notice shall be included in all
--** copies or substantial portions of the Software.
--**
--** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
--** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
--** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
--** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
--** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
--** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
--** SOFTWARE.
--******************************************************************************************************

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

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

---@param self DebugProjectileComponent | Projectile
---@param ... any
DebugSpew = function(self, ...)
if not self.EnabledSpewing then
return
end

local launcher = self.Launcher
if launcher and IsUnit(launcher) and (not IsDestroyed(launcher)) then
-- allows the developer to track down the launcher
launcher:SetCustomName(launcher.EntityId or 'unknown')
self:DebugDraw('gray')
end

SPEW(launcher.UnitId, launcher.EntityId, self.Blueprint.BlueprintId, unpack(arg))
end,

---@param self DebugProjectileComponent | Projectile
---@param ... any
DebugLog = function(self, ...)
if not self.EnabledLogging then
return
end

local launcher = self.Launcher
if launcher and IsUnit(launcher) and (not IsDestroyed(launcher)) then
-- allows the developer to track down the launcher
launcher:SetCustomName(launcher.EntityId or 'unknown')
self:DebugDraw('white')
end

_ALERT(launcher.UnitId, launcher.EntityId, self.Blueprint.BlueprintId, unpack(arg))
end,

---@param self DebugProjectileComponent | Projectile
---@param ... any
DebugWarn = function(self, ...)
if not self.EnabledWarnings then
return
end

local launcher = self.Launcher
if launcher and IsUnit(launcher) and (not IsDestroyed(launcher)) then
-- allows the developer to track down the launcher
launcher:SetCustomName(launcher.EntityId or 'unknown')
self:DebugDraw('orange')
end

WARN(launcher.UnitId, launcher.EntityId, self.Blueprint.BlueprintId, unpack(arg))
end,

---@param self DebugProjectileComponent | Projectile
---@param message any
DebugError = function(self, message)
if not self.EnabledErrors then
return
end

local launcher = self.Launcher
if launcher and IsUnit(launcher) and (not IsDestroyed(launcher)) then
-- allows the developer to track down the launcher
launcher:SetCustomName(launcher.EntityId or 'unknown')
self:DebugDraw('red')
end

error(
string.format(
"%s\t%s\t%s\t%s",
tostring(launcher.UnitId),
tostring(launcher.EntityId),
tostring(self.Blueprint.BlueprintId),
tostring(message)
)
)
end,

---@param self DebugProjectileComponent | Projectile
---@param color? Color # Defaults to white
DebugDraw = function(self, color)
if not self.EnabledDrawing then
return
end

-- we can't draw dead things
if IsDestroyed(self) then
return
end

-- do not draw everything, just what the developer may be interested in
if not (GetFocusArmy() == -1 or GetFocusArmy() == self.Army) then
return
end

color = color or 'ffffff'

local launcher = self.Launcher
if launcher and not IsDestroyed(launcher) then
launcher:DebugDraw(color)
DrawLine(launcher:GetPosition(), self:GetPosition(), color)
end

DrawCircle(self:GetPosition(), 0.25, color)
end,
}
Loading

0 comments on commit 2158d74

Please sign in to comment.