Skip to content
Browse files

using ree under rvm and making fewer surfaces, halve runtime of the s…

…pecs
  • Loading branch information...
1 parent 875d465 commit dbb3b2d38836c3f341832c28ab6d23a401f817b6 @bgoodspeed committed Mar 11, 2011
View
44 do_profile.rb
@@ -0,0 +1,44 @@
+#!/bin/env ruby
+
+# One way of making an object start and stop moving gradually:
+# make user input affect acceleration, not velocity.
+
+require 'rubygems'
+
+require 'perftools'
+require 'ruby-prof'
+
+require 'rubygame'
+require 'json'
+require 'forwardable'
+
+require 'lib/game_settings'
+require 'lib/game_requirements'
+
+g = Game.new
+
+def the_profiled_code(g, iters=100)
+ iters.times { g.step }
+end
+
+
+PerfTools::CpuProfiler.start("perftools.profile") do
+ the_profiled_code(g)
+end
+
+require 'ruby-prof'
+
+# Profile the code
+result = RubyProf.profile do
+ the_profiled_code(g)
+end
+
+
+profile_printers = {RubyProf::GraphPrinter.new(result) => "rubyprof.graph.profile",
+ RubyProf::FlatPrinter.new(result) => "rubyprof.flat.profile",
+ RubyProf::CallTreePrinter.new(result) => "rubyprof.calltree.profile"
+ }
+
+profile_printers.each {|printer, path| printer.print(File.new(path, "w"), 0)}
+
+Rubygame.quit()
View
12 lib/battle/battle_hud.rb
@@ -4,6 +4,8 @@ def initialize(screen, text_rendering_helper, layer, surface_factory=SurfaceFact
@text_rendering_helper = text_rendering_helper
@layer = layer
@surface_factory = surface_factory
+ @sub_surface = @surface_factory.make_surface([10, 10])
+ @surface = @surface_factory.make_surface([500, 50])
end
def map_to_colors(rate)
@@ -26,23 +28,21 @@ def ready_rates(heroes)
end
def build_sub(s,hr,hi,heroes)
- sub = @surface_factory.make_surface([10, 10])
colors = map_to_colors(hr)
ready_colors = map_to_colors(ready_rates(heroes)[hi])
colors.each_with_index do |color, idx|
- fill_in_sub(s, sub, color, hi, idx, ready_colors)
+ fill_in_sub(s, @sub_surface, color, hi, idx, ready_colors)
end
end
def draw(menu_layer_config, game, battle)
heroes = battle.heroes
- s = @surface_factory.make_surface([500, 50])
- s.fill(:green)
+ @surface.fill(:green)
health_rates(heroes).each_with_index do |hr, hi|
- build_sub(s, hr, hi, heroes)
+ build_sub(@surface, hr, hi, heroes)
end
- s.blit(@screen, [40,400])
+ @surface.blit(@screen, [40,400])
end
View
1 lib/palettes/composite_interactable_surface_backed_pallette.rb
@@ -13,6 +13,7 @@ def []=(key, value)
end
def [](key)
+
@backing.each {|k,v|
r = v[key]
return r unless r.nil?
View
5 lib/palettes/interactable_surface_backed_pallette.rb
@@ -4,8 +4,7 @@ class InteractableSurfaceBackedPallette < SurfaceBackedPallette
def [](key)
entry = @pal[key]
return nil if entry.nil?
- s = @surface_factory.make_surface([@tile_x,@tile_y])
- @surface.blit(s, [0,0], [entry.offsets[0] * @tile_x, entry.offsets[1] * @tile_y, @tile_x, @tile_y] )
- ISBPResult.new(s, entry.actionable, self)
+ @surface.blit(@s, [0,0], [entry.offsets[0] * @tile_x, entry.offsets[1] * @tile_y, @tile_x, @tile_y] )
+ ISBPResult.new(@s, entry.actionable, self)
end
end
View
7 lib/palettes/surface_backed_pallette.rb
@@ -8,7 +8,7 @@ def initialize(filename, x, y, pal=nil, surface_factory=SurfaceFactory.new)
@surface = @surface_factory.load_surface(filename)
@tile_x = x
@tile_y = y
-
+ @s = @surface_factory.make_surface([@tile_x, @tile_y])
end
def offsets(key)
@pal[key]
@@ -19,9 +19,8 @@ def [](key)
entry = @pal[key]
offset_x = entry.offsets[0]
offset_y = entry.offsets[1]
- s = @surface_factory.make_surface([@tile_x,@tile_y])
- @surface.blit(s,[0,0], [offset_x * @tile_x, offset_y * @tile_y, @tile_x, @tile_y] )
- SBPResult.new(s, entry.actionable, self)
+ @surface.blit(@s,[0,0], [offset_x * @tile_x, offset_y * @tile_y, @tile_x, @tile_y] )
+ SBPResult.new(@s, entry.actionable, self)
end
end

0 comments on commit dbb3b2d

Please sign in to comment.
Something went wrong with that request. Please try again.