root/as3/SiOPM/trunk/src/org/si/utils/timer.as

リビジョン 3165, 2.2 kB (コミッタ: keim, コミット時期: 3 年 前)

SiON update to ver0.58, add FFT module, change voice architecture and many bug fixes

Line 
1 package org.si.utils {
2     import flash.display.DisplayObjectContainer;
3     import flash.text.TextField;
4     import flash.events.Event;
5     import flash.utils.getTimer;
6    
7    
8     /** static timer class */
9     public class timer {
10         static public var title:String = "";
11         static private var _text:TextField = null;
12         static private var _time:Vector.<int>;
13         static private var _sum :Vector.<int>;
14         static private var _stat:Vector.<String>;
15         static private var _cnt :int;
16         static private var _avc:int;
17        
18        
19         /** initialize timer.
20          *  @param parent parent object
21          *  @param averagingCount averaging frames
22          *  @param stat texts to display measured times. "##" is replaced with measured time.
23          */
24         static public function initialize(parent:DisplayObjectContainer, averagingCount:int, ...stat) : void {
25             if (!_text) parent.addChild(_text = new TextField());
26             _avc  = averagingCount;
27             _stat = Vector.<String>(stat);
28             _time = new Vector.<int>(stat.length);
29             _sum  = new Vector.<int>(stat.length);
30             _cnt  = new Vector.<int>(stat.length);
31             _text.background = true;
32             _text.backgroundColor = 0x80c0f0;
33             _text.autoSize = "left";
34             _text.multiline = true;
35             parent.addEventListener("enterFrame", _onEnterFrame);
36         }
37        
38         /** start timer */
39         static public function start(slot:int=0) : void { _time[slot] = getTimer(); }
40        
41         /** pause timer */
42         static public function pause(slot:int=0) : void { _sum[slot] += getTimer() - _time[slot]; }
43        
44         // enter frame event handler
45         static private function _onEnterFrame(e:Event) : void {
46             if (++_cnt == _avc) {
47                 _cnt = 0;
48                 var str:String = "", line:String;
49                 for (var slot:int = 0; slot<_sum.length; slot++) {
50                     line = _stat[slot].replace("##", String(_sum[slot] / _avc).substr(0,3));
51                     str += line + "\n";
52                     _sum[slot] = 0;
53                 }
54                 _text.text = title + "\n" + str;
55             }
56         }
57     }
58 }
59
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。