// ================= PUBLIC FACING ================== //


    // ----------------------------------------------------
    // name: ListenForEvent
    // desc: start checking chuck for eventToListenFor so
    //       that callback will be called when the event
    //       broadcasts (or signals, if it's its turn)
    // ----------------------------------------------------
    public void ListenForEvent(ChuckSubInstance chuck, string eventToListenFor, Action callback)
    {
        // cancel existing if it's happening
        StopListening();

        // start up again
        myVoidCallback = Chuck.CreateVoidCallback(MyCallback);
        userCallback   = callback;
        myChuck        = chuck;
        myEventName    = eventToListenFor;
        myChuck.StartListeningForChuckEvent(myEventName, myVoidCallback);
    }
Exemple #2
0
    // Use this for initialization
    void Start()
    {
        newRound        = true;
        otherReady      = false;
        startTheTicker  = false;
        sent1000        = false;
        goToNextStep    = false;
        instructionMesh = (TextMesh)instructionText.GetComponent(typeof(TextMesh));

        prevBeat       = 0;
        beat           = 0;
        timeOfLastBeat = 0;
        beatBufferTime = .09f;
        prevBeatLength = 0;

        currLetter = 0;
        linePos    = 0.0f;

        topColor     = new Color32(255, 56, 129, 255);
        bottomColor  = new Color32(63, 56, 255, 255);
        correctColor = new Color32(56, 224, 101, 255);

        myChuck          = GetComponent <ChuckInstance> ();
        myGetIntCallback = Chuck.CreateGetIntCallback(GetIntCallback);
        myCallback       = Chuck.CreateVoidCallback(NewMessageReceived);
        message          = -1;
        newMessage       = false;

        mainScript = main.GetComponent <MainController> ();

        initialTickerX = ticker.transform.position.x;

        for (int i = 0; i < acceptableKeys.GetLength(0); i++)
        {
            acceptableKeys[i, 2] = (i + 72).ToString();
        }
        //set space to none
        acceptableKeys[acceptableKeys.GetLength(0) - 1, 2] = "0";

        //create container to have new keys added
        currKeysTop = new GameObject("currKeysTop");
        currKeysTop.AddComponent <MeshFilter>();
        currKeysTop.AddComponent <MeshRenderer>();
        currKeysBottom = new GameObject("currKeysBottom");
        currKeysBottom.AddComponent <MeshFilter>();
        currKeysBottom.AddComponent <MeshRenderer>();
    }
Exemple #3
0
    // Use this for initialization
    void Start()
    {
        myChuck            = GetComponent <ChuckSubInstance>();
        myGetPosCallback   = Chuck.CreateGetFloatCallback(GetPosCallback);
        myTimeStepCallback = Chuck.CreateVoidCallback(BeNotified1);

        myPos = 0;

        myChuck.RunCode(@"
			1 => global float timeStep;
			global float pos;
			global Event notifier;

			fun void updatePos() {
				timeStep::second => dur currentTimeStep;
				currentTimeStep / 1000 => dur deltaTime;
				now => time startTime;
				
				pos => float originalPos;
								
				while( now < startTime + currentTimeStep )
				{
					deltaTime / currentTimeStep +=> pos;
					deltaTime => now;
				}
			}
			

			fun void playNote() {
				SinOsc foo => dac;
				0.2::second => now;
				foo =< dac;
			}

			while( true )
			{
				spork ~ playNote();
				spork ~ updatePos();
				notifier.broadcast();
				timeStep::second => now;
			}
		"        );

        myChuck.StartListeningForChuckEvent("notifier", myTimeStepCallback);
    }
Exemple #4
0
    void Start()
    {
        // get reference to chuck instance
        myChuck = GetComponent <ChuckSubInstance>();
        // create the callback we will pass
        myCallback = Chuck.CreateVoidCallback(CallbackFunction);

        // run code: make a global event, and every 250 ms, broadcast it to all listeners
        myChuck.RunCode(@"
			global Event notifier;
			while( true )
			{
				notifier.broadcast();
				250::ms => now;
			}
		"        );

        // register myCallback as a listener of Event "notifier" until I tell it to stop
        myChuck.StartListeningForChuckEvent("notifier", myCallback);
    }
Exemple #5
0
 // ----------------------------------------------------
 // name: CreateVoidCallback
 // desc: create the callback necessary for waiting on
 //       chuck events
 // ----------------------------------------------------
 public Chuck.VoidCallback CreateVoidCallback(Action callbackFunction)
 {
     return(Chuck.CreateVoidCallback(callbackFunction));
 }