Class: SFML::Time

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/sfml/system/time.rb

Overview

Represents a time value. Stored internally as microseconds (int64), same as sfTime in CSFML. Immutable and comparable.

SFML::Time.seconds(1.5)        #=> 1_500_000 µs
SFML::Time.milliseconds(500)
SFML::Time.microseconds(42)
SFML::Time.zero

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(microseconds) ⇒ Time

Returns a new instance of Time.



19
20
21
22
# File 'lib/sfml/system/time.rb', line 19

def initialize(microseconds)
  @microseconds = Integer(microseconds)
  freeze
end

Instance Attribute Details

#microsecondsObject (readonly)

Returns the value of attribute microseconds.



12
13
14
# File 'lib/sfml/system/time.rb', line 12

def microseconds
  @microseconds
end

Class Method Details

.from_native(struct) ⇒ Object

:nodoc:



40
41
42
# File 'lib/sfml/system/time.rb', line 40

def self.from_native(struct) # :nodoc:
  new(struct[:microseconds])
end

.microseconds(value) ⇒ Object



16
# File 'lib/sfml/system/time.rb', line 16

def self.microseconds(value) = new(Integer(value))

.milliseconds(value) ⇒ Object



15
# File 'lib/sfml/system/time.rb', line 15

def self.milliseconds(value) = new(Integer(value) * 1_000)

.seconds(value) ⇒ Object



14
# File 'lib/sfml/system/time.rb', line 14

def self.seconds(value)      = new((value * 1_000_000).to_i)

.zeroObject



17
# File 'lib/sfml/system/time.rb', line 17

def self.zero                = new(0)

Instance Method Details

#+(other) ⇒ Object



28
# File 'lib/sfml/system/time.rb', line 28

def +(other) = Time.new(@microseconds + other.microseconds)

#-(other) ⇒ Object



29
# File 'lib/sfml/system/time.rb', line 29

def -(other) = Time.new(@microseconds - other.microseconds)

#-@Object



30
# File 'lib/sfml/system/time.rb', line 30

def -@       = Time.new(-@microseconds)

#<=>(other) ⇒ Object



31
# File 'lib/sfml/system/time.rb', line 31

def <=>(other) = @microseconds <=> other.microseconds

#as_microsecondsObject



26
# File 'lib/sfml/system/time.rb', line 26

def as_microseconds = @microseconds

#as_millisecondsObject



25
# File 'lib/sfml/system/time.rb', line 25

def as_milliseconds = @microseconds / 1_000

#as_secondsObject



24
# File 'lib/sfml/system/time.rb', line 24

def as_seconds      = @microseconds / 1_000_000.0

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


34
# File 'lib/sfml/system/time.rb', line 34

def eql?(other) = other.is_a?(Time) && @microseconds == other.microseconds

#hashObject



33
# File 'lib/sfml/system/time.rb', line 33

def hash = @microseconds.hash

#to_nativeObject

:nodoc:



44
45
46
# File 'lib/sfml/system/time.rb', line 44

def to_native # :nodoc:
  C::System::Time.new.tap { |t| t[:microseconds] = @microseconds }
end

#to_sObject Also known as: inspect



37
# File 'lib/sfml/system/time.rb', line 37

def to_s = "#<SFML::Time #{as_seconds}s>"