inexorgame-obsolete / deprecated-cube-engine-inexor

UNMAINTAINED: Please have a look at the vulkan-renderer
https://inexor.org
zlib License
11 stars 1 forks source link

Add callback for finished initialisation in NodeJS #332

Closed movabo closed 8 years ago

movabo commented 8 years ago

Right now when you edit for example code/node/app/server.js and add these two lines:

console.log(inexor.tree.maxfps) // Logs false to the console
setTimeout(function () { console.log(inexor.tree.maxfps) }, 10000) // Logs the actual maxfps (for example 200) to the console

one will log the right amout of maxfps and the other won't. I guess this is due to the fact that the initialisation did not finish.

So a callback should be added, which will be executed after the initialistation finished.

For example:

console.log(inexor.tree.maxfps) // Still logs false
inexor.tree.onReady(function () {
    console.log(inexor.tree.maxfps) // Logs the actual maxfps.
})
Fohlen commented 8 years ago

This has actually been discussed by me and @aschaeffer beforehand. The main problem is that there's no-yet asynchronous architecture behind the application server, as neither the plugin system is implemented ..

Fohlen commented 8 years ago

095e275 introduces a ready event and an asynchronous startup routine. How about you be the first to write a plugin for an onReady state URL?

aschaeffer commented 7 years ago

This will be fixed in master by completing #354 and #368.

aschaeffer commented 7 years ago

Now it's possible to watch if an instance is running:

let instanceId = 31416;
let root = ...;
let instanceNode = root.instances.getChild(instanceId);
instanceNode.state.on('postSet', function(oldValue, newValue) {
  switch (newValue) {
    case 'stopped':
      if (oldValue == null) {
        log.info('Instance has been created');
      } else if (oldValue == 'started' || oldValue == 'running') {
        log.info('Instance has been stopped');
      }
      break;
    case 'started':
      log.info('Instance has been started, but there is no RPC connection established right now');
      break;
    case 'running':
      if (oldValue == 'started') {
        log.info('Instance has been connected and is now running');
      } else if (oldValue == 'paused') {
        log.info('Instance has been resumed and is now running again');
      }
      break;
    case 'paused':
      log.info('Instance is paused');
      break;
  }
});