mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-12-15 15:20:57 -08:00
Removed serverPaused
This commit is contained in:
parent
bc2664994e
commit
7f37b97861
7 changed files with 37 additions and 25 deletions
|
|
@ -269,6 +269,9 @@ public class Control implements ApplicationListener, Loadable{
|
||||||
|
|
||||||
Events.on(SaveWriteEvent.class, e -> forcePlaceAll());
|
Events.on(SaveWriteEvent.class, e -> forcePlaceAll());
|
||||||
Events.on(HostEvent.class, e -> forcePlaceAll());
|
Events.on(HostEvent.class, e -> forcePlaceAll());
|
||||||
|
Events.on(HostEvent.class, e -> {
|
||||||
|
state.set(State.playing);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void forcePlaceAll(){
|
private void forcePlaceAll(){
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,6 @@ public class GameState{
|
||||||
public boolean gameOver = false;
|
public boolean gameOver = false;
|
||||||
/** Whether the player's team won the match. */
|
/** Whether the player's team won the match. */
|
||||||
public boolean won = false;
|
public boolean won = false;
|
||||||
/** If true, the server has been put into the paused state on multiplayer. This is synced. */
|
|
||||||
public boolean serverPaused = false;
|
|
||||||
/** Server ticks/second. Only valid in multiplayer. */
|
/** Server ticks/second. Only valid in multiplayer. */
|
||||||
public int serverTps = -1;
|
public int serverTps = -1;
|
||||||
/** Map that is currently being played on. */
|
/** Map that is currently being played on. */
|
||||||
|
|
@ -51,12 +49,8 @@ public class GameState{
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(State astate){
|
public void set(State astate){
|
||||||
//horrible horrible horrible
|
//nothing to change.
|
||||||
if(astate == State.paused && net.server() && !headless) serverPaused = true;
|
if(state == astate) return;
|
||||||
if(astate != State.paused && net.server() && !headless) serverPaused = false;
|
|
||||||
|
|
||||||
//cannot pause when in multiplayer
|
|
||||||
if(astate == State.paused && net.active()) return;
|
|
||||||
|
|
||||||
Events.fire(new StateChangeEvent(state, astate));
|
Events.fire(new StateChangeEvent(state, astate));
|
||||||
state = astate;
|
state = astate;
|
||||||
|
|
@ -88,7 +82,7 @@ public class GameState{
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPaused(){
|
public boolean isPaused(){
|
||||||
return (is(State.paused) && !net.active()) || (serverPaused && !isMenu());
|
return is(State.paused);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlaying(){
|
public boolean isPlaying(){
|
||||||
|
|
|
||||||
|
|
@ -488,7 +488,9 @@ public class NetClient implements ApplicationListener{
|
||||||
state.wavetime = waveTime;
|
state.wavetime = waveTime;
|
||||||
state.wave = wave;
|
state.wave = wave;
|
||||||
state.enemies = enemies;
|
state.enemies = enemies;
|
||||||
state.serverPaused = paused;
|
if(!state.isMenu()){
|
||||||
|
state.set(paused ? State.paused : State.playing);
|
||||||
|
}
|
||||||
state.serverTps = tps & 0xff;
|
state.serverTps = tps & 0xff;
|
||||||
|
|
||||||
//note that this is far from a guarantee that random state is synced - tiny changes in delta and ping can throw everything off again.
|
//note that this is far from a guarantee that random state is synced - tiny changes in delta and ping can throw everything off again.
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@ public class NetServer implements ApplicationListener{
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private boolean closing = false;
|
private boolean closing = false, pvpAutoPaused = true;
|
||||||
private Interval timer = new Interval(10);
|
private Interval timer = new Interval(10);
|
||||||
private IntSet buildHealthChanged = new IntSet();
|
private IntSet buildHealthChanged = new IntSet();
|
||||||
|
|
||||||
|
|
@ -862,7 +862,18 @@ public class NetServer implements ApplicationListener{
|
||||||
|
|
||||||
if(state.isGame() && net.server()){
|
if(state.isGame() && net.server()){
|
||||||
if(state.rules.pvp){
|
if(state.rules.pvp){
|
||||||
state.serverPaused = isWaitingForPlayers();
|
boolean waiting = isWaitingForPlayers(), paused = state.isPaused();
|
||||||
|
if(waiting != paused){
|
||||||
|
if(waiting){
|
||||||
|
//is now waiting, enable pausing, flag it correctly
|
||||||
|
pvpAutoPaused = true;
|
||||||
|
state.set(State.paused);
|
||||||
|
}else if(pvpAutoPaused){
|
||||||
|
//no longer waiting, stop pausing
|
||||||
|
state.set(State.playing);
|
||||||
|
pvpAutoPaused = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
sync();
|
sync();
|
||||||
|
|
@ -941,7 +952,7 @@ public class NetServer implements ApplicationListener{
|
||||||
dataStream.close();
|
dataStream.close();
|
||||||
|
|
||||||
//write basic state data.
|
//write basic state data.
|
||||||
Call.stateSnapshot(player.con, state.wavetime, state.wave, state.enemies, state.serverPaused, state.gameOver,
|
Call.stateSnapshot(player.con, state.wavetime, state.wave, state.enemies, state.isPaused(), state.gameOver,
|
||||||
universe.seconds(), tps, GlobalVars.rand.seed0, GlobalVars.rand.seed1, syncStream.toByteArray());
|
universe.seconds(), tps, GlobalVars.rand.seed0, GlobalVars.rand.seed1, syncStream.toByteArray());
|
||||||
|
|
||||||
syncStream.reset();
|
syncStream.reset();
|
||||||
|
|
|
||||||
|
|
@ -116,13 +116,13 @@ public class LogicDialog extends BaseDialog{
|
||||||
buttons.button("@variables", Icon.menu, () -> {
|
buttons.button("@variables", Icon.menu, () -> {
|
||||||
BaseDialog dialog = new BaseDialog("@variables");
|
BaseDialog dialog = new BaseDialog("@variables");
|
||||||
dialog.hidden(() -> {
|
dialog.hidden(() -> {
|
||||||
if(!wasPaused){
|
if(!wasPaused && !net.active()){
|
||||||
state.set(State.paused);
|
state.set(State.paused);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
dialog.shown(() -> {
|
dialog.shown(() -> {
|
||||||
if(!wasPaused){
|
if(!wasPaused && !net.active()){
|
||||||
state.set(State.playing);
|
state.set(State.playing);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -24,10 +24,8 @@ public class BaseDialog extends Dialog{
|
||||||
.growX().height(3f).pad(4f);
|
.growX().height(3f).pad(4f);
|
||||||
|
|
||||||
hidden(() -> {
|
hidden(() -> {
|
||||||
if(shouldPause && state.isGame() && !net.active()){
|
if(shouldPause && state.isGame() && !net.active() && !wasPaused){
|
||||||
if(!wasPaused || net.active()){
|
state.set(State.playing);
|
||||||
state.set(State.playing);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Sounds.back.play();
|
Sounds.back.play();
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -272,8 +272,8 @@ public class ServerControl implements ApplicationListener{
|
||||||
});
|
});
|
||||||
|
|
||||||
Events.on(PlayerJoin.class, e -> {
|
Events.on(PlayerJoin.class, e -> {
|
||||||
if(state.serverPaused && autoPaused && Config.autoPause.bool()){
|
if(state.isPaused() && autoPaused && Config.autoPause.bool()){
|
||||||
state.serverPaused = false;
|
state.set(State.playing);
|
||||||
autoPaused = false;
|
autoPaused = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -281,8 +281,8 @@ public class ServerControl implements ApplicationListener{
|
||||||
Events.on(PlayerLeave.class, e -> {
|
Events.on(PlayerLeave.class, e -> {
|
||||||
// The player list length is compared with 1 and not 0 here,
|
// The player list length is compared with 1 and not 0 here,
|
||||||
// because when PlayerLeave gets fired, the player hasn't been removed from the player list yet
|
// because when PlayerLeave gets fired, the player hasn't been removed from the player list yet
|
||||||
if(!state.serverPaused && Config.autoPause.bool() && Groups.player.size() == 1){
|
if(!state.isPaused() && Config.autoPause.bool() && Groups.player.size() == 1){
|
||||||
state.serverPaused = true;
|
state.set(State.paused);
|
||||||
autoPaused = true;
|
autoPaused = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -372,7 +372,7 @@ public class ServerControl implements ApplicationListener{
|
||||||
netServer.openServer();
|
netServer.openServer();
|
||||||
|
|
||||||
if(Config.autoPause.bool()){
|
if(Config.autoPause.bool()){
|
||||||
state.serverPaused = true;
|
state.set(State.paused);
|
||||||
autoPaused = true;
|
autoPaused = true;
|
||||||
}
|
}
|
||||||
}catch(MapException e){
|
}catch(MapException e){
|
||||||
|
|
@ -489,9 +489,13 @@ public class ServerControl implements ApplicationListener{
|
||||||
});
|
});
|
||||||
|
|
||||||
handler.register("pause", "<on/off>", "Pause or unpause the game.", arg -> {
|
handler.register("pause", "<on/off>", "Pause or unpause the game.", arg -> {
|
||||||
|
if(!state.isMenu()){
|
||||||
|
err("Cannot pause without a game running.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
boolean pause = arg[0].equals("on");
|
boolean pause = arg[0].equals("on");
|
||||||
autoPaused = false;
|
autoPaused = false;
|
||||||
state.serverPaused = pause;
|
state.set(state.isPaused() ? State.playing : State.paused);
|
||||||
info(pause ? "Game paused." : "Game unpaused.");
|
info(pause ? "Game paused." : "Game unpaused.");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue