Implemented leaky liquid explosions / New entity save system

This commit is contained in:
Anuken
2018-04-16 22:46:16 -04:00
parent a4962c5225
commit 0bebe5008b
7 changed files with 141 additions and 102 deletions

View File

@@ -23,8 +23,14 @@ import io.anuke.ucore.core.Settings;
import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.graphics.Draw;
import io.anuke.ucore.util.*;
import io.anuke.ucore.util.Angles;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timer;
import io.anuke.ucore.util.Translator;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.*;
@@ -306,6 +312,26 @@ public class Player extends Unit{
return "Player{" + id + ", mech=" + mech.name + ", local=" + isLocal + ", " + x + ", " + y + "}\n";
}
@Override
public void writeSave(DataOutputStream stream) throws IOException {
stream.writeBoolean(isLocal);
if(isLocal) super.writeSave(stream);
}
@Override
public void readSave(DataInputStream stream) throws IOException {
boolean local = stream.readBoolean();
if(local){
player.readSaveSuper(stream);
}
}
private void readSaveSuper(DataInputStream stream) throws IOException {
super.readSave(stream);
add();
}
@Override
public void writeSpawn(ByteBuffer buffer) {
buffer.put((byte)name.getBytes().length);

View File

@@ -0,0 +1,11 @@
package io.anuke.mindustry.entities;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
/**Marks an entity as serializable.*/
public interface SerializableEntity {
void writeSave(DataOutputStream stream) throws IOException;
void readSave(DataInputStream stream) throws IOException;
}

View File

@@ -10,10 +10,14 @@ import io.anuke.ucore.core.Timers;
import io.anuke.ucore.entities.SolidEntity;
import io.anuke.ucore.util.Mathf;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import static io.anuke.mindustry.Vars.state;
import static io.anuke.mindustry.Vars.world;
public abstract class Unit extends SyncEntity {
public abstract class Unit extends SyncEntity implements SerializableEntity {
//total duration of hit effect
public static final float hitDuration = 9f;
@@ -42,6 +46,32 @@ public abstract class Unit extends SyncEntity {
status.clear();
}
@Override
public void writeSave(DataOutputStream stream) throws IOException {
stream.writeByte(team.ordinal());
stream.writeFloat(x);
stream.writeFloat(y);
stream.writeShort((short)health);
stream.writeByte(status.current().id);
stream.writeFloat(status.getTime());
}
@Override
public void readSave(DataInputStream stream) throws IOException {
byte team = stream.readByte();
float x = stream.readFloat();
float y = stream.readFloat();
int health = stream.readShort();
byte effect = stream.readByte();
float etime = stream.readFloat();
this.team = Team.values()[team];
this.health = health;
this.x = x;
this.y = y;
this.status.set(StatusEffect.getByID(effect), etime);
}
public Floor getFloorOn(){
Tile tile = world.tileWorld(x, y);
return (Floor)(tile == null || (!(tile.floor() instanceof Floor)) ? Blocks.defaultFloor : tile.floor());

View File

@@ -1,18 +1,19 @@
package io.anuke.mindustry.entities.units;
import io.anuke.mindustry.entities.Bullet;
import io.anuke.mindustry.entities.BulletType;
import io.anuke.mindustry.entities.Unit;
import io.anuke.mindustry.entities.*;
import io.anuke.mindustry.game.Team;
import io.anuke.ucore.entities.Entity;
import io.anuke.ucore.util.Mathf;
import io.anuke.ucore.util.Timer;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import static io.anuke.mindustry.Vars.unitGroups;
public class BaseUnit extends Unit {
public class BaseUnit extends Unit{
public UnitType type;
public Timer timer = new Timer(5);
public float walkTime = 0f;
@@ -109,6 +110,21 @@ public class BaseUnit extends Unit {
return add(unitGroups[team.ordinal()]);
}
@Override
public void writeSave(DataOutputStream stream) throws IOException {
super.writeSave(stream);
stream.writeByte(type.id);
}
@Override
public void readSave(DataInputStream stream) throws IOException {
super.readSave(stream);
byte type = stream.readByte();
this.type = UnitType.getByID(type);
add(unitGroups[team.ordinal()]);
}
@Override
public void writeSpawn(ByteBuffer buffer) {
buffer.put(type.id);