isConnected() public method

public isConnected ( ) : bool
return bool
Example #1
0
 // Use this for initialization
 void Start()
 {
     client = new TuioClient(port);
     client.addTuioListener(this);
     client.connect();
     Debug.Log (client.isConnected());
 }
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Moves starting window location
            myForm = (System.Windows.Forms.Form)System.Windows.Forms.Control.FromHandle(this.Window.Handle);
            myForm.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
            myForm.Location = new System.Drawing.Point(0, 0);

            // Explicitly set number of samples for antialiasing; may not be necessary
            //GraphicsDevice.PresentationParameters.MultiSampleCount = 16;
            //Debug.WriteLine(graphicsDevice.PresentationParameters.MultiSampleCount);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            //planktonTarget = new RenderTarget2D(GraphicsDevice, (int)(CIRCLE_RADIUS + CIRCLE_RADIUS_OVERSCAN) * 2, (int)(Game1.CIRCLE_RADIUS + Game1.CIRCLE_RADIUS_OVERSCAN) * 2);

            // Create a new renderTarget to prerender before drawing on screen.
            PresentationParameters pp = GraphicsDevice.PresentationParameters;
            fullScreenTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, GraphicsDevice.DisplayMode.Format, DepthFormat.Depth24);

            maskTextureArray = new Color[(int)((Settings.CIRCLE_RADIUS + Settings.CIRCLE_RADIUS_OVERSCAN) * 2 * (Settings.CIRCLE_RADIUS + Settings.CIRCLE_RADIUS_OVERSCAN) * 2)];

            subtractAlpha = new BlendState();
            subtractAlpha.AlphaBlendFunction = BlendFunction.ReverseSubtract;
            subtractAlpha.AlphaSourceBlend = Blend.One;
            subtractAlpha.AlphaDestinationBlend = Blend.One;
            subtractAlpha.ColorBlendFunction = BlendFunction.ReverseSubtract;
            subtractAlpha.ColorSourceBlend = Blend.One;
            subtractAlpha.ColorDestinationBlend = Blend.One;

            // Initialize tools
            for (int i = 0; i < Settings.NUM_NUTRIENTTOOLS; i++)
            {
                nutrientTools.Enqueue(new NutrientTool(new Vector2(50, 350 + 100 * i)));
            }

            for (int i = 0; i < Settings.NUM_TEMPTOOLS; i++)
            {
                tempTools.Enqueue(new TempTool(new Vector2(50, 150 + i * 100)));
            }

            // Add datanames to the list
            //"T", "SiO2", "POSi"
            dataNames = new List<string>() { "PhyGrp1", "PhyGrp3", "PhyGrp4", "PhyGrp5" }; // PhyGrp data needs to be the first four
            if (Settings.SHOW_LIGHT)
                dataNames.Add("PAR");
            if (Settings.SHOW_NITRATE)
                dataNames.Add("NO3");
            if (Settings.SHOW_TEMP || Settings.NUM_TEMPTOOLS > 0)
                dataNames.Add("T");
            if (Settings.SHOW_SILICA || Settings.NUM_NUTRIENTTOOLS > 0)
                dataNames.Add("SiO2");

            // Set up data structure for all the data
            for (int i = 0; i < dataNames.Count; i++)
                theData.Add(dataNames[i], new Dictionary<int, byte[]>());

            // Draw a loading rectangle
            GraphicsDevice.Clear(Color.CornflowerBlue);
            spriteBatch.Begin();
            spriteBatch.DrawRectangle(new Rectangle(0, 0, 100, 100), Color.White);
            spriteBatch.End();
            base.Draw(new GameTime());

            // Load data from files
            FileStream[] fileStreams = new FileStream[dataNames.Count];
            for (int timestamp = 52704; timestamp <= 210384; timestamp += 1080)
            {
                Debug.WriteLine(string.Format("Reading data, {0}% complete...", ((float)timestamp - 52704.0) * 100.0 / (210384.0 - 52704.0)));

                for (int i = 0; i < dataNames.Count; i++)
                {
                    //// Read data from file into a float array
                    //float[] floats = new float[583200/4];
                    //byte[] fourBytes = new byte[4];
                    //fileStreams[i] = new FileStream(string.Format("Data\\{0}_{1}.data", dataNames[i], timestamp), FileMode.Open);
                    //Debug.WriteLine(string.Format("Reading {0}_{1}.data...", dataNames[i], timestamp));

                    //for (int j = 0; j < 583200/4; j++)
                    //{
                    //    // Read four bytes from the file
                    //    for (int k = 0; k < 4; k++)
                    //        fourBytes[k] = (byte)fileStreams[i].ReadByte();

                    //    // Convert four bytes to float (big-endian, so reverse it)
                    //    floats[j] = BitConverter.ToSingle(fourBytes.Reverse().ToArray(), 0);

                    //    // Check for NaN's
                    //    if (float.IsNaN(floats[j]))
                    //        floats[j] = 0;
                    //}

                    //// Add float data to the data structure
                    //theData[dataNames[i]].Add(timestamp, floats);

                    //// Done with this file
                    //fileStreams[i].Close();

                    // Read data from file
                    byte[] bytes = new byte[583200];
                    float[] floats = new float[583200 / 4];
                    byte[] fourBytes = new byte[4];
                    fileStreams[i] = new FileStream(string.Format("Data\\{0}_{1}.data", dataNames[i], timestamp), FileMode.Open);

                    // Read data from file into a byte array
                    fileStreams[i].Read(bytes, 0, 583200);

                    // Done with this file
                    fileStreams[i].Close();

                    //// Convert byte array to float array
                    //for (int j = 0; j < 583200 / 4; j++)
                    //{
                    //    // Read four bytes from the file
                    //    for (int k = 0; k < 4; k++)
                    //        fourBytes[k] = bytes[j*4+k];

                    //    // Convert four bytes to float (big-endian, so reverse it)
                    //    floats[j] = BitConverter.ToSingle(fourBytes.Reverse().ToArray(), 0);

                    //    // Check for NaN's
                    //    if (float.IsNaN(floats[j]))
                    //        floats[j] = 0;
                    //}

                    // Add byte array to the data structure
                    theData[dataNames[i]].Add(timestamp, bytes);

                }
                //Debug.WriteLine(timestamp);

                //// Save phytoplankton group distributions in a dictionary of timestamps
                //byte[][] values = new byte[4][];
                //for (int i = 0; i < 4; i++)
                //{
                //    values[i] = new byte[583200];
                //    fileStreams[i].Read(values[i], 0, 583200);
                //    fileStreams[i].Close();
                //}

                //phygrpData.Add(timestamp, values);

                // Load landmask data from file
                FileStream landmaskFS = new FileStream("Data\\landmask-2-540x270.data", FileMode.Open);
                landmaskFS.Read(landmaskArray, 0, 583200);
                landmaskFS.Close();
            }

            base.Initialize();

            // Initialize a TUIO client and set this LivingLiquid instance as a listener
            tuioClient = new TuioClient(3333);
            //Debug.WriteLine("Removing all TUIO listeners...");
            //tuioClient.removeAllTuioListeners();
            //Debug.WriteLine("Disconnecting TUIO client...is connected: " + tuioClient.isConnected());
            //tuioClient.disconnect();
            Debug.WriteLine("Adding TUIO listener......is connected: " + tuioClient.isConnected());
            tuioClient.addTuioListener(this);
            Debug.WriteLine("Connecting TUIO client...is connected: " + tuioClient.isConnected());
            tuioClient.connect();
            Debug.WriteLine("TUIO client connected: " + tuioClient.isConnected());

            // Initialize Tuio Time
            TuioTime.initSession();

            // Flag ready for input
            this.readyForInput = true;

            // Because the movie has greater than a 2:1 aspect ratio, need to vertically center on screen
            // This section locates a rectangle on screen where the movie should be displayed
            // (unless we're using a really weird narrow screen, in which case, redo this section)
            movieScale = (float)GraphicsDevice.Viewport.Width / (float)(video.Width);
            float movieScaledHeight = (float)(video.Height * movieScale);
            movieVerticalOffset = (GraphicsDevice.Viewport.Height - movieScaledHeight) / 2;
            movieDestination = new Rectangle(GraphicsDevice.Viewport.X,
                (int)(GraphicsDevice.Viewport.Y + movieVerticalOffset),
                GraphicsDevice.Viewport.Width,
                (int)movieScaledHeight);

            InitializeCircles();
        }