Sign in to follow this  

Using Relational DB on non-MMORPG games

This topic is 2665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys.

Working on my game i found that my Data Information ( Pg, Enemy, Items and so on ) it's a real mess!!

I'm using c/c++ and every time i need a table i have to wrote a new class. For example if i need a new table for my db like a Car i'll wrote this.

class Car
{
public:
int speed;
int acceleration;
.....
}

Then when the game is initialized i read from an xml file ( Car.xml ) all car tuples. ( So i have to wrote the loadFromXml method for every table ).
If i want to do a specific query i have to create a new method everytime.

I was thinking to use something like sqllite and move all my table structure from code to a real DB but i don't know if this is a good idea ( speaking of performance and other aspects ) . How others engines manage these stuffs ? (For example UE3). Any suggestions ?

Thanks :D

Share this post


Link to post
Share on other sites
Quote:
Original post by st4lk3r
I'm using c/c++ and every time i need a table i have to wrote a new class. For example if i need a new table for my db like a Car i'll wrote this.

This could be automated by writing a script that converts a SQL table dump into a C++ class, including xml-reading methods for that class. Alternately, you could use Google protobuf instead. Another option would be to dump C++ and go with a language that offers reflection - that would allow you to write a single toXML funcion that can operate on any object you throw at it.

Personally, I'd use JSON instead of XML - it's less heavy, and can easily be mapped to dictionaries and arrays, which makes it a pretty natural way to represent objects and object hierarchies.

Share this post


Link to post
Share on other sites
I think you'd want to load your objects at the start of the game, level, or save, and not for every access. Since that's true, speed doesn't matter as much. I don't think that using SQL is going to save any code over XML. XML has the advantage that as long as you plan ahead, it may be easier to upgrade, and let someone running 1.5.7 load the data from a 1.1. save game. I like XML because I can read and edit it by hand and it has a flexible format, so I can skip fields easily, etc. XML can also help promote a modding community since they don't need special tools. The downside is that it takes up a lot more room on disk. In the end, I don't think it matters much. Use the one you're most comfortable with and plan ahead by figuring out how you're going to do versioning.

Ralph

Share this post


Link to post
Share on other sites
See if your XML library supports serialization. Any decent one should I think. Serialization enables you to save/load any number of objects directly to/from file. No need for line-by-line manual parsing and no need to change your save and load functions when object member variables change.

Share this post


Link to post
Share on other sites

This topic is 2665 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this