\ \ This defines a NUT that can be eaten by a squirrel \ \ Compound object modules: \ Object files \ nut.rwx The nut \ Headers: \ objects.mh 2400 Module: foo only main also std.mlContext! also foo also definitions BeginModule p" objects.mh" "load variable queuetask \ Brain->Engine Message related variables fvariable start_time \ Start-time of current task fvariable end_time \ The time this task should end fvariable curr_task \ The current task variable braintask \ Message header: BeginStruct Int msgCode Float startTime Float endTime Struct msgHead \ msgPickUp / msgLayDown / msgEatUp uses this struct BeginStruct 1 msgHead pcHead Int pcObject Struct Pick variable nut variable self \ This meme will eventually return the ground level for a given x,z \ coordinate pair. : GroundLevel fdrop fdrop 0e ; : queue_manager begin fGetTime fdup end_time f@ f> if curr_task @ sleep then \ To be implemented: Get next item in queue... fdrop pause again ; \ The "brain" of the nut.... fvariable dropTime fvariable startY fvariable pitchSpin fvariable XMove fvariable XOrigin fvariable ZMove fvariable ZOrigin fvariable tNow fvariable bounceStart fvariable overShoot variable dropping 9.81e fconstant g : brain begin fGetTime tNow f! \ Plunge it into a variable... startY f@ 0e f= if self @ y@ startY f! self @ x@ XOrigin f! self @ z@ ZOrigin f! then dropping @ if tNow f@ bounceStart f@ f- fdup XMove f@ f* XOrigin f@ f+ self @ x! ZMove f@ f* ZOrigin f@ f+ self @ z! self @ pitchSpin f@ pitch+! \ Ain't so bloody picky! :-) startY f@ tNow f@ dropTime f@ f- fdup f* g f* f- fdup 0.0e f> if 0.3e f+ self @ y! else fdrop \ Loose the Y 0.3e self @ y! \ Ground it, no matta what! \ Calculate exact hit time dropTime f@ startY f@ g f/ fsqrt f+ \ Difference it from current time tNow f@ fswap f- overShoot f! startY f@ 0.5e frand f* f* startY f! \ startY *= 0.5 * frand startY f@ 0.1e f< if 0 dropping ! 50e tNow f@ f+ dropTime f! \ Suicide in 50 seconds... else \ Calculate new droptime startY f@ g f/ fsqrt tNow f@ f+ overShoot f@ f+ dropTime f! frand 100e f* 50e f- pitchSpin f! frand 0.5e f- 8e f* XMove f! frand 0.5e f- 8e f* ZMove f! self @ x@ XOrigin f! self @ z@ ZOrigin f! tNow f@ bounceStart f! then then else \ tNow f@ dropTime f@ f> if \ self @ DestroyObject \ Commit suicide... \ then then pause again ; variable msg \ Da Message receiver.... : rcvr msg ! \ Store the freaki'n adress, we'll bloody need it! :-) msg @ mhMsgBody @ case -1024 of \ The "What Are You" message objNut msg @ mhMsgBody ! endof -1025 of \ The "I picked you up" message 0 dropping ! endof -1026 of \ The "I let you go" message 1 dropping ! 0e startY f! \ Forces it to recalculate the drop... (see brain code) endof dup dup of ." Nut received unknown message" . endof endcase ; TheReceiverMemeIs rcvr : go if \ Calculate the self object (The Compound object I am) moduleOrigin WhichObject self ! ModuleWorld lockedLink plainVisible c" http://www.immersive.com/sq/nut.rwx" NewVisible nut ! nut @ if fGetTime dropTime f! 1 dropping ! 0e startY f! ['] brain NewTask ?dup if dup braintask ! wake then then else nut @ ?dup if DestroyObject then braintask @ ?dup if DestroyTask then then ; TheGoMemeIs go ModuleUsed EndModule only main also definitions .( Writing nut.mm ) ' foo ModuleAddr p" nut.mm" UnloadModuleToFile forget foo