mirror of
https://github.com/Retera/WarsmashModEngine.git
synced 2022-07-31 17:38:59 +02:00
Merge
This commit is contained in:
commit
7db2e0094a
@ -4,11 +4,9 @@ import java.io.IOException;
|
|||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import com.etheller.warsmash.networking.udp.OrderedUdpServer;
|
import com.etheller.warsmash.networking.udp.OrderedUdpServer;
|
||||||
import com.etheller.warsmash.util.WarsmashConstants;
|
import com.etheller.warsmash.util.WarsmashConstants;
|
||||||
@ -141,19 +139,19 @@ public class WarsmashServer implements ClientToServerListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void finishedTurn(final SocketAddress sourceAddress, final int clientGameTurnTick) {
|
public void finishedTurn(final SocketAddress sourceAddress, final int clientGameTurnTick) {
|
||||||
int gameTurnTick = clientGameTurnTick + MAGIC_DELAY_OFFSET;
|
final int gameTurnTick = clientGameTurnTick + MAGIC_DELAY_OFFSET;
|
||||||
if(WarsmashConstants.VERBOSE_LOGGING) {
|
if (WarsmashConstants.VERBOSE_LOGGING) {
|
||||||
System.out.println("finishedTurn(" + gameTurnTick + ") from " + sourceAddress);
|
System.out.println("finishedTurn(" + gameTurnTick + ") from " + sourceAddress);
|
||||||
}
|
}
|
||||||
if (!this.gameStarted) {
|
if (!this.gameStarted) {
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"Client should not send us finishedTurn() message when game has not started!");
|
"Client should not send us finishedTurn() message when game has not started!");
|
||||||
}
|
}
|
||||||
clientToTurnFinished.put(sourceAddress, clientGameTurnTick);
|
this.clientToTurnFinished.put(sourceAddress, clientGameTurnTick);
|
||||||
boolean allDone = true;
|
boolean allDone = true;
|
||||||
for(SocketAddress clientAddress: socketAddressToPlayerIndex.keySet()) {
|
for (final SocketAddress clientAddress : this.socketAddressToPlayerIndex.keySet()) {
|
||||||
Integer turnFinishedValue = clientToTurnFinished.get(clientAddress);
|
final Integer turnFinishedValue = this.clientToTurnFinished.get(clientAddress);
|
||||||
if(turnFinishedValue == null || turnFinishedValue < clientGameTurnTick) {
|
if ((turnFinishedValue == null) || (turnFinishedValue < clientGameTurnTick)) {
|
||||||
allDone = false;
|
allDone = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,13 +167,13 @@ public class WarsmashServer implements ClientToServerListener {
|
|||||||
@Override
|
@Override
|
||||||
public void framesSkipped(final int nFramesSkipped) {
|
public void framesSkipped(final int nFramesSkipped) {
|
||||||
// dont care for now
|
// dont care for now
|
||||||
long currentTimeMillis = System.currentTimeMillis();
|
final long currentTimeMillis = System.currentTimeMillis();
|
||||||
if(currentTimeMillis - lastServerHeartbeatTime > 3000) {
|
if ((currentTimeMillis - this.lastServerHeartbeatTime) > 3000) {
|
||||||
// 3 seconds of frame skipping, make sure we keep in contact with client
|
// 3 seconds of frame skipping, make sure we keep in contact with client
|
||||||
System.out.println("sending server heartbeat()");
|
System.out.println("sending server heartbeat()");
|
||||||
WarsmashServer.this.writer.heartbeat();
|
WarsmashServer.this.writer.heartbeat();
|
||||||
WarsmashServer.this.writer.send();
|
WarsmashServer.this.writer.send();
|
||||||
lastServerHeartbeatTime = currentTimeMillis;
|
this.lastServerHeartbeatTime = currentTimeMillis;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user