Start Multithreaded and Separated
It's not difficult to rearrange this with native C++ threads.
Spoiler// I assume you have a header file so function order doesn't matter // C++ #include and using statements up here void DX11_Master(//initial variables here) { // Start the game // Set up the game loop // call DX 11 pipeline functions and get info from other major components // Dispatch kernel // Send synchronization signal to other threads } // DX 11 Functions Here void AI_Master(//initial variables here) { // Begin Loop // Probe the "enemies" array/vector in environment data to determine AI routines // Execute routines // Send info back to environment data // Help Physics/Networking // Wait For Sync Signal // Loop } // AI Functions Here void Networking_Master(//initial variables here) { // Contact Server or Set Self Up as Server // Begin Loop // Get Area, Positional Info For Self and Others // Send info back to environment data // Help Physics/AI // Wait For Sync Signal // Loop } // Networking Functions Here void Physics_Master(//initial variables here) { // Begin Loop // Get positional/action/texture/light/etc info from environment data // Run Transform Functions // Send info back to environment data // Help AI/Networking // Wait For Sync Signal // Loop } // Physics Functions Here int main (int argc, char** argv) { // Set up all environmental data for sharing between threads (data to be passed between them) #pragma omp parallel sections { #pragma omp section { // DX 11 Master Control here } #pragma omp section { // Artificial Intelligence Master Control Here } #pragma omp section { // Networking Master Control Here } #pragma omp section { // Physics Master Control Here } } }
The benefit to starting with this template is easy compartmentalization, easy debugging, easy expandability, and it's not overly difficult to optimize or rebalance if one thread is getting bogged down. You can rapidly figure out where in the system you're choking and can find ways to alleviate it.
If you're building a game and you don't start with something similar to this, I blame you for the mediocrity of game programming today.
4 Comments