shimeji class rewriten as the base for the rest, physis next
This commit is contained in:
@@ -211,7 +211,71 @@ export class Shimejii {
|
||||
moveTo(pos: number) {}
|
||||
}
|
||||
|
||||
export class Shimeji {
|
||||
namespace Shimagic {
|
||||
export class Shimeji {
|
||||
private WebGEngine: WebG.Engine;
|
||||
private PhysisEngine: Physis.Engine;
|
||||
//private PhysisEngine: Physis.Engine;
|
||||
private size!: number;
|
||||
|
||||
private AnimID: number | null = null;
|
||||
private pDeltaT: number = 0;
|
||||
|
||||
constructor(webgengine: WebG.Engine /* physis: Physis.Engine */) {
|
||||
this.WebGEngine = webgengine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Factory method: Initializes all sub-systems like WebG & Physis aswell as initializes the Shimeji and starts its animation
|
||||
* @async
|
||||
* @public
|
||||
* @param {ShimejiConfig} config - Shimeji configuration
|
||||
* @returns {Promise<Shimeji>} that resolves when the Shimeji is done initializing
|
||||
*/
|
||||
public static async Initialize(config: ShimejiConfig): Promise<Shimeji> {
|
||||
const webg = await WebG.Engine.Initialize(config.webG);
|
||||
//const physis = await Physis.Engine.Initialize(config.physis);
|
||||
|
||||
const shimeji = new Shimeji(webg);
|
||||
shimeji.size = config.size;
|
||||
|
||||
const AFrame = (delta: number) => {
|
||||
shimeji.pDeltaT = delta;
|
||||
shimeji.AnimID = requestAnimationFrame(shimeji._anim);
|
||||
};
|
||||
|
||||
shimeji.AnimID = requestAnimationFrame(AFrame);
|
||||
|
||||
return shimeji;
|
||||
}
|
||||
|
||||
private _anim(delta: number) {
|
||||
let dt = (delta - this.pDeltaT) / 1000;
|
||||
dt = Math.min(dt, 0.05 /* * this.Physis.TIMESCALE */);
|
||||
this.pDeltaT = delta;
|
||||
|
||||
this.UpdatePhysics(dt);
|
||||
this.UpdateFrame(dt);
|
||||
|
||||
this.AnimID = requestAnimationFrame(this._anim);
|
||||
}
|
||||
|
||||
/**
|
||||
* A function called automatically every "frame" where the code for calculating the next physics frame of the Shimeji is placed
|
||||
* @param delta - Automatically passed in deltaT value;
|
||||
*/
|
||||
private UpdatePhysics(delta: number): void {}
|
||||
|
||||
/**
|
||||
* A function called automatically every "frame" where the code for drawing the next frame of the Shimeji is placed
|
||||
* @param delta - Automatically passed in deltaT value;
|
||||
*/
|
||||
private UpdateFrame(delta: number): void {}
|
||||
}
|
||||
|
||||
interface ShimejiConfig {
|
||||
sprite: string; //temp soultion to
|
||||
size: number;
|
||||
webG: WebG.EngineConfig;
|
||||
//physis: Physis.EngineConfig;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user