Esempio n. 1
0
        private bool ConnectToSharedMemory()
        {
            try
            {
                memoryStatus = AC_MEMORY_STATUS.CONNECTING;

                // Connect to shared memory
                physicsMMF    = MemoryMappedFile.OpenExisting("Local\\acpmf_physics");
                graphicsMMF   = MemoryMappedFile.OpenExisting("Local\\acpmf_graphics");
                staticInfoMMF = MemoryMappedFile.OpenExisting("Local\\acpmf_static");
                carsInfoMMF   = MemoryMappedFile.OpenExisting("Local\\acpmf_cars");

                physics    = ReadPhysics();
                graphics   = ReadGraphics();
                staticInfo = ReadStaticInfo();
                cars       = ReadCars();

                memoryStatus = AC_MEMORY_STATUS.CONNECTED;

                return(true);
            }
            catch (FileNotFoundException)
            {
                return(false);
            }
        }
Esempio n. 2
0
        public void Run(bool mapTrack, bool positionTrigger)
        {
            bool running = false;

            int countdown = 4000;
            int safety    = 200;

            float lastTime = graphics.SessionTimeLeft;

            while (true)
            {
                physics    = ReadPhysics();
                graphics   = ReadGraphics();
                staticInfo = ReadStaticInfo();
                cars       = ReadCars();

                bool wait = true;

                if (mapTrack)
                {
                    if (!writeCoordinates())
                    {
                        break;
                    }
                }
                else if (positionTrigger)
                {
                    checkCoordinates();
                }
                else
                {
                    if (!running)
                    {
                        running = ((lastTime != graphics.SessionTimeLeft) || (countdown-- <= 0) || (physics.SpeedKmh >= 200));
                    }

                    if (running)
                    {
                        if (physics.SpeedKmh > 120)
                        {
                            safety = 200;
                        }

                        if ((safety-- <= 0) && (waitYellowFlagState > 0))
                        {
                            running = false;
                        }
                    }
                    else if ((safety <= 0) && (physics.SpeedKmh > 120))
                    {
                        running = true;
                        safety  = 200;
                    }

                    if (running)
                    {
                        if ((graphics.Status == AC_STATUS.AC_LIVE) && (graphics.IsInPit == 0) && (graphics.IsInPitLane == 0))
                        {
                            if (!checkFlagState() && !checkPositions())
                            {
                                wait = !checkPitWindow();
                            }
                            else
                            {
                                wait = false;
                            }
                        }
                        else
                        {
                            longitudinalRearDistance = 5;

                            lastSituation     = CLEAR;
                            carBehind         = false;
                            carBehindLeft     = false;
                            carBehindRight    = false;
                            carBehindReported = false;

                            lastFlagState = 0;
                        }
                    }
                }

                if (positionTrigger)
                {
                    Thread.Sleep(10);
                }
                else if (wait)
                {
                    Thread.Sleep(50);
                }
            }

            Close();
        }
Esempio n. 3
0
 public StaticInfoEventArgs(StaticInfo staticInfo)
 {
     this.StaticInfo = staticInfo;
 }