Commit f76122d8 authored by Bogdan's avatar Bogdan Committed by bogdanbear

Fixed restart bug in singlePlayer!

parent 942d79d7
......@@ -50,7 +50,7 @@ public class GameContent implements Serializable{
* Relayer dmr = Relayers.addNewRelayer(2,AItest,this);
* AIControler.add(gameContent,dmr);
*/
System.out.println("GameContent class: One gameContent created");
System.out.println("GameContent class: One gameContent created by"+Thread.currentThread().getId());
}
public Map getMap() {
......
......@@ -33,14 +33,15 @@ public class DummyLocalGameLoop extends Thread{
public Relayer getFollowedRelayer() {
try {
relayerSemaphore.acquire();
System.out.println("Acquired relayer");
System.out.println("Acquired relayer "+ followedRelayer+ " by "+currentThread().getId());
return followedRelayer;
} catch (InterruptedException e) {
System.out.println("Problem with acquiring relayer...");
}finally {
//finally is almost always executed, unless an Interrupted exception or a System.exit appeared
System.out.println("Relayer is "+followedRelayer);
relayerSemaphore.release();
System.out.println("Released relayer");
System.out.println("Released relayer by "+currentThread().getId());
}
return followedRelayer;
......@@ -98,6 +99,9 @@ public class DummyLocalGameLoop extends Thread{
public synchronized void pauseGame()
{
isPlaying=false;
//do not release here
//relayerSemaphore.release();
System.out.println("Released relayer");
}
public synchronized boolean getIsPlaying()
......@@ -126,15 +130,15 @@ public class DummyLocalGameLoop extends Thread{
@Override
public void run() {
System.out.println("DummyLocalGameLoop Thread started");
System.out.println("DummyLocalGameLoop Thread started+"+currentThread().getId());
while (true) {
//System.out.println("DummyLocalGameLoopThread, game is "+isPlaying);
if (getIsPlaying()) {
System.out.println("DummyLocalGameLoopThread, game is "+isPlaying);
System.out.println("DummyLocalGameLoopThread,"+currentThread().getId()+ "game is "+isPlaying);
Event eventToReceive = null;
System.out.println("The game is on!");
while (!((eventToReceive = (Event) getNetworkConnection().receiveEvent(true)) instanceof EndEvent)) {
//System.out.println("DummyLocalGameLoop Thread: We have received an event!applying...");
//System.out.println("DummyLocalGameLoop Thread: We have received an event!applying...+"+eventToReceive);
eventToReceive.apply(gameContent);
if (eventToReceive instanceof MapInit) {
GameContent gc = DummyLocalGameLoop.getInstance().getContent();
......
......@@ -76,6 +76,7 @@ public class ServerLoop extends Thread {
System.out.println("DummyServerLoop: Just received an EndEvent");
//this is so bad because if this thread sleeps for too long it's a disaster
cont=false;
networkConnection.initiateConnectionEnd();
}
}
if(cont == false)
......
......@@ -70,6 +70,7 @@ public class ClientConnection extends NetworkConnection<NetworkObject>{
@Override
public void initiateConnectionEnd()
{
LOGGER.info("network:Client has called initaiteConnectionEnd!");
EndEvent endEvent=new EndEvent();
sendEvent(endEvent);
try {
......
......@@ -27,6 +27,7 @@ public class LocalConnection<E extends NetworkObject> extends NetworkConnection<
*/
@Override
public void initiateConnectionEnd() {
LOGGER.info("network:LocalConnection has called initaiteConnectionEnd!");
//serverIncomingEvents.clear();
//incomingEvents.clear();
EndEvent endEvent=new EndEvent();
......
......@@ -141,6 +141,7 @@ public class ServerConnection<E extends NetworkObject> extends NetworkConnection
@Override
public synchronized void initiateConnectionEnd()
{
LOGGER.info("network:Server has called initaiteConnectionEnd!");
try {
//first we stop listening to incoming clients, if we did that in the first place
setStillRunning(false);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment