Performance Optimizations

This commit is contained in:
Frank
2020-08-22 00:09:36 +02:00
parent 61adeeeda3
commit aac291c0c6
10 changed files with 304 additions and 138 deletions

View File

@@ -254,6 +254,8 @@ end
-- @param #BASE Parent is the Parent class that the Child inherits from.
-- @return #BASE Child
function BASE:Inherit( Child, Parent )
-- Create child.
local Child = routines.utils.deepCopy( Child )
if Child ~= nil then
@@ -269,6 +271,7 @@ function BASE:Inherit( Child, Parent )
--Child:_SetDestructor()
end
return Child
end

View File

@@ -896,31 +896,25 @@ function DATABASE:_RegisterStatics()
return self
end
--- @param #DATABASE self
--- Register all world airbases.
-- @param #DATABASE self
-- @return #DATABASE self
function DATABASE:_RegisterAirbases()
--[[
local CoalitionsData = { AirbasesRed = coalition.getAirbases( coalition.side.RED ), AirbasesBlue = coalition.getAirbases( coalition.side.BLUE ), AirbasesNeutral = coalition.getAirbases( coalition.side.NEUTRAL ) }
for CoalitionId, CoalitionData in pairs( CoalitionsData ) do
for DCSAirbaseId, DCSAirbase in pairs( CoalitionData ) do
local DCSAirbaseName = DCSAirbase:getName()
self:T( { "Register Airbase:", DCSAirbaseName, DCSAirbase:getID() } )
self:AddAirbase( DCSAirbaseName )
end
end
]]
for DCSAirbaseId, DCSAirbase in pairs(world.getAirbases()) do
local DCSAirbaseName = DCSAirbase:getName()
-- Get the airbase name.
local DCSAirbaseName = DCSAirbase:getName()
-- This gives the incorrect value to be inserted into the airdromeID for DCS 2.5.6!
local airbaseID=DCSAirbase:getID()
-- This gave the incorrect value to be inserted into the airdromeID for DCS 2.5.6. Is fixed now.
local airbaseID=DCSAirbase:getID()
local airbase=self:AddAirbase( DCSAirbaseName )
-- Add and register airbase.
local airbase=self:AddAirbase( DCSAirbaseName )
self:I(string.format("Register Airbase: %s, getID=%d, GetID=%d (unique=%d)", DCSAirbaseName, DCSAirbase:getID(), airbase:GetID(), airbase:GetID(true)))
-- Debug output.
self:I(string.format("Register Airbase: %s, getID=%d, GetID=%d (unique=%d)", DCSAirbaseName, DCSAirbase:getID(), airbase:GetID(), airbase:GetID(true)))
end
return self

View File

@@ -228,6 +228,7 @@ do -- COORDINATE
-- @return #COORDINATE
function COORDINATE:New( x, y, z )
--env.info("FF COORDINATE New")
local self = BASE:Inherit( self, BASE:New() ) -- #COORDINATE
self.x = x
self.y = y
@@ -717,12 +718,18 @@ do -- COORDINATE
--- Return the 2D distance in meters between the target COORDINATE and the COORDINATE.
-- @param #COORDINATE self
-- @param #COORDINATE TargetCoordinate The target COORDINATE.
-- @param #COORDINATE TargetCoordinate The target COORDINATE. Can also be a DCS#Vec3.
-- @return DCS#Distance Distance The distance in meters.
function COORDINATE:Get2DDistance( TargetCoordinate )
local TargetVec3 = TargetCoordinate:GetVec3()
local SourceVec3 = self:GetVec3()
return ( ( TargetVec3.x - SourceVec3.x ) ^ 2 + ( TargetVec3.z - SourceVec3.z ) ^ 2 ) ^ 0.5
local a={x=TargetCoordinate.x-self.x, y=0, z=TargetCoordinate.z-self.z}
return UTILS.VecNorm(a)
--local TargetVec3 = TargetCoordinate:GetVec3()
--local SourceVec3 = self:GetVec3()
--return ( ( TargetVec3.x - SourceVec3.x ) ^ 2 + ( TargetVec3.z - SourceVec3.z ) ^ 2 ) ^ 0.5
end
--- Returns the temperature in Degrees Celsius.

View File

@@ -56,6 +56,7 @@
--- @type ZONE_BASE
-- @field #string ZoneName Name of the zone.
-- @field #number ZoneProbability A value between 0 and 1. 0 = 0% and 1 = 100% probability.
-- @field Core.Point#COORDINATE Coordinate object of the zone.
-- @extends Core.Fsm#FSM
@@ -221,22 +222,6 @@ function ZONE_BASE:GetPointVec2()
end
--- Returns a @{Core.Point#COORDINATE} of the zone.
-- @param #ZONE_BASE self
-- @return Core.Point#COORDINATE The Coordinate of the zone.
function ZONE_BASE:GetCoordinate()
self:F2( self.ZoneName )
local Vec2 = self:GetVec2()
local Coordinate = COORDINATE:NewFromVec2( Vec2 )
self:T2( { Coordinate } )
return Coordinate
end
--- Returns the @{DCS#Vec3} of the zone.
-- @param #ZONE_BASE self
-- @param DCS#Distance Height The height to add to the land height where the center of the zone is located.
@@ -276,15 +261,27 @@ end
-- @param DCS#Distance Height The height to add to the land height where the center of the zone is located.
-- @return Core.Point#COORDINATE The Coordinate of the zone.
function ZONE_BASE:GetCoordinate( Height ) --R2.1
self:F2( self.ZoneName )
self:F2(self.ZoneName)
local Vec3 = self:GetVec3( Height )
local PointVec3 = COORDINATE:NewFromVec3( Vec3 )
self:T2( { PointVec3 } )
return PointVec3
if self.Coordinate then
-- Update coordinates.
self.Coordinate.x=Vec3.x
self.Coordinate.y=Vec3.y
self.Coordinate.z=Vec3.z
--env.info("FF GetCoordinate NEW for ZONE_BASE "..tostring(self.ZoneName))
else
-- Create a new coordinate object.
self.Coordinate=COORDINATE:NewFromVec3(Vec3)
--env.info("FF GetCoordinate NEW for ZONE_BASE "..tostring(self.ZoneName))
end
return self.Coordinate
end
@@ -433,12 +430,16 @@ ZONE_RADIUS = {
-- @param DCS#Distance Radius The radius of the zone.
-- @return #ZONE_RADIUS self
function ZONE_RADIUS:New( ZoneName, Vec2, Radius )
-- Inherit ZONE_BASE.
local self = BASE:Inherit( self, ZONE_BASE:New( ZoneName ) ) -- #ZONE_RADIUS
self:F( { ZoneName, Vec2, Radius } )
self.Radius = Radius
self.Vec2 = Vec2
--self.Coordinate=COORDINATE:NewFromVec2(Vec2)
return self
end