mirror of
https://github.com/FlightControl-Master/MOOSE.git
synced 2025-08-15 10:47:21 +00:00
UTILS - added FiFo
CTLD - correct imperial hover check messages
This commit is contained in:
parent
6828f7e262
commit
5065d3b068
@ -3848,7 +3848,7 @@ end
|
||||
else
|
||||
local minheight = UTILS.MetersToFeet(self.minimumHoverHeight)
|
||||
local maxheight = UTILS.MetersToFeet(self.maximumHoverHeight)
|
||||
text = string.format("Hover parameters (autoload/drop):\n - Min height %dm \n - Max height %dm \n - Max speed 6fts \n - In parameter: %s", minheight, maxheight, htxt)
|
||||
text = string.format("Hover parameters (autoload/drop):\n - Min height %dft \n - Max height %dft \n - Max speed 6ftps \n - In parameter: %s", minheight, maxheight, htxt)
|
||||
end
|
||||
self:_SendMessage(text, 10, false, Group)
|
||||
return self
|
||||
|
||||
@ -1668,8 +1668,8 @@ function UTILS.GetOSTime()
|
||||
end
|
||||
|
||||
--- Shuffle a table accoring to Fisher Yeates algorithm
|
||||
--@param #table t Table to be shuffled
|
||||
--@return #table
|
||||
--@param #table t Table to be shuffled.
|
||||
--@return #table Shuffled table.
|
||||
function UTILS.ShuffleTable(t)
|
||||
if t == nil or type(t) ~= "table" then
|
||||
BASE:I("Error in ShuffleTable: Missing or wrong type of Argument")
|
||||
@ -1687,6 +1687,32 @@ function UTILS.ShuffleTable(t)
|
||||
return TempTable
|
||||
end
|
||||
|
||||
--- Get a random element of a table.
|
||||
--@param #table t Table.
|
||||
--@param #boolean replace If `true`, the drawn element is replaced, i.e. not deleted.
|
||||
--@return #number Table element.
|
||||
function UTILS.GetRandomTableElement(t, replace)
|
||||
|
||||
if t == nil or type(t) ~= "table" then
|
||||
BASE:I("Error in ShuffleTable: Missing or wrong type of Argument")
|
||||
return
|
||||
end
|
||||
|
||||
math.random()
|
||||
math.random()
|
||||
math.random()
|
||||
|
||||
local r=math.random(#t)
|
||||
|
||||
local element=t[r]
|
||||
|
||||
if not replace then
|
||||
table.remove(t, r)
|
||||
end
|
||||
|
||||
return element
|
||||
end
|
||||
|
||||
--- (Helicopter) Check if one loading door is open.
|
||||
--@param #string unit_name Unit name to be checked
|
||||
--@return #boolean Outcome - true if a (loading door) is open, false if not, nil if none exists.
|
||||
@ -2329,3 +2355,215 @@ function UTILS.LoadStationaryListOfStatics(Path,Filename,Reduce)
|
||||
end
|
||||
return datatable
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- FIFO
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
do
|
||||
--- **UTILS** - FiFo Stack.
|
||||
--
|
||||
-- **Main Features:**
|
||||
--
|
||||
-- * Build a simple multi-purpose FiFo (First-In, First-Out) stack for generic data.
|
||||
--
|
||||
-- ===
|
||||
--
|
||||
-- ### Author: **applevangelist**
|
||||
-- @module Utils.FiFo
|
||||
-- @image MOOSE.JPG
|
||||
|
||||
|
||||
--- FIFO class.
|
||||
-- @type FIFO
|
||||
-- @field #string ClassName Name of the class.
|
||||
-- @field #boolean debug
|
||||
-- @field #string lid Class id string for output to DCS log file.
|
||||
-- @field #string version Version of FiFo
|
||||
-- @field #number counter
|
||||
-- @field #number pointer
|
||||
-- @field #number nextin
|
||||
-- @field #number nextout
|
||||
-- @field #table stackbypointer
|
||||
-- @field #table stackbyid
|
||||
-- @extends Core.Base#BASE
|
||||
--
|
||||
|
||||
---
|
||||
-- @type FIFO.IDEntry
|
||||
-- @field #number pointer
|
||||
-- @field #table data
|
||||
-- @field #table uniqueID
|
||||
|
||||
---
|
||||
-- @field #FIFO
|
||||
FIFO = {
|
||||
ClassName = "FIFO",
|
||||
debug = true,
|
||||
lid = "",
|
||||
version = "0.0.1",
|
||||
counter = 0,
|
||||
pointer = 0,
|
||||
nextin = 0,
|
||||
nextout = 0,
|
||||
stackbypointer = {},
|
||||
stackbyid = {}
|
||||
}
|
||||
|
||||
--- Instantiate a new FIFO Stack
|
||||
-- @param #FIFO self
|
||||
-- @return #FIFO self
|
||||
function FIFO:New()
|
||||
-- Inherit everything from BASE class.
|
||||
local self=BASE:Inherit(self, BASE:New()) -- #INTEL
|
||||
self.pointer = 0
|
||||
self.counter = 0
|
||||
self.stackbypointer = {}
|
||||
self.stackbyid = {}
|
||||
-- Set some string id for output to DCS.log file.
|
||||
self.lid=string.format("%s (%s) | ", "FiFo", self.version)
|
||||
self:I(self.lid .."Created.")
|
||||
return self
|
||||
end
|
||||
|
||||
--- FIFO Push Object to Stack
|
||||
-- @param #FIFO self
|
||||
-- @param #table Object
|
||||
-- @param #string UniqueID (optional) - will default to current pointer + 1
|
||||
-- @return #FIFO self
|
||||
function FIFO:Push(Object,UniqueID)
|
||||
self:T(self.lid.."Push")
|
||||
self:T({Object,UniqueID})
|
||||
self.pointer = self.pointer + 1
|
||||
self.counter = self.counter + 1
|
||||
self.stackbypointer[self.pointer] = { pointer = self.pointer, data = Object, uniqueID = UniqueID }
|
||||
if UniqueID then
|
||||
self.stackbyid[UniqueID] = { pointer = self.pointer, data = Object, uniqueID = UniqueID }
|
||||
else
|
||||
self.stackbyid[self.pointer] = { pointer = self.pointer, data = Object, uniqueID = UniqueID }
|
||||
end
|
||||
return self
|
||||
end
|
||||
|
||||
--- FIFO Pull Object from Stack
|
||||
-- @param #FIFO self
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function FIFO:Pull()
|
||||
self:T(self.lid.."Pull")
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbypointer[self.pointer].data
|
||||
self.stackbypointer[self.pointer] = nil
|
||||
self.counter = self.counter - 1
|
||||
self.pointer = self.pointer - 1
|
||||
self:Flatten()
|
||||
return object
|
||||
end
|
||||
|
||||
--- FIFO Pull Object from Stack by Pointer
|
||||
-- @param #FIFO self
|
||||
-- @param #number Pointer
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function FIFO:PullByPointer(Pointer)
|
||||
self:T(self.lid.."PullByPointer " .. tostring(Pointer))
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbypointer[Pointer] -- #FIFO.IDEntry
|
||||
self.stackbypointer[Pointer] = nil
|
||||
self.stackbyid[object.uniqueID] = nil
|
||||
self.counter = self.counter - 1
|
||||
self:Flatten()
|
||||
return object.data
|
||||
end
|
||||
|
||||
--- FIFO Pull Object from Stack by UniqueID
|
||||
-- @param #FIFO self
|
||||
-- @param #tableUniqueID
|
||||
-- @return #table Object or nil if stack is empty
|
||||
function FIFO:PullByID(UniqueID)
|
||||
self:T(self.lid.."PullByID " .. tostring(UniqueID))
|
||||
if self.counter == 0 then return nil end
|
||||
local object = self.stackbyid[UniqueID] -- #FIFO.IDEntry
|
||||
--self.stackbyid[UniqueID] = nil
|
||||
return self:PullByPointer(object.pointer)
|
||||
end
|
||||
|
||||
--- FIFO Housekeeping
|
||||
-- @param #FIFO self
|
||||
-- @return #FIFO self
|
||||
function FIFO:Flatten()
|
||||
self:T(self.lid.."Flatten")
|
||||
-- rebuild stacks
|
||||
local pointerstack = {}
|
||||
local idstack = {}
|
||||
local counter = 0
|
||||
for _ID,_entry in pairs(self.stackbypointer) do
|
||||
counter = counter + 1
|
||||
pointerstack[counter] = { pointer = counter, data = _entry.data, uniqueID = _entry.uniqueID}
|
||||
end
|
||||
for _ID,_entry in pairs(pointerstack) do
|
||||
idstack[_entry.uniqueID] = { pointer = _entry.pointer , data = _entry.data, uniqueID = _entry.uniqueID}
|
||||
end
|
||||
self.stackbypointer = nil
|
||||
self.stackbypointer = pointerstack
|
||||
self.stackbyid = nil
|
||||
self.stackbyid = idstack
|
||||
self.counter = counter
|
||||
self.pointer = counter
|
||||
return self
|
||||
end
|
||||
|
||||
--- FIFO Check Stack is empty
|
||||
-- @param #FIFO self
|
||||
-- @return #boolean empty
|
||||
function FIFO:IsEmpty()
|
||||
self:T(self.lid.."IsEmpty")
|
||||
return self.counter == 0 and true or false
|
||||
end
|
||||
|
||||
--- FIFO Check Stack is NOT empty
|
||||
-- @param #FIFO self
|
||||
-- @return #boolean notempty
|
||||
function FIFO:IsNotEmpty()
|
||||
self:T(self.lid.."IsNotEmpty")
|
||||
return not self:IsEmpty()
|
||||
end
|
||||
|
||||
--- FIFO Get the data stack by pointer
|
||||
-- @param #FIFO self
|
||||
-- @return #table Table of #FIFO.IDEntry entries
|
||||
function FIFO:GetPointerStack()
|
||||
self:T(self.lid.."GetPointerStack")
|
||||
return self.stackbypointer
|
||||
end
|
||||
|
||||
--- FIFO Get the data stack by UniqueID
|
||||
-- @param #FIFO self
|
||||
-- @return #table Table of #FIFO.IDEntry entries
|
||||
function FIFO:GetIDStack()
|
||||
self:T(self.lid.."GetIDStack")
|
||||
return self.stackbyid
|
||||
end
|
||||
|
||||
--- FIFO Print stacks to dcs.log
|
||||
-- @param #FIFO self
|
||||
-- @return #FIFO self
|
||||
function FIFO:Flush()
|
||||
self:T(self.lid.."FiFo Flush")
|
||||
self:I("FIFO Flushing Stack by Pointer")
|
||||
for _id,_data in pairs (self.stackbypointer) do
|
||||
local data = _data -- #FIFO.IDEntry
|
||||
self:I(string.format("Pointer: %s | Entry: Number = %s Data = %s UniID = %s",tostring(_id),tostring(data.pointer),tostring(data.data),tostring(data.uniqueID)))
|
||||
end
|
||||
self:I("FIFO Flushing Stack by ID")
|
||||
for _id,_data in pairs (self.stackbyid) do
|
||||
local data = _data -- #FIFO.IDEntry
|
||||
self:I(string.format("ID: %s | Entry: Number = %s Data = %s UniID = %s",tostring(_id),tostring(data.pointer),tostring(data.data),tostring(data.uniqueID)))
|
||||
end
|
||||
self:I("Counter = " .. self.counter)
|
||||
self:I("Pointer = ".. self.pointer)
|
||||
return self
|
||||
end
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
-- End FIFO
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user