module RbSDL2::Timer

Public Class Methods

delay(ms) click to toggle source

ms へ与えたミリ秒だけスレッドを停止します。SDL のタイマーを使用しています。 ms が負の数だった場合 ArgumentError が発生します。

# File lib/rb_sdl2/timer.rb, line 6
def delay(ms)
  raise ArgumentError if ms < 0
  ::SDL2.SDL_Delay(ms)
end
performance_count(= ::SDL2.SDL_GetPerformanceCounter) click to toggle source

SDL が提供する高精度カウンターの値を返します。 返ってくる値には意味がありません。精度も SDL の実装や動作環境ごとに違います。

# File lib/rb_sdl2/timer.rb, line 16
    def performance_count = ::SDL2.SDL_GetPerformanceCounter

    # 与えられたブロックの実行時間を返します。単位は秒です。
    # 実行時間の計測に SDL の高精度カウンターを使用しています。
    def realtime
      t = performance_count
      yield
      (performance_count - t).fdiv(performance_frequency)
    end

    # SDL が起動してからの経過時間をミリ秒で返します。
    # SDL のタイマーを使用しており、49日ほどで 0 に戻ります。
    def ticks = ::SDL2.SDL_GetTicks
  end
end
performance_frequency(= ::SDL2.SDL_GetPerformanceFrequency) click to toggle source

performance_count の 1 秒あたりの増加量を返します。

# File lib/rb_sdl2/timer.rb, line 12
      def performance_frequency = ::SDL2.SDL_GetPerformanceFrequency

      # SDL が提供する高精度カウンターの値を返します。
      # 返ってくる値には意味がありません。精度も SDL の実装や動作環境ごとに違います。
      def performance_count = ::SDL2.SDL_GetPerformanceCounter

      # 与えられたブロックの実行時間を返します。単位は秒です。
      # 実行時間の計測に SDL の高精度カウンターを使用しています。
      def realtime
        t = performance_count
        yield
        (performance_count - t).fdiv(performance_frequency)
      end

      # SDL が起動してからの経過時間をミリ秒で返します。
      # SDL のタイマーを使用しており、49日ほどで 0 に戻ります。
      def ticks = ::SDL2.SDL_GetTicks
    end
  end
end
realtime() { || ... } click to toggle source

与えられたブロックの実行時間を返します。単位は秒です。 実行時間の計測に SDL の高精度カウンターを使用しています。

# File lib/rb_sdl2/timer.rb, line 20
def realtime
  t = performance_count
  yield
  (performance_count - t).fdiv(performance_frequency)
end
ticks(= ::SDL2.SDL_GetTicks) click to toggle source

SDL が起動してからの経過時間をミリ秒で返します。 SDL のタイマーを使用しており、49日ほどで 0 に戻ります。

# File lib/rb_sdl2/timer.rb, line 28
  def ticks = ::SDL2.SDL_GetTicks
end