How do online games handle creation of new entities? I currently have an EntityFactory class that requires an ID (specifying the entity type). A bunch of subroutines are executed to determine exactly what the entity is and how it should be composed, and then the final function spits out the result.
I see a few potential issues with this system though:
- First of all, it's difficult to add new entity types. I don't like having to go into my game's code in order to change entity behaviour.
- Second, it's impossible to modify the way entities are generated at runtime. It would be nice to have this functionality, especially when testing game mechanics.
- And finally, since all of the information about creating objects is inside my game code, I'm worried about performance becoming an issue when I have a large number of entities that can be created. I use inheritance for entities in the same "class" to reduce the amount of code I need to write, but it's still a lot of code.
I've heard of using JSON to combat some of these issues, but I can't picture how that would work.
If I load all of the JSON data into the game upon starting the server, then I solve the first issue, but not the second and third.
If I only "require" the JSON as I need it and have none of the data in memory, then I solve the second issue as well, but isn't this even worse for performance? I can't imagine this would be better than keeping everything in memory, because I would need to deserialize in realtime.
I could do both, keeping all "current" data about entity initialization in memory, and only deserialize when a change is made to a file. I can't help but feel like there are better options though. For example, if a monster is only spawned once every 100 hours, it doesn't really make sense to me to not have it in a separate file somewhere and only read when necessary.
I guess I can keep data that is needed frequently deserialized at all times and data that isn't required often can be deserialized on request?
If anyone has experience with these topics I'd really appreciate some insight into the matter.