Add renderFrames callbag

This commit is contained in:
Tangent 2020-02-15 21:10:19 -05:00
parent 5e29841717
commit c77499a577
3 changed files with 34 additions and 4 deletions

View file

@ -1,5 +1,7 @@
import { Callbag } from "callbag";
import animationFrames from "callbag-animation-frames";
import map from "callbag-map";
import { INPUT_FREQUENCY, LockstepProcessor, LockstepState } from "../Ecs/Lockstep";
@ -44,7 +46,7 @@ export abstract class LockstepClient<Input, State> {
if (serverTalkback) {
const input = this.gatherInput();
this.state.addLocalInput(input);
serverTalkback(1, {t: MessageTypes.INPUT, i: input});
serverTalkback(1, { t: MessageTypes.INPUT, i: input });
setTimeout(sampleInput, INPUT_FREQUENCY);
}
};
@ -59,7 +61,7 @@ export abstract class LockstepClient<Input, State> {
} else if (mode == 1) {
// server message
const message = data as ServerMessage<Input, State>;
switch(message.t) {
switch (message.t) {
case MessageTypes.RESET:
const resetState = this.initState(message.s);
this.state = new LockstepState(resetState, this.engine);
@ -82,4 +84,5 @@ export abstract class LockstepClient<Input, State> {
};
}
}
public renderFrames = map((ms: number) => this.state.getStateToRender())(animationFrames);
}