Beispiel #1
0
        /// <summary>
        /// See <see cref="IEtsInterface.Open"/>
        /// </summary>
        public void Open()
        {
            Log.Verbose("ETSI: Starting client...");
            string etsiLogFile = Log.Instance.FilePath.Replace(".log", " etsi.log");

            System.Diagnostics.Process client = new System.Diagnostics.Process();
            client.StartInfo.FileName         = "py";
            client.StartInfo.Arguments        = "start_server.py > " + etsiLogFile;
            client.StartInfo.WorkingDirectory = etsiPath;
            client.StartInfo.CreateNoWindow   = !showConsoleWindow;
            client.Start();

            Log.Verbose("ETSI: Starting server...");
            server = new Socket(SocketType.Stream, ProtocolType.Tcp);
            server.Bind(new IPEndPoint(new IPAddress(Ip), Port));
            //server.ReceiveTimeout = TIMEOUT;
            //server.SendTimeout = TIMEOUT;
            server.Listen(1);

            Log.Verbose("ETSI: Waiting for physical interface connection...");
            socket                = server.Accept();
            socket.SendTimeout    = Timeout;
            socket.ReceiveTimeout = Timeout;
            IsOpen                = true;
            Log.Verbose("ETSI: Physical interface connected.");

            // query the full physical game state once to ensure no arrays in state are null and to check for technical failures
            Log.Verbose("ETSI: Querying intial state and checking for technical failures...");
            query = new PhysicalStateQuery(true, true, true, true, true, true);
            PhysicalStateResponse response = SendQuery <PhysicalStateResponse>("get_game_state", query);

            state = response.@return;
        }
Beispiel #2
0
        public void ForceTriggerUpdate()
        {
            PhysicalStateQuery    selectiveQuery = new PhysicalStateQuery(false, false, false, false, false, true);
            PhysicalStateResponse response       = SendQuery <PhysicalStateResponse>("get_game_state", selectiveQuery);

            query.blasting = true;
            state.blasting = [email protected];
        }
Beispiel #3
0
        public void ForceDynamiteUpdate()
        {
            PhysicalStateQuery    selectiveQuery = new PhysicalStateQuery(false, false, false, false, true, false);
            PhysicalStateResponse response       = SendQuery <PhysicalStateResponse>("get_game_state", selectiveQuery);

            query.dynamite = true;
            state.dynamite = [email protected];
        }
Beispiel #4
0
        public void ForcePipesUpdate()
        {
            PhysicalStateQuery    selectiveQuery = new PhysicalStateQuery(false, false, true, false, false, false);
            PhysicalStateResponse response       = SendQuery <PhysicalStateResponse>("get_game_state", selectiveQuery);

            query.pipes = true;
            state.pipes = [email protected];
        }
Beispiel #5
0
        /// <summary>
        /// See <see cref="IEtsInterface.Update()"/>. Sends a request via socket to ETSI to query the
        /// physical state. Also waits for, receives and parses the response.
        /// </summary>
        public void PhysicalUpdate(float deltaTime)
        {
            // query state
            query = new PhysicalStateQuery(true, true,
                                           pipes.State == GameState.Initialized || pipes.State == GameState.Running || maintenanceMode.enabled,
                                           crane.State == GameState.Initialized || crane.State == GameState.Running || maintenanceMode.enabled,
                                           dynamite.State == GameState.Initialized || dynamite.State == GameState.Running || maintenanceMode.enabled,
                                           trigger.State == GameState.Initialized || trigger.State == GameState.Running || maintenanceMode.enabled
                                           );
            PhysicalStateResponse response = SendQuery <PhysicalStateResponse>("get_game_state", query);

            PhysicalState newState = response.@return;

            if (query.pipes)
            {
                state.pipes = newState.pipes;
            }
            if (query.crane)
            {
                state.crane = newState.crane;
            }
            if (query.dynamite)
            {
                state.dynamite = newState.dynamite;
            }
            if (query.blasting)
            {
                state.blasting = newState.blasting;
            }
            if (query.lights)
            {
                state.lights = newState.lights;
            }
            if (query.control)
            {
                state.control = newState.control;
            }

            if (OverrideLighting && GetLightStates().Contains(false))
            {
                bool[] lights = new bool[LightsCount];
                for (int i = 0; i < lights.Length; i++)
                {
                    lights[i] = true;
                }

                OverrideLighting = false;
                SetLightStates(lights);
                OverrideLighting = true;
            }
        }