Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / FPS decreasing gradually
- - By kuehkookies Date 2012-01-28 06:02
This is bothering me since I make a map based on tiles, which drawn in 24x24 pixels size and in original window size viewport (it's 480x360 pixels size). I got 60 fps in first seconds, then it keeps decreasing and ended up in 15 fps, resulting in really SLOW frame rate.
Also, when executing/compiling the scripts, I noticed in Task Manager that my game eats up to almost 100% of my CPU usage. Not only makes my game runs slow, it also makes another apps I opened runs really slow and almost not responding.

I've read about Ruby itself, and some opinions from others which Ruby is a bit slow. But it can't stop me to stay with Ruby.

However, is there some suggestions to cover this problem?
FYI I use Dynabook Satellite 1870, with 1.6GHz Intel Celeron and 512MB of RAM. Pretty old, of course, but this is my only machine I can use for now.
Parent - - By jlnr (dev) Date 2012-01-28 08:05
I have not heard anything about Gosu that would make it slow down over time. Can you post your script or explain what it does?
Parent - - By kuehkookies Date 2012-01-28 08:33
Since it's involving many lines of code, I'll explain it.

When executing my game, it loads all of included scripts and other resources (image and sounds), then the window appeared and it shows its current FPS. It's 60 FPS in first 10 seconds.
After 10 seconds, the frame rate becomes degraded gradually over time and ended up in 15 FPS. It just goes down in every second as long as the window stays on screen. I tried to minimize used resources (removing some unneeded code lines, not using sounds) and no significant result scored.

Libraries currently I used are Gosu and Chingu.

Once I tried to use single huge image instead of several tiles as platform, then I got normal frame rate as expected. However, the frame rate goes decreasing slightly (I got 45 FPS at the lowest peak). I think multiple image usage as tile is the culprit...

P.S.: I still wondering how does 'clip_to' method works.

Thanks for response.
Parent - - By jlnr (dev) Date 2012-01-28 10:40
Are any resources loaded while the game becomes slower and slower? Have you tried inserting some puts statements here and there to observe what the game is doing?

BTW it works like this: clip_to(10, 10, 40, 20) { everything_in_here_is_clipped }
Parent - By kuehkookies Date 2012-01-28 15:47
I don't know exactly, and everything is fine when I checked my applied logic in my script.

But to ensure it's only happened to me, I attach the source to be inspected. Maybe there are some suggestion from you guys about it since I'm new in Ruby especially Gosu (and Chingu) libraries I currently use.
I'm afraid this problem is because of my current machine I use to develop my game.

Thanks in advance.

And about the clip_to method maybe will be useful later :)
Attachment: (234k)
Parent - - By Spooner Date 2012-01-29 17:16 Edited 2012-01-29 17:23
Not sure if this is relevant, but the game creates a new Chingu::Text each and every draw. This generates a completely new Image 60x a second, which is not good for Gosu. Generally I avoid using Chingu::Text for text that updates a lot, since it is rather inefficient in that case, instead using Gosu::Font#draw.

If you still want to use Chingu::Text for this (assuming the score doesn't change too often), you could use it a lot more efficiently by doing something like this:

# in #initialize (only create it once)
@score_label ="0", :x => 12, :y = 5)

# in #update (only update, and thus create a new image, if score actually changes)
@score_label.text = @score.to_s unless @score.to_s == @score_label.text

# in #draw (don't do any processing in #draw)
Parent - By jlnr (dev) Date 2012-01-29 17:19
I am on OS X but the game ran much faster when I kicked the whole line out. I think this may be very related. :)
Parent - By kuehkookies Date 2012-01-30 01:31
So the Text is the culprit...
I replaced the lines with the lines you suggested, and now I get normal FPS as usual.

Thanks for the tips! :D
Parent - By kuehkookies Date 2012-04-05 14:51 Edited 2012-04-17 08:21
Everything ran well before I kick my 'restart' method, which restarting whole game immediately and will be implemented for death condition. It's all okay when I call another YML file (yes, I use some features of Chingu, and still wondering how it works :P ) but when I call the same YML file--in other words, I attempted to recall the same map, I got degraded performance as the first problem with my HUD before.
Is there some tricks or way to use Gosu (especially Chingu) efficiently? And how to make a game restarts without loading its previous state?

I'll put my project into Github so you guys can check'em out and maybe pull tickets for it.

Thanks in advance, sorry if my post confuses you and any help is appreciated so much! :D

EDIT: It's now in Github! Here's my project involving Gosu and Chingu to make things clear:
Feel free to pull issues, by the way :D

EDIT: My bad, I created a cache for all objects and I didn't flush them when I recall ANY GameStates.
Up Topic Gosu / Gosu Exchange / FPS decreasing gradually

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill