Fixed bundle bugs.
This commit is contained in:
@ -8,10 +8,20 @@ const FILE_MAIN = 'main.js';
|
|||||||
let doneFiles = [];
|
let doneFiles = [];
|
||||||
let full = `
|
let full = `
|
||||||
var exports = {};
|
var exports = {};
|
||||||
|
|
||||||
|
function __extends(d,b) {
|
||||||
|
d.prototype = b.prototype;
|
||||||
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const CRUMMY_EXTENDS = /var __extends =([\S\s]*?)\}\)\(\)\;/gm;
|
||||||
|
const ES5_DEFINED = /Object\.defineProperty\(exports, \"__esModule\", \{ value\: true \}\)\;/gm
|
||||||
|
|
||||||
const outputFix = (output, dir) => {
|
const outputFix = (output, dir) => {
|
||||||
let out = output.replace(/exports\.\_\_esModule\ =\ true\;/gm, '');
|
let out = output
|
||||||
|
.replace(CRUMMY_EXTENDS, '')
|
||||||
|
.replace(/exports\.\_\_esModule\ =\ true\;/gm, '')
|
||||||
|
;
|
||||||
|
|
||||||
// Replace requires with exports.
|
// Replace requires with exports.
|
||||||
const reg = /var\ (.*?)\ \= require\("(.*?)"\)\;/gm;
|
const reg = /var\ (.*?)\ \= require\("(.*?)"\)\;/gm;
|
||||||
@ -23,8 +33,13 @@ const outputFix = (output, dir) => {
|
|||||||
out = out.replace(match.value[0], '').replace(exp, 'exports.');
|
out = out.replace(match.value[0], '').replace(exp, 'exports.');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove exports.whatever = void 0;
|
out = out
|
||||||
out = out.replace(/exports\.(.*?) \= void 0\;/gm, '');
|
.replace(CRUMMY_EXTENDS, '')
|
||||||
|
.replace(ES5_DEFINED, '')
|
||||||
|
.replace(/exports\.(.*?) \= void 0\;/gm, '')
|
||||||
|
.replace(/\ \ \ \ /gm, ' ')
|
||||||
|
;
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,16 +139,15 @@ void assetXmlLoad(xml_t *xml, char *assetName) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void assetScripterAppend(scripter_t *scripter, char *fileName) {
|
void assetScripterAppend(scripter_t *scripter, char *fileName) {
|
||||||
assetbuffer_t *asset = assetBufferOpen(fileName);
|
char *data;
|
||||||
int32_t read;
|
|
||||||
char buffer[2048];
|
|
||||||
|
|
||||||
duk_push_global_object(scripter->context);
|
|
||||||
|
|
||||||
while(read = assetBufferRead(asset, buffer, 2048)) {
|
|
||||||
duk_push_lstring(scripter->context, buffer, (duk_size_t)read);
|
|
||||||
}
|
|
||||||
|
|
||||||
duk_peval(scripter->context);
|
data = assetStringLoad(fileName);
|
||||||
assetBufferClose(asset);
|
duk_push_global_object(scripter->context);
|
||||||
|
duk_push_lstring(scripter->context, data, strlen(data));
|
||||||
|
|
||||||
|
if(duk_peval(scripter->context) != 0) {
|
||||||
|
printf("Error running: %s\n", duk_safe_to_string(scripter->context, -1));
|
||||||
|
}
|
||||||
|
|
||||||
|
free(data);
|
||||||
}
|
}
|
@ -28,9 +28,9 @@ bool sandboxSceneInit(sandboxscene_t *game) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void sandboxSceneUpdate(sandboxscene_t *game) {
|
void sandboxSceneUpdate(sandboxscene_t *game) {
|
||||||
scripterInvokeMethodSimple(&game->scripter, "update");
|
// scripterInvokeMethodSimple(&game->scripter, "update");
|
||||||
}
|
}
|
||||||
|
|
||||||
void sandboxSceneDispose(sandboxscene_t *game) {
|
void sandboxSceneDispose(sandboxscene_t *game) {
|
||||||
scripterInvokeMethodSimple(&game->scripter, "dispose");
|
// scripterInvokeMethodSimple(&game->scripter, "dispose");
|
||||||
}
|
}
|
@ -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() {
|
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() {
|
init() {
|
||||||
print("init");
|
this.timeUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
update() {
|
update() {
|
||||||
print("update");
|
this.timeUpdate();
|
||||||
|
|
||||||
|
if(this.scene) this.scene.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
dispose() {
|
dispose() {
|
||||||
print("Disposed");
|
if(this.scene) this.scene.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main Game Instance
|
||||||
let GAME_MAIN:Game|null = null;
|
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) => {
|
export const gameSetMain = (game:Game) => {
|
||||||
print("setting", game);
|
|
||||||
GAME_MAIN = game;
|
GAME_MAIN = game;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that is invoked by C when the game needs to intialize.
|
||||||
|
*/
|
||||||
const init = () => {
|
const init = () => {
|
||||||
if(!GAME_MAIN) return;
|
print("init");
|
||||||
GAME_MAIN.init();
|
// if(!GAME_MAIN) return;
|
||||||
|
// GAME_MAIN.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that is invoked by C every single frame.
|
||||||
|
*/
|
||||||
const update = () => {
|
const update = () => {
|
||||||
if(!GAME_MAIN) return;
|
if(!GAME_MAIN) return;
|
||||||
GAME_MAIN.update();
|
GAME_MAIN.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method that is invoked by C when the game needs to stop and clean up.
|
||||||
|
*/
|
||||||
const dispose = () => {
|
const dispose = () => {
|
||||||
if(!GAME_MAIN) return;
|
if(!GAME_MAIN) return;
|
||||||
GAME_MAIN.dispose();
|
GAME_MAIN.dispose();
|
||||||
|
44
ts/main.ts
44
ts/main.ts
@ -1,7 +1,49 @@
|
|||||||
import { Game, gameSetMain } from "./game/Game";
|
import { Game, gameSetMain } from "./game/Game";
|
||||||
|
import { Scene } from "./scene/Scene";
|
||||||
|
|
||||||
|
class TestScene extends Scene {
|
||||||
|
private quad:Primitive;
|
||||||
|
private camera:Camera;
|
||||||
|
private shader:Shader;
|
||||||
|
private texture:Texture;
|
||||||
|
|
||||||
|
init() {
|
||||||
|
this.quad = primitiveCreate();
|
||||||
|
quadInit(this.quad, 0,
|
||||||
|
-1, -1, 0, 0,
|
||||||
|
1, 1, 1, 1
|
||||||
|
);
|
||||||
|
|
||||||
|
this.shader = shaderCreate();
|
||||||
|
assetShaderLoad(this.shader,
|
||||||
|
"shaders/textured.vert",
|
||||||
|
"shaders/textured.frag"
|
||||||
|
);
|
||||||
|
|
||||||
|
this.camera = cameraCreate();
|
||||||
|
cameraLookAt(this.camera, 3,3,3, 0,0,0);
|
||||||
|
cameraPerspective(this.camera, 45, 16/9, 0.01, 1000);
|
||||||
|
|
||||||
|
this.texture = textureCreate();
|
||||||
|
assetTextureLoad(this.texture, "test_texture.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
update() {
|
||||||
|
shaderUse(this.shader);
|
||||||
|
shaderUseCamera(this.shader, this.camera);
|
||||||
|
shaderUsePosition(this.shader, 0,0,0, 0,this.game.time.current,0);
|
||||||
|
primitiveDraw(this.quad, 0, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
dispose() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class MainGame extends Game {
|
class MainGame extends Game {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this.setScene(new TestScene(this));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gameSetMain(new MainGame());
|
gameSetMain(new MainGame());
|
13
ts/scene/Scene.ts
Normal file
13
ts/scene/Scene.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { Game } from "../game/Game";
|
||||||
|
|
||||||
|
export abstract class Scene {
|
||||||
|
public readonly game:Game;
|
||||||
|
|
||||||
|
constructor(game:Game) {
|
||||||
|
this.game = game;
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract init():void;
|
||||||
|
abstract update():void;
|
||||||
|
abstract dispose():void;
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es3",
|
"target": "ES5",
|
||||||
"noImplicitAny": true,
|
"noImplicitAny": true,
|
||||||
"removeComments": true,
|
"removeComments": true,
|
||||||
"preserveConstEnums": true,
|
"preserveConstEnums": true,
|
||||||
|
Reference in New Issue
Block a user