Skip to content

Commit b75ab87

Browse files
Drop sim and precalctc improvements.
1 parent 0816810 commit b75ab87

2 files changed

Lines changed: 13 additions & 19 deletions

File tree

dropsim.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -259,18 +259,7 @@ int main(int argc, char* argv[]) {
259259
dropcycles = std::max(1, dropcycles);
260260
dropcycles = std::min(1000000, dropcycles);
261261

262-
int mindropcount = 30;
263-
264-
if (argc >= 5) {
265-
mindropcount = atoi(argv[4]);
266-
}
267-
268-
mindropcount = std::max(1, mindropcount);
269-
270-
std::cout << "TC: " << tcname << std::endl;
271-
std::cout << "Player mod: " << playermod << std::endl;
272-
std::cout << "Drop cycles per set: " << dropcycles << std::endl;
273-
std::cout << "Minimum drop count per thread: " << mindropcount << std::endl;
262+
std::cout << tcname << " [" << playermod << "]" << std::endl;
274263

275264
// Open the treasure class file at: txt/treasureclassex.txt
276265
FILE* tex = fopen((txtDir + (BASETC ? "base/treasureclassex.txt" : "treasureclassex.txt")).c_str(), "r");
@@ -385,9 +374,9 @@ int main(int argc, char* argv[]) {
385374
}
386375

387376
// Get CPU count.
388-
int thread_count = std::thread::hardware_concurrency();
377+
int thread_count = std::thread::hardware_concurrency() * 2 / 3; // Use 2/3 of available threads to avoid overloading the system
389378

390-
if (thread_count == 0) {
379+
if (thread_count < 1) {
391380
thread_count = 1; // Fallback to 1 if hardware_concurrency cannot determine.
392381
}
393382
else {
@@ -397,8 +386,13 @@ int main(int argc, char* argv[]) {
397386
}
398387
}
399388

400-
std::cout << "Using " << thread_count << " threads\n";
401-
std::cout << "Output files periodically written to: " << simulationsPath << std::endl;
389+
long mindropcount = thread_count;
390+
391+
if (argc >= 5) {
392+
mindropcount = atoi(argv[4]);
393+
}
394+
395+
mindropcount = std::max(1L, mindropcount);
402396

403397
std::vector<std::thread> threads;
404398

@@ -472,6 +466,7 @@ int main(int argc, char* argv[]) {
472466
for (const auto& drop : totaldrops) {
473467
if (drop.second < mindropcount) {
474468
allAboveMin = false;
469+
printf("Thread %d: Item \'%s\' has %ld drops left...\n", i, drop.first.name.c_str(), mindropcount - drop.second);
475470
break;
476471
}
477472
}

precalctc.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
] as $basepath => [$simulationpath, $treasureclassex, $simulator]) {
1919
print("Generating $basepath\n");
2020

21-
foreach (glob($basepath . '*.json') as $file) {
21+
foreach (glob($basepath . '*.{json,mjs}', GLOB_BRACE) as $file) {
2222
if (is_file($file) && $file[0] !== '.') {
2323
unlink($file);
2424
}
@@ -36,9 +36,8 @@
3636
}
3737

3838
foreach ([1, 2, 3, 4, 5, 6, 7, 8] as $dropmodifier) {
39-
print("Simulating $tc_name with drop modifier $dropmodifier\n");
4039
$tc_name_escaped = escapeshellarg($tc_name);
41-
exec("./$simulator $tc_name_escaped $dropmodifier");
40+
passthru("./$simulator $tc_name_escaped $dropmodifier");
4241
}
4342

4443
$totalruns = 0;

0 commit comments

Comments
 (0)