Skip to content

Commit

Permalink
Reduce memory impact pt. 1 (FAForever#3875)
Browse files Browse the repository at this point in the history
Reduces the number of pre-allocated fields and tables on units, weapons, props and projectiles.
  • Loading branch information
Garanas authored May 26, 2022
1 parent baca3a9 commit f157fab
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 158 deletions.
5 changes: 3 additions & 2 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ b5ad96a044b34f12b1c95121c4b49297fc0d243d
# Changes all line endings to LF
76f8ac36b322bae6c0145e9da7b56e3e5dabb1ca

# Global white space cleanup
16d5cfebac6ddd19a3a9496b810beb9a1a73d950
# white space cleanups
16d5cfebac6ddd19a3a9496b810beb9a1a73d950
ce65d77916260cb29d021a036d484e84bd38eabd
38 changes: 19 additions & 19 deletions lua/EffectUtilitiesAeon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ local function SharedBuildThread(pool, unitBeingBuilt, unitBeingBuiltTrash, unit
if EntityCategoryContains(CategoriesHover, unitBeingBuilt) then

-- set elevation offset
offset = unitBeingBuilt.Elevation or 0
offset = unitBeingBuilt.Blueprint.Elevation or 0

-- create a slider
slider = CreateSlider(unitBeingBuilt, 0)
Expand Down Expand Up @@ -132,7 +132,7 @@ local function SharedBuildThread(pool, unitBeingBuilt, unitBeingBuiltTrash, unit
end

-- set correct shader of unitBeingBuilt so that it happens instantly after finishing
unitBeingBuilt:SetMesh(unitBeingBuilt.MeshBlueprint, true)
unitBeingBuilt:SetMesh(unitBeingBuilt.Blueprint.Display.MeshBlueprint, true)
end

--- The build animation for Aeon buildings in general.
Expand All @@ -153,20 +153,20 @@ function CreateAeonBuildBaseThread(unitBeingBuilt, builder, effectsBag)

local effect = false
local army = unitBeingBuilt.Army
local orientation = EntityGetOrientation(unitBeingBuilt)
local unitBeingBuiltTrash = unitBeingBuilt.Trash
local unitOnStopBeingBuiltTrash = unitBeingBuilt.OnBeingBuiltEffectsBag
local sx = unitBeingBuilt.BuildExtentsX
local sz = unitBeingBuilt.BuildExtentsZ
local sy = unitBeingBuilt.BuildExtentsY or (sx + sz)
local bp = unitBeingBuilt.Blueprint
local sx = bp.Physics.MeshExtentsX or bp.Footprint.SizeX
local sz = bp.Physics.MeshExtentsZ or bp.Footprint.SizeZ
local sy = bp.Physics.MeshExtentsY or bp.Footprint.SizeYX or (sx + sz)

-- # Create pool of mercury

local pool = EntityCreateProjectile(unitBeingBuilt, '/effects/entities/AeonBuildEffect/AeonBuildEffect01_proj.bp', nil, 0, 0, nil, nil, nil)
TrashBagAdd(unitBeingBuiltTrash, pool)
TrashBagAdd(unitOnStopBeingBuiltTrash, pool)

EntitySetOrientation(pool, orientation, true)
EntitySetOrientation(pool, EntityGetOrientation(unitBeingBuilt), true)
ProjectileSetScale(pool, sx, sy * 1.5, sz)

-- # Create effects
Expand Down Expand Up @@ -229,9 +229,9 @@ function CreateAeonFactoryBuildingEffects(builder, unitBeingBuilt, buildEffectBo
local unitBeingBuiltTrash = unitBeingBuilt.Trash
local unitOnStopBeingBuiltTrash = unitBeingBuilt.OnBeingBuiltEffectsBag

local sx = unitBeingBuilt.BuildExtentsX
local sz = unitBeingBuilt.BuildExtentsZ
local sy = unitBeingBuilt.BuildExtentsY or (sx + sz)
local sx = unitBeingBuilt.Blueprint.Physics.MeshExtentsX or unitBeingBuilt.Blueprint.Footprint.SizeX
local sz = unitBeingBuilt.Blueprint.Physics.MeshExtentsZ or unitBeingBuilt.Blueprint.Footprint.SizeZ
local sy = unitBeingBuilt.Blueprint.Physics.MeshExtentsY or unitBeingBuilt.Blueprint.Footprint.SizeY or (sx + sz)

-- # Create pool of mercury

Expand Down Expand Up @@ -443,9 +443,9 @@ function CreateAeonCZARBuildingEffects(unitBeingBuilt)
local onFinishedTrash = unitBeingBuilt.OnBeingBuiltEffectsBag
local orientation = EntityGetOrientation(unitBeingBuilt)

local sx = 0.6 * unitBeingBuilt.BuildExtentsX
local sz = 0.6 * unitBeingBuilt.BuildExtentsZ
local sy = 1.5 * (unitBeingBuilt.BuildExtentsY or (sx + sz))
local sx = 0.6 * unitBeingBuilt.Blueprint.Physics.MeshExtentsX or unitBeingBuilt.Blueprint.Footprint.SizeX
local sz = 0.6 * unitBeingBuilt.Blueprint.Physics.MeshExtentsZ or unitBeingBuilt.Blueprint.Footprint.SizeZ
local sy = 1.5 * unitBeingBuilt.Blueprint.Physics.MeshExtentsY or unitBeingBuilt.Blueprint.Footprint.SizeY or (sx + sz)

-- # Create generic build effects

Expand Down Expand Up @@ -513,9 +513,9 @@ function CreateAeonTempestBuildingEffects(unitBeingBuilt)
local onFinishedTrash = unitBeingBuilt.OnBeingBuiltEffectsBag
local orientation = EntityGetOrientation(unitBeingBuilt)

local sx = 0.55 * unitBeingBuilt.BuildExtentsX
local sz = 0.55 * unitBeingBuilt.BuildExtentsZ
local sy = 3 * unitBeingBuilt.BuildExtentsY or (sx + sz)
local sx = 0.55 * unitBeingBuilt.Blueprint.Physics.MeshExtentsX or unitBeingBuilt.Blueprint.Footprint.SizeX
local sz = 0.55 * unitBeingBuilt.Blueprint.Physics.MeshExtentsZ or unitBeingBuilt.Blueprint.Footprint.SizeZ
local sy = 3 * unitBeingBuilt.Blueprint.Physics.MeshExtentsY or unitBeingBuilt.Blueprint.Footprint.SizeY or (sx + sz)

-- # Create effects of build animation

Expand Down Expand Up @@ -619,9 +619,9 @@ function CreateAeonParagonBuildingEffects(unitBeingBuilt)
local onFinishedTrash = unitBeingBuilt.OnBeingBuiltEffectsBag
local orientation = EntityGetOrientation(unitBeingBuilt)

local sx = 1 * unitBeingBuilt.BuildExtentsX
local sz = 1 * unitBeingBuilt.BuildExtentsZ
local sy = 2 * unitBeingBuilt.BuildExtentsY or (sx + sz)
local sx = 1 * unitBeingBuilt.Blueprint.Physics.MeshExtentsX or unitBeingBuilt.Blueprint.Footprint.SizeX
local sz = 1 * unitBeingBuilt.Blueprint.Physics.MeshExtentsZ or unitBeingBuilt.Blueprint.Footprint.SizeZ
local sy = 2 * unitBeingBuilt.Blueprint.Physics.MeshExtentsY or unitBeingBuilt.Blueprint.Footprint.SizeY or (sx + sz)

-- # Create effects of build animation

Expand Down
14 changes: 10 additions & 4 deletions lua/EffectUtilitiesSeraphim.lua
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,15 @@ function CreateSeraphimFactoryBuildingEffects(builder, unitBeingBuilt, effectBon

local effect = false
local army = builder.Army
local sy = unitBeingBuilt.BuildExtentsY or (unitBeingBuilt.BuildExtentsX + unitBeingBuilt.BuildExtentsZ) or 1
local bp = unitBeingBuilt.Blueprint
local sx = bp.Physics.MeshExtentsX or bp.Footprint.SizeX
local sz = bp.Physics.MeshExtentsZ or bp.Footprint.SizeZ
local sy = bp.Physics.MeshExtentsY or bp.Footprint.SizeYX or (sx + sz)

-- do not apply offsets for subs and air units
local offset = 0
if unitBeingBuilt.Cache.HashedCats["HOVER"] then
offset = unitBeingBuilt.Elevation or 0
offset = bp.Elevation or 0
end

-- # Create effects for each build bone
Expand Down Expand Up @@ -166,7 +169,10 @@ function CreateSeraphimBuildThread(unitBeingBuilt, builder, effectsBag, scaleFac
-- determine a sane LOD cutoff for the size of the unit
local lods = unitBeingBuilt.Blueprint.Display.Mesh.LODs
local count = TableGetn(lods)
local LODCutoff = 0.9 * lods[count].LODCutoff or (90 * MathMax(unitBeingBuilt.BuildExtentsX, unitBeingBuilt.BuildExtentsZ))

local sx = unitBeingBuilt.Blueprint.Physics.MeshExtentsX or unitBeingBuilt.Blueprint.Footprint.SizeX
local sz = unitBeingBuilt.Blueprint.Physics.MeshExtentsZ or unitBeingBuilt.Blueprint.Footprint.SizeZ
local LODCutoff = 0.9 * lods[count].LODCutoff or (90 * MathMax(sx, sz))

-- smaller inner, dark-purple effect
for _, vEffect in BuildEffectsEmitters do
Expand All @@ -193,7 +199,7 @@ function CreateSeraphimBuildThread(unitBeingBuilt, builder, effectsBag, scaleFac
-- # Scale effects until the unit is finished

-- only naval factories are not square, use the Z axis to get largest axis
local unitScaleMetric = unitBeingBuilt.BuildExtentsZ * 0.75
local unitScaleMetric = 0.75 * sz
local complete = UnitGetFractionComplete(unitBeingBuilt)
while not unitBeingBuilt.Dead and complete < 1.0 do

Expand Down
18 changes: 9 additions & 9 deletions lua/EffectUtilitiesUEF.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,9 @@ function CreateUEFBuildSliceBeams(
end

-- Determine beam positioning on build cube, this should match sizes of CreateBuildCubeThread
local ox = unitBeingBuilt.BuildExtentsX
local oz = unitBeingBuilt.BuildExtentsZ
local oy = unitBeingBuilt.BuildExtentsY
local ox = unitBeingBuilt.Blueprint.Physics.MeshExtentsX or unitBeingBuilt.Blueprint.Footprint.SizeX
local oz = unitBeingBuilt.Blueprint.Physics.MeshExtentsZ or unitBeingBuilt.Blueprint.Footprint.SizeZ
local oy = unitBeingBuilt.Blueprint.Physics.MeshExtentsY or unitBeingBuilt.Blueprint.Footprint.SizeY or (ox + oz)

ox = ox * 0.5
oz = oz * 0.5
Expand Down Expand Up @@ -266,9 +266,9 @@ function CreateBuildCubeThread(
local px, py, pz = EntityGetPositionXYZ(unitBeingBuilt)
py = py + (unitBeingBuilt.Blueprint.Physics.MeshExtentsOffsetY or 0)

local bx = unitBeingBuilt.BuildExtentsX
local by = unitBeingBuilt.BuildExtentsY
local bz = unitBeingBuilt.BuildExtentsZ
local bx = unitBeingBuilt.Blueprint.Physics.MeshExtentsX or unitBeingBuilt.Blueprint.Footprint.SizeX
local bz = unitBeingBuilt.Blueprint.Physics.MeshExtentsZ or unitBeingBuilt.Blueprint.Footprint.SizeZ
local by = unitBeingBuilt.Blueprint.Physics.MeshExtentsY or unitBeingBuilt.Blueprint.Footprint.SizeY or (bx + bz)

-- create a quick glow effect
local proj = EntityCreateProjectile(unitBeingBuilt, '/effects/Entities/UEFBuildEffect/UEFBuildEffect02_proj.bp', 0, 0, 0, nil, nil, nil)
Expand Down Expand Up @@ -420,9 +420,9 @@ function CreateUEFCommanderBuildSliceBeams(
end

-- Determine beam positioning on build cube, this should match sizes of CreateBuildCubeThread
local ox = unitBeingBuilt.BuildExtentsX
local oz = unitBeingBuilt.BuildExtentsZ
local oy = unitBeingBuilt.BuildExtentsY
local ox = unitBeingBuilt.Blueprint.Physics.MeshExtentsX or unitBeingBuilt.Blueprint.Footprint.SizeX
local oz = unitBeingBuilt.Blueprint.Physics.MeshExtentsZ or unitBeingBuilt.Blueprint.Footprint.SizeZ
local oy = unitBeingBuilt.Blueprint.Physics.MeshExtentsY or unitBeingBuilt.Blueprint.Footprint.SizeY or (ox + oz)

ox = ox * 0.5
oz = oz * 0.5
Expand Down
4 changes: 2 additions & 2 deletions lua/cybranunits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ CConstructionUnit = Class(ConstructionUnit, CConstructionTemplate){
end,

LayerChangeTrigger = function(self, new, old)
if self.AnimationWater then
if self.Blueprint.Display.AnimationWater then
if self.TerrainLayerTransitionThread then
self.TerrainLayerTransitionThread:Destroy()
self.TerrainLayerTransitionThread = nil
Expand All @@ -429,7 +429,7 @@ CConstructionUnit = Class(ConstructionUnit, CConstructionTemplate){
end

if water then
self.TransformManipulator:PlayAnim(self.AnimationWater)
self.TransformManipulator:PlayAnim(self.Blueprint.Display.AnimationWater)
self.TransformManipulator:SetRate(1)
self.TransformManipulator:SetPrecedence(0)
else
Expand Down
2 changes: 1 addition & 1 deletion lua/defaultunits.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ StructureUnit = Class(Unit) {
OnCreate = function(self)
Unit.OnCreate(self)
self:HideLandBones()
self.WeaponMod = {}
self.AdjacentUnits = {}
self.FxBlinkingLightsBag = {}
if self.Layer == 'Land' and self.Blueprint.Physics.FlattenSkirt then
self:FlattenSkirt()
Expand Down
10 changes: 0 additions & 10 deletions lua/proptree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,6 @@ local EffectSetEmitterCurveParam = EffectMethods.SetEmitterCurveParam

Tree = Class(Prop) {

--- Initialize the tree
OnCreate = function (self, spec)
Prop.OnCreate(self, spec)
self.NoBurn = false
self.Burning = false
self.Fallen = false
self.Dead = false
end,

OnDestroy = function(self)
Prop.OnDestroy(self)

Expand Down Expand Up @@ -77,7 +68,6 @@ Tree = Class(Prop) {
--- When damaged in some fashion - note that the tree can only be destroyed by disintegrating
-- damage and that the base class is not called accordingly.
OnDamage = function(self, instigator, amount, direction, type)

if not self.Dead then

local canFall = not self.Fallen
Expand Down
6 changes: 1 addition & 5 deletions lua/sim/Prop.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ local StringGsub = string.gsub
-- upvalue table functions for performance
local TableInsert = table.insert

Prop = Class(moho.prop_methods, Entity) {

-- override the functions provided in the Entity class: we don't need an additional c-object!
__init = false,
__post_init = false,
Prop = Class(moho.prop_methods) {

OnCreate = function(self)

Expand Down
Loading

0 comments on commit f157fab

Please sign in to comment.