mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-01-03 13:30:25 +07:00
More refactoring; created Net class for multiplayer in the future
This commit is contained in:
parent
f0e5477346
commit
128079071b
60
core/src/io/anuke/mindustry/Net.java
Normal file
60
core/src/io/anuke/mindustry/Net.java
Normal file
@ -0,0 +1,60 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
import io.anuke.ucore.function.Consumer;
|
||||
|
||||
//TODO stub
|
||||
public class Net{
|
||||
private static boolean server;
|
||||
private static boolean active;
|
||||
private static ObjectMap<Class<?>, Consumer<?>> listeners = new ObjectMap<>();
|
||||
private static NetProvider provider;
|
||||
|
||||
/**Connect to an address.*/
|
||||
public static void connect(String ip, String port) throws IOException{
|
||||
provider.connect(ip, port);
|
||||
}
|
||||
|
||||
/**Send an object to all connected clients.*/
|
||||
public static void send(Object object){
|
||||
provider.send(object);
|
||||
}
|
||||
|
||||
/**Sets the net provider, e.g. what handles sending, recieving and connecting.*/
|
||||
public static void setProvider(NetProvider provider){
|
||||
Net.provider = provider;
|
||||
}
|
||||
|
||||
/**Registers a listener for when an object is recieved.*/
|
||||
public static <T> void handle(Class<T> type, Consumer<T> listener){
|
||||
listeners.put(type, listener);
|
||||
}
|
||||
|
||||
/**Call to handle a packet being recieved.*/
|
||||
public static void handleNetReceived(Object object){
|
||||
if(listeners.get(object.getClass()) != null){
|
||||
|
||||
}else{
|
||||
Gdx.app.error("Net", "Unhandled packet type: '" + object.getClass() + "'!");
|
||||
}
|
||||
}
|
||||
|
||||
/**Whether the net is active, e.g. whether this is a multiplayer game.*/
|
||||
public static boolean active(){
|
||||
return active;
|
||||
}
|
||||
|
||||
/**Whether this is a server or not.*/
|
||||
public static boolean server(){
|
||||
return server;
|
||||
}
|
||||
|
||||
public static interface NetProvider{
|
||||
public void connect(String ip, String port) throws IOException;
|
||||
public void send(Object object);
|
||||
}
|
||||
}
|
@ -12,7 +12,6 @@ import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import com.badlogic.gdx.utils.reflect.Constructor;
|
||||
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.Tutorial;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.ai.Pathfind;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
@ -155,10 +154,7 @@ public class Control extends Module{
|
||||
spacing = 3;
|
||||
scaling = 5;
|
||||
}}
|
||||
|
||||
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
|
@ -12,11 +12,11 @@ import com.badlogic.gdx.graphics.profiling.GLProfiler;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.Shaders;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.TileEntity;
|
||||
import io.anuke.mindustry.entities.effect.Shaders;
|
||||
import io.anuke.mindustry.entities.enemies.Enemy;
|
||||
import io.anuke.mindustry.input.AndroidInput;
|
||||
import io.anuke.mindustry.input.Input;
|
||||
|
@ -1,8 +1,8 @@
|
||||
package io.anuke.mindustry;
|
||||
package io.anuke.mindustry.core;
|
||||
|
||||
import com.badlogic.gdx.math.GridPoint2;
|
||||
|
||||
import io.anuke.mindustry.core.GameState;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.core.GameState.State;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
@ -1,4 +1,4 @@
|
||||
package io.anuke.mindustry;
|
||||
package io.anuke.mindustry.entities.effect;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
|
@ -5,13 +5,13 @@ import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
|
||||
import io.anuke.mindustry.Shaders;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.ai.Pathfind;
|
||||
import io.anuke.mindustry.entities.Bullet;
|
||||
import io.anuke.mindustry.entities.BulletType;
|
||||
import io.anuke.mindustry.entities.Player;
|
||||
import io.anuke.mindustry.entities.effect.Fx;
|
||||
import io.anuke.mindustry.entities.effect.Shaders;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.World;
|
||||
import io.anuke.ucore.core.*;
|
||||
|
Loading…
Reference in New Issue
Block a user