How do on-line video games deal with creation of latest entities? I presently have an EntityFactory class that requires an ID (specifying the entity kind). A bunch of subroutines are executed to find out precisely what the entity is and the way it ought to be composed, after which the ultimate perform spits out the end result.
I see a number of potential points with this method although:
- Initially, it is tough so as to add new entity varieties. I do not like having to enter my recreation’s code in an effort to change entity behaviour.
- Second, it is unimaginable to switch the best way entities are generated at runtime. It might be good to have this performance, particularly when testing recreation mechanics.
- And eventually, since all the details about creating objects is inside my recreation code, I am apprehensive about efficiency changing into a difficulty when I’ve numerous entities that may be created. I take advantage of inheritance for entities in the identical “class” to scale back the quantity of code I would like to jot down, nevertheless it’s nonetheless a variety of code.
I’ve heard of utilizing JSON to fight a few of these points, however I can not image how that will work.
If I load all the JSON knowledge into the sport upon beginning the server, then I clear up the primary problem, however not the second and third.
If I solely “require” the JSON as I would like it and have not one of the knowledge in reminiscence, then I clear up the second problem as nicely, however is not this even worse for efficiency? I can not think about this may be higher than retaining every part in reminiscence, as a result of I would wish to deserialize in realtime.
I might do each, retaining all “present” knowledge about entity initialization in reminiscence, and solely deserialize when a change is made to a file. I can not assist however really feel like there are higher choices although. For instance, if a monster is just spawned as soon as each 100 hours, it does not actually make sense to me to not have it in a separate file someplace and solely learn when needed.
I suppose I can hold knowledge that’s wanted steadily deserialized always and knowledge that is not required typically may be deserialized on request?
If anybody has expertise with these matters I might actually recognize some perception into the matter.