Needle Engine

Changes between version 3.12.0-beta.1 and 3.12.1-beta
Files changed (4) hide show
  1. plugins/next/next.js +3 -1
  2. src/engine/engine_networking_utils.ts +4 -3
  3. src/engine/engine_physics_rapier.ts +11 -2
  4. src/engine/engine_typestore.ts +19 -11
plugins/next/next.js CHANGED
@@ -38,7 +38,9 @@
38
38
  /** @param {import ('next').NextConfig config } */
39
39
  function nextWebPack(config, { buildId, dev, isServer, defaultLoaders, webpack }) {
40
40
  const meta = getMeta();
41
- let useRapier = userSettings?.useRapier ?? meta?.useRapier === false ?? true;
41
+ let useRapier = true;
42
+ if (userSettings.useRapier === false) useRapier = false;
43
+ else if (meta.useRapier === false) useRapier = false;
42
44
  // add defines
43
45
  const webpackModule = userSettings.modules?.webpack;
44
46
  const definePlugin = webpackModule && new webpackModule.DefinePlugin({
src/engine/engine_networking_utils.ts CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  export function isLocalNetwork(hostname = globalThis.location?.hostname) {
7
7
  if (localNetworkResults.has(hostname)) return localNetworkResults.get(hostname)!;
8
- const isLocalNetwork = new RegExp("([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\:[0-9]{1,5})|localhost").test(hostname);
8
+ const isLocalNetwork = /(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})|localhost/.test(hostname);
9
9
  localNetworkResults.set(hostname, isLocalNetwork);
10
10
  if (isLocalNetwork === true) return true;
11
11
  return false;
@@ -16,8 +16,9 @@
16
16
  }
17
17
 
18
18
  // const testUrls = [
19
- // "https://192.254.384.122:3000/",
20
- // "https://my-glitch-page.glitch.me/",
19
+ // "192.254.384.122",
20
+ // "my-glitch-page.glitch.me",
21
+ // "a4d35231.my-url.dev"
21
22
  // ]
22
23
  // for (let url of testUrls)
23
24
  // console.log("Testing url: " + url, isLocalNetwork(url));
src/engine/engine_physics_rapier.ts CHANGED
@@ -211,10 +211,12 @@
211
211
  }
212
212
 
213
213
  private async internalInitialization() {
214
+ if(debugPhysics) console.log("Initialize rapier physics engine");
214
215
  // NEEDLE_PHYSICS_INIT_START
215
216
  // use .env file with VITE_NEEDLE_USE_RAPIER=false to treeshake rapier
216
217
  // @ts-ignore
217
218
  if ("env" in import.meta && import.meta.env.VITE_NEEDLE_USE_RAPIER === "false") {
219
+ if (debugPhysics) console.log("Rapier disabled");
218
220
  return false;
219
221
  }
220
222
  // Can be transformed during build time to disable rapier
@@ -225,7 +227,9 @@
225
227
  }
226
228
  this._hasCreatedWorld = true;
227
229
  if (RAPIER === undefined) {
230
+ if (debugPhysics) console.log("Import Rapier");
228
231
  RAPIER = await import("@dimforge/rapier3d-compat");
232
+ if (debugPhysics) console.log("Init Rapier");
229
233
  await RAPIER.init()
230
234
  }
231
235
  if (debugPhysics) console.log("Physics engine initialized, creating world...");
@@ -240,8 +244,13 @@
240
244
  /** Check is the physics engine has been initialized and the call can be made */
241
245
  private validate() {
242
246
  if (!this._isInitialized) {
243
- if (debugPhysics)
244
- console.warn("Physics engine is not initialized");
247
+ if (debugPhysics) {
248
+ this["_lastWarnTime"] = this["_lastWarnTime"] ?? 0;
249
+ if (Date.now() - this["_lastWarnTime"] > 1000) {
250
+ this["_lastWarnTime"] = Date.now();
251
+ console.warn("Physics engine is not initialized");
252
+ }
253
+ }
245
254
  }
246
255
  }
247
256
 
src/engine/engine_typestore.ts CHANGED
@@ -1,28 +1,36 @@
1
+ import { getParam } from "./engine_utils.js";
1
2
 
2
- class _TypeStore {
3
+ const debug = getParam("debugtypes");
3
4
 
4
- private _types = {};
5
+ /**
6
+ * global types
7
+ */
8
+ const _types = globalThis["__NEEDLE_ENGINE_TYPES"] = globalThis["__NEEDLE_ENGINE_TYPES"] || {};
5
9
 
6
- public add(key, type) {
7
- const existing = this._types[key];
10
+ export class TypeStore {
11
+
12
+ public static add(key, type) {
13
+ if (debug) console.warn("ADD TYPE", key);
14
+ const existing = _types[key];
8
15
  if (existing === undefined)
9
- this._types[key] = type;
16
+ _types[key] = type;
10
17
  else {
11
- if (existing !== type)
12
- console.warn("Type name exists multiple times in your project and may lead to runtime errors:", key)
18
+ if (debug) {
19
+ if (existing !== type) {
20
+ console.warn("Type name exists multiple times in your project and may lead to runtime errors:", key)
21
+ }
22
+ }
13
23
  }
14
24
  }
15
25
 
16
- public get(key) {
17
- return this._types[key];
26
+ public static get(key) {
27
+ return _types[key];
18
28
  }
19
29
  }
20
30
 
21
31
  export const $BuiltInTypeFlag = Symbol("BuiltInType");
22
32
 
23
- export const TypeStore = new _TypeStore();
24
33
 
25
-
26
34
  /**
27
35
  * add to a class declaration to automatically register it to the TypeStore (required for HMR right now)
28
36
  *