Reset state on client connection instead of as a special manipulation of the local server.

This commit is contained in:
Tangent Wantwight 2020-05-09 22:08:22 -04:00
parent 7c06ab473d
commit c620e4c982
3 changed files with 8 additions and 6 deletions

View file

@ -92,6 +92,11 @@ export abstract class LockstepClient<LocalInput, GlobalInput, State> {
}
});
// talkback should exist at this point, send reset message
if(this.serverTalkback) {
this.serverTalkback(1, {t: MessageTypes.SET_STATE, s: {}});
}
// disposal
return () => {
this.serverTalkback?.(2);

View file

@ -39,6 +39,9 @@ export class LoopbackServer<LocalInput, State> {
this.inputBuffer[playerNumber] = message.i;
}
break;
case MessageTypes.SET_STATE:
this.broadcast(1, { t: MessageTypes.SET_STATE, u: -1, s: message.s });
break;
}
}
@ -52,8 +55,4 @@ export class LoopbackServer<LocalInput, State> {
return message;
}
}
public resetState(newState: Partial<State>) {
this.broadcast(1, { t: MessageTypes.SET_STATE, u: -1, s: newState });
}
}

View file

@ -20,6 +20,4 @@ const server = new LoopbackServer<KeyName[], Data>();
Select(".GameCanvas").forEachCanvas((c, cx, keys) => new Main(c, cx, keys, server));
server.resetState({});
BindTests();