PDA

View Full Version : Qt Scripting Potentialities (ProcessingJS+QT)



gabon
16th May 2010, 13:19
Hi guys, I am very interested in the potentialities of QT Scripting. I used rapid prototyping platforms like Processing in the past. Its recent online version ProcessingJS seems to be pretty popular and proved Processing to be a good language for visualizations. I am very interested to see if QT could be used to build more performant visualisations than the Java Processing itself. I presume it shouldn't be hard to build a javascript middle layer to communicate to OpenGL, I am just a bit concerned about the javascript execution speed (since big part of the logic, the user code, could still be there).

What do you reckon? Does it worth investigating? Is there anyone who wants to be involved?

Thanks for any info/opinion, cheers, chr

gabon
17th May 2010, 08:27
I made a test with random() and when Javascript and Processing Java take around 5ms to generate 100,000 numbers, QT engine takes > 20 ms. I am not particularly surprised, but this seems to be a show stopper for my purposes :(

Clearly QT Script hasn't been created to compute demanding operations, and this is totally understandable.


Thanks, chr

tbscope
17th May 2010, 09:26
Well, did you try creating a script function that calls a C++ function to generate those numbers?

You can create wrapper functions for your scripts. Keep performance demanding functions in C++ and provide wrapper or access functions in your scripts.

gabon
17th May 2010, 09:34
// .cpp
QScriptValue random(QScriptContext *context, QScriptEngine *engine)
{
float r = (float) rand()/RAND_MAX;
int len = context->argumentCount();
if(len == 0){
return r;
}
QScriptValue a = context->argument(0);
if(len == 1){
return r * a.toNumber();
}
Q_ASSERT(len < 3);
QScriptValue b = context->argument(1);
return a.toNumber() + (b.toNumber() - a.toNumber()) * r;
}

linked


engine.globalObject().setProperty("random", engine.newFunction(random));


// .js
var m = new Date().getTime();
var num;
for(var i=0; i<100000; i++){
num = random(10,200);
}
println("qt processed in " + (new Date().getTime() - m));


Cheers, chr

gabon
17th May 2010, 09:44
You can create wrapper functions for your scripts. Keep performance demanding functions in C++ and provide wrapper or access functions in your scripts.

Sure, but the purpose of the experiment was to let the user write the whole application in js and just provide some global functions for the OpenGL rendering.

Cheers, chr