Synced whole place queue / Fixed player flash desync
This commit is contained in:
@@ -82,14 +82,6 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
|||||||
|
|
||||||
//region unit and event overrides, utility methods
|
//region unit and event overrides, utility methods
|
||||||
|
|
||||||
@Remote(targets = Loc.server, called = Loc.server)
|
|
||||||
public static void onPlayerDamage(Player player, float amount){
|
|
||||||
if(player == null) return;
|
|
||||||
|
|
||||||
player.hitTime = hitDuration;
|
|
||||||
player.health -= amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Remote(targets = Loc.server, called = Loc.server)
|
@Remote(targets = Loc.server, called = Loc.server)
|
||||||
public static void onPlayerDeath(Player player){
|
public static void onPlayerDeath(Player player){
|
||||||
if(player == null) return;
|
if(player == null) return;
|
||||||
@@ -227,7 +219,10 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void damage(float amount){
|
public void damage(float amount){
|
||||||
Call.onPlayerDamage(this, calculateDamage(amount));
|
hitTime = hitDuration;
|
||||||
|
if(!Net.client()){
|
||||||
|
health -= amount;
|
||||||
|
}
|
||||||
|
|
||||||
if(health <= 0 && !dead){
|
if(health <= 0 && !dead){
|
||||||
Call.onPlayerDeath(this);
|
Call.onPlayerDeath(this);
|
||||||
|
|||||||
@@ -185,7 +185,6 @@ public class NetworkIO{
|
|||||||
int height = stream.readShort();
|
int height = stream.readShort();
|
||||||
|
|
||||||
//TODO send advanced map meta such as author, etc
|
//TODO send advanced map meta such as author, etc
|
||||||
//TODO scan for cores
|
|
||||||
Map currentMap = new Map(map, new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null);
|
Map currentMap = new Map(map, new MapMeta(0, new ObjectMap<>(), width, height, null), true, () -> null);
|
||||||
currentMap.meta.tags.clear();
|
currentMap.meta.tags.clear();
|
||||||
currentMap.meta.tags.putAll(tags);
|
currentMap.meta.tags.putAll(tags);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package io.anuke.mindustry.net;
|
package io.anuke.mindustry.net;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.utils.Array;
|
||||||
import com.badlogic.gdx.utils.Base64Coder;
|
import com.badlogic.gdx.utils.Base64Coder;
|
||||||
import com.badlogic.gdx.utils.TimeUtils;
|
import com.badlogic.gdx.utils.TimeUtils;
|
||||||
import io.anuke.mindustry.Vars;
|
import io.anuke.mindustry.Vars;
|
||||||
@@ -155,7 +156,7 @@ public class Packets{
|
|||||||
public float x, y, pointerX, pointerY, rotation, baseRotation, xv, yv;
|
public float x, y, pointerX, pointerY, rotation, baseRotation, xv, yv;
|
||||||
public Tile mining;
|
public Tile mining;
|
||||||
public boolean boosting, shooting;
|
public boolean boosting, shooting;
|
||||||
public BuildRequest currentRequest;
|
public Array<BuildRequest> requests = new Array<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write(ByteBuffer buffer){
|
public void write(ByteBuffer buffer){
|
||||||
@@ -180,17 +181,14 @@ public class Packets{
|
|||||||
|
|
||||||
buffer.putInt(player.getMineTile() == null ? -1 : player.getMineTile().packedPosition());
|
buffer.putInt(player.getMineTile() == null ? -1 : player.getMineTile().packedPosition());
|
||||||
|
|
||||||
BuildRequest request = player.getCurrentRequest();
|
buffer.putShort((short)player.getPlaceQueue().size);
|
||||||
|
for(BuildRequest request : player.getPlaceQueue()){
|
||||||
if(request != null){
|
|
||||||
buffer.put(request.remove ? (byte) 1 : 0);
|
buffer.put(request.remove ? (byte) 1 : 0);
|
||||||
buffer.putInt(world.toPacked(request.x, request.y));
|
buffer.putInt(world.toPacked(request.x, request.y));
|
||||||
if(!request.remove){
|
if(!request.remove){
|
||||||
buffer.put((byte) request.recipe.id);
|
buffer.put((byte) request.recipe.id);
|
||||||
buffer.put((byte) request.rotation);
|
buffer.put((byte) request.rotation);
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
buffer.put((byte) -1);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,10 +209,13 @@ public class Packets{
|
|||||||
rotation = buffer.getShort() / 2f;
|
rotation = buffer.getShort() / 2f;
|
||||||
baseRotation = buffer.getShort() / 2f;
|
baseRotation = buffer.getShort() / 2f;
|
||||||
mining = world.tile(buffer.getInt());
|
mining = world.tile(buffer.getInt());
|
||||||
|
requests.clear();
|
||||||
|
|
||||||
byte type = buffer.get();
|
short reqamount = buffer.getShort();
|
||||||
if(type != -1){
|
for(int i = 0; i < reqamount; i++){
|
||||||
|
byte type = buffer.get();
|
||||||
int position = buffer.getInt();
|
int position = buffer.getInt();
|
||||||
|
BuildRequest currentRequest;
|
||||||
|
|
||||||
if(type == 1){ //remove
|
if(type == 1){ //remove
|
||||||
currentRequest = new BuildRequest(position % world.width(), position / world.width());
|
currentRequest = new BuildRequest(position % world.width(), position / world.width());
|
||||||
@@ -223,8 +224,8 @@ public class Packets{
|
|||||||
byte rotation = buffer.get();
|
byte rotation = buffer.get();
|
||||||
currentRequest = new BuildRequest(position % world.width(), position / world.width(), rotation, Recipe.getByID(recipe));
|
currentRequest = new BuildRequest(position % world.width(), position / world.width(), rotation, Recipe.getByID(recipe));
|
||||||
}
|
}
|
||||||
}else{
|
|
||||||
currentRequest = null;
|
requests.add(currentRequest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user