Jibble

Author Topic: Slow Drawing, how can I improve it  (Read 831 times)

Dualnames

  • AGS Baker
  • Pretty Badass
    • Dualnames worked on one or more games that won an AGS Award!
    •  
    • Dualnames worked on one or more games that was nominated for an AGS Award!
Re: Slow Drawing, how can I improve it
« Reply #20 on: 16 Feb 2019, 22:03 »
It is the iterations, Steve is doing way less of those.
No more military army stuff. I'm alive and back.

Scavenger

  • Cavefish
  • In Four Glorious Colours!
    • I can help with animation
    • I can help with backgrounds
    • I can help with characters
    • I can help with scripting
    • Scavenger worked on one or more games that won an AGS Award!
    •  
    • Scavenger worked on one or more games that was nominated for an AGS Award!
Re: Slow Drawing, how can I improve it
« Reply #21 on: 17 Feb 2019, 01:33 »
Wait a minute, I think I've done a similar effect in Terror of the Vampire. You don't even need to use PutPixel, because DrawCircle and CopyTransparencyMask are much, much faster. It ends up looking like this:
(It's at 2:25)

Basically, you draw two circles over each other (one to draw the ring, the other to cut out the middle), take a screenshot of the current screen, and cut it out with the mask. Then you blit that translucently to the screen with maybe just 1 pixel of random jitter to throw everything off, and the next frame, before you even remove the first bit, you take another screenshot and do the same thing. It's crude, but it's FAST. Also I'm really regretting not commenting all my code, but this was for a MAGS game so I didn't have much time to document it.
Code: Adventure Game Studio
  1.  
  2. // new module script
  3. DynamicSprite *echosprite;
  4. DynamicSprite *echosprite2;
  5. DynamicSprite *echomask;
  6. int angle = 1;
  7. int echoX;
  8. int echoY;
  9. int echotimer=0;
  10. bool doEcho = false;
  11. int size;
  12.  
  13. static function VFX::EchoAt (int x, int y,int radius)
  14. {
  15.   echoX = x;
  16.   echoY = y;
  17.   echotimer = 0;
  18.   doEcho = true;
  19.   size = radius*2;
  20.   echosprite = DynamicSprite.Create (radius*2, radius*2);
  21.   echosprite2 = DynamicSprite.CreateFromExistingSprite (echosprite.Graphic);
  22.   sldEcho.Min = 0;
  23.   sldEcho.Max = radius;
  24.   sldEcho.Value = 0;
  25.   sldEcho.TweenValue (1.0, radius, eEaseLinearTween, eNoBlockTween);
  26.   sldEcho2.Min = 0;
  27.   sldEcho2.Max = radius;
  28.   sldEcho2.Value = 0;
  29.   sldEcho2.TweenValue (1.2, radius, eEaseInOutSineTween, eNoBlockTween);
  30. }
  31.  
  32. function MakeEcho ()
  33. {
  34.   if (echotimer < size && doEcho)
  35.   {
  36.   echomask = DynamicSprite.Create (size, size);
  37.   DrawingSurface *surf = echomask.GetDrawingSurface ();
  38.   surf.DrawingColor = 15;
  39.   surf.DrawCircle (size/2, size/2, sldEcho.Value);
  40.   surf.DrawingColor = 0;
  41.   surf.DrawCircle (size/2, size/2, sldEcho2.Value);
  42.   surf.Release ();
  43.   echosprite2 = DynamicSprite.CreateFromExistingSprite (echosprite.Graphic);
  44.   echosprite = DynamicSprite.CreateFromScreenShot (320, 200);
  45.   int newX = echoX-(size/2);
  46.   int w=newX+size;
  47.   int underflowX;
  48.   int overflowX;
  49.   int newY = echoY-(size/2);
  50.   int h = newY+size;
  51.   int underflowY;
  52.   int overflowY;
  53.   if (newX < 0)
  54.   {
  55.     underflowX =  newX * (-1);
  56.     newX = 0;
  57.   }
  58.   if (newX+size > 320)
  59.   {
  60.     overflowX = (newX+size-320);
  61.     w = 320-overflowX;
  62.   }
  63.   {
  64.    
  65.   }
  66.    if (newY < 0)
  67.   {
  68.     underflowY =  newY * (-1);
  69.     newY = 0;
  70.   }
  71.   if (newY+size > 200)
  72.   {
  73.     overflowY = (newY+size-200);
  74.     h = 200-overflowY;
  75.   }
  76.   if (w+newX > echosprite.Width)
  77.   {
  78.     newX = 0;
  79.     w = echosprite.Width;
  80.   }
  81.   if (h+newY > echosprite.Height)
  82.   {
  83.     newY = 0;
  84.     h = echosprite.Height;
  85.   }
  86.   echosprite.Crop (newX, newY, w, h);
  87.   echosprite.ChangeCanvasSize (size, size, overflowX-underflowX, overflowY-underflowY);
  88.   echosprite.CopyTransparencyMask (echomask.Graphic);
  89.   Translucence.CreateOverlay (80, echosprite.Graphic, 128, 2, echoX-(size/2)-1-Random(1), echoY-(size/2)+1-Random(1)); //You can replace this with drawing at 50% transparency.
  90.   //Translucence.CreateOverlay (81, echomask.Graphic, 128-echotimer, 2, echoX-(size/2), echoY-size/2);
  91.   echotimer = sldEcho.Value;
  92.   }
  93.   else
  94.   {
  95.     echotimer = 0;
  96.     echoX = 0;
  97.     echoY = 0;
  98.     doEcho = false;
  99.     Translucence.DeleteOverlay (80);
  100.     Translucence.DeleteOverlay (81);
  101.   }
  102. }
  103.  

Kweepa

  • Mutated Guano Deviser
    • Best Innovation Award Winner 2009, for his modules and plugins
    • Kweepa worked on one or more games that won an AGS Award!
    •  
    • Kweepa worked on one or more games that was nominated for an AGS Award!
Re: Slow Drawing, how can I improve it
« Reply #22 on: 17 Feb 2019, 02:30 »
what a bastard
I love you too, Dual!
Smart idea with the mask, Snarky & Scavenger! Kind of hard to tell with the video compression but it sounds like it would work well. (And lovely art all round!)
« Last Edit: 17 Feb 2019, 02:33 by Kweepa »
Still waiting for Purity of the Surf II

Dualnames

  • AGS Baker
  • Pretty Badass
    • Dualnames worked on one or more games that won an AGS Award!
    •  
    • Dualnames worked on one or more games that was nominated for an AGS Award!
Re: Slow Drawing, how can I improve it
« Reply #23 on: 17 Feb 2019, 05:55 »
Well, my issues with my code is i wanted to do a rectangle then i thought why not a circle, then proceeded to circle the rectangle instead of drawing a circle lol, also wow that is almost the exact same effect!
No more military army stuff. I'm alive and back.