Using Relational DB on non-MMORPG games

Started by
3 comments, last by EJH 13 years, 7 months ago
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
Advertisement
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.
Create-ivity - a game development blog Mouseover for more information.
Which API are you using to treat your XML like a database? It doesn't sound like you're getting the most out of it. Can you provide an example of loadFromXml for a table and a query or two?
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
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.

This topic is closed to new replies.

Advertisement