Keep in mind while reading that I'm doing this to challenge myself.
Alright while I wait for the new Graphics API comming out I'm faking perspective on the CPU with Ruby which is really really slow as it seems. My minimum platform are also pretty slow so it kinda backfires on me.
Here is what I am currently doing:
And the framerate of 600 FPS is what I've reached after micro optimizing the shit out of my perspective algorithm. And I'm out of ideas on what I can improve more. If I comment out the update on my tiles I will reach up to something about ~1300 FPS(I'm still looping trough them).
I want to see if someone else might find what I can improve in order to not have such a huge performance penalty? Maybe someone can break out parts in the math that's not needed or something I don't know. It's not really a language specific question.
Here's my perspective faking:
class Tile
def update( camera_position )
x_movement_factor = @position.z * ( camera_position.x.to_i - @position.x * Tile::Size ) / Tile::HalfSize
y_movement_factor = @position.z * ( camera_position.y.to_i - @position.y * Tile::Size ) / Tile::HalfSize
x_movement_factor = @max_movement_factor if x_movement_factor > @max_movement_factor
x_movement_factor = @min_movement_factor if x_movement_factor < @min_movement_factor
y_movement_factor = @max_movement_factor if y_movement_factor > @max_movement_factor
y_movement_factor = @min_movement_factor if y_movement_factor < @min_movement_factor
@sprite_origin.x = HalfSize + x_movement_factor
@sprite_origin.y = HalfSize + y_movement_factor
@sprite.origin = @sprite_origin
x_scale_factor = 1.0
y_scale_factor = 1.0
if @max_movement_factor != 0
depth_factor = 1 + @position.z * 0.25
x_scale_factor = depth_factor + x_movement_factor.abs / @max_movement_factor.to_f
y_scale_factor = depth_factor + y_movement_factor.abs / @max_movement_factor.to_f
end
@sprite_scale.x = x_scale_factor
@sprite_scale.y = y_scale_factor
@sprite.scale = @sprite_scale
end
end
Of course when the support for Vertex Shaders come this won't be a problem but would still be nice to have some ideas on how to maybe optimize other areas in Ruby more.
Any ideas you have can come in handy. Any idea you have that can make math calculations in Ruby faster is a plus.