Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Commit

Permalink
feat: remote debugger (#1404)
Browse files Browse the repository at this point in the history
* initial changes to make it debuggable

* production mode minifies the final file

* add checks to build real scenes and libraries

* a bit more readable makefile

* move terser to dev dependencies

* rename ulla -> dcl

* fix build

* checkpoint;

* import only types when possible

* rename shell to runtime

Co-authored-by: Nicolas Chamo <[email protected]>
  • Loading branch information
menduz and nchamo authored Oct 14, 2020
1 parent ce467f8 commit d120cc4
Show file tree
Hide file tree
Showing 10 changed files with 743 additions and 656 deletions.
3 changes: 2 additions & 1 deletion kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ DECENTRALAND_ECS_COMPILED_FILES := packages/decentraland-ecs/dist/src/index.js

DECENTRALAND_ECS_TYPEDEF_FILE := packages/decentraland-ecs/types/dcl/index.d.ts

SCENE_SYSTEM_SOURCES := $(wildcard static/systems/**/*.ts)
SCENE_SYSTEM := static/systems/scene.system.js
DECENTRALAND_LOADER := static/loader/lifecycle/worker.js
GIF_PROCESSOR := static/gif-processor/worker.js
Expand Down Expand Up @@ -51,7 +52,7 @@ static/voice-chat-codec/worker.js: packages/voice-chat-codec/*.ts
static/default-profile/contents:
@node ./static/default-profile/download_all.js

static/systems/scene.system.js: $(DECENTRALAND_ECS_TYPEDEF_FILE) packages/scene-system/scene.system.ts
static/systems/scene.system.js: $(DECENTRALAND_ECS_TYPEDEF_FILE) $(SCENE_SYSTEM_SOURCES) packages/scene-system/scene.system.ts
@$(COMPILER) targets/engine/scene-system.json

static/systems/decentraland-ui.scene.js: $(SCENE_SYSTEM) packages/ui/tsconfig.json packages/ui/decentraland-ui.scene.ts
Expand Down
9 changes: 3 additions & 6 deletions kernel/packages/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { contracts as contractInfo } from './contracts'
const queryString = require('query-string')
declare var window: any

export const performanceConfigurations = [
{ antialiasing: true, downsampling: 0, shadows: true },
Expand Down Expand Up @@ -212,11 +211,9 @@ let network: ETHEREUM_NETWORK | null = null

export function getTLD() {
if (ENV_OVERRIDE) {
return window.location.search.match(/ENV=(\w+)/)[1]
}
if (window) {
return window.location.hostname.match(/(\w+)$/)[0]
return location.search.match(/ENV=(\w+)/)![1]
}
return location.hostname.match(/(\w+)$/)![0]
}

export const knownTLDs = ['zone', 'org', 'today']
Expand All @@ -240,7 +237,7 @@ export function getDefaultTLD() {
}

export function getExclusiveServer() {
const url = new URL(window.location)
const url = new URL(location.toString())
if (url.searchParams.has('TEST_WEARABLES')) {
const value = url.searchParams.get('TEST_WEARABLES')
if (value) {
Expand Down
2 changes: 1 addition & 1 deletion kernel/packages/decentraland-ecs/types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@
"."
]
}
}
}
10 changes: 8 additions & 2 deletions kernel/packages/entryPoints/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ if (!container) throw new Error('cannot find element #gameContainer')

const defaultScene: IFuture<ILand> = future()

let wsScene: string | undefined = undefined

if (location.search.indexOf("WS_SCENE") !== -1) {
wsScene = `${location.protocol === 'https:' ? 'wss' : 'ws'}://${document.location.host}/?scene`
}

function startPreviewWatcher() {
// this is set to avoid double loading scenes due queued messages
let isSceneLoading: boolean = true

const loadScene = () => {
loadPreviewScene()
isSceneLoading = true
loadPreviewScene(wsScene)
.then((scene) => {
isSceneLoading = false
defaultScene.resolve(scene)
Expand All @@ -57,7 +64,6 @@ function startPreviewWatcher() {
return
}

isSceneLoading = true
loadScene()
}
}
Expand Down
45 changes: 45 additions & 0 deletions kernel/packages/scene-system/cli.scene.system.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { WebWorkerTransport } from 'decentraland-rpc'
import { SceneRuntime } from './sdk/SceneRuntime'
import type { IWorker } from 'decentraland-rpc/lib/common/transports/WebWorker'

/**
* This file starts the scene in a Node.js context.
* The runtime ends up mocking the WebWorker environment
* (postMessage,addEventListener,fetch, WebSocket) for fidelity.
*/

export interface VMEnvironment extends IWorker {
global: VMEnvironment
__env__onTick(cb: (dt: number) => void): void
__env__error(error: Error): void
__env__log(...args: any[]): void
runCode(filename: string): Promise<void>
}

const globalObject: VMEnvironment = globalThis as any

if (!('global' in globalObject)) {
;(globalObject as any).global = globalObject
}

class CliScene extends SceneRuntime {
onError(error: Error): void {
globalObject.__env__error(error)
}

onLog(...messages: any[]): void {
globalObject.__env__log(...messages)
}

async runCode(location: string, env: any): Promise<void> {
Object.assign(globalObject, env)
return globalObject.runCode(location)
}

startLoop(): void {
globalObject.__env__onTick((dt) => this.update(dt))
}
}

// tslint:disable-next-line
new CliScene(WebWorkerTransport(globalObject))
Loading

0 comments on commit d120cc4

Please sign in to comment.