Raw draw and raw restore became slow as hell on sundays

Started by Goldmund, Tue 05/08/2003 00:28:22

Previous topic - Next topic

Goldmund

Okay, this here function performed very  nicely in version before - I think - say - version 2.50, 2.52, somewhere around that. Then it became really, really slow, although it works. What has caused this great slowing down? I haven't changed anything in my script!

What this does:
I have an open electronic lock in the game, and the character uses inventory item "wires" to connect them to different nodes of the lock to find the proper combination and unlock it.
"pointa" is the starting point, the node at which player clicked first with mode 4, useinv (wires)
"pointb" is the ending point, the node at which player clicked after he chose the first node to attach the wire to.


function room_a() {
 // script for room: Repeatedly execute

if (pointa>0) {
if (pointb<1) {
 if ((GetCursorMode()==4)&&(character[EGO].activeinv==46)) {
   if (pointa==10) {
    RawRestoreScreen ();
    RawDrawLine (139, 52, mouse.x, mouse.y);}
   if (pointa==1) {
    RawRestoreScreen ();
    RawDrawLine (140, 57, mouse.x, mouse.y);}
   if (pointa==2) {
    RawRestoreScreen ();
    RawDrawLine (141, 62, mouse.x, mouse.y);}
   if (pointa==3) {
    RawRestoreScreen ();
    RawDrawLine (141, 67, mouse.x, mouse.y);}
   if (pointa==4) {
    RawRestoreScreen ();
    RawDrawLine (141, 73, mouse.x, mouse.y);}
   if (pointa==5) {
    RawRestoreScreen ();
    RawDrawLine (142, 78, mouse.x, mouse.y);}
   if (pointa==6) {
    RawRestoreScreen ();
    RawDrawLine (142, 83, mouse.x, mouse.y);}
   if (pointa==7) {
    RawRestoreScreen ();
    RawDrawLine (142, 89, mouse.x, mouse.y);}
   if (pointa==8) {
    RawRestoreScreen ();
    RawDrawLine (142, 94, mouse.x, mouse.y);}
   if (pointa==9) {
    RawRestoreScreen ();
    RawDrawLine (142, 99, mouse.x, mouse.y);}
   if (pointa==11) {
    RawRestoreScreen ();
    RawDrawLine (152, 101, mouse.x, mouse.y);}
   if (pointa==12) {
    RawRestoreScreen ();
    RawDrawLine (153, 69, mouse.x, mouse.y);}
   if (pointa==13) {
    RawRestoreScreen ();
    RawDrawLine (171, 72, mouse.x, mouse.y);}
   }
  }
else {//pointb juz podlaczone
  if (((pointa==7)&&(pointb==13))||((pointb==7)&&(pointa==13))) {
    invwires=invwires-1;PlaySound(1);ObjectOn(3);RawRestoreScreen ();
    if (invwires==0) {SetPlayerCharacter(EGO);LoseInventory(46);}
    Display("Beep! Seems this connection is right.");
    pointa=0;pointb=0;cona=1;}
  else if (((pointa==4)&&(pointb==11))||((pointa==11)&&(pointb==4))) {
    invwires=invwires-1;PlaySound(1);ObjectOn(4);RawRestoreScreen ();
    if (invwires==0) {SetPlayerCharacter(EGO);LoseInventory(46);}
    Display("Beep! Seems this connection is right.");
    pointa=0;pointb=0;conb=1;}
  else if (((pointa==10)&&(pointb==3))||((pointa==3)&&(pointb==10))) {
    invwires=invwires-1;PlaySound(1);
    ObjectOn(5);RawRestoreScreen ();
    if (invwires==0) {SetPlayerCharacter(EGO);LoseInventory(46);}
    Display("Beep! Seems this connection is right.");
    pointa=0;pointb=0;conc=1;}
  else {Display("Nope. No sound. I remove the wire, let's try one more time.");
   pointa=0;pointb=0;RawRestoreScreen ();}
  }
}

Gilbert

Hmmm did you test your game using the same resolution in both version?
Because use RawSaveScreen() or RawRestoreScreen() repeatedly in higher res can possibly cause slow down if the computer is not fast enough.

Goldmund

No, everything remains the same.
It seems that there is something in the newer versions that make raw-restore or raw-draw painfully slow... maybe someone should re-compile ags-draw and see if it works in normal speed?

Pumaman

Well, a possible way to speed it up is not to call RawRestoreScreen on every frame. Change this:

if ((GetCursorMode()==4)&&(character[EGO].activeinv==46)) {

to something like:

if ((GetCursorMode()==4)&&(character[EGO].activeinv==46) && (mouse.x != mouse_x_was)) {
mouse_x_was = mouse.x;


obviously you'll have to declare mouse_x_was at the top of the room script.

This way, the line will only be re-drawn when the mouse moves. See if it helps at all.

Goldmund

Thanks, Chris: there IS an improvement, but very small and still making playing impossible.
It cannot compare with the absolute smoothness with which it worked before; I'm afraid that there is something in newer versions that slows it immensely.

Pumaman

I just tried something similar, and had no problems with a consistent 40 fps.

Try commenting out the whole "if ((GetCursorMode()==4)&&(character[EGO].activeinv==46)) {"  block, so that it's not actually drawing the line, and see if it still goes slowly. It might be something else causing the problem.

Goldmund

Hm, I've traced the problem to just one command - RawRestoreScreen.
If I erase the command, everything else goes smoothly - but, of course, the screen gets all cluttered with previous positions of the "wire", then.

Pumaman

What resolution are you using?
How fast is your computer?
Which version of AGS are you using?

Goldmund

1) 640/400 hi-colour

2) I don't really know how to answer it...
gfx card: NVIDIA GeForce2 mx,
comp is Genuine Intel x86, 128mb ram
Still, it performed this task very smoothly on the previous AGS versions, so I don't think it's the fault of the hardware.

3) the newest beta, although the problem persists for something like 3-4 (?) betas

Pumaman

Very strange - I just tested it at 640x400x16 with the latest version and I didn't have any problems. Do you have the possibility of running your game on another computer and see if it suffers the same problem?

SMF spam blocked by CleanTalk