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

View File

@@ -13,7 +13,7 @@ import mindustry.graphics.*;
import static mindustry.Vars.*;
@EntityDef(value = {Bulletc.class}, pooled = true)
@EntityDef(value = {Bulletc.class}, pooled = true, serialize = false)
@Component
abstract class BulletComp implements Timedc, Damagec, Hitboxc, Teamc, Posc, Drawc, Shielderc, Ownerc, Velc, Bulletc, Timerc{
@Import Team team;

View File

@@ -7,7 +7,7 @@ import mindustry.annotations.Annotations.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@EntityDef(value = {Decalc.class}, pooled = true)
@EntityDef(value = {Decalc.class}, pooled = true, serialize = false)
@Component
abstract class DecalComp implements Drawc, Timedc, Rotc, Posc{
@Import float x, y, rotation;

View File

@@ -1,13 +1,11 @@
package mindustry.entities.def;
import arc.graphics.*;
import arc.graphics.g2d.*;
import mindustry.annotations.Annotations.*;
import mindustry.entities.*;
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
abstract class EffectComp implements Posc, Drawc, Timedc, Rotc, Childc{
Color color = new Color(Color.white);

View File

@@ -252,8 +252,8 @@ public abstract class SaveVersion extends SaveFileReader{
}
}
stream.writeInt(Groups.sync.count(Entityc::serialize));
for(Syncc entity : Groups.sync){
stream.writeInt(Groups.all.count(Entityc::serialize));
for(Entityc entity : Groups.all){
if(!entity.serialize()) continue;
writeChunk(stream, true, out -> {
@@ -278,9 +278,9 @@ public abstract class SaveVersion extends SaveFileReader{
for(int j = 0; j < amount; j++){
readChunk(stream, true, in -> {
byte typeid = in.readByte();
Syncc sync = (Syncc)EntityMapping.map(typeid).get();
sync.read(Reads.get(in));
sync.add();
Entityc entity = (Entityc)EntityMapping.map(typeid).get();
entity.read(Reads.get(in));
entity.add();
});
}
}

View File

@@ -259,6 +259,15 @@ public class TypeIO{
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){
if(string != null){
byte[] bytes = string.getBytes(charset);

View File

@@ -19,7 +19,7 @@ import java.util.regex.*;
public class Scripts implements Disposable{
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",
".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 Context context;
private Scriptable scope;

View File

@@ -52,17 +52,22 @@ public abstract class Weather extends MappableContent{
@Component
abstract class WeatherComp implements Posc, Drawc{
Weather weather;
float intensity = 1f;
float intensity = 1f, opacity = 1f;
void init(Weather weather){
this.weather = weather;
}
@Override
public void update(){
weather.update((Weatherc)this);
}
@Override
public void draw(){
if(renderer.weatherAlpha() > 0.0001f){
Draw.draw(Layer.weather, () -> {
Draw.alpha(renderer.weatherAlpha());
Draw.alpha(renderer.weatherAlpha() * opacity);
weather.draw((Weatherc)this);
Draw.reset();
});

View File

@@ -56,6 +56,15 @@ public class Router extends Block{
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){
int counter = tile.rotation();
for(int i = 0; i < proximity.size; i++){
@@ -68,14 +77,5 @@ public class Router extends Block{
}
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;
}
}
}