Help with morph and world refresh

Stephane Ducasse ducasse at
Sat Apr 5 16:27:35 UTC 2003

Hi ned

> But how is this method being executed? It *must* be executed in the
> main UI process!
> Which means you only have a couple of valid choices:
> * run it from a step method (which is executed in the main UI process)
> * use WorldState>>addDeferredUIMessage: to do the synchronization and
> updating.

Ok I will look at that.
In fact the problem with not pick the diamonds only occurs if I execute 
from a workspace really fast multiple times the expression

b2 go.
b2 canPick ifTrue: [b2 pick]

This suggests to me that I'm executing several commands at the same 

>> the bot misses to pick some diamonds: really annoying. I guess that
>> this is because the method can pick and pick do not contain World
>> doOneCycle.
> Using World>>doOneCycle* is almost always a bad idea. I'd like to
> purge it from the existing "modal" dialogs wherever possible. And
> it's just wrong if you do it from a background thread.

Thanks to confirm that I was using a hack without understanding the 
>> I have the impression that this is a really bad practice to
>> explicitly wait for the refresh but I do not know how to do it in a
>> better way.
>> Have you suggestion to fix my problem?
> Yes. I would do this:
> * put your interpreter or control thread into a background process.
> * where synchronization/refresh is necessary (i.e. on a new position),
> add a message to your robot's SharedQueue that contains the new
> position.
> * then, wait on a per-robot Semaphore from your background process.
> * have your step method peek at the SharedQueue; if there is a new
> position there, remove the new position, update the robot's position
> (which will invalidate the robot's display rectangle and force it to
> be refreshed), and then signal the Semaphore.

> You can set the step rate to whatever gives you the most usable
> animation speed.

Nathanael already did that for the turtle with animation that I have.
But this is really complex.
I'm amazed to see how difficult it is to simply do a stupid small 
in Squeak that requires animation (ok I do not use step). Still.

I'm not sure that I can really develop your solution but thanks for 
suggesting it.
When I read it, I'm really frustrated by my lack of concurrent 
programming skills.

Would the WorldState>>addDeferredUIMessage: solve my problem?

I will really look in the changeset you sent. ***Thanks***.


More information about the Squeak-dev mailing list