New widget: Enemy Spotter - Page 10

New widget: Enemy Spotter

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: New widget: Enemy Spotter

Post by Argh »

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.
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Re: New widget: Enemy Spotter

Post by TradeMark »

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:
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: New widget: Enemy Spotter

Post by Argh »

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.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: New widget: Enemy Spotter

Post by Niobium »

300ms to initialize the table sounded ridiculously high. So I went and tested it. Building the table takes ~0.0002 seconds.
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: New widget: Enemy Spotter

Post by very_bad_soldier »

Niobium wrote:300ms to initialize the table sounded ridiculously high. So I went and tested it. Building the table takes ~0.0002 seconds.
Its because your version is 300% faster. :mrgreen:

If you are not able to reproduce, just ask...
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: New widget: Enemy Spotter

Post by lurker »

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.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: New widget: Enemy Spotter

Post by Argh »

Localizing an upvalue is going to have a small impact when you get and set it about 3-5 times.
But how long until it's actually slower than using those two additional instructions?
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: New widget: Enemy Spotter

Post by lurker »

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.
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: New widget: Enemy Spotter

Post by very_bad_soldier »

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.
This is how it happens for me:
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?
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: New widget: Enemy Spotter

Post by lurker »

It makes those at game start.

Try leaving that in but removing the opengl calls.
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: New widget: Enemy Spotter

Post by very_bad_soldier »

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
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: New widget: Enemy Spotter

Post by Kloot »

*sigh*

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);
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.
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: New widget: Enemy Spotter

Post by lurker »

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.
User avatar
Niobium
Posts: 456
Joined: 07 Dec 2008, 02:35

Re: New widget: Enemy Spotter

Post by Niobium »

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.
When I tested it yes, other widgets had done the exact same computation, maybe half a dozen of them even, it's quite common.
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: New widget: Enemy Spotter

Post by Argh »

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.
User avatar
Floris
Posts: 611
Joined: 04 Jan 2011, 20:00

Re: New widget: Enemy Spotter

Post by Floris »

Could somebody build in support for different enemy colors for different ally's?


As a spec 4v4v4v4 games arent followable due to this.
User avatar
very_bad_soldier
Posts: 1397
Joined: 20 Feb 2007, 01:10

Re: New widget: Enemy Spotter

Post by very_bad_soldier »

Use Team Platter for that? For me its exactly the point of this widget to not try to use different colors.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: New widget: Enemy Spotter

Post by smoth »

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.
User avatar
Floris
Posts: 611
Joined: 04 Jan 2011, 20:00

Re: New widget: Enemy Spotter

Post by Floris »

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.
User avatar
Floris
Posts: 611
Joined: 04 Jan 2011, 20:00

Re: New widget: Enemy Spotter

Post by Floris »

What Sring function gives back the ally id number given the teamID

is it this?

Spring.GetReadAllyTeam(teamID) ?
Post Reply

Return to “Lua Scripts”