Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Conway's game of life  (Read 4881 times)

0 Members and 1 Guest are viewing this topic.

Neomex

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Conway's game of life
« on: January 02, 2012, 03:27:45 pm »
Here's my result of few days of learning sfml :)



My 'framework' took me 3 days to look like a framework :D
and game itself one day.

I've started with rendering grid and cells using primitives, but it was definitely bad idea, now grid and cells are just sprites, whereas I noticed, that filling image with color in-code, gives ~20fps performance for me.

Without any cells shown it runs with 900fps, with 100 cels about 260 fps.

I'm quite sad with sfml (1.6) rendering speed, maybe just my code is wrong, but for now showing for example many tiles is just impossible.

I'll probably extend this 'game' as a part of learning openGL :)

LMB - set cell talive
RMB - set cell dead
G - toggle grid
P - pause/unpause simulation
+/- change speed of simulation

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Conway's game of life
« Reply #1 on: January 02, 2012, 03:35:58 pm »
Some tiles are definitely no problem for SFML, even if performances have been further improved in SFML 2.

Do you manipulate sf::Image objects every frame?
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Neomex

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Conway's game of life
« Reply #2 on: January 02, 2012, 04:44:53 pm »
No, I simply apply single image for single sprite at initialisation point:
Code: [Select]
imgBlueLifeForm.Create( 16, 16, sf::Color::Blue );
BlueLifeForm.SetImage( imgBlueLifeForm );

and draw it this way:
Code: [Select]

for( int i = 0 ; i < 64 ; i ++ )
{
for( int j = 0 ; j < 48 ; j ++ )
{
if( isAlive[i][j] == true )
{
BlueLifeForm.SetPosition( i * GridSpacing, j * GridSpacing );
AppWindow.Draw( BlueLifeForm );
}
}
}

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Conway's game of life
« Reply #3 on: January 02, 2012, 05:26:07 pm »
Okay, that shouldn't be too slow. Did you already try SFML 2?

And if your images consist of a single color, you might also consider to use sf::Shape instead of sf::Sprite.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Neomex

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Conway's game of life
« Reply #4 on: January 02, 2012, 09:02:28 pm »
Haven't yet, waiting for it to be released, I'll play some more time with 1.6 and eventually move then :)

Also yes, tried with shapes, but it was 2x slower.

Does it create new object with every call?

Code: [Select]
AppWindow.Draw( sf::Shape::Rectangle( i * GridSpacing, j * GridSpacing, i * GridSpacing + GridSpacing, j * GridSpacing+ GridSpacing, sf::Color( 0, 0, 255 ), 0, sf::Color::Black ) );


To be honest didn't though about it before.