So for practice and as a learning exercise i foolishly decided to make a text based rpg on my phone using the c4droid ide. ive done well and have learned a lot.

So far you can create a new character or load the previous one. and you can walk around in the rooms ive made. currently the rooms load from a file when you enter it, and then it loads again every time you do anything except leave,which loads the next room instead. ill be tweaking my gameloop so it doesnt reload the room everytime soon.

so the basic question is this: leave loading the rooms the eay it is, load them all at the beginning of the game, or something else?

all help is appreciated

• std::vector is basically an array encapsulated in an object-oriented wrapper. – Philipp Jul 6 '18 at 14:06
• Careful with Vectors in C++, as you could be talking about the std::vector as mentioned above, or be talking about directional vectors such as Vector3D in the DirectX framework and similar. – blurry Jul 6 '18 at 15:21

To add to other answers, we don't really know how many rooms you have (or plan to), so loading every room in the beginning might work, but not in all cases.

As a text-based game however, you can still keep track of all spawned enemies, something like this:

• Move to a new room, load it
• Enemy is in the room (based on the room file), check if that enemy has already spawned (exists) in the "enemy array"
• if not, spawn a new enemy, and add its instance to the enemy array.
• if yes, do not load that enemy again, as its most likely wondering around the map.

Now every time you visit a new room, keep in memory the previous room (that the enemy is in) so that it can navigate through the room to find you. If you move too many rooms away, maybe you can despawn the enemy (unload and remove from enemy array) or you can keep all previous rooms in memory, until the enemy navigates past them. It all depends on how you want enemies to behave.

Since you are using C++, the best choice is a std::vector, as mentioned in the comments as well.

The details really are up to you to decide, as its implementation will slightly change the enemy's behaviour (if you want it to respawn, or chase you indefinitely etc etc). Also, I'm not sure what's the size of the "map" that contains all the rooms, but if you have divined your game in stages, or something that can make you "progress" to another set of rooms (like ascending, descending floor), you can load all rooms of that stage in the memory, and spawn all enemies the moment you appear there. Assuming that your gave mimics the appearance of rogue-like games, it shouldn't be intensive at all memory-wise.

You didn't post any numbers regarding the RAM usage of your game, but reading between the lines I get the impression that your game is still far too simple to require so much memory that you can't load all the rooms at game startup and then keep their state in memory while the game is running.

But if you want to keep your architecture where you load every room from the filesystem when you enter it and unload it when you leave it, then you could add a second "change file" for each room. This file represents the state of any changing properties of the room (like the status of any mobs in it). After you loaded the room file, check if there is a change file for that room and when you have one, load it and apply the changes to the room data you just loaded. When these properties change, write a change file for that room with those changes.

And by the way, you now have a working savegame system.

I'm looking forward to playing your game.

• thanks! ill share it somewhere for folks to try it out when it gets to a playable point. – Richard Carpenter Jul 7 '18 at 0:16