2 // Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include "movie_root.h"
27 #include "Global_as.h"
28 #include "as_function.h"
30 #include <limits> // for numeric_limits
40 Timer::Timer(as_function
& method
, unsigned long ms
,
41 as_object
* this_ptr
, const fn_call::Args
& args
, bool runOnce
)
44 _start(std::numeric_limits
<unsigned long>::max()),
54 Timer::Timer(as_object
* this_ptr
, const ObjectURI
& methodName
,
55 unsigned long ms
, const fn_call::Args
& args
, bool runOnce
)
58 _start(std::numeric_limits
<unsigned long>::max()),
60 _methodName(methodName
),
69 Timer::clearInterval()
72 _start
= std::numeric_limits
<unsigned long>::max();
78 _start
= getVM(*_object
).getTime();
83 Timer::expired(unsigned long now
, unsigned long& elapsed
)
85 if (cleared()) return false;
86 long unsigned expTime
= _start
+ _interval
;
87 if (now
< expTime
) return false;
88 elapsed
= expTime
-now
;
93 Timer::executeAndReset()
95 if (cleared()) return;
97 if (_runOnce
) clearInterval();
98 else _start
+= _interval
; // reset the timer
105 // If _function is not 0, _methodName should be 0 anyway, but the
106 // ternary operator is there for clarity.
107 as_object
* super
= _function
? _object
->get_super()
108 : _object
->get_super(_methodName
);
109 VM
& vm
= getVM(*_object
);
111 as_value timer_method
= _function
? _function
:
112 getMember(*_object
, _methodName
);
114 as_environment
env(vm
);
117 fn_call::Args
argsCopy(_args
);
119 invoke(timer_method
, env
, _object
, argsCopy
, super
);
124 Timer::markReachableResources() const
126 _args
.setReachable();
128 if (_function
) _function
->setReachable();
129 if (_object
) _object
->setReachable();