Large amounts of text

I currently building a point&click game and I will probable need lots of text data (dialogs, explanation about items, etc).

What’s the best practice for handling this?

  • load and store all the text for the current level in arrays
  • load the required text when asked for, realtime

I tried option 2, dialogs stored in xml. But when reading and searching the file for the correct entry, the game pauzes for just a fraction of a second. Not a disaster by all means, but this hickup will grow as the file gets larger.

I’d like to know about better ways to handle large amounts of text to create a fluid and polished game…

Anyone please?

I’m interested in this answer as well :).

Well search times on a harddisk is in the range of 8 - 13 ms and if you want to run your game at minimum 30 fps that means that one frame is 1000/30 = 33 ms long or ~17 ms at 60 fps.

so by loading on demand you will spend a large part of your entire frametime just searching for the file you want to read from not to mention reading it and finding the string you need.

I would strongly recomend reading the file at level load time and storing the strings there.

If you absolutly want to load them on demand I would load the string in an async operation as this will not stop your game loop from running.

//perlohmann

alternatively for iphone / standalone, consider using something like SQLite which give you the possibility to save time in maintain, load and store, given you can store them in a structured way

As long as the database is loaded “permanently” into memory at some point that is also a good option.

On the iphone though you have flash memory which does not have as long search times as a normal harddisk so reading directly from file might have a smaller impact there.

//perlohmann

I’ll try to load all dialogs etc at loadtime to get rid of the hickups caused by loading a file.

The SQLite option seems a nice option too, maybe I’ll try it too some day :slight_smile:

Just a little curious, how would games like mass effect and other rpg’s handle this problem? I can’t imagine them loading all the text (and audio) at loadtime. That’s when threading comes in handy I presume…

they normally use some kind of “database” but not relational databases as they don’t need to search for freeform data.

if you know what you search for (unique ID), then you can create a sequential file database and write the byte offset from start at the position 4*id

that way you can use direct file lookups, even from memory cached versions.

they are easy to maintain and use too, which makes them a very good thing if you know that you will never look for random data.