Rudimentary visibility saving
This commit is contained in:
@@ -33,6 +33,7 @@ public class RtsAI{
|
|||||||
//in order of priority??
|
//in order of priority??
|
||||||
static final BlockFlag[] flags = {BlockFlag.generator, BlockFlag.factory, BlockFlag.core, BlockFlag.battery};
|
static final BlockFlag[] flags = {BlockFlag.generator, BlockFlag.factory, BlockFlag.core, BlockFlag.battery};
|
||||||
static final ObjectFloatMap<Building> weights = new ObjectFloatMap<>();
|
static final ObjectFloatMap<Building> weights = new ObjectFloatMap<>();
|
||||||
|
//TODO configurable, perhaps
|
||||||
static final int minSquadSize = 4;
|
static final int minSquadSize = 4;
|
||||||
//TODO max squad size
|
//TODO max squad size
|
||||||
static final boolean debug = OS.hasProp("mindustry.debug");
|
static final boolean debug = OS.hasProp("mindustry.debug");
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
transient boolean wasDamaged; //used only by the indexer
|
transient boolean wasDamaged; //used only by the indexer
|
||||||
transient float visualLiquid;
|
transient float visualLiquid;
|
||||||
|
|
||||||
/** TODO Each bit corresponds to a team ID. Only 64 are supported. */
|
/** TODO Each bit corresponds to a team ID. Only 64 are supported. Does not work on servers. */
|
||||||
transient long visibleFlags;
|
transient long visibleFlags;
|
||||||
transient boolean wasVisible; //used only by the block renderer when fog is on (TODO replace with discovered check?)
|
transient boolean wasVisible; //used only by the block renderer when fog is on (TODO replace with discovered check?)
|
||||||
|
|
||||||
@@ -165,10 +165,12 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
//region io
|
//region io
|
||||||
|
|
||||||
public final void writeBase(Writes write){
|
public final void writeBase(Writes write){
|
||||||
|
boolean writeVisibility = state.rules.fog && visibleFlags != 0;
|
||||||
|
|
||||||
write.f(health);
|
write.f(health);
|
||||||
write.b(rotation | 0b10000000);
|
write.b(rotation | 0b10000000);
|
||||||
write.b(team.id);
|
write.b(team.id);
|
||||||
write.b(3); //version
|
write.b(writeVisibility ? 4 : 3); //version
|
||||||
write.b(enabled ? 1 : 0);
|
write.b(enabled ? 1 : 0);
|
||||||
//write presence of items/power/liquids/cons, so removing/adding them does not corrupt future saves.
|
//write presence of items/power/liquids/cons, so removing/adding them does not corrupt future saves.
|
||||||
write.b(moduleBitmask());
|
write.b(moduleBitmask());
|
||||||
@@ -179,6 +181,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
//efficiency is written as two bytes to save space
|
//efficiency is written as two bytes to save space
|
||||||
write.b((byte)(Mathf.clamp(efficiency) * 255f));
|
write.b((byte)(Mathf.clamp(efficiency) * 255f));
|
||||||
write.b((byte)(Mathf.clamp(optionalEfficiency) * 255f));
|
write.b((byte)(Mathf.clamp(optionalEfficiency) * 255f));
|
||||||
|
|
||||||
|
//only write visibility when necessary, saving 8 bytes - implies new version
|
||||||
|
if(writeVisibility){
|
||||||
|
write.l(visibleFlags);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void readBase(Reads read){
|
public final void readBase(Reads read){
|
||||||
@@ -220,6 +227,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
efficiency = read.ub() / 255f;
|
efficiency = read.ub() / 255f;
|
||||||
optionalEfficiency = read.ub() / 255f;
|
optionalEfficiency = read.ub() / 255f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//version 4 (and only 4 at the moment) has visibility flags
|
||||||
|
if(version == 4){
|
||||||
|
visibleFlags = read.l();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int moduleBitmask(){
|
public int moduleBitmask(){
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ public class BlockRenderer{
|
|||||||
updateFloors.add(new UpdateRenderState(tile, tile.floor()));
|
updateFloors.add(new UpdateRenderState(tile, tile.floor()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tile.build != null && (tile.team() == player.team() || !state.rules.fog)){
|
if(tile.build != null && (tile.team() == player.team() || !state.rules.fog || (tile.build.visibleFlags & (1L << player.team().id)) != 0)){
|
||||||
tile.build.wasVisible = true;
|
tile.build.wasVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,6 +416,7 @@ public class BlockRenderer{
|
|||||||
updateShadow(build);
|
updateShadow(build);
|
||||||
renderer.minimap.update(tile);
|
renderer.minimap.update(tile);
|
||||||
}
|
}
|
||||||
|
build.visibleFlags |= (1L << player.team().id);
|
||||||
build.wasVisible = true;
|
build.wasVisible = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user