Skip to content

Commit

Permalink
Optimize marker usage (FAForever#3387)
Browse files Browse the repository at this point in the history
* Add a marker utilities file to manage markers on a map.

Specifically it allows AI developers / map scripters to work
with markers without having to worrying about underlying
inefficiencies. As an example, retrieving the mass markers
on a map is a common operation for AIs. If done through
the base game code it would re-allocate a new table of
markers each time an AI condition manager starts checking
the state of the game. That is quite wasteful. This file keeps
track of previous calls, caching the result. Supports adaptive
and crazy rush-like maps.

Introduces a UI that allows you to inspect the cached 
markers. The window is toggled with 'K' by default.
  • Loading branch information
Garanas authored Feb 6, 2022
1 parent f99f88a commit b2fc59f
Show file tree
Hide file tree
Showing 9 changed files with 644 additions and 5 deletions.
8 changes: 8 additions & 0 deletions lua/SimCallbacks.lua
Original file line number Diff line number Diff line change
Expand Up @@ -580,3 +580,11 @@ Callbacks.FlagShield = function(data, units)
end

Callbacks.WeaponPriorities = import('/lua/WeaponPriorities.lua').SetWeaponPriorities

Callbacks.ToggleDebugChainByName = function (data, units)
LOG("ToggleDebugChainByName")
end

Callbacks.ToggleDebugMarkersByType = function (data, units)
import("/lua/sim/markerutilities.lua").ToggleDebugMarkersByType(data.Type)
end
1 change: 1 addition & 0 deletions lua/keymap/alternativeKeyMap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ defaultKeyMap = {
['F10'] = 'toggle_main_menu',
['F11'] = 'toggle_disconnect_screen',
['F12'] = 'show_objective_screen',
['K'] = 'toggle_markers_screen',

['1'] = 'group1',
['2'] = 'group2',
Expand Down
1 change: 1 addition & 0 deletions lua/keymap/defaultKeyMap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ defaultKeyMap = {
['F10'] = 'toggle_main_menu',
['F11'] = 'toggle_disconnect_screen',
['F12'] = 'show_objective_screen',
['K'] = 'toggle_markers_screen',

['1'] = 'group1',
['2'] = 'group2',
Expand Down
1 change: 1 addition & 0 deletions lua/keymap/hotbuildKeyMap.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ defaultKeyMap = {
['F10'] = 'toggle_main_menu',
['F11'] = 'toggle_disconnect_screen',
['F12'] = 'show_objective_screen',
['K'] = 'toggle_markers_screen',

['1'] = 'group1',
['2'] = 'group2',
Expand Down
2 changes: 2 additions & 0 deletions lua/keymap/keyactions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ keyActions = {
category = 'ui', order = 4,},
['toggle_disconnect_screen'] = {action = 'UI_Lua import("/lua/ui/game/connectivity.lua").CreateUI()',
category = 'ui', order = 21,},
['toggle_markers_screen'] = {action = 'UI_Lua import("/lua/ui/dialogs/MarkerUtilitiesView.lua").OpenWindow()',
category = 'ui', order = 21,},
['toggle_reclaim_labels'] = {action = 'UI_Lua import("/lua/ui/game/reclaim.lua").ToggleReclaim()',
category = 'ui'},
['group1'] = {action = 'UI_ApplySelectionSet 1',
Expand Down
67 changes: 62 additions & 5 deletions lua/maui/window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
--# cursorFunc = UIUtil.GetCursor,
--#}
--#################################################

local UIUtil = import('/lua/ui/uiutil.lua')
local Group = import('/lua/maui/group.lua').Group
local Bitmap = import('/lua/maui/bitmap.lua').Bitmap
local Text = import('/lua/maui/text.lua').Text
Expand All @@ -71,11 +73,11 @@ styles = {}

Window = Class(Group) {
__init = function(self, parent, title, icon, pin, config, lockSize, lockPosition, prefID, defaultPosition, textureTable)
Group.__init(self, parent, 'window')
Group.__init(self, parent, tostring(title) .. "-window")

self:DisableHitTest()

self._resizeGroup = Group(parent, 'window resize group')
self._resizeGroup = Group(self, 'window resize group')
LayoutHelpers.FillParent(self._resizeGroup, self)
self._resizeGroup.Depth:Set(function() return self.Depth() + 100 end)
self._resizeGroup:DisableHitTest()
Expand Down Expand Up @@ -550,6 +552,61 @@ Window = Class(Group) {

OnMouseWheel = function(self, rotation) end,

OnClose = function(self) end,
OnHideWindow = function(self, hidden) end,
}
OnClose = function(control) end,
OnHideWindow = function(control, hidden) end,
}

local windowTextures = {
tl = UIUtil.UIFile('/game/mini-map-brd/mini-map_brd_ul.dds'),
tr = UIUtil.UIFile('/game/mini-map-brd/mini-map_brd_ur.dds'),
tm = UIUtil.UIFile('/game/mini-map-brd/mini-map_brd_horz_um.dds'),
ml = UIUtil.UIFile('/game/mini-map-brd/mini-map_brd_vert_l.dds'),
m = UIUtil.UIFile('/game/mini-map-brd/mini-map_brd_m.dds'),
mr = UIUtil.UIFile('/game/mini-map-brd/mini-map_brd_vert_r.dds'),
bl = UIUtil.UIFile('/game/mini-map-brd/mini-map_brd_ll.dds'),
bm = UIUtil.UIFile('/game/mini-map-brd/mini-map_brd_lm.dds'),
br = UIUtil.UIFile('/game/mini-map-brd/mini-map_brd_lr.dds'),
borderColor = 'ff415055',
}

--- Constructs a default window.
-- @param parent Parent of the window, defaults to GetFrame(0)
-- @param title Title of the window
-- @param icon Path to the icon to use for the window, defaults to false (in other words: no icon)
-- @param pin Toggle for the pin button, override window.OnPinCheck(self, checked) to set the behavior
-- @param config Toggle for configuration button, override window.OnConfigClick(self) to set the behavior
-- @Param lockSize Toggle to allow the user to adjust the size of the window.
-- @param lockPosition Toggle to allow the user to adjust the position of the window.
-- @param preferenceID Identifier used in the preference file to remember where this window was located last
-- @param defaultLeft The default left boundary of the window, defaults to 10
-- @param defaultTop The default top boundary of the window, defaults to 300
-- @param defaultBottom The default bottom boundary of the window, defaults to 600
-- @param defaultRight The default right boundary of the window, defaults to 210
function CreateDefaultWindow(parent, title, icon, pin, config, lockSize, lockPosition, preferenceID, defaultLeft, defaultTop, defaultBottom, defaultRight)

-- allow for optionals
parent = parent or GetFrame(0)

defaultLeft = defaultLeft or 10
defaultTop = defaultTop or 300
defaultBottom = defaultBottom or 600
defaultRight = defaultRight or 210

-- setup data
local defaults = { Left = defaultLeft, Top = defaultTop, Bottom = defaultBottom, Right = defaultRight }

-- create and return window
return Window(
parent, -- parent
title, -- title
icon, -- icon
pin, -- pin
config, -- config
lockSize, -- lockSize
lockPosition, -- lockPosition
preferenceID, -- prefID
defaults, -- default position
windowTextures -- textureTable
)

end
Loading

0 comments on commit b2fc59f

Please sign in to comment.