We-the-People-civ4col-mod / Mod

This is the repository where the mod resides.
85 stars 36 forks source link

Implement Task Parallelism #204

Open devolution79 opened 5 years ago

devolution79 commented 5 years ago

To be updated.

Nightinggale commented 5 years ago

We should make some sort of on/off switch for multithreading. It would be useful to use the approach proposed in #210 to tell if the desync log remains consistent for both single threaded and multi threaded operation. It would at the same time assist with profiling, hence figuring out if it helps with performance.

Nightinggale commented 5 years ago

We should make a function to call tbb::parallel_reduce() instead of calling it directly. This function can then contain a (compile time?) if else to allow running in single thread mode, which will give us the benefit of quickly switch between those two modes to test performance and functionality.

Using a function will also allow us to use a global bool to tell if the code is currently in multi threaded mode. Simply start by setting the bool to true and set it to false when returning. This can be used for multiple purposes:

I'm not entirely sure how to make this function, but I assume it can be done without too much hassle, like if it's a static (inline?) template function in a header file.

Nightinggale commented 4 years ago

Linker option /DELAYLOAD will delay loading dll files. This is important because without it, the game will try to load all needed dll files when CvGameCoreDLL.dll is loaded. That's an issue because that's before the call to DllMain (in CvGameCoreDLL.cpp), meaning we can't run modded code prior to opening other dll files like TBB. By default the game assumes the dll files to be next to the exe file.

If we delay loading dll files, we can use the DLL_PROCESS_ATTACH call to DllMain to load TBB at the same location as the modded dll file. In fact getting the mod location is as easy as calling gDLL->getModName().