While I’ve been brushing up on the finer points of C++ before I start this endeavor, I’ve been putting some time into researching some architecture and design paterns I could use in this wingdom server. I already have a version of this server in c# from when I put down wingdom, but now is the best time if any to make some improvements to it, not to mention some things I’m not exactly sure how to transfer to C++. Two major things I looked into today were large static variables and the underlining network architecture that is multithreaded.
Multithreaded Network Architecture
Things were pretty easy in c#. It had the TCP Client, and that was all I ever needed. (Note, I did and continue to want to use TCP over UDP. This may change when I need the extra speed later, but I’m comfortable with sacrificing speed for packet delivery reliability.) Now with C++, I really don’t have that luxury. Furthermore I was spawning off a separate thread for each client that connected to the server which I learned today, although not completely surprising, does not scale horribly well. After some searching I came across Boost, or more specifically the sub-package Boost.Asio that does the networking/threading/etc for me. It looks to be using thread pooling instead of a separate thread for each client, which should help a whole lot with efficiency. While I’d love to have something like this done with my own code, it’s silly to get held up here re-inventing the wheel when it has already been done for me, so I’m going to be looking into the boost documentation more in the coming days to see where I can use it even more.
Large Static Variables
Previously in the c# server (and even the current client) I was using a large static class that had multiple static variables to contain all information that I needed to access in one spot in memory. This is of course a terrible idea, if not soley for breaking OOP so badly. At the moment I still want to have all the information in one object for all client communication/server processes have the same copy of the data, but I am going to go for a more OOP approach. I’m going to go with what I’ve found called Inversion of Control. I’ll be basically creating an instance of a struct (note, not class) at the beginning of the program. Then in the constructor of all objects that need access, I’ll pass a pointer to this global data object. This way I’ll preserve OOP as much as possible, while still having the desired effect I had before.