Open Abul22 opened 9 years ago
Is this w/o rendering (e.g. a multiplayer server) or are you still rendering?
If it's w/o, it seems like you should be able to just not call Q.setup() and just write your own stage game loop to skip the render part of it:
Q.headlessStageGameLoop = function(dt) {
var i,len,stage;
if(dt < 0) { dt = 1.0/60; }
if(dt > 1/15) { dt = 1.0/15; }
for(i =0,len=Q.stages.length;i<len;i++) {
Q.activeStage = i;
stage = Q.stage();
if(stage) {
stage.step(dt);
}
}
Q.activeStage = 0;
};
And explicitly start that game loop before you stage your first scene:
Q.gameLoop(Q.headlessStageGameLoop);
Yea, aiming for a authoritative server side client to run just the logic w/o any gfx rendering... Ideally I'd be able to do things like receive a message from a client like 'right' and alter the server side -> entity.p.vx=10 and then continue to have the control over viewing the that players x/y coords. Just to give a fuller scope, I'm using node with socketio and obviously quintus.
I attempted to test your given solution without much success. ( I'm admittedly a complete amateur at this, so could just be my flawed implementation) -- I just made a js file, required 'quintus-all.js' and dropped the above code in.
Getting the familiar error -
//quintus-all.js:2199
// for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
// ^
//ReferenceError: window is not defined
Understandably this isn't a help desk, so if you don't have the time &/or effort to address these just say and I'll seek elsewhere. But I do plan on making my project available as a MIT licensed example for others looking for the same structure as I.
A MP template for an authorative server and client model I feel is a must to let this platform be used for more complex games requiring protection from simple js editing cheating.
Cheers :)
That's just the requestAnimationFrame shim that's being added in - you can remove that whole IIFE and you should be fine. I don't think there's any other window. req's you'll hit as long as you stay out of Input and Audio.
I've been meaning to make the module work both in the Browser and Node for a while, will probably have a version that works in both soon...
Hmmm, sounds like it may be best if I just eagerly await that... I removed the the reqAnimFrame IIFE and yea, it cleared up that error. Now I'm back to troubles instantiating it doing it this way... I don't know.
var game = require('../public/lib/quintus-all.js');
var Q = game.Quintus({ development: true }) ^ TypeError: Object #
You might just want to wait then - Quintus isn't set up for Node module.exports and unless you're familiar with those it'll take some wrangling.
Necroing this a little... @Abul22 - this works for me:
Quintus = require('quintus')
var Q = window.Q = Quintus()
.include("Sprites, Scenes, Input, 2D, Anim, Touch, UI, TMX")
.setup({ maximize: true })
.controls().touch();
This is using Browserify + Gulp
EDIT This won't fix the rest of the server side, though.
Currently I'm trying to remove all refs to 'window' in the libs so I can run it serverside ...It's quite difficult to do without breaking / without understanding what all the code within it does.
Is there another distrib for running it headless? Or will it be in the works? Or do you have any suggestions on how to do this more efficiently?
Thanks!