Fixed bundle bugs.
This commit is contained in:
@ -1,39 +1,74 @@
|
||||
import { Scene } from "../scene/Scene";
|
||||
|
||||
type Time = {
|
||||
delta:number;
|
||||
current:number;
|
||||
last:number;
|
||||
}
|
||||
|
||||
export class Game {
|
||||
public time:Time;
|
||||
private scene:Scene|null;
|
||||
|
||||
export abstract class Game {
|
||||
constructor() {
|
||||
|
||||
this.time = { delta: 0, current: 0, last: 0 };
|
||||
this.scene = null;
|
||||
}
|
||||
|
||||
public setScene(scene:Scene) { this.scene = scene; }
|
||||
|
||||
private timeUpdate() {
|
||||
this.time.delta = epochGetDelta();
|
||||
this.time.current = epochGetCurrent();
|
||||
this.time.last = epochGetLast();
|
||||
}
|
||||
|
||||
init() {
|
||||
print("init");
|
||||
this.timeUpdate();
|
||||
}
|
||||
|
||||
update() {
|
||||
print("update");
|
||||
this.timeUpdate();
|
||||
|
||||
if(this.scene) this.scene.update();
|
||||
}
|
||||
|
||||
dispose() {
|
||||
print("Disposed");
|
||||
if(this.scene) this.scene.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// Main Game Instance
|
||||
let GAME_MAIN:Game|null = null;
|
||||
|
||||
/**
|
||||
* Set the main game instance.
|
||||
* @param game Game to become the main game instance.
|
||||
*/
|
||||
export const gameSetMain = (game:Game) => {
|
||||
print("setting", game);
|
||||
GAME_MAIN = game;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that is invoked by C when the game needs to intialize.
|
||||
*/
|
||||
const init = () => {
|
||||
if(!GAME_MAIN) return;
|
||||
GAME_MAIN.init();
|
||||
print("init");
|
||||
// if(!GAME_MAIN) return;
|
||||
// GAME_MAIN.init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that is invoked by C every single frame.
|
||||
*/
|
||||
const update = () => {
|
||||
if(!GAME_MAIN) return;
|
||||
GAME_MAIN.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that is invoked by C when the game needs to stop and clean up.
|
||||
*/
|
||||
const dispose = () => {
|
||||
if(!GAME_MAIN) return;
|
||||
GAME_MAIN.dispose();
|
||||
|
Reference in New Issue
Block a user