summaryrefslogtreecommitdiff
path: root/src/omni.ts
diff options
context:
space:
mode:
authorJ08nY2016-04-29 00:09:43 +0200
committerJ08nY2016-04-29 00:09:43 +0200
commit7caff3e0edcf8982ec716143ed030b2790061b39 (patch)
tree16673b30ff5fcb35c53bdcbeeea0cf0fa9b22d25 /src/omni.ts
parente243829840896b29c2508d3984b229adc3074edc (diff)
downloadomniplex-master.tar.gz
omniplex-master.tar.zst
omniplex-master.zip
pointerlock workHEADmaster
Diffstat (limited to 'src/omni.ts')
-rw-r--r--src/omni.ts158
1 files changed, 6 insertions, 152 deletions
diff --git a/src/omni.ts b/src/omni.ts
index 64a31a8..fcef3d9 100644
--- a/src/omni.ts
+++ b/src/omni.ts
@@ -1,156 +1,10 @@
/// <reference path="../ts/three.d.ts" />
/// <reference path="../ts/physijs.d.ts" />
-/// <reference path="cube.ts" />
+
+/// <reference path="game.ts" />
+/// <reference path="interface.ts" />
+/// <reference path="input.ts" />
/// <reference path="block.ts" />
/// <reference path="puzzle.ts" />
-/// <reference path="pointerlock.ts" />
-/// <reference path="interface.ts" />
-
-module Omni {
- /**
- * Base game class, will handle the game loop, rendering,
- */
- export class Game implements Tickable {
- private renderer:THREE.WebGLRenderer;
- private camera:THREE.PerspectiveCamera;
-
- private block_loader:BlockLoader;
- private current_cube:Cube;
-
- private ticks:number = 0;
- private delta:number = 0;
- private lastFrame:number = 0;
- private timestep:number = 1000 / 60;
- private maxFPS:number = 60;
-
- private keepRunning:boolean;
-
- static CAMERA_FOV:number = 55;
- static CAMERA_NEAR:number = 1;
- static CAMERA_FAR:number = 1000;
-
- /**
- *
- */
- constructor() {
- this.renderer = new THREE.WebGLRenderer({
- antialias: true
- });
- this.renderer.setClearColor(0xcacaca);
- this.renderer.setSize(window.innerWidth, window.innerHeight);
- document.body.appendChild(this.renderer.domElement);
- window.addEventListener("resize", this.onWindowResize, false);
-
- this.camera = new THREE.PerspectiveCamera(Game.CAMERA_FOV, window.innerWidth / window.innerHeight, Game.CAMERA_NEAR, Game.CAMERA_FAR);
- this.block_loader = new BlockLoader(BlockLoader.FILES);
- }
-
- /**
- *
- */
- init():void {
-
- this.block_loader.load();
- }
-
- /**
- *
- */
- start():void {
-
- }
-
- /**
- *
- */
- unpause():void {
-
- }
-
- /**
- *
- * @param delta
- */
- tick(delta:number):void {
- this.ticks++;
- this.current_cube.tick(delta);
- }
-
- /**
- *
- */
- render():void {
- this.renderer.render(this.current_cube, this.camera);
- }
-
- /**
- *
- * @param timestamp
- */
- run(timestamp?:number):void {
- if (!timestamp) {
- timestamp = performance.now();
- }
-
- if (timestamp < this.lastFrame + (1000 / this.maxFPS)) {
- if (this.keepRunning) {
- requestAnimationFrame(() => this.run());
- }
- return;
- }
- this.delta += timestamp - this.lastFrame;
- this.lastFrame = timestamp;
-
- var numUpdateSteps = 0;
- while (this.delta >= this.timestep) {
- this.tick(this.timestep);
- this.delta -= this.timestep;
- if (++numUpdateSteps >= 240) {
- // panic here, reset delta
- this.delta = 0;
- break;
- }
- }
- this.render();
- if (this.keepRunning) {
- requestAnimationFrame((time) => this.run(time));
- }
- }
-
- /**
- * When releasing pointer lock/on menu. Menu is HTML based.
- */
- pause():void {
-
- }
-
- /**
- * When leaving the page.
- */
- stop():void {
- this.block_loader.dispose();
- }
-
- onWindowResize = () => {
- this.camera.aspect = window.innerWidth / window.innerHeight;
- this.camera.updateProjectionMatrix();
-
- this.renderer.setSize(window.innerWidth, window.innerHeight);
- };
-
- }
-}
-
-let game:Omni.Game;
-window.onload = () => {
- console.log("onload");
- game = new Omni.Game();
- game.init();
- game.start();
-};
-
-window.onunload = () => {
- console.log("onunload");
- game.pause();
- game.stop();
-};
+/// <reference path="cube.ts" />
+/// <reference path="pointerlock.ts" /> \ No newline at end of file