Hi, I switched to Gideros around week ago from Cocos2d-x ( C++ ) and I need advice in term of speed. I developed own physics engine specialized for cars in c++. What is the best practice in Gideros, to use c++ code and call from Lua ( is this going to slow a lot because call is going to be in every frame, call c++ from has to cost some amount of time ) or to rewrite in Lua ( if there is a lot calculation Lua can be harder to achieve 60fps ). What is a approach in Gideros when you have a lot calcuation in every frame, to call c++ or is ther any other way ?
Comments
There are two things to consider.
When using luajit, lua code (in some our tests) may even outperform c++ code (I was shocked, but its true). But the problem is that only Android and Desktop versions support luajit (I think it is on ios too, but it does not give such huge performance boost as on other platforms, due to apple limitations)
If without luajit, then of course calling c++ and doing all heavy calculations there will be faster.
And since you already wrote your code in c++, I think it would be easy for you to bind some interfaces to lua and use it as a plugin.
Here is a great discussion on doing c++ plugins:
http://giderosmobile.com/forum/discussion/1025/step-by-step-how-to-write-a-c-plugin-and-deploy-it-to-the-desktop-windows-player/p1
As for best practices, then, as you have physics engine, I think the best way would be to
1) set all coordinates and dimensions as they change in your Gideros Sprites
so you would have up to date state of everything in your physics world in c++ too
2) on enterframe call only one funciton, like world step, which would calculate all collisions and other things needed
3) dispatch Gideros events from C++ on collisions and other events you want to track
As Gideros is open sourced and so are many plugins, you can check all the code for examples, but if you have any questions, feel free to also ask here
https://deluxepixel.com