AS3: How accurate are the getTimer () methods and the Timer class?

I'm developing a game (shmup), and I started asking questions about the accuracy of timers in ActionScript. Of course, they are accurate enough if you want the time to be on the order of several seconds or decibels, but it seems to work poorly when you fall into thinner ranges. This makes it quite difficult to do things like a spaceship that fires a hundred lasers per second.

In the following example, I tested how long (on average) the intervals were 1000 timer timers, calculated for 30 ms. Time and time again, the results are ~ 35-36 ms. Reducing the time, I found that the floor on the timer delay is ~ 16-17 ms. This gives me max fps ~ 60, which is fine visually, but also means that I cannot run more than 60 lasers per second :-( I did this test several times at 100 and 1000 loops, but for both 30 ms and 1 ms the result hasn't changed. I'm printing to textField at the end, because using trace () and running swf in debug mode seems to negatively impact the test. So I'm wondering:

  • Is this test a worthy assessment of the performance of the Timer class or are my results dubious?
  • Will these results change dramatically on other machines?

I understand that this depends on the accuracy of the getTimer () method, but the discussions that I find in this topic usually focus on the accuracy of getTimer () at large intervals.

package 
{
import flash.display.Sprite; import flash.events.TimerEvent; import flash.text.TextField; import flash.utils.getTimer; import flash.utils.Timer;
public class testTimerClass extends Sprite
{
    private var testTimer:Timer = new Timer(30, 1000);
    private var testTimes:Array = new Array();
    private var testSum:int = 0;
    private var testAvg:Number;
    private var lastTime:int;
    private var thisTime:int;

    public function testTimerClass()
    {
        testTimer.addEventListener(TimerEvent.TIMER, step);
        testTimer.addEventListener(TimerEvent.TIMER_COMPLETE, printResults);
        lastTime = getTimer();
        testTimer.start();
    }

    private function step(event:TimerEvent):void
    {
        thisTime = getTimer();
        testTimes.push(thisTime - lastTime);
        lastTime = thisTime;
    }

    private function printResults(event:TimerEvent):void
    {
        while (testTimes.length > 0)
        {
            testSum += testTimes.pop();
        }
        testAvg = testSum / Number(testTimer.repeatCount);              
        var txtTestResults:TextField = new TextField();
        txtTestResults.text = testAvg.toString();
        this.addChild(txtTestResults);  
    }       
}

}

I suggest that the best way would be to simply draw multiple lasers in the same frame with different positions and avoid having more than one Timer object.

edit: I used stage.frameRate to change the render frameRate and ran the test on multiple frames, but there were no changes.

+3
source share
5 answers

Tinic Uro ( Flash Player) .

+4

, enterframe eventlistener.

getTimer(), , , , "" .. , , 60FPS 10FPS.

, FPS .

, , " " , . . , .

jorelli :

, , , . . , : http://www.bigroom.co.uk/blog/polling-the-keyboard-in-actionscript-3

+2

, , script, , Timer , . 30 33-34, 3 3,4 3,5. 1 1,4 1,6 . Flash .

, . Tinic Luke. , , 16 , , , - , , , , . , , , .

- , , ENTER_FRAME. , 30 3 , ( , , , ). , , , - , , , , . , , 3 , 10 30 , 3 6 9 .

, "" T . ENTER_FRAME F/T , F - , . , , 5 , , 30FPS, 30FPS, ENTER_FRAME 5-7 , , . , 5 , .

+1

BitmapData.scroll BitmapData.copyPixels - , movieclips gpu . OpenGL, , GPU. , . , , , - . , , , .

+1

This gives me max fps ~ 60, which is fine visually, but also means that I cannot run more than 60 lasers per second: - (

I would say that you are very lucky that you get this type of FPS, and most of your users (provided that your audience is the Internet as a whole) will most likely not reach this frame rate.

I would agree that the capabilities of the flash player are probably not enough for what you are trying to achieve.

0
source

Source: https://habr.com/ru/post/1710792/


All Articles