Class: Mittsu::Clock
- Inherits:
-
Object
- Object
- Mittsu::Clock
- Defined in:
- lib/mittsu/core/clock.rb
Instance Attribute Summary collapse
-
#auto_start ⇒ Object
Returns the value of attribute auto_start.
-
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
-
#old_time ⇒ Object
Returns the value of attribute old_time.
-
#running ⇒ Object
Returns the value of attribute running.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
Instance Method Summary collapse
- #get_delta ⇒ Object
- #get_elapsed_time ⇒ Object
-
#initialize(auto_start = true) ⇒ Clock
constructor
A new instance of Clock.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(auto_start = true) ⇒ Clock
Returns a new instance of Clock.
5 6 7 8 9 10 11 |
# File 'lib/mittsu/core/clock.rb', line 5 def initialize(auto_start = true) @auto_start = auto_start @start_time = 0 @old_time = 0 @elapsed_time = 0 @running = false end |
Instance Attribute Details
#auto_start ⇒ Object
Returns the value of attribute auto_start.
3 4 5 |
# File 'lib/mittsu/core/clock.rb', line 3 def auto_start @auto_start end |
#elapsed_time ⇒ Object
Returns the value of attribute elapsed_time.
3 4 5 |
# File 'lib/mittsu/core/clock.rb', line 3 def elapsed_time @elapsed_time end |
#old_time ⇒ Object
Returns the value of attribute old_time.
3 4 5 |
# File 'lib/mittsu/core/clock.rb', line 3 def old_time @old_time end |
#running ⇒ Object
Returns the value of attribute running.
3 4 5 |
# File 'lib/mittsu/core/clock.rb', line 3 def running @running end |
#start_time ⇒ Object
Returns the value of attribute start_time.
3 4 5 |
# File 'lib/mittsu/core/clock.rb', line 3 def start_time @start_time end |
Instance Method Details
#get_delta ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mittsu/core/clock.rb', line 29 def get_delta diff = 0 if @auto_start && ! @running self.start end if @running new_time = Time.now diff = 0.001 * (new_time - @old_time) @old_time = new_time @elapsed_time += diff end diff end |
#get_elapsed_time ⇒ Object
24 25 26 27 |
# File 'lib/mittsu/core/clock.rb', line 24 def get_elapsed_time self.get_delta @elapsed_time end |
#start ⇒ Object
13 14 15 16 17 |
# File 'lib/mittsu/core/clock.rb', line 13 def start @start_time = Time.now @old_time = @start_time @running = true end |
#stop ⇒ Object
19 20 21 22 |
# File 'lib/mittsu/core/clock.rb', line 19 def stop self.get_elapsed_time @running = false end |