Can anyone find the slow-down?

Started by bx83, Wed 19/06/2019 07:22:47

Previous topic - Next topic

bx83

I can't for the life of me find what is slowing this game down; it's trying to do something every 1/40th of a second. Can anyone help?

Code: ags

function room_FirstLoad()
{
  oCandlelight.IgnoreWalkbehinds=true;
}

//----------------------------------------------------------------------------------------------------------------------
// Room Load
//----------------------------------------------------------------------------------------------------------------------

function room_Load()
{
  JULIUS_WALKSPEED_X = 8;
  JULIUS_WALKSPEED_Y = 7;
  cJulius.SetWalkSpeed(JULIUS_WALKSPEED_X, JULIUS_WALKSPEED_Y);

  TOD=0;     //cheat
  


// TOD = 1;
// TimeHoleMade = false;
// TimeHoleMade = true;
	
// TOD = time of day
// 0 day
// 1 early morning
// 2 night

	
  DrawingSurface* surface = Room.GetDrawingSurfaceForBackground();
  switch (TOD)
  {
    case 0:                                                           // day time
      if (TimeHoleMade) {
        oTimeHole.Visible=true;
      } else {
        oTimeHole.Visible=false;
        if (HoleMade) {
          surface.DrawImage(0, 0, 2558, 0);                             // day / hole
        } else {
          surface.DrawImage(0, 0, 2561, 0);                             // day / no hole
        }
      }
      
      //ape awake
      SetTimer(TIMER_APE, GetGameSpeed()*6);
      if (!ApeConvoDone) cApe.SetProperty("convodone",0);
      
      //giraffe asleep
      cGiraffe.LockView(178);
      cGiraffe.Animate(0, 10, eRepeat, eNoBlock);
      cGiraffe.SetProperty("convodone",1);
      
      break;

    case 1:                                                             // morning
      if (TimeHoleMade) {
        oTimeHole.Visible=true;                                        // morning / hole
      } else {
        oTimeHole.Visible=false;
        if (HoleMade) {
          surface.DrawImage(0, 0, 2557, 0);                             // morning / hole
        } else {
          surface.DrawImage(0, 0, 2560, 0);                             // morning / no hole
        }
      }
      
      //giraffe awake
      cGiraffe.SetIdleView(175, 12);
      if (!GiraffeConvoDone) cGiraffe.SetProperty("convodone",0);
      
      //tiger awake
      cTiger.SetIdleView(16, 10);
      if (!TigerConvoDone) cTiger.SetProperty("convodone",0);
      
      //ape asleep
      cApe.LockView(177);
      cApe.Animate(0, 7, eRepeat, eNoBlock);
      cApe.SetProperty("convodone",1);
      
      //tiger asleep
      cTiger.ChangeView(179);
      cTiger.SetProperty("convodone", 1);
      
      break;

    case 2:                                                             // nightime
      if (TimeHoleMade) {
        oTimeHole.Visible=true;
      } else {
        oTimeHole.Visible=false;
        if (HoleMade) {
          surface.DrawImage(0, 0, 2556, 0);                             // night / hole
        } else {
          surface.DrawImage(0, 0, 2559, 0);                             // night / no hole
        }
      }
      
      
      //giraffe awake
      cGiraffe.SetIdleView(175, 12);
      if (!GiraffeConvoDone) cGiraffe.SetProperty("convodone",0);
      
      //ape's asleep
      cApe.LockView(177);
      cApe.Animate(0, 7, eRepeat, eNoBlock);
      cApe.SetProperty("convodone",1);
      
      //tiger asleep
      cTiger.ChangeView(179);
      cTiger.SetProperty("convodone", 1);
      
      break;
	}	
  surface.Release();
  
}


//----------------------------------------------------------------------------------------------------------------------
// Room Repeat Exec
//----------------------------------------------------------------------------------------------------------------------

function room_RepExec()
{
  if (CandleLit) {
    oCandlelight.X = mouse.x+OFFSET_X;
    oCandlelight.Y = mouse.y+OFFSET_Y;
  }
  oCandlelight.Visible = CandleLit;
  
  if (!cApe.Animating && IsTimerExpired(TIMER_APE) && TOD!=0) {
    if (AngryApe) {
      cApe.LockView(174);
      cApe.Animate(0, 3, eOnce, eNoBlock, eForwards);
    } else {
      cApe.LockView(173);
      cApe.Animate(0, 5, eOnce, eNoBlock, eForwards);
    }
    SetTimer(TIMER_APE, GetGameSpeed()*16);
  }
  
  if (!cTiger.Animating && IsTimerExpired(TIMER_TIGER) && TOD!=1) {
    cTiger.LockView(179);
    switch (Random(1)) {
      case 0:
        cTiger.Animate(0, 6, eOnce, eNoBlock); break;
      case 1:
        cTiger.Animate(1, 14, eOnce, eNoBlock); break;
    }
  }
}


Here is a video:
https://redrom.ltd/img/zoovidslow.webm

Vincent

I just would like to point out something totally unrelated to your question.
Code: ags

oCandlelight.IgnoreWalkbehinds=true;


This is not going to work if you use the D3D 9 graphic driver.


Crimson Wizard

Yes, I'd like to repeat Vincent's warning, it is strongly suggested to not use IgnoreWalkbehinds at all, ever, because it breaks drawing logic, and your game won't be displayed correctly with Direct3D or OpenGL renderer and you'll get stuck with software one (DirectDraw5).

Instead, setting up object baselines should be enough, if not maybe cutting room background into more objects.


Regarding your script, I do not see anything that would slow things down in rep_exec. Have you tried disabling code there? If nothing changes then it's not this script that causes slowdowns. It may be something else too, like other script modules running on background.

bx83

Firstly, if not IgnoreWalkBehinds(), how can I get the candlelight (a large round translucent bit of yellow light that follows the mouse) to show up on all surfaces? By allowing walkbehinds, I can a) see them with the candlelight, as it goes 'behind' them, and b) can't you know, get rid of them.
Is there any graphics engine it work with? Why have the function at all? Hasn't caused any problems so far, and this command is in every room.

Would using a GUI get past all of this, instead of the oCandlelight object?

Also: it's the cages slowing everything down. 1 slows down things a bit, and can't be detected; 2 slows down things noticeably; 3 slows down things to a crawl. They're objects. Is there any way to make them faster, if not to have them in the background itself? If the do have to be in the background then a) doing a 'climbing through a hole in the wall' animation (the hole appears as part of the story) is very, very complicated; and b) they... look like shit. I can't use walk-behinds on the bars, hence I used objects to easily simulate things the animals are behind.

Any solutions to the above problems?

Slasher

Hi,

to start with, work on baselines.. the flame baseline should be higher than the objects/walkbehinds that it should be in front of...

Code: ags

object[4].Baseline=800;  just an example flame object in Global Rep Exec....

Snarky

Quote from: bx83 on Thu 20/06/2019 02:47:09
Firstly, if not IgnoreWalkBehinds(), how can I get the candlelight (a large round translucent bit of yellow light that follows the mouse) to show up on all surfaces? By allowing walkbehinds, I can a) see them with the candlelight, as it goes 'behind' them, and b) can't you know, get rid of them.
Is there any graphics engine it work with? Why have the function at all? Hasn't caused any problems so far, and this command is in every room.

It works with software rendering (DirectDraw). However...

QuoteAlso: it's the cages slowing everything down. 1 slows down things a bit, and can't be detected; 2 slows down things noticeably; 3 slows down things to a crawl. They're objects. Is there any way to make them faster, if not to have them in the background itself? If the do have to be in the background then a) doing a 'climbing through a hole in the wall' animation (the hole appears as part of the story) is very, very complicated; and b) they... look like shit. I can't use walk-behinds on the bars, hence I used objects to easily simulate things the animals are behind.

Any solutions to the above problems?

The problem is that software rendering is sloooooow, and it has problems drawing several large objects on screen (particularly with transparency). The solution is to switch to hardware-accelerated rendering (Direct3D or OpenGL), in which case IgnoreWalkBehinds() won't work. Instead you should, as Slasher says, adjust the object baseline so that it gets drawn on top of any walkbehinds.

bx83

Cool okay - It's just running slow when I press F5 and run debug, do I have to compile it for the OpenGL to work or do I have to edit something in my code?

bx83

Obviously I change winsetup.exe but... in the debug area?? When it compiles it defaults to OpenGL, so.....??

Slasher

This slowness usually happens when you fill the whole screen with an animated object/gui...

Usually I speed up players animation speed and walkspeed to compensate...

Khris

Quote from: bx83 on Thu 20/06/2019 09:18:52
Obviously I change winsetup.exe but... in the debug area?? When it compiles it defaults to OpenGL, so.....??
Not sure I understand exactly what you mean but you can do "Run game setup..." from the Build menu.

bx83

Do I have to run it from 'Build...' every time and choose OpenGL every time? Or does it just default to my first choices when running the game using F5 (debug)?

Khris

Afaik you only have to change the setup options once and they will be used for all future test runs.

SMF spam blocked by CleanTalk