Example #1
0
 // Function: Send
 //        (Internal) Sends a message (or address+values) to the daemon, with the bezel address prepended
 public void Send(GhopperMessage message)
 {
     message.address = GhopperDaemon.BEZEL_API_ADDRESS + message.address;
     daemon.Send(message.address, message.values);
 }
Example #2
0
 // Function: OnReceiveOsc
 // 		Private. Takes in osc messages and routes them to internal sorting for /tuio/ (as OSC) or /ghpr/ (converted to <GhopperMessage>).
 void OnReceiveOsc(OSCMessage message)
 {
     //		DebugExtras.Log("OnReceiveOsc!");
     //		if (message.Address.StartsWith(TOUCH_INPUT_ADDRESS)) {
     //			OnReceiveTuio(message);
     //		} else
     if (message.Address.StartsWith(GRASSHOPPER_API_ADDRESS)) {
         GhopperMessage ghMessage = new GhopperMessage(message.Address, message.Values);
         OnReceiveDaemonMessage(ghMessage);
     } else {
         OnReceiveOtherOsc(message);
     }
 }
Example #3
0
 // Function: AddPendingCall
 //        Internal. Stores an outgoing message to send it later. Called by <TellBezel> if the template hasn't finished loading.
 void AddPendingCall(string callAddress, ArrayList values)
 {
     //		DebugExtras.Log("Add Pending Call");
     GhopperMessage message = new GhopperMessage();
     message.address = callAddress;
     message.values = values;
     pendingMessages.Add(message);
 }
Example #4
0
    // Function: GeneratePlayerAddMessage
    //        (Internal) Used by <TriggerSampleStartup>.
    GhopperMessage GeneratePlayerAddMessage(int playerNum)
    {
        int playerPosition = Mathf.CeilToInt( playerNum * (360 / 6) );
        int playerColor = (int)Mathf.Floor((Random.value * 2 - 1) * int.MaxValue);
        string playerFirstName = "Figment";
        string playerLastName = "#" + playerNum.ToString();

        GhopperMessage message = new GhopperMessage();
        ArrayList messageValues = message.values;
        string address = PLAYER_API_ADDRESS + playerNum.ToString() + "/add";

        message.address = address;
        messageValues.Add("daemon");
        messageValues.Add(playerPosition);
        messageValues.Add(playerFirstName);
        messageValues.Add(playerLastName);
        messageValues.Add(playerColor);

        return message;
    }
Example #5
0
 // Function: GenerateReadyMessage
 //        (Internal) Used by <TriggerSampleStartup>.
 GhopperMessage GenerateReadyMessage()
 {
     GhopperMessage message = new GhopperMessage();
     message.address = GAME_API_ADDRESS + "ready";
     message.values.Add("daemon");
     return message;
 }
Example #6
0
    public void RouteDaemonMessage(GhopperMessage message)
    {
        GhopperMessageHandler handler = null;
        int longestAddressLength = 0;

        // find best-matching address, and send the message to the handler for that address
        foreach (string address in ghAddressTable.Keys) {
            // find the longest partial match for address (could stand to be optimized)
            if (message.address.StartsWith(address) && address.Length > longestAddressLength) {
                longestAddressLength = address.Length;
                handler = (GhopperMessageHandler)ghAddressTable[address];
            }
        }
        if (handler != null) {
            handler(message);
        } else {
            DebugExtras.LogWarning("No handler found for this address: "+message.address);
        }
    }
Example #7
0
    // Function: OnReceivePlayerEvent
    // 		(Internal) Receives /ghpr/player/ messages and triggers the appropriate <gameEventReceiver> method, passing along the salient values.
    public void OnReceivePlayerEvent(GhopperMessage message)
    {
        string[] signature = message.address.Substring(PLAYER_API_ADDRESS.Length).Split(ADDRESS_SEPARATOR);
        int playerId = int.Parse(signature[0]);
        string method = signature[1];
        ArrayList values = message.values;

        if (method == "add") { // vars: (message sender--ignore this), id (int), angle (int), first name (string), last name (string), color (int)
            GhopperEnv.OnAddPlayer(playerId, (int)values[1], values[2].ToString(), values[3].ToString(), (int)values[4]);
        //			gameEventReceiver.OnAddPlayer(playerId, (int)values[1], values[2].ToString(), values[3].ToString(), (int)values[4]);
        } else if (method == "remove") { // vars: (none)
            GhopperEnv.OnRemovePlayer(playerId);
        //			gameEventReceiver.OnRemovePlayer(playerId);
        } else {
            DebugExtras.LogWarning("Unrecognized player api method: " + method);
        }
    }
Example #8
0
 // Function: OnReceiveGameEvent
 // 		(Internal) Receives /ghpr/game/ messages and triggers the appropriate <gameEventReceiver> method, passing along the salient values.
 //        (Also handles offset internally. Maybe this message should be moved to a different address? '/ghpr/screen/', perhaps?)
 public void OnReceiveGameEvent(GhopperMessage message)
 {
     string[] signature = message.address.Substring(GAME_API_ADDRESS.Length).Split(ADDRESS_SEPARATOR);
     string method = signature[0];
     ArrayList values = message.values;
     if (method == "ready") { // vars: (none)
         TuioTrackingComponent.ResetScreenScale();
         gameEventReceiver.OnReady();
     } else if (method == "pause") { // vars: (none)
         gameEventReceiver.OnPause();
     } else if (method == "unpause") { // vars: (none)
         gameEventReceiver.OnUnpause();
     } else if (method == "offset") { // vars: (x offset, y offset) -- NOTE: the daemon will handle this on its own
         OnReceiveScreenOffset((int)values[1], (int)values[2]);
     } else {
         DebugExtras.LogWarning("Unrecognized game api method: " + method);
     }
 }
Example #9
0
 // Function: OnReceiveDaemonMessage
 // 		(Internal) Takes in <GhopperMessage>s received from the daemon and routes them to the handler associated with their address.
 public void OnReceiveDaemonMessage(GhopperMessage message)
 {
     lock ( ghMessageLock ) {
         incomingMessages.Add(message);
     }
 }
Example #10
0
 // Function: OnReceiveBezelEvent
 // 		(Internal) Receives /ghpr/bezel/ messages and sends them to the bezel instance for further parsing.
 public void OnReceiveBezelEvent(GhopperMessage message)
 {
     string eventAddress = message.address.Substring(BEZEL_API_ADDRESS.Length);
     bezel.OnReceiveBezelMessage(eventAddress, message.values);
 }