aboutsummaryrefslogtreecommitdiffstats
path: root/src/ru/olamedia/olacraft/game
diff options
context:
space:
mode:
authorolamedia <[email protected]>2012-09-28 18:46:42 +0600
committerolamedia <[email protected]>2012-09-28 18:46:42 +0600
commitb4192c7a88bad111bebbd42d391d6e729c8617d6 (patch)
treeb05a586dbc60c5427fcc7f3fe01cf2fdcb970272 /src/ru/olamedia/olacraft/game
initial
Diffstat (limited to 'src/ru/olamedia/olacraft/game')
-rw-r--r--src/ru/olamedia/olacraft/game/Game.java106
-rw-r--r--src/ru/olamedia/olacraft/game/GameInterface.java7
-rw-r--r--src/ru/olamedia/olacraft/game/IGameWrapper.java7
-rw-r--r--src/ru/olamedia/olacraft/game/LocalGameWrapper.java17
-rw-r--r--src/ru/olamedia/olacraft/game/SpawnLocation.java7
-rw-r--r--src/ru/olamedia/olacraft/game/Timer.java99
-rw-r--r--src/ru/olamedia/olacraft/game/package-info.java8
7 files changed, 251 insertions, 0 deletions
diff --git a/src/ru/olamedia/olacraft/game/Game.java b/src/ru/olamedia/olacraft/game/Game.java
new file mode 100644
index 0000000..0980505
--- /dev/null
+++ b/src/ru/olamedia/olacraft/game/Game.java
@@ -0,0 +1,106 @@
+package ru.olamedia.olacraft.game;
+
+import com.jogamp.newt.opengl.GLWindow;
+
+import ru.olamedia.camera.MatrixCamera;
+import ru.olamedia.game.GameFrame;
+import ru.olamedia.olacraft.events.GameEvent;
+import ru.olamedia.olacraft.network.GameClient;
+import ru.olamedia.olacraft.network.GameServer;
+import ru.olamedia.olacraft.scene.GameScene;
+import ru.olamedia.olacraft.world.dataProvider.AbstractChunkDataProvider;
+import ru.olamedia.player.Player;
+
+public class Game {
+ public static Game instance = null;
+ public static int port = 26002;
+ public static boolean isServerRunning = false;
+ public static GameServer server = new GameServer();
+ public static GameClient client = new GameClient();
+ public static Timer timer = new Timer();
+
+ public MatrixCamera camera;
+
+ public static int MODE_SINGLEPLAYER = 1;
+ public static int MODE_MULTIPLAYER = 2;
+ public static int MODE_SERVER = 4;
+ @SuppressWarnings("unused")
+ private int mode = 1;
+ private boolean isRunning = false;
+ @SuppressWarnings("unused")
+ // player
+ public Player player;
+
+ // block world
+ // private blockWorld;
+ // live entities (including player and npcs)
+ // private liveEntities;
+ public Game() {
+ this(MODE_SINGLEPLAYER);
+ }
+
+ public Game(int mode) {
+ this.mode = mode;
+ if ((MODE_MULTIPLAYER & mode) > 0) {
+ if ((MODE_SERVER & mode) > 0) {
+ // init server
+ } else {
+ // init client
+ }
+ }
+ player = new Player();
+ camera = new MatrixCamera();
+ camera.attachTo(player);
+ camera.setFov(90);
+ camera.pack();
+ // scene.registerLiveEntity(player);
+ }
+
+ public void start() {
+ isRunning = true;
+ GameEvent e = new GameEvent(null);
+ e.setType(GameEvent.GAME_START);
+ e.dispatch();
+ }
+
+ // Pause game in single mode
+ public void pause() {
+
+ }
+
+ public void stop() {
+
+ }
+
+ public boolean isRunning() {
+ return isRunning;
+ }
+
+ public void spawnMe(int x, int y, int z) {
+ player.setLocation(x, y, z);
+ }
+
+ public void tick() {
+ timer.update();
+
+ }
+
+ public static class Display {
+ public static int getWidth() {
+ return (int) GameFrame.getWidth();
+ }
+
+ public static int getHeight() {
+ return (int) GameFrame.getHeight();
+ }
+
+ public static float getAspect() {
+ return ((float) getWidth()) / ((float) getHeight());
+ }
+ }
+
+ public float getDelta() {
+ return (float) timer.getElapsedTime() / 1000;
+ }
+
+}
diff --git a/src/ru/olamedia/olacraft/game/GameInterface.java b/src/ru/olamedia/olacraft/game/GameInterface.java
new file mode 100644
index 0000000..1f02071
--- /dev/null
+++ b/src/ru/olamedia/olacraft/game/GameInterface.java
@@ -0,0 +1,7 @@
+package ru.olamedia.olacraft.game;
+
+public class GameInterface {
+ public void requestSpawn(){
+
+ }
+}
diff --git a/src/ru/olamedia/olacraft/game/IGameWrapper.java b/src/ru/olamedia/olacraft/game/IGameWrapper.java
new file mode 100644
index 0000000..a4a7ed1
--- /dev/null
+++ b/src/ru/olamedia/olacraft/game/IGameWrapper.java
@@ -0,0 +1,7 @@
+package ru.olamedia.olacraft.game;
+
+public interface IGameWrapper {
+ public void setMyId(int connectionId);
+
+ public void spawn(int connectionId, int x, int y, int z);
+}
diff --git a/src/ru/olamedia/olacraft/game/LocalGameWrapper.java b/src/ru/olamedia/olacraft/game/LocalGameWrapper.java
new file mode 100644
index 0000000..8c19ce6
--- /dev/null
+++ b/src/ru/olamedia/olacraft/game/LocalGameWrapper.java
@@ -0,0 +1,17 @@
+package ru.olamedia.olacraft.game;
+
+public class LocalGameWrapper implements IGameWrapper {
+
+ @Override
+ public void setMyId(int connectionId) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void spawn(int connectionId, int x, int y, int z) {
+ // TODO Auto-generated method stub
+
+ }
+
+}
diff --git a/src/ru/olamedia/olacraft/game/SpawnLocation.java b/src/ru/olamedia/olacraft/game/SpawnLocation.java
new file mode 100644
index 0000000..2ff0c39
--- /dev/null
+++ b/src/ru/olamedia/olacraft/game/SpawnLocation.java
@@ -0,0 +1,7 @@
+package ru.olamedia.olacraft.game;
+
+public class SpawnLocation {
+ public int x;
+ public int y;
+ public int z;
+}
diff --git a/src/ru/olamedia/olacraft/game/Timer.java b/src/ru/olamedia/olacraft/game/Timer.java
new file mode 100644
index 0000000..1c0aaee
--- /dev/null
+++ b/src/ru/olamedia/olacraft/game/Timer.java
@@ -0,0 +1,99 @@
+package ru.olamedia.olacraft.game;
+
+/**
+ * For frame-rate independent movement
+ *
+ * @author Oskar Veerhoek
+ */
+public class Timer {
+ private long lastTime; // nanoseconds
+ private double elapsedTime;
+ private float fps;
+ private int fpsCounter = 0;
+ private long lastFPS;
+ private float avgSeconds = 3;
+
+ /**
+ * @return the fps
+ */
+ public float getFps() {
+ return fps;
+ }
+
+ /**
+ * @return the avgFps
+ */
+ public float getAvgFps() {
+ return avgFps;
+ }
+
+ private float avgFps;
+
+ /**
+ * Creates a timer.
+ */
+ public Timer() {
+ fps = 0;
+ }
+
+ /**
+ * Initializes the timer. Call this just before entering the game loop.
+ */
+ public void initialize() {
+ lastTime = System.nanoTime();
+ }
+
+ /**
+ * @return the elapsed time since the the next to last update call
+ */
+ public double getElapsedTime() {
+ return elapsedTime;
+ }
+
+ /**
+ * Updates the timer. Call this once every iteration of the game loop.
+ *
+ * @return the elapsed time in milliseconds
+ */
+ public double update() {
+ if (lastTime == 0) {
+ lastTime = System.nanoTime();
+ return 0;
+ } else {
+ long elapsedTime = System.nanoTime() - lastTime;
+ updateFps(elapsedTime);
+ lastTime = System.nanoTime();
+ this.elapsedTime = elapsedTime / (double) 1000000;
+ return this.elapsedTime;
+ }
+ }
+
+ public void updateFps(long elapsedTime) {
+ if (elapsedTime > 0) {
+ float ms = (float) (elapsedTime / 1000000);
+ if (ms > 0) {
+ fps = (float) (1000 / ms);
+ }
+ }
+ fpsCounter++;
+ if (lastFPS == 0) {
+ lastFPS = System.nanoTime();
+ } else {
+ double elapsedFPS = (System.nanoTime() - lastFPS) / (double) 1000000;
+ if (elapsedFPS > 1000 * avgSeconds) {
+ avgFps = fpsCounter / avgSeconds;
+ fpsCounter = 0;
+ lastFPS = System.nanoTime();
+ }
+ }
+
+ // if (elapsedTime > 0) {
+ // fps = (float) (1000 / (elapsedTime / 1000000));
+ // if (avgFps == 0) {
+ // avgFps = fps;
+ // } else {
+ // avgFps = avgFps + (fps - avgFps) / 1000;
+ // }
+ // }
+ }
+} \ No newline at end of file
diff --git a/src/ru/olamedia/olacraft/game/package-info.java b/src/ru/olamedia/olacraft/game/package-info.java
new file mode 100644
index 0000000..85b0f16
--- /dev/null
+++ b/src/ru/olamedia/olacraft/game/package-info.java
@@ -0,0 +1,8 @@
+/**
+ *
+ */
+/**
+ * @author olamedia
+ *
+ */
+package ru.olamedia.olacraft.game; \ No newline at end of file