LUA Efficiency

LUA Efficiency

Discuss game development here, from a distinct game project to an accessible third-party mutator, down to the interaction and design of individual units if you like.

Moderator: Moderators

Post Reply
deveyus
Posts: 6
Joined: 25 Dec 2006, 06:27

LUA Efficiency

Post by deveyus »

I was looking into having structures that only function or run at full capacity when within range of specific other structures. What I'm wondering is if it's more efficient to run a check for structures that the central structure empowers as part of that unit's code or if the empowered structures should check to see if they are within range of the central structure and then set their own values.

Perhaps some sort of hybrid solution is the best answer, or maybe there are quirks in Spring I'm not yet aware of, I do know that someone mentioned that checking the range from one thing to another was an expensive thing to do, but it seems like it would be okay upon either attempting to build something, or build completion. (Not sure if I wanna let people 'pre-build' outside of the central structures yet, among other things.)

Thanks for any information you can provide.
User avatar
MidKnight
Posts: 2652
Joined: 10 Sep 2008, 03:11

Re: LUA Efficiency

Post by MidKnight »

It's certainly doable. Check out KDR's Fibre. It's a game with features similar to what you outlined.

PS: It's Lua, not lua or LUA. :wink:
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: LUA Efficiency

Post by Tobi »

deveyus wrote:I was looking into having structures that only function or run at full capacity when within range of specific other structures. What I'm wondering is if it's more efficient to run a check for structures that the central structure empowers as part of that unit's code or if the empowered structures should check to see if they are within range of the central structure and then set their own values.
If there's only a few central structures then it's certainly faster to just store the positions of the central structures in some array, and for all empowered structures, calculate distances to these positions to see if they are in range of (one of the) central structures.

Recalculate everything whenever central structure is created / destroyed / changes team. (Re)calculate for empowered structure when it is created / changes team.

This definitely applies if the range is pretty big and there are usually lots of irrelevant units within this range.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: LUA Efficiency

Post by FLOZi »

I'd suggest looking at the code for supply giving structures in S44, only the code (game_ammo.lua) is really just dreadful and shouldn't be viewed by anyone other than me the next time it breaks.
deveyus
Posts: 6
Joined: 25 Dec 2006, 06:27

Re: LUA Efficiency

Post by deveyus »

Excellent, I'll do that with storing the information in an array and then pulling it for the structures that need to know. (which is a -large- percent of the structures.)

From what I understand, just about anything we want to do is possible (though, perhaps impractical) through Lua, correct?

While I've got your ear, is there a gameplay reason why the commander in many mods (not all, as I'm well aware) is a 'kbot' type? Is it to be able to play on rough maps (i.e. a starting vehicle wouldn't be able to do so because of the slopes) or is it merely an old aesthetic left over from OTA?
User avatar
MidKnight
Posts: 2652
Joined: 10 Sep 2008, 03:11

Re: LUA Efficiency

Post by MidKnight »

you can change the slope tolerance of various units. If you wanted, you could have an all-terrain vehicle! It's merely a TA holdover. Some games, like GRTS, S44, and KP have buildings as starting units.
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6242
Joined: 29 Apr 2005, 01:14

Re: LUA Efficiency

Post by FLOZi »

It's a holdover from TA when you couldn't select your start position, and the set positions may be on hilly terrain or under water, so the start unit/commander (btw, no need to start with just 1 unit in Spring - S44 spawns multiple units in addition to the Headquarters building which is what the engine sees as the commander, at game start) traditionally has very high slope tolerance and amphibious capability of some kind.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: LUA Efficiency

Post by jK »

there is a lua callin to block start points
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: LUA Efficiency

Post by AF »

structures within range of other structures.

You shouldnt need to recheck since structures do not move!

Run an initial test on startup, and then whenever the influencing structure is built, on the unitfinished check, test if it is within range to make a difference, and if so, recalc. Same on UnitDestroyed.

No need for second by second updates unless you're a mobile unit..
Post Reply

Return to “Game Development”