WIP ws messages, TODO backend receiving frontend messages
This commit is contained in:
@@ -4,55 +4,6 @@ import 'dart:isolate';
|
||||
import 'package:logging/logging.dart';
|
||||
import 'package:shared_models/room.dart';
|
||||
|
||||
// class GameRoomManager {
|
||||
// GameRoomManager({required SendPort this.socketManagerSendPort}) {
|
||||
// managerReceivePort = ReceivePort();
|
||||
// gamePorts = {};
|
||||
// receiveSubscription = managerReceivePort.listen((message) {
|
||||
// if (message is GameRoomManagerMessage) {
|
||||
// handleMessage(message);
|
||||
// } else if (message is GameRoomMessage) {
|
||||
// final gameUuid = message.gameUuid;
|
||||
// final gamePort = gamePorts[gameUuid];
|
||||
// if (gamePort == null) {
|
||||
// _logger.warning('Received GameRoomMessage for empty gamePort');
|
||||
// return;
|
||||
// }
|
||||
// gamePort.send(message);
|
||||
// } else {
|
||||
// _logger.warning('Received unknown message: $message');
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// late final Map<String, SendPort> gamePorts;
|
||||
// late final ReceivePort managerReceivePort;
|
||||
// late final StreamSubscription<dynamic> receiveSubscription;
|
||||
// final SendPort socketManagerSendPort;
|
||||
// final Logger _logger = Logger('GameRoomManager');
|
||||
|
||||
// void close() {
|
||||
// receiveSubscription.cancel();
|
||||
// //TODO remove connections
|
||||
// }
|
||||
|
||||
// Future<void> createRoom({required String roomUuid}) async {
|
||||
// // receivePort
|
||||
// final wsSendPort = SocketManager().createWsSendPort(roomUuid);
|
||||
// await Isolate.spawn(LiveGameRoom.spawn, LiveGameRoomData(roomUuid: roomUuid, wsSendPort: wsSendPort, gameManagerSendPort: ));
|
||||
// // first message from new isolate will be its SendPort
|
||||
// gamePorts[roomUuid] = await roomReceivePort.first as SendPort;
|
||||
// }
|
||||
|
||||
// void routePlayerToRoom(String roomCode, PlayerConnection player) {
|
||||
// gamePorts[roomCode]?.addPlayer(player);
|
||||
// }
|
||||
|
||||
// void handleMessage(message) {
|
||||
// throw UnimplementedError();
|
||||
// }
|
||||
// }
|
||||
|
||||
class LiveGameRoomData {
|
||||
LiveGameRoomData({
|
||||
required this.wsSendPort,
|
||||
@@ -102,15 +53,16 @@ class LiveGameRoom {
|
||||
}
|
||||
|
||||
void start() {
|
||||
gameLoop = Timer.periodic(const Duration(milliseconds: 750), update);
|
||||
gameLoop = Timer.periodic(const Duration(milliseconds: 3500), update);
|
||||
}
|
||||
|
||||
void update(Timer timer) {
|
||||
logger.finest('Room $roomUuid tick: ${timer.tick}');
|
||||
wsSendPort.send(
|
||||
RoomPingMessage(
|
||||
PingMessage.now(
|
||||
roomUuid,
|
||||
dest: PingDestination.client,
|
||||
userUuid: '',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user