Fix some script bugs
This commit is contained in:
+13
-13
@@ -1,8 +1,8 @@
|
|||||||
var scene = {};
|
var scene = {};
|
||||||
|
|
||||||
// var assets = AssetBatch([
|
var assets = AssetBatch([
|
||||||
// { path: 'test.png', type: Asset.TYPE_TEXTURE, format: Texture.FORMAT_RGBA }
|
{ path: 'test.png', type: Asset.TYPE_TEXTURE, format: Texture.FORMAT_RGBA }
|
||||||
// ]);
|
]);
|
||||||
|
|
||||||
var cam;
|
var cam;
|
||||||
var camPos;
|
var camPos;
|
||||||
@@ -11,12 +11,12 @@ var testPos;
|
|||||||
var testRenderable;
|
var testRenderable;
|
||||||
var texEntry;
|
var texEntry;
|
||||||
|
|
||||||
scene.init = function() {
|
scene.init = async function() {
|
||||||
// assets.lock();
|
assets.lock();
|
||||||
// await assets.loaded();
|
await assets.loaded();
|
||||||
|
|
||||||
Console.print('Scene Init');
|
Console.print('Scene Init');
|
||||||
// texEntry = assets.entry(0);
|
texEntry = assets.entry(0);
|
||||||
|
|
||||||
// Camera at (3, 3, 3) looking at origin
|
// Camera at (3, 3, 3) looking at origin
|
||||||
cam = Entity.create();
|
cam = Entity.create();
|
||||||
@@ -30,11 +30,11 @@ scene.init = function() {
|
|||||||
testPos = testEntity.add(Component.POSITION);
|
testPos = testEntity.add(Component.POSITION);
|
||||||
testRenderable = testEntity.add(Component.RENDERABLE);
|
testRenderable = testEntity.add(Component.RENDERABLE);
|
||||||
|
|
||||||
// testRenderable.texture = texEntry.texture;
|
testRenderable.texture = texEntry.texture;
|
||||||
// testRenderable.type = Renderable.SPRITEBATCH;
|
testRenderable.type = Renderable.SPRITEBATCH;
|
||||||
// testRenderable.sprites = [
|
testRenderable.sprites = [
|
||||||
// [0, 0, 1, 1, 0, 1, 1, 0]
|
[0, 0, 1, 1, 0, 1, 1, 0]
|
||||||
// ];
|
];
|
||||||
// testPos.localPosition = new Vec3(0, 0, 0);
|
// testPos.localPosition = new Vec3(0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ scene.dispose = function() {
|
|||||||
Console.print('Scene Dispose');
|
Console.print('Scene Dispose');
|
||||||
Entity.dispose(cam);
|
Entity.dispose(cam);
|
||||||
Entity.dispose(testEntity);
|
Entity.dispose(testEntity);
|
||||||
// assets.unlock();
|
assets.unlock();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = scene;
|
module.exports = scene;
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ moduleBaseFunction(moduleAssetBatchLock) {
|
|||||||
moduleBaseFunction(moduleAssetBatchUnlock) {
|
moduleBaseFunction(moduleAssetBatchUnlock) {
|
||||||
jsassetbatch_t *b = moduleAssetBatchSelf(callInfo);
|
jsassetbatch_t *b = moduleAssetBatchSelf(callInfo);
|
||||||
if(!b || !b->batch) return jerry_undefined();
|
if(!b || !b->batch) return jerry_undefined();
|
||||||
|
assetBatchUnlock(b->batch);
|
||||||
assetBatchDispose(b->batch);
|
assetBatchDispose(b->batch);
|
||||||
memoryFree(b->batch);
|
memoryFree(b->batch);
|
||||||
b->batch = NULL;
|
b->batch = NULL;
|
||||||
|
|||||||
@@ -128,6 +128,12 @@ errorret_t scriptDispose(void) {
|
|||||||
"All script assets should be disposed by now."
|
"All script assets should be disposed by now."
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Script modules are now freed, so any JS objects that were only reachable
|
||||||
|
// through module-scope globals (texEntry, renderable._tex, etc.) are now
|
||||||
|
// orphaned. A GC pass here fires their finalizers and releases asset entry
|
||||||
|
// locks before assetDispose() checks ref counts.
|
||||||
|
jerry_heap_gc(JERRY_GC_PRESSURE_HIGH);
|
||||||
|
|
||||||
moduleListDispose();
|
moduleListDispose();
|
||||||
jerry_cleanup();
|
jerry_cleanup();
|
||||||
SCRIPT.initialized = false;
|
SCRIPT.initialized = false;
|
||||||
|
|||||||
Vendored
+6
-1
@@ -31,7 +31,12 @@ interface AssetBatch {
|
|||||||
/** `true` if any entry is in an `ERROR` state. */
|
/** `true` if any entry is in an `ERROR` state. */
|
||||||
readonly hasError: boolean;
|
readonly hasError: boolean;
|
||||||
/**
|
/**
|
||||||
* Blocks until every entry is loaded.
|
* Returns a Promise that resolves when all entries have loaded, or rejects
|
||||||
|
* if any entry errors. Use with `await`.
|
||||||
|
*/
|
||||||
|
loaded(): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Blocks (spin-waits) until every entry is loaded.
|
||||||
* Returns `this` for chaining.
|
* Returns `this` for chaining.
|
||||||
* @throws If any entry fails to load.
|
* @throws If any entry fails to load.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Vendored
+6
-1
@@ -33,7 +33,12 @@ interface AssetEntry {
|
|||||||
/** Event proxy — subscribe up to 4 callbacks for when loading fails. */
|
/** Event proxy — subscribe up to 4 callbacks for when loading fails. */
|
||||||
readonly onError: AssetEventProxy;
|
readonly onError: AssetEventProxy;
|
||||||
/**
|
/**
|
||||||
* Blocks until the entry reaches `LOADED` (or `ERROR`).
|
* Returns a Promise that resolves when the entry is loaded, or rejects on
|
||||||
|
* error. Use with `await`.
|
||||||
|
*/
|
||||||
|
loaded(): Promise<void>;
|
||||||
|
/**
|
||||||
|
* Blocks (spin-waits) until the entry reaches `LOADED` (or `ERROR`).
|
||||||
* Returns `this` for chaining.
|
* Returns `this` for chaining.
|
||||||
* @throws If the load fails.
|
* @throws If the load fails.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Vendored
+23
@@ -0,0 +1,23 @@
|
|||||||
|
/**
|
||||||
|
* Copyright (c) 2026 Dominic Masters
|
||||||
|
*
|
||||||
|
* This software is released under the MIT License.
|
||||||
|
* https://opensource.org/licenses/MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An event proxy with up to 4 subscribable callback slots (indices 0–3).
|
||||||
|
* Assign a function to subscribe; assign `null` to unsubscribe.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* assets.onLoaded[0] = () => { Console.print('all loaded'); };
|
||||||
|
* assets.onLoaded[0] = null; // unsubscribe
|
||||||
|
*/
|
||||||
|
interface AssetEventProxy {
|
||||||
|
0: (() => void) | null;
|
||||||
|
1: (() => void) | null;
|
||||||
|
2: (() => void) | null;
|
||||||
|
3: (() => void) | null;
|
||||||
|
/** Number of available slots (always 4). */
|
||||||
|
readonly length: number;
|
||||||
|
}
|
||||||
Vendored
+4
-12
@@ -19,19 +19,11 @@ interface Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface ComponentConstructor {
|
interface ComponentConstructor {
|
||||||
/** Sentinel for an invalid component ID. */
|
readonly POSITION: number;
|
||||||
readonly INVALID: number;
|
readonly CAMERA: number;
|
||||||
|
|
||||||
readonly POSITION: number;
|
|
||||||
readonly CAMERA: number;
|
|
||||||
readonly RENDERABLE: number;
|
readonly RENDERABLE: number;
|
||||||
readonly PHYSICS: number;
|
readonly PHYSICS: number;
|
||||||
readonly TRIGGER: number;
|
readonly TRIGGER: number;
|
||||||
readonly OVERWORLD: number;
|
|
||||||
readonly PLAYER: number;
|
|
||||||
readonly INTERACTABLE: number;
|
|
||||||
readonly OVERWORLD_CAMERA: number;
|
|
||||||
readonly OVERWORLD_TRIGGER: number;
|
|
||||||
|
|
||||||
new(): never;
|
new(): never;
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
+1
-5
@@ -26,6 +26,7 @@
|
|||||||
/// <reference path="./display/texture.d.ts" />
|
/// <reference path="./display/texture.d.ts" />
|
||||||
|
|
||||||
// asset
|
// asset
|
||||||
|
/// <reference path="./asset/asseteventproxy.d.ts" />
|
||||||
/// <reference path="./asset/assetentry.d.ts" />
|
/// <reference path="./asset/assetentry.d.ts" />
|
||||||
/// <reference path="./asset/assetbatch.d.ts" />
|
/// <reference path="./asset/assetbatch.d.ts" />
|
||||||
/// <reference path="./asset/asset.d.ts" />
|
/// <reference path="./asset/asset.d.ts" />
|
||||||
@@ -41,12 +42,7 @@
|
|||||||
// entity / components
|
// entity / components
|
||||||
/// <reference path="./entity/component.d.ts" />
|
/// <reference path="./entity/component.d.ts" />
|
||||||
/// <reference path="./entity/component/camera.d.ts" />
|
/// <reference path="./entity/component/camera.d.ts" />
|
||||||
/// <reference path="./entity/component/interactable.d.ts" />
|
|
||||||
/// <reference path="./entity/component/overworld.d.ts" />
|
|
||||||
/// <reference path="./entity/component/overworldcamera.d.ts" />
|
|
||||||
/// <reference path="./entity/component/overworldtrigger.d.ts" />
|
|
||||||
/// <reference path="./entity/component/physics.d.ts" />
|
/// <reference path="./entity/component/physics.d.ts" />
|
||||||
/// <reference path="./entity/component/player.d.ts" />
|
|
||||||
/// <reference path="./entity/component/position.d.ts" />
|
/// <reference path="./entity/component/position.d.ts" />
|
||||||
/// <reference path="./entity/component/renderable.d.ts" />
|
/// <reference path="./entity/component/renderable.d.ts" />
|
||||||
/// <reference path="./entity/component/trigger.d.ts" />
|
/// <reference path="./entity/component/trigger.d.ts" />
|
||||||
|
|||||||
Reference in New Issue
Block a user