15.1. Creating a generator
In order to be able to generate names, the name generator needs to be fed proper data. It will then be ready to generate random names defined in the file(s) it is fed. Syllable set parsing is achieved via the following.
Note 1: Each file will be parsed once only. If, for some reason, you would like to parse the same file twice, you will need to destroy the generator first, which will empty the list of parsed files along with erasing all the data retrieved from those files.
Note 2: The generator can be fed data multiple times if you have it in separate files. Just make sure the structure names in them aren't duplicated, otherwise they will be silently ignored.
Note 3: In the C++ version, you are not obliged to specify the random number generator. If you skip it in the function call, the generator will assume you would like to use an instance of the default generator.
static void TCODNamegen::parse (const char * filename, TCODRandom * random = NULL)
void TCOD_namegen_parse (const char * filename, TCOD_random_t random)
namegen_parse (filename, random = 0)
static void TCODNameGenerator::parse(string filename)
static void TCODNameGenerator::parse(string filename, TCODRandom random)
Parameter | Description |
---|---|
filename | The file where the desired syllable set is saved, along with its relative parh, for instance, "data/names.txt". |
random | A random number generator object. Use NULL for the default random number generator |
Example:
TCODNamegen::parse("data/names.txt",TCODRandom::getInstance());
TCODNamegen::parse("data/names2.txt");
TCOD_namegen_parse("data/names.txt",TCOD_random_get_instance());
libtcod.namegen_parse('data/names.txt')
Destroying a generator
To release the resources used by a name generator, you may call:
This will free all memory used by the generator. In order to generate a name again, you have to parse a file again.
static void TCODNamegen::destroy (void)
void TCOD_namegen_destroy (void)
namegen_destroy ()
static void TCODNameGenerator::destroy()