Pazyryk
Deity
- Joined
- Jun 13, 2008
- Messages
- 3,584
I've resisted this (so far) out of fear of overhead. But it's just too tempting.
Has anyone used this and payed attention to game speed effects? The Lua part of my code should be very efficient:
The majority of units will not be indexed in g_unitsToWatch, so it is just a quick index check that resolves to nil. But I suspect the overhead here would actually be on the C++ side (how the DLL passes off to Lua). If it can do that 1000 times/sec, OK. If < 100, not so OK.
Has anyone used this and payed attention to game speed effects? The Lua part of my code should be very efficient:
Code:
local g_unitsToWatch = {}
for iPlayer = 0, GameDefines.MAX_PLAYERS - 1 do
g_unitsToWatch[iPlayer] = {}
end
local function OnUnitSetXY(iPlayer, iUnit, x, y)
if g_unitsToWatch[iPlayer][iUnit] then
--stuff happens
end
end
GameEvents.UnitSetXY(OnUnitSetXY)
The majority of units will not be indexed in g_unitsToWatch, so it is just a quick index check that resolves to nil. But I suspect the overhead here would actually be on the C++ side (how the DLL passes off to Lua). If it can do that 1000 times/sec, OK. If < 100, not so OK.