How to re-use precompiled data for newly created objects?

Started by 32kda, June 15, 2012, 12:33:52 PM

Previous topic - Next topic

32kda

Good day.
In my app I need to create projectile objects several times on user input. If I create new Object3d every time, it causes terrible lag like
Object 3/shell1 compiled to 1 subobjects in 936ms!
Tried to precrerate one object and use it's compiled data:


Object3D precompiledObject = PrecompiledObjectManager.getInstance().getPrecompiledObject(ID);
Object3D object = new Object3D(precompiledObject);
precompiledObject.shareCompiledData(object);


But it crashes throwing " ERROR: Can't share data from different meshes!"

Can't find samples for this, please tell how it should be done.

EgonOlsen

Simply do this:


               Object3D precompiledObject = PrecompiledObjectManager.getInstance().getPrecompiledObject(ID);
Object3D object = new Object3D(precompiledObject, true);
precompiledObject.shareCompiledData(object);

32kda

Thanks for your answer, Egon.

Done so:

Object3D precompiledObject = PrecompiledObjectManager.getInstance().getPrecompiledObject(ID);
Object3D object = new Object3D(precompiledObject, true);
precompiledObject.shareCompiledData(object);

And it works OK withoout exceptions. But unfortunately I can still see 1-2s lag when creating object and adding it to world. Compilation is still called and takes very significant time. Note - when I run app on my device without eclipse debugging, lag is much smaller and only a bit sensible. All other time rendering speed with & without debug differs not significantly.
Maybe some object initialization causes hevy-weight recompile?
Is there some sample code, how spawning units/projectiles or some other such objects should be done?

EgonOlsen

Switch the order in shareCompiledData-call. The method should be called on the new object with the blueprint as a parameter and not vice versa.

32kda

Thank you very much. It works fine now.
It would be great to have this explanation somewhere in project wiki.

EgonOlsen

I guess i should rather reword the docs. I agree that they might be misleading.