Author Topic: How to re-use precompiled data for newly created objects?  (Read 1432 times)

Offline 32kda

  • byte
  • *
  • Posts: 10
    • View Profile
How to re-use precompiled data for newly created objects?
« 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to re-use precompiled data for newly created objects?
« Reply #1 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);

Offline 32kda

  • byte
  • *
  • Posts: 10
    • View Profile
Re: How to re-use precompiled data for newly created objects?
« Reply #2 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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to re-use precompiled data for newly created objects?
« Reply #3 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.

Offline 32kda

  • byte
  • *
  • Posts: 10
    • View Profile
Re: How to re-use precompiled data for newly created objects?
« Reply #4 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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11745
    • View Profile
    • http://www.jpct.net
Re: How to re-use precompiled data for newly created objects?
« Reply #5 on: June 19, 2012, 08:55:54 am »
I guess i should rather reword the docs. I agree that they might be misleading.