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

The engine is evolving: Online RPG Engine!

Icon 6 Comments
Yup, multiplayer. :)

It's actually quite simple. It's slow for the time being, I've got too much going on in a single loop (it will all be multithreaded in the end) but it's certainly on its way to being a decent (small) online multiplayer rpg engine. (I refuse to say that thing that all 12 year olds want to make)

The concept is simple. When the player moves, their location will be updated on a database. (located on a web server) Periodically, these coordinates are downloaded for all users on the same screen, and they are drawn on. (This is what makes it slow for the time being)

The plan is to process all that information in another thread. Meaning, it won't have any effect on the main game loop, and thus, it won't slow down gameplay as a whole.

To express the simplicity of it (it will obviously become more complex over time) this is how they are downloaded (this is a simple MySQL SELECT statement)

SELECT * FROM users WHERE screen_id = 1 AND user_id != 1

Obviously this isn't hard coded, and the screen & user id are actually called in from the game details. Something like:

ostringstream q;
q << "SELECT * FROM users WHERE screen_id = " << the_map->get_screen_id() << " AND user_id != " << p->get_userid();


I have a demo ready, and I've actually walked around on a map with several other people at the same time, so I know it works. I won't be releasing it to you DIC heads just yet though, there's quite a lot of work to get it done until it's actually good enough to show off completely. (Though I've tested it with a few of my followers on twitter)

Oh, and one more thing...
In a slightly unrelated note, I'm gonna throw a quick tip out there for you MySQL Connector/C users out there. This is an issue I experienced with my code, and it relates to a memory leak. Something that seemed to be missed out in a lot of the examples.

DON'T FORGET TO FREE THAT MYSQL RESULT!

In other words: mysql_free_result(result);!!!

I went from 5mb to 18mb in memory because I didn't do just that. And I spent at least an hour hunting it down.

6 Comments On This Entry

Page 1 of 1

girasquid Icon

13 May 2009 - 11:18 AM
I toyed around with an engine for something like this, but never got much farther than movement and chat - I think I got a job or something, and ended up losing interest.

One piece that I remember putting a lot of thought into was packets and protocols, though - are you using TCP, or UDP?
0

gabehabe Icon

13 May 2009 - 11:27 AM
Haha! Out of curiosity, what did you code it in?

I'll hopefully have a chat window up and running by late this weekend, after getting the core functionality multithreaded.

The MySQL Connector/C API uses a TCP connection, and I was amazed at the similarities between it and PHP. Quick comparison.

C is something like this (might be slightly different, I'm doing this off the top of my head and I didn't focus on MySQL connectivity too much)
MYSQL mysql;
MYSQL_ROW* row;
MYSQL_RES* result;

mysql_init(&mysql, "server", "username", "password", "database", 3306, NULL, 0); // or something like that
mysql_query("SELECT * FROM users", &mysql);
// there's an extra step in C
res = mysql_use_result(&mysql);
while(row = mysql_fetch_row(res)) {
    printf("%s\n", row[0]);
}
mysql_free_result(res);
mysql_close(&mysql);


Now the PHP one, see the similarities? (Note this is slightly shorter)
$con = @mysql_connect("localhost", "username", "password");
@mysql_select_db("database");
$result = @mysql_query("SELECT * FROM users") or die(mysql_error());
while($row = @mysql_fetch_array($result)) {
    echo $row["username"] . "<br />";
}
@mysql_close($con);
0

girasquid Icon

13 May 2009 - 12:40 PM
My server and client were both done in C++, but it's been a long time - I think in the midst of all my computer upgrades, the original source has disappeared.
0

gabehabe Icon

13 May 2009 - 12:45 PM
ooh, gutted. :/

What did you use graphics-wise? You said you made chat, how did you implement that? I've had to create my own textbox class :)
0

modi123_1 Icon

13 May 2009 - 01:07 PM
tsk..tsk.. "SELCT *" is a bad habit! ;)
0

gabehabe Icon

13 May 2009 - 01:09 PM
lol modi, it's still in testing at the moment. ;)
0
Page 1 of 1

November 2014

S M T W T F S
      1
2345678
9101112131415
16171819202122
23 242526272829
30      

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: gabehabe@gmail.com

Google Talk: gabehabe@gmail.com
MSN: gabehabe@hotmail.com
Yahoo: gabehabe (rarely used)
AIM: gabehabe (rarely used)

Skype: gabehabe

Want me to work for you? [click]