Work on networking
This commit is contained in:
parent
0f8609079a
commit
992bd92d5f
@ -30,7 +30,14 @@ public class MainConfig {
|
|||||||
//
|
//
|
||||||
//Networking related
|
//Networking related
|
||||||
//
|
//
|
||||||
|
//should we run a server at all?
|
||||||
public boolean runServer;
|
public boolean runServer;
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//Rendering related
|
||||||
|
//
|
||||||
|
//should the renderer run at all?
|
||||||
public boolean runRenderer;
|
public boolean runRenderer;
|
||||||
|
|
||||||
|
|
||||||
@ -45,6 +52,9 @@ public class MainConfig {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate a localconfig.json and save it to our resources dir
|
||||||
|
*/
|
||||||
public static void generateMainConfig(){
|
public static void generateMainConfig(){
|
||||||
System.out.println("localconfig.json either doesn't exist or is out of date");
|
System.out.println("localconfig.json either doesn't exist or is out of date");
|
||||||
System.out.println("Would you like to generate a new one?(1-y/0-n)");
|
System.out.println("Would you like to generate a new one?(1-y/0-n)");
|
||||||
|
|||||||
@ -0,0 +1,9 @@
|
|||||||
|
package electrosphere.game.simcell.physical;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author satellite
|
||||||
|
*/
|
||||||
|
public class PhysicalCell {
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
package electrosphere.game.simcell.virtual;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author satellite
|
||||||
|
*/
|
||||||
|
public class VirtualCell {
|
||||||
|
|
||||||
|
}
|
||||||
@ -13,6 +13,7 @@ import electrosphere.cfg.MainConfig;
|
|||||||
import electrosphere.entity.Entity;
|
import electrosphere.entity.Entity;
|
||||||
import electrosphere.entity.EntityManager;
|
import electrosphere.entity.EntityManager;
|
||||||
import electrosphere.game.cell.CellManager;
|
import electrosphere.game.cell.CellManager;
|
||||||
|
import electrosphere.net.client.Connection;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@ -38,6 +39,14 @@ public class Globals {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//
|
||||||
|
//Client connection to server
|
||||||
|
//
|
||||||
|
public static Connection connection;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
//Generic OpenGL Statements
|
//Generic OpenGL Statements
|
||||||
//
|
//
|
||||||
|
|||||||
@ -12,6 +12,8 @@ import electrosphere.entity.Entity;
|
|||||||
import electrosphere.entity.EntityUtil;
|
import electrosphere.entity.EntityUtil;
|
||||||
import electrosphere.game.cell.CellManager;
|
import electrosphere.game.cell.CellManager;
|
||||||
import electrosphere.game.terrain.TerrainManager;
|
import electrosphere.game.terrain.TerrainManager;
|
||||||
|
import electrosphere.net.client.Connection;
|
||||||
|
import electrosphere.net.server.Server;
|
||||||
import electrosphere.renderer.ModelUtils;
|
import electrosphere.renderer.ModelUtils;
|
||||||
import electrosphere.terraingen.TerrainGen;
|
import electrosphere.terraingen.TerrainGen;
|
||||||
import electrosphere.terraingen.models.TerrainModel;
|
import electrosphere.terraingen.models.TerrainModel;
|
||||||
@ -89,8 +91,8 @@ public class Main {
|
|||||||
public static boolean CAMERA_IS_ORBIT = true;
|
public static boolean CAMERA_IS_ORBIT = true;
|
||||||
public static float camera_Orbit_Length = 1.0f;
|
public static float camera_Orbit_Length = 1.0f;
|
||||||
|
|
||||||
static final int playerStartRealX = 580 * 200;
|
static int playerStartRealX = 580 * 200;
|
||||||
static final int playerStartRealY = 900 * 200;
|
static int playerStartRealY = 900 * 200;
|
||||||
|
|
||||||
// public static Camera cam_Player_Orbit;
|
// public static Camera cam_Player_Orbit;
|
||||||
//Camera angles using theta-phi system
|
//Camera angles using theta-phi system
|
||||||
@ -114,23 +116,29 @@ public class Main {
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
|
|
||||||
|
if(Globals.mainConfig.runServer){
|
||||||
|
forkServer();
|
||||||
|
}
|
||||||
|
|
||||||
//run initialization stuff
|
//run initialization stuff
|
||||||
|
initTerrainManager();
|
||||||
|
|
||||||
initWorld();
|
if(Globals.mainConfig.runRenderer){
|
||||||
|
//Create opengl
|
||||||
|
RenderUtils.createOpenglContext();
|
||||||
//Create opengl
|
}
|
||||||
RenderUtils.createOpenglContext();
|
|
||||||
|
|
||||||
//init global variables
|
//init global variables
|
||||||
Globals.initGlobals();
|
Globals.initGlobals();
|
||||||
|
|
||||||
|
if(Globals.mainConfig.runRenderer){
|
||||||
|
forkConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if(Globals.mainConfig.runRenderer){
|
||||||
initWorld();
|
initCellManager();
|
||||||
|
}
|
||||||
initCellManager();
|
|
||||||
|
|
||||||
initSkybox();
|
initSkybox();
|
||||||
|
|
||||||
@ -148,10 +156,10 @@ public class Main {
|
|||||||
Camera camera_player_chase = new Camera();
|
Camera camera_player_chase = new Camera();
|
||||||
Camera cam_Player_Orbit = new Camera();
|
Camera cam_Player_Orbit = new Camera();
|
||||||
|
|
||||||
|
boolean running = true;
|
||||||
|
|
||||||
//main loop
|
//main loop
|
||||||
while (!glfwWindowShouldClose(Globals.window)) {
|
while (running) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Frame calculation
|
Frame calculation
|
||||||
@ -278,6 +286,10 @@ public class Main {
|
|||||||
//check and call events and swap the buffers
|
//check and call events and swap the buffers
|
||||||
glfwSwapBuffers(Globals.window);
|
glfwSwapBuffers(Globals.window);
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
|
|
||||||
|
if(glfwWindowShouldClose(Globals.window)){
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//Terminate the program.
|
//Terminate the program.
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
@ -340,7 +352,7 @@ public class Main {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void initWorld(){
|
static void initTerrainManager(){
|
||||||
|
|
||||||
float[][] elevation;
|
float[][] elevation;
|
||||||
terrainManager = new TerrainManager(2000,200,100);
|
terrainManager = new TerrainManager(2000,200,100);
|
||||||
@ -393,6 +405,9 @@ public class Main {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
playerStartRealX = playerStartX * chunkSize;
|
||||||
|
playerStartRealY = playerStartY * chunkSize;
|
||||||
|
|
||||||
Globals.player = new Entity();
|
Globals.player = new Entity();
|
||||||
Globals.player.putData("position", new Vector3f(playerStartX*chunkSize,terrainManager.getHeightAtPosition(playerStartX*chunkSize, playerStartY*chunkSize),playerStartY*chunkSize));
|
Globals.player.putData("position", new Vector3f(playerStartX*chunkSize,terrainManager.getHeightAtPosition(playerStartX*chunkSize, playerStartY*chunkSize),playerStartY*chunkSize));
|
||||||
|
|
||||||
@ -403,12 +418,12 @@ public class Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void initServer(){
|
public static void forkServer(){
|
||||||
|
Server.startServerThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initClient(){
|
public static void forkConnection(){
|
||||||
|
Connection.startConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
package electrosphere.net.client;
|
package electrosphere.net.client;
|
||||||
|
|
||||||
|
import electrosphere.main.Globals;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import org.apache.commons.crypto.stream.CryptoInputStream;
|
import org.apache.commons.crypto.stream.CryptoInputStream;
|
||||||
import org.apache.commons.crypto.stream.CryptoOutputStream;
|
import org.apache.commons.crypto.stream.CryptoOutputStream;
|
||||||
|
|
||||||
@ -9,11 +13,59 @@ import org.apache.commons.crypto.stream.CryptoOutputStream;
|
|||||||
* @author amaterasu
|
* @author amaterasu
|
||||||
*/
|
*/
|
||||||
public class Connection {
|
public class Connection {
|
||||||
|
|
||||||
|
enum ConnectionState {
|
||||||
|
HANDSHAKE_START,
|
||||||
|
HANDSHAKE_SUCCESS,
|
||||||
|
HANDSHAKE_FAILURE,
|
||||||
|
}
|
||||||
|
|
||||||
|
ConnectionState state;
|
||||||
|
|
||||||
|
static int port = 42536;
|
||||||
|
|
||||||
Socket socket;
|
Socket socket;
|
||||||
|
|
||||||
CryptoInputStream inputStream;
|
CryptoInputStream inputStream;
|
||||||
|
|
||||||
CryptoOutputStream outputStream;
|
CryptoOutputStream outputStream;
|
||||||
|
|
||||||
|
public Connection(String address, int port){
|
||||||
|
try {
|
||||||
|
this.socket = new Socket(address,port);
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.err.println("Failed to connect!");
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void processAllPackets(){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void startConnection(){
|
||||||
|
Globals.connection = new Connection("localhost",port);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class ConnectionProtocol implements Runnable {
|
||||||
|
Connection connection;
|
||||||
|
|
||||||
|
public ConnectionProtocol(Connection conn){
|
||||||
|
connection = conn;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
boolean running = true;
|
||||||
|
// while(running){
|
||||||
|
// if(connection.inputStream.read)
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ import org.apache.commons.crypto.stream.CryptoOutputStream;
|
|||||||
*
|
*
|
||||||
* @author satellite
|
* @author satellite
|
||||||
*/
|
*/
|
||||||
public class Client {
|
public class Client implements Runnable {
|
||||||
|
|
||||||
|
|
||||||
Socket socket;
|
Socket socket;
|
||||||
@ -17,4 +17,14 @@ public class Client {
|
|||||||
|
|
||||||
CryptoOutputStream outputStream;
|
CryptoOutputStream outputStream;
|
||||||
|
|
||||||
|
|
||||||
|
public Client(Socket socket) {
|
||||||
|
this.socket = socket;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
System.out.println("aaaaaaaaaaaeoiu");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,11 @@
|
|||||||
package electrosphere.net.server;
|
package electrosphere.net.server;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
|
import java.net.Socket;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -8,9 +13,52 @@ import java.net.ServerSocket;
|
|||||||
*/
|
*/
|
||||||
public class Server {
|
public class Server {
|
||||||
|
|
||||||
|
static int port = 42536;
|
||||||
|
|
||||||
ServerSocket serverSocket;
|
ServerSocket serverSocket;
|
||||||
|
|
||||||
public Server(int port){
|
HashMap<String,Client> clientMap;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void initServer(){
|
||||||
|
clientMap = new HashMap();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Server(int port){
|
||||||
|
initServer();
|
||||||
|
try {
|
||||||
|
serverSocket = new ServerSocket();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.err.println("Failed to start server socket!");
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
boolean running = true;
|
||||||
|
while(running){
|
||||||
|
Socket newSocket;
|
||||||
|
try {
|
||||||
|
newSocket = serverSocket.accept();
|
||||||
|
Client newClient = new Client(newSocket);
|
||||||
|
clientMap.put(newSocket.getInetAddress().getHostAddress(), newClient);
|
||||||
|
new Thread(newClient).start();
|
||||||
|
} catch (IOException ex) {
|
||||||
|
System.err.println("Socket error on client socket!");
|
||||||
|
ex.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static void startServerThread(){
|
||||||
|
Thread t = new Thread(){
|
||||||
|
@Override
|
||||||
|
public void run(){
|
||||||
|
Server s = new Server(port);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
t.start();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user