Added build progress sync
This commit is contained in:
@@ -11,6 +11,7 @@ import io.anuke.annotations.Annotations.Remote;
|
||||
import io.anuke.mindustry.content.Mechs;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest;
|
||||
import io.anuke.mindustry.entities.traits.SyncTrait;
|
||||
import io.anuke.mindustry.game.Version;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
@@ -43,7 +44,7 @@ public class NetServer extends Module{
|
||||
public final static boolean showSnapshotSize = false;
|
||||
|
||||
private final static byte[] reusableSnapArray = new byte[maxSnapshotSize];
|
||||
private final static float serverSyncTime = 5, kickDuration = 30 * 1000;
|
||||
private final static float serverSyncTime = 4, kickDuration = 30 * 1000;
|
||||
private final static Vector2 vector = new Vector2();
|
||||
/**If a play goes away of their server-side coordinates by this distance, they get teleported back.*/
|
||||
private final static float correctDist = 16f;
|
||||
@@ -200,8 +201,8 @@ public class NetServer extends Module{
|
||||
player.isBoosting = packet.boosting;
|
||||
player.isShooting = packet.shooting;
|
||||
player.getPlaceQueue().clear();
|
||||
if(packet.currentRequest != null){
|
||||
player.getPlaceQueue().addLast(packet.currentRequest);
|
||||
for(BuildRequest req : packet.requests){
|
||||
player.getPlaceQueue().addLast(req);
|
||||
}
|
||||
|
||||
vector.set(packet.x - player.getInterpolator().target.x, packet.y - player.getInterpolator().target.y);
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.Unit;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.Recipe;
|
||||
import io.anuke.mindustry.world.Build;
|
||||
@@ -71,6 +72,7 @@ public interface BuilderTrait extends Entity{
|
||||
if(request != null){
|
||||
output.writeByte(request.remove ? 1 : 0);
|
||||
output.writeInt(world.toPacked(request.x, request.y));
|
||||
output.writeFloat(request.progress);
|
||||
if(!request.remove){
|
||||
output.writeByte(request.recipe.id);
|
||||
output.writeByte(request.rotation);
|
||||
@@ -91,6 +93,7 @@ public interface BuilderTrait extends Entity{
|
||||
byte type = input.readByte();
|
||||
if(type != -1){
|
||||
int position = input.readInt();
|
||||
float progress = input.readFloat();
|
||||
BuildRequest request;
|
||||
|
||||
if(type == 1){ //remove
|
||||
@@ -101,6 +104,8 @@ public interface BuilderTrait extends Entity{
|
||||
request = new BuildRequest(position % world.width(), position / world.width(), rotation, Recipe.getByID(recipe));
|
||||
}
|
||||
|
||||
request.progress = progress;
|
||||
|
||||
if(applyChanges){
|
||||
getPlaceQueue().addLast(request);
|
||||
}
|
||||
@@ -207,17 +212,21 @@ public interface BuilderTrait extends Entity{
|
||||
return;
|
||||
}
|
||||
|
||||
//deconstructing is 2x as fast
|
||||
if(current.remove){
|
||||
entity.deconstruct(unit, core, 2f / entity.buildCost * Timers.delta() * getBuildPower(tile));
|
||||
}else{
|
||||
entity.construct(unit, core, 1f / entity.buildCost * Timers.delta() * getBuildPower(tile));
|
||||
}
|
||||
|
||||
if(unit.distanceTo(tile) <= placeDistance){
|
||||
unit.rotation = Mathf.slerpDelta(unit.rotation, unit.angleTo(entity), 0.4f);
|
||||
}
|
||||
current.progress = entity.progress();
|
||||
|
||||
//progress is synced, thus not updated clientside
|
||||
if(!Net.client()){
|
||||
//deconstructing is 2x as fast
|
||||
if(current.remove){
|
||||
entity.deconstruct(unit, core, 2f / entity.buildCost * Timers.delta() * getBuildPower(tile));
|
||||
}else{
|
||||
entity.construct(unit, core, 1f / entity.buildCost * Timers.delta() * getBuildPower(tile));
|
||||
}
|
||||
|
||||
current.progress = entity.progress();
|
||||
}
|
||||
}
|
||||
|
||||
/**Do not call directly.*/
|
||||
|
||||
Reference in New Issue
Block a user