Jump to content
  • entries
    2
  • comments
    4
  • views
    943

Start Multithreaded and Separated

patrickjp93

726 views

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

11 hours ago, DXMember said:

HA you forgot a figure bracket

and you should probably reformat it, because it shows up in a single line...

I haven't checked it since the forum changed, so this is hilarious. I'll fix soon. Also, there's no missing bracket.

Link to comment
Link to post
4 hours ago, patrickjp93 said:

I haven't checked it since the forum changed, so this is hilarious. I'll fix soon. Also, there's no missing bracket.

maybe it has something to do with formatting,

but I copied that single line from LTT,

split in to lanis and padded with Tabs, I got short of one bracket that's suppose to close the first opening bracket

 

but yes I would very much appretiate if you could fix the formatting on this and the other of your blog posts

Thank you for sharing this

Link to comment
Link to post
15 minutes ago, DXMember said:

maybe it has something to do with formatting,

but I copied that single line from LTT,

split in to lanis and padded with Tabs, I got short of one bracket that's suppose to close the first opening bracket

 

but yes I would very much appretiate if you could fix the formatting on this and the other of your blog posts

Thank you for sharing this

Formatting fixed. Also, no missing braces. Count them up. Same as before.

Link to comment
Link to post
×