BUGFIX: Game takes too long to process crime work with large number of cycles (#1821)

This commit is contained in:
catloversg 2024-12-12 18:11:58 +07:00 committed by GitHub
parent 1c7230a799
commit 74ede7d947
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -33,6 +33,12 @@ export class CrimeWork extends Work {
} }
process(cycles = 1): boolean { process(cycles = 1): boolean {
/**
* Crime work is processed in a loop. If the number of cycles is too large, the loop blocks the game engine for too
* long. 12960000 is the number of cycles in 30 days (5 * 3600 * 24 * 30). On a very old machine, the loop takes
* ~800-1000 ms to process the "shoplift" crime which is the fastest crime (faster crime = more iteration).
*/
cycles = Math.min(cycles, 12960000);
this.cyclesWorked += cycles; this.cyclesWorked += cycles;
const time = Object.values(Crimes).find((c) => c.type === this.crimeType)?.time ?? 0; const time = Object.values(Crimes).find((c) => c.type === this.crimeType)?.time ?? 0;
this.unitCompleted += CONSTANTS.MilliPerCycle * cycles; this.unitCompleted += CONSTANTS.MilliPerCycle * cycles;