On 21.05.2008, at 10:33, Herbert König wrote:
Hello Bert,
BF> Keep in mind we are on the beginners list. I do know where this is BF> used, and why. But if someone asks this on the beginners list it is BF> bad advice to give.
thanks for your clear words. I'll refrain from further giving that advice here.
I started with every Morph having its own step method for the animation. Then I found I needed exactly controlled synchronisation and ended up with one transparent Morph (subclassed the model from Morph instead of Object) with one central step method to animate everything.
Sounds great so far ...
That's how I ended up with doOneCycle.
... but I have no idea how this comes into play here.
Other use case: the model is rally busy with a simulation but knows when to draw the animation. And it needs *every* Morph redrawn.
So how to solve this? Send drawOn: in the step method and send step from the model?
No - to mark a Morph for redraw, send #changed to it (or #invalidRect:).
In searching I found World>>restoreMorphicDisplay (from the World menu) and WorldState>>displayWorldSavely
Any pointers on how to control morphic display?
Well, this example does not quite fit into the Morphic logic. Fortunately, Squeak is malleable enough so you can still do what you want, as you found out already :)
Morphic normally forces you to break up the computation into small steps. It has a mainloop that repeatedly evaluates doOneCycle, which dispatches events, calls the step methods, and redraws. What you appear to want to do is run that loop yourself inside your simulation. And indeed repeatedly calling doOneCycle does exactly that. So for that specific use case it might actually be the best way to do it.
It makes sense if your image is customized to run exactly that one application, and you control what is available and what not. But it would interact badly with other Morphs. Imagine you wanted to run two copies of your simulation at the same time. That's a piece of cake with "well-behaved" morphs, you just duplicate it via its green halo handle and it works. But it would break spectacularly if you messed with the main loop.
- Bert -