~ubuntu-branches/ubuntu/oneiric/haxe/oneiric

« back to all changes in this revision

Viewing changes to haxe/std/haxe/Timer.hx

  • Committer: Bazaar Package Importer
  • Author(s): Jens Peter Secher
  • Date: 2009-03-18 23:09:50 UTC
  • mfrom: (3.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20090318230950-pgfuxg2ucolps74t
Tags: 1:2.2-2
* Use ocamlfind to locate and use the libraries xml-light and extlib
  which already exist in Debian as separate packages.
  (Closes: #519630)
* Fixed compile error with camlp4 3.11, thanks to Stéphane Glondu.
  (Closes: #519627)
* Use quilt instead of dpatch for patches, and describe how to use
  quilt in Debian.source (thanks to Russ Allbery).
* Added a Vcs-Hg control filed to indicate the location of the public
  repository.
* Bumped Standards-Version to 3.8.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
package haxe;
26
26
 
27
27
class Timer {
 
28
        #if (neko || php)
 
29
        #else
28
30
 
29
31
        private var id : Null<Int>;
30
32
 
33
35
        private var timerId : Int;
34
36
        #end
35
37
 
36
 
        #if !neko
37
 
 
38
 
        public function new( time : Int ){
 
38
        public function new( time_ms : Int ){
39
39
                #if flash9
40
40
                        var me = this;
41
 
                        id = untyped __global__["flash.utils.setInterval"](function() { me.run(); },time);
42
 
                #else flash
 
41
                        id = untyped __global__["flash.utils.setInterval"](function() { me.run(); },time_ms);
 
42
                #elseif flash
43
43
                        var me = this;
44
 
                        id = untyped _global["setInterval"](function() { me.run(); },time);
45
 
                #else js
 
44
                        id = untyped _global["setInterval"](function() { me.run(); },time_ms);
 
45
                #elseif js
46
46
                        id = arr.length;
47
47
                        arr[id] = this;
48
 
                        timerId = untyped window.setInterval("haxe.Timer.arr["+id+"].run();",time);
 
48
                        timerId = untyped window.setInterval("haxe.Timer.arr["+id+"].run();",time_ms);
49
49
                #end
50
50
        }
51
51
 
52
 
        public function stop(){
 
52
        public function stop() {
53
53
                if( id == null )
54
54
                        return;
55
55
                #if flash9
56
56
                        untyped __global__["flash.utils.clearInterval"](id);
57
 
                #else flash
 
57
                #elseif flash
58
58
                        untyped _global["clearInterval"](id);
59
 
                #else js
 
59
                #elseif js
60
60
                        untyped window.clearInterval(timerId);
61
61
                        arr[id] = null;
62
62
                        if( id > 100 && id == arr.length - 1 ) {
66
66
                                        p--;
67
67
                                arr = arr.slice(0,p+1);
68
68
                        }
69
 
                #else neko
70
69
                #end
71
70
                id = null;
72
71
        }
73
72
 
74
 
        public f9dynamic function run(){
 
73
        public dynamic function run() {
75
74
        }
76
75
 
77
 
        public static function delayed( f : Void -> Void, time : Int ) : Void -> Void {
78
 
                return function() {
79
 
                        var t = new haxe.Timer(time);
80
 
                        t.run = function() {
81
 
                                t.stop();
82
 
                                f();
83
 
                        };
 
76
        public static function delay( f : Void -> Void, time_ms : Int ) {
 
77
                var t = new haxe.Timer(time_ms);
 
78
                t.run = function() {
 
79
                        t.stop();
 
80
                        f();
84
81
                };
85
82
        }
86
83
 
87
 
        private static var fqueue = new Array<Void -> Void>();
88
 
        public static function queue( f : Void -> Void, ?time : Int ) : Void {
89
 
                fqueue.push(f);
90
 
                haxe.Timer.delayed(function() {
91
 
                        fqueue.shift()();
92
 
                },if( time == null ) 0 else time)();
93
 
        }
94
 
 
95
84
        #end
96
85
 
97
86
        /**
99
88
        **/
100
89
        public static function stamp() : Float {
101
90
                #if flash
102
 
                return flash.Lib.getTimer() / 1000;
103
 
                #else neko
104
 
                return neko.Sys.time();
105
 
                #else js
106
 
                return Date.now().getTime() / 1000;
107
 
                #else error
 
91
                        return flash.Lib.getTimer() / 1000;
 
92
                #elseif neko
 
93
                        return neko.Sys.time();
 
94
                #elseif php
 
95
                        return php.Sys.time();
 
96
                #elseif js
 
97
                        return Date.now().getTime() / 1000;
 
98
                #else
 
99
                        return 0;
108
100
                #end
109
101
        }
110
102