I've been working on an online game, and recently have been working on converting the base of the game to use the Artemis Entity System Framework. I'm having a bit of difficulty conceptualizing exactly how the server networking should be changed to work with this approach.
My original approach was to have each session receive packets, attach session information to them and then push them to a master queue. I then had a seperate thread (let's call it InputHandler) which was responsible for removing packets from the master queue and processing them. During the packet handling, this thread can add packets to be sent to clients to an output queue. I then have another thread (let's call it OutputHandler) read from the output queue and dispatch the packets to the appropriate sessions (for example if a packet needs to be sent to all sessions or a single sesion).
My initial idea when converting to use Artemis was to have yet another thread (WorldProcessor) take care of doing all the entity processing (this is where AI, general logic, automatic saving, etc. would be done). However I realized that I could no longer do things such as adding entities from the InputHandler thread as it could cause concurrency issues.
Would a better idea be to do the world processing in the InputHandler thread? I thought this could maybe be done by having a Networking system which would try to handle as many packets as possible during a given time frame and then pass control to the other sytems. Another approach I considered was having the InputHandler add events to a queue in the WorldProcessor which would then process these events during the system processing, but I feel this is adding another layer of complexity and that there must be a better way.
I was hoping you could give me some insight or some tips on how to go about connecting the networking and the world processor in a thread-safe fashion.