From 9e0f03a3cdfe73af5aea8259bf02eaff8425bada Mon Sep 17 00:00:00 2001 From: smiki Date: Thu, 3 Jul 2025 08:44:41 +0200 Subject: [PATCH 1/4] [FIXED] Memory leaks --- .../Moose/Core/MarkerOps_Base.lua | 18 ++++++++++++------ Moose Development/Moose/Core/Zone.lua | 7 +------ .../Moose/Functional/Warehouse.lua | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Moose Development/Moose/Core/MarkerOps_Base.lua b/Moose Development/Moose/Core/MarkerOps_Base.lua index 4571eed25..d249a27cd 100644 --- a/Moose Development/Moose/Core/MarkerOps_Base.lua +++ b/Moose Development/Moose/Core/MarkerOps_Base.lua @@ -156,12 +156,6 @@ function MARKEROPS_BASE:OnEventMark(Event) end --position local vec3={y=Event.pos.y, x=Event.pos.x, z=Event.pos.z} - local coord=COORDINATE:NewFromVec3(vec3) - if self.debug then - local coordtext = coord:ToStringLLDDM() - local text = tostring(Event.text) - local m = MESSAGE:New(string.format("Mark added at %s with text: %s",coordtext,text),10,"Info",false):ToAll() - end local coalition = Event.MarkCoalition -- decision if Event.id==world.event.S_EVENT_MARK_ADDED then @@ -170,6 +164,12 @@ function MARKEROPS_BASE:OnEventMark(Event) local Eventtext = tostring(Event.text) if Eventtext~=nil then if self:_MatchTag(Eventtext) then + local coord=COORDINATE:NewFromVec3(vec3) + if self.debug then + local coordtext = coord:ToStringLLDDM() + local text = tostring(Event.text) + local m = MESSAGE:New(string.format("Mark added at %s with text: %s",coordtext,text),10,"Info",false):ToAll() + end local matchtable = self:_MatchKeywords(Eventtext) self:MarkAdded(Eventtext,matchtable,coord,Event.idx,coalition,Event.PlayerName,Event) end @@ -180,6 +180,12 @@ function MARKEROPS_BASE:OnEventMark(Event) local Eventtext = tostring(Event.text) if Eventtext~=nil then if self:_MatchTag(Eventtext) then + local coord=COORDINATE:NewFromVec3(vec3) + if self.debug then + local coordtext = coord:ToStringLLDDM() + local text = tostring(Event.text) + local m = MESSAGE:New(string.format("Mark added at %s with text: %s",coordtext,text),10,"Info",false):ToAll() + end local matchtable = self:_MatchKeywords(Eventtext) self:MarkChanged(Eventtext,matchtable,coord,Event.idx,coalition,Event.PlayerName,Event) end diff --git a/Moose Development/Moose/Core/Zone.lua b/Moose Development/Moose/Core/Zone.lua index 0ad088d6d..6664364ed 100644 --- a/Moose Development/Moose/Core/Zone.lua +++ b/Moose Development/Moose/Core/Zone.lua @@ -3204,12 +3204,7 @@ function ZONE_POLYGON:Scan( ObjectCategories, UnitCategories ) local vectors = self:GetBoundingSquare() - local minVec3 = {x=vectors.x1, y=0, z=vectors.y1} - local maxVec3 = {x=vectors.x2, y=0, z=vectors.y2} - - local minmarkcoord = COORDINATE:NewFromVec3(minVec3) - local maxmarkcoord = COORDINATE:NewFromVec3(maxVec3) - local ZoneRadius = minmarkcoord:Get2DDistance(maxmarkcoord)/2 + local ZoneRadius = UTILS.VecDist2D({x=vectors.x1, y=vectors.y1}, {x=vectors.x2, y=vectors.y2})/2 -- self:I("Scan Radius:" ..ZoneRadius) local CenterVec3 = self:GetCoordinate():GetVec3() diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 29682074f..51e9ad1f9 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -6893,7 +6893,7 @@ function WAREHOUSE:_CheckConquered() for _,_unit in pairs(units) do local unit=_unit --Wrapper.Unit#UNIT - local distance=coord:Get2DDistance(unit:GetCoordinate()) + local distance=coord:Get2DDistance(unit:GetCoord()) -- Filter only alive groud units. Also check distance again, because the scan routine might give some larger distances. if unit:IsGround() and unit:IsAlive() and distance <= radius then From f9257b2b0dcbe9cb5064ebfb200a1002ab39c91a Mon Sep 17 00:00:00 2001 From: smiki Date: Thu, 3 Jul 2025 09:45:21 +0200 Subject: [PATCH 2/4] [FIXED] Memory leaks --- Moose Development/Moose/Functional/Warehouse.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Moose Development/Moose/Functional/Warehouse.lua b/Moose Development/Moose/Functional/Warehouse.lua index 51e9ad1f9..2486e74b6 100644 --- a/Moose Development/Moose/Functional/Warehouse.lua +++ b/Moose Development/Moose/Functional/Warehouse.lua @@ -3153,7 +3153,7 @@ end -- @param #WAREHOUSE self -- @return Core.Point#COORDINATE The coordinate of the warehouse. function WAREHOUSE:GetCoordinate() - return self.warehouse:GetCoordinate() + return self.warehouse:GetCoord() end --- Get 3D vector of warehouse static. From 773461aad95f0defc0c09902bb59771a82f12cd1 Mon Sep 17 00:00:00 2001 From: smiki Date: Thu, 3 Jul 2025 09:54:07 +0200 Subject: [PATCH 3/4] [FIXED] Memory leaks --- Moose Development/Moose/Core/MarkerOps_Base.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Moose Development/Moose/Core/MarkerOps_Base.lua b/Moose Development/Moose/Core/MarkerOps_Base.lua index d249a27cd..6de154d73 100644 --- a/Moose Development/Moose/Core/MarkerOps_Base.lua +++ b/Moose Development/Moose/Core/MarkerOps_Base.lua @@ -155,7 +155,6 @@ function MARKEROPS_BASE:OnEventMark(Event) return true end --position - local vec3={y=Event.pos.y, x=Event.pos.x, z=Event.pos.z} local coalition = Event.MarkCoalition -- decision if Event.id==world.event.S_EVENT_MARK_ADDED then @@ -164,7 +163,7 @@ function MARKEROPS_BASE:OnEventMark(Event) local Eventtext = tostring(Event.text) if Eventtext~=nil then if self:_MatchTag(Eventtext) then - local coord=COORDINATE:NewFromVec3(vec3) + local coord=COORDINATE:NewFromVec3({y=Event.pos.y, x=Event.pos.x, z=Event.pos.z}) if self.debug then local coordtext = coord:ToStringLLDDM() local text = tostring(Event.text) @@ -180,7 +179,7 @@ function MARKEROPS_BASE:OnEventMark(Event) local Eventtext = tostring(Event.text) if Eventtext~=nil then if self:_MatchTag(Eventtext) then - local coord=COORDINATE:NewFromVec3(vec3) + local coord=COORDINATE:NewFromVec3({y=Event.pos.y, x=Event.pos.x, z=Event.pos.z}) if self.debug then local coordtext = coord:ToStringLLDDM() local text = tostring(Event.text) From 068d21612f0e42b0a00b079d6ef734a9918dd6fc Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Thu, 3 Jul 2025 10:48:54 +0200 Subject: [PATCH 4/4] #MARKEROPS - do not crate a COORDINATE b4 you need it #UTILS - added * UTILS.ShowHelperGate(pos, heading) * UTILS.ShellZone * UTILS.RemoveObjects * UTILS.DestroyScenery --- .../Moose/Core/MarkerOps_Base.lua | 6 ++- Moose Development/Moose/Utilities/Utils.lua | 47 +++++++++++++++++++ Moose Development/Moose/Wrapper/Unit.lua | 7 +++ 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Core/MarkerOps_Base.lua b/Moose Development/Moose/Core/MarkerOps_Base.lua index 4571eed25..d2f056757 100644 --- a/Moose Development/Moose/Core/MarkerOps_Base.lua +++ b/Moose Development/Moose/Core/MarkerOps_Base.lua @@ -50,7 +50,7 @@ MARKEROPS_BASE = { ClassName = "MARKEROPS", Tag = "mytag", Keywords = {}, - version = "0.1.3", + version = "0.1.4", debug = false, Casesensitive = true, } @@ -156,8 +156,8 @@ function MARKEROPS_BASE:OnEventMark(Event) end --position local vec3={y=Event.pos.y, x=Event.pos.x, z=Event.pos.z} - local coord=COORDINATE:NewFromVec3(vec3) if self.debug then + local coord=COORDINATE:NewFromVec3(vec3) local coordtext = coord:ToStringLLDDM() local text = tostring(Event.text) local m = MESSAGE:New(string.format("Mark added at %s with text: %s",coordtext,text),10,"Info",false):ToAll() @@ -171,6 +171,7 @@ function MARKEROPS_BASE:OnEventMark(Event) if Eventtext~=nil then if self:_MatchTag(Eventtext) then local matchtable = self:_MatchKeywords(Eventtext) + local coord=COORDINATE:NewFromVec3(vec3) self:MarkAdded(Eventtext,matchtable,coord,Event.idx,coalition,Event.PlayerName,Event) end end @@ -181,6 +182,7 @@ function MARKEROPS_BASE:OnEventMark(Event) if Eventtext~=nil then if self:_MatchTag(Eventtext) then local matchtable = self:_MatchKeywords(Eventtext) + local coord=COORDINATE:NewFromVec3(vec3) self:MarkChanged(Eventtext,matchtable,coord,Event.idx,coalition,Event.PlayerName,Event) end end diff --git a/Moose Development/Moose/Utilities/Utils.lua b/Moose Development/Moose/Utilities/Utils.lua index f0c7b4aaf..6429e01ed 100644 --- a/Moose Development/Moose/Utilities/Utils.lua +++ b/Moose Development/Moose/Utilities/Utils.lua @@ -4428,3 +4428,50 @@ end function UTILS.Weather.StopFogAnimation() return world.weather.setFogAnimation({}) end + +--- Find a ME created zone by its name +function UTILS.GetEnvZone(name) + for _,v in ipairs(env.mission.triggers.zones) do + if v.name == name then + return v + end + end +end + +--- Show a helper gate at a DCS#Vec3 position +-- @param DCS#Vec3 pos The position +-- @param number heading Heading in degrees, can be 0..359 degrees +function UTILS.ShowHelperGate(pos, heading) + net.dostring_in("mission",string.format("a_show_helper_gate(%s, %s, %s, %f)", pos.x, pos.y, pos.z, math.rad(heading))) +end + +--- Shell a zone, zone must ME created +-- @param #string name The name of the ME created zone +-- @param #number power Equals kg of TNT, e.g. 75 +-- @param #count Number of shells simulated +function UTILS.ShellZone(name, power, count) + local z = UTILS.GetEnvZone(name) + if z then + net.dostring_in("mission",string.format("a_shelling_zone(%d, %d, %d)", z.zoneId, power, count)) + end +end + +--- Remove objects from a zone, zone must ME created +-- @param #string name The name of the ME created zone +-- @param #number type Type of objects to remove can be 0:all, 1: trees, 2:objects +function UTILS.RemoveObjects(name, type) + local z = UTILS.GetEnvZone(name) + if z then + net.dostring_in("mission",string.format("a_remove_scene_objects(%d, %d)", z.zoneId, type)) + end +end + +--- Remove scenery objects from a zone, zone must ME created +-- @param #string name The name of the ME created zone +-- @param #number level Level of removal +function UTILS.DestroyScenery(name, level) + local z = UTILS.GetEnvZone(name) + if z then + net.dostring_in("mission",string.format("a_scenery_destruction_zone(%d, %d)", z.zoneId, level)) + end +end diff --git a/Moose Development/Moose/Wrapper/Unit.lua b/Moose Development/Moose/Wrapper/Unit.lua index 1a5e51011..20ce4837d 100644 --- a/Moose Development/Moose/Wrapper/Unit.lua +++ b/Moose Development/Moose/Wrapper/Unit.lua @@ -1924,3 +1924,10 @@ function UNIT:IsAAA() end return false end + +--- Set the relative life points of a UNIT object +-- @param #UNIT self +-- @param #number Percent Percent to set, can be 0..100. +function UNIT:SetLife(Percent) + net.dostring_in("mission",string.format("a_unit_set_life_percentage(%d, %f)", self:GetID(), Percent)) +end