Sync progress
This commit is contained in:
@@ -567,7 +567,7 @@ public class NetClient implements ApplicationListener{
|
||||
|
||||
Call.onClientShapshot(lastSent++,
|
||||
unit.x(), unit.y(),
|
||||
player.mouseX(), player.mouseY(),
|
||||
player.unit().aimX(), player.unit().aimY(),
|
||||
unit.rotation(),
|
||||
unit instanceof Legsc ? ((Legsc)unit).baseRotation() : 0,
|
||||
unit.vel().x, unit.vel().y,
|
||||
|
||||
@@ -551,6 +551,7 @@ public class NetServer implements ApplicationListener{
|
||||
player.mouseX(pointerX);
|
||||
player.mouseY(pointerY);
|
||||
player.typing(chatting);
|
||||
player.shooting(shooting);
|
||||
|
||||
player.unit().controlWeapons(shooting, shooting);
|
||||
player.unit().aim(pointerX, pointerY);
|
||||
|
||||
@@ -28,17 +28,17 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
||||
static final float deathDelay = 30f;
|
||||
|
||||
@NonNull @ReadOnly Unitc unit = Nulls.unit;
|
||||
transient @Nullable NetConnection con;
|
||||
|
||||
@ReadOnly Team team = Team.sharded;
|
||||
String name = "noname";
|
||||
@Nullable NetConnection con;
|
||||
boolean admin, typing;
|
||||
boolean admin, typing, shooting;
|
||||
Color color = new Color();
|
||||
float mouseX, mouseY;
|
||||
float deathTimer;
|
||||
|
||||
String lastText = "";
|
||||
float textFadeTime;
|
||||
transient float deathTimer;
|
||||
transient String lastText = "";
|
||||
transient float textFadeTime;
|
||||
|
||||
public boolean isBuilder(){
|
||||
return unit instanceof Builderc;
|
||||
@@ -64,7 +64,16 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
||||
|
||||
@Replace
|
||||
public float clipSize(){
|
||||
return 20;
|
||||
return unit.isNull() ? 20 : unit.type().hitsize * 2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterSync(){
|
||||
unit.aim(mouseX, mouseY);
|
||||
//this is only necessary when the thing being controlled isn't synced
|
||||
unit.isShooting(shooting);
|
||||
//extra precaution, necessary for non-synced things
|
||||
unit.controller(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -113,6 +122,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
||||
|
||||
public void unit(Unitc unit){
|
||||
if(unit == null) throw new IllegalArgumentException("Unit cannot be null. Use clearUnit() instead.");
|
||||
if(this.unit == unit) return;
|
||||
if(this.unit != Nulls.unit){
|
||||
//un-control the old unit
|
||||
this.unit.controller(this.unit.type().createController());
|
||||
|
||||
@@ -17,6 +17,7 @@ abstract class SyncComp implements Entityc{
|
||||
void writeSync(Writes write){}
|
||||
void readSyncManual(FloatBuffer buffer){}
|
||||
void writeSyncManual(FloatBuffer buffer){}
|
||||
void afterSync(){}
|
||||
void interpolate(){}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -5,7 +5,7 @@ import mindustry.annotations.Annotations.*;
|
||||
|
||||
@Component
|
||||
abstract class TimerComp{
|
||||
Interval timer = new Interval(6);
|
||||
transient Interval timer = new Interval(6);
|
||||
|
||||
public boolean timer(int index, float time){
|
||||
return timer.get(index, time);
|
||||
|
||||
@@ -23,7 +23,7 @@ abstract class UnitComp implements Healthc, Physicsc, Hitboxc, Statusc, Teamc, I
|
||||
|
||||
@Import float x, y, rotation, elevation, maxHealth;
|
||||
|
||||
private transient UnitController controller;
|
||||
private UnitController controller;
|
||||
private UnitType type;
|
||||
boolean spawnedByCore;
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ abstract class WeaponsComp implements Teamc, Posc, Rotc{
|
||||
/** weapon mount array, never null */
|
||||
@ReadOnly transient WeaponMount[] mounts = {};
|
||||
@ReadOnly transient float range, aimX, aimY;
|
||||
@ReadOnly transient boolean isRotate, isShooting;
|
||||
@ReadOnly transient boolean isRotate;
|
||||
boolean isShooting;
|
||||
|
||||
void setWeaponRotation(float rotation){
|
||||
for(WeaponMount mount : mounts){
|
||||
|
||||
@@ -5,6 +5,7 @@ import arc.math.geom.*;
|
||||
import arc.struct.*;
|
||||
import arc.util.io.*;
|
||||
import arc.util.pooling.*;
|
||||
import mindustry.ai.types.*;
|
||||
import mindustry.annotations.Annotations.*;
|
||||
import mindustry.ctype.*;
|
||||
import mindustry.entities.bullet.*;
|
||||
@@ -15,6 +16,7 @@ import mindustry.net.Administration.*;
|
||||
import mindustry.net.Packets.*;
|
||||
import mindustry.type.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.*;
|
||||
@@ -26,8 +28,6 @@ import static mindustry.Vars.*;
|
||||
@TypeIOHandler
|
||||
public class TypeIO{
|
||||
|
||||
//TODO read/write enums like commands!
|
||||
|
||||
public static void writeObject(Writes write, Object object){
|
||||
if(object == null){
|
||||
write.b((byte)0);
|
||||
@@ -87,6 +87,32 @@ public class TypeIO{
|
||||
}
|
||||
}
|
||||
|
||||
//only for players!
|
||||
public static void writeUnit(Writes write, Unitc unit){
|
||||
write.b(unit.isNull() ? 0 : unit instanceof BlockUnitc ? 1 : 2);
|
||||
//block units are special
|
||||
if(unit instanceof BlockUnitc){
|
||||
write.i(((BlockUnitc)unit).tile().pos());
|
||||
}else{
|
||||
write.i(unit.id());
|
||||
}
|
||||
}
|
||||
|
||||
public static Unitc readUnit(Reads read){
|
||||
byte type = read.b();
|
||||
int id = read.i();
|
||||
//nothing
|
||||
if(type == 0) return Nulls.unit;
|
||||
if(type == 2){ //standard unit
|
||||
Unitc unit = Groups.unit.getByID(id);
|
||||
return unit == null ? Nulls.unit : unit;
|
||||
}else if(type == 1){ //block
|
||||
Tilec tile = world.ent(id);
|
||||
return tile instanceof ControlBlock ? ((ControlBlock)tile).unit() : Nulls.unit;
|
||||
}
|
||||
return Nulls.unit;
|
||||
}
|
||||
|
||||
public static void writeEntity(Writes write, Entityc entity){
|
||||
write.i(entity == null ? -1 : entity.id());
|
||||
}
|
||||
@@ -184,6 +210,33 @@ public class TypeIO{
|
||||
return reqs;
|
||||
}
|
||||
|
||||
public static void writeController(Writes write, UnitController control){
|
||||
//no real unit controller state is written, only the type
|
||||
if(control instanceof Playerc){
|
||||
write.b(0);
|
||||
write.i(((Playerc)control).id());
|
||||
}else{
|
||||
write.b(1);
|
||||
}
|
||||
}
|
||||
|
||||
public static UnitController readController(Reads read, UnitController prev){
|
||||
byte type = read.b();
|
||||
if(type == 0){ //is player
|
||||
int id = read.i();
|
||||
Playerc player = Groups.player.getByID(id);
|
||||
//local players will cause problems if assigned, since they may not know they are controlling the unit
|
||||
if(player == null || player.isLocal()) return prev;
|
||||
return player;
|
||||
}else{
|
||||
//there are two cases here:
|
||||
//1: prev controller was not a player, carry on
|
||||
//2: prev controller was a player, so replace this controller with *anything else*
|
||||
//...since AI doesn't update clientside it doesn't matter what
|
||||
return prev instanceof Playerc ? new GroundAI() : prev;
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeKick(Writes write, KickReason reason){
|
||||
write.b((byte)reason.ordinal());
|
||||
}
|
||||
@@ -215,6 +268,10 @@ public class TypeIO{
|
||||
}
|
||||
}
|
||||
|
||||
public static Vec2 readVec2(Reads read, Vec2 base){
|
||||
return base.set(read.f(), read.f());
|
||||
}
|
||||
|
||||
public static Vec2 readVec2(Reads read){
|
||||
return new Vec2(read.f(), read.f());
|
||||
}
|
||||
@@ -233,6 +290,10 @@ public class TypeIO{
|
||||
write.i(stack.amount);
|
||||
}
|
||||
|
||||
public static ItemStack readItems(Reads read, ItemStack stack){
|
||||
return stack.set(readItem(read), read.i());
|
||||
}
|
||||
|
||||
public static ItemStack readItems(Reads read){
|
||||
return new ItemStack(readItem(read), read.i());
|
||||
}
|
||||
@@ -277,6 +338,10 @@ public class TypeIO{
|
||||
return new Color(read.i());
|
||||
}
|
||||
|
||||
public static Color readColor(Reads read, Color color){
|
||||
return color.set(read.i());
|
||||
}
|
||||
|
||||
public static void writeLiquid(Writes write, Liquid liquid){
|
||||
write.s(liquid == null ? -1 : liquid.id);
|
||||
}
|
||||
@@ -314,18 +379,17 @@ public class TypeIO{
|
||||
|
||||
public static void writeString(Writes write, String string){
|
||||
if(string != null){
|
||||
byte[] bytes = string.getBytes(charset);
|
||||
write.s((short)bytes.length);
|
||||
write.b(bytes);
|
||||
write.b(1);
|
||||
write.str(string);
|
||||
}else{
|
||||
write.s((short)-1);
|
||||
write.b(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static String readString(Reads read){
|
||||
short slength = read.s();
|
||||
if(slength != -1){
|
||||
return new String(read.b(new byte[slength]), charset);
|
||||
byte exists = read.b();
|
||||
if(exists != 0){
|
||||
return read.str();
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,12 @@ public class ItemStack implements Comparable<ItemStack>{
|
||||
item = Items.copper;
|
||||
}
|
||||
|
||||
public ItemStack set(Item item, int amount){
|
||||
this.item = item;
|
||||
this.amount = amount;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack copy(){
|
||||
return new ItemStack(item, amount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user