fjkfhjfjhfjhfjh

Jul 6

Minor speed improvement on doUpdate method

1 comment

According to https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame, a requestAnimationFrame function call is passed a parameter which contains a timestamp. This means you can avoid having to call new Date().getTime() on each RAF. It's not a massive improvement, but you get this for free so you could use it?

 

Diff below:

 

diff --git a/runtime/run/amos.js b/runtime/run/amos.js
index ebe53dd..cede8b0 100644
--- a/runtime/run/amos.js
+++ b/runtime/run/amos.js
@@ -157,16 +157,19 @@ function AMOS( canvasId, manifest )
   {
      if ( response )
      {
-        self.previousTime = new Date().getTime();
-        window.requestAnimationFrame( doUpdate );
+        window.requestAnimationFrame( startUpdates );
      }
   }, 0 );
 
-  function doUpdate()
+  function startUpdates( time ) {
+     self.previousTime = time;
+     window.requestAnimationFrame( time );
+  }
+
+  function doUpdate( time )
   {
      if ( self.section )
      {
-        var time = new Date().getTime();
         self.fps[ self.fpsPosition++ ] = time - self.previousTime;
         self.fpsPosition = self.fpsPosition >= self.fps.length ? 0 : self.fpsPosition;
         self.previousTime = time;

 

 

 

I created an issue on BitBucket - https://bitbucket.org/francoislionet/amos-2/issues/1/minor-speed-improvement-on-doupdate-method

New Posts
  • With my AMOS Code, when I want to compile it with AMOS2 Compiler, I have errors on the "Shared" statement. V1=23:X=0:Y=0:LIFE=5 Dim MAP(121) Shared V1,MAP(),X,Y,LIFE >> Syntax error here But on Amiga and AMOS Pro, that's works very well. Will "Shared"statement be available? Thanks.
  • A new version is out! It has the wrong date; it says 05/05/19 - Now fixed with 07/07/19 version. ------------ I've copied the A1200 manifest into it and compiled a program. It's giving a syntax error on an input line: locate 19,22:input pw$ ------------ It looks like co-ords are working better, as pixel co-ords now match the bob/sprite co-ords. Bobs are now showing much smaller. Possibly too small, but I'll do some testing on that. - Now fixed. The scaling was wrong. ------------ main.amos:181:18: error: syntax error main.amos:182:18: error: syntax error main.amos:184:14: error: syntax error main.amos:185:47: error: syntax error for check=1 to bobson a#=abs(x#-( bpos #(check,1)))^2 b#=abs(y#-( bpos #(check,2)))^2 dist#=sqr(a#+b#) area#=63* bz #(check) if (dist#<area# and dist#<>0) and (abs(z#- bz #(check))<0.05) then hit=1 next check ------------ Not sure if PAL screen should work yet, but I'm still having to use the tiny NTSC 200 pixel high one. I noticed PAL mentioned in the manifest, and I tried changing the screen to 256 high in there. - PAL screen seems to work now
  • Hi there, I downloaded the most recent build (2019-07-13), and followed the Quick Start instructions, but I needed to manually install the pngjs library. If you hit F5 in the Code workspace without doing this, you get: Error: Cannot find module 'pngjs' Require stack: - c:\Development\amos-2\compiler\utilities.js - c:\Development\amos-2\compiler\messages.js - c:\Development\amos-2\compiler\amosc.js at Function.Module._resolveFilename (internal/modules/cjs/loader.js:625:15) at Function.Module._load (internal/modules/cjs/loader.js:527:27) at Module.require (internal/modules/cjs/loader.js:683:19) at require (internal/modules/cjs/helpers.js:16:16) at Object.<anonymous> (c:\Development\amos-2\compiler\utilities.js:21:7) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:643:32) at Function.Module._load (internal/modules/cjs/loader.js:556:12) at Module.require (internal/modules/cjs/loader.js:683:19) I fixed this by entering the amos-2 folder and running: npm install pngjs I'm running NodeJS v12.6.0.