Author Topic: eXtreme 2.7: Arcade Hud  (Read 138 times)

Offline {NADF}Geronimo

  • Rank: Private
  • *
  • Posts: 65
eXtreme 2.7: Arcade Hud
« on: July 16, 2011, 12:50:09 pm »
Hi Pat!

Can we optimize the "arcade" file a bit?



File: _ex_arcade.gsc
Code: [Select]

main()
{
level endon("ex_gameover");
self endon("disconnect");

//********************************************************************************
//{NADF} Arcade Fix
//********************************************************************************
//Created by: {NADF}Geronimo
//Date: 19.06.2011
//Version: 1.0
//Website: http://nadfserver.org
//Clan: {NADF} - North Atlantic Defence Force
//Comment: Simpler solution, to make sure, less player-threads are running!
//********************************************************************************
self.ex_arcade_test = 1;
//********************************************************************************


if(!isDefined(self.ex_arcade))
{
self.ex_arcade = newClientHudElem(self);
self.ex_arcade.archived = true;
self.ex_arcade.horzAlign = "fullscreen";
self.ex_arcade.vertAlign = "fullscreen";
self.ex_arcade.alignX = "center";
self.ex_arcade.alignY = "middle";
self.ex_arcade.x = 340;
self.ex_arcade.y = 220;
self.ex_arcade.fontscale = 2.0;
self.ex_arcade.alpha = 0;
}

if(level.ex_arcade_shaders)
{
if(!isDefined(self.ex_arcade_shader))
{
self.ex_arcade_shader = newClientHudElem(self);
self.ex_arcade_shader.archived = true;
self.ex_arcade_shader.horzAlign = "fullscreen";
self.ex_arcade_shader.vertAlign = "fullscreen";
self.ex_arcade_shader.alignX = "center";
self.ex_arcade_shader.alignY = "middle";
self.ex_arcade_shader.x = 320;
self.ex_arcade_shader.y = 105;
self.ex_arcade_shader.alpha = 0;
}
}

self.ex_arcade_oldscore = self.score;
while(1)
{
self waittill("update_playerscore_hud");
self thread checkScoreUpdate();
}
}

checkScoreUpdate()
{
scorediff = self.score - self.ex_arcade_oldscore;
if(scorediff != 0) self thread showScoreUpdate(scorediff);
}

showScoreUpdate(scorediff)
{
self notify("kill_scoreupdate");
waittillframeend;
self endon("kill_scoreupdate");
self endon("disconnect");

// wait a brief moment to let quick consecutive kills come through
wait( [[level.ex_fpstime]](0.1) );

if(isDefined(self.ex_arcade))
{
self.ex_arcade.alpha = 0;

if(scorediff <0> 0)
{
self.ex_arcade.label = &"MP_PLUS";
self.ex_arcade.color = (level.ex_arcade_red, level.ex_arcade_green, level.ex_arcade_blue);
}

scoreabs = abs(scorediff);
self.ex_arcade setValue(scoreabs);
self.ex_arcade.alpha = 1;
wait( [[level.ex_fpstime]](0.01) );
self.ex_arcade fadeOverTime(1);
self.ex_arcade.alpha = 0;
}

self.ex_arcade_oldscore = self.score;
}

showArcadeShader(shader, time)
{
self notify("kill_shaderupdate");
waittillframeend;
self endon("kill_shaderupdate");
self endon("disconnect");

// wait a brief moment to let quick consecutive kills come through
wait( [[level.ex_fpstime]](0.5) );

if(isDefined(self.ex_arcade_shader))
{
if(!isDefined(time)) time = 1;
self.ex_arcade_shader.alpha = 0;
self.ex_arcade_shader setShader(shader, 160, 160);
self.ex_arcade_shader.alpha = 1;
if(time > 1) wait( [[level.ex_fpstime]](time - 1) );
else wait( [[level.ex_fpstime]](0.01) );
self.ex_arcade_shader fadeOverTime(1);
self.ex_arcade_shader.alpha = 0;
}
}

abs(var)
{
if(var < 0) var = var * (-1);
return var;
}

And change file: "_main":

Code: [Select]
// arcade style HUD element
if(level.ex_arcade)
{
//********************************************************************************
//{NADF} Arcade Fix
//********************************************************************************
//Created by: {NADF}Geronimo
//Date: 19.06.2011
//Version: 1.0
//Website: http://nadfserver.org
//Clan: {NADF} - North Atlantic Defence Force
//Comment: Simpler solution, to make sure, less player-threads are running!
//********************************************************************************
if (!isDefined(self.ex_arcade_test))self thread extreme\_ex_arcade::main();
//********************************************************************************
}

In that way the player-thread:
Code: [Select]
arcadeActive()
{
level endon("ex_gameover");
self endon("disconnect");

while(1)
{
self waittill("arcade_test");
self.ex_arcade_test = 1;
}
}
Is not longer needed. Also the player-thread "arcade main" is not always created and died again (as it must run only 1 time).

Your thoughts please  :)

Regards,
Geronimo