\ \ This defines a TREE that once in a while can decide to release NUTS. \ \ Compound object modules: \ nut.mm \ Object files \ halftree.rwx The stem of the tree \ headtree.rwx The crown of the tree \ Headers: \ objects.mh \ 3100 Module: foo only main also std.mlContext! also foo also definitions BeginModule p" objects.mh" "load variable queuetask \ For the "appearance flash" variable appeartask variable l1 variable l2 \ 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 self \ The Self object variable tree variable leaves \ 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 tree.... fvariable nextdrop fvariable radius fvariable angle variable nut : appear begin pause l1 @ ?dup if DestroyObject 0 l1 ! then l2 @ ?dup if DestroyObject 0 l2 ! then appeartask @ sleep pause again ; \ Structure of a "What are you" message BeginStruct Int wauMsgNum Struct WAUMsg \ Create the "what are u" message buffer create myMsg SizeOf MsgHeader SizeOf WAUMsg + dup allot myMsg mhMsgLen ! : IsANut? \ objaddr -- flag ptr @ myMsg mhDestModuleID ! moduleOrigin myMsg mhSrcModuleID ! localHost dup myMsg mhSrcHostID ! myMsg mhDestHostID ! -1024 myMsg mhMsgBody ! myMsg SendMessage drop myMsg mhMsgBody @ objNut = ; \ Return the number of nuts in the object array \ -- #nuts : #nuts { ; curobj curobjaddr sofar numobjs numnuts -- } #objects to numobjs begin numobjs sofar > while curobj dup 1+ to curobj object dup to curobjaddr used @ if \ If object is used sofar 1+ to sofar \ Increment count of objs so far curobjaddr objecttype @ compoundObject = if \ If compound object curobjaddr IsANut? \ Ask if it's a nut if \ If it's a nut numnuts 1+ to numnuts \ Increment number of nuts then then then repeat numnuts ; \ When there are 0 nuts, give a delay time of 10 seconds. \ When there are 30 nuts, give a delay time of 90 seconds. \ seconds = 8/3 * nuts + 10 : NutSeparation \ -- delaytime #nuts ( .s ) float \ convert to floating point 8e f* 3e f/ 10e f+ ( f.s ) ; : brain begin fGetTime nextdrop f@ f> \ If time for the next nut if frand 1.5e f+ 1.5e f* radius f! frand 6.28e f* angle f! \ Use same parent as the tree... self @ parent @ lockedLink c" http://www.immersive.com/sq/nut.mm" NewCompound nut ! nut @ if self @ x@ angle f@ fsin radius f@ self @ xscale@ f* f* f+ nut @ x! self @ z@ angle f@ fcos radius f@ self @ zscale@ f* f* f+ nut @ z! self @ y@ 10e self @ yscale@ f* f+ nut @ y! 360e frand f* nut @ yaw! then NutSeparation frand f* fGetTime f+ nextdrop f! 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 \ ." Tree got the WAU message" objTree msg @ mhMsgBody ! endof dup dup of ." Tree 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/halftree.rwx" NewVisible tree ! tree @ if tree @ lockedLink plainVisible c" http://www.immersive.com/sq/headtree.rwx" NewVisible leaves ! leaves @ if leaves @ fdup 12e fswap 1.5e f/ f/ y! leaves @ scale then tree @ lockedLink pointLight NewLight l1 ! 5e l1 @ x! 4e l1 @ y! l1 @ 0.4e 0.9e 0.6e LightColor tree @ lockedLink pointLight NewLight l2 ! -5e l2 @ x! 4e l2 @ y! l2 @ 0.4e 0.6e 0.9e LightColor fGetTime NutSeparation frand f* f+ nextdrop f! ['] brain NewTask ?dup if dup braintask ! wake then ['] appear NewTask ?dup if dup appeartask ! wake then then else tree @ ?dup if DestroyObject then leaves @ ?dup if DestroyObject then braintask @ ?dup if DestroyTask then appeartask @ ?dup if DestroyTask then then ; TheGoMemeIs go ModuleUsed EndModule only main also definitions .( Writing tree.mm ) ' foo ModuleAddr p" tree.mm" UnloadModuleToFile forget foo