mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 11:17:11 +07:00
Implemented sending of players to client (incomplete)
This commit is contained in:
parent
7b1c8d5769
commit
eecd0f6d02
@ -52,6 +52,7 @@ public class Control extends Module{
|
||||
public final EntityGroup<TileEntity> tileGroup = Entities.addGroup(TileEntity.class, false);
|
||||
public final EntityGroup<Bullet> bulletGroup = Entities.addGroup(Bullet.class);
|
||||
public final EntityGroup<Shield> shieldGroup = Entities.addGroup(Shield.class);
|
||||
public final EntityGroup<Player> playerGroup = Entities.addGroup(Player.class);
|
||||
|
||||
Array<EnemySpawn> spawns;
|
||||
int wave = 1;
|
||||
@ -660,9 +661,10 @@ public class Control extends Module{
|
||||
Entities.update(enemyGroup);
|
||||
Entities.update(tileGroup);
|
||||
Entities.update(shieldGroup);
|
||||
Entities.update(playerGroup);
|
||||
|
||||
Entities.collideGroups(enemyGroup, bulletGroup);
|
||||
Entities.collideGroups(Entities.defaultGroup(), bulletGroup);
|
||||
Entities.collideGroups(playerGroup, bulletGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
@ -9,6 +10,7 @@ import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.Packets.Connect;
|
||||
import io.anuke.mindustry.net.Packets.Disconnect;
|
||||
import io.anuke.mindustry.net.Packets.EntityDataPacket;
|
||||
import io.anuke.mindustry.net.Packets.WorldData;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
@ -42,12 +44,26 @@ public class NetClient extends Module {
|
||||
Gdx.app.postRunnable(() -> {
|
||||
UCore.log("Recieved world data: " + data.stream.available() + " bytes.");
|
||||
SaveIO.load(data.stream);
|
||||
|
||||
GameState.set(State.playing);
|
||||
connecting = false;
|
||||
Vars.ui.hideLoading();
|
||||
Vars.ui.hideJoinGame();
|
||||
});
|
||||
});
|
||||
|
||||
Net.handle(EntityDataPacket.class, data -> {
|
||||
|
||||
Gdx.app.postRunnable(() -> {
|
||||
Timers.run(10f, () -> {
|
||||
for (Player player : data.players) {
|
||||
if (player.id != data.playerid) {
|
||||
player.add();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
public void update(){
|
||||
|
@ -1,19 +1,27 @@
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.IntMap;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.net.Net.SendMode;
|
||||
import io.anuke.mindustry.net.Packets.Connect;
|
||||
import io.anuke.mindustry.net.Packets.EntityDataPacket;
|
||||
import io.anuke.mindustry.net.Packets.SyncPacket;
|
||||
import io.anuke.mindustry.net.Packets.WorldData;
|
||||
import io.anuke.ucore.UCore;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.modules.Module;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class NetServer extends Module{
|
||||
IntMap<Player> connections = new IntMap<>();
|
||||
float serverSyncTime = 4;
|
||||
|
||||
public NetServer(){
|
||||
|
||||
@ -24,10 +32,26 @@ public class NetServer extends Module{
|
||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||
SaveIO.write(stream);
|
||||
|
||||
UCore.log("Packed " + stream.size() + " bytes of data.");
|
||||
UCore.log("Packed " + stream.size() + " uncompressed bytes of data.");
|
||||
|
||||
//TODO compress and uncompress when sending
|
||||
data.stream = new ByteArrayInputStream(stream.toByteArray());
|
||||
|
||||
Net.sendStream(packet.id, data);
|
||||
|
||||
Gdx.app.postRunnable(() -> {
|
||||
EntityDataPacket dp = new EntityDataPacket();
|
||||
|
||||
Player player = new Player();
|
||||
player.clientid = packet.id;
|
||||
player.add();
|
||||
connections.put(player.id, player);
|
||||
|
||||
dp.playerid = player.id;
|
||||
dp.players = Vars.control.playerGroup.all().toArray(Player.class);
|
||||
|
||||
Net.sendTo(packet.id, dp, SendMode.tcp);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -35,9 +59,19 @@ public class NetServer extends Module{
|
||||
if(!Net.server()) return;
|
||||
|
||||
if(!GameState.is(State.menu) && Net.active()){
|
||||
|
||||
sync();
|
||||
}else{
|
||||
Net.closeServer();
|
||||
}
|
||||
}
|
||||
|
||||
void sync(){
|
||||
if(Timers.get("serverSync", serverSyncTime)){
|
||||
SyncPacket packet = new SyncPacket();
|
||||
|
||||
for(Player player : Vars.control.playerGroup.all()){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -222,6 +222,7 @@ public class Renderer extends RendererModule{
|
||||
Entities.draw(control.enemyGroup);
|
||||
Graphics.shader();
|
||||
|
||||
Entities.draw(control.playerGroup);
|
||||
Entities.draw(Entities.defaultGroup());
|
||||
|
||||
blocks.drawBlocks(true);
|
||||
|
@ -7,6 +7,7 @@ import com.badlogic.gdx.Input.Buttons;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.graphics.Fx;
|
||||
import io.anuke.mindustry.input.PlaceMode;
|
||||
import io.anuke.mindustry.net.Syncable;
|
||||
import io.anuke.mindustry.resource.Mech;
|
||||
import io.anuke.mindustry.resource.Recipe;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
@ -17,14 +18,16 @@ import io.anuke.ucore.entities.DestructibleEntity;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Player extends DestructibleEntity{
|
||||
public class Player extends DestructibleEntity implements Syncable{
|
||||
private static final float speed = 1.1f;
|
||||
private static final float dashSpeed = 1.8f;
|
||||
|
||||
public Weapon weapon;
|
||||
public transient Weapon weapon;
|
||||
public Mech mech = Mech.standard;
|
||||
public float angle;
|
||||
|
||||
|
||||
public transient int clientid;
|
||||
|
||||
public transient float breaktime = 0;
|
||||
public transient Recipe recipe;
|
||||
public transient int rotation;
|
||||
@ -122,4 +125,9 @@ public class Player extends DestructibleEntity{
|
||||
this.angle = Mathf.lerpAngDelta(this.angle, angle, 0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player add(){
|
||||
return add(Vars.control.playerGroup);
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,7 @@ public class Enemy extends DestructibleEntity{
|
||||
|
||||
//no tile found
|
||||
if(target == null){
|
||||
target = Entities.getClosest(Entities.defaultGroup(), x, y, range, e -> e instanceof Player);
|
||||
target = Entities.getClosest(Vars.control.playerGroup, x, y, range, e -> true);
|
||||
}
|
||||
}else if(nearCore){
|
||||
target = Vars.control.getCore().entity;
|
||||
|
@ -1,6 +1,8 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import java.io.InputStream;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
|
||||
/**Class for storing all packets.*/
|
||||
public class Packets {
|
||||
@ -18,4 +20,13 @@ public class Packets {
|
||||
public static class WorldData extends Streamable{
|
||||
|
||||
}
|
||||
|
||||
public static class EntityDataPacket{
|
||||
public Player[] players;
|
||||
public int playerid;
|
||||
}
|
||||
|
||||
public static class SyncPacket{
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,16 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.net.Packets.EntityDataPacket;
|
||||
import io.anuke.mindustry.net.Packets.SyncPacket;
|
||||
import io.anuke.mindustry.net.Packets.WorldData;
|
||||
import io.anuke.mindustry.net.Streamable.StreamBegin;
|
||||
import io.anuke.mindustry.net.Streamable.StreamChunk;
|
||||
import io.anuke.mindustry.resource.Mech;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.ucore.entities.Entity;
|
||||
|
||||
public class Registrator {
|
||||
|
||||
@ -11,8 +19,18 @@ public class Registrator {
|
||||
StreamBegin.class,
|
||||
StreamChunk.class,
|
||||
WorldData.class,
|
||||
SyncPacket.class,
|
||||
EntityDataPacket.class,
|
||||
Class.class,
|
||||
byte[].class
|
||||
byte[].class,
|
||||
Entity[].class,
|
||||
Player[].class,
|
||||
Array.class,
|
||||
Vector2.class,
|
||||
|
||||
Entity.class,
|
||||
Player.class,
|
||||
Mech.class
|
||||
};
|
||||
}
|
||||
}
|
||||
|
4
core/src/io/anuke/mindustry/net/Syncable.java
Normal file
4
core/src/io/anuke/mindustry/net/Syncable.java
Normal file
@ -0,0 +1,4 @@
|
||||
package io.anuke.mindustry.net;
|
||||
|
||||
public interface Syncable {
|
||||
}
|
@ -13,6 +13,7 @@ import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import com.badlogic.gdx.utils.compression.Lzma;
|
||||
import com.esotericsoftware.kryonet.*;
|
||||
import com.esotericsoftware.kryonet.util.InputStreamSender;
|
||||
import com.esotericsoftware.minlog.Log;
|
||||
|
Loading…
Reference in New Issue
Block a user