Fix: Replaced Model With MiniModel in the client implementation and in the view
This commit is contained in:
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Network.RMI.Client;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;
|
||||
|
||||
@@ -37,7 +38,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
||||
* @throws RemoteException if any RMI error occurs
|
||||
*/
|
||||
@Override
|
||||
public void onGameInit(Game model) throws RemoteException {
|
||||
public void onGameInit(MiniModel model) throws RemoteException {
|
||||
clientController.setModel(model);
|
||||
clientController.view.render();
|
||||
}
|
||||
@@ -55,7 +56,7 @@ public class ClientCallbackImpl extends UnicastRemoteObject implements IClientCa
|
||||
if(event.getIsError()) {
|
||||
clientController.view.showError(event.toString());
|
||||
} else {
|
||||
event.apply(clientController.localController);
|
||||
event.apply(clientController.miniModel);
|
||||
clientController.view.render();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package it.polimi.ingsw.gc14.Network.RMI.Common;
|
||||
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.*;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.Board;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.rmi.*;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Callback interface used by the server to notify an RMI client about
|
||||
@@ -21,7 +24,7 @@ public interface IClientCallback extends Remote, Serializable {
|
||||
* @param model the current game model.
|
||||
* @throws RemoteException if an RMI communication error occurs.
|
||||
*/
|
||||
void onGameInit(Game model) throws RemoteException;
|
||||
void onGameInit(MiniModel miniModel) throws RemoteException;
|
||||
|
||||
/**
|
||||
* Notifies the client about a network action to process.
|
||||
|
||||
@@ -3,6 +3,8 @@ package it.polimi.ingsw.gc14.Network.RMI.Server;
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.LimitedMap;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.GamePackage.CurrentState;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||
import it.polimi.ingsw.gc14.Network.RMI.Common.IClientCallback;
|
||||
@@ -25,7 +27,6 @@ import java.rmi.*;
|
||||
public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
private String host;
|
||||
private GameController controller;
|
||||
private Game model;
|
||||
private Registry registry;
|
||||
private int nPort;
|
||||
|
||||
@@ -89,7 +90,8 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
clients.put(username, callback);
|
||||
System.out.println("Reconnected player: " + username);
|
||||
startWatchdog(username);
|
||||
callback.onGameInit(controller.getModel());
|
||||
Game game = controller.getModel();
|
||||
callback.onGameInit(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers()));
|
||||
System.out.println("Model sent: " + username);
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
return true;
|
||||
@@ -98,8 +100,7 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
else
|
||||
{
|
||||
if (playerList.isEmpty()) {
|
||||
model = new Game(preferredInt);
|
||||
controller.setModel(model);
|
||||
controller.setModel(new Game(preferredInt));
|
||||
playerList.setLimit(preferredInt);
|
||||
}
|
||||
if (controller.addPlayer(username)) {
|
||||
@@ -115,7 +116,8 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
clients.put(username, callback);
|
||||
System.out.println("Reconnected player: " + username);
|
||||
startWatchdog(username);
|
||||
callback.onGameInit(controller.getModel());
|
||||
Game game = controller.getModel();
|
||||
callback.onGameInit(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers()));
|
||||
System.out.println("Model sent: " + username);
|
||||
actionQueue.add(new ReconnectPlayer(username));
|
||||
return true;
|
||||
@@ -165,10 +167,11 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
* Mirrors {@code TCPServer.notifyAll(Game)} + the {@code ClientHandler.notifyModel}
|
||||
* call that stores the model for disconnect-turn checking.
|
||||
*/
|
||||
public void notifyAll(Game model) throws RemoteException {
|
||||
this.model = model;
|
||||
public void notifyAll(MiniModel model) throws RemoteException {
|
||||
// Keep every watchdog's game reference up to date
|
||||
watchdogs.values().forEach(wd -> wd.setGame(model));
|
||||
synchronized (controller){
|
||||
watchdogs.values().forEach(wd -> wd.setGame(controller.getModel()));
|
||||
}
|
||||
for (IClientCallback cb : clients.values()) {
|
||||
cb.onGameInit(model);
|
||||
}
|
||||
@@ -326,7 +329,10 @@ public class RMIServer extends UnicastRemoteObject implements IGameServer {
|
||||
private void startWatchdog(String username) {
|
||||
RMIHeartbeat wd = new RMIHeartbeat(
|
||||
username, playerList, clients, actionQueue);
|
||||
if (model != null) wd.setGame(model);
|
||||
synchronized (controller)
|
||||
{
|
||||
if (controller.getModel() != null) wd.setGame(controller.getModel());
|
||||
}
|
||||
watchdogs.put(username, wd);
|
||||
wd.start();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Network.TCP.Client;
|
||||
|
||||
import it.polimi.ingsw.gc14.Controller.ClientController;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.IClient;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.*;
|
||||
@@ -165,11 +166,11 @@ public class TCPClient implements IClient {
|
||||
if (event.getIsError()) {
|
||||
controller.view.showError(event.toString());
|
||||
} else {
|
||||
event.apply(controller.localController);
|
||||
event.apply(controller.miniModel);
|
||||
controller.view.render();
|
||||
}
|
||||
|
||||
} else if (read instanceof Game model) {
|
||||
} else if (read instanceof MiniModel model) {
|
||||
controller.setModel(model);
|
||||
controller.view.render();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package it.polimi.ingsw.gc14.Network.TCP.Server;
|
||||
|
||||
import it.polimi.ingsw.gc14.LimitedMap;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvent;
|
||||
import it.polimi.ingsw.gc14.Network.NetworkEvents.DisconnectedPlayer;
|
||||
|
||||
@@ -24,7 +25,6 @@ public class ClientHandler implements Runnable {
|
||||
|
||||
private boolean running ;
|
||||
|
||||
private Game game;
|
||||
/**
|
||||
* Returns the username associated with this client.
|
||||
*
|
||||
@@ -120,8 +120,7 @@ public class ClientHandler implements Runnable {
|
||||
* Sends the current game model to this client.
|
||||
* @param game The current state of the game to send to the client.
|
||||
*/
|
||||
public synchronized void notifyModel(Game game) {
|
||||
this.game = game;
|
||||
public synchronized void notifyMiniModel(MiniModel game) {
|
||||
try {
|
||||
out.writeObject(game);
|
||||
} catch (IOException e) {
|
||||
|
||||
@@ -3,6 +3,7 @@ package it.polimi.ingsw.gc14.Network.TCP.Server;
|
||||
import it.polimi.ingsw.gc14.Controller.GameController;
|
||||
import it.polimi.ingsw.gc14.LimitedMap;
|
||||
import it.polimi.ingsw.gc14.Model.Game;
|
||||
import it.polimi.ingsw.gc14.Model.MiniModel;
|
||||
import it.polimi.ingsw.gc14.Model.Player;
|
||||
import it.polimi.ingsw.gc14.Network.ClientPlayer;
|
||||
import it.polimi.ingsw.gc14.Network.EventType;
|
||||
@@ -124,7 +125,8 @@ public class TCPServer {
|
||||
);
|
||||
clientSocket.getOutputStream().write(1);
|
||||
pendingHeartbeat.put(username, handler);
|
||||
handler.notifyModel(controller.getModel());
|
||||
Game game = controller.getModel();
|
||||
handler.notifyMiniModel(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers()));
|
||||
Thread thread = new Thread(handler);
|
||||
thread.start();
|
||||
clientHandlers.add(handler);
|
||||
@@ -172,7 +174,8 @@ public class TCPServer {
|
||||
);
|
||||
clientSocket.getOutputStream().write(1);
|
||||
pendingHeartbeat.put(username, handler);
|
||||
handler.notifyModel(controller.getModel());
|
||||
Game game = controller.getModel();
|
||||
handler.notifyMiniModel(new MiniModel(game.getBoard(),game.getSlotMap(), game.orderLogicCard,game.getCurrentState(),game.getPlayers()));
|
||||
Thread thread = new Thread(handler);
|
||||
thread.start();
|
||||
clientHandlers.add(handler);
|
||||
@@ -232,7 +235,7 @@ public class TCPServer {
|
||||
});
|
||||
}
|
||||
|
||||
public void notifyAll(Game model) {
|
||||
clientHandlers.forEach(h -> h.notifyModel(model));
|
||||
public void notifyAll(MiniModel model) {
|
||||
clientHandlers.forEach(h -> h.notifyMiniModel(model));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user