Page 1 of 1

Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 7:51 pm
by Hblade
I can't seem to bypass this lag! I've tried everything, but ever since I added a new section, the game has dropped in frame rate heavilly. I tried adding activation regions, which did nothing but cause more glitches. the frame rate did not increase, it still spikes randomly between 60 and 30 FPS... Someone please help! I'm excited about this game, but of course there has to be some bull crap obsticle in the way of making it.. as usual.

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 7:59 pm
by skydereign
If activation regions didn't work, it's probably something to do with a bit of code you wrote. Since activation regions prevent anything not in the current region from being created/run, that means if the lag exists in the previous level, you must have something in that level causing the lag. Given what you have though, we can't do much in the way of help.

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 8:09 pm
by Hblade
If I provide the ged, can you fix the code up?

Be warned.. o-o if you do, the code is A MESS xD its understandable, easilly, but its just sloppy, too much code for the functions needed.

Better yet, heres the most of the code
Code: Select all
//Player COLL
getKeys
getDir
if(MAP>0 && SHOP==0)
{
switch(dir)
{
            case 0:
            if(spd<0)
            {
                spd+=.5;
                if(spd>-.5)
                {
                    spd=0;
                }
            }
            if(spd>0)
            {
                spd-=.5;
                if(spd<.5)
                {
                    spd=0;
                }
            }
            COLL.x+=spd;
                switch(pSpin)
                {
                    case 0:
                    if(pJump)
                    {
                        switch(cDir)
                        {
                            case 0:
                            SetPlayerAnim("FallLeft");
                            break;
                            case 1:
                            SetPlayerAnim("FallRight");
                            break;
                        }
                    }
                    if (!pJump)
                    {
                        if(animindex==0)
                        {
                            SetPlayerAnim("StandLeft");
                        }
                        if(animindex==1)
                        {
                            SetPlayerAnim("StandRight");
 
                        }
                    }
                    break;
                    case 1:
                        switch(cDir)
                        {
                            case 0:
                            SetPlayerAnim("SpinLeft");
                            break;
                            case 1:
                            SetPlayerAnim("SpinRight");
                            break;
                        }
                    break;
                }
            break;
            case 1:
                cDir=1;
                if(pJump==1 && pSpin==0)
                {
                    SetPlayerAnim("FallRight");
                }
                if(pSpin==1 && pJump==1)
                {
                    SetPlayerAnim("SpinRight");
                }
                if(!pJump && !pSpin)
                {
                    if(cmr==0)
                    {
                        SetPlayerAnim("WalkRight");
                    }
                    else if(cmr==1)
                    {
                        SetPlayerAnim("StandRight");
                    }
                }
                cml=0;
                if(cmr==0){
                switch(RunKey)
            {
                case 0:
                SetMove(3+sextra, .5);
                break;
                case 1:
                SetMove(5+sextra, .5);
                break;
            }
                          }
            break;
            case -1:
            cDir=0;
                if(pJump==1 && pSpin==0)
                {
                    SetPlayerAnim("FallLeft");
                }
                if(pSpin==1 && pJump==1)
                {
                    SetPlayerAnim("SpinLeft");
                }
                if(!pJump && !pSpin)
                {
                    if(cml==0)
                    {
                        SetPlayerAnim("WalkLeft");
                    }
                    else if(cml==1)
                    {
                        SetPlayerAnim("StandLeft");
                    }
                }
                cmr=0;
                if(cml==0){
            switch(RunKey)
            {
                case 0:
                SetMove(-3-sextra, .5);
                break;
                case 1:
                SetMove(-5-sextra, .5);
                break;
            }
                          }
            break;
}
pAnimNum=animindex;
if(hp<=0)
{
    transp=.99;
    gameoverx=1;
}
if(KeyAttack)
{
    at++;
    if(at==1)
    {
        PlaySound2("data/shot.wav", 1, 1, 0.000000);
        switch(cDir)
        {
            case 0:
            CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
            break;
            case 1:
            CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
            break;
        }
    }
    if(at>=5)
    {
        at=0;
    }
}
if(!KeyAttack)
{
    at=-0;
}
}
if(pSpin) {
    soundtimer++;
    if(soundtimer>=6)
    {
 
        soundtimer=0;
    }
    PlaySound2("data/spin3.wav", .2, 1, 0.000000);
          }
if(pSpin==0)
{
    soundtimer=0;
}
if(pJump)
{
    cmr=0; cml=0;
}
if(frameflash)
{
    temp++;
    if(temp==10||temp==20||temp==30||temp==40||temp==50)
    {
        transp=.99;
    }
    if(temp==5||temp==15||temp==25||temp==35||temp==45||temp==55)
    {
        transp=0;
    }
    if(temp>=60)
    {
        frameflash=0;
        temp=0;
    }
}


xD... think you can fix that up?

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 8:14 pm
by skydereign
I can try.

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 8:15 pm
by Hblade
I edited my previous post withg the part tha thas the most and sloppiest code.


and thanks sky, I'll be so happy if you fix this

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 8:25 pm
by Hblade
Explanation:
COLL is the actor used for collision, the player is parrented to him so when coll moves, he moves (COLL.x+=yada)
spd is speed, the character gains velocity and slows down accordingly to the function "SetMove"

Variables:
sextra is speed extra
jextra is jump extra
bulletLevel is the level of your shots

Functions:
SetMove(var1, increase_ammount)
var1 is the max speed, increase_ammount is how fast he increases to that speed.

SetPlayerAnim() Sets the players animation without bugs

getKeys
char*key=GetKeyState();

getDir
dir=key[KEY_RIGHT]-key[KEY_LEFT];

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 9:05 pm
by skydereign
Well by the looks of it, none of this would cause the lag. But while going through it I did clean it up a bit. I could have condensed it more with the ternary operator, but I wasn't sure how comfortable with it you are, so I just most of those as they were. A couple of things though...

You like to not specify comparisons in if statements, which I personally don't like, but the real problem is that you aren't really uniform in doing it. You had a couple of if(var) and if(var==0). While other times you had if(var) and if(!var). Most of the cases I don't think you really meant if(var) but rather if(var==1). Sometimes it is better to be explicit, as it explains what type of values the variable has (and I didn't fix these as I still wasn't completely sure if they were just boolean valued variable). Namely since I was looking at it, I couldn't directly tell what values the variable had. Along those lines, you should use else if more often. You had in many places if statements followed by another if statement that couldn't possibly trigger if the one above it did. That's the time you want to use an else if, that way you aren't making redundant checks with if. The last thing, as always, I'd recommend using a more standard spacing scheme. Even if you personally don't find the default spacing scheme any easier to read, it does make looking through your code a whole lot easier. Uniform spacing can tell you were in the code you are.
Code: Select all
//Player COLL
getKeys
getDir


if(MAP>0 && SHOP==0)
{
    switch(dir)
    {
        case 0:
        spd = spd<0 ? min(spd+0.5, 0) : max(spd-0.5, 0);
        COLL.x+=spd;
 
        switch(pSpin)
        {
            case 0:
            if(pJump)
            {
                switch(cDir)
                {
                    case 0:
                    SetPlayerAnim("FallLeft");
                    break;
 
                    case 1:
                    SetPlayerAnim("FallRight");
                    break;
                }
            }
            else // (!pJump)
            {
                switch(animindex)
                {
                    case 0:
                    SetPlayerAnim("StandLeft");
                    break;
 
                    case 1:
                    SetPlayerAnim("StandRight");
                    break;

               }
            }
            break;
 
            case 1:
            switch(cDir)
            {
                case 0:
                SetPlayerAnim("SpinLeft");
                break;
 
                case 1:
                SetPlayerAnim("SpinRight");
                break;
            }
            break;
        }
        break;
 
        case 1:
        cDir=1;
        switch(pJump+pSpin*2)
        {
            case 0: // pJump==0 && pSpin==0
            if(cmr==0)
            {
                SetPlayerAnim("WalkRight");
            }
            else if(cmr==1)
            {
                SetPlayerAnim("StandRight");
            }
            break;
 
            case 1: // pJump==1 && pSpin==0
            SetPlayerAnim("FallRight");
            break;
 
            case 2: // pJump==0 && pSpin==1
            break;
 
            case 3: // pJump==1 && pSpin==1
            SetPlayerAnim("SpinRight");
            break;
        }
 
        cml=0;
        if(cmr==0)
        {
            switch(RunKey)
            {
                case 0:
                SetMove(3+sextra, .5);
                break;
 
                case 1:
                SetMove(5+sextra, .5);
                break;
            }
        }
        break;
 
        case -1:
        cDir=0;
        switch(pJump+pSpin*2)
        {
            case 0: // pJump==0 && pSpin==0
            if(cml==0)
            {
                SetPlayerAnim("WalkLeft");
            }
            else if(cml==1)
            {
                SetPlayerAnim("StandLeft");
            }
            break;
 
            case 1: // pJump==1 && pSpin==0
            SetPlayerAnim("FallLeft");
            break;
 
            case 2: // pJump==0 && pSpin==1
            break;
 
            case 3: // pJump==1 && pSpin==1
            SetPlayerAnim("SpinLeft");
            break;
        }
        cmr=0;
 
        if(cml==0)
        {
            switch(RunKey)
            {
                case 0:
                SetMove(-3-sextra, .5);
                break;
 
                case 1:
                SetMove(-5-sextra, .5);
                break;
            }
        }
        break;
    }
 
    pAnimNum=animindex;
    if(hp<=0)
    {
        transp=.99;
        gameoverx=1;
    }
 
    if(KeyAttack)
    {
        at++;
 
        if(at==1)
        {
            PlaySound2("data/shot.wav", 1, 1, 0.000000);
            switch(cDir)
            {
                case 0:
                CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
                break;
 
                case 1:
                CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
                break;
            }
        }
        else if(at>=5)
        {
            at=0;
        }
    }
    else if(!KeyAttack)
    {
        at=0;
    }
}


if(pSpin)
{
    soundtimer++;
    if(soundtimer>=6)
    {

        soundtimer=0;
    }
    PlaySound2("data/spin3.wav", .2, 1, 0.000000);
}
else if(pSpin==0)
{
    soundtimer=0;
}

if(pJump)
{
    cmr=0; cml=0;
}


if(frameflash)
{
    temp++;
    if(temp%10==0)
    {
        transp=.99;
    }
    else if((temp+5)%10==0)
    {
        transp=0;
    }
 
    if(temp>=60)
    {
        frameflash=0;
        temp=0;
    }
}

Lastly, seeing that code it's no wonder you don't like debugging. Your habits make your code rather hard to look through. Did you have anything else that would cause the lag? It would be easier to see the ged though.

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 9:18 pm
by Hblade
skydereign wrote:Well by the looks of it, none of this would cause the lag. But while going through it I did clean it up a bit. I could have condensed it more with the ternary operator, but I wasn't sure how comfortable with it you are, so I just most of those as they were. A couple of things though...

You like to not specify comparisons in if statements, which I personally don't like, but the real problem is that you aren't really uniform in doing it. You had a couple of if(var) and if(var==0). While other times you had if(var) and if(!var). Most of the cases I don't think you really meant if(var) but rather if(var==1). Sometimes it is better to be explicit, as it explains what type of values the variable has (and I didn't fix these as I still wasn't completely sure if they were just boolean valued variable). Namely since I was looking at it, I couldn't directly tell what values the variable had. Along those lines, you should use else if more often. You had in many places if statements followed by another if statement that couldn't possibly trigger if the one above it did. That's the time you want to use an else if, that way you aren't making redundant checks with if. The last thing, as always, I'd recommend using a more standard spacing scheme. Even if you personally don't find the default spacing scheme any easier to read, it does make looking through your code a whole lot easier. Uniform spacing can tell you were in the code you are.
Code: Select all
//Player COLL
getKeys
getDir


if(MAP>0 && SHOP==0)
{
    switch(dir)
    {
        case 0:
        spd = spd<0 ? min(spd+0.5, 0) : max(spd-0.5, 0);
        COLL.x+=spd;
 
        switch(pSpin)
        {
            case 0:
            if(pJump)
            {
                switch(cDir)
                {
                    case 0:
                    SetPlayerAnim("FallLeft");
                    break;
 
                    case 1:
                    SetPlayerAnim("FallRight");
                    break;
                }
            }
            else // (!pJump)
            {
                switch(animindex)
                {
                    case 0:
                    SetPlayerAnim("StandLeft");
                    break;
 
                    case 1:
                    SetPlayerAnim("StandRight");
                    break;

               }
            }
            break;
 
            case 1:
            switch(cDir)
            {
                case 0:
                SetPlayerAnim("SpinLeft");
                break;
 
                case 1:
                SetPlayerAnim("SpinRight");
                break;
            }
            break;
        }
        break;
 
        case 1:
        cDir=1;
        switch(pJump+pSpin*2)
        {
            case 0: // pJump==0 && pSpin==0
            if(cmr==0)
            {
                SetPlayerAnim("WalkRight");
            }
            else if(cmr==1)
            {
                SetPlayerAnim("StandRight");
            }
            break;
 
            case 1: // pJump==1 && pSpin==0
            SetPlayerAnim("FallRight");
            break;
 
            case 2: // pJump==0 && pSpin==1
            break;
 
            case 3: // pJump==1 && pSpin==1
            SetPlayerAnim("SpinRight");
            break;
        }
 
        cml=0;
        if(cmr==0)
        {
            switch(RunKey)
            {
                case 0:
                SetMove(3+sextra, .5);
                break;
 
                case 1:
                SetMove(5+sextra, .5);
                break;
            }
        }
        break;
 
        case -1:
        cDir=0;
        switch(pJump+pSpin*2)
        {
            case 0: // pJump==0 && pSpin==0
            if(cml==0)
            {
                SetPlayerAnim("WalkLeft");
            }
            else if(cml==1)
            {
                SetPlayerAnim("StandLeft");
            }
            break;
 
            case 1: // pJump==1 && pSpin==0
            SetPlayerAnim("FallLeft");
            break;
 
            case 2: // pJump==0 && pSpin==1
            break;
 
            case 3: // pJump==1 && pSpin==1
            SetPlayerAnim("SpinLeft");
            break;
        }
        cmr=0;
 
        if(cml==0)
        {
            switch(RunKey)
            {
                case 0:
                SetMove(-3-sextra, .5);
                break;
 
                case 1:
                SetMove(-5-sextra, .5);
                break;
            }
        }
        break;
    }
 
    pAnimNum=animindex;
    if(hp<=0)
    {
        transp=.99;
        gameoverx=1;
    }
 
    if(KeyAttack)
    {
        at++;
 
        if(at==1)
        {
            PlaySound2("data/shot.wav", 1, 1, 0.000000);
            switch(cDir)
            {
                case 0:
                CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
                break;
 
                case 1:
                CreateActor("Bullet", "Bullet", "(none)", "(none)", 0, 12, false);
                break;
            }
        }
        else if(at>=5)
        {
            at=0;
        }
    }
    else if(!KeyAttack)
    {
        at=0;
    }
}


if(pSpin)
{
    soundtimer++;
    if(soundtimer>=6)
    {

        soundtimer=0;
    }
    PlaySound2("data/spin3.wav", .2, 1, 0.000000);
}
else if(pSpin==0)
{
    soundtimer=0;
}

if(pJump)
{
    cmr=0; cml=0;
}


if(frameflash)
{
    temp++;
    if(temp%10==0)
    {
        transp=.99;
    }
    else if((temp+5)%10==0)
    {
        transp=0;
    }
 
    if(temp>=60)
    {
        frameflash=0;
        temp=0;
    }
}

Lastly, seeing that code it's no wonder you don't like debugging. Your habits make your code rather hard to look through. Did you have anything else that would cause the lag? It would be easier to see the ged though.


This wasn't the source of lag? I'll send the ged then. Thanks for cleaning it up a bit. And whats a "ternary operator"? and yeah, my if's are very.. well, I don't know how to put it o-o. I'll throw in that code you sent and give you the ged. Thanks a million sky!

Oh and the uniform spacing, I agree, 100%. Sometimes I get lazy and end up not fixing it though.

Actually the code you gave had a bug. The player would become invisible and not return to his original state after he gets hit.

Anywho heres the get :)

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 9:32 pm
by skydereign
Oh, yeah I tried to keep things logically similar, but I forgot that. Changing the bottom if(temp%10==0) to if(temp>0 && temp<60 && temp%10==0) would fix that. From just running it I don't see any lag in either of the areas. And for the spacing problem, gE provides a decent spacing scheme by default. You seem to be going out of the way to not use it. And might as well point out your zdepth scheme is messed up. You are behind the grass while in front of the tiles. Not a major thing but it was one of the first things I noticed.

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 9:43 pm
by Hblade
Your supposed to be behind the grass :P One thing though, I forgot to edit the bullets zdepth haha.

And yeah, I'll start to use the default spacing, then need to add another if statement, such as at the top for example, or something related to that, and I end up never correcting it.
Cheers man.

It lags on me because I guess I'm using Wine, but I also tried the linux version (Not the alsa one, that doesn't work), and still had performance issues.

Pentium Dual Core 3.2GHZ SSSE3.1 support processor
8GB Ram (Only opperating at low speed though, because of motherboard)
Nvidia GeForce 9800GT
Ubuntu 11.10 with Ubuntu Studio installed.

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 9:47 pm
by skydereign
Ah, I'm currently on a school computer so I'm using windows. Have you tried commenting out everything that has to do with sound? Since you are experiencing lag on Linux and I'm not on windows, chances are high it has something to do with sound. Otherwise there are no major differences between the two. And your zdpeth scheme wouldn't work in real life, which is why it seems weird to me. If you are behind the grass (which is on the platform) how can you be in front of the platform? Having the grass in front of the player is a nice way to add depth, but either the player shouldn't be able to colliding so close to the wall, or he should be behind the wall. It's really only obvious if you jump onto a new platform.

Re: Unknown Lag Bug?

PostPosted: Tue Mar 06, 2012 9:51 pm
by Hblade
Hahaha good point, I changed that. Now the grass is behind. I might add trees or something to place in front.

Anyway, thanks man. I'm going to re-install windows later on actually.