Example #1
0
        public override CtrlAction handleCtrlMsg(Message msg)
        {
            var t = msg.type;
            if (t == Const.kGraphSwitch) {
                var name = (msg.data ["graph_name"]).ToString ();
                var index = 0;
                if (name == "land_temp") {
                    index = 1;

                } else if (name == "snow_cover") {
                    index = 2;

                } else if (name =="precipitation") {
                    index = 3;

                } else {
                    index = 0;
                }
                return delegate{
                    SwapEarth(index);
                };

            } else if (t == Const.kGraphWordmap) {
                var enabled = (bool)msg.data ["enabled"];
                if (enabled) {
                    return new CtrlAction (OpenWorldmap);

                } else {
                    return new CtrlAction (CloseWorldmap);
                }

            } else if (t == Const.kEarthRotate) {

                var velocity = (float)msg.data ["velocity"];
                if (velocity > 0.01) {
                    return new CtrlAction (StartRotation);

                } else {
                    return new CtrlAction (StopRotation);
                }

            } else if (t == Const.kEarthTimeAnimation) {

            } else {
                Debug.Log ("Unsupported " + t);
            }

            return null;
        }
Example #2
0
        public void handleMessage(Message msg)
        {
            print ("Receive: " + msg.Marshal ());

            if (msg.type == Const.kHandshakeAccept) {
                if (status == kStatusConnecting) {
                    id = msg.peer_id;
                } else {
                    Debug.LogError ("Unexpected handshake accept: " + msg.type);
                }

            } else if (msg.type == Const.kHandshakeError) {
                if (status == kStatusConnecting && connectingRetries < maxConnectingRetries) {
                    connectingRetries += 1;
                    Debug.LogError ("Handshake error. Retry " + connectingRetries + "/" + maxConnectingRetries + ": " + msg.type);

                    this.Invoke ("setupSocket", 500);
                    closeSocket ();
                    status = kStatusDisconnected;

                } else {
                    Debug.LogError ("Handshake error. Disconnected: " + msg.type);
                }

            } else if (msg.type == Const.kHandshakeClose) {
                Debug.Log ("Receive handshake close");
                status = kStatusDisconnected;
                closeSocket ();

            } else if (msg.type.StartsWith (Const.kHandshake)) {
                Debug.LogWarning ("Unknown handshake message: " + msg.type);

            } else if (msg.type == Const.kAck) {
                // Do nothing

            } else {
                handleControlMessage (msg);
            }
        }
Example #3
0
        void handleControlMessage(Message msg)
        {
            try {
                var action = ctrl.handleCtrlMsg (msg);
                if (action != null) {
                    queue.Enqueue (action);
                }

            } catch (Exception e) {
                Debug.LogError (e);
            }
        }
Example #4
0
        public void setupSocket()
        {
            try {
                mySocket = new TcpClient (Host, Port);
                theStream = mySocket.GetStream ();
                theWriter = new StreamWriter (theStream);
                theReader = new StreamReader (theStream);
                socketReady = true;

                status = kStatusConnecting;

                // connect or reconnect
                if (id == 0) {
                    Debug.Log ("Connecting...");
                    Message msg = new Message (Const.kHandshakeConnect, Const.kRoleApp);
                    msg.channel_name = channelName;
                    sendMessage (msg);

                } else {
                    Debug.Log ("Reconnecting...");
                    Message msg = new Message (Const.kHandshakeReconnect, Const.kRoleApp);
                    msg.peer_id = id;
                    msg.channel_name = channelName;
                    sendMessage (msg);

                }

            } catch (Exception e) {
                Debug.Log ("Socket error:" + e);
            }
        }
Example #5
0
 public void sendMessage(Message msg)
 {
     string s = msg.Marshal ();
     Debug.Log ("Send message: " + s);
     writeSocket (s);
 }
Example #6
0
        void handleCtrllerMsg(Message msg)
        {
            var t = msg.type;
            if (t == Const.kGraphSwitch) {
                var name = (msg.data ["graph_name"]).ToString ();
                //                var name = "";
                if (name == "land_temp") {
                    //                                      Invoke ("ShowLandTemp", 0);
                    queue.Enqueue ("show_temp");

                } else {
                    //                                      Invoke ("ShowEarth", 0);
                    queue.Enqueue ("show_earth");
                }

            } else if (t == Const.kEarthMoveTo) {
                string location = (string)msg.data ["location"];
                string time = (string)msg.data ["time"];

                if (location != "") {
                    // us, china, vietnam, biendong, southem, northem
            //                    if (location == "us") {
            //                        CameraController.GetComponent<CameraController> ().PointToUS ();
            //
            //                    } else if (location == "china") {
            //                        CameraController.GetComponent<CameraController> ().PointToChina ();
            //
            //                    } else if (location == "vietnam") {
            //                        CameraController.GetComponent<CameraController> ().PointToVietnam ();
            //
            //                    } else if (location == "biendong") {
            //                        CameraController.GetComponent<CameraController> ().PointToBienDong ();
            //
            //                    } else if (location == "southem") {
            //                        CameraController.GetComponent<CameraController> ().PointToSouthem ();
            //
            //                    } else if (location == "northem") {
            //                        CameraController.GetComponent<CameraController> ().PointToNorthem ();
            //
            //                    } else {
            //                        print ("Not support location " + location);
            //                    }
                }

                if (time != "") {
                    var day = int.Parse (time.Substring (0, 2));
                    var month = int.Parse (time.Substring (3, 5));
                    var year = int.Parse (time.Substring (6, 10));
                    DateTime date = new DateTime (year, month, day);
                    var d = date.Subtract (baseDate).Days;

                    print ("date " + d / 5);
                    var d2 = (int)d / 5;
                    d2 = d2 < 0 ? 0 : d2;
                    d2 = d2 >= maxTime ? maxTime : d2;
                    GetMatChanger().SetCurTexIndex (d2);
                }

                float delta_time = (float)msg.data;
                if (delta_time > 0) {

                    //                                      Invoke ("TimeForward", 0);
                    queue.Enqueue ("time_forward");

                } else if (delta_time < 0) {

                    //                                      Invoke ("TimeBackward", 0);
                    queue.Enqueue ("time_backward");

                }

            } else if (t == Const.kEarthRotate) {
                var delta = (float)msg.data ["delta"];
                print ("delta " + delta);
                int deltaInt = (int)delta;

                if (deltaInt > 0) {
                    for (int i=0; i<deltaInt; i++) {
                        //                                              Invoke ("RotateLeft", 0);

                        queue.Enqueue ("rotate_left");
                    }

                } else {
                    for (int i=0; i > deltaInt; i--) {
                        //                                              Invoke ("RotateRight", 0);
                        //                                              CameraController.GetComponent<CameraController> ().RotateRight (0);
                        queue.Enqueue ("rotate_right");
                    }
                }

            } else if (t == Const.kEarthTimeAnimation) {

            } else {
                print ("Unsupported " + t);
            }
        }
Example #7
0
        void handleControlMessage(Message msg)
        {
            var app = AppState.getInstance ();
            var config = AppState.getConfig ();
            var earth = AppState.getConfig ();
            var leap = AppState.getLeap ();

            if (msg.role == Const.kRoleLeap) {

            } else if (msg.role == Const.kRoleController) {
                handleCtrllerMsg (msg);

            } else {
                Debug.LogWarning ("Unknown control message: " + msg.type);
            }
        }
Example #8
0
		public void Sync(Message data){_Sync (data);}
Example #9
0
 public abstract CtrlAction handleCtrlMsg(Message msg);
Example #10
0
        public CtrlAction handleCtrlMsg_backup(Message msg)
        {
            var t = msg.type;
                if (t == Const.kGraphSwitch) {
                    var name = (msg.data ["graph_name"]).ToString ();
                    if (name == "land_temp") {
                        return new CtrlAction (ShowLandTemp);

                    } else if (name == "snow_cover") {
                        return new CtrlAction (ShowSnowCover);

                    } else {
                        return new CtrlAction (ShowEarth);
                    }

                } else if (t == Const.kGraphWordmap) {
                    var enabled = (bool)msg.data ["enabled"];
                    if (enabled) {
                        return new CtrlAction (OpenWorldmap);

                    } else {
                        return new CtrlAction (CloseWorldmap);
                    }

                } else if (t == Const.kEarthMoveTo) {
                    string location = (string)msg.data ["location"];
                    string time = (string)msg.data ["time"];

                    CtrlAction moveTo = null;
                    if (location != "") {

                        // us, china, vietnam, biendong, southem, northem
                        if (location == "us") {
                            moveTo = delegate {
                                cameraController.PointToUS ();
                            };

                        } else if (location == "china") {
                            moveTo = delegate {
                                cameraController.PointToChina ();
                            };

                        } else if (location == "vietnam") {
                            moveTo = delegate {
                                cameraController.PointToVietnam ();
                            };

                        } else if (location == "biendong") {
                            moveTo = delegate {
                                cameraController.PointToBienDong ();
                            };

                        } else if (location == "southem") {
                            moveTo = delegate {
                                cameraController.PointToSouthem ();
                            };

                        } else if (location == "northem") {
                            moveTo = delegate {
                                cameraController.PointToNorthem ();
                            };

                        } else {
                            Debug.Log ("Not support location " + location);
                        }
                    }
                    if (moveTo != null) {
                        return moveTo;
                    }

                    if (time != "") {
                        var day = int.Parse (time.Substring (0, 2));
                        var month = int.Parse (time.Substring (3, 5));
                        var year = int.Parse (time.Substring (6, 10));
                        DateTime date = new DateTime (year, month, day);
                        var d = date.Subtract (baseDate).Days;

                        Debug.Log ("date " + d / 5);
                        var d2 = (int)d / 5;
                        d2 = d2 < 0 ? 0 : d2;
                        d2 = d2 >= maxTime ? maxTime : d2;
                        earthController.SetTexIndex (d2);
                    }

                    float delta_time = (float)msg.data;
                    if (delta_time > 0) {
                        return new CtrlAction (TimeForward);

                    } else if (delta_time < 0) {
                        return new CtrlAction (TimeBackward);

                    }

                } else if (t == Const.kEarthRotate) {

                    var velocity = (float)msg.data ["velocity"];
                    if (velocity > 0.01) {
                        return new CtrlAction (StartRotation);

                    } else {
                        return new CtrlAction (StopRotation);
                    }

            //                var delta = (float)msg.data ["delta"];
            //                int deltaInt = (int)delta;
            //
            //                if (deltaInt > 0) {
            //                    for (int i=0; i<deltaInt && i < 20; i++) {
            //                        returnnew CtrlAction(RotateLeft));
            //                    }
            //
            //                } else {
            //                    for (int i=0; i > deltaInt && i > -20; i--) {
            //                        returnnew CtrlAction(RotateLeft));
            //                    }
            //                }

                } else if (t == Const.kEarthTimeAnimation) {
                    // TODO

                } else {
                    Debug.Log ("Unsupported " + t);
                }

            return null;
        }
Example #11
0
 public override CtrlAction handleCtrlMsg(Message msg)
 {
     // Do nothing
     return null;
 }