Skip to content

Commit

Permalink
chore(core): Move init.ts into luma.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ibgreen committed Apr 28, 2024
1 parent 9163836 commit b79b5bf
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 60 deletions.
3 changes: 0 additions & 3 deletions modules/core/src/adapter/device.ts
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

import {VERSION} from '../init';
import {StatsManager, lumaStats} from '../utils/stats-manager';
import {log} from '../utils/log';
import {uid} from '../utils/uid';
Expand Down Expand Up @@ -294,8 +293,6 @@ export abstract class Device {
return 'Device';
}

static VERSION = VERSION;

constructor(props: DeviceProps) {
this.props = {...Device.defaultProps, ...props};
this.id = this.props.id || uid(this[Symbol.toStringTag].toLowerCase());
Expand Down
37 changes: 36 additions & 1 deletion modules/core/src/adapter/luma.ts
Expand Up @@ -9,6 +9,13 @@ import {StatsManager} from '../utils/stats-manager';
import {lumaStats} from '../utils/stats-manager';
import {log} from '../utils/log';

declare global {
// eslint-disable-next-line no-var
var luma: Luma;
}

const STARTUP_MESSAGE = 'set luma.log.level=1 (or higher) to trace rendering';

const ERROR_MESSAGE =
'No matching device found. Ensure `@luma.gl/webgl` and/or `@luma.gl/webgpu` modules are imported.';

Expand Down Expand Up @@ -43,11 +50,39 @@ export class Luma {
/** Global stats for all devices */
readonly stats: StatsManager = lumaStats;

/** Global log */
/**
* Global log
*
* Assign luma.log.level in console to control logging: \
* 0: none, 1: minimal, 2: verbose, 3: attribute/uniforms, 4: gl logs
* luma.log.break[], set to gl funcs, luma.log.profile[] set to model names`;
*/
readonly log: Log = log;

/** Version of luma.gl */
readonly VERSION: string =
// Version detection using build plugin
// @ts-expect-error no-undef
typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'running from source';

protected deviceMap = new Map<string, DeviceFactory>();

constructor() {
if (globalThis.luma) {
if (globalThis.luma.VERSION !== this.VERSION) {
log.error(`Found luma.gl ${globalThis.luma.VERSION} while initialzing ${this.VERSION}`)();
log.error(`'yarn why @luma.gl/core' can help identify the source of the conflict`)();
throw new Error(`luma.gl - multiple versions detected: see console log`);
}

log.error('This version of luma.gl has already been initialized')();
}

log.log(1, `${this.VERSION} - ${STARTUP_MESSAGE}`)();

globalThis.luma = this;
}

registerDevices(deviceClasses: DeviceFactory[]): void {
for (const deviceClass of deviceClasses) {
this.deviceMap.set(deviceClass.type, deviceClass);
Expand Down
2 changes: 0 additions & 2 deletions modules/core/src/index.ts
Expand Up @@ -2,8 +2,6 @@
// SPDX-License-Identifier: MIT
// Copyright (c) vis.gl contributors

export {VERSION} from './init';

// MAIN API ACCESS POINT
export {luma} from './adapter/luma';

Expand Down
53 changes: 0 additions & 53 deletions modules/core/src/init.ts

This file was deleted.

2 changes: 1 addition & 1 deletion modules/webgl/src/context/debug/spector.ts
Expand Up @@ -52,7 +52,7 @@ export function initializeSpectorJS(props?: SpectorProps) {
log.probe(LOG_LEVEL, 'SPECTOR found and initialized')();
spector = new globalThis.SPECTOR.Spector();
if (globalThis.luma) {
globalThis.luma.spector = spector;
(globalThis.luma as any).spector = spector;
}
}

Expand Down

0 comments on commit b79b5bf

Please sign in to comment.