www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: 32kda on June 15, 2012, 12:33:52 pm

Title: How to re-use precompiled data for newly created objects?
Post by: 32kda on June 15, 2012, 12:33:52 pm
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:

Code: [Select]
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.
Title: Re: How to re-use precompiled data for newly created objects?
Post by: EgonOlsen on June 15, 2012, 01:09:12 pm
Simply do this:

Code: [Select]

               Object3D precompiledObject = PrecompiledObjectManager.getInstance().getPrecompiledObject(ID);
Object3D object = new Object3D(precompiledObject, true);
precompiledObject.shareCompiledData(object);
Title: Re: How to re-use precompiled data for newly created objects?
Post by: 32kda on June 18, 2012, 04:08:29 pm
Thanks for your answer, Egon.

Done so:
Code: [Select]
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?
Title: Re: How to re-use precompiled data for newly created objects?
Post by: EgonOlsen on June 18, 2012, 04:47:25 pm
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.
Title: Re: How to re-use precompiled data for newly created objects?
Post by: 32kda on June 19, 2012, 08:32:02 am
Thank you very much. It works fine now.
It would be great to have this explanation somewhere in project wiki.
Title: Re: How to re-use precompiled data for newly created objects?
Post by: EgonOlsen on June 19, 2012, 08:55:54 am
I guess i should rather reword the docs. I agree that they might be misleading.