reworked ticking for many configs! maybe in settings?!
parent
845cb376e8
commit
8f4d21c00d
|
|
@ -24,9 +24,9 @@ export class Game extends Frigid implements Tickable {
|
|||
return game;
|
||||
}
|
||||
|
||||
async tick() {
|
||||
async tick(seconds: number) {
|
||||
for(const pawn of this.pawns) {
|
||||
pawn.tick();
|
||||
pawn.tick(seconds);
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ export class Pawn extends Serializable implements Tickable {
|
|||
|
||||
job: TaskState<unknown, unknown>;
|
||||
|
||||
async tick() {
|
||||
this.age ++;
|
||||
async tick(seconds: number) {
|
||||
this.age += seconds;
|
||||
}
|
||||
|
||||
get idle() {
|
||||
|
|
|
|||
117
src/Time.ts
117
src/Time.ts
|
|
@ -201,45 +201,112 @@ export default class Time extends Serializable {
|
|||
}
|
||||
}
|
||||
|
||||
async execTick(seconds: number) {
|
||||
const doDynamicTick = true;
|
||||
|
||||
if(doDynamicTick) {
|
||||
if(this.thing) {
|
||||
await this.thing.tick(seconds);
|
||||
}
|
||||
this.advanceTime(seconds);
|
||||
} else {
|
||||
for(let i = 0; i < seconds; i ++) {
|
||||
if(this.thing) {
|
||||
await this.thing.tick(1);
|
||||
}
|
||||
this.advanceTime(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async doTick() {
|
||||
|
||||
this.advanceTime(3);
|
||||
const timeout = 1000 / this.targetTPS;
|
||||
// const start = ms4()
|
||||
const start = ms4();
|
||||
if(this.thing) {
|
||||
await this.thing.tick();
|
||||
}
|
||||
const end = ms4()
|
||||
const elapsed = end - start;
|
||||
const wait = timeout - elapsed;
|
||||
const normalizedWait = Math.floor(Math.max(wait, 0));
|
||||
// the higher the multitick, the more lopsided
|
||||
// ticks become in realtime, however, they rely
|
||||
// on fewer setTimeouts, which helps tick scheduling
|
||||
const multitick = 1;
|
||||
|
||||
// process.stdout.write(`tick took ${elapsed} waiting ${normalizedWait}\n`);
|
||||
if(multitick > 1) {
|
||||
const timeout = (1000 / this.targetTPS) * multitick;
|
||||
const start = ms4();
|
||||
|
||||
if(wait < 0) {
|
||||
const ticksOver = (-wait / timeout) + 1;
|
||||
if(ticksOver > 1.5)
|
||||
console.log(chalk.yellow('Can\'t keep up! Tick took ' + ticksOver.toFixed(2) + ' ticks (' + (timeout - wait).toFixed(4) + 'ms)'));
|
||||
for(let tickNum = 0; tickNum < multitick; tickNum ++ ) {
|
||||
const seconds = 3;
|
||||
|
||||
this.execTick(seconds);
|
||||
|
||||
this.ticksInSecond ++;
|
||||
const end = ms4();
|
||||
|
||||
if(end > this.lastTPSCheckpoint + 1000) {
|
||||
this.lastTPSCheckpoint = end;
|
||||
this.tps = this.ticksInSecond;
|
||||
this.ticksInSecond = 0;
|
||||
}
|
||||
}
|
||||
|
||||
const end = ms4()
|
||||
const elapsed = end - start;
|
||||
const wait = timeout - elapsed;
|
||||
const normalizedWait = Math.floor(Math.max(wait, 0));
|
||||
|
||||
// process.stdout.write(`tick took ${elapsed} waiting ${normalizedWait}\n`);
|
||||
|
||||
if(wait < 0) {
|
||||
const ticksOver = (-wait / timeout) + 1;
|
||||
if(ticksOver > 1.5)
|
||||
console.log(chalk.yellow('Can\'t keep up! Tick took ' + ticksOver.toFixed(2) + ' ticks (' + (timeout - wait).toFixed(4) + 'ms)'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
if(this.paused) return;
|
||||
setTimeout(this._boundTick, normalizedWait);
|
||||
} else {
|
||||
// this code is from not needing a multi-tick workaround, due to scheduling.
|
||||
const seconds = 3;
|
||||
const timeout = 1000 / this.targetTPS;
|
||||
// const start = ms4()
|
||||
const start = ms4();
|
||||
|
||||
this.execTick(seconds);
|
||||
|
||||
const end = ms4()
|
||||
const elapsed = end - start;
|
||||
const wait = timeout - elapsed;
|
||||
const normalizedWait = Math.floor(Math.max(wait, 0));
|
||||
|
||||
// process.stdout.write(`tick took ${elapsed} waiting ${normalizedWait}\n`);
|
||||
|
||||
if(wait < 0) {
|
||||
const ticksOver = (-wait / timeout) + 1;
|
||||
if(ticksOver > 1.5)
|
||||
console.log(chalk.yellow('Can\'t keep up! Tick took ' + ticksOver.toFixed(2) + ' ticks (' + (timeout - wait).toFixed(4) + 'ms)'));
|
||||
}
|
||||
|
||||
|
||||
this.ticksInSecond ++;
|
||||
|
||||
if(end > this.lastTPSCheckpoint + 1000) {
|
||||
this.lastTPSCheckpoint = end;
|
||||
this.tps = this.ticksInSecond;
|
||||
this.ticksInSecond = 0;
|
||||
}
|
||||
|
||||
if(this.paused) return;
|
||||
setTimeout(this._boundTick, normalizedWait);
|
||||
}
|
||||
|
||||
|
||||
this.ticksInSecond ++;
|
||||
|
||||
if(end > this.lastTPSCheckpoint + 1000) {
|
||||
this.lastTPSCheckpoint = end;
|
||||
this.tps = this.ticksInSecond;
|
||||
this.ticksInSecond = 0;
|
||||
}
|
||||
|
||||
if(this.paused) return;
|
||||
setTimeout(this._boundTick, normalizedWait)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
export interface Tickable {
|
||||
tick: () => Promise<void>
|
||||
tick: (seconds: number) => Promise<void>
|
||||
}
|
||||
|
||||
function ms4() {
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ ipc.config.silent = true;
|
|||
const exec = 'qode' +
|
||||
(process.platform === "win32" ? '.cmd' : '');
|
||||
const args = [
|
||||
// '--inspect',
|
||||
'bin/app.bundle.cjs'
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -64,8 +64,9 @@ ProcessManager.on('reload', () => {
|
|||
|
||||
// HACK this is bullshit, :)
|
||||
function f() {
|
||||
win.repaint();
|
||||
// win.repaint();
|
||||
win.update();
|
||||
setTimeout(f, 0);
|
||||
}
|
||||
f();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue