Posted by
| David Haley
USA (3,881 posts) bio
|
Message
| SMAUG-style files are evil, error-prone and all sorts of bad things. I would stay away if at all possible. Still, if you *are* going to do plain-text, there are much smarter ways of doing it than SMAUG's approach.
I tried using a database (BerkeleyDBXML) and it wasn't the best experience. One major problem was that it was very sensitive to being opened and closed correctly, so if the MUD crashed, it got extremely upset and had to be massaged back into working again.
XML is good, although a bit verbose at times. Nick uses it for his TinyMudServer, I believe. Still, it is not nearly as good as the next option.
Lua is what we're starting to use on BabbleMUD. I also just implemented a questing system on Darkstone that uses a Lua backend.
There are several advantages to Lua:
- You don't have to write any code to do the actual loading of the data. You just run the datafile through the interpreter, and you've got it all in memory.
- You have to do very little work saving the data. Nick has for instance written a serialization routine that is on these forums somewhere. There are plenty of more-or-less elaborate serialization libraries out there, e.g. Pluto, a heavyweight champion of sorts.
- The data files are relatively easy to read by a human. Not harder than XML, in any case.
- Unlike XML, your data is typed, which helps to avoid continuous conversions back and forth. (You do however have to convert back and forth between Lua's types and yours. Still, it's not as bad as having to convert strings to/from numbers all the time.
- Lua is F-A-S-T.
- Using Lua for data opens the possibility of writing Lua scripts to act directly upon that data.
Once you've read the Lua data table into memory, you can do one of two things:
- Convert the entire structure to a C/C++ structure. This is practical for very small structures (it's what I'm doing for the quest system), but gets a little unwieldy for larger tables. The advantage is that your C code simply talks C to access its data, once it has been loaded.
- Access the Lua table, with Lua API calls. You need to do a little more effort to wrap around the Lua table. But you won't take a significant speed hit, again, because Lua is very fast.
I will be writing a forum post sometime soon examining the case study of the questing system, with code and all that. I have not finished the entire system yet, so it should be within a few days to a week or two, homework allowing. |
David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone
http://david.the-haleys.org | top |
|