Advice for design decision regarding object creation! 
Posted: 01 May 2012 05:02 AM   [ Ignore ]
Rank
Joined  2010-12-29
Total Posts:  32
New Member

Hey,

currently im faced with a big problem. I have a app, which lets the user create many components (e.g. rectangles, ellipses) in a short time!
I cannot post the entire code, because it is too much! You can imagine it as follow:

The user picks a component (e.g. rectangle), now lets say he can click a button and will have several hundrets of the exact same dimensions at random positions.
As you my guess, the more copies, the more my app gets sluggish!

What would be you recommendations for creating the copies!
No interaction with the copies, the only thing is, when the dimensions of the original are modified all other should be modified as well! Same with the rotation!

What i actually do is, something like the following:

for(MTPolygon t copies)
{
    t
.setVertices(original.getVerticesLocal() );
    
t.setPositionGlobal(randomPos)
}

This is of cause a very expensive call, so it is just called, when a modification has taken place.
In case that i do not need any interaction with the copies, they must just once drawn and stay at their position!

I also tried is use the setClear(false) method of the scene the objects live in! Maybe this is already the right way to do this, but i just dont want to miss a easy soltuion for this, that i do not know yet!
I already studied the documentation of coressponding classes! When doing this that way, the copies cannot be rotated on the fly!!

What is your opinion of storing the positioning data, the dimension data, the shapes count, the rotation angle and drawing everything from new, if a modfication has taken place!
I do not know, if this is more effective??

Mabe someone has an idea??
I would appreciate for any hint!!

Profile
 
 
Posted: 01 May 2012 12:24 PM   [ Ignore ]   [ # 1 ]
Avatar
Rank
Joined  2012-04-15
Total Posts:  38
New Member

mm I don’t really know very much about performance, but a guy recommended me the usage of the translate and transform methods. This way, if I’ve understood what you want to do:

for(MTPolygon t copies)
{
t
.translate(randomPos);
t.transform(modifiedMTPolygon.getGlobalMatrix());
}

Profile
 
 
Posted: 27 May 2012 11:11 PM   [ Ignore ]   [ # 2 ]
Avatar
Rank
Joined  2012-03-29
Total Posts:  59
New Member

The problem is that all objects have his own memory heap and else, if there will be a lot, just painting it, you should create an unique object that handles all the copies, you should check the simpleParticle example, were they create several images with a single touch (handling everything inside the class, not creating other classes), and the performance is quite well

Profile
 
 
Posted: 29 May 2012 07:34 AM   [ Ignore ]   [ # 3 ]
Avatar
RankRankRankRank
Joined  2008-04-30
Total Posts:  612
Elite

If the copies dont have to be interactable the fastest and memory friendliest way would be to make no copies at all. Just draw the same component over and over again using a different translation and rotation.

So what I would do is: create a new class extending MTComponent. Then in its constructor create the MTPolygon you want to draw. In the drawComponent() method of the MTComponent do graphics.pushMatrix() graphics.translate(..) graphics.rotateZ(..) and polygon.drawComponent(graphics) then graphics.popMatrix(). To draw the polygon. As you want to draw it many times, just do that in a loop, changing translation and rotation before each polygon.drawComponent() call. You could store the rotation and translation of each “copy” in another array.

 Signature 

MT4j - Multi-Touch for Java!

Profile
 
 
Posted: 31 May 2012 08:03 AM   [ Ignore ]   [ # 4 ]
Rank
Joined  2010-12-29
Total Posts:  32
New Member

Thanks for your help!

The way Therion described it, is actually the exact way i have done it!

Works quite well!!

Profile