修复 Affinity 计算

This commit is contained in:
xkeyC 2023-11-23 22:30:00 +08:00
parent e8a58a9c42
commit 3f637f4aef
2 changed files with 23 additions and 5 deletions

View File

@ -218,9 +218,26 @@ foreach ($adapter in $adapterMemory) {
return int.tryParse(cpuNumberResult.stdout.toString().trim()) ?? 0;
}
static Future<int?> getCpuAffinity(int eCoreCount) async {
static Future<String?> getCpuAffinity(int eCoreCount) async {
final cpuNumber = await getNumberOfLogicalProcessors();
if (cpuNumber == 0) return null;
return (1 << cpuNumber) - (1 << eCoreCount);
if (cpuNumber == 0 || eCoreCount == 0 || eCoreCount > cpuNumber) {
return null;
}
StringBuffer sb = StringBuffer();
for (var i = 0; i < cpuNumber; i++) {
if (i < eCoreCount) {
sb.write("0");
} else {
sb.write("1");
}
}
final binaryString = sb.toString();
int hexDigits = (binaryString.length / 4).ceil();
dPrint("Affinity sb ==== $sb");
return int.parse(binaryString, radix: 2)
.toRadixString(16)
.padLeft(hexDigits, '0')
.toUpperCase();
}
}

View File

@ -527,7 +527,7 @@ class HomeUIModel extends BaseUIModel {
}
doLaunchGame(String launchExe, List<String> args, String installPath,
int? processorAffinity) async {
String? processorAffinity) async {
_isGameRunning[installPath] = true;
notifyListeners();
try {
@ -537,13 +537,14 @@ class HomeUIModel extends BaseUIModel {
dPrint('stdout: ${result.stdout}');
dPrint('stderr: ${result.stderr}');
} else {
dPrint("set Affinity === $processorAffinity ");
ProcessResult result = await Process.run("cmd.exe", [
'/C',
'Start',
'"StarCitizen"',
'/High',
'/Affinity',
'$processorAffinity',
processorAffinity,
launchExe,
...args
]);