Organizing large amounts of information in game

  • Currently I'm working with a game engine which uses Xml files initially. From the Xml files it's supposed to make a hierarchy of the game elements, like textures, models, music, sounds and scenes. The hierarchy is supposed to contain information on each element, like the file for a texture or the volume for a certain piece of music.
    An element in the hierarchy would be called "actors/npcs/npc001", and when needed, another part of the program will be able to get the required information about this actor, like model, texture and a file to describe interaction.
    Currently, the program is able to output the information it gets from a QDomDocument, so I need a place to put it, basically.

    What is the suggested way of achieving this or anything similar..?
    I'm sorry if I haven't supplied a sufficient amount of information on what I'm requesting.

  • I'm afraid it's not quite clear what the problem is. Is it creating the XML files? Managing the XML files? Reading them? Or the concept how to write a node-hierarchy to an XML file?

  • Would XML file be to store startup information or for processing too during gameplay ?

  • I'd recommend against using XML for these kinds of applications. XML has a big overhead, both in terms of parsing and in terms of file size. It has very useful applications, but it is not the one-size-fits-all storage solution.

    Just define your own custom data structure instead that is optimized for your use case, and (de-) serialize that to your storage instead.

  • XML files would be for storing it in the filesystem only. Reading them all the time would be inefficient. They're loaded into memory when the program starts. These are as mentioned assets for a game, like single models, textures, sprites etc which have a set of values attached to them. With these I want to put them in a hierarchy (in memory) where I can retrieve the values from them for use in the game at runtime on request, and therefore it should search and retrieve values quickly. These values won't be modified during gameplay.
    I'm not sure if I have any other explanation than this as to what I'm attempting to do.

    Also, since the time I posted this thread I found QMap, which seems to be what I've been looking for. SQL seems to require making a file, which isn't optimal for this use. (It also seems like it is a tad bit out of my league to deal with.)
    It adds the keys and values quickly and also retrieves them quickly.

    The only problem I'm having with QMap is retrieving a single key's value, but I don't find the documentation to be sufficient at explaining how to do it.

    Andre, I find it hard to ditch XML at the moment now that I've gotten to know how to use it within Qt. For now, I'll keep it because it works. I might end up ditching it later in development, but I won't at this moment.
    XML works very nicely because of attributes and being organized in a hierarchy from the start, where it's easy to find all the values. Also, it is aimed at being easy to understand and to modify.

  • Actually, you can use SQL in-memory. SQLite is able to work with in-memory databases. Still, perhaps SQL is not the interface best suited for what you want...

    Again: I'd just create your own data structure. It can internally use QMap, QHash (prefer this over QMap if you can!), QVector (prefer over QList if you can!) etc., but it would keep your API sane and the resulting code readable, and it would allow items to point to each other.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.