Various sync fixes
This commit is contained in:
@@ -334,12 +334,12 @@ public class UnitTypes implements ContentList{
|
||||
accel = 0.1f;
|
||||
range = 70f;
|
||||
itemCapacity = 30;
|
||||
health = 400;
|
||||
health = 80f;
|
||||
engineOffset = 6f;
|
||||
hitsize = 8f;
|
||||
|
||||
weapons.add(new Weapon("small-basic-weapon"){{
|
||||
reload = 20f;
|
||||
reload = 25f;
|
||||
x = -1f;
|
||||
y = -1f;
|
||||
shootX = 3.5f;
|
||||
|
||||
@@ -548,10 +548,16 @@ public class NetServer implements ApplicationListener{
|
||||
connection.viewWidth = viewWidth;
|
||||
connection.viewHeight = viewHeight;
|
||||
|
||||
//disable shooting when a mech flies
|
||||
if(!player.dead() && player.unit().isFlying() && !player.unit().type().flying){
|
||||
shooting = false;
|
||||
}
|
||||
|
||||
player.mouseX(pointerX);
|
||||
player.mouseY(pointerY);
|
||||
player.typing(chatting);
|
||||
player.shooting(shooting);
|
||||
player.boosting(boosting);
|
||||
|
||||
player.unit().controlWeapons(shooting, shooting);
|
||||
player.unit().aim(pointerX, pointerY);
|
||||
@@ -593,8 +599,6 @@ public class NetServer implements ApplicationListener{
|
||||
connection.rejectedRequests.clear();
|
||||
|
||||
if(!player.dead()){
|
||||
player.unit().elevation(!player.unit().type().flying && boosting && player.unit().type().canBoost ? 1f : 0f);
|
||||
|
||||
Unitc unit = player.unit();
|
||||
long elapsed = Time.timeSinceMillis(connection.lastRecievedClientTime);
|
||||
float maxSpeed = player.dead() ? Float.MAX_VALUE : player.unit().type().speed;
|
||||
@@ -645,8 +649,9 @@ public class NetServer implements ApplicationListener{
|
||||
//read sync data so it can be used for interpolation for the server
|
||||
unit.readSyncManual(fbuffer);
|
||||
|
||||
//TODO fix
|
||||
unit.vel().set(xVelocity, yVelocity); //only for visual calculation purposes, doesn't actually update the player (TODO or does it?)
|
||||
//TODO clients shouldn't care about velocities, so should it always just get set to 0? why even save it?
|
||||
//[[ignore sent velocity values, set it to the delta movement vector instead]]
|
||||
//unit.vel().set(vector);
|
||||
}else{
|
||||
player.x(x);
|
||||
player.y(y);
|
||||
|
||||
@@ -17,7 +17,7 @@ abstract class FlyingComp implements Posc, Velc, Healthc, Hitboxc{
|
||||
@Import float x, y;
|
||||
@Import Vec2 vel;
|
||||
|
||||
float elevation;
|
||||
@SyncField(value = true, clamped = true) @SyncLocal float elevation;
|
||||
private transient boolean wasFlying;
|
||||
transient float drownTime;
|
||||
transient float splashTimer;
|
||||
|
||||
@@ -7,7 +7,7 @@ import mindustry.gen.*;
|
||||
|
||||
@Component
|
||||
abstract class LegsComp implements Posc, Flyingc, Hitboxc, Unitc, Legsc, ElevationMovec{
|
||||
@SyncField(false) float baseRotation;
|
||||
@SyncField(false) @SyncLocal float baseRotation;
|
||||
transient float walkTime;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@ import mindustry.net.Administration.*;
|
||||
import mindustry.net.*;
|
||||
import mindustry.net.Packets.*;
|
||||
import mindustry.ui.*;
|
||||
import mindustry.world.*;
|
||||
import mindustry.world.blocks.storage.CoreBlock.*;
|
||||
|
||||
import static mindustry.Vars.*;
|
||||
@@ -32,7 +33,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
||||
|
||||
@ReadOnly Team team = Team.sharded;
|
||||
String name = "noname";
|
||||
boolean admin, typing, shooting;
|
||||
boolean admin, typing, shooting, boosting;
|
||||
Color color = new Color();
|
||||
float mouseX, mouseY;
|
||||
|
||||
@@ -71,7 +72,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
||||
public void afterSync(){
|
||||
unit.aim(mouseX, mouseY);
|
||||
//this is only necessary when the thing being controlled isn't synced
|
||||
unit.isShooting(shooting);
|
||||
unit.controlWeapons(shooting, shooting);
|
||||
//extra precaution, necessary for non-synced things
|
||||
unit.controller(this);
|
||||
}
|
||||
@@ -89,14 +90,24 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
|
||||
y(unit.y());
|
||||
unit.team(team);
|
||||
deathTimer = 0;
|
||||
|
||||
//update some basic state to sync things
|
||||
if(unit.type().canBoost){
|
||||
Tile tile = unit.tileOn();
|
||||
unit.elevation(Mathf.approachDelta(unit.elevation(), (tile != null && tile.solid()) || boosting ? 1f : 0f, 0.08f));
|
||||
}
|
||||
}else if(core != null){
|
||||
//have a small delay before death to prevent the camera from jumping around too quickly
|
||||
//(this is not for balance)
|
||||
deathTimer += Time.delta();
|
||||
if(deathTimer >= deathDelay){
|
||||
core.requestSpawn((Playerc)this);
|
||||
deathTimer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
textFadeTime -= Time.delta() / (60 * 5);
|
||||
|
||||
}
|
||||
|
||||
public void team(Team team){
|
||||
|
||||
@@ -12,7 +12,7 @@ import static mindustry.Vars.world;
|
||||
|
||||
@Component
|
||||
abstract class PosComp implements Position{
|
||||
@SyncField(true) float x, y;
|
||||
@SyncField(true) @SyncLocal float x, y;
|
||||
|
||||
void set(float x, float y){
|
||||
this.x = x;
|
||||
|
||||
@@ -5,5 +5,5 @@ import mindustry.gen.*;
|
||||
|
||||
@Component
|
||||
abstract class RotComp implements Entityc{
|
||||
@SyncField(false) float rotation;
|
||||
@SyncField(false) @SyncLocal float rotation;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,8 @@ import mindustry.gen.*;
|
||||
abstract class VelComp implements Posc{
|
||||
@Import float x, y;
|
||||
|
||||
final Vec2 vel = new Vec2();
|
||||
//TODO @SyncLocal this? does it even need to be sent?
|
||||
transient final Vec2 vel = new Vec2();
|
||||
transient float drag = 0f;
|
||||
|
||||
//velocity needs to be called first, as it affects delta and lastPosition
|
||||
|
||||
@@ -588,15 +588,9 @@ public class DesktopInput extends InputHandler{
|
||||
}
|
||||
|
||||
unit.aim(unit.type().faceTarget ? Core.input.mouseWorld() : Tmp.v1.trns(unit.rotation(), Core.input.mouseWorld().dst(unit)).add(unit.x(), unit.y()));
|
||||
unit.controlWeapons(true, isShooting && !(!unit.type().flying && unit.isFlying()));
|
||||
|
||||
unit.controlWeapons(true, isShooting);
|
||||
|
||||
isBoosting = Core.input.keyDown(Binding.boost);
|
||||
|
||||
if(unit.type().canBoost){
|
||||
Tile tile = unit.tileOn();
|
||||
|
||||
unit.elevation(Mathf.approachDelta(unit.elevation(), (tile != null && tile.solid()) || (isBoosting && !movement.isZero()) ? 1f : 0f, 0.08f));
|
||||
}
|
||||
isBoosting = Core.input.keyDown(Binding.boost) && !movement.isZero();
|
||||
player.boosting(isBoosting);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,14 +43,15 @@ public class CoreBlock extends StorageBlock{
|
||||
CoreEntity entity = tile.ent();
|
||||
CoreBlock block = (CoreBlock)tile.block();
|
||||
Fx.spawn.at(entity);
|
||||
entity.progress = 0;
|
||||
|
||||
Unitc unit = block.unitType.create(tile.team());
|
||||
unit.set(entity);
|
||||
unit.impulse(0f, 8f);
|
||||
unit.controller(player);
|
||||
unit.spawnedByCore(true);
|
||||
unit.add();
|
||||
if(!net.client()){
|
||||
Unitc unit = block.unitType.create(tile.team());
|
||||
unit.set(entity);
|
||||
unit.impulse(0f, 2f);
|
||||
unit.controller(player);
|
||||
unit.spawnedByCore(true);
|
||||
unit.add();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -78,20 +79,10 @@ public class CoreBlock extends StorageBlock{
|
||||
}
|
||||
|
||||
public class CoreEntity extends TileEntity{
|
||||
protected float time, heat, progress;
|
||||
protected int storageCapacity;
|
||||
protected boolean shouldBuild;
|
||||
protected Playerc lastRequested;
|
||||
|
||||
public void requestSpawn(Playerc player){
|
||||
shouldBuild = true;
|
||||
if(lastRequested == null){
|
||||
lastRequested = player;
|
||||
}
|
||||
|
||||
if(progress >= 1f){
|
||||
Call.onPlayerSpawn(tile, player);
|
||||
}
|
||||
Call.onPlayerSpawn(tile, player);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,17 +201,6 @@ public class CoreBlock extends StorageBlock{
|
||||
state.teams.registerCore(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(){
|
||||
super.draw();
|
||||
|
||||
if(heat > 0.001f){
|
||||
Draw.draw(Layer.blockOver, () -> {
|
||||
Drawf.respawn(this, heat, progress, time, unitType, lastRequested);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleItem(Tilec source, Item item){
|
||||
if(net.server() || !net.active()){
|
||||
@@ -230,26 +210,5 @@ public class CoreBlock extends StorageBlock{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTile(){
|
||||
|
||||
if(shouldBuild){
|
||||
heat = Mathf.lerpDelta(heat, 1f, 0.1f);
|
||||
time += delta();
|
||||
progress += 1f / state.rules.respawnTime * delta();
|
||||
}else{
|
||||
progress = 0f;
|
||||
heat = Mathf.lerpDelta(heat, 0f, 0.1f);
|
||||
}
|
||||
|
||||
shouldBuild = false;
|
||||
lastRequested = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldActiveSound(){
|
||||
return shouldBuild;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user