Pools replace with Pooling / Removed all core reflection
This commit is contained in:
@@ -129,7 +129,7 @@ public class RemoteWriteGenerator{
|
|||||||
method.beginControlFlow("if(" + getCheckString(methodEntry.where) + ")");
|
method.beginControlFlow("if(" + getCheckString(methodEntry.where) + ")");
|
||||||
|
|
||||||
//add statement to create packet from pool
|
//add statement to create packet from pool
|
||||||
method.addStatement("$1N packet = $2N.obtain($1N.class)", "io.anuke.mindustry.net.Packets.InvokePacket", "io.anuke.ucore.util.Pooling");
|
method.addStatement("$1N packet = $2N.obtain($1N.class, $1N::new)", "io.anuke.mindustry.net.Packets.InvokePacket", "io.anuke.ucore.util.Pooling");
|
||||||
//assign buffer
|
//assign buffer
|
||||||
method.addStatement("packet.writeBuffer = TEMP_BUFFER");
|
method.addStatement("packet.writeBuffer = TEMP_BUFFER");
|
||||||
//assign priority
|
//assign priority
|
||||||
|
|||||||
@@ -225,8 +225,8 @@ project(":kryonet") {
|
|||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile project(":core")
|
compile project(":core")
|
||||||
compile 'com.github.crykn:kryonet:2.22.1'
|
|
||||||
compile "org.lz4:lz4-java:1.4.1"
|
compile "org.lz4:lz4-java:1.4.1"
|
||||||
|
compile 'com.github.Anuken:kryonet:53b10247b1'
|
||||||
compile 'com.github.Anuken:WaifUPnP:05eb46bc577fd7674596946ba288c96c0cedd893'
|
compile 'com.github.Anuken:WaifUPnP:05eb46bc577fd7674596946ba288c96c0cedd893'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class Renderer extends RendererModule{
|
|||||||
if(view.overlaps(pos)){
|
if(view.overlaps(pos)){
|
||||||
|
|
||||||
if(!(effect instanceof GroundEffect)){
|
if(!(effect instanceof GroundEffect)){
|
||||||
EffectEntity entity = Pooling.obtain(EffectEntity.class);
|
EffectEntity entity = Pooling.obtain(EffectEntity.class, EffectEntity::new);
|
||||||
entity.effect = effect;
|
entity.effect = effect;
|
||||||
entity.color = color;
|
entity.color = color;
|
||||||
entity.rotation = rotation;
|
entity.rotation = rotation;
|
||||||
@@ -94,7 +94,7 @@ public class Renderer extends RendererModule{
|
|||||||
}
|
}
|
||||||
threads.runGraphics(() -> effectGroup.add(entity));
|
threads.runGraphics(() -> effectGroup.add(entity));
|
||||||
}else{
|
}else{
|
||||||
GroundEffectEntity entity = Pooling.obtain(GroundEffectEntity.class);
|
GroundEffectEntity entity = Pooling.obtain(GroundEffectEntity.class, GroundEffectEntity::new);
|
||||||
entity.effect = effect;
|
entity.effect = effect;
|
||||||
entity.color = color;
|
entity.color = color;
|
||||||
entity.rotation = rotation;
|
entity.rotation = rotation;
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import com.badlogic.gdx.graphics.Color;
|
|||||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.Pools;
|
|
||||||
import com.badlogic.gdx.utils.Queue;
|
import com.badlogic.gdx.utils.Queue;
|
||||||
import io.anuke.annotations.Annotations.Loc;
|
import io.anuke.annotations.Annotations.Loc;
|
||||||
import io.anuke.annotations.Annotations.Remote;
|
import io.anuke.annotations.Annotations.Remote;
|
||||||
@@ -373,7 +372,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawName(){
|
public void drawName(){
|
||||||
GlyphLayout layout = Pools.obtain(GlyphLayout.class);
|
GlyphLayout layout = Pooling.obtain(GlyphLayout.class, GlyphLayout::new);
|
||||||
|
|
||||||
Draw.tscl(0.25f / 2);
|
Draw.tscl(0.25f / 2);
|
||||||
layout.setText(Core.font, name);
|
layout.setText(Core.font, name);
|
||||||
@@ -390,7 +389,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
|||||||
}
|
}
|
||||||
|
|
||||||
Draw.reset();
|
Draw.reset();
|
||||||
Pools.free(layout);
|
Pooling.free(layout);
|
||||||
Draw.tscl(fontScale);
|
Draw.tscl(fontScale);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class StatusController implements Saveable{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//otherwise, no opposites found, add direct effect
|
//otherwise, no opposites found, add direct effect
|
||||||
StatusEntry entry = Pooling.obtain(StatusEntry.class);
|
StatusEntry entry = Pooling.obtain(StatusEntry.class, StatusEntry::new);
|
||||||
entry.set(effect, newTime);
|
entry.set(effect, newTime);
|
||||||
statuses.add(entry);
|
statuses.add(entry);
|
||||||
}
|
}
|
||||||
@@ -146,7 +146,7 @@ public class StatusController implements Saveable{
|
|||||||
for(int i = 0; i < amount; i++){
|
for(int i = 0; i < amount; i++){
|
||||||
byte id = stream.readByte();
|
byte id = stream.readByte();
|
||||||
float time = stream.readShort() / 2f;
|
float time = stream.readShort() / 2f;
|
||||||
StatusEntry entry = Pooling.obtain(StatusEntry.class);
|
StatusEntry entry = Pooling.obtain(StatusEntry.class, StatusEntry::new);
|
||||||
entry.set(content.getByID(ContentType.status, id), time);
|
entry.set(content.getByID(ContentType.status, id), time);
|
||||||
statuses.add(entry);
|
statuses.add(entry);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class Bullet extends BulletEntity<BulletType> implements TeamTrait, SyncT
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void create(BulletType type, Entity owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl, Object data){
|
public static void create(BulletType type, Entity owner, Team team, float x, float y, float angle, float velocityScl, float lifetimeScl, Object data){
|
||||||
Bullet bullet = Pooling.obtain(Bullet.class);
|
Bullet bullet = Pooling.obtain(Bullet.class, Bullet::new);
|
||||||
bullet.type = type;
|
bullet.type = type;
|
||||||
bullet.owner = owner;
|
bullet.owner = owner;
|
||||||
bullet.data = data;
|
bullet.data = data;
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class Fire extends TimedEntity implements SaveTrait, SyncTrait, Poolable{
|
|||||||
Fire fire = map.get(tile.packedPosition());
|
Fire fire = map.get(tile.packedPosition());
|
||||||
|
|
||||||
if(fire == null){
|
if(fire == null){
|
||||||
fire = Pooling.obtain(Fire.class);
|
fire = Pooling.obtain(Fire.class, Fire::new);
|
||||||
fire.tile = tile;
|
fire.tile = tile;
|
||||||
fire.lifetime = baseLifetime;
|
fire.lifetime = baseLifetime;
|
||||||
fire.set(tile.worldx(), tile.worldy());
|
fire.set(tile.worldx(), tile.worldy());
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void create(Item item, float fromx, float fromy, PosTrait to, Runnable done){
|
public static void create(Item item, float fromx, float fromy, PosTrait to, Runnable done){
|
||||||
ItemTransfer tr = Pooling.obtain(ItemTransfer.class);
|
ItemTransfer tr = Pooling.obtain(ItemTransfer.class, ItemTransfer::new);
|
||||||
tr.item = item;
|
tr.item = item;
|
||||||
tr.from.set(fromx, fromy);
|
tr.from.set(fromx, fromy);
|
||||||
tr.to = to;
|
tr.to = to;
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ public class Lightning extends TimedEntity implements Poolable, DrawTrait, SyncT
|
|||||||
/**Do not invoke!*/
|
/**Do not invoke!*/
|
||||||
@Remote(called = Loc.server)
|
@Remote(called = Loc.server)
|
||||||
public static void createLighting(int seed, Team team, Effect effect, Color color, float damage, float x, float y, float targetAngle, int length){
|
public static void createLighting(int seed, Team team, Effect effect, Color color, float damage, float x, float y, float targetAngle, int length){
|
||||||
Lightning l = Pooling.obtain(Lightning.class);
|
Lightning l = Pooling.obtain(Lightning.class, Lightning::new);
|
||||||
|
|
||||||
//TODO hacky workaround
|
//TODO hacky workaround
|
||||||
if(checkShield(team, x, y)) return;
|
if(checkShield(team, x, y)) return;
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ public class Puddle extends BaseEntity implements SaveTrait, Poolable, DrawTrait
|
|||||||
if(p == null){
|
if(p == null){
|
||||||
if(Net.client()) return; //not clientside.
|
if(Net.client()) return; //not clientside.
|
||||||
|
|
||||||
Puddle puddle = Pooling.obtain(Puddle.class);
|
Puddle puddle = Pooling.obtain(Puddle.class, Puddle::new);
|
||||||
puddle.tile = tile;
|
puddle.tile = tile;
|
||||||
puddle.liquid = liquid;
|
puddle.liquid = liquid;
|
||||||
puddle.amount = amount;
|
puddle.amount = amount;
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import com.badlogic.gdx.net.HttpRequestBuilder;
|
|||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.IntMap;
|
import com.badlogic.gdx.utils.IntMap;
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
|
||||||
import io.anuke.mindustry.core.Platform;
|
import io.anuke.mindustry.core.Platform;
|
||||||
import io.anuke.mindustry.gen.Call;
|
import io.anuke.mindustry.gen.Call;
|
||||||
import io.anuke.mindustry.net.Packets.KickReason;
|
import io.anuke.mindustry.net.Packets.KickReason;
|
||||||
@@ -68,7 +67,7 @@ public class Net{
|
|||||||
if(loaded){
|
if(loaded){
|
||||||
//handle all packets that were skipped while loading
|
//handle all packets that were skipped while loading
|
||||||
for(int i = 0; i < packetQueue.size; i++){
|
for(int i = 0; i < packetQueue.size; i++){
|
||||||
Log.info("Processing {0} packet post-load.", ClassReflection.getSimpleName(packetQueue.get(i).getClass()));
|
Log.info("Processing {0} packet post-load.", packetQueue.get(i).getClass());
|
||||||
handleClientReceived(packetQueue.get(i));
|
handleClientReceived(packetQueue.get(i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,14 +237,14 @@ public class Net{
|
|||||||
}
|
}
|
||||||
}else if(!((object instanceof Packet) && ((Packet) object).isUnimportant())){
|
}else if(!((object instanceof Packet) && ((Packet) object).isUnimportant())){
|
||||||
packetQueue.add(object);
|
packetQueue.add(object);
|
||||||
Log.info("Queuing packet {0}.", ClassReflection.getSimpleName(object.getClass()));
|
Log.info("Queuing packet {0}.", object);
|
||||||
}else{
|
}else{
|
||||||
synchronized(packetPoolLock){
|
synchronized(packetPoolLock){
|
||||||
Pooling.free(object);
|
Pooling.free(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
Log.err("Unhandled packet type: '{0}'!", ClassReflection.getSimpleName(object.getClass()));
|
Log.err("Unhandled packet type: '{0}'!", object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -261,7 +260,7 @@ public class Net{
|
|||||||
Pooling.free(object);
|
Pooling.free(object);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
Log.err("Unhandled packet type: '{0}'!", ClassReflection.getSimpleName(object.getClass()));
|
Log.err("Unhandled packet type: '{0}'!", object.getClass());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package io.anuke.mindustry.net;
|
|||||||
import com.badlogic.gdx.utils.ObjectIntMap;
|
import com.badlogic.gdx.utils.ObjectIntMap;
|
||||||
import io.anuke.mindustry.net.Packets.*;
|
import io.anuke.mindustry.net.Packets.*;
|
||||||
import io.anuke.ucore.function.Supplier;
|
import io.anuke.ucore.function.Supplier;
|
||||||
import io.anuke.ucore.util.Pooling;
|
|
||||||
|
|
||||||
public class Registrator{
|
public class Registrator{
|
||||||
private static ClassEntry[] classes = {
|
private static ClassEntry[] classes = {
|
||||||
@@ -18,7 +17,6 @@ public class Registrator{
|
|||||||
static{
|
static{
|
||||||
if(classes.length > 127) throw new RuntimeException("Can't have more than 127 registered classes!");
|
if(classes.length > 127) throw new RuntimeException("Can't have more than 127 registered classes!");
|
||||||
for(int i = 0; i < classes.length; i++){
|
for(int i = 0; i < classes.length; i++){
|
||||||
Pooling.registerType((Class<Packet>) classes[i].type, (Supplier<Packet>) classes[i].constructor);
|
|
||||||
ids.put(classes[i].type, i);
|
ids.put(classes[i].type, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import com.badlogic.gdx.files.FileHandle;
|
|||||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||||
import com.badlogic.gdx.utils.Align;
|
import com.badlogic.gdx.utils.Align;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.Pools;
|
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
import io.anuke.mindustry.core.Platform;
|
import io.anuke.mindustry.core.Platform;
|
||||||
import io.anuke.ucore.core.Core;
|
import io.anuke.ucore.core.Core;
|
||||||
@@ -18,6 +17,7 @@ import io.anuke.ucore.scene.ui.layout.Table;
|
|||||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||||
import io.anuke.ucore.scene.utils.UIUtils;
|
import io.anuke.ucore.scene.utils.UIUtils;
|
||||||
import io.anuke.ucore.util.OS;
|
import io.anuke.ucore.util.OS;
|
||||||
|
import io.anuke.ucore.util.Pooling;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
@@ -186,7 +186,7 @@ public class FileChooser extends FloatingDialog{
|
|||||||
//if is mac, don't display extra info since you can only ever go to downloads
|
//if is mac, don't display extra info since you can only ever go to downloads
|
||||||
navigation.setText(OS.isMac ? directory.name() : directory.toString());
|
navigation.setText(OS.isMac ? directory.name() : directory.toString());
|
||||||
|
|
||||||
GlyphLayout layout = Pools.obtain(GlyphLayout.class);
|
GlyphLayout layout = Pooling.obtain(GlyphLayout.class, GlyphLayout::new);
|
||||||
|
|
||||||
layout.setText(Core.font, navigation.getText());
|
layout.setText(Core.font, navigation.getText());
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ public class FileChooser extends FloatingDialog{
|
|||||||
navigation.setCursorPosition(navigation.getText().length());
|
navigation.setCursorPosition(navigation.getText().length());
|
||||||
}
|
}
|
||||||
|
|
||||||
Pools.free(layout);
|
Pooling.free(layout);
|
||||||
|
|
||||||
files.clearChildren();
|
files.clearChildren();
|
||||||
files.top().left();
|
files.top().left();
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package io.anuke.mindustry.ui.dialogs;
|
package io.anuke.mindustry.ui.dialogs;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
|
||||||
import io.anuke.mindustry.core.GameState.State;
|
import io.anuke.mindustry.core.GameState.State;
|
||||||
import io.anuke.mindustry.game.Saves.SaveSlot;
|
import io.anuke.mindustry.game.Saves.SaveSlot;
|
||||||
import io.anuke.ucore.core.Timers;
|
import io.anuke.ucore.core.Timers;
|
||||||
@@ -55,7 +54,7 @@ public class SaveDialog extends LoadDialog{
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
e = (e.getCause() == null ? e : e.getCause());
|
e = (e.getCause() == null ? e : e.getCause());
|
||||||
|
|
||||||
ui.showError("[orange]" + Bundles.get("text.savefail") + "\n[white]" + ClassReflection.getSimpleName(e.getClass()) + ": " + e.getMessage() + "\n" + "at " + e.getStackTrace()[0].getFileName() + ":" + e.getStackTrace()[0].getLineNumber());
|
ui.showError("[orange]" + Bundles.get("text.savefail"));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package io.anuke.mindustry.world;
|
|||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
|
||||||
import io.anuke.mindustry.entities.Damage;
|
import io.anuke.mindustry.entities.Damage;
|
||||||
import io.anuke.mindustry.entities.Player;
|
import io.anuke.mindustry.entities.Player;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
@@ -466,7 +465,7 @@ public class Block extends BaseBlock {
|
|||||||
"floor", tile.floor().name,
|
"floor", tile.floor().name,
|
||||||
"x", tile.x,
|
"x", tile.x,
|
||||||
"y", tile.y,
|
"y", tile.y,
|
||||||
"entity.name", ClassReflection.getSimpleName(tile.entity.getClass()),
|
"entity.name", tile.entity.getClass(),
|
||||||
"entity.x", tile.entity.x,
|
"entity.x", tile.entity.x,
|
||||||
"entity.y", tile.entity.y,
|
"entity.y", tile.entity.y,
|
||||||
"entity.id", tile.entity.id,
|
"entity.id", tile.entity.id,
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package io.anuke.mindustry.world;
|
|||||||
import com.badlogic.gdx.math.GridPoint2;
|
import com.badlogic.gdx.math.GridPoint2;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.utils.Array;
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
|
||||||
import io.anuke.mindustry.content.blocks.Blocks;
|
import io.anuke.mindustry.content.blocks.Blocks;
|
||||||
import io.anuke.mindustry.entities.TileEntity;
|
import io.anuke.mindustry.entities.TileEntity;
|
||||||
import io.anuke.mindustry.entities.traits.TargetTrait;
|
import io.anuke.mindustry.entities.traits.TargetTrait;
|
||||||
@@ -472,7 +471,7 @@ public class Tile implements PosTrait, TargetTrait{
|
|||||||
Block block = block();
|
Block block = block();
|
||||||
Block floor = floor();
|
Block floor = floor();
|
||||||
|
|
||||||
return floor.name() + ":" + block.name() + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : ClassReflection.getSimpleName(entity.getClass())) +
|
return floor.name() + ":" + block.name() + "[" + x + "," + y + "] " + "entity=" + (entity == null ? "null" : (entity.getClass())) +
|
||||||
(link != 0 ? " link=[" + (Bits.getLeftByte(link) - 8) + ", " + (Bits.getRightByte(link) - 8) + "]" : "");
|
(link != 0 ? " link=[" + (Bits.getLeftByte(link) - 8) + ", " + (Bits.getRightByte(link) - 8) + "]" : "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -79,7 +79,7 @@ public class MassDriver extends Block{
|
|||||||
entity.reload = 1f;
|
entity.reload = 1f;
|
||||||
entity.power.amount = 0f;
|
entity.power.amount = 0f;
|
||||||
|
|
||||||
DriverBulletData data = Pooling.obtain(DriverBulletData.class);
|
DriverBulletData data = Pooling.obtain(DriverBulletData.class, DriverBulletData::new);
|
||||||
data.from = entity;
|
data.from = entity;
|
||||||
data.to = other;
|
data.to = other;
|
||||||
for(int i = 0; i < content.items().size; i++){
|
for(int i = 0; i < content.items().size; i++){
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package io.anuke.mindustry.world.consumers;
|
|||||||
|
|
||||||
import com.badlogic.gdx.utils.ObjectMap;
|
import com.badlogic.gdx.utils.ObjectMap;
|
||||||
import com.badlogic.gdx.utils.ObjectSet;
|
import com.badlogic.gdx.utils.ObjectSet;
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
|
||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.mindustry.type.ItemStack;
|
import io.anuke.mindustry.type.ItemStack;
|
||||||
import io.anuke.mindustry.type.Liquid;
|
import io.anuke.mindustry.type.Liquid;
|
||||||
@@ -22,7 +21,7 @@ public class Consumers{
|
|||||||
public void checkRequired(Block block){
|
public void checkRequired(Block block){
|
||||||
for(Class<? extends Consume> c : required){
|
for(Class<? extends Consume> c : required){
|
||||||
if(!map.containsKey(c)){
|
if(!map.containsKey(c)){
|
||||||
throw new RuntimeException("Missing required consumer of type \"" + ClassReflection.getSimpleName(c) + "\" in block \"" + block.name + "\"!");
|
throw new RuntimeException("Missing required consumer of type \"" + c + "\" in block \"" + block.name + "\"!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
package io.anuke.kryonet;
|
package io.anuke.kryonet;
|
||||||
|
|
||||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
|
||||||
import com.esotericsoftware.kryonet.FrameworkMessage;
|
import com.esotericsoftware.kryonet.FrameworkMessage;
|
||||||
import com.esotericsoftware.kryonet.serialization.Serialization;
|
import com.esotericsoftware.kryonet.serialization.Serialization;
|
||||||
import io.anuke.mindustry.net.Packet;
|
import io.anuke.mindustry.net.Packet;
|
||||||
import io.anuke.mindustry.net.Registrator;
|
import io.anuke.mindustry.net.Registrator;
|
||||||
|
import io.anuke.ucore.function.Supplier;
|
||||||
import io.anuke.ucore.util.Pooling;
|
import io.anuke.ucore.util.Pooling;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
|
||||||
import static io.anuke.mindustry.net.Net.packetPoolLock;
|
import static io.anuke.mindustry.net.Net.packetPoolLock;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
public class ByteSerializer implements Serialization {
|
public class ByteSerializer implements Serialization {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -23,7 +24,7 @@ public class ByteSerializer implements Serialization {
|
|||||||
throw new RuntimeException("All sent objects must implement be Packets! Class: " + o.getClass());
|
throw new RuntimeException("All sent objects must implement be Packets! Class: " + o.getClass());
|
||||||
byte id = Registrator.getID(o.getClass());
|
byte id = Registrator.getID(o.getClass());
|
||||||
if (id == -1)
|
if (id == -1)
|
||||||
throw new RuntimeException("Unregistered class: " + ClassReflection.getSimpleName(o.getClass()));
|
throw new RuntimeException("Unregistered class: " + o.getClass());
|
||||||
byteBuffer.put(id);
|
byteBuffer.put(id);
|
||||||
((Packet) o).write(byteBuffer);
|
((Packet) o).write(byteBuffer);
|
||||||
}
|
}
|
||||||
@@ -36,7 +37,7 @@ public class ByteSerializer implements Serialization {
|
|||||||
return FrameworkSerializer.read(byteBuffer);
|
return FrameworkSerializer.read(byteBuffer);
|
||||||
}else{
|
}else{
|
||||||
synchronized (packetPoolLock) {
|
synchronized (packetPoolLock) {
|
||||||
Packet packet = (Packet) Pooling.obtain(Registrator.getByID(id).type);
|
Packet packet = Pooling.obtain((Class<Packet>) Registrator.getByID(id).type, (Supplier<Packet>) Registrator.getByID(id).constructor);
|
||||||
packet.read(byteBuffer);
|
packet.read(byteBuffer);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -169,7 +169,6 @@ public class KryoServer implements ServerProvider {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
UCore.setPrivate(server, "shutdown", true);
|
|
||||||
connections.clear();
|
connections.clear();
|
||||||
lastconnection = 0;
|
lastconnection = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user