Skip to content

Commit

Permalink
fix all API's
Browse files Browse the repository at this point in the history
  • Loading branch information
gonpombo8 committed May 14, 2024
1 parent 987cf20 commit 811145c
Show file tree
Hide file tree
Showing 7 changed files with 331 additions and 234 deletions.
16 changes: 15 additions & 1 deletion scene-lod-entities-manifest-builder/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion scene-lod-entities-manifest-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@well-known-components/fetch-component": "^2.0.2",
"@well-known-components/http-server": "^2.0.0",
"@well-known-components/interfaces": "^1.4.2",
"protobufjs": "^7.2.5"
"protobufjs": "^7.2.5",
"source-map": "^0.7.4"
}
}
20 changes: 15 additions & 5 deletions scene-lod-entities-manifest-builder/src/adapters/scene.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { customEvalSdk7 } from '../logic/scene-runtime/sandbox'
import { createModuleRuntime } from '../logic/scene-runtime/sdk7-runtime'
import { setTimeout } from 'timers/promises'
import { initSourcemap } from '../logic/sourcemap'

export const FRAMES_TO_RUN = 90
export let framesCount = 1


export type ISceneComponent = {
start(hash: string, sourceCode: string): Promise<void>
}
Expand All @@ -17,20 +17,30 @@ export async function createSceneComponent(): Promise<ISceneComponent> {
async function start(hash: string, sourceCode: string) {
abortController = new AbortController()
loaded = true

const runtimeExecutionContext = Object.create(null)
const sceneModule = createModuleRuntime(runtimeExecutionContext)
try {
await customEvalSdk7(sourceCode, runtimeExecutionContext)

// This only works for scenes that has the sourcemap uploaded inside the .js file or local scenes.
const sourceMap = await initSourcemap(sourceCode, true)
//30 FPS
const updateIntervalMs: number = 33.33

await sceneModule.runStart()
try {
await sceneModule.runStart()
} catch (e: any) {
console.log('[Start failed]: ', sourceMap.parseError(e))
}

// start event loop
if (sceneModule.exports.onUpdate) {
// first update always use 0.0 as delta time
await sceneModule.runUpdate(0.0)
try {
await sceneModule.runUpdate(0.0)
} catch (e: any) {
console.log('[Update failed]: ', sourceMap.parseError(e))
}
let start = performance.now()

while (framesCount < FRAMES_TO_RUN) {
Expand Down Expand Up @@ -62,6 +72,6 @@ export async function createSceneComponent(): Promise<ISceneComponent> {
}

return {
start,
start
}
}
Loading

0 comments on commit 811145c

Please sign in to comment.