More multiplayer fixes
This commit is contained in:
@@ -178,6 +178,7 @@ public class NetServer extends Module{
|
||||
player.pointerX = packet.pointerX;
|
||||
player.pointerY = packet.pointerY;
|
||||
player.setMineTile(packet.mining);
|
||||
player.isBoosting = packet.boosting;
|
||||
|
||||
vector.set(packet.x - player.getInterpolator().target.x, packet.y - player.getInterpolator().target.y);
|
||||
|
||||
|
||||
@@ -41,16 +41,19 @@ public class ItemTransfer extends TimedEntity implements DrawTrait{
|
||||
|
||||
@Remote(in = In.entities, called = Loc.server, unreliable = true)
|
||||
public static void transferItemEffect(Item item, float x, float y, Unit to){
|
||||
if(to == null) return;
|
||||
create(item, x, y, to, () -> {});
|
||||
}
|
||||
|
||||
@Remote(in = In.entities, called = Loc.server, unreliable = true)
|
||||
public static void transferItemToUnit(Item item, float x, float y, Unit to){
|
||||
if(to == null) return;
|
||||
create(item, x, y, to, () -> to.inventory.addItem(item, 1));
|
||||
}
|
||||
|
||||
@Remote(in = In.entities, called = Loc.server)
|
||||
public static void transferItemTo(Item item, int amount, float x, float y, Tile tile){
|
||||
if(tile == null) return;
|
||||
for (int i = 0; i < Mathf.clamp(amount/3, 1, 8); i++) {
|
||||
Timers.run(i*3, () -> create(item, x, y, tile, () -> {}));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.entities.traits;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.net.Interpolator;
|
||||
import io.anuke.ucore.entities.trait.Entity;
|
||||
|
||||
@@ -24,8 +25,8 @@ public interface SyncTrait extends Entity, TypeTrait {
|
||||
if(getInterpolator() != null) {
|
||||
getInterpolator().target.set(x, y);
|
||||
getInterpolator().last.set(x, y);
|
||||
getInterpolator().spacing = 1f;
|
||||
getInterpolator().time = 0f;
|
||||
getInterpolator().updateSpacing = 16;
|
||||
getInterpolator().lastUpdated = TimeUtils.millis();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import io.anuke.mindustry.gen.CallEntity;
|
||||
import io.anuke.mindustry.graphics.Palette;
|
||||
import io.anuke.mindustry.input.PlaceUtils.NormalizeDrawResult;
|
||||
import io.anuke.mindustry.input.PlaceUtils.NormalizeResult;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.core.Graphics;
|
||||
@@ -124,6 +125,10 @@ public class DesktopInput extends InputHandler{
|
||||
|
||||
@Override
|
||||
public void update(){
|
||||
if(Net.active() && Inputs.keyTap("player_list")){
|
||||
ui.listfrag.toggle();
|
||||
}
|
||||
|
||||
if(player.isDead() || state.is(State.menu) || ui.hasDialog()) return;
|
||||
|
||||
player.isBoosting = Inputs.keyDown("dash");
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Interpolator {
|
||||
@@ -11,19 +10,20 @@ public class Interpolator {
|
||||
public Vector2 target = new Vector2();
|
||||
public Vector2 last = new Vector2();
|
||||
public float[] targets = {};
|
||||
public float spacing = 1f;
|
||||
public float time;
|
||||
public long lastUpdated, updateSpacing;
|
||||
|
||||
//current state
|
||||
public Vector2 pos = new Vector2();
|
||||
public float[] values = {};
|
||||
|
||||
public void read(float cx, float cy, float x, float y, long sent, float... target1ds){
|
||||
if(lastUpdated != 0) updateSpacing = TimeUtils.timeSinceMillis(lastUpdated);
|
||||
|
||||
lastUpdated = sent;
|
||||
|
||||
targets = target1ds;
|
||||
time = 0f;
|
||||
last.set(cx, cy);
|
||||
target.set(x, y);
|
||||
spacing = Math.min(Math.max(((TimeUtils.timeSinceMillis(sent) / 1000f) * 60f), 4f), 10);
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
@@ -31,13 +31,36 @@ public class Interpolator {
|
||||
targets = new float[0];
|
||||
target.setZero();
|
||||
last.setZero();
|
||||
spacing = 1f;
|
||||
time = 0f;
|
||||
lastUpdated = updateSpacing = 0;
|
||||
pos.setZero();
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
||||
if(lastUpdated != 0){
|
||||
float timeSinceUpdate = TimeUtils.timeSinceMillis(lastUpdated);
|
||||
float alpha = Math.min(timeSinceUpdate / updateSpacing, 1f);
|
||||
|
||||
Mathf.lerp2(last, target, alpha);
|
||||
|
||||
pos.set(last).lerp(target, alpha);
|
||||
|
||||
if(values.length != targets.length){
|
||||
values = new float[targets.length];
|
||||
}
|
||||
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
values[i] = Mathf.slerp(values[i], targets[i], alpha);
|
||||
}
|
||||
|
||||
if(target.dst(pos) > 128){
|
||||
pos.set(target);
|
||||
last.set(target);
|
||||
}
|
||||
}else{
|
||||
pos.set(target);
|
||||
}
|
||||
/*
|
||||
time += 1f / spacing * Math.min(Timers.delta(), 1f);
|
||||
|
||||
time = Mathf.clamp(time, 0, 2f);
|
||||
@@ -56,7 +79,7 @@ public class Interpolator {
|
||||
pos.set(target);
|
||||
last.set(target);
|
||||
time = 0f;
|
||||
}
|
||||
}*/
|
||||
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ public class HudFragment implements Fragment{
|
||||
|
||||
new imagebutton("icon-pause", isize, () -> {
|
||||
if (Net.active()) {
|
||||
ui.listfrag.visible = !ui.listfrag.visible;
|
||||
ui.listfrag.toggle();
|
||||
} else {
|
||||
state.set(state.is(State.paused) ? State.playing : State.paused);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,31 @@
|
||||
package io.anuke.mindustry.ui.fragments;
|
||||
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.net.EditLog;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
import io.anuke.mindustry.net.Packets.AdminAction;
|
||||
import io.anuke.mindustry.ui.BorderImage;
|
||||
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
|
||||
import io.anuke.ucore.core.Inputs;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.Element;
|
||||
import io.anuke.ucore.scene.Group;
|
||||
import io.anuke.ucore.scene.builders.button;
|
||||
import io.anuke.ucore.scene.builders.label;
|
||||
import io.anuke.ucore.scene.builders.table;
|
||||
import io.anuke.ucore.scene.event.Touchable;
|
||||
import io.anuke.ucore.scene.ui.Image;
|
||||
import io.anuke.ucore.scene.ui.ScrollPane;
|
||||
import io.anuke.ucore.scene.ui.layout.Stack;
|
||||
import io.anuke.ucore.scene.ui.layout.Table;
|
||||
import io.anuke.ucore.util.Bundles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class PlayerListFragment implements Fragment{
|
||||
public boolean visible = false;
|
||||
Table content = new Table();
|
||||
ObjectMap<Player, Boolean> checkmap = new ObjectMap<>();
|
||||
private boolean visible = false;
|
||||
private Table content = new Table();
|
||||
private ObjectMap<Player, Boolean> checkmap = new ObjectMap<>();
|
||||
|
||||
@Override
|
||||
public void build(Group parent){
|
||||
@@ -48,33 +43,25 @@ public class PlayerListFragment implements Fragment{
|
||||
add(pane).grow();
|
||||
row();
|
||||
new table("pane"){{
|
||||
margin(12f);
|
||||
margin(0f);
|
||||
defaults().growX().height(50f).fillY();
|
||||
|
||||
get().addCheck("$text.server.friendlyfire", b -> {
|
||||
//get().addCheck("$text.server.friendlyfire", b -> {
|
||||
// CallClient.friendlyFireChange(b);
|
||||
}).growX().update(i -> i.setChecked(state.friendlyFire)).disabled(b -> Net.client()).padRight(5);
|
||||
//}).left().padLeft(-12).pad(0).update(i -> i.setChecked(state.friendlyFire)).disabled(b -> Net.client()).padRight(5);
|
||||
|
||||
new button("$text.server.bans", () -> {
|
||||
ui.bans.show();
|
||||
}).padTop(-12).padBottom(-12).fillY().cell.disabled(b -> Net.client());
|
||||
}).cell.disabled(b -> Net.client());
|
||||
|
||||
new button("$text.server.admins", () -> {
|
||||
ui.admins.show();
|
||||
}).padTop(-12).padBottom(-12).padRight(-12).fillY().cell.disabled(b -> Net.client());
|
||||
|
||||
new button("$text.server.rollback", () -> {
|
||||
ui.rollback.show();
|
||||
}).padTop(-12).padBottom(-12).padRight(-12).fillY().cell.disabled(b -> !players[0].isAdmin);
|
||||
}).cell.disabled(b -> Net.client());
|
||||
|
||||
}}.pad(10f).growX().end();
|
||||
}}.end();
|
||||
|
||||
update(t -> {
|
||||
if(!mobile){
|
||||
if(Inputs.keyTap("player_list")){
|
||||
visible = !visible;
|
||||
}
|
||||
}
|
||||
if(!(Net.active() && !state.is(State.menu))){
|
||||
visible = false;
|
||||
}
|
||||
@@ -113,15 +100,7 @@ public class PlayerListFragment implements Fragment{
|
||||
|
||||
stack.add(image);
|
||||
|
||||
stack.add(new Element(){
|
||||
public void draw(){
|
||||
float s = getWidth() / 12f;
|
||||
for(int i : Mathf.signs){
|
||||
Draw.rect((player.mech.weapon.name)
|
||||
+ "-equip", x + s * 6 + i * 3*s, y + s*6 + 2*s, -8*s*i, 8*s);
|
||||
}
|
||||
}
|
||||
});
|
||||
stack.add(new Image(player.mech.iconRegion));
|
||||
|
||||
button.add(stack).size(h);
|
||||
button.labelWrap("[#" + player.color.toString().toUpperCase() + "]" + player.name).width(170f).pad(10);
|
||||
@@ -179,44 +158,8 @@ public class PlayerListFragment implements Fragment{
|
||||
content.marginBottom(5);
|
||||
}
|
||||
|
||||
public void showBlockLogs(Array<EditLog> currentEditLogs, int x, int y){
|
||||
boolean wasPaused = state.is(State.paused);
|
||||
state.set(State.paused);
|
||||
|
||||
FloatingDialog d = new FloatingDialog("$text.blocks.editlogs");
|
||||
Table table = new Table();
|
||||
table.defaults().pad(1f);
|
||||
ScrollPane pane = new ScrollPane(table, "clear");
|
||||
pane.setFadeScrollBars(false);
|
||||
Table top = new Table();
|
||||
top.left();
|
||||
top.add("[accent]Edit logs for: "+ x + ", " + y);
|
||||
table.add(top).fill().left();
|
||||
table.row();
|
||||
|
||||
d.content().add(pane).grow();
|
||||
|
||||
if(currentEditLogs == null || currentEditLogs.size == 0) {
|
||||
table.add("$text.block.editlogsnotfound").left();
|
||||
table.row();
|
||||
}
|
||||
|
||||
else {
|
||||
for(int i = 0; i < currentEditLogs.size; i++) {
|
||||
EditLog log = currentEditLogs.get(i);
|
||||
//TODO display log info.
|
||||
table.add("[gold]" + (i + 1) + ". [white]INVALID").left();
|
||||
table.row();
|
||||
}
|
||||
}
|
||||
|
||||
d.buttons().addButton("$text.ok", () -> {
|
||||
if(!wasPaused)
|
||||
state.set(State.playing);
|
||||
d.hide();
|
||||
}).size(110, 50).pad(10f);
|
||||
|
||||
d.show();
|
||||
public void toggle(){
|
||||
visible = !visible;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -107,6 +107,10 @@ public class BreakBlock extends Block {
|
||||
public void drawShadow(Tile tile) {
|
||||
BreakEntity entity = tile.entity();
|
||||
|
||||
if(entity.previous instanceof BreakBlock){
|
||||
return;
|
||||
}
|
||||
|
||||
entity.previous.drawShadow(tile);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user