At 10:39 06.01.2005 -0600, Daniel Nelson wrote:

But calls to native Director methods (imaging Lingo calls, for instance) are machine compiled code, so those run full-speed.

true, and while I never benchmarked it, I always felt that lists are a particular strength of lingo.


Comparisons like this are interesting, but they don't necessarily mean that much.

(longish example follows)

Some months ago I had a particle simulation of the "n-hundred bouncing balls in a square" type. There were reference implementations of the same thing done in java and VB, which both looked awful but performed reasonably fast. The VB-example (which I had in sources) went the number crunching way:

(lingoid pseudo code)

on animationStep
  repeat with ballNo = 1 to ballAmount
    moveThisBall(ballNo)
    repeat with otherballNo = 1 to ballAmount
      if otherBallNo = ballNo then
        next repeat
      else
        testForCollision(ballNo,otherBallNo)
      end if
    end repeat
  end repeat
end

My (lazy) attempts to just translate the VB to lingo effectively failed since lingo was dead slow when ballAmount had more than 2 digits.

Thus I decided to use Lingo's strength (lists). I introduced two _sorted_ property lists which keep the LocH / LocV of all the BallSprites in the form
[ballNo:Loc, ... ]
There are methods to update the LocH / LocV value related to some ballNo in those lists and there is a method to return a number of neighboring entries from each of those sorted lists.


(pseudo code)

on animateThisBallStep me
  me.moveThisBall()

  UpdatePropertyListOfHorizontalPositions( me.ballNo, mySprite.locH )
  UpdatePropertyListOfVerticalPositions(   me.ballNo, mySprite.locV )

  LH = getListOfHorizontalNeighbours( me.ballNo, Resolution )
  LV = getListOfVerticalNeighbours(   me.ballNo, Resolution )
  LBallsCloseToMe = getThoseInBothLists( LH,LV )

  repeat with otherBallNo in LBallsCloseToMe
    me.testForCollision(ballNo,otherBallNo)
  end repeat
end

Thus, Lingo's sorting does the major part of the collision detection and the repeat loop typically goes over a sinle digit number of entries ( instead of m*10^4 entries).

The difference of performance was dramatic and the customer insisted to introduce a new parameter "temperature" in order to slow down the animation...


daniel


[To remove yourself from this list, or to change to digest mode, go to http://www.penworks.com/lingo-l.cgi To post messages to the list, email lingo-l@penworks.com (Problems, email [EMAIL PROTECTED]). Lingo-L is for learning and helping with programming Lingo. Thanks!]

Reply via email to