Ajout du systeme de sauvegarde
This commit is contained in:
parent
810b52d57c
commit
bc1003b599
1297 changed files with 1902 additions and 111 deletions
|
@ -1,10 +1,17 @@
|
|||
package mrdev023.blocks;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import mrdev023.math.*;
|
||||
|
||||
|
||||
|
||||
public abstract class Block {
|
||||
public abstract class Block implements Serializable{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -4814279699620370899L;
|
||||
|
||||
public static final Block OAK_WOOD = new OakWoodBlock(),
|
||||
GRASS = new GrassBlock(),
|
||||
|
@ -110,7 +117,7 @@ public abstract class Block {
|
|||
return size;
|
||||
}
|
||||
|
||||
|
||||
public abstract String toString();
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -8,4 +8,8 @@ public class FirLeafBlock extends Block{
|
|||
super(new Color4f(0.0f,0.4f,0f));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,4 +7,8 @@ public class GrassBlock extends Block{
|
|||
super(new Color4f(0.2f,0.6f,0f));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,4 +8,8 @@ public class LeafBlock extends Block{
|
|||
super(new Color4f(0,0.6f,0,1));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,4 +8,8 @@ public class TransparentBlock extends Block {
|
|||
super(new Color4f(1,1,1,0));
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,4 +8,8 @@ public class WoodBlock extends Block{
|
|||
super(c);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
13
VBO/src/mrdev023/entities/BlockMonster.java
Normal file
13
VBO/src/mrdev023/entities/BlockMonster.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package mrdev023.entities;
|
||||
|
||||
import mrdev023.entities.ia.*;
|
||||
import mrdev023.entities.physics.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class BlockMonster extends Entity{
|
||||
|
||||
public BlockMonster(World world, Physics physics, PathFinding pathFinding) {
|
||||
super(world, physics, pathFinding);
|
||||
}
|
||||
|
||||
}
|
45
VBO/src/mrdev023/entities/Entity.java
Normal file
45
VBO/src/mrdev023/entities/Entity.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package mrdev023.entities;
|
||||
|
||||
import mrdev023.entities.ia.*;
|
||||
import mrdev023.entities.physics.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public abstract class Entity {
|
||||
|
||||
private World world;
|
||||
private Physics physics;
|
||||
private PathFinding pathFinding;
|
||||
|
||||
public Entity(World world,Physics physics,PathFinding pathFinding){
|
||||
this.pathFinding = pathFinding;
|
||||
this.world = world;
|
||||
this.physics = physics;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public Physics getPhysics() {
|
||||
return physics;
|
||||
}
|
||||
|
||||
public void setPhysics(Physics physics) {
|
||||
this.physics = physics;
|
||||
}
|
||||
|
||||
public PathFinding getPathFinding() {
|
||||
return pathFinding;
|
||||
}
|
||||
|
||||
public void setPathFinding(PathFinding pathFinding) {
|
||||
this.pathFinding = pathFinding;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
11
VBO/src/mrdev023/entities/Player.java
Normal file
11
VBO/src/mrdev023/entities/Player.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package mrdev023.entities;
|
||||
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class Player extends Entity{
|
||||
|
||||
public Player(World world) {
|
||||
super(world, null, null);
|
||||
}
|
||||
|
||||
}
|
34
VBO/src/mrdev023/entities/ia/PathFinding.java
Normal file
34
VBO/src/mrdev023/entities/ia/PathFinding.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package mrdev023.entities.ia;
|
||||
|
||||
import mrdev023.entities.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class PathFinding {
|
||||
|
||||
private World world;
|
||||
private Entity entity;
|
||||
|
||||
public PathFinding(World world,Entity entity){
|
||||
this.world = world;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void setEntity(Entity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
34
VBO/src/mrdev023/entities/physics/Physics.java
Normal file
34
VBO/src/mrdev023/entities/physics/Physics.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package mrdev023.entities.physics;
|
||||
|
||||
import mrdev023.entities.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class Physics {
|
||||
|
||||
private World world;
|
||||
private Entity entity;
|
||||
|
||||
public Physics(World world,Entity entity){
|
||||
this.entity = entity;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
return world;
|
||||
}
|
||||
|
||||
public void setWorld(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
public void setEntity(Entity entity) {
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
9
VBO/src/mrdev023/exception/LostConnectionException.java
Normal file
9
VBO/src/mrdev023/exception/LostConnectionException.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package mrdev023.exception;
|
||||
|
||||
public class LostConnectionException extends Exception{
|
||||
|
||||
public LostConnectionException(String a){
|
||||
super(a);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
package mrdev023.game;
|
||||
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.rendering.gui.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class AboutMenu implements GameInterface{
|
||||
|
@ -33,4 +34,12 @@ public class AboutMenu implements GameInterface{
|
|||
|
||||
}
|
||||
|
||||
public void updateGUI() {
|
||||
|
||||
}
|
||||
|
||||
public void init() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package mrdev023.game;
|
|||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import mrdev023.audio.*;
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.gameengine.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.gui.*;
|
||||
import mrdev023.rendering.gui.action.*;
|
||||
|
@ -16,10 +18,12 @@ import org.lwjgl.opengl.*;
|
|||
|
||||
public class MainMenu implements GameInterface{
|
||||
|
||||
public ArrayList<GUI> guiList = new ArrayList<GUI>();
|
||||
public ArrayList<GUI> guiList = new ArrayList<GUI>();
|
||||
|
||||
public MainMenu(){
|
||||
GUI button = new ButtonGUI("SOLO",Display.getDisplayMode().getWidth()/2 - 100,Display.getDisplayMode().getHeight()/2 - 80,200,60);
|
||||
public MainMenu(){}
|
||||
|
||||
public void init(){
|
||||
GUI button = new ButtonGUI("SOLO",0.4f,0.3f,0.2f,0.075f);
|
||||
button.setAction(new Action() {
|
||||
public void manageAction(int action) {
|
||||
if(action == GUI.CLICKED)GameEngine.changeGameState(GameState.SOLO_GAME);
|
||||
|
@ -28,7 +32,34 @@ public class MainMenu implements GameInterface{
|
|||
public void hover(Vector2f position) {}
|
||||
});
|
||||
guiList.add(button);
|
||||
guiList.add(new LabelGUI("Test Voxel v0.1", Display.getDisplayMode().getWidth()/2 - 100, Display.getDisplayMode().getHeight()/2 - 300, 200, 100));
|
||||
button = new ButtonGUI("OPTION",0.4f,0.4f,0.2f,0.075f);
|
||||
button.setAction(new Action() {
|
||||
public void manageAction(int action) {
|
||||
if(action == GUI.CLICKED)GameEngine.changeGameState(GameState.OPTION_MENU);
|
||||
}
|
||||
|
||||
public void hover(Vector2f position) {}
|
||||
});
|
||||
guiList.add(button);
|
||||
button = new ButtonGUI("ABOUT",0.4f,0.5f,0.2f,0.075f);
|
||||
button.setAction(new Action() {
|
||||
public void manageAction(int action) {
|
||||
if(action == GUI.CLICKED)GameEngine.changeGameState(GameState.ABOUT_MENU);
|
||||
}
|
||||
|
||||
public void hover(Vector2f position) {}
|
||||
});
|
||||
guiList.add(button);
|
||||
button = new ButtonGUI("EXIT",0.4f,0.6f,0.2f,0.075f);
|
||||
button.setAction(new Action() {
|
||||
public void manageAction(int action) {
|
||||
if(action == GUI.CLICKED)GameEngine.destroy();
|
||||
}
|
||||
|
||||
public void hover(Vector2f position) {}
|
||||
});
|
||||
guiList.add(button);
|
||||
guiList.add(new LabelGUI("Test Voxel v0.1", 0.34f,0.1f,0.3f,0.10f));
|
||||
}
|
||||
|
||||
public void render() {
|
||||
|
@ -67,14 +98,11 @@ public class MainMenu implements GameInterface{
|
|||
}
|
||||
|
||||
public void updateKeyboard() {
|
||||
while(Keyboard.next()){
|
||||
if(Keyboard.getEventKeyState()){
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){
|
||||
GameEngine.setRunning(false);
|
||||
}
|
||||
}else{
|
||||
}
|
||||
|
||||
}
|
||||
public void updateGUI() {
|
||||
for(GUI gui : guiList){
|
||||
gui.updateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import org.lwjgl.opengl.*;
|
|||
|
||||
import mrdev023.blocks.*;
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.gameengine.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.update.*;
|
||||
|
@ -19,7 +19,7 @@ public class MultiGame extends Game implements GameInterface{
|
|||
private static Vector3f selectedVector = new Vector3f(0,0,0);
|
||||
|
||||
public MultiGame() {
|
||||
super(new MultiWorld(0,120,50));
|
||||
super(null);
|
||||
}
|
||||
|
||||
public void render(){
|
||||
|
@ -60,6 +60,10 @@ public class MultiGame extends Game implements GameInterface{
|
|||
destroyGame();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
setWorld(new MultiWorld(0,120,50));
|
||||
}
|
||||
|
||||
private static void renderBlock(int x,int y ,int z){
|
||||
float s = 1;
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
@ -198,4 +202,8 @@ public class MultiGame extends Game implements GameInterface{
|
|||
|
||||
}
|
||||
|
||||
public void updateGUI() {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,24 +1,152 @@
|
|||
package mrdev023.game;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.lwjgl.*;
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.gameengine.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.rendering.gui.*;
|
||||
import mrdev023.rendering.gui.action.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class OptionMenu implements GameInterface{
|
||||
public class OptionMenu implements GameInterface {
|
||||
|
||||
public ArrayList<GUI> guiList = new ArrayList<GUI>();
|
||||
public DisplayMode[] availableDisplayMode;
|
||||
public int selectDisplayMode = 0;
|
||||
public GUI displayRender,fullscreenRender;
|
||||
public boolean IsFullscreen;
|
||||
|
||||
public OptionMenu() {}
|
||||
|
||||
public void init() {
|
||||
guiList.clear();
|
||||
availableDisplayMode = DisplayManager.getDisplayModeArray();
|
||||
IsFullscreen = Display.isFullscreen();
|
||||
displayRender = new ButtonGUI(Display.getDisplayMode().getWidth() + "x"
|
||||
+ Display.getDisplayMode().getHeight() + ":"
|
||||
+ Display.getDisplayMode().getFrequency() + ":"
|
||||
+ Display.getDisplayMode().getBitsPerPixel(),0.35f,0.3f,0.3f,0.075f).setAction(
|
||||
new Action() {
|
||||
public void manageAction(int action) {
|
||||
|
||||
}
|
||||
|
||||
public void hover(Vector2f position) {
|
||||
}
|
||||
}).setHoverAnimation(false);
|
||||
guiList.add(new ButtonGUI("Back",0.2f,0.8f,0.2f,0.075f).setAction(new Action() {
|
||||
public void manageAction(int action) {
|
||||
if (action == GUI.CLICKED)
|
||||
GameEngine.changeGameState(GameState.MAIN_MENU);
|
||||
}
|
||||
|
||||
public void hover(Vector2f position) {
|
||||
}
|
||||
}));
|
||||
guiList.add(new ButtonGUI("Apply",0.6f,0.8f,0.2f,0.075f).setAction(new Action() {
|
||||
public void manageAction(int action) {
|
||||
try {
|
||||
Display.setDisplayMode(availableDisplayMode[selectDisplayMode]);
|
||||
Display.setFullscreen(IsFullscreen);
|
||||
DisplayManager.updateDisplay();
|
||||
} catch (LWJGLException e) {}
|
||||
}
|
||||
|
||||
public void hover(Vector2f position) {
|
||||
}
|
||||
}));
|
||||
guiList.add(new ButtonGUI("<",0.1f,0.3f,0.2f,0.075f).setAction(new Action() {
|
||||
public void manageAction(int action) {
|
||||
if (action == GUI.CLICKED) {
|
||||
selectDisplayMode--;
|
||||
if (selectDisplayMode > availableDisplayMode.length - 1)
|
||||
selectDisplayMode = 0;
|
||||
if (selectDisplayMode < 0)
|
||||
selectDisplayMode = availableDisplayMode.length - 1;
|
||||
displayRender.setValue(availableDisplayMode[selectDisplayMode].getWidth()
|
||||
+ "x"
|
||||
+ availableDisplayMode[selectDisplayMode].getHeight()
|
||||
+ ":"
|
||||
+ availableDisplayMode[selectDisplayMode].getFrequency()
|
||||
+ ":" + availableDisplayMode[selectDisplayMode].getBitsPerPixel() + " (" + (selectDisplayMode+1) + "/" + availableDisplayMode.length + ")");
|
||||
}
|
||||
}
|
||||
|
||||
public void hover(Vector2f position) {
|
||||
}
|
||||
}));
|
||||
guiList.add(new ButtonGUI(">",0.7f,0.3f,0.2f,0.075f).setAction(new Action() {
|
||||
public void manageAction(int action) {
|
||||
if (action == GUI.CLICKED) {
|
||||
selectDisplayMode++;
|
||||
if (selectDisplayMode > availableDisplayMode.length - 1)
|
||||
selectDisplayMode = 0;
|
||||
if (selectDisplayMode < 0)
|
||||
selectDisplayMode = availableDisplayMode.length - 1;
|
||||
displayRender.setValue(availableDisplayMode[selectDisplayMode].getWidth()
|
||||
+ "x"
|
||||
+ availableDisplayMode[selectDisplayMode].getHeight()
|
||||
+ ":"
|
||||
+ availableDisplayMode[selectDisplayMode].getFrequency()
|
||||
+ ":" + availableDisplayMode[selectDisplayMode].getBitsPerPixel());
|
||||
}
|
||||
}
|
||||
|
||||
public void hover(Vector2f position) {
|
||||
}
|
||||
}));
|
||||
guiList.add(displayRender);
|
||||
guiList.add((fullscreenRender = new ButtonGUI("Fullscreen: " + Display.isFullscreen(),0.4f,0.4f,0.2f,0.075f).setAction(
|
||||
new Action() {
|
||||
public void manageAction(int action) {
|
||||
IsFullscreen = !IsFullscreen;
|
||||
fullscreenRender.setValue("Fullscreen: " + IsFullscreen);
|
||||
}
|
||||
|
||||
public void hover(Vector2f position) {
|
||||
}
|
||||
})));
|
||||
guiList.add(new LabelGUI("Option", 0.34f,0.1f,0.3f,0.10f));
|
||||
}
|
||||
|
||||
public void render() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void updateGUI() {
|
||||
for(GUI gui : guiList){
|
||||
gui.updateGUI();
|
||||
}
|
||||
}
|
||||
|
||||
public void update() {
|
||||
|
||||
for (GUI gui : guiList) {
|
||||
gui.updateAction();
|
||||
}
|
||||
}
|
||||
|
||||
public void renderGUI() {
|
||||
|
||||
glColor3f(0, 0, 0);
|
||||
glPointSize(5);
|
||||
glBegin(GL_POINTS);
|
||||
glVertex2f(Mouse.getX(),
|
||||
Display.getDisplayMode().getHeight() - Mouse.getY());
|
||||
glEnd();
|
||||
for (GUI gui : guiList) {
|
||||
gui.render();
|
||||
}
|
||||
}
|
||||
|
||||
public void destroyGameState() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
|
@ -26,11 +154,12 @@ public class OptionMenu implements GameInterface{
|
|||
}
|
||||
|
||||
public void updateMouse() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void updateKeyboard() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -7,9 +7,10 @@ import org.lwjgl.opengl.*;
|
|||
|
||||
import mrdev023.blocks.*;
|
||||
import mrdev023.game.gamestate.*;
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.gameengine.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.rendering.gui.*;
|
||||
import mrdev023.update.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
|
@ -20,7 +21,7 @@ public class SoloGame extends Game implements GameInterface{
|
|||
private static Vector3f selectedVector = new Vector3f(0,0,0);
|
||||
|
||||
public SoloGame() {
|
||||
super(new MultiWorld(0,120,50));
|
||||
super(null);
|
||||
}
|
||||
|
||||
public void render(){
|
||||
|
@ -55,6 +56,10 @@ public class SoloGame extends Game implements GameInterface{
|
|||
|
||||
public void renderGUI() {
|
||||
|
||||
}
|
||||
|
||||
public void updateGUI() {
|
||||
|
||||
}
|
||||
|
||||
public void destroyGameState() {
|
||||
|
@ -127,25 +132,10 @@ public class SoloGame extends Game implements GameInterface{
|
|||
xDir = 0;
|
||||
yDir = 0;
|
||||
zDir = 0;
|
||||
while(Keyboard.next()){
|
||||
if(Keyboard.getEventKeyState()){
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_ESCAPE){
|
||||
GameEngine.setRunning(false);
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_F2){
|
||||
Mouse.setGrabbed(!Mouse.isGrabbed());
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_F5){
|
||||
Camera.setPosition(new Vector3f(0,2,0));
|
||||
}
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_X){
|
||||
Camera.noClip = !Camera.noClip;
|
||||
}
|
||||
}else{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (Update.keyboardButtonPressed(Keyboard.KEY_ESCAPE))GameEngine.changeGameState(GameState.MAIN_MENU);
|
||||
if (Update.keyboardButtonPressed(Keyboard.KEY_F2)) Mouse.setGrabbed(!Mouse.isGrabbed());
|
||||
if (Update.keyboardButtonPressed(Keyboard.KEY_F5)) Camera.setPosition(new Vector3f(0, 2, 0));
|
||||
if (Update.keyboardButtonPressed(Keyboard.KEY_X)) Camera.noClip = !Camera.noClip;
|
||||
|
||||
if(Mouse.isGrabbed()){
|
||||
if(Camera.getRotation().x < -90) Camera.getRotation().x = -90;
|
||||
|
@ -199,4 +189,8 @@ public class SoloGame extends Game implements GameInterface{
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
public void init() {
|
||||
setWorld(new SoloWorld(0,120,50));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,7 @@ public interface GameInterface {
|
|||
public World getWorld();
|
||||
public void updateMouse();
|
||||
public void updateKeyboard();
|
||||
public void updateGUI();
|
||||
public void init();
|
||||
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import mrdev023.world.*;
|
|||
|
||||
public enum GameState {
|
||||
|
||||
MAIN_MENU(new MainMenu()),SOLO_GAME(new SoloGame()),MULTI_GAME(new MultiGame()),OPTION_MENU(new OptionMenu()),ABOUT_MENU(new AboutMenu());
|
||||
MAIN_MENU(new MainMenu()),OPTION_MENU(new OptionMenu()),ABOUT_MENU(new AboutMenu()),SOLO_GAME(new SoloGame()),MULTI_GAME(new MultiGame());
|
||||
|
||||
GameInterface gameInterface;
|
||||
|
||||
|
@ -40,4 +40,12 @@ public enum GameState {
|
|||
public void updateKeyboard() {
|
||||
this.gameInterface.updateKeyboard();
|
||||
}
|
||||
|
||||
public void updateGUI() {
|
||||
this.gameInterface.updateGUI();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
this.gameInterface.init();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package mrdev023.gameEngine;
|
||||
package mrdev023.gameengine;
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
|
@ -24,7 +24,7 @@ public class GameEngine {
|
|||
private static final String TITLE = "Test VBO";
|
||||
private static final int width = 1280, height = 720;
|
||||
|
||||
public static GameState gameState;
|
||||
public static GameState gameState = GameState.MAIN_MENU;
|
||||
|
||||
public static void initWindow(){
|
||||
Main.mainPool = Executors.newWorkStealingPool();
|
||||
|
@ -36,7 +36,7 @@ public class GameEngine {
|
|||
AudioManager.create();
|
||||
Camera.initCamera();
|
||||
Mouse.setGrabbed(true);
|
||||
gameState = GameState.MAIN_MENU;
|
||||
changeGameState(GameState.MAIN_MENU);
|
||||
loop();
|
||||
} catch (Exception e) {
|
||||
|
||||
|
@ -55,10 +55,6 @@ public class GameEngine {
|
|||
elapsedInfo += current - previous;
|
||||
DisplayManager.setDelta(current - previous);
|
||||
|
||||
if (Display.wasResized()) {
|
||||
DisplayManager.updateDisplay();
|
||||
}
|
||||
|
||||
current2 = System.nanoTime();
|
||||
if (elapsed >= 1000 / 60) {
|
||||
Update.updateMouse();
|
||||
|
@ -101,7 +97,8 @@ public class GameEngine {
|
|||
|
||||
public static void changeGameState(GameState newGameState){
|
||||
gameState.destroyGameState();
|
||||
gameState = newGameState;
|
||||
newGameState.init();
|
||||
gameState = newGameState;
|
||||
}
|
||||
|
||||
public static void destroy(){
|
77
VBO/src/mrdev023/io/IO.java
Normal file
77
VBO/src/mrdev023/io/IO.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
package mrdev023.io;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.zip.*;
|
||||
|
||||
import mrdev023.blocks.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.world.*;
|
||||
import mrdev023.world.chunk.*;
|
||||
|
||||
public class IO {
|
||||
|
||||
public static void saveChunk(Chunk c,String map) throws IOException{
|
||||
long current = System.currentTimeMillis();
|
||||
String file = "save" + File.separatorChar + map + File.separatorChar + c.getX() + "_" + c.getY() + "_" + c.getZ() + ".chunk";
|
||||
ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new GZIPOutputStream(new FileOutputStream(file))));
|
||||
oos.writeObject(c.getBlocks());
|
||||
oos.flush();
|
||||
oos.close();
|
||||
System.out.println("File: " + file + " saved in " + (System.currentTimeMillis() - current) + "ms");
|
||||
}
|
||||
|
||||
public static Chunk loadChunk(Vector3i c,String map) throws IOException, ClassNotFoundException{
|
||||
long current = System.currentTimeMillis();
|
||||
String file = "save" + File.separatorChar + map + File.separatorChar + c.getX() + "_" + c.getY() + "_" + c.getZ() + ".chunk";
|
||||
FileInputStream fis=new FileInputStream(file);
|
||||
GZIPInputStream gzis=new GZIPInputStream(fis);
|
||||
BufferedInputStream bis = new BufferedInputStream(gzis);
|
||||
ObjectInputStream in=new ObjectInputStream(bis);
|
||||
Chunk c1 = new Chunk((int)c.getX(),(int)c.getY(),(int)c.getZ());
|
||||
Block[][][] blocks = (Block[][][])in.readObject();
|
||||
c1.setBlocks(blocks);
|
||||
in.close();
|
||||
gzis.close();
|
||||
bis.close();
|
||||
fis.close();
|
||||
System.out.println("File: " + file + " loaded in " + (System.currentTimeMillis() - current) + "ms");
|
||||
return c1;
|
||||
}
|
||||
|
||||
public static boolean chunkIsSaved(Vector3i c,String map){
|
||||
String file = "save" + File.separatorChar + map + File.separatorChar + c.getX() + "_" + c.getY() + "_" + c.getZ() + ".chunk";
|
||||
File f = new File(file);
|
||||
return f.isFile();
|
||||
}
|
||||
|
||||
public static byte[] compressData(Object data) throws IOException{
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
GZIPOutputStream gzout = new GZIPOutputStream(out);
|
||||
BufferedOutputStream bout = new BufferedOutputStream(gzout);
|
||||
ObjectOutputStream oos = new ObjectOutputStream(bout);
|
||||
oos.writeObject(data);
|
||||
oos.flush();
|
||||
oos.close();
|
||||
bout.close();
|
||||
gzout.close();
|
||||
byte[] outData = out.toByteArray();
|
||||
out.close();
|
||||
return outData;
|
||||
}
|
||||
|
||||
public static Object decompressData(byte[] data) throws IOException, ClassNotFoundException{
|
||||
ByteArrayInputStream in = new ByteArrayInputStream(data);
|
||||
GZIPInputStream gzin = new GZIPInputStream(in);
|
||||
BufferedInputStream bin = new BufferedInputStream(gzin);
|
||||
ObjectInputStream ois = new ObjectInputStream(bin);
|
||||
Object obj = ois.readObject();
|
||||
ois.close();
|
||||
gzin.close();
|
||||
bin.close();
|
||||
in.close();
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,10 +1,8 @@
|
|||
package mrdev023.main;
|
||||
|
||||
|
||||
import java.util.concurrent.*;
|
||||
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.network.*;
|
||||
import mrdev023.gameengine.*;
|
||||
import mrdev023.network.server.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
|
@ -20,7 +18,7 @@ public class Main {
|
|||
for(String arg : args){
|
||||
if(arg.equals("-server"))IsServer = true;
|
||||
}
|
||||
|
||||
|
||||
if(IsServer){
|
||||
Server.initServer();
|
||||
}else{
|
||||
|
|
200
VBO/src/mrdev023/math/Vector3i.java
Normal file
200
VBO/src/mrdev023/math/Vector3i.java
Normal file
|
@ -0,0 +1,200 @@
|
|||
package mrdev023.math;
|
||||
|
||||
|
||||
public class Vector3i {
|
||||
|
||||
public int x, y, z;
|
||||
|
||||
public Vector3i() {
|
||||
this(0, 0, 0);
|
||||
}
|
||||
|
||||
public Vector3i(Vector3i v) {
|
||||
this(v.x, v.y, v.z);
|
||||
}
|
||||
|
||||
public Vector3i(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return (int) Math.sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
public Vector3i normalize() {
|
||||
x /= length();
|
||||
y /= length();
|
||||
z /= length();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3i add(Vector3i vec) {
|
||||
x += vec.getX();
|
||||
y += vec.getY();
|
||||
z += vec.getZ();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3i check(){
|
||||
int max = Math.max(Math.max(x, y),z);
|
||||
int min = Math.min(Math.min(x, y),z);
|
||||
|
||||
int absMax = Math.abs(max - 1);
|
||||
int absMin = Math.abs(min);
|
||||
|
||||
int v = 0;
|
||||
|
||||
if(absMax>absMin)v=min;
|
||||
else v=max;
|
||||
|
||||
int rv = 1;
|
||||
|
||||
if(v<0.5f)rv=-1;
|
||||
|
||||
return new Vector3i(v == x ? rv : 0,v == y ? rv : 0,v == z ? rv : 0);
|
||||
}
|
||||
|
||||
public Vector3i copy(){
|
||||
return new Vector3i(this);
|
||||
}
|
||||
|
||||
public Vector3i sub(Vector3i vec) {
|
||||
x -= vec.getX();
|
||||
y -= vec.getY();
|
||||
z -= vec.getZ();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public void set(Vector3i vec){
|
||||
this.x = vec.x;
|
||||
this.y = vec.y;
|
||||
this.z = vec.z;
|
||||
}
|
||||
|
||||
public Vector3i mul(Vector3i vec) {
|
||||
x *= vec.getX();
|
||||
y *= vec.getY();
|
||||
z *= vec.getZ();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3i div(Vector3i vec) {
|
||||
x /= vec.getX();
|
||||
y /= vec.getY();
|
||||
z /= vec.getZ();
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public Vector3i add(int v) {
|
||||
x += v;
|
||||
y += v;
|
||||
z += v;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3i add(int x,int y, int z) {
|
||||
this.x += x;
|
||||
this.y += y;
|
||||
this.z += z;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3i sub(int v) {
|
||||
x -= v;
|
||||
y -= v;
|
||||
z -= v;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3i mul(int v) {
|
||||
x *= v;
|
||||
y *= v;
|
||||
z *= v;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public Vector3i div(int v) {
|
||||
x /= v;
|
||||
y /= v;
|
||||
z /= v;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// ---- X
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public Vector3i addX(int v) {
|
||||
x += v;
|
||||
return this;
|
||||
}
|
||||
public Vector3i subX(int v) {
|
||||
x -= v;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// ----- Y
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public Vector3i addY(int v) {
|
||||
y += v;
|
||||
return this;
|
||||
}
|
||||
public Vector3i subY(int v) {
|
||||
y -= v;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// ----- Z
|
||||
public int getZ() {
|
||||
return z;
|
||||
}
|
||||
|
||||
public void setZ(int z) {
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
public Vector3i addZ(int v) {
|
||||
z += v;
|
||||
return this;
|
||||
}
|
||||
public Vector3i subZ(int v) {
|
||||
z -= v;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
return x + " " + y + " " + z;
|
||||
}
|
||||
|
||||
public static int distance(Vector3i a,Vector3i b){
|
||||
return (int)Math.sqrt((Math.pow(b.getX()-a.getX(), 2))+(Math.pow(b.getY()-a.getY(), 2))+(Math.pow(b.getZ()-a.getZ(), 2)));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package mrdev023.network;
|
||||
|
||||
public class Client {
|
||||
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package mrdev023.network;
|
||||
|
||||
public class Server {
|
||||
|
||||
public static void initServer(){
|
||||
|
||||
}
|
||||
|
||||
}
|
149
VBO/src/mrdev023/network/client/Client.java
Normal file
149
VBO/src/mrdev023/network/client/Client.java
Normal file
|
@ -0,0 +1,149 @@
|
|||
package mrdev023.network.client;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
import mrdev023.network.packet.*;
|
||||
import mrdev023.network.packet.wait.*;
|
||||
|
||||
public class Client {
|
||||
|
||||
private String ip;
|
||||
private short port;
|
||||
private Socket connection;
|
||||
public boolean IsError = false;
|
||||
public boolean IsRunning = true;
|
||||
private ObjectOutputStream out;
|
||||
private PacketManager paketManager;
|
||||
private Thread threadPacketManager;
|
||||
|
||||
public Client(String ip,short port)throws Exception{
|
||||
this.ip = ip;
|
||||
this.port = port;
|
||||
this.connection = new Socket(ip, port);
|
||||
this.out = new ObjectOutputStream(connection.getOutputStream());
|
||||
this.paketManager = new PacketManager(this);
|
||||
this.threadPacketManager = new Thread(this.paketManager);
|
||||
this.threadPacketManager.start();
|
||||
}
|
||||
|
||||
public void sendData(Packet packet) throws IOException{
|
||||
out.writeObject(packet);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public short getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setPort(short port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public Socket getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void setConnection(Socket connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public boolean isIsError() {
|
||||
return IsError;
|
||||
}
|
||||
|
||||
public void setIsError(boolean isError) {
|
||||
IsError = isError;
|
||||
}
|
||||
|
||||
public boolean isIsRunning() {
|
||||
return IsRunning;
|
||||
}
|
||||
|
||||
public void setIsRunning(boolean isRunning) {
|
||||
IsRunning = isRunning;
|
||||
}
|
||||
|
||||
public ObjectOutputStream getOut() {
|
||||
return out;
|
||||
}
|
||||
|
||||
public void setOut(ObjectOutputStream out) {
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
public PacketManager getPaketManager() {
|
||||
return paketManager;
|
||||
}
|
||||
|
||||
public void setPaketManager(PacketManager paketManager) {
|
||||
this.paketManager = paketManager;
|
||||
}
|
||||
|
||||
public Thread getThreadPacketManager() {
|
||||
return threadPacketManager;
|
||||
}
|
||||
|
||||
public void setThreadPacketManager(Thread threadPacketManager) {
|
||||
this.threadPacketManager = threadPacketManager;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
class ClientReader implements Runnable{
|
||||
|
||||
private Client client;
|
||||
private ObjectInputStream in;
|
||||
|
||||
public ClientReader(Client client){
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while(client.IsRunning){
|
||||
try {
|
||||
Object packet = in.readObject();
|
||||
if(packet != null){
|
||||
if(packet instanceof WaitPacket){
|
||||
WaitPacketManager.setWaitPacket(((WaitPacket)packet).getId(), (WaitPacket)packet);
|
||||
}else if(packet instanceof Packet){
|
||||
client.getPaketManager().addPacket((Packet)packet);
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
client.IsError = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Client getClient() {
|
||||
return client;
|
||||
}
|
||||
|
||||
public void setClient(Client client) {
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public ObjectInputStream getIn() {
|
||||
return in;
|
||||
}
|
||||
|
||||
public void setIn(ObjectInputStream in) {
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
31
VBO/src/mrdev023/network/client/PacketManager.java
Normal file
31
VBO/src/mrdev023/network/client/PacketManager.java
Normal file
|
@ -0,0 +1,31 @@
|
|||
package mrdev023.network.client;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import mrdev023.network.*;
|
||||
import mrdev023.network.packet.*;
|
||||
|
||||
public class PacketManager implements Runnable{
|
||||
|
||||
public ArrayList<Packet> packetList = new ArrayList<Packet>();
|
||||
|
||||
public Client client;
|
||||
|
||||
public PacketManager(Client client){
|
||||
this.client = client;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while(client.IsRunning){
|
||||
for (Packet e : packetList) {
|
||||
e.manageClientPacket(client, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addPacket(Packet packet){
|
||||
packetList.add(packet);
|
||||
}
|
||||
|
||||
}
|
25
VBO/src/mrdev023/network/client/WaitPacketManager.java
Normal file
25
VBO/src/mrdev023/network/client/WaitPacketManager.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
package mrdev023.network.client;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import mrdev023.network.packet.wait.*;
|
||||
|
||||
public class WaitPacketManager{
|
||||
|
||||
public static HashMap<String,WaitPacket> waitPacketList = new HashMap<String,WaitPacket>();
|
||||
|
||||
public static void sendWaitPacket(WaitPacket packet,Client client) throws IOException{
|
||||
packet.sendPacket(client, packet);
|
||||
client.sendData(packet);
|
||||
waitPacketList.put(packet.getId(), packet);
|
||||
}
|
||||
|
||||
public static boolean isRep(String id){
|
||||
return waitPacketList.get(id).getIsRep();
|
||||
}
|
||||
|
||||
public static void setWaitPacket(String id,WaitPacket packet){
|
||||
waitPacketList.replace(id, packet);
|
||||
}
|
||||
}
|
53
VBO/src/mrdev023/network/packet/ChunkPacket.java
Normal file
53
VBO/src/mrdev023/network/packet/ChunkPacket.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package mrdev023.network.packet;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import mrdev023.io.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.network.client.*;
|
||||
import mrdev023.network.packet.wait.*;
|
||||
import mrdev023.network.server.*;
|
||||
import mrdev023.world.chunk.*;
|
||||
|
||||
public class ChunkPacket implements Packet{
|
||||
|
||||
public Vector3i position;
|
||||
public Chunk chunk = null;
|
||||
|
||||
public ChunkPacket(Vector3i position){
|
||||
this.position = position;
|
||||
this.chunk = null;
|
||||
}
|
||||
|
||||
public void setChunk(Chunk ch){
|
||||
this.chunk = ch;
|
||||
}
|
||||
|
||||
public void manageClientPacket(Client client, Packet packet) {
|
||||
WaitPacketManager.setWaitPacket(((WaitPacket)packet).getId(), (WaitPacket)packet);
|
||||
}
|
||||
|
||||
public void manageServerPacket(ClientConnection client, Packet packet) {
|
||||
if((((WaitPacket)packet).getPacket()) != null){
|
||||
Chunk ch = (Chunk)((((WaitPacket)packet).getPacket()));
|
||||
if(Server.getChunk(ch.getPosition()) == null){
|
||||
try {
|
||||
IO.saveChunk(ch, "multiWorld");
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}else{
|
||||
try {
|
||||
Vector3i pos = ((ChunkPacket)(((WaitPacket)packet).getPacket())).position;
|
||||
((WaitPacket)packet).setPacket(Server.getChunk(pos));
|
||||
client.sendData(packet);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
12
VBO/src/mrdev023/network/packet/Packet.java
Normal file
12
VBO/src/mrdev023/network/packet/Packet.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package mrdev023.network.packet;
|
||||
|
||||
import mrdev023.network.*;
|
||||
import mrdev023.network.client.*;
|
||||
import mrdev023.network.server.*;
|
||||
|
||||
public interface Packet {
|
||||
|
||||
public void manageClientPacket(Client client,Packet packet);
|
||||
public void manageServerPacket(ClientConnection client,Packet packet);
|
||||
|
||||
}
|
17
VBO/src/mrdev023/network/packet/TestPacket.java
Normal file
17
VBO/src/mrdev023/network/packet/TestPacket.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package mrdev023.network.packet;
|
||||
|
||||
import mrdev023.network.*;
|
||||
import mrdev023.network.client.*;
|
||||
import mrdev023.network.server.*;
|
||||
|
||||
public class TestPacket implements Packet {
|
||||
|
||||
public void manageClientPacket(Client client, Packet packet) {
|
||||
|
||||
}
|
||||
|
||||
public void manageServerPacket(ClientConnection client, Packet packet) {
|
||||
|
||||
}
|
||||
|
||||
}
|
28
VBO/src/mrdev023/network/packet/wait/ChunkWaitPacket.java
Normal file
28
VBO/src/mrdev023/network/packet/wait/ChunkWaitPacket.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
package mrdev023.network.packet.wait;
|
||||
|
||||
import mrdev023.network.client.*;
|
||||
import mrdev023.network.packet.*;
|
||||
import mrdev023.network.server.*;
|
||||
|
||||
public class ChunkWaitPacket extends WaitPacket{
|
||||
|
||||
public ChunkWaitPacket(String id) {
|
||||
super("chunkWaitPacket" + (Math.random()*20000));
|
||||
}
|
||||
|
||||
public void manageClientPacket(Client client, Packet packet) {
|
||||
((ChunkPacket)(((WaitPacket)packet).getPacket())).manageClientPacket(client, packet);
|
||||
}
|
||||
|
||||
public void manageServerPacket(ClientConnection client, Packet packet) {
|
||||
((ChunkPacket)(((WaitPacket)packet).getPacket())).manageServerPacket(client, packet);
|
||||
}
|
||||
|
||||
public void repPacket(ClientConnection client, WaitPacket packet) {
|
||||
packet.IsRep = true;
|
||||
}
|
||||
|
||||
public void sendPacket(Client client, WaitPacket packet) {
|
||||
}
|
||||
|
||||
}
|
36
VBO/src/mrdev023/network/packet/wait/WaitPacket.java
Normal file
36
VBO/src/mrdev023/network/packet/wait/WaitPacket.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package mrdev023.network.packet.wait;
|
||||
|
||||
import mrdev023.network.client.*;
|
||||
import mrdev023.network.packet.*;
|
||||
import mrdev023.network.server.*;
|
||||
|
||||
public abstract class WaitPacket implements Packet{
|
||||
|
||||
protected boolean IsRep = false;
|
||||
protected String id;
|
||||
protected Object packet;
|
||||
|
||||
public WaitPacket(String id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId(){
|
||||
return this.id;
|
||||
}
|
||||
|
||||
public boolean getIsRep(){
|
||||
return this.IsRep;
|
||||
}
|
||||
|
||||
public Object getPacket(){
|
||||
return this.packet;
|
||||
}
|
||||
|
||||
public void setPacket(Object obj){
|
||||
this.packet = obj;
|
||||
}
|
||||
|
||||
public abstract void repPacket(ClientConnection client,WaitPacket packet);
|
||||
public abstract void sendPacket(Client client,WaitPacket packet);
|
||||
|
||||
}
|
130
VBO/src/mrdev023/network/server/ClientConnection.java
Normal file
130
VBO/src/mrdev023/network/server/ClientConnection.java
Normal file
|
@ -0,0 +1,130 @@
|
|||
package mrdev023.network.server;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import mrdev023.network.packet.*;
|
||||
import mrdev023.network.packet.wait.*;
|
||||
|
||||
public class ClientConnection {
|
||||
|
||||
private Socket connection;
|
||||
private ObjectOutputStream out;
|
||||
private ClientReader in;
|
||||
private Thread th;
|
||||
public boolean IsRunning = true;
|
||||
public boolean IsError = false;
|
||||
|
||||
public ClientConnection(Socket connection) throws IOException{
|
||||
this.connection = connection;
|
||||
out = new ObjectOutputStream(connection.getOutputStream());
|
||||
in = new ClientReader(this);
|
||||
}
|
||||
|
||||
public ClientConnection start(){
|
||||
th = new Thread(in);
|
||||
th.start();
|
||||
return this;
|
||||
}
|
||||
|
||||
public void sendData(Packet packet) throws IOException{
|
||||
out.writeObject(packet);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
public Socket getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public void setConnection(Socket connection) {
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public void destroy(){
|
||||
th.stop();
|
||||
try {
|
||||
connection.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
connection = null;
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
out = null;
|
||||
try {
|
||||
in.in.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
in = null;
|
||||
IsRunning = false;
|
||||
}
|
||||
|
||||
public ObjectOutputStream getOut() {
|
||||
return out;
|
||||
}
|
||||
|
||||
public void setOut(ObjectOutputStream out) {
|
||||
this.out = out;
|
||||
}
|
||||
|
||||
public ClientReader getIn() {
|
||||
return in;
|
||||
}
|
||||
|
||||
public void setIn(ClientReader in) {
|
||||
this.in = in;
|
||||
}
|
||||
|
||||
public Thread getTh() {
|
||||
return th;
|
||||
}
|
||||
|
||||
public void setTh(Thread th) {
|
||||
this.th = th;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class ClientReader implements Runnable{
|
||||
|
||||
public ClientConnection client;
|
||||
public ObjectInputStream in;
|
||||
|
||||
public ClientReader(ClientConnection client) throws IOException{
|
||||
this.client = client;
|
||||
in = new ObjectInputStream(client.getConnection().getInputStream());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while(client.IsRunning){
|
||||
try {
|
||||
Object packet = in.readObject();
|
||||
if(packet != null){
|
||||
if(packet instanceof WaitPacket){
|
||||
manageWaitPacket((WaitPacket)packet);
|
||||
}else if(packet instanceof Packet){
|
||||
if(packet != null){
|
||||
Server.packetManager.addPacket(client, (Packet)packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
client.IsError = true;
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void manageWaitPacket(WaitPacket packet){
|
||||
packet.repPacket(client,packet);
|
||||
}
|
||||
|
||||
}
|
32
VBO/src/mrdev023/network/server/PacketManager.java
Normal file
32
VBO/src/mrdev023/network/server/PacketManager.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package mrdev023.network.server;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import mrdev023.network.*;
|
||||
import mrdev023.network.packet.*;
|
||||
import mrdev023.network.server.*;
|
||||
|
||||
public class PacketManager implements Runnable{
|
||||
|
||||
public HashMap<Packet,ClientConnection> packetList = new HashMap<Packet,ClientConnection>();
|
||||
|
||||
public PacketManager(){
|
||||
|
||||
}
|
||||
|
||||
public void run() {
|
||||
while(Server.IsRunning){
|
||||
for (Entry<Packet, ClientConnection> e : packetList.entrySet()) {
|
||||
Packet packet = e.getKey();
|
||||
ClientConnection client = e.getValue();
|
||||
packet.manageServerPacket(client, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addPacket(ClientConnection client,Packet packet){
|
||||
packetList.put(packet, client);
|
||||
}
|
||||
|
||||
}
|
71
VBO/src/mrdev023/network/server/Server.java
Normal file
71
VBO/src/mrdev023/network/server/Server.java
Normal file
|
@ -0,0 +1,71 @@
|
|||
package mrdev023.network.server;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import mrdev023.exception.*;
|
||||
import mrdev023.io.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.network.packet.*;
|
||||
import mrdev023.world.chunk.*;
|
||||
|
||||
public class Server {
|
||||
|
||||
public static ServerSocket server;
|
||||
public static PacketManager packetManager;
|
||||
public static Thread threadPacketManager;
|
||||
public static boolean IsRunning = true;
|
||||
|
||||
public static ArrayList<ClientConnection> clientList = new ArrayList<ClientConnection>();
|
||||
|
||||
public static void initServer(){
|
||||
try {
|
||||
server = new ServerSocket(9999);
|
||||
server.setSoTimeout(1000);
|
||||
packetManager = new PacketManager();
|
||||
(threadPacketManager = new Thread(packetManager)).start();
|
||||
while(IsRunning){
|
||||
try{
|
||||
Socket client = server.accept();
|
||||
clientList.add(new ClientConnection(client).start());
|
||||
System.out.println("Client:" + client.getInetAddress().getHostAddress() + ":" + client.getPort() + " join game");
|
||||
}catch(Exception e){}
|
||||
|
||||
for (ClientConnection cl : clientList) {
|
||||
try{
|
||||
cl.sendData(new TestPacket());
|
||||
if(cl.IsError)throw new LostConnectionException("Data Error");
|
||||
} catch (Exception e) {
|
||||
cl = null;
|
||||
clientList.remove(cl);
|
||||
System.out.println("Client:"
|
||||
+ cl.getConnection().getInetAddress()
|
||||
.getHostAddress() + ":"
|
||||
+ cl.getConnection().getPort() + " left game");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
for(ClientConnection client : clientList){
|
||||
client.destroy();
|
||||
}
|
||||
server.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
System.exit(-1);
|
||||
}
|
||||
}
|
||||
|
||||
public static Chunk getChunk(Vector3i pos){
|
||||
try {
|
||||
return IO.loadChunk(pos, "multiWorld");
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ package mrdev023.rendering;
|
|||
import static org.lwjgl.opengl.GL11.*;
|
||||
import mrdev023.blocks.*;
|
||||
import mrdev023.entity.*;
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.gameengine.*;
|
||||
import mrdev023.main.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.world.*;
|
||||
|
|
|
@ -1,18 +1,20 @@
|
|||
package mrdev023.rendering;
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import static org.lwjgl.util.glu.GLU.*;
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.update.*;
|
||||
|
||||
import org.lwjgl.input.*;
|
||||
import java.util.*;
|
||||
|
||||
import mrdev023.gameengine.*;
|
||||
|
||||
import org.lwjgl.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
import org.lwjgl.util.glu.*;
|
||||
|
||||
|
||||
public class DisplayManager {
|
||||
|
||||
private static long delta = 0;
|
||||
private static float fov = 45;
|
||||
private static int height = GameEngine.getHeight(),width = GameEngine.getWidth();
|
||||
|
||||
/**
|
||||
* @Info Nettoie l'ecran
|
||||
|
@ -67,7 +69,30 @@ public class DisplayManager {
|
|||
* @Info mets a jour la resolution de l'ecran
|
||||
*/
|
||||
public static void updateDisplay() {
|
||||
glViewport(0, 0, Display.getWidth(), Display.getHeight());
|
||||
width = Display.getDisplayMode().getWidth();
|
||||
height = Display.getDisplayMode().getHeight();
|
||||
glViewport(0, 0, width,height);
|
||||
GameEngine.gameState.updateGUI();
|
||||
}
|
||||
|
||||
public static DisplayMode[] getDisplayModeArray(){
|
||||
try {
|
||||
ArrayList<DisplayMode> dl = new ArrayList<DisplayMode>();
|
||||
for(DisplayMode d : Display.getAvailableDisplayModes()){
|
||||
if(d.getBitsPerPixel() == 32 && d.getFrequency() == 60){
|
||||
dl.add(d);
|
||||
}
|
||||
}
|
||||
DisplayMode[] dl2 = new DisplayMode[dl.size()];
|
||||
for(int i = 0;i < dl2.length;i++){
|
||||
dl2[i] = dl.get(i);
|
||||
}
|
||||
dl = null;
|
||||
return dl2;
|
||||
} catch (LWJGLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static long getDelta() {
|
||||
|
@ -85,5 +110,23 @@ public class DisplayManager {
|
|||
public static void setFov(float fov) {
|
||||
DisplayManager.fov = fov;
|
||||
}
|
||||
|
||||
public static int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public static void setHeight(int height) {
|
||||
DisplayManager.height = height;
|
||||
}
|
||||
|
||||
public static int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public static void setWidth(int width) {
|
||||
DisplayManager.width = width;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ public class VBO {
|
|||
*/
|
||||
|
||||
public void clearBuffer(){
|
||||
buffer.clear();
|
||||
floatlist.clear();
|
||||
}
|
||||
|
||||
public void addDataByFloatArray(float[] a){
|
||||
|
|
|
@ -1,14 +1,28 @@
|
|||
package mrdev023.rendering.gui;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import mrdev023.rendering.*;
|
||||
|
||||
import org.newdawn.slick.*;
|
||||
|
||||
|
||||
public class ButtonGUI extends GUI{
|
||||
|
||||
public boolean IsLoaded = false;
|
||||
|
||||
public float px,py,pwidth,pheight;
|
||||
|
||||
public ButtonGUI(String value,float x,float y,float width,float height){
|
||||
super(value,x, y, width, height,(int)(height/2));
|
||||
super(value,x * DisplayManager.getWidth(), y * DisplayManager.getHeight(), width * DisplayManager.getWidth(), height * DisplayManager.getHeight(),24);
|
||||
if(!IsLoaded){
|
||||
int size = (int)((height * DisplayManager.getHeight())/2);
|
||||
setFont(new TrueTypeFont (new java.awt.Font("Times New Roman", java.awt.Font.PLAIN, size),false));
|
||||
IsLoaded = true;
|
||||
}
|
||||
this.px = x;
|
||||
this.py = y;
|
||||
this.pwidth = width;
|
||||
this.pheight = height;
|
||||
}
|
||||
|
||||
public void render()
|
||||
|
@ -17,13 +31,13 @@ public class ButtonGUI extends GUI{
|
|||
glLoadIdentity();
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
if(mouseIsCollide()){
|
||||
if(mouseIsCollide() && IsHover){
|
||||
font.drawString((int)(x + (width/2 - font.getWidth(value)/2)),(int)(y + font.getHeight()/2 - height/16),value,Color.green);
|
||||
}else{
|
||||
font.drawString((int)(x + (width/2 - font.getWidth(value)/2)),(int)(y + font.getHeight()/2 - height/16),value,Color.red);
|
||||
}
|
||||
glDisable(GL_BLEND);
|
||||
if(mouseIsCollide())glColor4f(0,1,0,1);
|
||||
if(mouseIsCollide() && IsHover)glColor4f(0,1,0,1);
|
||||
else glColor4f(1,0,0,1);
|
||||
glLineWidth(height/(height/2));
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
@ -41,4 +55,8 @@ public class ButtonGUI extends GUI{
|
|||
|
||||
}
|
||||
|
||||
public void updateGUI() {
|
||||
updateFrame(px * DisplayManager.getWidth(), py * DisplayManager.getHeight(), pwidth * DisplayManager.getWidth(), pheight * DisplayManager.getHeight(),(int)((pheight * DisplayManager.getHeight())/2));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package mrdev023.rendering.gui;
|
|||
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.gui.action.*;
|
||||
import mrdev023.update.*;
|
||||
|
||||
import org.lwjgl.input.*;
|
||||
import org.lwjgl.opengl.*;
|
||||
|
@ -16,7 +17,9 @@ public abstract class GUI {
|
|||
|
||||
public static final int NULL = 0,CLICKED = 1;
|
||||
|
||||
public Action action;
|
||||
protected Action action = null;
|
||||
|
||||
protected boolean IsHover = true;
|
||||
|
||||
protected TrueTypeFont font = null;
|
||||
|
||||
|
@ -28,31 +31,38 @@ public abstract class GUI {
|
|||
this.color = new Color4f(1f,1f,1f,1f);
|
||||
this.value = value;
|
||||
font = new TrueTypeFont (new java.awt.Font("Times New Roman", java.awt.Font.PLAIN, size),false);
|
||||
this.action = new Action() {
|
||||
public void manageAction(int action) {}
|
||||
public void hover(Vector2f position) {}
|
||||
};
|
||||
}
|
||||
|
||||
public abstract void render();
|
||||
public abstract void update();
|
||||
|
||||
|
||||
public void updateAction(){
|
||||
while(Mouse.next()){
|
||||
if(Mouse.getEventButtonState()){
|
||||
if(Mouse.getEventButton() == 0 && mouseIsCollide()){
|
||||
action.manageAction(CLICKED);
|
||||
}
|
||||
}else{
|
||||
|
||||
}
|
||||
}
|
||||
if(mouseIsCollide())action.hover(new Vector2f(Mouse.getX(),(Display.getDisplayMode().getHeight() - Mouse.getY())));
|
||||
public void updateFrame(float x,float y,float width,float height,int size){
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
font = null;
|
||||
font = new TrueTypeFont (new java.awt.Font("Times New Roman", java.awt.Font.PLAIN, size),false);
|
||||
}
|
||||
|
||||
public void setAction(Action a){
|
||||
public abstract void updateGUI();
|
||||
|
||||
public void updateAction(){
|
||||
if(this.action != null){
|
||||
if(Update.mouseButtonPressed(0) && mouseIsCollide())action.manageAction(CLICKED);
|
||||
if(mouseIsCollide())action.hover(new Vector2f(Mouse.getX(),(Display.getDisplayMode().getHeight() - Mouse.getY())));
|
||||
}
|
||||
}
|
||||
|
||||
public GUI setAction(Action a){
|
||||
this.action = a;
|
||||
return this;
|
||||
}
|
||||
|
||||
public GUI setHoverAnimation(boolean a){
|
||||
this.IsHover = a;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean mouseIsCollide(){
|
||||
|
@ -105,6 +115,38 @@ public abstract class GUI {
|
|||
public Action getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public boolean isIsHover() {
|
||||
return IsHover;
|
||||
}
|
||||
|
||||
public void setIsHover(boolean isHover) {
|
||||
IsHover = isHover;
|
||||
}
|
||||
|
||||
public TrueTypeFont getFont() {
|
||||
return font;
|
||||
}
|
||||
|
||||
public void setFont(TrueTypeFont font) {
|
||||
this.font = font;
|
||||
}
|
||||
|
||||
public static int getNull() {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
public static int getClicked() {
|
||||
return CLICKED;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,27 @@
|
|||
package mrdev023.rendering.gui;
|
||||
|
||||
import static org.lwjgl.opengl.GL11.*;
|
||||
import mrdev023.rendering.*;
|
||||
|
||||
import org.newdawn.slick.*;
|
||||
|
||||
public class LabelGUI extends GUI{
|
||||
|
||||
public boolean IsLoaded = false;
|
||||
|
||||
public float px,py,pwidth,pheight;
|
||||
|
||||
public LabelGUI(String value,float x, float y, float width, float height) {
|
||||
super(value,x, y, width, height,(int)(height/2));
|
||||
super(value,x * DisplayManager.getWidth(), y * DisplayManager.getHeight(), width * DisplayManager.getWidth(), height * DisplayManager.getHeight(),24);
|
||||
if(!IsLoaded){
|
||||
int size = (int)((height * DisplayManager.getHeight())/2);
|
||||
setFont(new TrueTypeFont (new java.awt.Font("Times New Roman", java.awt.Font.PLAIN, size),false));
|
||||
IsLoaded = true;
|
||||
}
|
||||
this.px = x;
|
||||
this.py = y;
|
||||
this.pwidth = width;
|
||||
this.pheight = height;
|
||||
}
|
||||
|
||||
public void render() {
|
||||
|
@ -24,4 +38,8 @@ public class LabelGUI extends GUI{
|
|||
|
||||
}
|
||||
|
||||
public void updateGUI() {
|
||||
updateFrame(px * DisplayManager.getWidth(), py * DisplayManager.getHeight(), pwidth * DisplayManager.getWidth(), pheight * DisplayManager.getHeight(),(int)((pheight * DisplayManager.getHeight())/2));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -36,4 +36,37 @@ public class Text {
|
|||
GL11.glPopMatrix();
|
||||
}
|
||||
|
||||
private static String chars = "abcdefghijklmnopqrstuvwxyz 0123456789:!?.,()";
|
||||
|
||||
public static void drawString(String msg, int x, int y, int size) {
|
||||
msg = msg.toLowerCase();
|
||||
// Texture.font.bind();
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
for (int i = 0; i < msg.length(); i++) {
|
||||
int xi = chars.indexOf(msg.charAt(i));
|
||||
int yi = 0;
|
||||
if (xi >= 27) {
|
||||
xi %= 27;
|
||||
yi++;
|
||||
}
|
||||
if ((yi >= 0) && (xi >= 0)) {
|
||||
quadData(x + i * size, y, size, size, xi, yi, 27.0F, 4.0F);
|
||||
}
|
||||
}
|
||||
GL11.glEnd();
|
||||
// Texture.font.unbind();
|
||||
}
|
||||
|
||||
public static void quadData(int x, int y, int w, int h, int xo, int yo,
|
||||
float xSize, float ySize) {
|
||||
GL11.glTexCoord2f((0 + xo) / xSize, (0 + yo) / ySize);
|
||||
GL11.glVertex2f(x, y);
|
||||
GL11.glTexCoord2f((1 + xo) / xSize, (0 + yo) / ySize);
|
||||
GL11.glVertex2f(x + w, y);
|
||||
GL11.glTexCoord2f((1 + xo) / xSize, (1 + yo) / ySize);
|
||||
GL11.glVertex2f(x + w, y + h);
|
||||
GL11.glTexCoord2f((0 + xo) / xSize, (1 + yo) / ySize);
|
||||
GL11.glVertex2f(x, y + h);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,23 +1,78 @@
|
|||
package mrdev023.update;
|
||||
import mrdev023.gameEngine.*;
|
||||
import java.util.*;
|
||||
|
||||
import org.lwjgl.input.*;
|
||||
|
||||
import mrdev023.gameengine.*;
|
||||
|
||||
|
||||
public class Update {
|
||||
|
||||
private static ArrayList<Integer> mousePressed = new ArrayList<Integer>();
|
||||
private static ArrayList<Integer> mouseReleased = new ArrayList<Integer>();
|
||||
private static ArrayList<Integer> keyboardPressed = new ArrayList<Integer>();
|
||||
private static ArrayList<Integer> keyboardReleased = new ArrayList<Integer>();
|
||||
|
||||
/**
|
||||
* @Info Fonction permettant de gerer les action de la souris
|
||||
*/
|
||||
public static void updateMouse(){
|
||||
mousePressed.clear();
|
||||
mouseReleased.clear();
|
||||
while(Mouse.next()){
|
||||
if(Mouse.getEventButtonState()){
|
||||
mousePressed.add(Mouse.getEventButton());
|
||||
}else{
|
||||
mouseReleased.add(Mouse.getEventButton());
|
||||
}
|
||||
}
|
||||
GameEngine.getGameState().updateMouse();
|
||||
}
|
||||
|
||||
public static boolean mouseButtonPressed(int button){
|
||||
for(Integer m : mousePressed){
|
||||
if(m == button)return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean mouseButtonReleased(int button){
|
||||
for(Integer m : mouseReleased){
|
||||
if(m == button)return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Info Fonction permettant de gerer les action du clavier
|
||||
*/
|
||||
public static void updateKeyboard(){
|
||||
keyboardPressed.clear();
|
||||
keyboardReleased.clear();
|
||||
while(Keyboard.next()){
|
||||
if(Keyboard.getEventKeyState()){
|
||||
keyboardPressed.add(Keyboard.getEventKey());
|
||||
}else{
|
||||
keyboardReleased.add(Keyboard.getEventKey());
|
||||
}
|
||||
}
|
||||
GameEngine.getGameState().updateKeyboard();
|
||||
}
|
||||
|
||||
public static boolean keyboardButtonPressed(int button){
|
||||
for(Integer m : keyboardPressed){
|
||||
if(m == button)return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean keyboardButtonReleased(int button){
|
||||
for(Integer m : keyboardReleased){
|
||||
if(m == button)return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Info Fonction de mettre a jour le display et d'autre choses predefinie
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package mrdev023.world;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
import mrdev023.io.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.world.chunk.*;
|
||||
|
||||
|
@ -24,8 +27,26 @@ public class SoloWorld extends World{
|
|||
for(int k = 0;k <= delta_z;k++){
|
||||
// for(int j = 0; j < HEIGHT; j++){
|
||||
if(getChunk((xa + i), 0, (za + k)) != null)continue;
|
||||
Chunk ch = new Chunk((xa + i),0,(za + k),this);
|
||||
chunks.add(ch);
|
||||
if(IO.chunkIsSaved(new Vector3i((xa + i),0,(za + k)),"soloWorld")){
|
||||
try {
|
||||
Chunk ch = IO.loadChunk(new Vector3i((xa + i),0,(za + k)),"soloWorld");
|
||||
chunks.add(ch);
|
||||
} catch (ClassNotFoundException e1) {
|
||||
if(getChunk((xa + i), 0, (za + k)) != null)continue;
|
||||
Chunk ch = new Chunk((xa + i),0,(za + k),this);
|
||||
chunks.add(ch);
|
||||
System.err.println(e1.getMessage());
|
||||
} catch (IOException e1) {
|
||||
if(getChunk((xa + i), 0, (za + k)) != null)continue;
|
||||
Chunk ch = new Chunk((xa + i),0,(za + k),this);
|
||||
chunks.add(ch);
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}else{
|
||||
if(getChunk((xa + i), 0, (za + k)) != null)continue;
|
||||
Chunk ch = new Chunk((xa + i),0,(za + k),this);
|
||||
chunks.add(ch);
|
||||
}
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,6 +164,16 @@ public abstract class World {
|
|||
return VIEW_CHUNK;
|
||||
}
|
||||
|
||||
public static void printBlockArray(Block[][][] blocks){
|
||||
for(int x = 0; x < blocks.length;x++){
|
||||
for(int y = 0; y < blocks[x].length;y++){
|
||||
for(int z = 0; z < blocks[x][y].length;z++){
|
||||
System.out.println(blocks[x][y][z]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void destroyWorld(){
|
||||
for(Chunk c : chunks){
|
||||
c.destroyChunk();
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
package mrdev023.world.chunk;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import mrdev023.blocks.*;
|
||||
import mrdev023.gameEngine.*;
|
||||
import mrdev023.gameengine.*;
|
||||
import mrdev023.io.*;
|
||||
import mrdev023.main.*;
|
||||
import mrdev023.math.*;
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class Chunk {
|
||||
public class Chunk{
|
||||
|
||||
public final static int SIZE = 64;
|
||||
private int x, y, z;
|
||||
|
@ -27,6 +30,15 @@ public class Chunk {
|
|||
this.blocks = new Block[SIZE][SIZE][SIZE];
|
||||
vbo = new VBO();
|
||||
}
|
||||
|
||||
public Chunk(int x, int y, int z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.world = null;
|
||||
this.blocks = new Block[SIZE][SIZE][SIZE];
|
||||
vbo = new VBO();
|
||||
}
|
||||
|
||||
public void render() {
|
||||
vbo.renderVBO();
|
||||
|
@ -35,7 +47,18 @@ public class Chunk {
|
|||
public void update() {
|
||||
|
||||
}
|
||||
|
||||
public void setBlocks(Block[][][] blocks){
|
||||
this.blocks = blocks;
|
||||
vbo.clearBuffer();
|
||||
Main.addThread(new LoadChunk(this, world),"Load Chunk");
|
||||
IsCurrentGenerate = true;
|
||||
}
|
||||
|
||||
public Block[][][] getBlocks(){
|
||||
return blocks;
|
||||
}
|
||||
|
||||
public void createChunk(World world) {
|
||||
this.world = world;
|
||||
Main.addThread(new Generate(this, world),"Create Chunk");
|
||||
|
@ -50,7 +73,7 @@ public class Chunk {
|
|||
public void updateChunk() {
|
||||
vbo.clearBuffer();
|
||||
for (int i = 0; i < SIZE; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
for (int j = 0; j < SIZE; j++) {
|
||||
for (int k = 0; k < SIZE; k++) {
|
||||
loopChunk(i, j, k);
|
||||
}
|
||||
|
@ -75,8 +98,8 @@ public class Chunk {
|
|||
return z;
|
||||
}
|
||||
|
||||
public Vector3f getPosition() {
|
||||
return new Vector3f(x, y, z);
|
||||
public Vector3i getPosition() {
|
||||
return new Vector3i((int)x, (int)y, (int)z);
|
||||
}
|
||||
|
||||
public Block getBlock(int x, int y, int z) {
|
||||
|
@ -274,8 +297,16 @@ public class Chunk {
|
|||
return IsGenerated;
|
||||
}
|
||||
|
||||
public void setGenerated(boolean g) {
|
||||
public void setGenerated(boolean g,boolean IsGenerate) {
|
||||
IsGenerated = g;
|
||||
if(g && IsGenerate){
|
||||
try {
|
||||
IO.saveChunk(this,"soloWorld");
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString(){
|
||||
|
|
|
@ -35,7 +35,7 @@ class Generate implements Runnable {
|
|||
long current = System.currentTimeMillis();
|
||||
long elapsed1 = 0;
|
||||
boolean IsError = true;
|
||||
Noise noise = new Noise(world.seed, world.octave, world.amplitude);;
|
||||
Noise noise = new Noise(world.seed, world.octave, world.amplitude);
|
||||
Random random = new Random(world.seed);
|
||||
Noise colorVariationNoise = new Noise(world.seed,world.octave,2);
|
||||
for (int x = 0; x < chunk.SIZE; x++) {
|
||||
|
@ -87,12 +87,13 @@ class Generate implements Runnable {
|
|||
// }
|
||||
}
|
||||
// }
|
||||
chunk.setGenerated(true);
|
||||
chunk.setGenerated(true,true);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
IsError = true;
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(Thread.currentThread().getName() + " terminated | loop1:" + elapsed1 + "ms loop2:" + (System.currentTimeMillis()-current) + "ms");
|
||||
Thread.currentThread().stop();
|
||||
}
|
||||
|
|
53
VBO/src/mrdev023/world/chunk/LoadChunk.java
Normal file
53
VBO/src/mrdev023/world/chunk/LoadChunk.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
package mrdev023.world.chunk;
|
||||
|
||||
import mrdev023.rendering.*;
|
||||
import mrdev023.world.*;
|
||||
|
||||
public class LoadChunk implements Runnable{
|
||||
|
||||
private Chunk chunk;
|
||||
private World world;
|
||||
|
||||
public LoadChunk(Chunk chunk, World world) {
|
||||
this.chunk = chunk;
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public void run(){
|
||||
long current = System.currentTimeMillis();
|
||||
boolean IsError = true;
|
||||
while(IsError){
|
||||
IsError = false;
|
||||
try{
|
||||
// synchronized (world.chunks) {
|
||||
for (int i = 0; i < chunk.SIZE; i++) {
|
||||
for (int j = 0; j < chunk.SIZE; j++) {
|
||||
for (int k = 0; k < chunk.SIZE; k++) {
|
||||
int xa = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK;
|
||||
int xb = (int)((Camera.getPosition().getX()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK;
|
||||
int za = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) - World.VIEW_CHUNK;
|
||||
int zb = (int)((Camera.getPosition().getZ()-((float)Chunk.SIZE/2.0f))/(float)Chunk.SIZE) + World.VIEW_CHUNK;
|
||||
if(chunk.getX() < xa || chunk.getX() > xb || chunk.getZ() < za || chunk.getZ() > zb ){
|
||||
System.out.println(Thread.currentThread().getName() + " stopped | " + (System.currentTimeMillis()-current));
|
||||
Thread.currentThread().stop();
|
||||
return;
|
||||
}
|
||||
int xx = chunk.getX() * chunk.SIZE + i;
|
||||
int zz = chunk.getZ() * chunk.SIZE + k;
|
||||
chunk.loopChunk(i, j, k);
|
||||
}
|
||||
}
|
||||
}
|
||||
// }
|
||||
chunk.setGenerated(true,false);
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
IsError = true;
|
||||
}
|
||||
}
|
||||
System.out.println(Thread.currentThread().getName() + " terminated | loop1:" + (System.currentTimeMillis()-current) + "ms");
|
||||
Thread.currentThread().stop();
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue