Not logged inGosu Forums
Forum back to Help Search Register Login
Up Forum
Topic [Texplay] Ruby GC make the game freeze when using Texplay By Gavos Date 2010-03-01 18:31
Thanks for your feedback erisdiscord, I had not caught this one and it is now fixed :-)

We (my wife and myself) will probably present the game in the Showcase section when we will consider it to be finished, but if you want you can still try the version we published for the contest here:
Topic [Texplay] Ruby GC make the game freeze when using Texplay By Gavos Date 2010-02-28 15:16
Hey, your "slight speedup" did the trick!

I am running on a quite old machine (Athlon XP 2000, 6 years old), which might be the reason why I notice the freezes so much. But with your code it is actually *much* smoother. I also tried it with the GC disabled and the memory increase is very slow now, pretty much the same as if I was not using Texplay, I think that confirms that the problem was coming from the way I used the lib. I am quite a beginner with Ruby so I am not very aware of the cost of creating a block object a running _eval.

Thanks a lot! I can get back to working on a better gameplay, now :-)
Topic [Texplay] Ruby GC make the game freeze when using Texplay By Gavos Date 2010-02-28 13:28
Sure, you can get the "game" here:

We have not managed to make it interesting yet (still need some time). The goal is to cover the biggest surface on the screen. Right-click to create a "stain" anywhere, left-click to create on your on color.

The garbage collector is enabled by default. Just create a few stains in a row and you will notice the small freeze, like the stains pausing their progression and then resuming (it happens at last least once a second, actually). I forgot to say that I am running on Windows, maybe the GC perfoms a very different way on this platform?

The code responsible for the graphics part is in window.rb, and here are a few keystrokes we created for testing:

'E' -> enable garbage collector
'D' -> disable garbage collector

'C' -> clear the screen
'Esc' -> quit the game

'O' -> select round stain
'X' -> select cross shaped stain
'R' -> select red color
'B' -> select blue color
Topic [Texplay] Ruby GC make the game freeze when using Texplay By Gavos Date 2010-02-28 04:59
Hi everyone,

As people advised me to do in, I switched to Texplay for building a single image that is getting drawn to the screen. The performance is very good, except... when Ruby's garbage collector enter the scene!

Everytime it is called it makes a small (but very noticeable) freeze of about 100 ms. The GC seems to be run quite often (once every 2 seconds maybe) and I suppose it comes from the use I make of Texplay. The reason for that is that when I disable the GC ("GC.disable") there is no more freeze but my program reaches the gig in 1 minute, but if I disable the use of Texplay the memory consumption increases much slower (but maybe it is not a good clue as to whether Texplay is the one who makes the GC run that often?)

Now, I would like to know if there is a better way to use Texplay that would not be so memory consuming. Here is what I am doing:

It is quite simple, I read a list of squares to draw and I call "rect" on the picture on each one of them. But it could be done differently maybe? Or I could play with the cache? And if not, does anyone knows any good tricks to "smooth" the garbage collector? But to be honest, I cannot think of any good time to run it manually (if I could) because the game can be continuous, that is without any pause.

Thanks in advance for your answers!
Topic [ruby/optim] How to update the modified sprites only? By Gavos Date 2010-02-26 22:09
Thanks a million to all of you, this lib is great! And even better, it does not bloat my code at all! And even *more* better, I can decrease the size of my squares!

The proof:

If the result happens to be interesting (not quite sure yet, it is kind of an experiment), I will add it to the Showcase forum :-)

Thanks again!
Topic [ruby/optim] How to update the modified sprites only? By Gavos Date 2010-02-26 02:18
Hi everyone,

As part of a 9-day game development contest (finishing the 28th), I am creating a game (with RubyGosu) that simulates a battle between two swarms of microbs trying to conquier a Petri dish. You can get an idea here:

Now I am running into problems with performance. On this screenshot the battle is far from finished, a Petri dish full of microbs would run around 15 FPS. And there is no gameplay logic (on this screenshot) or AI neither...

The way I implemented this was as follow:
- loop through the list of colour squares that are on the field
- draw every square using Gosu::Image.draw

The field is 800x600 large and the squares are 8-pixel large, so I might have to draw up to 7500 images per frame... You can find the code responsible for the graphics here:

What I would like to do is:
- loop through the list of colour squares that have been updated at this turn
- only draw those squares on top of the existing screen

Is there any way to do that with Gosu? I am aware of what that technique involves when using double (triple?) buffering but I am kind of desperate, I do not have any other idea for optimisation now. I know it would reduce the number of squares to draw enough to stay over 40 FPS (without game logic / AI). If you think of any other way to optimise that would be great as well :-)  I have started programming in Ruby at the beginning of this week (I am more of a C++ programmer), so there might be obvious ruby-ish optimisations left to do.

There is nothing to win in the contest but I would be disapointed to publish a game that is hardly playable...

Thanks a lot for your answers :-)

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill