Solved clearL script help

Question that is answered or resolved.

PS_VITA

Active member
Hey guys,
can this script be optimized further?  :
Code:
@cmd ClearL

Code:
void clearL()
{// Clears all local variables
     clearlocalvar();
}

if this script is used to often - it slows down the game - the strange thing is that
the engine will accumulate the slow down over time  do to this script.

Is hard to explain , but I can elaborate further if you guys need me to.

 
Solution
YES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IT took 6 months - but I finally found out the dang problem

The problem was found inside this .c text file
Code:
custom_chase.c

The code that had to be altered was  this...

Code:
  setidle(self, openborconstant("ANI_IDLE"), 1, 1);

To this .... 
Code:
setidle(self, openborconstant("ANI_IDLE"));

And that fixed the issue. No more lag in long missions or if the player takes to long to choose a character,
or if you create a survival mode with like 99 lives or whatever.

Here's the  full custom_chase.c file and code...

Code:
void main()
{
    void self = getlocalvar("self");
    void target = findtarget(self); // locked opponent
    float x = getentityproperty(self, "x");
    float z =...
First thing - that's not a native script function. It's something someone wrote. From the naming convention I'd guess it was Bloodbane. You'd need to post the function for us to know exactly what it does.

Second issue question is, assuming the script does what it sounds like, why? The engine clears localvars for you automatically. Unless you are needing a total reset of a script while it's running, it's a waste of time and resources to do it manually.

DC
 
Damon Caskey said:
First thing - that's not a native script function. It's something someone wrote. From the naming convention I'd guess it was Bloodbane. You'd need to post the function for us to know exactly what it does.

Second issue question is, assuming the script does what it sounds like, why? The engine clears localvars for you automatically. Unless you are needing a total reset of a script while it's running, it's a waste of time and resources to do it manually.

DC


Here's an example

Code:
anim idle
	loop	0
	delay	10
	offset	82 177
	bbox	63 68 39 112
        @cmd    clearL
	frame	data/chars/gang1/roper/idle0.png
	frame	data/chars/gang1/roper/idle1.png
	frame	data/chars/gang1/roper/idle2.png
	frame	data/chars/gang1/roper/idle1.png

Bloodbane
Has previously explained to me that he used to use this for his crime buster game. However he would not suggest using on the idle animation, but instead using it at the end of slamthrows.

My issue is that when enemies grab the players and if I disable the clearL in the idle animation,  I get alot of enemies merging with the player and each other.

But I will do more research and try to understand how this works and find a way to avoid using clearL or use it correctly.


 
My issue is that when enemies grab the players and if I disable the clearL in the idle animation,  I get alot of enemies merging with the player and each other.

Well, why not declare clearL at end of enemy's grab/slam/throw animation?
 
Bloodbane said:
My issue is that when enemies grab the players and if I disable the clearL in the idle animation,  I get alot of enemies merging with the player and each other.

Well, why not declare clearL at end of enemy's grab/slam/throw animation?

I did and it didn't work as intended.  It's probably because the enemies have other scripts such as hurt3  and bind scripts that I need to look into.

But besides my actual problem,  I honestly wanted to know why is it that clearL is dropping frames when enemies idle and why wont the script clearL free some memory after the enemies have been killed. I Also wonder why is that the fps restore back to 60 fps, but than revert back to 20fps whenever I get killed or get knocked out until I get up,  which is precisely when enemies go into an idle animation.

(I will do some more testing but if you need me to make a video of how clearL breaks the game, let me know)

Thanks for the suggestions and help as always.
 
Damon Caskey
Bloodbane

I tested this further and any time the engine runs
clearlocalvar();

It consumes memory  the reason why it stood out so much in double dragon reloaded is because #1 I'm running it on the vita and two the clearlocalvar(); was used repeatedly in a loop sequence in the anim idle of the enemies.

Now, even if we were to use clearlocalvar(); sporadically or at the end of slam throws eventually the game will slow down.

An example is when I was creating an endless survival mode, eventually the game started slowing
Down.


The strange thing about this, is that when you use

clearlocalvar();  and say it slows down the game to 20fps, than say you move your character or don't perform a move that requires clearlocalvar(); the game will restore itself back to 60fps, however the moment you call clearlocalvar(); the game will continue were it left of at 20fps and continue to decrease the fps to even lower frames.

I found a couple of solutions that could remedy the problem,  but they all involve getting rid of ever using
Local variables and clearlocalvar();
 
YES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! IT took 6 months - but I finally found out the dang problem

The problem was found inside this .c text file
Code:
custom_chase.c

The code that had to be altered was  this...

Code:
  setidle(self, openborconstant("ANI_IDLE"), 1, 1);

To this .... 
Code:
setidle(self, openborconstant("ANI_IDLE"));

And that fixed the issue. No more lag in long missions or if the player takes to long to choose a character,
or if you create a survival mode with like 99 lives or whatever.

Here's the  full custom_chase.c file and code...

Code:
void main()
{
    void self = getlocalvar("self");
    void target = findtarget(self); // locked opponent
    float x = getentityproperty(self, "x");
    float z = getentityproperty(self, "z");
    int dir = getentityproperty(self,"direction");
    void vAniID2 = getentityproperty(self,"animationID");

    if( target != NULL() && getentityproperty(target,"exists") ){
      int tdir = getentityproperty(target,"direction");
      float tx = getentityproperty(target, "x");
      float tz = getentityproperty(target, "z");
      int vEnemy = openborvariant("count_enemies");
      float Disx = tx - x;
      float Disz = tz - z;

      if(Disx < 0){
        Disx = -Disx;
      }

      if ( vEnemy > 1 ) {
         if ( dir == 0 && dir != tdir && Disz <= 0 && Disz <= 34 && Disx < 125 && (getentityproperty(self,"aiflag","attacking") == 0 || getentityproperty(self,"aiflag","walking") == 1) && (getentityproperty(target,"aiflag","attacking") == 1 || getentityproperty(target,"aiflag","inpain") == 1) ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
	     changeentityproperty(self, "destz", tz+46);
	     changeentityproperty(self, "destx", x-70);
         } else if ( dir == 0 && dir != tdir && Disz > 34 && Disx < 125 && (getentityproperty(self,"aiflag","attacking") == 0 || getentityproperty(self,"aiflag","walking") == 1) && (getentityproperty(target,"aiflag","attacking") == 1 || getentityproperty(target,"aiflag","inpain") == 1) ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
	     changeentityproperty(self, "destx", tx);
	     changeentityproperty(self, "destz", tz+46);
	     changeentityproperty(self, "destx", x-70);
         } else if ( dir == 1 && dir != tdir && Disz <= 0 && Disz <= 34 && Disx < 125 && (getentityproperty(self,"aiflag","attacking") == 0 || getentityproperty(self,"aiflag","walking") == 1) && (getentityproperty(target,"aiflag","attacking") == 1 || getentityproperty(target,"aiflag","inpain") == 1) ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
	     changeentityproperty(self, "destz", tz+46);
	     changeentityproperty(self, "destx", x+70);
         } else if ( dir == 1 && dir != tdir && Disz > 34 && Disx < 125 && (getentityproperty(self,"aiflag","attacking") == 0 || getentityproperty(self,"aiflag","walking") == 1) && (getentityproperty(target,"aiflag","attacking") == 1 || getentityproperty(target,"aiflag","inpain") == 1) ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
	     changeentityproperty(self, "destx", tx);
	     changeentityproperty(self, "destz", tz+46);
	     changeentityproperty(self, "destx", x+70);
         } else if ( dir == 0 && dir != tdir && Disz <= -1 && Disz <= -34 && Disx < 125 && (getentityproperty(self,"aiflag","attacking") == 0 || getentityproperty(self,"aiflag","walking") == 1) && (getentityproperty(target,"aiflag","attacking") == 1 || getentityproperty(target,"aiflag","inpain") == 1) ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
	     changeentityproperty(self, "destz", tz-46);
	     changeentityproperty(self, "destx", x-70);
         } else if ( dir == 0 && dir != tdir && Disz > -34 && Disx < 125 && (getentityproperty(self,"aiflag","attacking") == 0 || getentityproperty(self,"aiflag","walking") == 1) ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
	     changeentityproperty(self, "destx", tx);
	     changeentityproperty(self, "destz", tz-46);
	     changeentityproperty(self, "destx", x-70);
         } else if ( dir == 1 && dir != tdir && Disz <= -1 && Disz <= -34 && Disx < 125 && (getentityproperty(self,"aiflag","attacking") == 0 || getentityproperty(self,"aiflag","walking") == 1) && (getentityproperty(target,"aiflag","attacking") == 1 || getentityproperty(target,"aiflag","inpain") == 1) ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
	     changeentityproperty(self, "destz", tz-46);
	     changeentityproperty(self, "destx", x+70);
         } else if ( dir == 1 && dir != tdir && Disz > -34 && Disx < 125 && (getentityproperty(self,"aiflag","attacking") == 0 || getentityproperty(self,"aiflag","walking") == 1) && (getentityproperty(target,"aiflag","attacking") == 1 || getentityproperty(target,"aiflag","inpain") == 1) ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
	     changeentityproperty(self, "destx", tx);
	     changeentityproperty(self, "destz", tz-46);
	     changeentityproperty(self, "destx", x+70);
         } else if ( dir == 0 && dir == tdir && Disx < 70 ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
             changeentityproperty(self, "destx", x+70);
	     changeentityproperty(self, "destz", tz);
         } else if ( dir == 0 && dir == tdir && Disx > 70 ) {
	     changeentityproperty(self, "aimove", openborconstant("AIMOVE1_CHASE"));
         } else if ( dir == 1 && dir == tdir && Disx < 70 ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_NORMAL"));
             changeentityproperty(self, "destx", x-70);
	     changeentityproperty(self, "destz", tz);
         } else if ( dir == 1 && dir == tdir && Disx > 70 ) {
	     changeentityproperty(self, "aimove", openborconstant("AIMOVE1_CHASE"));
         } else if ( dir == 0 && dir != tdir && Disx > 1 && (getentityproperty(self,"aiflag","attacking") == 0 || getentityproperty(self,"aiflag","walking") == 1) ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_CHASE")) + changeentityproperty(self, "destz", z) + changeentityproperty(self, "destx", tx-70);
         } else if ( dir == 1 && dir != tdir && Disx > 1 && (getentityproperty(self,"aiflag","attacking") == 0 || getentityproperty(self,"aiflag","walking") == 1) ) {
             changeentityproperty(self, "aimove", openborconstant("AIMOVE1_CHASE")) + changeentityproperty(self, "destz", z) + changeentityproperty(self, "destx", tx+70);
         }
      } else if ( vEnemy == 1 ) {
         changeentityproperty(self, "aimove", openborconstant("AIMOVE1_CHASE"));
      }
    }else if(target == NULL() && !getentityproperty(target,"exists") && getentityproperty(target,"dead") && vAniID2 == openborconstant("ANI_WALK") || vAniID2 == openborconstant("ANI_UP") || vAniID2 == openborconstant("ANI_IDLE")){
      setidle(self, openborconstant("ANI_IDLE"));
   }
}

Bloodbane  and Damon Caskey

Thank you guys - it turns out that the reset option was what was stressing the engine to the max do to the clearL being set on the idle animation.

setidle(entity, int anim, int resetable, int stalltime)
This method change the entity back to idle status.
anim - same as above. Optional. You probably will use idle animation, but that is up to you.
resetable - same as above. Optional.stalltime - how long will current idle status last, in game tick. 200 will be about 1 second. Optional.
Notice, idle status means the entity can change to other status automatically by the engine. So walk/run/idle can all
be treated as idle.
Also notice, you can set velocity for the entity later to simulate walk/run.

resetable - Optional. If current animation number is same as this one, and resetable is 1, current animation will be
reset or else, the anim will be ignored.
Notice: If you provide anim parameter, and this function is called in an animation script, you probably need to add a
return behind it because the animation might be changed and the animation script will be re-called.

I tried to make the animation only loop on the 3rd frame to avoid it reading the clearL on frame 0
but I could not get it to work, I tried , 0, 1,2 and 3 and nothing worked until I just got rid of the parameter.

I guess if I wanted to have the enemies just stand there like in double dragon ( when I die) I need to probably duplicate the idle anim into a follow that does not have the clearL script or whatever - but yeah at least I didn't have to  temper to much with the code it was just a few lines to solve the slow down issue that had been bothering for months.
 
Solution
Back
Top Bottom