Subscribe to gabehabe's on-topic ramblings        RSS Feed
-----

Multithreading the Game Engine!

Icon Leave Comment
So, I finally got around to putting the server communication stuff in a different thread. :)

Main also got a little longer! And I've made my game wrapper slightly more detailed, so now you can add maps from main (I was still adding them direct from within the class while I was testing it)

{side note: FUCK, got a memory leak} :(
Probably related to the MySQL in some way, it will be sorted.
<edit>heh, got it. My bad, I forgot to call SDL_FreeSurface somewhere.</edit>

So, while I sort that out, why not check out the usage of the engine?

It's slightly longer, mostly due to the map creation in there, and there's a few new lines thrown in, such as creating the thread.

#include "game.h"

int do_mysql(void* foo);

// must be global for the sake of accessing in the thread
game* the_game;
SDL_Surface* players;

int main(int argc, char *argv[]) {
    players = SDL_CreateRGBSurface(SDL_SWSURFACE, SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH, RMASK, GMASK, BMASK, AMASK);

    the_game = new game(players);

    map* m1 = new map(1, the_game->get_screen());
    m1->set_player_location(180,220);
    m1->set_map(IMG_Load(".\\img\\map.png"));
    m1->add_object(new object(the_game->get_screen(), ".\\img\\tile1.png", 30, 30, 25, 25));
    m1->add_object(new object(the_game->get_screen(), ".\\img\\tile1.png", 10, 250, 25, 5));
    m1->add_object(new object(the_game->get_screen(), ".\\img\\tile2.png", 180, 150, 25, 25, NOTHING, &found_potion));

    map* m2 = new map(2,the_game->get_screen());
    m2->set_map(IMG_Load(".\\img\\map2.png"));
    m2->set_player_location(145,227);
    m2->add_exit(new exit(".\\img\\tile3.png", 120, 240, 25, 25, m1));
    m1->add_exit(new exit(".\\img\\tile3.png", 180, 210, 25, 25, m2));


    the_game->add_map(m1);
    the_game->add_map(m2);

    the_game->do_intro();
    SDL_CreateThread(&do_mysql, NULL);

    the_game->do_main();

    return EXIT_SUCCESS;
} 

0 Comments On This Entry

 

December 2017

S M T W T F S
     12
3456789
101112131415 16
17181920212223
24252627282930
31      

Request A Topic!

Want me to blog about something? Perhaps a language? A piece of software? A specific topic? Let me know! Even guests can post here on my blog!

If you would like to request a topic, please post a comment here and I'll get on it right away! smile.gif

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)

gabehabe's off-topic ramblings

Follow me on Twitter!
lol, my other blog died a horrible lonely death. Ah well.

Smiley of the [however often I change it]

IPB Image

Contact Me

e-mail: [email protected]

Google Talk: [email protected]
MSN: [email protected]
Yahoo: gabehabe (rarely used)
AIM: gabehabe (rarely used)

Skype: gabehabe

Want me to work for you? [click]