gosu / releasy

A rake task generator to help with building/packaging/deploying Ruby applications (⚠️ unmaintained)
https://spooner.github.com/libraries/releasy/
MIT License
378 stars 29 forks source link

Poor performance on Windows #51

Closed cyberarm closed 10 years ago

cyberarm commented 10 years ago

My game runs at 60-63 FPS with Ocra, however, when I use Releasy the game averages 9 FPS.

bil-bas commented 10 years ago

Can you give any more information that that? What gems are you using? What Releasy build (wrapped, standalone, installer) are you using?

cyberarm commented 10 years ago

Gems:

chingu
texplay
ashton
orca # is in the gemfile

Using the windows_folder build method

It is only slow on this GameState:

class Game < Chingu::GameState
  trait :timer
  trait :viewport

  def setup
    Gosu::enable_undocumented_retrofication
    @music = MusicManager.new unless ARGV.first == '-d'

    WorldGen.new(40, 3000, 3000)
    @ship = Ship.create(x: 3000/2, y: 3000/2, zorder: 100, world: [0,3000,0,3000])#x-left, x-right, y-, y

    @fps = Chingu::Text.new('', x: 10, y: 10)
    @ship_location = Chingu::Text.new('', x: 10, y: 30)
    @ship_boost    = Chingu::Text.new('', x: 10, y: 60)
    @instructions  = Chingu::Text.new('(U)pgrade Ship, (Enter) Explore Planet, (M)anage all Planets.', x: 10, y: 90)
    @debug_text   = Chingu::Text.new("", x:10, y: 100)

    @minimap = MiniMap.new

    @planet_check = 0

    viewport.lag  = 0.22
    viewport.game_area = [0, 0, 1000*3, 1000*3]
  end

  def draw
    super
    @fps.draw
    @ship_location.draw
    @ship_boost.draw
    @instructions.draw
    @minimap.draw
    @debug_text.draw
  end

  def update
    super
    MiniMap.all.first.update
    @debug_text.text = "A:#{@ship.acceleration};\nV:#{@ship.velocity};"
    @fps.text = "FPS: #{$window.fps}"
    @ship_location.text = "X: #{@ship.x}\nY: #{@ship.y}"
    @ship_boost.text = "Boost: #{@ship.boost}"
    self.viewport.center_around(@ship)

    planet_check
    key_check
  end

  def needs_cursor?
    true
  end

  def planet_check
    if @planet_check >= 3
      Planet.each_collision(Planet) do |one, two|
        two.destroy
        Planet.create(x: rand($window.width), y: rand($window.height), zorder: 0) unless $window.fps < 30
      end

    end

    Planet.each_bounding_circle_collision(Ship.all.first) do |planet, ship|
      if button_down?(Gosu::KbEnter) or button_down?(Gosu::KbReturn)
        push_game_state(PlanetView.new(planet: planet))
      end
    end

    @planet_check += 1
  end

  def key_check
    if button_down?(Gosu::KbEscape)
      close
      exit
    end

    if button_down?(Gosu::KbU)
      push_game_state(UpgradeShip)
    end

    if button_down?(Gosu::KbM)
      # push_game_state(UpgradeShip)
    end
  end

  def button_down?(id)
    $window.button_down?(id)
  end
end
bil-bas commented 10 years ago

Do not use dynamic Chingu::Text (that is, text that is often changed) along with TexPlay. Every time you change the text, it will create an entirely new image, which tends to clog things up. You should use Gosu::Font#draw for text that changes a lot, since that just renders the characters directly onto the window, rather than creating an image to put it in. Chingu::Text is fine for

Of course, I don't understand why it is faster without Releasy, but it this is a problem I've had before with dynamic Chingu::Text used alongside TexPlay.

cyberarm commented 10 years ago

Worked! replaced my usage of Chingu::Text with:

class Text
  attr_accessor :text
  def initialize(text, options={})
    @textobject = Gosu::Font.new($window, "./fonts/Alfphabet-IV.ttf", 13)
    @text = text || ""
    @x = options[:x] || 0
    @y = options[:y] || 0
    @z = options[:z] || 0
  end

  def draw
    @textobject.draw(@text, @x, @y, @z)
  end
end

Am now getting 62 FPS average. :)