Whats up everybody,
I’m making an attempt to optimise my sport which has poor efficiency in iOS native in CC3.8.3. Fundamental subject I’ve is that I’m doing the renderdata(vertices) caculations each body and updating to the sprite element which is heavy in JS with out JIT in iOS.
So checking the chance to maneuver the heavy calculations to the C++ however having onerous time to determine the way in which to do it.
Questions –
-
What can I do for transferring my gamestate(information required for calculations) from JS code to C++ and have the consequence again?
-
How a lot does it have an effect on the efficiency with information passing from JS to C++ and again. Will it’s price making an attempt this when it comes to efficiency achieve.
-
Is it possible to replace the render information immediately within the C++ code if I transfer the calculations to C++ by any method.
Is also there some other element I can use to simply replace the renderdata(vertices and indices) which have higher efficiency relatively than customising the sprite element and assembler and utilizing spriteframe.vertices to do it since in contrast to 2.4 the spritetype Mesh is eliminated in 3.8.
Any various approaches are welcome.
Thanks!
Hello @A_S ,
how did you customised Sprite Part and Assembler? What sorts of complicated calculation
did you do?
At present, Elements and 2D Assemblers are all carried out in TS.
- What can I do for transferring my gamestate(information required for calculations) from JS code to C++ and have the consequence again?
You could possibly confer with the documentation ( Introduction | Cocos Creator ) to export a C++ class to JS.
- How a lot does it have an effect on the efficiency with information passing from JS to C++ and again. Will it’s price making an attempt this when it comes to efficiency achieve.
That relies on how continuously do the information go from JS to C++ or C++ to JS.
If the information is all numbers, you in all probability might use share ArrayBuffer technique to keep away from passing massive information between languages.
There’s a doc ( Optimization of Cross-Language Invocation | Cocos Creator ) right here to explain this optimization technique in engine.
- Is it possible to replace the render information immediately within the C++ code if I transfer the calculations to C++ by any method.
Sorry, there is no such thing as a eazy approach to archive this since Assembler is barely accessable in JS/TS.
Hello @dumganhar ,
Thanks for the reply,
I customised the sprite element to make use of customized assembler and replace the renderdata immediately as an alternative of assembler. Within the assembler I simply replace the colour and uv in chunk.vb
buffer from renderdata and indices from spriteframe.vertices.indices
(which I replace when calculating the vertices) into chunk.ib
. Right here I skip updateVertexData()
the place place, rotation and scale are calculated since I’m doing it myself.
Additionally someday range the renderdata size utilizing renderData.resize(vertCount, indexCount)
The calculations usually are not complicated, they’re simply simple arithmetic, however there are fairly a lot of vertices that have to calculated each body and utilizing the sprite.markForUpdateRenderData()
to replace the adjustments in each body.
I’m stopping these calculations when the sport is idle and getting good efficiency that point however when person is dragging the display all of the renderData should be recalculated each body that’s the place the efficiency drop happens in iOS because of massive JS code that should run.
Simply doing the easy math utilizing C++ won’t be efficient since there could be a number of calls from C++ to JS and again each body proper.
Is there any method in JS itself the place I can get the vertex and index buffer utilizing C++ shared reminiscence and immediately replace the buffers in JS with out updating the renderdata after which copying it to the buffers.