Re: New widget: Enemy Spotter
Posted: 03 Dec 2009, 05:53
.. stop trolling trademark smoth. - ModeratorTradeMark wrote:oh no, soon my thread gets locked again ;_;
Open Source Realtime Strategy Game Engine
https://springrts.com/phpbb/
.. stop trolling trademark smoth. - ModeratorTradeMark wrote:oh no, soon my thread gets locked again ;_;
Team platter uses team color. They can be similar. Other problem that you see circles around your own units and allies. It's a bit harder to distinguish.Wombat wrote:isnt team platter enough ?
don't use it. Trademark wanted this so he made it. you don't have to use this.Wombat wrote:isnt team platter enough ?
Code: Select all
function widget:DrawWorldPreUnit()
glDepthTest(true)
glPolygonOffset(-50, -2)
for _,unitID in ipairs(spGetAllUnits()) do
if (spIsUnitVisible(unitID)) then
My lua understanding is limited.. what is the reason? As in why is this faster?Niobium wrote:This = bad. This widget will be the laggiest widget anyone runs.Code: Select all
function widget:DrawWorldPreUnit() glDepthTest(true) glPolygonOffset(-50, -2) for _,unitID in ipairs(spGetAllUnits()) do if (spIsUnitVisible(unitID)) then
1. Use Spring.GetVisibleUnits(...), it is much more efficient than checking visibility of every unit.
Put simply, as it appears from the source, spring will only check the visibility (expensive) of a subset of all units, rather than all of them.smoth wrote:My lua understanding is limited.. what is the reason? As in why is this faster?Niobium wrote:This = bad. This widget will be the laggiest widget anyone runs.Code: Select all
function widget:DrawWorldPreUnit() glDepthTest(true) glPolygonOffset(-50, -2) for _,unitID in ipairs(spGetAllUnits()) do if (spIsUnitVisible(unitID)) then
1. Use Spring.GetVisibleUnits(...), it is much more efficient than checking visibility of every unit.
how do i do that? i dont think it will work... it needs to be drawn every frame when unit has moved, or it will "lag" the movements...Niobium wrote:2. Also, instead of calling it every drawframe, you should call it in Update() or something a few times per second and store the result in a global table which DrawWorldPreUnit can use. Move enemy checking here as well.
if you read the GetUnitDefRealRadius function further, you notice it will store the data in table, and once it has the data, it returns it straight from the table instead of calculating it again. this will have no impact on efficiency at all.Niobium wrote:3. Don't use this strange GetUnitDefRealRadius function... Use a table like 'table[uDefID] = radius' instead, which you fully build on initialize().
This is stupid statement, especially for games.TradeMark wrote:checking few hundred units or thousand units shouldnt make any more lag, unless you own really crappy CPU...
Code: Select all
local circleDivs = 16 -- how precise circle? octagon by default
local innersize = 1.5 -- circle scale compared to unit radius
local outersize = 0.9 -- outer fade size compared to circle scale (1 = no outer fade)
local fadefrom = { 0, 0, 1, 0 } -- inner color
local colorSet = { 0, 0, 1, 0.23 } -- middle color
local fadeto = { 0, 0, 1, 0.4 } -- outer color
Code: Select all
local circleDivs = 16 -- how precise circle? octagon by default
local innersize = 1.5 -- circle scale compared to unit radius
local outersize = 1.1 -- outer fade size compared to circle scale (1 = no outer fade)
Code: Select all
local circleDivs = 8 -- how precise circle? octagon by default
local innersize = 1.5 -- circle scale compared to unit radius
local outersize = 1.75 -- outer fade size compared to circle scale (1 = no outer fade)
Update is called at the same rate as the Draw functions. To update unit (simulation) related stuff you should use GameFrame().slogic wrote:As i know Update () is called each game frame. There are 30 game frames per sec. DrawWorldPreUnit() should be called (in theory) at videocard framerate. Feel the difference. In DrawWorldPreUnit() you should prefer draw stuff only, not calculation.
I have a widget that maintains a global (across all widgets) table of visible units. It updates visible units only once per second, or whenever the camera changes position/direction (But no more than 10 times per second). You are somewhat correct with this 'lag' thing, in that, it is possible that a visible unit is not in the table, or vice-versa. But every 1 second, and on camera changes, is more than sufficient, I never see a case of a unit not being seen as visible. I'll attach it at the end so you can see what I do.TradeMark wrote:how do i do that? i dont think it will work... it needs to be drawn every frame when unit has moved, or it will "lag" the movements...Niobium wrote:2. Also, instead of calling it every drawframe, you should call it in Update() or something a few times per second and store the result in a global table which DrawWorldPreUnit can use. Move enemy checking here as well.
This is what I use in my custom teamplatters-like widget:TradeMark wrote:if you read the GetUnitDefRealRadius function further, you notice it will store the data in table, and once it has the data, it returns it straight from the table instead of calculating it again. this will have no impact on efficiency at all.Niobium wrote:3. Don't use this strange GetUnitDefRealRadius function... Use a table like 'table[uDefID] = radius' instead, which you fully build on initialize().
Code: Select all
local radiusDefs = {}
for uDefID, uDef in pairs(uDefs) do
radiusDefs[uDefID] = uDef.radius
end
Like he explained it provides a list of visible units for other widget to work with. It has no direct functionality for the user.manolo_ wrote:@Niobium i dled ur widget and nothing happens (fast game vs ai), what should it do?
All it does is provide a way for widgets to quickly get access to visible units, instead of having many widgets constantly calling GetVisibleUnits.SirMaverick wrote:Like he explained it provides a list of visible units for other widget to work with. It has no direct functionality for the user.manolo_ wrote:@Niobium i dled ur widget and nothing happens (fast game vs ai), what should it do?
yeah thats also why there should be some better way to do this... than making some widget mess for it.Niobium wrote:In my case I have three widgets that are faster because of the global visunits widget I posted; healthbars, teamplatter, and unit experience.