Ideas to optimize BOS script?

Ideas to optimize BOS script?

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

Ideas to optimize BOS script?

Post by TradeMark »

Some people claims that my nanotowers lags when used hundreds of them. Im not sure what to believe...

I have changed the script so it doesnt draw nanospray anymore, just one or two particles to make nanos only glow while being used.

Could it make it less laggy if i remove the part which moves at the direction of building? thats pretty useless part anyways, how to remove it properly?

So if anyone of you could point out which parts are useless in this code? just to make it less CPU using, or even less bandwidth using?

Code: Select all

#define TA			// This is a TA script

#include "sfxtype.h"
#include "exptype.h"
#define SIG_Build 8

piece  base, body, aim, emitnano;

static-var  Static_Var_1, Static_Var_2, statechg_DesiredState, statechg_StateChanging;


Activatescr()
{
	sleep 1;
}

Deactivatescr()
{
	sleep 1;
}

SmokeUnit(healthpercent, sleeptime, smoketype)
{
	while( get BUILD_PERCENT_LEFT )
	{
		sleep 400;
	}
	while( TRUE )
	{
		healthpercent = get HEALTH;
		if( healthpercent < 66 )
		{
			smoketype = 256 | 2;
			if( Rand( 1, 66 ) < healthpercent )
			{
				smoketype = 256 | 1;
			}
			emit-sfx smoketype from aim;
		}
		sleeptime = healthpercent * 50;
		if( sleeptime < 200 )
		{
			sleeptime = 200;
		}
		sleep sleeptime;
	}
}

Go()
{
	call-script Activatescr();
	turn aim to y-axis Static_Var_1 speed <160.000000>;
	wait-for-turn aim around y-axis;
	set INBUILDSTANCE to 1;
}

Stop()
{
	set INBUILDSTANCE to 0;
	call-script Deactivatescr();
}

InitState()
{
	statechg_DesiredState = TRUE;
	statechg_StateChanging = FALSE;
}

RequestState(requestedstate, currentstate)
{
	if( statechg_StateChanging )
	{
		statechg_DesiredState = requestedstate;
		return (0);
	}
	statechg_StateChanging = TRUE;
	currentstate = statechg_DesiredState;
	statechg_DesiredState = requestedstate;
	while( statechg_DesiredState != currentstate )
	{
		if( statechg_DesiredState == 0 )
		{
			call-script Go();
			currentstate = 0;
		}
		if( statechg_DesiredState == 1 )
		{
			call-script Stop();
			currentstate = 1;
		}
	}
	statechg_StateChanging = FALSE;
}

Create()
{
	set ARMORED to 1;
	call-script InitState();
	start-script SmokeUnit();
	Static_Var_1 = 0;
	Static_Var_2 = 5000;
	sleep 5000;
	set ARMORED to 0;
}

RestoreAfterDelay()
{
	sleep Static_Var_2;
	turn aim to y-axis <0.000000> speed <100.000000>;
	wait-for-turn aim around y-axis;
}

Activate()
{
	start-script RequestState(0);
}

Deactivate()
{
	start-script RequestState(1);
}

QueryWeapon1(piecenum)
{
	piecenum=emitnano;
}

AimFromWeapon1(piecenum)
{
	piecenum=aim;
}

AimWeapon1(h,p)
{
	return 0;
}


StartBuilding(Func_Var_1)
{
	Static_Var_1 = Func_Var_1;
	start-script RequestState(0);
	
	signal SIG_Build;
	set-signal-mask SIG_Build;
	set INBUILDSTANCE to 1;
		
	while (1) {
		emit-sfx 2048 from emitnano;
		sleep 60;
	}
}

StopBuilding()
{
	start-script RequestState(1);
	
	signal SIG_Build;
	set-signal-mask SIG_Build;
	set INBUILDSTANCE to 0;

}

QueryNanoPiece(piecenum)
{
	piecenum = emitnano;
}

TargetHeading(Func_Var_1)
{
	Static_Var_1 = 0 - Func_Var_1;
}

SweetSpot(piecenum)
{
	piecenum = aim;
}

Killed(severity, corpsetype)
{
	if( severity <= 25 )
	{
		corpsetype = 1;
		explode base type BITMAPONLY | BITMAP1;
		explode aim type BITMAPONLY | BITMAP3;
		return (0);
	}
	if( severity <= 50 )
	{
		corpsetype = 2;
		explode base type FALL | BITMAP1;
		explode aim type FALL | BITMAP3;
		return (0);
	}
	if( severity <= 99 )
	{
		corpsetype = 3;
		explode base type FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP1;
		explode aim type FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP3;
		return (0);
	}
	corpsetype = 3;
	explode base type FALL | SMOKE | FIRE | EXPLODE_ON_HIT | BITMAP1;
	explode aim type SHATTER | EXPLODE_ON_HIT | BITMAP3;
}
User avatar
Hoi
Posts: 2917
Joined: 13 May 2008, 16:51

Re: Ideas to optimize BOS script?

Post by Hoi »

Some people claims that my nanotowers lags when used hundreds of them. Im not sure what to believe...
BS, get a few hundered nano's = lag, get a few hundered ak's = lag, it just happends, if you don't want that, stop playing speedmetal :mrgreen:
[Krogoth86]
Posts: 1176
Joined: 23 Aug 2007, 19:46

Re: Ideas to optimize BOS script?

Post by [Krogoth86] »

The primary problem with the Nanotowers is the particle amount they spawn. Nano particles don't mind the max particle number you gave in your settings (at least it was this way in former versions) so together with their huge range they spawned hundreds of particles and each has to be animated by the CPU giving you immense slowdowns...

Another thing when talking about "using hundreds" might be their sightrange. I don't know how severe this is for non-moving things but planes with big sightranges gave you quite a slowdown too so maybe reduce that value to something small like below 200...
User avatar
Noruas
XTA Developer
Posts: 1269
Joined: 24 Feb 2005, 02:58

Re: Ideas to optimize BOS script?

Post by Noruas »

/maxparticles 5
User avatar
lurker
Posts: 3842
Joined: 08 Jan 2007, 06:13

Re: Ideas to optimize BOS script?

Post by lurker »

[Krogoth86] wrote:how severe this is for non-moving things
Tiny load when built, small load when the terrain in LOS is deformed, nothing else.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Re: Ideas to optimize BOS script?

Post by Tobi »

[Krogoth86] wrote:Nano particles don't mind the max particle number you gave in your settings (at least it was this way in former versions
They do respect this setting in current version.
User avatar
Tribulexrenamed
Posts: 775
Joined: 22 Apr 2008, 19:06

Re: Ideas to optimize BOS script?

Post by Tribulexrenamed »

Delete all of it.

Just make it happen to magically cause things to build faster. Its the future anything is possible.
User avatar
Otherside
Posts: 2296
Joined: 21 Feb 2006, 14:09

Re: Ideas to optimize BOS script?

Post by Otherside »

LUPS nano spray solves
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Ideas to optimize BOS script?

Post by Pxtl »

Alternately, you could make a Lua script where a block of 4 nanos automagically amalgamates into a big super-nano, and cut your unit-count (and likewise for blocks of 16).

edit: the more I think about this, the more I like the idea. Oooh, that could be fun for Solars too.
User avatar
TradeMark
Posts: 4867
Joined: 17 Feb 2006, 15:58

Re: Ideas to optimize BOS script?

Post by TradeMark »

Pxtl wrote:Oooh, that could be fun for Solars too.
Nice idea! But there are problems when you build in different altitude of ground, etc...
User avatar
Pxtl
Posts: 6112
Joined: 23 Oct 2004, 01:43

Re: Ideas to optimize BOS script?

Post by Pxtl »

I don't think so, actually. Slope = rise/run. So if you can build 2 units right next to each other (like, touching each other) then the maximum slope of the ground those two units cover is (rise1 + rise2)/(run1 + run2) which will always be less than or equal the maximum value of rise1/run1 and rise2/run2.

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

Re: Ideas to optimize BOS script?

Post by Argh »

Go read the Sheep script from NanoBlobs, and learn how to write an efficient script for a builder.

All you need, for an immobile builder unit, is a StartBuilding(), StopBuilding(), some function that loops and watches the state of a static-var set during those two functions with a timer to keep it from running more than once every few frames at most, a Create() and a Killed().

Past that, it's all FX stuff- SmokeUnit (which, btw, you should learn to write a header for, or just take the one from NanoBlobs, which is very efficient, or the Lups one from CA, which I'm sure is probably even faster) and ancillary building effects, like the "beams" that Overmind units emit in P.U.R.E.

The AutoFac and Sheep units use really utterly simple BOS scripts, take a look at them and if you have further questions, ask.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Ideas to optimize BOS script?

Post by KDR_11k »

I sure hope your looping function doesn't loop when the unit isn't building...
User avatar
Argh
Posts: 10920
Joined: 21 Feb 2005, 03:38

Re: Ideas to optimize BOS script?

Post by Argh »

Er, yeah, I forgot that the old version still did that. Here's a more modern one, doesn't loop anywhere unless it's supposed to, including the FX script. Saves a lot of cycles.

Code: Select all

BuilderFX()
{
	while(IsBuildingNow)
	{
		emit-sfx BUILDER_FX from sprayer;
		sleep 900 + RandomNumber2;
	}
	return (0);
}

BuildingStuff()
{
	turn turret to y-axis BuildHeading speed <400>;
	wait-for-turn turret around y-axis;
	IsBuildingNow = TRUE;
	set INBUILDSTANCE to 1;
	start-script BuilderFX();
}

StopBuild()
{
	IsBuildingNow = FALSE;
	set INBUILDSTANCE to 0;
	turn turret to y-axis <0> speed <5>;
	return (0);
}

StartBuilding(heading,pitch)
{	
	BuildHeading = heading;
	call-script BuildingStuff();
}

StopBuilding()
{
	call-script StopBuild();
}

QueryNanoPiece(piecenum)
{
	piecenum = sprayer;
}
Even the old looping variety was faster than what he was doing, though. There are some things where you cannot avoid having a loop without some issues, but this isn't one of them.
Post Reply

Return to “Game Development”