Skip to content

Commit

Permalink
don't speed up fastloop() under accelerated time
Browse files Browse the repository at this point in the history
Instead of simply running the game in tighter loops, multiply resource
calculations by game speed. This is only done for `fastloop()` for now
as most other code is tightly build around the timings of `midloop()`
and `longloop()`.

In a few places a `++` was replaced by `4*time_multiplier` to account
for the loop running 4 times per second and `time_multiplier` being
0.25 under normal game speed.
  • Loading branch information
Daxtorim committed Jul 22, 2023
1 parent 83306d0 commit 9d803df
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
7 changes: 4 additions & 3 deletions src/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ export function gameLoop(act){
global.settings.gameSpeed *= fast;
}

for (let key in webWorker.timers) {
webWorker.timers[key] /= global.settings.gameSpeed;
}
// timers.main stays as is since ressource calculations in
// fastloop() are already gamespeed compensated
webWorker.timers.mid /= global.settings.gameSpeed;
webWorker.timers.long /= global.settings.gameSpeed;

if (webWorker.w){
webWorker.w.postMessage({ loop: 'short', period: webWorker.timers.main });
Expand Down
29 changes: 12 additions & 17 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -978,7 +978,7 @@ function fastLoop(){
breakdown.p[res] = {};
});

var time_multiplier = 0.25;
var time_multiplier = webWorker.timers.main * global.settings.gameSpeed / 1000;

if (global.race.species === 'protoplasm'){
// Early Evolution Game
Expand Down Expand Up @@ -1879,7 +1879,7 @@ function fastLoop(){
if (global.space['m_relay']){
if (p_on['m_relay']){
if (global.space.m_relay.charged < 10000){
global.space.m_relay.charged++;
global.space.m_relay.charged += 4 * time_multiplier;
}
}
else {
Expand Down Expand Up @@ -3365,12 +3365,15 @@ function fastLoop(){
// Fortress Repair
if (global.portal['fortress'] && global.portal.fortress.walls < 100){
if (modRes('Stone', -(200 * time_multiplier))){
global.portal.fortress.repair++;
global.portal.fortress.repair += 4 * time_multiplier;
breakdown.p.consume.Stone[loc('portal_fortress_name')] = -200;
}
if (global.portal.fortress.repair >= actions.portal.prtl_fortress.info.repair()){
global.portal.fortress.repair = 0;
global.portal.fortress.walls++;
global.portal.fortress.walls += 4 * time_multiplier;
if (global.portal.fortress.walls > 100) {
global.portal.fortress.walls = 100;
}
}
}

Expand Down Expand Up @@ -3548,7 +3551,7 @@ function fastLoop(){

if (global.race['emfield']){
if (global.race['discharge'] && global.race['discharge'] > 0){
global.race.discharge--;
global.race.discharge -= 4 * time_multiplier;
}
else {
global.race.emfield++;
Expand Down Expand Up @@ -7020,7 +7023,7 @@ function fastLoop(){
if (!$('#portal-carport .count').hasClass('has-text-alert')){
$('#portal-carport .count').addClass('has-text-alert');
}
global.portal.carport.repair++;
global.portal.carport.repair += 4 * time_multiplier;
if (global.portal.carport.repair >= actions.portal.prtl_fortress.carport.repair()){
global.portal.carport.repair = 0;
global.portal.carport.damaged--;
Expand Down Expand Up @@ -11231,21 +11234,13 @@ function q_check(load){
}

function diffCalc(res,period){
let sec = 1000;
if (global.race['slow']){
let slow = 1 + (traits.slow.vars()[0] / 100);
sec = Math.floor(sec * slow);
}
if (global.race['hyper']){
let fast = 1 - (traits.hyper.vars()[0] / 100);
sec = Math.floor(sec * fast);
}
const periods = 1000 / period

global.resource[res].diff = +(global.resource[res].delta / (period / sec)).toFixed(2);
global.resource[res].diff = +(global.resource[res].delta * periods).toFixed(2);
global.resource[res].delta = 0;

if (global.resource[res].hasOwnProperty('gen') && global.resource[res].hasOwnProperty('gen_d')){
global.resource[res].gen = +(global.resource[res].gen_d / (period / sec)).toFixed(2);
global.resource[res].gen = +(global.resource[res].gen_d * periods).toFixed(2);
global.resource[res].gen_d = 0;
}

Expand Down
6 changes: 3 additions & 3 deletions src/portal.js
Original file line number Diff line number Diff line change
Expand Up @@ -1970,7 +1970,7 @@ export function buildFortress(parent,full){
let wallStatus = $('<div></div>');
fort.append(wallStatus);

wallStatus.append($(`<span class="has-text-warning" :aria-label="defense()">${loc('fortress_wall')} <span :class="wall()">{{ f.walls }}%</span></span>`))
wallStatus.append($(`<span class="has-text-warning" :aria-label="defense()">${loc('fortress_wall')} <span :class="wall()">{{ Math.ceil(f.walls) }}%</span></span>`))

let station = $(`<div></div>`);
fort.append(station);
Expand Down Expand Up @@ -2543,7 +2543,7 @@ export function bloodwar(){
if (siege > 0){
damage++;
global.portal.fortress.walls--;
if (global.portal.fortress.walls === 0){
if (global.portal.fortress.walls <= 0){
siege_report.destroyed = true;
destroyed = true;
break;
Expand Down Expand Up @@ -5294,4 +5294,4 @@ function purgeReports(refresh){
}
return removed;
}
}
}

0 comments on commit 9d803df

Please sign in to comment.