Sign in to follow this  

How to initialize a world

Recommended Posts

Hi, I am considering a way to set up my world as follows The world is comprised of many Map classes each Map has Map* exits that points to the Map of the linking area. I'm hoping to do something like character.move(character.currentmap->exit[0]) to move a character to the next map; I'm thinking of recursively initializing linked area with something like
    while (lua_next(L, -2) != 0) {
        /* uses 'key' (at index -2) and 'value' (at index -1) */
        //add your own code to get the key and value
        exits_scrpt[i] = lua_tostring(L, -1);
        cout <<"exits:"<<exits_scrpt[i]<<endl;
        exits = new Map(exits_scrpt[i],i,exits);
        //here I provided an index, the script to load from, and the pointer to the current map to the next one
        /* removes 'value'; keeps 'key' for next iteration */
        lua_pop(L, 1);

and link back to this map using the code in constructor. But then I realized there would be problems when two or more maps link to the same map, in which case, another instance of that map will be created and that is not desired. Do you think this way would work? Or should I just assign an id to a map and use the ids to find the maps to be operated on?

Share this post

Link to post
Share on other sites
Recursive initialization sounds scary, for maps that can link back and forth to eachother in any order. ID values would be a good choice. Or you could do a 2 pass initialization, where the first pass creates all the maps, and the second pass sets the exit pointers. But that usually requires ID values anyway, since you need some way of finding the already-created maps that the current one links to.

Share this post

Link to post
Share on other sites
yeah, that's what I was considering
I think I'll organize all the related maps under an Area struct, and assign IDs within an area

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this