Implemented sector state network sync

This commit is contained in:
Anuken
2018-10-20 18:41:05 -04:00
parent e6f076306f
commit 4668a6d8c0
3 changed files with 46 additions and 24 deletions

View File

@@ -1,6 +1,8 @@
package io.anuke.mindustry.core;
import com.badlogic.gdx.utils.Array;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.entities.TileEntity;
@@ -19,6 +21,7 @@ import io.anuke.ucore.entities.EntityQuery;
import io.anuke.ucore.modules.Module;
import static io.anuke.mindustry.Vars.*;
import io.anuke.mindustry.gen.Call;
/**
* Logic module.
@@ -108,28 +111,44 @@ public class Logic extends Module{
//check unlocked sectors
while(!world.getSector().complete && world.getSector().currentMission().isComplete()){
world.getSector().currentMission().onComplete();
world.getSector().completedMissions ++;
state.mode = world.getSector().currentMission().getMode();
world.getSector().currentMission().onBegin();
world.sectors.save();
Call.onMissionFinish(world.getSector().completedMissions);
}
//check if all assigned missions are complete
if(!world.getSector().complete && world.getSector().completedMissions >= world.getSector().missions.size){
state.mode = GameMode.victory;
world.sectors.completeSector(world.getSector().x, world.getSector().y);
world.sectors.save();
if(!headless){
ui.missions.show(world.getSector());
}
Events.fire(new SectorCompleteEvent());
Call.onSectorComplete();
}
}
@Remote(called = Loc.both)
public static void onGameOver(Team winner){
threads.runGraphics(() -> ui.restart.show(winner));
netClient.setQuiet();
}
@Remote(called = Loc.server)
public static void onMissionFinish(int index){
world.getSector().missions.get(index).onComplete();
world.getSector().completedMissions = index + 1;
state.mode = world.getSector().currentMission().getMode();
world.getSector().currentMission().onBegin();
world.sectors.save();
}
@Remote(called = Loc.server)
public static void onSectorComplete(){
state.mode = GameMode.victory;
world.sectors.completeSector(world.getSector().x, world.getSector().y);
world.sectors.save();
if(!headless){
ui.missions.show(world.getSector());
}
Events.fire(new SectorCompleteEvent());
}
@Override
public void update(){
if(threads.isEnabled() && !threads.isOnThread()) return;
@@ -144,9 +163,8 @@ public class Logic extends Module{
Timers.update();
}
updateSectors();
if(!Net.client() && !world.isInvalidMap()){
updateSectors();
checkGameOver();
}

View File

@@ -415,12 +415,6 @@ public class NetServer extends Module{
Log.info("&y{0} has connected.", player.name);
}
@Remote(called = Loc.both)
public static void onGameOver(Team winner){
threads.runGraphics(() -> ui.restart.show(winner));
netClient.setQuiet();
}
public boolean isWaitingForPlayers(){
return state.mode.isPvp && playerGroup.size() < 2;
}

View File

@@ -36,6 +36,8 @@ public class NetworkIO{
//--GENERAL STATE--
stream.writeByte(state.mode.ordinal()); //gamemode
stream.writeUTF(world.getMap().name); //map name
stream.writeInt(world.getSector() == null ? invalidSector : world.getSector().packedPosition()); //sector ID
stream.writeInt(world.getSector() == null ? 0 : world.getSector().completedMissions);
//write tags
ObjectMap<String, String> tags = world.getMap().meta.tags;
@@ -163,6 +165,15 @@ public class NetworkIO{
//general state
byte mode = stream.readByte();
String map = stream.readUTF();
int sector = stream.readInt();
int missions = stream.readInt();
if(sector != invalidSector){
world.sectors.createSector(Bits.getLeftShort(sector), Bits.getRightShort(sector));
world.setSector(world.sectors.get(sector));
world.getSector().completedMissions = missions;
}
ObjectMap<String, String> tags = new ObjectMap<>();
byte tagSize = stream.readByte();
@@ -195,7 +206,6 @@ public class NetworkIO{
Map currentMap = new Map(map, new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null);
currentMap.meta.tags.clear();
currentMap.meta.tags.putAll(tags);
world.setSector(null);
world.setMap(currentMap);
Tile[][] tiles = world.createTiles(width, height);