tag:robotlegs.tenderapp.com,2009-10-18:/discussions/robotlegs-2/5027-architectural-question-how-to-wire-an-enter_frame-flow Robotlegs: Discussion 2013-09-23T14:37:27Z tag:robotlegs.tenderapp.com,2009-10-18:Comment/28524829 2013-08-30T15:39:17Z 2013-08-30T18:29:47Z Architectural question - how to wire an ENTER_FRAME flow? <div><p>PROPER POST, mods please delete all previous ones</p> <p>Hello,</p> <p>I've never had much success with RL, the framework always got in the way more than it helped and custom, simple design patterns turned out to be more practical in all but the most complex projects - but I figure that's because I used it wrong, and often found myself doing hackish solutions and injections that you could technically do, but defeated the purpose of MVC in the first place.</p> <p>So I'm giving it another try with RL 2 (and I love some of the changes!) - I'm stuck trying to find a fast, efficient and architecturally sound way to solve this scenario.</p> <p>Basically, it's a video with overlaying elements on top, their position controlled from XML and updated every frame to match the movie currentframe.</p> <p>Commands are expensive, Events are sort of expensive, and the event triggering so much code execution is a performance problem. How would I solve this so that it's still elegant but not quite as resource-intensive?</p> <p>BTW, flowcharts are awesome, so I sketched one up, it's attached here. Is there any plugin or parser that could help me visualize the relationship between various MVC elements? I'm using the global search function more than I'd like and I would love to get a bigger picture of the whole thing without having to manually recreate the whole thing in a flowchart drawing tool?</p> <p>Also great job on RL2, I'm still getting my feet wet but it just.. <em>feels</em> better than RL1.</p> <p><img src="http://i.imgur.com/On2Virq.png" alt="Flowchart"></p></div> archont tag:robotlegs.tenderapp.com,2009-10-18:Comment/28524829 2013-08-30T19:00:37Z 2013-08-30T19:00:37Z Architectural question - how to wire an ENTER_FRAME flow? <div><p>Hmm. there's some weirdness going on with Tender today - this post keeps ending up in the Spam queue.</p> <p>Anyhow.. I would definitely recommend <em>against</em> pushing performance critical stuff through the command map (or any similar abstraction).</p> <p>Decoupling is a great principle, but use it where it makes sense, and where it provides benefit. Bootstrapping, handing user triggered actions and application state changes, things that occur relatively infrequently etc.</p> <p>But a "gameloop", or any sequence of code that is executed on every frame, should be kept as tight as possible. Avoid creating throwaway objects (events for example) as this puts strain on the garbage collector. Avoid loops. Avoid deep call stacks. Heck, avoid method calls if you can!</p> <p>So why use RL at all then? Because many things benefit from decoupling; from being given readable, well defined roles within a system. RL and automated DI often make code easier to read and maintain (when used correctly). But things tend to fall apart when developers try to force every single aspect of their system into some imagined MVC structure. An unreasonably decoupled system can be a nightmare to read and understand.</p> <p>In your case I might use RL to bootstrap the app, handle the loading and parsing of data, sign users in/out, and wire things together. But the subsystem (module, service, whatever we might call it) that handles frame events and creates, positions and destroys the overlays would be tight and fast.</p> <p>Hope that helps a bit!</p></div> Shaun Smith tag:robotlegs.tenderapp.com,2009-10-18:Comment/28524829 2013-08-30T19:49:38Z 2013-08-30T19:49:38Z Architectural question - how to wire an ENTER_FRAME flow? <div><p>Hey Shaun, thanks for your reply, I never really thought about blending MVC with non-MVC code. I always thought of MVC as more of an all-or-nothing pattern.</p> <p>The "gameloop" is a critical, but very tiny part of the application. It's short, simple and linear, with no branching. As it's pretty simple and there's just one of it, an extra function call or two won't really harm performance, but a few dozen calls, few new Events and a Command does.</p> <p>While it would be possible to flatten the 2 models and 1 mediator into a single Manager blob, they all do various non-time-critical stuff that greatly benefits from decoupling and MVC. I would want the gameloop handler to be as small and single-purpose as possible.</p> <p>What I'm thinking is leaving the non-time-critical functionality in their respective models, then creating an optimized single-purpose singleton Manager(Sprite) that actually stores the data, manipulates itself and listens to ENTER_FRAME on it's own - while being exposed to MVC via a thin Model with tight bindings to the manager.</p> <p>This would mean that this new thin Model is a tightly-coupled MVC interface for a singleton manager - so in effect it's kind of like a Mediator and Model rolled into one. Time-critical stuff gets handled inside the manager, while the Manager is fed data via the Model.</p> <p>Another option is to have the singleton manager exposed via a Mediator instead - on one hand the overlay has multiple inputs (currentFrame, parsed XML data, responds to stage resize events) and just one output (clicked), so in that respect it ultimately acts like a view. On the other hand Views and their Mediators are supposed to be stateless, disposable elements that rely on a Model for data.</p> <p>I'm, still learning to "think in Robotlegs" so I want to know if such an approach would be a sane compromise or a total misinterpretation of MVC principles.</p></div> archont tag:robotlegs.tenderapp.com,2009-10-18:Comment/28524829 2013-08-30T21:43:50Z 2013-08-30T21:43:50Z Architectural question - how to wire an ENTER_FRAME flow? <div><p>Hey, no problemo. So I'm not necessarily suggesting "flattening" a number of classes into a god object, my comments were more to do with message passing, how collaborators are wired together, and how deep the callstack gets inside the gameloop - you should still avoid writing classes that do more than one thing (which is made most obvious when you need to use the word "and" when describing what a class does!).</p> <p>It sounds like you have a couple of approaches in mind. Really, you just need to try them out and see what feels the best. Personally, I'd avoid the word "manager" :)</p></div> Shaun Smith