Example #1
0
        // runs the simulation
        public void startSimulation()
        {
            stop = false;
            TcpClient tcpClient = new TcpClient("127.0.0.1", 4500);
            String    line = fileLoader.GetCSVLine(stateController.CurrentIndexOfLine);
            int       millisecondsPerFrame, startTime, usedTime, milliSecondLeftToSleep;

            while (line != null)
            {
                startTime            = DateTime.Now.Millisecond; // for timing
                millisecondsPerFrame = speedController.getTimeToSleep();

                // show next shot
                stateController.CurrentIndexOfLine = stateController.CurrentIndexOfLine + 1;
                Byte[]        data   = System.Text.Encoding.ASCII.GetBytes(line);
                NetworkStream stream = tcpClient.GetStream();
                stream.Write(data, 0, data.Length);

                // sleep the rest of the time (if needed)
                usedTime = DateTime.Now.Millisecond - startTime;
                milliSecondLeftToSleep = millisecondsPerFrame - usedTime;
                if (milliSecondLeftToSleep > 0)
                {
                    Thread.Sleep(speedController.getTimeToSleep());
                }
            }
        }
 public string GetCSVLine(int x)
 {
     return(model.GetCSVLine(x));
 }