mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-11 15:48:07 +07:00
Experimental new block sync system
This commit is contained in:
parent
608343b9d1
commit
9dbed76a53
@ -15,6 +15,7 @@ import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.NetworkIO;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.world.Map;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.ProductionBlocks;
|
||||
@ -263,6 +264,13 @@ public class NetClient extends Module {
|
||||
});
|
||||
|
||||
Net.handleClient(FriendlyFireChangePacket.class, packet -> state.friendlyFire = packet.enabled);
|
||||
|
||||
Net.handleClient(ItemTransferPacket.class, packet -> {
|
||||
Tile tile = world.tile(packet.position);
|
||||
Tile next = tile.getNearby(packet.rotation);
|
||||
tile.entity.items[packet.itemid] --;
|
||||
next.block().handleItem(Item.getByID(packet.itemid), next, tile);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,9 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.utils.*;
|
||||
import com.badlogic.gdx.utils.ByteArray;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.SyncEntity;
|
||||
@ -8,7 +11,6 @@ import io.anuke.mindustry.game.EventType.GameOverEvent;
|
||||
import io.anuke.mindustry.io.Platform;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.NetConnection;
|
||||
import io.anuke.mindustry.net.NetworkIO;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.resource.Upgrade;
|
||||
@ -21,7 +23,6 @@ import io.anuke.ucore.entities.Entities;
|
||||
import io.anuke.ucore.entities.EntityGroup;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
import io.anuke.ucore.util.Log;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@ -288,8 +289,7 @@ public class NetServer extends Module{
|
||||
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
if(Timers.get("serverBlockSync", blockSyncTime)){
|
||||
|
||||
Array<NetConnection> connections = Net.getConnections();
|
||||
@ -304,7 +304,7 @@ public class NetServer extends Module{
|
||||
int h = 16;
|
||||
sendBlockSync(id, x, y, w, h);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public void sendBlockSync(int client, int x, int y, int viewx, int viewy){
|
||||
|
@ -6,12 +6,14 @@ import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.Packets.*;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.Vars.netCommon;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
public class NetEvents {
|
||||
|
||||
@ -127,4 +129,12 @@ public class NetEvents {
|
||||
packet.y = (short)y;
|
||||
Net.send(packet, SendMode.tcp);
|
||||
}
|
||||
|
||||
public static void handleTransfer(Tile tile, byte rotation, Item item){
|
||||
ItemTransferPacket packet = new ItemTransferPacket();
|
||||
packet.position = tile.packedPosition();
|
||||
packet.rotation = rotation;
|
||||
packet.itemid = (byte)item.id;
|
||||
Net.send(packet, SendMode.udp);
|
||||
}
|
||||
}
|
||||
|
@ -500,4 +500,24 @@ public class Packets {
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) { }
|
||||
}
|
||||
|
||||
public static class ItemTransferPacket implements Packet{
|
||||
public int position;
|
||||
public byte rotation;
|
||||
public byte itemid;
|
||||
|
||||
@Override
|
||||
public void write(ByteBuffer buffer) {
|
||||
buffer.putInt(position);
|
||||
buffer.put(rotation);
|
||||
buffer.put(itemid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteBuffer buffer) {
|
||||
position = buffer.getInt();
|
||||
rotation = buffer.get();
|
||||
itemid = buffer.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ public class Registrator {
|
||||
CustomMapPacket.class,
|
||||
MapAckPacket.class,
|
||||
EntitySpawnPacket.class,
|
||||
ItemTransferPacket.class
|
||||
};
|
||||
private static ObjectIntMap<Class<?>> ids = new ObjectIntMap<>();
|
||||
|
||||
|
@ -8,6 +8,7 @@ import com.badlogic.gdx.utils.ObjectMap;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.NetEvents;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
@ -173,6 +174,8 @@ public class Block{
|
||||
* Tries to put this item into a nearby container, if there are no available
|
||||
* containers, it gets added to the block's inventory.*/
|
||||
protected void offloadNear(Tile tile, Item item){
|
||||
if(Net.client()) return;
|
||||
|
||||
byte i = tile.getDump();
|
||||
byte pdump = (byte)(i % 4);
|
||||
|
||||
@ -183,6 +186,7 @@ public class Block{
|
||||
if(other != null && other.block().acceptItem(item, other, tile)){
|
||||
other.block().handleItem(item, other, tile);
|
||||
tile.setDump((byte)((i+1)%4));
|
||||
if(Net.server()) NetEvents.handleTransfer(tile, i, item);
|
||||
return;
|
||||
}
|
||||
i++;
|
||||
@ -201,6 +205,8 @@ public class Block{
|
||||
* Try dumping any item near the tile. -1 = any direction
|
||||
*/
|
||||
protected boolean tryDump(Tile tile, int direction, Item todump){
|
||||
if(Net.client()) return false;
|
||||
|
||||
int i = tile.getDump()%4;
|
||||
|
||||
Tile[] tiles = tile.getNearby(temptiles);
|
||||
@ -217,6 +223,7 @@ public class Block{
|
||||
other.block().handleItem(item, other, tile);
|
||||
tile.entity.removeItem(item, 1);
|
||||
tile.setDump((byte)((i+1)%4));
|
||||
if(Net.server()) NetEvents.handleTransfer(tile, (byte)i, item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -229,6 +229,14 @@ public class Tile{
|
||||
return world.tile(x - (dx - 8), y - (dy - 8));
|
||||
}
|
||||
}
|
||||
|
||||
public Tile getNearby(int rotation){
|
||||
if(rotation == 0) return world.tile(x + 1, y);
|
||||
if(rotation == 1) return world.tile(x, y + 1);
|
||||
if(rotation == 2) return world.tile(x - 1, y);
|
||||
if(rotation == 3) return world.tile(x, y - 1);
|
||||
return null;
|
||||
}
|
||||
|
||||
public Tile[] getNearby(){
|
||||
return world.getNearby(x, y);
|
||||
|
Loading…
Reference in New Issue
Block a user