Skip to content

Commit 84d8d80

Browse files
committed
Code edits to SingleCore to make it run safer
Changed SingleCore to be disabled by default. (its usage is questionable on newer systems.)
1 parent b3c5fad commit 84d8d80

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

artifacts/ddraw.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ ViewXPos=-1
406406
ViewYPos=-1
407407

408408
;Set to 1 to force Fallout not to use multiple processor cores even if they are available
409-
SingleCore=1
409+
SingleCore=0
410410

411411
;Set to 1 to override the art_cache_size setting in fallout2.cfg
412412
OverrideArtCacheSize=0

sfall/Modules/MiscPatches.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,13 +928,21 @@ void MiscPatches::init() {
928928
SafeWrite32(0x444323, (DWORD)&patchName);
929929
}
930930

931-
if (IniReader::GetConfigInt("Misc", "SingleCore", 1)) {
931+
if (IniReader::GetConfigInt("Misc", "SingleCore", 0)) {
932932
SYSTEM_INFO sysInfo;
933933
GetSystemInfo(&sysInfo);
934934
if (sysInfo.dwNumberOfProcessors > 1) {
935-
dlogr("Applying single core patch.", DL_INIT);
936935
HANDLE process = GetCurrentProcess();
937-
SetProcessAffinityMask(process, 2); // use only CPU 1
936+
DWORD_PTR procAffinity, sysAffinity;
937+
if (GetProcessAffinityMask(process, &procAffinity, &sysAffinity)) {
938+
DWORD_PTR newMask = procAffinity & ~static_cast<DWORD_PTR>(1); // exclude CPU 0
939+
if (newMask == 0) newMask = procAffinity; // fall back if no other cores
940+
newMask &= -static_cast<LONG_PTR>(newMask); // pick the first available core
941+
if (newMask != 0 && newMask != procAffinity) {
942+
dlogr("Applying single core patch.", DL_INIT);
943+
SetProcessAffinityMask(process, newMask);
944+
}
945+
}
938946
}
939947
}
940948

0 commit comments

Comments
 (0)