Rudimentary visibility saving

This commit is contained in:
Anuken
2022-03-02 16:15:59 -05:00
parent 6d568318f9
commit d9ced82352
3 changed files with 17 additions and 3 deletions

View File

@@ -33,6 +33,7 @@ public class RtsAI{
//in order of priority??
static final BlockFlag[] flags = {BlockFlag.generator, BlockFlag.factory, BlockFlag.core, BlockFlag.battery};
static final ObjectFloatMap<Building> weights = new ObjectFloatMap<>();
//TODO configurable, perhaps
static final int minSquadSize = 4;
//TODO max squad size
static final boolean debug = OS.hasProp("mindustry.debug");

View File

@@ -70,7 +70,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
transient boolean wasDamaged; //used only by the indexer
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 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
public final void writeBase(Writes write){
boolean writeVisibility = state.rules.fog && visibleFlags != 0;
write.f(health);
write.b(rotation | 0b10000000);
write.b(team.id);
write.b(3); //version
write.b(writeVisibility ? 4 : 3); //version
write.b(enabled ? 1 : 0);
//write presence of items/power/liquids/cons, so removing/adding them does not corrupt future saves.
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
write.b((byte)(Mathf.clamp(efficiency) * 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){
@@ -220,6 +227,11 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
efficiency = 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(){

View File

@@ -83,7 +83,7 @@ public class BlockRenderer{
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;
}
@@ -416,6 +416,7 @@ public class BlockRenderer{
updateShadow(build);
renderer.minimap.update(tile);
}
build.visibleFlags |= (1L << player.team().id);
build.wasVisible = true;
}