Serialization that makes more sense

This commit is contained in:
Anuken
2020-05-08 20:22:11 -04:00
parent aab97fefc8
commit 8d5cd7b814
10 changed files with 36 additions and 22 deletions
@@ -0,0 +1 @@
{version:1,fields:[{name:intensity,type:float,size:4},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
@@ -0,0 +1 @@
{version:2,fields:[{name:intensity,type:float,size:4},{name:opacity,type:float,size:4},{name:weather,type:mindustry.type.Weather,size:-1},{name:x,type:float,size:4},{name:y,type:float,size:4}]}
@@ -13,7 +13,7 @@ import mindustry.graphics.*;
import static mindustry.Vars.*; import static mindustry.Vars.*;
@EntityDef(value = {Bulletc.class}, pooled = true) @EntityDef(value = {Bulletc.class}, pooled = true, serialize = false)
@Component @Component
abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc{ abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc{
@Import Team team; @Import Team team;
@@ -7,7 +7,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*; import mindustry.graphics.*;
@EntityDef(value = {Decalc.class}, pooled = true) @EntityDef(value = {Decalc.class}, pooled = true, serialize = false)
@Component @Component
abstract class DecalComp implements Drawc, Timedc, Rotc, Posc{ abstract class DecalComp implements Drawc, Timedc, Rotc, Posc{
@Import float x, y, rotation; @Import float x, y, rotation;
@@ -1,13 +1,11 @@
package mindustry.entities.def; package mindustry.entities.def;
import arc.graphics.*; import arc.graphics.*;
import arc.graphics.g2d.*;
import mindustry.annotations.Annotations.*; import mindustry.annotations.Annotations.*;
import mindustry.entities.*; import mindustry.entities.*;
import mindustry.gen.*; import mindustry.gen.*;
import mindustry.graphics.*;
@EntityDef(value = {Effectc.class, Childc.class}, pooled = true) @EntityDef(value = {Effectc.class, Childc.class}, pooled = true, serialize = false)
@Component @Component
abstract class EffectComp implements Posc, Drawc, Timedc, Rotc, Childc{ abstract class EffectComp implements Posc, Drawc, Timedc, Rotc, Childc{
Color color = new Color(Color.white); Color color = new Color(Color.white);
+5 -5
View File
@@ -252,8 +252,8 @@ public abstract class SaveVersion extends SaveFileReader{
} }
} }
stream.writeInt(Groups.sync.count(Entityc::serialize)); stream.writeInt(Groups.all.count(Entityc::serialize));
for(Syncc entity : Groups.sync){ for(Entityc entity : Groups.all){
if(!entity.serialize()) continue; if(!entity.serialize()) continue;
writeChunk(stream, true, out -> { writeChunk(stream, true, out -> {
@@ -278,9 +278,9 @@ public abstract class SaveVersion extends SaveFileReader{
for(int j = 0; j < amount; j++){ for(int j = 0; j < amount; j++){
readChunk(stream, true, in -> { readChunk(stream, true, in -> {
byte typeid = in.readByte(); byte typeid = in.readByte();
Syncc sync = (Syncc)EntityMapping.map(typeid).get(); Entityc entity = (Entityc)EntityMapping.map(typeid).get();
sync.read(Reads.get(in)); entity.read(Reads.get(in));
sync.add(); entity.add();
}); });
} }
} }
+9
View File
@@ -259,6 +259,15 @@ public class TypeIO{
return id == -1 ? null : content.item(id); return id == -1 ? null : content.item(id);
} }
public static void writeWeather(Writes write, Weather item){
write.s(item == null ? -1 : item.id);
}
public static Weather readWeather(Reads read){
short id = read.s();
return id == -1 ? null : content.getByID(ContentType.weather, id);
}
public static void writeString(Writes write, String string){ public static void writeString(Writes write, String string){
if(string != null){ if(string != null){
byte[] bytes = string.getBytes(charset); byte[] bytes = string.getBytes(charset);
+1 -1
View File
@@ -19,7 +19,7 @@ import java.util.regex.*;
public class Scripts implements Disposable{ public class Scripts implements Disposable{
private final Array<String> blacklist = Array.with("net", "files", "reflect", "javax", "rhino", "file", "channels", "jdk", private final Array<String> blacklist = Array.with("net", "files", "reflect", "javax", "rhino", "file", "channels", "jdk",
"runtime", "util.os", "rmi", "security", "org.", "sun.", "beans", "sql", "http", "exec", "compiler", "process", "system", "runtime", "util.os", "rmi", "security", "org.", "sun.", "beans", "sql", "http", "exec", "compiler", "process", "system",
".awt", "socket", "classloader", "oracle", "invoke", "arc.events"); ".awt", "socket", "classloader", "oracle", "invoke", "arc.events", "java.util.function", "java.util.stream");
private final Array<String> whitelist = Array.with("mindustry.net", "netserver", "netclient", "com.sun.proxy.$proxy"); private final Array<String> whitelist = Array.with("mindustry.net", "netserver", "netclient", "com.sun.proxy.$proxy");
private final Context context; private final Context context;
private Scriptable scope; private Scriptable scope;
+7 -2
View File
@@ -52,17 +52,22 @@ public abstract class Weather extends MappableContent{
@Component @Component
abstract class WeatherComp implements Posc, Drawc{ abstract class WeatherComp implements Posc, Drawc{
Weather weather; Weather weather;
float intensity = 1f; float intensity = 1f, opacity = 1f;
void init(Weather weather){ void init(Weather weather){
this.weather = weather; this.weather = weather;
} }
@Override
public void update(){
weather.update((Weatherc)this);
}
@Override @Override
public void draw(){ public void draw(){
if(renderer.weatherAlpha() > 0.0001f){ if(renderer.weatherAlpha() > 0.0001f){
Draw.draw(Layer.weather, () -> { Draw.draw(Layer.weather, () -> {
Draw.alpha(renderer.weatherAlpha()); Draw.alpha(renderer.weatherAlpha() * opacity);
weather.draw((Weatherc)this); weather.draw((Weatherc)this);
Draw.reset(); Draw.reset();
}); });
@@ -56,6 +56,15 @@ public class Router extends Block{
lastInput = source.tile(); lastInput = source.tile();
} }
@Override
public int removeStack(Item item, int amount){
int result = super.removeStack(item, amount);
if(result != 0 && item == lastItem){
lastItem = null;
}
return result;
}
Tilec getTileTarget(Item item, Tile from, boolean set){ Tilec getTileTarget(Item item, Tile from, boolean set){
int counter = tile.rotation(); int counter = tile.rotation();
for(int i = 0; i < proximity.size; i++){ for(int i = 0; i < proximity.size; i++){
@@ -68,14 +77,5 @@ public class Router extends Block{
} }
return null; return null;
} }
@Override
public int removeStack(Item item, int amount){
int result = super.removeStack(item, amount);
if(result != 0 && item == lastItem){
lastItem = null;
}
return result;
}
} }
} }