Require async
This commit is contained in:
+6
-19
@@ -10,24 +10,11 @@ const platformNames = {
|
||||
|
||||
Console.print('Platform: ' + (platformNames[System.platform] || 'Unknown'));
|
||||
|
||||
// Testing async/await
|
||||
async function testAsync() {
|
||||
Console.print('Testing async/await...');
|
||||
await frame();
|
||||
Console.print('First await done!');
|
||||
await timeout(1000);
|
||||
Console.print('Async/await works!');
|
||||
async function testRequireAsync() {
|
||||
Console.print('Loading testscene.js...');
|
||||
const scene = await requireAsync('testscene.js');
|
||||
Console.print('Loaded!');
|
||||
Console.print(scene.test());
|
||||
}
|
||||
|
||||
testAsync();
|
||||
|
||||
// Scene.set('testscene.js');
|
||||
// Console.print('Loading scene...');
|
||||
// requireAsync('./testscene.js', function(scene) {
|
||||
// throw "test";
|
||||
// Console.print('Initializing scene...');
|
||||
// var batch = scene.load();
|
||||
// batch.lock();
|
||||
// batch.requireLoaded();
|
||||
// scene.init();
|
||||
// });
|
||||
testRequireAsync();
|
||||
+54
-46
@@ -1,50 +1,58 @@
|
||||
var scene = {
|
||||
'test': 'teststring'
|
||||
};
|
||||
Console.print('testscene.js is loaded');
|
||||
|
||||
var assets = AssetBatch([
|
||||
{ path: 'test.png', type: Asset.TYPE_TEXTURE, format: Texture.FORMAT_RGBA }
|
||||
]);
|
||||
|
||||
var cam;
|
||||
var camPos;
|
||||
var testEntity;
|
||||
var testPos;
|
||||
var testRenderable;
|
||||
var texEntry;
|
||||
|
||||
scene.init = function() {
|
||||
assets.lock();
|
||||
assets.onLoaded[0] = scene.loaded;
|
||||
};
|
||||
|
||||
scene.loaded = function() {
|
||||
texEntry = assets.entry(0);
|
||||
|
||||
// Camera at (3, 3, 3) looking at origin
|
||||
cam = Entity.create();
|
||||
camPos = cam.add(Component.POSITION);
|
||||
cam.add(Component.CAMERA);
|
||||
camPos.localPosition = new Vec3(3, 3, 3);
|
||||
camPos.lookAt(new Vec3(0, 0, 0));
|
||||
|
||||
// Test entity with textured quad at origin
|
||||
testEntity = Entity.create();
|
||||
testPos = testEntity.add(Component.POSITION);
|
||||
testRenderable = testEntity.add(Component.RENDERABLE);
|
||||
|
||||
testRenderable.texture = texEntry.texture;
|
||||
testRenderable.sprites = [
|
||||
[0, 0, 1, 1, 0, 1, 1, 0]
|
||||
];
|
||||
testPos.localPosition = new Vec3(0, 0, 0);
|
||||
module.exports = {
|
||||
test: function() {
|
||||
return 'Hello string';
|
||||
}
|
||||
}
|
||||
|
||||
scene.dispose = function() {
|
||||
Console.print('Scene Dispose');
|
||||
Entity.dispose(cam);
|
||||
Entity.dispose(testEntity);
|
||||
assets.unlock();
|
||||
};
|
||||
// var scene = {
|
||||
// 'test': 'teststring'
|
||||
// };
|
||||
|
||||
module.exports = scene;
|
||||
// var assets = AssetBatch([
|
||||
// { path: 'test.png', type: Asset.TYPE_TEXTURE, format: Texture.FORMAT_RGBA }
|
||||
// ]);
|
||||
|
||||
// var cam;
|
||||
// var camPos;
|
||||
// var testEntity;
|
||||
// var testPos;
|
||||
// var testRenderable;
|
||||
// var texEntry;
|
||||
|
||||
// scene.init = function() {
|
||||
// assets.lock();
|
||||
// assets.onLoaded[0] = scene.loaded;
|
||||
// };
|
||||
|
||||
// scene.loaded = function() {
|
||||
// texEntry = assets.entry(0);
|
||||
|
||||
// // Camera at (3, 3, 3) looking at origin
|
||||
// cam = Entity.create();
|
||||
// camPos = cam.add(Component.POSITION);
|
||||
// cam.add(Component.CAMERA);
|
||||
// camPos.localPosition = new Vec3(3, 3, 3);
|
||||
// camPos.lookAt(new Vec3(0, 0, 0));
|
||||
|
||||
// // Test entity with textured quad at origin
|
||||
// testEntity = Entity.create();
|
||||
// testPos = testEntity.add(Component.POSITION);
|
||||
// testRenderable = testEntity.add(Component.RENDERABLE);
|
||||
|
||||
// testRenderable.texture = texEntry.texture;
|
||||
// testRenderable.sprites = [
|
||||
// [0, 0, 1, 1, 0, 1, 1, 0]
|
||||
// ];
|
||||
// testPos.localPosition = new Vec3(0, 0, 0);
|
||||
// }
|
||||
|
||||
// scene.dispose = function() {
|
||||
// Console.print('Scene Dispose');
|
||||
// Entity.dispose(cam);
|
||||
// Entity.dispose(testEntity);
|
||||
// assets.unlock();
|
||||
// };
|
||||
|
||||
// module.exports = scene;
|
||||
|
||||
Reference in New Issue
Block a user