Monster Evolution in Qt: Part 1 (using Qt Script)
However, like any other good hackers (or foolish ones, depending on how you look at it), I can not afford to stay quiet in my cave and watch Chrome users enjoy the wonderful Monster demo. So I sat down and dedicated (or wasted, again depending on how you look at it) few evenings and one Creative Friday to scratch my so-far most challenging itch (read: obsession), i.e. to make Qt lovers be able to run the demo. To certain extent, I did not succeed (I know I am a lousy developer, but that is the story for another day). Here lies the proof:
As you can see, only 8 frames/second at the most intensive loop. That is far from acceptable. In fact, that is a failure. However, the rendering seems to be as good as it could be. Here lies the proof (or watch on YouTube directly or grab the video (AVI, 3 MB):
Note that the video looks smooth, but this is because it is just a time-lapsed video (i.e. not a real-time capture). So ignore the speed, just mind the rendering quality. Compare with what a web browser renders. To the curious readers: motion blur is implemented via alpha-blending. In this Qt implementation, it is as easy as keeping the default composition mode (SourceOver) and set the widget to have Qt::WA_OpaquePaintEvent attribute.
For the code, check out our usual repository under qsmonster directory. Non-git users can click on the snapshot link to grab the archive. You can use both Qt 4.4 or Qt 4.5 to give it a try. Running it using raster or OpenGL graphics system is also recommended. In addition, thanks to our very own David Boddie, you can enjoy this demo using PyQt as well.
Shocked because you can not reach 8 fps at all? Continue reading to find out the full story behind the scene.
The monster script is however very math-intensive. At its peak, it calculates the projection and lighting for around 600 little polygons per frame. If you want something like 30 fps, this is sadly too heavyweight for Qt Script. For example, profiling shows that most of the time spent in object member and property lookup. I tried to patch Qt Script with cached name id mapping, it did boost the performance a little but not significantly.
To conclude: although the example runs with pristine Qt Script from Qt 4.4 and 4.5, it is rather slow. I released the code only for completeness, and so you try it again once Qt 4.6 is out.
Stay tuned for Part 2. I will show another very similar example which uses QtWebKit to run the monster script. And this will be something which you can try with your wonderful Qt 4.5 and still get a reasonable fps.
A little FAQ:
A: This is our internal experimental branch, it is fairly broken. It can't be used to run any non-trivial scripts. We would make it available for testing when we feel that it already reaches certain level of confidence.
Q: Does this example use QtWebKit?
Q: Can I run other Chrome experiments?
A: Very unlikely. I wrote this example specifically to run Monster Evolution (even excluding the event handling etc).
Q: Did you test with or without the JIT compiler?
A: Both. JIT compiler typically gives extra 20% boost.
Q: Why don't you use OpenGL to speed things up?
A: You do use OpenGL anyway, if you use OpenGL graphics system to launch the example. Anyway, the bottleneck is not in the graphics side. Drawing 15000 alpha-blended, anti-aliased, flat-shaded quads in a fraction of a second is not a big deal with typical graphics card these days.
Q: Does this mean QtWebKit canvas will be improved?
A: Yes and no. This example is specific only to the Monster demo. Some of tricks and hacks here are useless in other context. However, several ideas and attempts on making this example are valuable for generic canvas performance tuning.
Q: Where is the 3-D engine?
A: In the script called monster.js. This example downloads the script directly from the location you can see in the source code.
Q: Can you explain something about monster.js?
A: I got no clue, I did not write it. This qsmonster runs the script as it is.
Subscribe to our newsletter
Try Qt 6.1 Now!
Download the latest release here: www.qt.io/download.
Qt 6 was created to be the productivity platform for the future, with next-gen 2D & 3D UX and limitless scalability.
Explore Qt World
Check our Qt demos and case studies in the virtual Qt World
Check out all our open positions here and follow us on Instagram to see what it's like to be #QtPeople.
Näytä tämä julkaisu Instagramissa.
Want to build something for tomorrow, join #QtPeople today! We have loads of cool jobs you don’t want to miss! http://qt.io/careers #builtwithQt #software #developers #coding #framework #tool #tooling #C++ #QML #engineers #sales #tech #technology #UI #UX #CX #Qt #Qtdev #global #openpositions #careers #job
Henkilön Qt (@theqtcompany) jakama julkaisu