Implemented full multiplayer; block syncing still unfinished
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
|
||||
/**Class for storing all packets.*/
|
||||
public class Packets {
|
||||
@@ -27,6 +28,7 @@ public class Packets {
|
||||
public static class SyncPacket{
|
||||
public int[] ids;
|
||||
public float[][] data;
|
||||
public int enemyStart = 0;
|
||||
}
|
||||
|
||||
public static class BlockSyncPacket extends Streamable{
|
||||
@@ -55,6 +57,12 @@ public class Packets {
|
||||
public int playerid;
|
||||
}
|
||||
|
||||
public static class BulletPacket{
|
||||
public int type, owner;
|
||||
public float x, y, angle;
|
||||
public short damage;
|
||||
}
|
||||
|
||||
public static class PlacePacket{
|
||||
public int playerid;
|
||||
public byte rotation;
|
||||
@@ -66,4 +74,28 @@ public class Packets {
|
||||
public int playerid;
|
||||
public short x, y;
|
||||
}
|
||||
|
||||
public static class EnemySpawnPacket{
|
||||
public Class<? extends Enemy> type;
|
||||
public byte lane, tier;
|
||||
public float x, y;
|
||||
public int id;
|
||||
}
|
||||
|
||||
public static class EnemyDeathPacket{
|
||||
public int id;
|
||||
}
|
||||
|
||||
public static class PathPacket{
|
||||
public int[] path;
|
||||
public byte index;
|
||||
}
|
||||
|
||||
public static class BlockDestroyPacket{
|
||||
public int position;
|
||||
}
|
||||
|
||||
public static class BlockUpdatePacket{
|
||||
public int health;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.anuke.mindustry.net;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.enemies.*;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
||||
import io.anuke.mindustry.net.Streamable.StreamChunk;
|
||||
@@ -24,12 +25,17 @@ public class Registrator {
|
||||
BreakPacket.class,
|
||||
StateSyncPacket.class,
|
||||
BlockSyncPacket.class,
|
||||
EnemySpawnPacket.class,
|
||||
PathPacket.class,
|
||||
BulletPacket.class,
|
||||
EnemyDeathPacket.class,
|
||||
|
||||
Class.class,
|
||||
byte[].class,
|
||||
float[].class,
|
||||
float[][].class,
|
||||
int[].class,
|
||||
int[][].class,
|
||||
Entity[].class,
|
||||
Player[].class,
|
||||
Array.class,
|
||||
@@ -37,7 +43,19 @@ public class Registrator {
|
||||
|
||||
Entity.class,
|
||||
Player.class,
|
||||
Mech.class
|
||||
Mech.class,
|
||||
|
||||
Enemy.class,
|
||||
FastEnemy.class,
|
||||
RapidEnemy.class,
|
||||
FlamerEnemy.class,
|
||||
TankEnemy.class,
|
||||
BlastEnemy.class,
|
||||
MortarEnemy.class,
|
||||
TestEnemy.class,
|
||||
HealerEnemy.class,
|
||||
TitanEnemy.class,
|
||||
EmpEnemy.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
//TODO clean up this giant mess
|
||||
public interface Syncable {
|
||||
|
||||
public Interpolator<?> getInterpolator();
|
||||
@@ -39,11 +41,38 @@ public interface Syncable {
|
||||
entity.angle = Mathf.lerpAngDelta(entity.angle, i.targetrot, 0.6f);
|
||||
}
|
||||
};
|
||||
|
||||
public static final SyncType<Enemy> enemy = new SyncType<Enemy>() {
|
||||
@Override
|
||||
public float[] write(Enemy entity) {
|
||||
return new float[]{entity.x, entity.y, entity.angle, entity.health};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(Enemy entity, float[] data) {
|
||||
entity.getInterpolator().target.set(data[0], data[1]);
|
||||
entity.getInterpolator().targetrot = data[2];
|
||||
entity.health = (int)data[3];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Enemy entity, Interpolator interpolator) {
|
||||
Interpolator i = entity.getInterpolator();
|
||||
if(i.target.dst(entity.x, entity.y) > 16){
|
||||
entity.set(i.target.x, i.target.y);
|
||||
}
|
||||
|
||||
entity.x = Mathf.lerpDelta(entity.x, i.target.x, 0.4f);
|
||||
entity.y = Mathf.lerpDelta(entity.y, i.target.y, 0.4f);
|
||||
entity.angle = Mathf.lerpAngDelta(entity.angle, i.targetrot, 0.6f);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class Interpolator<T extends Entity> {
|
||||
public SyncType<T> type;
|
||||
public Vector2 target = new Vector2();
|
||||
public Vector2 last = new Vector2();
|
||||
public float targetrot;
|
||||
|
||||
public Interpolator(SyncType<T> type){
|
||||
|
||||
Reference in New Issue
Block a user