public AssettoCorsaConnector()
            : base(AcExecutables)
        {
            _dependencies = new DependencyChecker(
                new IDependency[]
            {
                new DirectoryExistsDependency(@"apps\python\SecondMonitor"),
                new DirectoryExistsDependency(@"apps\python\SecondMonitor\stdlib"),
                new DirectoryExistsDependency(@"apps\python\SecondMonitor\stdlib64"),
                new FileExistsAndMatchDependency(
                    @"apps\python\SecondMonitor\SecondMonitor.py",
                    @"Connectors\AssettoCorsa\SecondMonitor.py"),
                new FileExistsAndMatchDependency(
                    @"apps\python\SecondMonitor\smshared_mem.py",
                    @"Connectors\AssettoCorsa\smshared_mem.py"),
                new FileExistsAndMatchDependency(
                    @"apps\python\SecondMonitor\stdlib\_ctypes.pyd",
                    @"Connectors\AssettoCorsa\stdlib\_ctypes.pyd"),
                new FileExistsAndMatchDependency(
                    @"apps\python\SecondMonitor\stdlib64\_ctypes.pyd",
                    @"Connectors\AssettoCorsa\stdlib64\_ctypes.pyd"),
            },
                () => true);

            _assettoCorsaStartObserver = new AssettoCorsaStartObserver();
            _physicsBuffer             = new MappedBuffer <SPageFilePhysics>(AssettoCorsaShared.SharedMemoryNamePhysics);
            _graphicsBuffer            = new MappedBuffer <SPageFileGraphic>(AssettoCorsaShared.SharedMemoryNameGraphic);
            _staticBuffer        = new MappedBuffer <SPageFileStatic>(AssettoCorsaShared.SharedMemoryNameStatic);
            _secondMonitorBuffer = new MappedBuffer <SPageFileSecondMonitor>(AssettoCorsaShared.SharedMemoryNameSecondMonitor);
            _acDataConverter     = new AcDataConverter(this, _assettoCorsaStartObserver);
            _rawLastSessionType  = AcSessionType.AC_UNKNOWN;
            _lastSessionType     = SessionType.Na;
            _lastSessionPhase    = SessionPhase.Countdown;
            _stopwatch           = new Stopwatch();
        }
        private int[] GetRestartIndices_UnsignedInt(out IntPtr[] count)
        {
            unsafe
            {
                List <int>    offsets      = new List <int>();
                List <IntPtr> counts       = new List <IntPtr>();
                uint *        indicesPtr   = (uint *)MappedBuffer.ToPointer();
                uint          restartIndex = RestartIndexKey;

                for (int i = 0; i < ItemsCount; i++)
                {
                    if (indicesPtr[i] == restartIndex)
                    {
                        int previousIndex = offsets[offsets.Count - 1];

                        counts.Add(new IntPtr(i - previousIndex));
                        offsets.Add(i + 1);
                    }
                }
                counts.Add(new IntPtr((int)ItemsCount - offsets[offsets.Count - 1]));

                Debug.Assert(offsets.Count == counts.Count);
                count = counts.ToArray();

                return(offsets.ToArray());
            }
        }
Beispiel #3
0
 internal Rch(MappedBuffer mBuf, string sLbl, string eLbl)
 {
     bl        = new Pile <Rch>("", true, this);
     this.mBuf = mBuf;
     this.sLbl = sLbl;
     this.eLbl = eLbl;
     mBuf.subscribe(this);
     upd();
 }
        public PCars2Connector()
            : base(PCars2Executables)
        {
            _sharedMemory = new MappedBuffer <PCars2SharedMemory>(SharedMemoryName);

            _pCars2DataConvertor      = new PCars2DataConvertor();
            _lastRawPCars2SessionType = PCars2SessionType.SessionInvalid;
            _lastSessionType          = SessionType.Na;
            _stopwatch = new Stopwatch();
        }
Beispiel #5
0
        /// <summary>
        /// Read an array from this BufferObject
        /// </summary>
        /// <param name="ctx"></param>
        /// <param name="value"></param>
        /// <param name="size"></param>
        /// <param name="offset"></param>
        public void Load(GraphicsContext ctx, Array value, ulong size, ulong offset = 0)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            using (CreateMapGuard(ctx, BufferAccess.ReadOnly))
                Memory.Copy(value, new IntPtr(MappedBuffer.ToInt64() + (long)offset), size);
        }
Beispiel #6
0
 protected Rch(string text)
 {
     //MethWatch mw = new MethWatch("RchFdn.Rch_string");
     //text = utl.f2s("e:/sfconf/Triples.0003.txt");
     bl   = new Pile <Rch>("", true, this);
     mBuf = new MappedBuffer(text, Reach.useReachNotify);
     sLbl = "" + mBuf.sLabel(1);
     eLbl = "" + mBuf.eLabel((int)mBuf.Len());
     mBuf.subscribe(this);
     upd(); //inf = new long[bl.Count + 1, 3];
     //mw._void();
 }
Beispiel #7
0
 internal void cloneFrom(Rch other) //only allowed if the other dies right after this call, example a.cloneFrom(b - c)
 {
     bl = other.bl;
     if (bl.Len == 1)
     {
         bl[1] = this;
     }
     mBuf   = other.mBuf;
     sLbl   = other.sLbl;
     eLbl   = other.eLbl;
     inf    = other.inf;
     fitted = other.fitted;
 }
Beispiel #8
0
    internal Rch(Rch source, Restrict rt)
    {
        //MethWatch mw = new MethWatch("RchFdn.Rch_Rch_Restrict");
        fitted = rt.fitted | source.fitted;
        bl     = new Pile <Rch>("", true, this);
        int sbl = 0; int ebl = 0; int sblPos = 0; int eblPos = 0; source.block4Pos(rt.sPos, rt.ePos, ref sbl, ref ebl, ref sblPos, ref eblPos);

        if (rt.ePos < rt.sPos)
        {
            ebl = sbl; eblPos = sblPos - 1;
        }
        if ((rt.sWide) && (sblPos <= 1))
        {
            for (int i = sbl - 1; i > 0; i--)
            {
                if (source.bl_Len(i) > 0)
                {
                    break;
                }
                sbl = i; sblPos = 1;
            }
        }
        if ((rt.eWide) && (eblPos >= source.bl_Len(ebl)))
        {
            for (int i = ebl + 1; i <= source.bl.Len; i++)
            {
                if (source.bl_Len(i) > 0)
                {
                    break;
                }
                ebl = i; eblPos = 0;
            }
        }
        if (sbl == ebl)
        {
            mBuf = source.bl[sbl].mBuf;
            //long sInx = mBuf.sIndex(source.bl[sbl].sLbl); // UNBELIEVABLE!!!! This variation slows doen by 10% !!!!!  long sInx = source.bl_sInx(sbl);
            long sInx = source.bl_sInx(sbl);
            sLbl = "" + mBuf.sLabel((int)(sInx - 1 + sblPos));
            eLbl = "" + mBuf.eLabel((int)(sInx - 1 + eblPos));
            mBuf.subscribe(this);
        }
        else
        {
            bl     = source.bl.slice(sbl, ebl);
            bl[1]  = source.bl[sbl].from(sblPos);
            bl[-1] = source.bl[ebl].upto(eblPos);
        }
        upd(); //inf = new long[bl.Count + 1, 3];
        //mw._void();
    }
Beispiel #9
0
    private Pile <Rch> pieces()
    {
        //MethWatch mw = new MethWatch("RchFdn.pieces");
        Pile <Rch> ret = new Pile <Rch>();
        Pile <Rch> res = new Pile <Rch>();

        foreach (Rch r in bl)
        {
            if (r.compact)
            {
                res.Add(r);
            }
            else
            {
                res.Add(r.pieces());
            }
        }
        int i = 1;

        while (i <= res.Len)
        {
            MappedBuffer _mBuf  = res[i].mBuf;
            long         _eInx  = res[i].bl_eInx(1);
            int          next_i = i + 1;
            for (int j = i + 1; j <= res.Len; j++)
            {
                if (res[j].mBuf != _mBuf)
                {
                    break;
                }
                if (res[j].bl_sInx(1) != _eInx + 1)
                {
                    break;
                }
                _eInx  = res[j].bl_eInx(1);
                next_i = j + 1;
            }
            if (next_i == i + 1)
            {
                ret.Add(res[i]);
            }
            else
            {
                ret.Add((Rch) new Reach(res[i].mBuf, res[i].sLbl, res[next_i - 1].eLbl));
            }
            i = next_i;
        }
        return(ret); //return mw._Pile_Rch(ret);
    }
Beispiel #10
0
        /// <summary>
        /// Get an element from this mapped Buffer.
        /// </summary>
        /// <typeparam name="T">
        /// A structure representing this Buffer element.
        /// </typeparam>
        /// <param name="offset">
        /// A <see cref="UInt64"/> that specify the offset applied to the mapped Buffer to get the stored
        /// value. This value is expressed in basic machine units (bytes).
        /// </param>
        /// <returns>
        /// It returns a structure of type <typeparamref name="T"/>, read from the mapped Buffer
        /// </returns>
        /// <exception cref="InvalidOperationException">
        /// Exception thrown if this Buffer is not mapped (<see cref="IsMapped"/>).
        /// </exception>
        protected T Get <T>(ulong offset) where T : struct
        {
            if (IsMapped == false)
            {
                throw new InvalidOperationException("not mapped");
            }

#if HAVE_UNSAFE
            unsafe
            {
                return(Unsafe.Read <T>((byte *)MappedBuffer.ToPointer() + offset));
            }
#else
            throw new NotImplementedException();
#endif
        }
Beispiel #11
0
        /// <summary>
        /// Set an value to this mapped Buffer.
        /// </summary>
        /// <typeparam name="T">
        /// A structure representing this Buffer element.
        /// </typeparam>
        /// <param name="value">
        /// A <typeparamref name="T"/> that specify the mapped Buffer element.
        /// </param>
        /// <param name="offset">
        /// A <see cref="UInt64"/> that specify the offset applied to the mapped Buffer where <paramref name="value"/>
        /// is stored. This value is expressed in basic machine units (bytes).
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Exception thrown if this Buffer is not mapped (<see cref="IsMapped"/>).
        /// </exception>
        protected void Set <T>(T value, ulong offset) where T : struct
        {
            if (IsMapped == false)
            {
                throw new InvalidOperationException("not mapped");
            }

#if HAVE_UNSAFE
            unsafe
            {
                Unsafe.Write((byte *)MappedBuffer.ToPointer() + offset, value);
            }
#else
            throw new NotImplementedException();
#endif
        }
Beispiel #12
0
        /// <summary>
        /// Set an array of elements to this mapped Buffer.
        /// </summary>
        /// <typeparam name="T">
        /// A structure representing this Buffer element.
        /// </typeparam>
        /// <param name="array">
        /// A <typeparamref name="T:T[]"/> that specify the mapped Buffer element.
        /// </param>
        /// <param name="offset">
        /// A <see cref="ulong"/> that specify the offset applied to the mapped Buffer where <paramref name="array"/>
        /// is stored. This value is expressed in basic machine units (bytes).
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Exception thrown if this Buffer is not mapped (<see cref="IsMapped"/>).
        /// </exception>
        protected void Set <T>(T[] array, ulong offset) where T : struct
        {
            if (IsMapped == false)
            {
                throw new InvalidOperationException("not mapped");
            }

#if HAVE_UNSAFE
            unsafe
            {
                byte *ptr    = (byte *)MappedBuffer.ToPointer() + offset;
                int   stride = Marshal.SizeOf(typeof(T));

                for (int i = 0; i < array.Length; i++, ptr += stride)
                {
                    Unsafe.Write(ptr, array[i]);
                }
            }
#else
            throw new NotImplementedException();
#endif
        }
Beispiel #13
0
 internal Reach(MappedBuffer mBuf, string sLbl, string eLbl) : base(mBuf, sLbl, eLbl)
 {
     init();
 }
Beispiel #14
0
 /// <summary>
 /// Store an array to this BufferObject.
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="ctx"></param>
 /// <param name="offset"></param>
 /// <returns></returns>
 public void Store(GraphicsContext ctx, Array value, ulong size, ulong offset = 0)
 {
     using (CreateMapGuard(ctx, BufferAccess.ReadOnly))
         Memory.Copy(new IntPtr(MappedBuffer.ToInt64() + (long)offset), value, size);
 }