Sync/save @tick/@time; make @time be based off of @tick

Closes Anuken/Mindustry-Suggestions/issues/2976
This commit is contained in:
Anuken 2021-09-22 19:35:15 -04:00
parent 6d41b894ab
commit 3f6d5b9dfe
5 changed files with 13 additions and 3 deletions

View File

@ -16,6 +16,8 @@ public class GameState{
public int wave = 1;
/** Wave countdown in ticks. */
public float wavetime;
/** Logic tick. */
public double tick;
/** Whether the game is in game over state. */
public boolean gameOver = false, serverPaused = false;
/** Server ticks/second. Only valid in multiplayer. */

View File

@ -370,6 +370,9 @@ public class Logic implements ApplicationListener{
}
if(!state.isPaused()){
float delta = Core.graphics.getDeltaTime();
state.tick += Float.isNaN(delta) || Float.isInfinite(delta) ? 0f : delta * 60f;
state.teams.updateTeamStats();
if(state.isCampaign()){

View File

@ -92,6 +92,7 @@ public abstract class SaveVersion extends SaveFileReader{
"build", Version.build,
"mapname", state.map.name(),
"wave", state.wave,
"tick", state.tick,
"wavetime", state.wavetime,
"stats", JsonIO.write(state.stats),
"rules", JsonIO.write(state.rules),
@ -110,6 +111,7 @@ public abstract class SaveVersion extends SaveFileReader{
state.wave = map.getInt("wave");
state.wavetime = map.getFloat("wavetime", state.rules.waveSpacing);
state.tick = map.getFloat("tick");
state.stats = JsonIO.read(GameStats.class, map.get("stats", "{}"));
state.rules = JsonIO.read(Rules.class, map.get("rules", "{}"));
if(state.rules.spawns.isEmpty()) state.rules.spawns = waves.get();

View File

@ -57,9 +57,10 @@ public class LExecutor{
/** Runs a single instruction. */
public void runOnce(){
//set time
vars[varTime].numval = Time.millis();
vars[varTick].numval = Time.time;
//set up time; note that @time is now only updated once every invocation and directly based off of @tick.
//having time be based off of user system time was a very bad idea.
vars[varTime].numval = state.tick / 60.0 * 1000.0;
vars[varTick].numval = state.tick;
//reset to start
if(vars[varCounter].numval >= instructions.length || vars[varCounter].numval < 0){

View File

@ -40,6 +40,7 @@ public class NetworkIO{
stream.writeInt(state.wave);
stream.writeFloat(state.wavetime);
stream.writeDouble(state.tick);
stream.writeInt(player.id);
player.write(Writes.get(stream));
@ -61,6 +62,7 @@ public class NetworkIO{
state.wave = stream.readInt();
state.wavetime = stream.readFloat();
state.tick = stream.readDouble();
Groups.clear();
int id = stream.readInt();