Whats up everybody,
I’m making an attempt to optimise my sport which has poor efficiency in iOS native in CC3.8.3. Major situation I’ve is that I’m doing the renderdata(vertices) caculations each body and updating to the sprite part which is heavy in JS with out JIT in iOS.
So checking the chance to maneuver the heavy calculations to the C++ however having arduous time to determine the best way to do it.
Questions –
-
What can I do for shifting my gamestate(information required for calculations) from JS code to C++ and have the end result 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 acquire.
-
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 every other part I can use to simply replace the renderdata(vertices and indices) which have higher efficiency slightly than customising the sprite part and assembler and utilizing spriteframe.vertices to do it since in contrast to 2.4 the spritetype Mesh is eliminated in 3.8.
Any different approaches are welcome.
Thanks!
Hello @A_S ,
how did you customised Sprite Part and Assembler? What sorts of complicated calculation
did you do?
Presently, Parts and 2D Assemblers are all applied in TS.
- What can I do for shifting my gamestate(information required for calculations) from JS code to C++ and have the end result again?
You possibly can discuss 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 acquire.
That depends upon how often do the information move from JS to C++ or C++ to JS.
If the information is all numbers, you most likely might use share ArrayBuffer technique to keep away from passing giant 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 technique to archive this since Assembler is simply accessable in JS/TS.
Hello @dumganhar ,
Thanks for the reply,
I customised the sprite part 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 fluctuate the renderdata size utilizing renderData.resize(vertCount, indexCount)
The calculations usually are not complicated, they’re simply basic math, however there are fairly a lot of vertices that must 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 consumer is dragging the display all of the renderData should be recalculated each body that’s the place the efficiency drop happens in iOS on account of giant JS code that should run.
Simply doing the easy math utilizing C++ won’t be efficient since there can 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.
Hello @A_S ,Thanks on your suggestions. Maybe rewriting the second assembler code in c++ is an choice to optimize the efficiency on iOS.
I’m additionally questioning how pool efficiency you bought. Is it doable to replace a easy demo that I might profile by?
Hello @dumganhar,
Are you able to give extra element on the place can I replace the renderdata or buffer in C++ or ought to I ship it again to JS.
Poor within the sense lower than 30 fps whereas touchmoving on display and typically very sluggish that the display type of leaping in iOS as an alternative of clean motion in contrast to android.
Additionally typically there are another gamestate calculations which can be heavy as properly however at the moment the efficiency even with out that could be very low.
Meantime I’ll attempt to create a easy demo to breed the difficulty.
Hello @A_S , as I point out that second assemblers are all applied in TS, so there is no such thing as a higher method to do this in C++. Did you profile your code and test the place the efficiency hotspots are?
Yep , a demo will make me know extra about how did you write the code and maybe we might discover a higher strategy to enhance the efficiency.