Save efficiency
This commit is contained in:
@@ -73,9 +73,6 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
transient boolean wasVisible; //used only by the block renderer when fog is on
|
transient boolean wasVisible; //used only by the block renderer when fog is on
|
||||||
transient float visualLiquid;
|
transient float visualLiquid;
|
||||||
|
|
||||||
//TODO save efficiency too!
|
|
||||||
//transient boolean consValid;
|
|
||||||
|
|
||||||
@Nullable PowerModule power;
|
@Nullable PowerModule power;
|
||||||
@Nullable ItemModule items;
|
@Nullable ItemModule items;
|
||||||
@Nullable LiquidModule liquids;
|
@Nullable LiquidModule liquids;
|
||||||
@@ -167,14 +164,17 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
write.f(health);
|
write.f(health);
|
||||||
write.b(rotation | 0b10000000);
|
write.b(rotation | 0b10000000);
|
||||||
write.b(team.id);
|
write.b(team.id);
|
||||||
write.b(2); //version
|
write.b(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());
|
||||||
if(items != null) items.write(write);
|
if(items != null) items.write(write);
|
||||||
if(power != null) power.write(write);
|
if(power != null) power.write(write);
|
||||||
if(liquids != null) liquids.write(write);
|
if(liquids != null) liquids.write(write);
|
||||||
write.bool(false);
|
|
||||||
|
//efficiency is written as two bytes to save space
|
||||||
|
write.b((byte)(Mathf.clamp(efficiency) * 255f));
|
||||||
|
write.b((byte)(Mathf.clamp(optionalEfficiency) * 255f));
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void readBase(Reads read){
|
public final void readBase(Reads read){
|
||||||
@@ -187,13 +187,14 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
|
|
||||||
int moduleBits = moduleBitmask();
|
int moduleBits = moduleBitmask();
|
||||||
boolean legacy = true;
|
boolean legacy = true;
|
||||||
|
byte version = 0;
|
||||||
|
|
||||||
//TODO new version with efficiency instead of consValid
|
//TODO new version with efficiency instead of consValid
|
||||||
|
|
||||||
//new version
|
//new version
|
||||||
if((rot & 0b10000000) != 0){
|
if((rot & 0b10000000) != 0){
|
||||||
byte ver = read.b(); //version of entity save
|
version = read.b(); //version of entity save
|
||||||
if(ver >= 1){
|
if(version >= 1){
|
||||||
byte on = read.b();
|
byte on = read.b();
|
||||||
this.enabled = on == 1;
|
this.enabled = on == 1;
|
||||||
if(!this.enabled){
|
if(!this.enabled){
|
||||||
@@ -202,7 +203,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
//get which modules should actually be read; this was added in version 2
|
//get which modules should actually be read; this was added in version 2
|
||||||
if(ver >= 2){
|
if(version >= 2){
|
||||||
moduleBits = read.b();
|
moduleBits = read.b();
|
||||||
}
|
}
|
||||||
legacy = false;
|
legacy = false;
|
||||||
@@ -211,7 +212,15 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
if((moduleBits & 1) != 0) (items == null ? new ItemModule() : items).read(read, legacy);
|
if((moduleBits & 1) != 0) (items == null ? new ItemModule() : items).read(read, legacy);
|
||||||
if((moduleBits & 2) != 0) (power == null ? new PowerModule() : power).read(read, legacy);
|
if((moduleBits & 2) != 0) (power == null ? new PowerModule() : power).read(read, legacy);
|
||||||
if((moduleBits & 4) != 0) (liquids == null ? new LiquidModule() : liquids).read(read, legacy);
|
if((moduleBits & 4) != 0) (liquids == null ? new LiquidModule() : liquids).read(read, legacy);
|
||||||
if((moduleBits & 8) != 0) read.bool();
|
|
||||||
|
//unnecessary consume module read in version 2
|
||||||
|
if(version == 2) read.bool();
|
||||||
|
|
||||||
|
//version 3 has efficiency numbers instead of bools
|
||||||
|
if(version >= 3){
|
||||||
|
efficiency = read.ub() / 255f;
|
||||||
|
optionalEfficiency = read.ub() / 255f;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int moduleBitmask(){
|
public int moduleBitmask(){
|
||||||
@@ -1680,7 +1689,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
|
|
||||||
/** @return ambient sound volume scale. */
|
/** @return ambient sound volume scale. */
|
||||||
public float ambientVolume(){
|
public float ambientVolume(){
|
||||||
return efficiency();
|
return efficiency;
|
||||||
}
|
}
|
||||||
|
|
||||||
//endregion
|
//endregion
|
||||||
@@ -1751,7 +1760,7 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
|
|||||||
case team -> team.id;
|
case team -> team.id;
|
||||||
case health -> health;
|
case health -> health;
|
||||||
case maxHealth -> maxHealth;
|
case maxHealth -> maxHealth;
|
||||||
case efficiency -> efficiency();
|
case efficiency -> efficiency;
|
||||||
case timescale -> timeScale;
|
case timescale -> timeScale;
|
||||||
case range -> this instanceof Ranged r ? r.range() / tilesize : 0;
|
case range -> this instanceof Ranged r ? r.range() / tilesize : 0;
|
||||||
case rotation -> rotation;
|
case rotation -> rotation;
|
||||||
|
|||||||
@@ -282,7 +282,7 @@ public class SectorDamage{
|
|||||||
|
|
||||||
//block dps + regen + extra health/shields
|
//block dps + regen + extra health/shields
|
||||||
for(Building build : Groups.build){
|
for(Building build : Groups.build){
|
||||||
float e = build.efficiency();
|
float e = build.efficiency;
|
||||||
if(e > 0.08f){
|
if(e > 0.08f){
|
||||||
if(build.team == state.rules.defaultTeam && build instanceof Ranged ranged && sparse.contains(t -> t.within(build, ranged.range() + 4*tilesize))){
|
if(build.team == state.rules.defaultTeam && build instanceof Ranged ranged && sparse.contains(t -> t.within(build, ranged.range() + 4*tilesize))){
|
||||||
//TODO make sure power turret network supports the turrets?
|
//TODO make sure power turret network supports the turrets?
|
||||||
|
|||||||
Reference in New Issue
Block a user