GithubHelp home page GithubHelp logo

box2d-core on the server side about box2d.ts HOT 13 CLOSED

lusito avatar lusito commented on July 30, 2024
box2d-core on the server side

from box2d.ts.

Comments (13)

Lusito avatar Lusito commented on July 30, 2024 1

Ah, I'm sorry. I forgot, that one timer gets created on top-level. Try this instead:

Create a file "fixPerformance.js" (name it whatever you like) with the 2 code lines above, then import that file before you import @box2d/core.

from box2d.ts.

Lusito avatar Lusito commented on July 30, 2024

You can check how the CLI benchmark does it: https://github.com/Lusito/box2d.ts/blob/master/packages/benchmark/src/cli/index.ts

import { performance } from "perf_hooks";

global.performance = performance as any;

from box2d.ts.

8Observer8 avatar 8Observer8 commented on July 30, 2024

Sorry, I don't understand what should I change to fix it. I use JavaScript instead of TypeScript.

from box2d.ts.

Lusito avatar Lusito commented on July 30, 2024

Somewhere in your server-side code, add the import and the global.performance assignment. Just make sure, the assignment happens before you work with box2d.

JavaScript version:

import { performance } from "perf_hooks";

global.performance = performance;

from box2d.ts.

8Observer8 avatar 8Observer8 commented on July 30, 2024
import { performance } from "perf_hooks";
global.performance = performance;
import { b2World } from "@box2d/core";

const world = b2World.Create({ x: 0, y: -9.8 });
console.log("ok");
E:\_Projects\Physics\box2d-core\server-side-box2dcore-webgl-js>node src/server/app.js
E:\_Projects\node_modules\@box2d\core\dist\common\b2_timer.js:27
        this.m_start = performance.now();
                       ^

ReferenceError: performance is not defined
    at new b2Timer (E:\_Projects\node_modules\�[4m@box2d�[24m\core\dist\common\b2_timer.js:27:24)
    at Object.<anonymous> (E:\_Projects\node_modules\�[4m@box2d�[24m\core\dist\collision\b2_time_of_impact.js:230:32)
�[90m    at Module._compile (internal/modules/cjs/loader.js:1072:14)�[39m
�[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)�[39m
�[90m    at Module.load (internal/modules/cjs/loader.js:937:32)�[39m
�[90m    at Function.Module._load (internal/modules/cjs/loader.js:778:12)�[39m
�[90m    at Module.require (internal/modules/cjs/loader.js:961:19)�[39m
�[90m    at require (internal/modules/cjs/helpers.js:92:18)�[39m
    at Object.<anonymous> (E:\_Projects\node_modules\�[4m@box2d�[24m\core\dist\index.js:46:14)
�[90m    at Module._compile (internal/modules/cjs/loader.js:1072:14)�[39m

from box2d.ts.

8Observer8 avatar 8Observer8 commented on July 30, 2024

Thank you very much!

fix-performance.js

import { performance } from "perf_hooks";
global.performance = performance;

app.js

import "./fix-performance.js"
import { b2World } from "@box2d/core";

const world = b2World.Create({ x: 0, y: -9.8 });
console.log(`gravity = ${world.GetGravity().y}`);

Output: gravity = -9.8

from box2d.ts.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.