Original Post
Hi,
I've been writing a simple 2D RPG in C++ and I'm gettnig a bit stuck again on how to organise certain things.
Firstly I have a question about RPG's typically handle what happens when a player moves from one area to the next. Is the area they are leaving kept in memory in any form? At first I thought they couldn't be, since surely you would simply run out of memory as the player keeps playing. But if the area is no longer in memory then it can't be updated and this could cause some problems.
Say for example an enemy wizard casts a defensive buff and an enterprising player decides to run to another area while it's duration runs out. Or say the player is being pursued and runs to another area, in a case where there's no reason why he couldn't be followed. It seems like I would need to keep track of what's going on in the other area. Or maybe not, I've thought that it's possible I could handle all these cases by having some special logic when areas are opened and closed, e.g I could examine all temporary spell effects and increment their durations by the time passed since the area was closed. And perhaps do things like randomise the positions of wandering creatures to make things look more dynamic. I can't quite figure out if all cases can be handled like this.
Could the alternative of keeping the area in memory work? I could release any resources needed to render the area, and reduce the frequency of AI updates, forget about collision detection and so on. And then perhaps organise my areas into sets based on the travel time between them, so areas can be closed when the player moves from one set to another.
When an area does have to be closed I plan to serialize it to the players save game folder, so in future my resource cache for area files will look there first for a modified file and load it if it exists. I don't think it's worth trying to split my area class into it's static and dynamic components and only saving the latter, since I think the latter dominate in terms of size.
As well as this issue of static and dynamic I have a general problem thinking about initialisation and serialisation. My game entities need access to a lot of resources and systems, stuff to do with scripts, sprites and sounds etc. I do this by dependency injection when the entities are constructed. Also the objects themselves need to be registered with a manager type class and assigned an ID as they are created. All of this works fine when creating a new object but seems to be awkard when loading them, particularly if you want to keep your loading and saving methods symmetric, which is very easy with boost serialization.
I've thought about splitting my entities into two, so I have say a CreatureProperties class which stores all the serializable state information about a creature, and a Creature class which inherits from Entity and deals with the dynamic and game logic aspects. A container of properties is serialized with the area file and the entities are created and registered etc when the area is initialised. Does this seem reasonable/necessary?
Appreciate any thoughts.
I've been writing a simple 2D RPG in C++ and I'm gettnig a bit stuck again on how to organise certain things.
Firstly I have a question about RPG's typically handle what happens when a player moves from one area to the next. Is the area they are leaving kept in memory in any form? At first I thought they couldn't be, since surely you would simply run out of memory as the player keeps playing. But if the area is no longer in memory then it can't be updated and this could cause some problems.
Say for example an enemy wizard casts a defensive buff and an enterprising player decides to run to another area while it's duration runs out. Or say the player is being pursued and runs to another area, in a case where there's no reason why he couldn't be followed. It seems like I would need to keep track of what's going on in the other area. Or maybe not, I've thought that it's possible I could handle all these cases by having some special logic when areas are opened and closed, e.g I could examine all temporary spell effects and increment their durations by the time passed since the area was closed. And perhaps do things like randomise the positions of wandering creatures to make things look more dynamic. I can't quite figure out if all cases can be handled like this.
Could the alternative of keeping the area in memory work? I could release any resources needed to render the area, and reduce the frequency of AI updates, forget about collision detection and so on. And then perhaps organise my areas into sets based on the travel time between them, so areas can be closed when the player moves from one set to another.
When an area does have to be closed I plan to serialize it to the players save game folder, so in future my resource cache for area files will look there first for a modified file and load it if it exists. I don't think it's worth trying to split my area class into it's static and dynamic components and only saving the latter, since I think the latter dominate in terms of size.
As well as this issue of static and dynamic I have a general problem thinking about initialisation and serialisation. My game entities need access to a lot of resources and systems, stuff to do with scripts, sprites and sounds etc. I do this by dependency injection when the entities are constructed. Also the objects themselves need to be registered with a manager type class and assigned an ID as they are created. All of this works fine when creating a new object but seems to be awkard when loading them, particularly if you want to keep your loading and saving methods symmetric, which is very easy with boost serialization.
I've thought about splitting my entities into two, so I have say a CreatureProperties class which stores all the serializable state information about a creature, and a Creature class which inherits from Entity and deals with the dynamic and game logic aspects. A container of properties is serialized with the area file and the entities are created and registered etc when the area is initialised. Does this seem reasonable/necessary?
Appreciate any thoughts.