Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The main key is to make sure your game logic is not affected by your threading model.</p> <p>As such, most game servers look something like this:</p> <pre><code>main() { gGlobalReadOnlyStuff = LoadReadOnlyStuff(); SpawnThreads(numCores); // could be another limiting resource... WaitForThreadsToBeReadyToGo(); while(1) { WaitForNetworkInput(networkInput); switch(networkInput.msg) { case ADMIN_THING: // start/stop websever, dump logs, whatever... DoAdminThing(networkInput.params); break; case SPAWN_GAME: // replace 'game' with 'zone' or 'instance' as needed idThread = ChooseBestThread(); // round robin, random, etc PostStartGameMessageToThread(idThread, networkInput.msg); break; // ... } } } void ThreadUpdate() { threadLocalStuff = LoadThreadLocalStuff(); SignalThreadIsReadyToGo(); while(1) { lock(myThreadsMessageQueue); // copy messages to keep lock short localMessageQueue = threadsMessageQueue; unlock(myThreadsMessageQueue); foreach(message in localMessageQueue) { switch(message.msg) { case SPAWN_GAME: threadLocalStuff.games.MakeNewGame(message.params)); break; case ADMIN_THING__LET_EVERYONE_KNOW_ABOUT_SERVER_RESET: ...; break; // etc... } } foreach(game in threadLocalStuff.games) { game.Update(); // game will handle its own network communication } } </code></pre> <p>The two hard things then are 'coming up with a partition (game, zone, instance, whatever) appropriate for you game' and 'transitioning things (players, fireballs, epic lootz) across those boundaries' One typical answer is "serialize it through a database", but you could use sockets/messages/files/whatever. But yeah, where and how to make these partitions and minimizing what can go across the boundaries is intimately tied to your game design.</p> <p>(And yes, depending on your setup, there are possibly a few 'shared' systems (logging, memory) that may need a multithreading treatment(or even better, just have one logger/heap per thread))</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload