Still looking for ways to save memory I'm sorry to post two threads at once, but the two subjects are definitely different and cant be joined in one thread only. So mister moderator, please excuse me, it wont happen again
Back to my question:
I am displaying Sprite3D elements under the text of my menu in a 3D rendered scene.
Lets imagine I have 5 choices in my main menu: 4 of them are not currently selected, one is. I'd like to display one special Sprite3D behind these 4 choices, and another one behind the choice currently selected.
Do I have to load 4 different Sprite3D objects to diplay the same image 4 times? Thats what I'm doing at the moment. It sure works, but it looks like a lot of memory wasted here.
So my question is pretty simple: can i create a Sprite3D object, and diplay it at 2 (at least :p) different places in my world space?
I tried already but a Sprite3D object can have one parent node only. I also tried to use the duplicate() method to avoid re-creating my Sprite3D object, but wouldnt it be exacty the same as the System migt create the duplicate objects in memory?
also the duplicate method is the same thing ...its jus keeps the same object wid separate transforms so there are no separate objects created in memory. so u can use both the ways to do wht u want to.
> also the duplicate method is the same thing ...its > jus keeps the same object wid separate transforms so > there are no separate objects created in memory. > so u can use both the ways to do wht u want to.
Not true, the duplicate method will create a completely new object with most of the fields set to the same data (except for some of those belonging to Node). It is not possible to just keep the same object with separate transforms.
Trying to save memory is a good thing, however I would recommend to not overdo it. If it is easy to save an object or two somewhere and doesn't impact readability of your code, by all means, do it. But you should only optimize where it really makes a difference (and only optimize once the code is running). It just doesn't pay off to chase every last byte, even on very limited mobile devices.
The minimum amount of memory used for a Sprite3D object should be around 176 bytes (12 for Object3D, 104 for Transformable, 32 for Node, 28 for Sprite3D). An implementation might of course use more than that internally, however this is still not excessively large if you only have five of them. In all likelyhood it is still much less memory than the Image2D for the sprites needs.
Well okay, there's no way to do it by sticking to retained mode. I'm gonna have to mix retained and immediate mode if i wanna use only one Sprite3D object instead of, actually, 6.
On the other hand, what Xmas says is quite true, I'm not sure I wanna get my code complicated that much to save a few bytes. I might give it a try though.
Thanx for answering guyz, and for being that clear.
how to declare transform here.....when i want to place 50 trees...i have to geive 50 transforms here....The transform is a 4*4 identity matrix.So it wil take more memory than the Sprite3D objects..i think......It's correct are not....
//this is a global (an attribute) used everywhere Transform rmp = new Transform();
//when i need a transform: tmp.setIdentity(); tmp.postTranslate( ... ); tmp.postScale( ... ); ... g3d.render( sp1, tmp ); //then do it again for the next sprite tmp.setIdentity(); tmp.postTranslate( ... ); tmp.postScale( ... ); ... g3d.render( sp2, tmp );
I'm suddenly wondering if it's the right way to do it. I'm gonna check the JSR184 doc to see if a call to render copies the Transform object or just makes a reference to it. In the latter, I think I'm screwed and gonna have to change some pieces of code.
Thx for making me focus on that anyway! Gonna check this and get back to this thread.
> w to declare transform here.....when i want to place > 50 trees...i have to geive 50 transforms here....The > transform is a 4*4 identity matrix.So it wil take > more memory than the Sprite3D objects..i > think......It's correct are not.... The 50 Transforms together will need more memory than one Sprite3D, but a Sprite3D object requires more memory than a Transform, since it's a subclass of Transformable.
> I'm suddenly wondering if it's the right way to do > it. I'm gonna check the JSR184 doc to see if a call > to render copies the Transform object or just makes a > reference to it. In the latter, I think I'm screwed > and gonna have to change some pieces of code. Don't worry. A call to render will always act as using the Transform object in its state at the point of the method call, regardless of whether it performs the actual rendering immediately or not.