Quantcast
Channel: Community | MonoGame - Latest topics
Viewing all articles
Browse latest Browse all 6821

Gameloops for Multicore Chipsets

$
0
0

@MrGrak wrote:

Hi,

I have some C# code I'd like to present. It is a console application that runs a game loop, and divides that game loop up among multiple threads. The concepts driving this design I've shamelessly stolen from NaughtyDog's fiber game engine, Destiny's job-system game engine, and Unity's latest job system (based on my understanding of them, which is entirely from GDC talks).

Alright, enough introduction - have some code: https://github.com/MrGrak/Gameloops/blob/master/CsharpConsoleAppExamples/main%2B3asJobs.cs

In this console application I'm simulating 256 actors moving towards a goal position each frame. If actors overlap, they are 'removed' from the simulation. The simulation completes when there is 1 or less actor remaining. The simulation is an example game loop, with move and collision phases. What I'd like to discuss is not the simulation, but how the simulation's workload is being divided up among multiple threads - and how those threads are reading and writing data - using two lists - which is based on the idea of the frame buffer we all know and love from games.

The questions I have are few: am I stupid? is this an efficient way to divide up work among the cpu cores?

Unlike the engines created by naughtyDog, bungie, and unity - I do not have control over thread to core affinity, and thus incur some context switching overhead. I'm trusting the OS to properly choose which cores are used for the different segments of work being done - and I know that's not too efficient, but I haven't found a reliable way to force or ensure core affinity in .Net. There are many articles I would like to link to, but I feel that would complicate what this post is trying to "be about" - questions and a discussion about game loops for multicore chipsets.

Here are a few more example that show the sim in 1, 2, and 3 threaded architectures:
https://github.com/MrGrak/Gameloops

Thanks for taking the time to read my post, and I hope to have an interesting discussion about game loop design for multiple cores.

MrGrak

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 6821

Trending Articles