Improve physics

This commit is contained in:
schmelczerandras 2020-10-06 09:26:56 +02:00
parent 8b87b68dae
commit ec0b700313
14 changed files with 181 additions and 71 deletions

View file

@ -1,9 +0,0 @@
import { Command } from 'shared';
export class StepCommand extends Command {
public static readonly type = 'StepCommand';
public constructor(public readonly deltaTimeInMiliseconds: DOMHighResTimeStamp) {
super();
}
}

View file

@ -15,6 +15,7 @@ import {
prettyPrint,
settings,
SetViewAreaActionCommand,
StepCommand,
TransportEvents,
} from 'shared';
import io from 'socket.io-client';
@ -23,7 +24,6 @@ import { MouseListener } from './commands/generators/mouse-listener';
import { TouchListener } from './commands/generators/touch-listener';
import { CommandReceiverSocket } from './commands/receivers/command-receiver-socket';
import { RenderCommand } from './commands/types/render';
import { StepCommand } from './commands/types/step';
import { Configuration } from './config/configuration';
import { DeltaTimeCalculator } from './helper/delta-time-calculator';
import { rgb } from './helper/rgb';
@ -142,7 +142,7 @@ export class Game {
}
private gameLoop(time: DOMHighResTimeStamp) {
const deltaTime = this.deltaTimeCalculator.getNextDeltaTime(time);
const deltaTime = this.deltaTimeCalculator.getNextDeltaTimeInMilliseconds(time);
this.keyboardListener.generateCommands();
if (this.gameObjects.camera) {

View file

@ -5,7 +5,9 @@ export class DeltaTimeCalculator {
document.addEventListener('visibilitychange', this.handleVisibilityChange.bind(this));
}
public getNextDeltaTime(currentTime: DOMHighResTimeStamp): DOMHighResTimeStamp {
public getNextDeltaTimeInMilliseconds(
currentTime: DOMHighResTimeStamp
): DOMHighResTimeStamp {
if (this.previousTime === null) {
this.previousTime = currentTime;
}

View file

@ -7,9 +7,9 @@ import {
DeleteObjectsCommand,
GameObject,
Id,
StepCommand,
UpdateObjectsCommand,
} from 'shared';
import { StepCommand } from '../commands/types/step';
import { deserialize, deserializeJsonArray } from '../transport/deserialize';
import { Camera } from './camera';
import { CharacterView } from './character-view';