Acknowledging the pros and cons of a Game Maker server
The first step to success in any process is to decide your best course of actions. So why would I use Game Maker to write a server instead of doing it from scratch in C# or another more performance savvy language/engine? Simply because it doesn't make sense to write two completely separate code bases. Collisions, networking, and mod management would have to be emulated in whatever alternative system I choose to use. It is far easier to just copy code from the client and reuse it on the server.
You should never pour extra time into performance gains if it means you will be stretching your own time thin in other places. The server being written in Game Maker does present one major issue which is that the server won't be headless. Luckily my game doesn't have a massive user base expecting headless servers. I'm sure a few people may appreciate it but I've decided to make up for it in other ways. On a side note, at the time of writing YoYoGames has said they may add headless functionality to Game Maker.
Since our server can't utilize the Windows Command Prompt, we will need to create our own server window from scratch. This means we have to setup some basic console functionality and window scaling.
I don't think it's necessary for me to post all my code for these scripts. It's neither exciting nor required for you to understand the overall process. However I will share some of the rendering code as it shows some of the rendering required to make a low cost server.
Now comes the joy of benchmarking the server! Since this is Game Maker we are using we will be able to take advantage of the FPS counter on our debugging tool.
Average FPS: 20,000~
Time Per Frame: 0.057ms (milliseconds)
These are great results! The profiler has helped us pinned down the slowest part of our code, draw_text(). This code runs every time the server window is resized or the cursor blinks. Now for the biggest question yet... should we remove the cursor to improve the servers performance? The answer is simply no. It wouldn't make a significant different in any real usage benchmark.
What about all the networking code?
I don't want to cram everything into a single post so I'm going to try and talk about networking later on when I have it more fleshed out. The starting point is just initializing a server but if we are going to talk about the back and forth communication between the server and client, it would be best to save all that for its own post.
The finished product
Our server is now capable of emulating a command prompt and displaying information. This is all the server code we'll need before we get into networking. It is important to keep your server as light weight as possible. This server (even with mods being loaded upon launch) only uses 7.7mb at peak usage. This leaves us lots of overhead for massive player counts and objects in the world.
Here you can get a glance at how the window scaling behaves. Kind of how you would expect right?