geckosio / phaser-on-nodejs

Allows you to run Phaser 3 game (including Phaser's physics engines) on Node.js
MIT License
102 stars 11 forks source link

Cannot spawn more than one thread #10

Closed hatala91 closed 3 years ago

hatala91 commented 3 years ago

Description I am using phaser-on-nodejs for implementing an authoritative server instance of a multiplayer online game. There might be multiple games in parallel, which is why I need multiple instances of the server and I was hoping to solve this with multithreading.

How to reproduce Assuing I have a working phaser-on-nodejs game working with an entry script called game.js, I spawn the server side code using something like:

import { Worker } from "worker_threads";
const gameProcess = new Worker(`game.js`, {
  workerData: gameParameters,
});

With the first thread this works fine, however on spawning a second thread I get:

Error: Module did not self-register: '/Users/sebastianhatala/dev/realtime-multiplayer-pong-backend/node_modules/canvas/build/Release/canvas.node'.
Process exited with exit code 1
yandeu commented 3 years ago

Looks like the error has something to do with node-canvas. Have you already check the node-canvas repo?

Maybe this helps: https://github.com/Automattic/node-canvas/issues/1718

hatala91 commented 3 years ago

Thanks for looking into this, turns out that the causing issue is indeed node-canvas but another issue: https://github.com/Automattic/node-canvas/issues/1394

Closing this, though of course a canvas independent implementation would be amazing - maybe with Phaser 4.

yandeu commented 3 years ago

👍🏻


Btw, I was experimenting with a Standalone Arcade Physics lib. Maybe it helps https://github.com/yandeu/arcade-physics_dev

hatala91 commented 3 years ago

Yes! Appreciate this so much since there seems to be no great standalone Node.JS physics engine out there (P2 and Matter.js seem abandoned) others are really small and barely used 🤔

yandeu commented 3 years ago

No, matter.js is not abandoned. It's my favorite 2d physics engine.

hatala91 commented 3 years ago

Okay, glad to hear that too! I had read that somewhere (cannot have been a credible source though) and the open issues/ PRs did not directly contradict it. But we are way off topic here now anyway 😉