[BUG]Picking up morphs with the hand.

Andreas Raab andreas.raab at gmx.de
Thu Aug 7 22:21:17 UTC 2003


Hi,

> > I did some timing :

Sorry to say that but the timing is meaningless. You should have profiled
the code instead of only measuring the overall time, e.g.,

"This is wrong"
[ActiveHand grabMorph: buddy. World doOneCycle] timeToRun

"This is right (note the doOneCycle-->NOW<-- below)"
MessageTally spyOn:[ActiveHand grabMorph: buddy. World doOneCycleNow].

"And this is even better"
MessageTally spyOn:[
	"First grab the buddy"
	ActiveHand grabMorph: buddy.
	World doOneCycleNow.
	"Then drop him again"
	ActiveHand dropMorphs.
	World doOneCycleNow.
].

This would have shown you that the "double time" that you measured can't
possibly come redrawing the morph twice, as, in fact, the morph is not drawn
twice but only once.

> Ok I found the reason for the double drawing in WorldState 
> displayWorld:submorphs:
> Two collections of damage are created and added together:
> 
> allDamage _ worldDamageRects, handDamageRects.
> 
> When a morph is grabbed or dropped it will be two allmost identical
> entries in the allDamage collection, one from the hand and one from
> the world.

If you read a little bit further down, you can see that this damage is not
used for any redrawing but merely for forcing the bits on the screen,
_after_ drawing is completed. That's effectively a BitBlt operation and
while it takes a bit more time if you have overlapping areas, it is
typically much, much faster than the actual drawing code.

> So what is best way to merge the double entries ?

The double entries in the above should probably be merged by replacing the

	allDamage := worldDamageRects, handDamageRects.

with:

	handDamageRects isEmpty ifTrue:[
		allDamage := worldDamageRects.
	] ifFalse:[
		"filter out potential overlaps between worldDamageRects and
handDamageRects"
		allDamage := OrderedCollection new.
		worldDamageRects 
			allAreasOutside: handDamageRects 
			do:[:rect| allDamage add: rect].
		allDamage addAll: handDamageRects.
	].

But don't expect too much from it. I would guess that you'll be lucky if you
see a 10-15% improvement. Not that it isn't worthwhile to do it, but it's
not going to double your grabbing speed.

Cheers,
  - Andreas



More information about the Squeak-dev mailing list