If I want to make a fast paced multiplayer FPS game with babylon.js, what is the best non TypeScript based framework for making it multiplayer?
I still think WebRTC is the best option.
Iām going to write a solution for this
NodeJS with the cluster system may be fine. No typescript.
Exemple de serveur Node Cluster :
class Serveur
{
constructor(host = "localhost", portIO = 8080, postRedis = 6379)
{
this.cluster = require('cluster');
this.redis = require('socket.io-redis');
this.socketIO = require('socket.io');
this.http = require('http');
this.os = require('os');
const express = require('express');
this.app = express();
this.ent = require('ent');
this.host = host;
this.portIO = portIO;
this.postRedis = postRedis;
}
createServeur()
{
if (this.cluster.isMaster)
{
this.http.globalAgent.maxSockets = Infinity;
const numberOfCPUs = this.os.cpus().length;
const ioMaster = this.socketIO.listen(this.http.createServer());
ioMaster.adapter(this.redis({ host: this.host, port: this.postRedis }));
for (let i = 0; i < numberOfCPUs; i++) {
this.cluster.fork();
}
this.cluster.on('fork', function(worker) {
console.log('Worker '+worker.process.pid+' created');
});
this.cluster.on('disconnect', function(worker) {
console.log('Worker '+worker.process.pid+' disconected');
});
this.cluster.on('exit', (worker, code, signal) => {
console.error('Worker '+worker.process.pid+' death '+ signal || code+'');
if (!worker.suicide) {
this.cluster.fork();
console.log('New worker '+worker.id+' created');
}
});
} else if (this.cluster.isWorker) {
let that = this;
const port = process.env.PORT || this.portIO;
const serverWorker = this.http.createServer(this.app).listen(port);
const ioWorker = this.socketIO.listen(serverWorker);
ioWorker.adapter(this.redis({ host: this.host, port: this.postRedis}));
this.app.get('/', function (req, res) {
res.emitfile(__dirname + '/index.php');
});
ioWorker.sockets.on('connection', that.onConnection.bind(this));
}
}
onConnection(socket)
{
socket.on('new_user', (pseudo) => {
socket.pseudo = this.ent.encode(pseudo);
socket.broadcast.emit('new_user', socket.pseudo);
});
socket.on('exit_user', function() {
if (socket.room) {
socket.to(socket.room).broadcast.emit('exit_user', socket.pseudo);
} else {
socket.broadcast.emit('exit_user', socket.pseudo);
}
socket.close();
});
socket.on('new_actor', function(data)> {
if (socket.room) {
socket.to(socket.room).broadcast.emit('new_actor', data);
} else {
socket.broadcast.emit('new_actor', data);
}
});
}
}
var serveur = new Serveur("localhost", 8080, 6379);
serveur.createServeur();
1 Like