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;
|
return game;
|
||||||
}
|
}
|
||||||
|
|
||||||
async tick() {
|
async tick(seconds: number) {
|
||||||
for(const pawn of this.pawns) {
|
for(const pawn of this.pawns) {
|
||||||
pawn.tick();
|
pawn.tick(seconds);
|
||||||
}
|
}
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ export class Pawn extends Serializable implements Tickable {
|
||||||
|
|
||||||
job: TaskState<unknown, unknown>;
|
job: TaskState<unknown, unknown>;
|
||||||
|
|
||||||
async tick() {
|
async tick(seconds: number) {
|
||||||
this.age ++;
|
this.age += seconds;
|
||||||
}
|
}
|
||||||
|
|
||||||
get idle() {
|
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() {
|
async doTick() {
|
||||||
|
|
||||||
this.advanceTime(3);
|
// the higher the multitick, the more lopsided
|
||||||
const timeout = 1000 / this.targetTPS;
|
// ticks become in realtime, however, they rely
|
||||||
// const start = ms4()
|
// on fewer setTimeouts, which helps tick scheduling
|
||||||
const start = ms4();
|
const multitick = 1;
|
||||||
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));
|
|
||||||
|
|
||||||
// process.stdout.write(`tick took ${elapsed} waiting ${normalizedWait}\n`);
|
if(multitick > 1) {
|
||||||
|
const timeout = (1000 / this.targetTPS) * multitick;
|
||||||
|
const start = ms4();
|
||||||
|
|
||||||
if(wait < 0) {
|
for(let tickNum = 0; tickNum < multitick; tickNum ++ ) {
|
||||||
const ticksOver = (-wait / timeout) + 1;
|
const seconds = 3;
|
||||||
if(ticksOver > 1.5)
|
|
||||||
console.log(chalk.yellow('Can\'t keep up! Tick took ' + ticksOver.toFixed(2) + ' ticks (' + (timeout - wait).toFixed(4) + 'ms)'));
|
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 {
|
export interface Tickable {
|
||||||
tick: () => Promise<void>
|
tick: (seconds: number) => Promise<void>
|
||||||
}
|
}
|
||||||
|
|
||||||
function ms4() {
|
function ms4() {
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ ipc.config.silent = true;
|
||||||
const exec = 'qode' +
|
const exec = 'qode' +
|
||||||
(process.platform === "win32" ? '.cmd' : '');
|
(process.platform === "win32" ? '.cmd' : '');
|
||||||
const args = [
|
const args = [
|
||||||
|
// '--inspect',
|
||||||
'bin/app.bundle.cjs'
|
'bin/app.bundle.cjs'
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,8 +64,9 @@ ProcessManager.on('reload', () => {
|
||||||
|
|
||||||
// HACK this is bullshit, :)
|
// HACK this is bullshit, :)
|
||||||
function f() {
|
function f() {
|
||||||
win.repaint();
|
// win.repaint();
|
||||||
win.update();
|
win.update();
|
||||||
setTimeout(f, 0);
|
setTimeout(f, 0);
|
||||||
}
|
}
|
||||||
f();
|
f();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue