New widget: Enemy Spotter
Moderator: Moderators
Re: New widget: Enemy Spotter
Well, that sounds good, but the problem there is that then they'd have to be globals. So we'd be paying for access to a global every time we wanted that array.
IOW, 300ms at start, before gameframes run, is just one of the many things we have to pay for at start for faster operation during the entire game.
IOW, 300ms at start, before gameframes run, is just one of the many things we have to pay for at start for faster operation during the entire game.
Re: New widget: Enemy Spotter
yeah 300ms for one widget, what if theres 10 widgets... 3 seconds...
also, isnt there some timeout for widgets...? in metal maps people drop because their metal patch finder or something freezes because of too much metal D:
also, isnt there some timeout for widgets...? in metal maps people drop because their metal patch finder or something freezes because of too much metal D:
Re: New widget: Enemy Spotter
There are no fixed timeouts, so far as I know. And if a Widget gets locked in a loop, then yeah, it'll cause serious problems, just like a Gadget can. Unsynced stuff is downright evil, if it gets locked in a loop or triggers really nasty issues due to iterations growing exponentially.
That's a problem with the Widget, though, not necessarily with Spring itself. If a "metal finder" is written so poorly that it can't handle a metal map, then it's a badly-written piece of software, basically.
It's pretty easy to avoid that kind of lock state- for example, it could do this, at start:
Check X,Z-->X2,Z2. Check only 60 elmos away. Do that 16 times, for a square 240X240 elmos on a side. If all or most of the squares report high metal values... voila, we have a metal map, do not perform further operations.
See? Not rocket science. Just some common sense.
That's a problem with the Widget, though, not necessarily with Spring itself. If a "metal finder" is written so poorly that it can't handle a metal map, then it's a badly-written piece of software, basically.
It's pretty easy to avoid that kind of lock state- for example, it could do this, at start:
Check X,Z-->X2,Z2. Check only 60 elmos away. Do that 16 times, for a square 240X240 elmos on a side. If all or most of the squares report high metal values... voila, we have a metal map, do not perform further operations.
See? Not rocket science. Just some common sense.
Re: New widget: Enemy Spotter
300ms to initialize the table sounded ridiculously high. So I went and tested it. Building the table takes ~0.0002 seconds.
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: New widget: Enemy Spotter
Its because your version is 300% faster.Niobium wrote:300ms to initialize the table sounded ridiculously high. So I went and tested it. Building the table takes ~0.0002 seconds.

If you are not able to reproduce, just ask...
Re: New widget: Enemy Spotter
If it manages to take that long, congrats, you've hit a horrible bug. First, actually check if it's that part of the widget, then report it.
Argh, you can't mention optimization and table.insert/delete in the same sentence. But I think you're missing what I meant. Telling lua to make a table of size 3-10 is reasonable. Initiating a *large* table is an extremely rare case and that's not even the right way to go about it.
Localizing an upvalue is going to have a small impact when you get and set it about 3-5 times.
Argh, you can't mention optimization and table.insert/delete in the same sentence. But I think you're missing what I meant. Telling lua to make a table of size 3-10 is reasonable. Initiating a *large* table is an extremely rare case and that's not even the right way to go about it.
Localizing an upvalue is going to have a small impact when you get and set it about 3-5 times.
Re: New widget: Enemy Spotter
But how long until it's actually slower than using those two additional instructions?Localizing an upvalue is going to have a small impact when you get and set it about 3-5 times.
Re: New widget: Enemy Spotter
I meant a small positive impact. It'll be slower and uglier with 1-4 uses of the var. And what do you mean 'than', localizing IS the two additional instructions.
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: New widget: Enemy Spotter
This is how it happens for me:lurker wrote:If it manages to take that long, congrats, you've hit a horrible bug. First, actually check if it's that part of the widget, then report it.
1. Start spring.exe and deactivate Argh's widget.
2. Quit spring
3. Again start spring.exe
4. When ingame, F11->Enable arghs widget
5. Short Freeze.
It does not happen if you disable and reenable it again ingame. And its clearly the function widget:Initialize(). When wiping that function it does not happen anymore.
Maybe when iterating UnitDefs for the very first time it gets (expensively) generated. And when using it later again its fetched fast from some cache?
Re: New widget: Enemy Spotter
It makes those at game start.
Try leaving that in but removing the opengl calls.
Try leaving that in but removing the opengl calls.
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: New widget: Enemy Spotter
Ok, I did. It still happens. This is how Initialize looks:
Code: Select all
function widget:Initialize()
for uDefID, uDef in pairs(UnitDefs) do
radiusDefs[uDefID] = uDef.radius * 1.25
end
end
Re: New widget: Enemy Spotter
*sigh*
What this means: caching the radius value in the radiusDefs table on Initialize causes all not-yet loaded models to be parsed first. Therefore the reported 300ms delay is normal, and a claim of 0.0002s startup time *highly* dubious for any widget performing the same computation unless said computation is 1) also done by another widget that comes earlier in the alphabetical ordering or 2) preceded by a /give all command.
Code: Select all
for uDefID, uDef in pairs(UnitDefs) do
radiusDefs[uDefID] = uDef.radius * 1.25
end
Code: Select all
#define TYPE_MODEL_FUNC(name, param) \
static int name(lua_State* L, const void* data) \
{ \
const UnitDef* ud = ((const UnitDef*) data); \
const S3DModel* model = ud->LoadModel(); \
lua_pushnumber(L, model->param); \
return 1; \
}
TYPE_MODEL_FUNC(ModelRadius, radius);
ADD_FUNCTION("radius", ud, ModelRadius);
Re: New widget: Enemy Spotter
Right, I'd forgotten that one out of ten files is delay-loaded for some strange reason.
I actually like delay-loading, but what is and what isn't is a mess.
I actually like delay-loading, but what is and what isn't is a mess.
Re: New widget: Enemy Spotter
When I tested it yes, other widgets had done the exact same computation, maybe half a dozen of them even, it's quite common.Kloot wrote:Therefore the reported 300ms delay is normal, and a claim of 0.0002s startup time *highly* dubious for any widget performing the same computation unless said computation is 1) also done by another widget that comes earlier in the alphabetical ordering or 2) preceded by a /give all command.
Re: New widget: Enemy Spotter
Yeah, testing that in isolation gives the wrong impression about what it does and how big of an issue it really is. Doing stuff like unitDef / weaponDef / featureDef table iterations... meh, I probably do that 3-4 dozen times as P.U.R.E. starts up, tbh, to speed various things up. I guess that's why I didn't observe the lag.
Re: New widget: Enemy Spotter
Could somebody build in support for different enemy colors for different ally's?
As a spec 4v4v4v4 games arent followable due to this.
As a spec 4v4v4v4 games arent followable due to this.
- very_bad_soldier
- Posts: 1397
- Joined: 20 Feb 2007, 01:10
Re: New widget: Enemy Spotter
Use Team Platter for that? For me its exactly the point of this widget to not try to use different colors.
Re: New widget: Enemy Spotter
this is a 4 year old thread, much of what was discussed may not be a limitation any more. It is probably better to to do a new discussion.
Re: New widget: Enemy Spotter
You are probably right Smoth, but we re here now... And this way all related info about this widget is bundled in one thread.
Why are people referring to teamplatter while teamplatter isnt 'allyplatter'. I am using enemyspotter for a reason, teamplatter doesnt give me clarity who is my teammate or enemy. Also, I prefer the more subtle gfx of enemyspotter. Teamplatter isnt relevant to me since the units are already teamcolored.
Allyspotter/platter is what it needs to be for me.
Why are people referring to teamplatter while teamplatter isnt 'allyplatter'. I am using enemyspotter for a reason, teamplatter doesnt give me clarity who is my teammate or enemy. Also, I prefer the more subtle gfx of enemyspotter. Teamplatter isnt relevant to me since the units are already teamcolored.
Allyspotter/platter is what it needs to be for me.
Re: New widget: Enemy Spotter
What Sring function gives back the ally id number given the teamID
is it this?
Spring.GetReadAllyTeam(teamID) ?
is it this?
Spring.GetReadAllyTeam(teamID) ?