PureMVC Architects Lounge

Announcements and General Discussion => Architecture => Topic started by: jgervin on February 13, 2009, 12:41:55



Title: 1000 Sprites /w data. Mediator for each? Memory?
Post by: jgervin on February 13, 2009, 12:41:55
I am building my first PureMVC based project and wondering which would be the best way to go.

My app can have up to 1000 sprites, think node/edge (tree structure), and I am thinking of giving each node and edge its own mediator and proxy.  I don't have to do this as I have a collection item that keeps track of each node and edge group ( so 500 in each), which contains functions to manipulate each node/edge.  But, it would make things a little more flexible if I can handle some mouse related events on each node and edge directly. 

So my question is? Is there any issues with memory usage with giving each node/edge (up to 1000 total) their own proxy and mediator?  Keep in mind my app will already be a memory/cpu hog because of all the sprites.

Or should I go with just a mediator and proxy for the container that holds all 1000 sprites?


 


Title: Re: 1000 Sprites /w data. Mediator for each? Memory?
Post by: Tekool on February 13, 2009, 02:50:13
The mediator pattern is thought to manage one or many objects. There in PureMVC, one *Mediator* object can manage as many as *View* object you need it to manage.

In your case the mediator will receive each node event, identify the node by its index and transmit a notification to inform the whole app that a node has been clicked, give its index and acts in consequence.


Title: Re: 1000 Sprites /w data. Mediator for each? Memory?
Post by: jgervin on February 13, 2009, 03:36:20
Won't that make the the performance worse?  I would then need to keep track of the nodes and edges in a Dictionary and do a lookup each time a get an event. So say a mouseover happens and I want to the sprite to display text and turn colors and increase size by 25%.  And maybe a click I want it to make the textfield editable.  I would then need to do a lookup for the node and then a lookup for the textfield in the proxy and make all the changes there.

Maybe a better question than my original is would there ever be a need to have one mediator and proxy for each 1000 nodes/edges. What would that get me that using only one med. and one proxy for all nodes/edges wouldn't?

TIA, J


Title: Re: 1000 Sprites /w data. Mediator for each? Memory?
Post by: Tekool on February 14, 2009, 04:46:24
>I would then need to keep track of the nodes and edges in a Dictionary and do a lookup each time a get an event.
No you don't need because the data which you fill your component already exists in a *Proxy* object. So it will not consume more memory, nor it will consume more CPU, it is exactly the same as used alone.

>Maybe a better question than my original is would there ever be a need to have one mediator and proxy for each 1000 nodes/edges.

No you may definitively not do that. You can at least have multiple mediators but here I'm sure you only need one proxy.

You need to create a component as smart as possible to be able to receive an XML (or anything else) with sufficient informations for each node to tell the cell that display related informations what to do when clicked. If this informations depends on the application state, you just have to update the item related to the node it in the proxy when needed.

It is possible to create a mediator for each node you have, but keep this idea as long as possible and try to better develop a smart component.


Title: Re: 1000 Sprites /w data. Mediator for each? Memory?
Post by: puremvc on February 14, 2009, 06:56:52
Scope out the HelloFlash demo. It generates a stream of differently Sprites with associated Mediators every time you grab one with the mouse and drag. The next color to use comes from a single Proxy.

So not only does it demonstrate the many views/mediators and single proxy setup, but you can fill up the screen with bouncing sprites and see if it slows down.

-=Cliff>


Title: Re: 1000 Sprites /w data. Mediator for each? Memory?
Post by: jgervin on February 14, 2009, 09:28:02
Cliff would there ever be a need for any reason to add a proxy for each Sprite? So something like this:

facade.registerProxy(new TestNodeProxy( n.name+"Proxy" ) );
facade.registerMediator( new TestNodeMediator( n ) );

Given n is a type of Object (Sprite, MC, etc...)


Title: Re: 1000 Sprites /w data. Mediator for each? Memory?
Post by: puremvc on February 14, 2009, 01:37:50
Check out this conversation:

http://forums.puremvc.org/index.php?board=8.0

It talks about 'document-based' apps. The idea is a proxy for a given document is tied to a mediator for a view component meant to display that document.

-=Cliff>