forked from tcecspectator/mytcecgui
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c9e644d
commit ee12ac1
Showing
9 changed files
with
639 additions
and
606 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,91 +1,63 @@ | ||
/* | ||
globals | ||
console, require, setInterval | ||
require, setInterval | ||
*/ | ||
'use strict'; | ||
|
||
const cluster = require('cluster'); | ||
const os = require('os'); | ||
const numServer = 1; | ||
const argv = require('yargs').argv; | ||
let {DefaultInt, LS} = require('./js/common.js'), | ||
cluster = require('cluster'), | ||
os = require('os'), | ||
argv = require('yargs').argv; | ||
|
||
if (argv.port == undefined) | ||
{ | ||
argv.port = 8000; | ||
portnum = 8000; | ||
} | ||
else | ||
{ | ||
portnum = argv.port; | ||
} | ||
|
||
if (argv.bonus != undefined) | ||
{ | ||
if (isNaN(argv.bonus)) | ||
{ | ||
bonus = 0; | ||
} | ||
else | ||
{ | ||
bonus = parseInt(argv.bonus); | ||
} | ||
} | ||
let // bonus = DefaultInt(argv.bonus, 0), | ||
numServer = 1, | ||
portnum = DefaultInt(argv.port, 8000); | ||
|
||
if (cluster.isMaster) | ||
{ | ||
const cpus = os.cpus().length; | ||
var count = 0; | ||
var clientCount = 0; | ||
for (let i = 0; i < numServer; i++) | ||
{ | ||
console.log(`Forking for ${cpus} CPUs`); | ||
var worker = cluster.fork(); | ||
count = 0; | ||
worker.on('message', function(msg) | ||
{ | ||
if (typeof msg.users != 'undefined') | ||
{ | ||
console.log ("CLUSTER: Count is :" + count + " ,got count:" + parseInt(msg.users) + ",clientCount:" + clientCount); | ||
count = parseInt(count) + parseInt(msg.users); | ||
clientCount ++; | ||
} | ||
}); | ||
} | ||
if (argv.port != undefined) | ||
argv.port = portnum; | ||
|
||
function eachWorker(callback) | ||
{ | ||
for (const id in cluster.workers) | ||
{ | ||
callback(cluster.workers[id]); | ||
} | ||
} | ||
|
||
const updateWorkers = () => { | ||
eachWorker(worker => { | ||
if (clientCount == numServer) | ||
{ | ||
worker.send({'count':count}); | ||
} | ||
}); | ||
count = 0; | ||
clientCount = 0; | ||
}; | ||
|
||
updateWorkers(); | ||
setInterval(updateWorkers, 10000); | ||
function eachWorker(callback) { | ||
for (let id in cluster.workers) | ||
callback(cluster.workers[id]); | ||
} | ||
|
||
cluster.on('exit', (worker, code, signal) => | ||
{ | ||
if (code !== 0 && !worker.exitedAfterDisconnect) | ||
{ | ||
console.log(`Worker ${worker.id} crashed. ` + | ||
'Starting a new worker...'); | ||
cluster.fork(); | ||
} | ||
}); | ||
if (cluster.isMaster) { | ||
let clientCount = 0, | ||
count = 0, | ||
cpus = os.cpus().length; | ||
|
||
for (let i = 0; i < numServer; i ++) { | ||
LS(`Forking for ${cpus} CPUs`); | ||
count = 0; | ||
let worker = cluster.fork(); | ||
|
||
worker.on('message', function(msg) { | ||
if (typeof msg.users != 'undefined') { | ||
LS(`CLUSTER: count=${count} : msg.users=${parseInt(msg.users)} : clientCount=${clientCount}`); | ||
count = parseInt(count) + parseInt(msg.users); | ||
clientCount ++; | ||
} | ||
}); | ||
} | ||
|
||
let updateWorkers = () => { | ||
eachWorker(worker => { | ||
if (clientCount == numServer) | ||
worker.send({'count':count}); | ||
}); | ||
count = 0; | ||
clientCount = 0; | ||
}; | ||
|
||
updateWorkers(); | ||
setInterval(updateWorkers, 10000); | ||
|
||
cluster.on('exit', (worker, code) => { | ||
if (code !== 0 && !worker.exitedAfterDisconnect) { | ||
LS(`Worker ${worker.id} crashed. Starting a new worker...`); | ||
cluster.fork(); | ||
} | ||
}); | ||
} | ||
else | ||
{ | ||
require("./server"); | ||
} | ||
|
||
require('./server-new.js'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// 3d.js | ||
// @author octopoulo <[email protected]> | ||
// @version 2021-02-02 | ||
// @version 2021-02-03 | ||
// | ||
// general 3d rendering code | ||
// | ||
|
@@ -15,7 +15,7 @@ S, save_option, set_modal_events, Show, Stats, Style, T:true, THREE, translate_n | |
'use strict'; | ||
|
||
// << | ||
if (typeof global != 'undefined') { | ||
if (typeof global != 'undefined' && typeof require != 'undefined') { | ||
['common'].forEach(key => { | ||
Object.assign(global, require(`./${key}.js`)); | ||
}); | ||
|
@@ -343,7 +343,7 @@ function interpolate_store(part) { | |
* Load a model | ||
* @param {string} name key for model storage | ||
* @param {string} filename | ||
* @param {function} callback | ||
* @param {Function} callback | ||
*/ | ||
function load_model(name, filename, callback) { | ||
// 0) need T | ||
|
@@ -394,7 +394,7 @@ function load_model(name, filename, callback) { | |
/** | ||
* Load multiple models | ||
* @param {Object} filenames | ||
* @param {function} callback | ||
* @param {Function} callback | ||
*/ | ||
function load_models(filenames, callback) { | ||
let keys = Keys(filenames), | ||
|
@@ -968,7 +968,7 @@ function gamepad_update() { | |
* @param {number=} cycle end of the cycle | ||
* @param {boolean=} inside | ||
* @param {boolean=} interrupt play the sound again even if it's being played | ||
* @param {function=} loaded only load the audio | ||
* @param {Function=} loaded only load the audio | ||
* @param {number=} start start of the 2nd cycle | ||
* @param {boolean=} voice | ||
* @param {number=} volume | ||
|
Oops, something went wrong.