Exemplo n.º 1
0
        /// <summary>
        /// Save all the dictionary to the specified MATR file (in plain format).
        /// </summary>
        public void SaveToTxt(String Path)
        {
            using (StreamWriter Stream = new StreamWriter(Path, false, Encoding.GetEncoding("UTF-8")))
            {
                IntPtr[] Pointers = new IntPtr[0];

                lock (Entries)
                {
                    Pointers = new IntPtr[Entries.Count];
                    Entries.CopyTo(Pointers, 0);
                }

                Stream.WriteLine("material={0}", Pointers.Length);
                for (Int32 i = 0; i < Pointers.Length; i++)
                {
                    Entry *pEntry = (Entry *)Pointers[i];

                    StringBuilder Builder = new StringBuilder(Kernel.MAX_BUFFER_SIZE);
                    Builder.Append(Kernel.cstring(pEntry->Name, MAX_NAMESIZE) + " ");
                    Builder.Append(pEntry->Param0.ToString("X2") + " ");
                    Builder.Append(pEntry->Param1.ToString("X2") + " ");
                    Builder.Append(pEntry->Param2.ToString("X2") + " ");
                    Builder.Append(pEntry->Param3.ToString("X2") + " ");
                    Builder.Append(pEntry->Param4.ToString("X2"));
                    Stream.WriteLine(Builder.ToString());
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Load the specified EMOI file (in binary format) into the dictionary.
        /// </summary>
        public void LoadFromDat(String Path)
        {
            Clear();

            lock (Entries)
            {
                using (FileStream Stream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Byte[]  Buffer  = new Byte[Kernel.MAX_BUFFER_SIZE];
                    Header *pHeader = stackalloc Header[1];

                    Stream.Read(Buffer, 0, sizeof(Header));
                    Kernel.memcpy(pHeader, Buffer, sizeof(Header));

                    if (pHeader->Identifier != EMOI_IDENTIFIER)
                    {
                        throw new Exception("Invalid EMOI Header in file: " + Path);
                    }

                    for (Int32 i = 0; i < pHeader->Amount; i++)
                    {
                        Entry *pEntry = (Entry *)Kernel.malloc(sizeof(Entry));
                        Stream.Read(Buffer, 0, sizeof(Entry));
                        Kernel.memcpy(pEntry, Buffer, sizeof(Entry));

                        if (!Entries.ContainsKey(pEntry->ID))
                        {
                            Entries.Add(pEntry->ID, (IntPtr)pEntry);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        public static void Clear(PtrIntDict *self)
        {
            int len = self->len;

            self->count = 0;
            self->free  = 0;

            var    entries = self->entries;
            Entry *entry   = null;

            for (int i = 0; i < len; i += 1)
            {
                entry       = entries + i;
                entry->val  = null;
                entry->next = i + 1;
            }
            entry->next = -1;              // the last free entry

            int *arr = self->arr;

            for (int i = 0; i < len; i += 1)
            {
                arr[i] = -1;
            }
        }
Exemplo n.º 4
0
            public bool Next()
            {
                if (Current != null)
                {
                    _index = Current->Right;
                }

                while (_index != 0 || _depth > 0)
                {
                    // push current left-most on stack
                    while (_index != 0)
                    {
                        // check for max depth
                        Assert.Check(_depth < MAX_DEPTH);

                        // pushes current on stack
                        _stack[_depth++] = _index;

                        // grab next left
                        _index = GetEntry(Collection, _index)->Left;
                    }

                    // grab from stack
                    _index  = _stack[--_depth];
                    Current = GetEntry(Collection, _index);
                    return(true);
                }

                Current = null;
                return(false);
            }
Exemplo n.º 5
0
 public static void Init(PtrIntDict *self)
 {
                 #if FDB
     Should.NotNull("self", self);
     self->type = Type;
                 #endif
     self->tag = Tag.PtrIntDict;
     int level = self->level = 0;
     int len   = self->len = Const.Lens[level];
     self->count = 0;
     self->free  = 0;
     // | (Entry)entries... | (int)arr... |
     // used entry: next: next entry in the bucket
     // free entry: next: next free entry
     int    EntrySize = Const.EntrySize;
     var    entries   = self->entries = (Entry *)Mem.Malloc(len * (EntrySize + IntSize));
     Entry *entry     = null;
     for (int i = 0; i < len; i += 1)
     {
         entry       = entries + i;
         entry->val  = null;
         entry->next = i + 1;
     }
     entry->next = -1;              // the last free entry
     int *arr = self->arr = (int *)((byte *)entries + len * EntrySize);
     for (int i = 0; i < len; i += 1)
     {
         arr[i] = -1;
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Save all the dictionary to the specified SIMO file (in plain format).
        /// </summary>
        public void SaveToTxt(String Path)
        {
            using (StreamWriter Stream = new StreamWriter(Path, false, Encoding.GetEncoding("Windows-1252")))
            {
                IntPtr[] Pointers = new IntPtr[0];

                lock (Entries)
                {
                    Pointers = new IntPtr[Entries.Count];
                    Entries.Values.CopyTo(Pointers, 0);
                }

                for (Int32 i = 0; i < Pointers.Length; i++)
                {
                    Entry *pEntry = (Entry *)Pointers[i];

                    Stream.WriteLine("[ObjIDType{0}]", pEntry->UniqId);
                    Stream.WriteLine("PartAmount={0}", pEntry->Amount);
                    for (Int32 x = 0; x < pEntry->Amount; x++)
                    {
                        Stream.WriteLine("Part{0}={1}", x, ((Part *)pEntry->Parts)[x].PartID);
                        Stream.WriteLine("Texture{0}={1}", x, ((Part *)pEntry->Parts)[x].Texture);
                    }
                    Stream.WriteLine();
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Load the specified itemtype file (in custom binary format) into the dictionary.
        /// </summary>
        public void LoadFromDat(String Path)
        {
            Clear();

            lock (Entries)
            {
                using (FileStream Stream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Byte[] Buffer = new Byte[Kernel.MAX_BUFFER_SIZE];
                    Entries = new Dictionary <Int32, IntPtr>();

                    Int32 Amount = 0;
                    Stream.Read(Buffer, 0, sizeof(Int32));

                    fixed(Byte *pBuffer = Buffer)
                    Amount = *((Int32 *)pBuffer);

                    //Bypass all the useless UIDs that are repeated in the entries...
                    Stream.Seek(sizeof(Int32) * Amount, SeekOrigin.Current);

                    for (Int32 i = 0; i < Amount; i++)
                    {
                        Entry *pEntry = (Entry *)Kernel.malloc(sizeof(Entry));
                        Kernel.memcpy((Byte *)pEntry, Buffer, sizeof(Entry));

                        if (!Entries.ContainsKey(pEntry->ID))
                        {
                            Entries.Add(pEntry->ID, (IntPtr)pEntry);
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Instantiate the epoch table
        /// </summary>
        public LightEpoch()
        {
            long p;

#if NET5_0_OR_GREATER
            tableRaw = GC.AllocateArray <Entry>(kTableSize + 2, true);
            p        = (long)Unsafe.AsPointer(ref tableRaw[0]);
#else
            // Over-allocate to do cache-line alignment
            tableRaw    = new Entry[kTableSize + 2];
            tableHandle = GCHandle.Alloc(tableRaw, GCHandleType.Pinned);
            p           = (long)tableHandle.AddrOfPinnedObject();
#endif
            // Force the pointer to align to 64-byte boundaries
            long p2 = (p + (Constants.kCacheLineBytes - 1)) & ~(Constants.kCacheLineBytes - 1);
            tableAligned = (Entry *)p2;

            CurrentEpoch       = 1;
            SafeToReclaimEpoch = 0;

            for (int i = 0; i < kDrainListSize; i++)
            {
                drainList[i].epoch = int.MaxValue;
            }
            drainCount = 0;
        }
Exemplo n.º 9
0
 /// <summary>
 /// Clean up epoch table
 /// </summary>
 public void Dispose()
 {
     tableHandle.Free();
     tableAligned       = null;
     tableRaw           = null;
     CurrentEpoch       = 1;
     SafeToReclaimEpoch = 0;
 }
Exemplo n.º 10
0
            public Iterator(UnsafeHashCollection *collection)
            {
                _index = -1;

                //
                Current    = null;
                Collection = collection;
            }
Exemplo n.º 11
0
            public Iterator(UnsafeOrderedCollection *collection)
            {
                Collection = collection;
                Current    = null;

                _depth = 0;
                _index = Collection->Root;
            }
Exemplo n.º 12
0
        /// <summary>
        /// Clean up epoch table
        /// </summary>
        void Uninitialize()
        {
            tableHandle.Free();
            tableAligned = null;
            tableRaw     = null;

            numEntries         = 0;
            CurrentEpoch       = 1;
            SafeToReclaimEpoch = 0;
        }
Exemplo n.º 13
0
        /// <summary>
        /// Load the specified RSDB_BIG file (in binary format) into the dictionary.
        /// </summary>
        public void LoadFromDat(String Path)
        {
            Clear();

            lock (Entries)
            {
                using (FileStream Stream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Byte[]  Buffer  = new Byte[Kernel.MAX_BUFFER_SIZE];
                    Header *pHeader = stackalloc Header[1];

                    Stream.Read(Buffer, 0, sizeof(Header));
                    Kernel.memcpy(pHeader, Buffer, sizeof(Header));

                    if (pHeader->Identifier != RSDB_BIG_IDENTIFIER)
                    {
                        throw new Exception("Invalid RSDB_BIG Header in file: " + Path);
                    }

                    Int64 Address = 0;
                    Console.WriteLine(pHeader->Amount);
                    for (Int32 i = 0; i < pHeader->Amount; i++)
                    {
                        Console.Write("\r{0}", (Int32)((Double)(i + 1) / (Double)pHeader->Amount * 100.0));
                        Entry *pEntry = (Entry *)Kernel.calloc(sizeof(Entry));
                        Stream.Read(Buffer, 0, sizeof(Entry) - 1);
                        Kernel.memcpy(pEntry, Buffer, sizeof(Entry) - 1);

                        Address = Stream.Position;
                        Stream.Seek(pEntry->Offset, SeekOrigin.Begin);

                        StringBuilder Builder = new StringBuilder(Kernel.MAX_BUFFER_SIZE);
                        Int32         Read    = Stream.ReadByte();
                        while (Read != '\0')
                        {
                            Builder.Append((Char)Read);
                            Read = Stream.ReadByte();
                        }
                        Builder.Append('\0');
                        Stream.Seek(Address, SeekOrigin.Begin);

                        Byte *pPath = Builder.ToString().ToPointer();
                        pEntry = (Entry *)Kernel.realloc(pEntry, sizeof(Entry) + Kernel.strlen(pPath));
                        Kernel.memcpy(pEntry->Path, pPath, Kernel.strlen(pPath) + 1);

                        if (!Entries.ContainsKey(pEntry->UniqId))
                        {
                            Entries.Add(pEntry->UniqId, (IntPtr)pEntry);
                        }

                        Kernel.free(pPath);
                    }
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Clean up epoch table
        /// </summary>
        public void Dispose()
        {
            tableHandle.Free();
            tableAligned = null;
            tableRaw     = null;

            numEntries         = 0;
            CurrentEpoch       = 1;
            SafeToReclaimEpoch = 0;

            threadEntryIndex.Dispose();
        }
Exemplo n.º 15
0
        /// <summary>
        /// Static constructor to setup shared cache-aligned space
        /// to store per-entry count of instances using that entry
        /// </summary>
        static LightEpoch()
        {
            // Over-allocate to do cache-line alignment
            threadIndex       = new Entry[kTableSize + 2];
            threadIndexHandle = GCHandle.Alloc(threadIndex, GCHandleType.Pinned);
            long p = (long)threadIndexHandle.AddrOfPinnedObject();

            // Force the pointer to align to 64-byte boundaries
            long p2 = (p + (Constants.kCacheLineBytes - 1)) & ~(Constants.kCacheLineBytes - 1);

            threadIndexAligned = (Entry *)p2;
        }
Exemplo n.º 16
0
        /// <summary>
        /// Load the specified EFFE file (in plain format) into the dictionary.
        /// TODO: The function is really slow... A good optimization is needed!
        /// </summary>
        public void LoadFromTxt(String Path)
        {
            Clear();

            lock (Entries)
            {
                Encoding Encoding = Encoding.GetEncoding("UTF-8");
                Ini      Ini      = new Ini(Path);

                using (StreamReader Stream = new StreamReader(Path, Encoding))
                {
                    String Line = null;
                    while ((Line = Stream.ReadLine()) != null)
                    {
                        if (Line.StartsWith("["))
                        {
                            String Name   = Line.Substring(1, Line.IndexOf("]") - 1);
                            Int16  Amount = Ini.ReadInt16(Name, "Amount");

                            Int32  Length = sizeof(Entry) + Amount * sizeof(Part);
                            Entry *pEntry = (Entry *)Kernel.calloc(Length);

                            Kernel.memcpy(pEntry->Name, Encoding.GetBytes(Name), Math.Min(Name.Length, MAX_NAMESIZE - 1));
                            pEntry->Amount = Amount;

                            pEntry->Delay         = Ini.ReadInt32(Name, "Delay");
                            pEntry->LoopTime      = Ini.ReadInt32(Name, "LoopTime");
                            pEntry->FrameInterval = Ini.ReadInt32(Name, "FrameInterval");
                            pEntry->LoopInterval  = Ini.ReadInt32(Name, "LoopInterval");
                            pEntry->OffsetX       = Ini.ReadInt32(Name, "OffsetX");
                            pEntry->OffsetY       = Ini.ReadInt32(Name, "OffsetY");
                            pEntry->OffsetZ       = Ini.ReadInt32(Name, "OffsetZ");
                            pEntry->ColorEnable   = Ini.ReadUInt8(Name, "ColorEnable");
                            pEntry->Level         = Ini.ReadUInt8(Name, "Lev");

                            for (Int32 i = 0; i < Amount; i++)
                            {
                                ((Part *)pEntry->Parts)[i].EffectId  = Ini.ReadInt32(Name, "EffectId" + i.ToString());
                                ((Part *)pEntry->Parts)[i].TextureId = Ini.ReadInt32(Name, "TextureId" + i.ToString());
                                ((Part *)pEntry->Parts)[i].Asb       = Ini.ReadUInt8(Name, "Asb" + i.ToString());
                                ((Part *)pEntry->Parts)[i].Adb       = Ini.ReadUInt8(Name, "Adb" + i.ToString());
                            }

                            if (!Entries.ContainsKey(Kernel.cstring(pEntry->Name, MAX_NAMESIZE)))
                            {
                                Entries.Add(Kernel.cstring(pEntry->Name, MAX_NAMESIZE), (IntPtr)pEntry);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Add the magic's information in the dictionary.
        /// It can be used to create an editor or an temp magic.
        /// </summary>
        public Boolean Add(Entry Entry)
        {
            lock (Entries)
            {
                if (!Entries.ContainsKey((Int32)((Entry.MagicType * 10) + Entry.Level)))
                {
                    Entry *pEntry = (Entry *)Kernel.calloc(sizeof(Entry));
                    Kernel.memcpy(pEntry, &Entry, sizeof(Entry));

                    Entries.Add((Int32)((pEntry->MagicType * 10) + pEntry->Level), (IntPtr)pEntry);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 18
0
            public bool Next()
            {
                while (++_index < Collection->UsedCount)
                {
                    var entry = UnsafeHashCollection.GetEntry(Collection, _index);
                    if (entry->State == EntryState.Used)
                    {
                        Current = entry;
                        return(true);
                    }
                }

                Current = null;
                return(false);
            }
Exemplo n.º 19
0
        /// <summary>
        /// Add the item's information in the dictionary.
        /// It can be used to create an editor or an temp item.
        /// </summary>
        public Boolean Add(Entry Entry)
        {
            lock (Entries)
            {
                if (!Entries.ContainsKey(Entry.ID))
                {
                    Entry *pEntry = (Entry *)Kernel.calloc(sizeof(Entry));
                    Kernel.memcpy(pEntry, &Entry, sizeof(Entry));

                    Entries.Add(Entry.ID, (IntPtr)pEntry);
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Open the specified DNP package.
        /// </summary>
        public void Open(String Source)
        {
            Close();

            lock (Entries)
            {
                Filename = Source;
                using (FileStream Stream = new FileStream(Filename, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Byte[] Buffer = new Byte[Kernel.MAX_BUFFER_SIZE];

                    Stream.Read(Buffer, 0, sizeof(Header));
                    Kernel.memcpy(pHeader, Buffer, sizeof(Header));

                    if (Kernel.cstring(pHeader->Identifier, MAX_IDENTIFIERSIZE) != DNP_IDENTIFIER)
                    {
                        throw new Exception("Invalid DNP Header in file: " + Filename);
                    }

                    if (pHeader->Version < MIN_VERSION || pHeader->Version > MAX_VERSION)
                    {
                        throw new Exception("Unsupported DNP version for file: " + Filename);
                    }

                    for (Int32 i = 0; i < pHeader->Number; i++)
                    {
                        Entry *pEntry = (Entry *)Kernel.malloc(sizeof(Entry));
                        Stream.Read(Buffer, 0, sizeof(Entry));
                        Kernel.memcpy(pEntry, Buffer, sizeof(Entry));

                        //Version 1001 XOR entry fields
                        if (pHeader->Version == 1001)
                        {
                            pEntry->UID    ^= 0x95279527;
                            pEntry->Size   ^= 0x96120059;
                            pEntry->Offset ^= 0x99589958;
                        }

                        if (Entries.ContainsKey(pEntry->UID))
                        {
                            throw new Exception("Doublon of " + pEntry->UID + " in the file: " + Filename);
                        }

                        Entries.Add(pEntry->UID, (IntPtr)pEntry);
                    }
                }
            }
        }
Exemplo n.º 21
0
        /// <summary>
        /// Load the specified MESH file (in binary format) into the dictionary.
        /// </summary>
        public void LoadFromDat(String Path)
        {
            Clear();

            lock (Entries)
            {
                using (FileStream Stream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Byte[]  Buffer  = new Byte[Kernel.MAX_BUFFER_SIZE];
                    Header *pHeader = stackalloc Header[1];

                    Stream.Read(Buffer, 0, sizeof(Header));
                    Kernel.memcpy(pHeader, Buffer, sizeof(Header));

                    if (pHeader->Identifier != MESH_IDENTIFIER)
                    {
                        throw new Exception("Invalid MESH Header in file: " + Path);
                    }

                    for (Int32 i = 0; i < pHeader->Amount; i++)
                    {
                        Stream.Read(Buffer, 0, sizeof(Int32) * 2);

                        Int32 UniqId = 0;
                        Int32 Amount = 0;
                        fixed(Byte *pBuffer = Buffer)
                        {
                            UniqId = *((Int32 *)pBuffer);
                            Amount = *((Int32 *)pBuffer + 1);
                        }

                        Int32 Length = (sizeof(Entry)) + (Amount * sizeof(Part));

                        Entry *pEntry = (Entry *)Kernel.malloc(Length);
                        Stream.Read(Buffer, 0, Length - sizeof(Entry));
                        Kernel.memcpy(pEntry->Parts, Buffer, Length - sizeof(Entry));

                        pEntry->UniqId = UniqId;
                        pEntry->Amount = Amount;

                        if (!Entries.ContainsKey(pEntry->UniqId))
                        {
                            Entries.Add(pEntry->UniqId, (IntPtr)pEntry);
                        }
                    }
                }
            }
        }
Exemplo n.º 22
0
        static string PrintBalance(Entry *entry)
        {
            switch (entry->Balance)
            {
            case -2: return("RR");

            case -1: return("R");

            case 0:  return("");

            case +1: return("L");

            case +2: return("LL");
            }

            throw new InvalidOperationException(entry->Balance.ToString());
        }
Exemplo n.º 23
0
        /// <summary>
        /// Static constructor to setup shared cache-aligned space
        /// to store per-entry count of instances using that entry
        /// </summary>
        static LightEpoch()
        {
            long p;

            // Over-allocate to do cache-line alignment
#if NET5_0_OR_GREATER
            threadIndex = GC.AllocateArray <Entry>(kTableSize + 2, true);
            p           = (long)Unsafe.AsPointer(ref threadIndex[0]);
#else
            threadIndex       = new Entry[kTableSize + 2];
            threadIndexHandle = GCHandle.Alloc(threadIndex, GCHandleType.Pinned);
            p = (long)threadIndexHandle.AddrOfPinnedObject();
#endif
            // Force the pointer to align to 64-byte boundaries
            long p2 = (p + (Constants.kCacheLineBytes - 1)) & ~(Constants.kCacheLineBytes - 1);
            threadIndexAligned = (Entry *)p2;
        }
Exemplo n.º 24
0
        /// <summary>
        /// Load the specified EFFE file (in binary format) into the dictionary.
        /// </summary>
        public void LoadFromDat(String Path)
        {
            Clear();

            lock (Entries)
            {
                using (FileStream Stream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Byte[]  Buffer  = new Byte[Kernel.MAX_BUFFER_SIZE];
                    Header *pHeader = stackalloc Header[1];

                    Stream.Read(Buffer, 0, sizeof(Header));
                    Kernel.memcpy(pHeader, Buffer, sizeof(Header));

                    if (pHeader->Identifier != EFFE_IDENTIFIER)
                    {
                        Kernel.free(pHeader);
                        throw new Exception("Invalid EFFE Header in file: " + Path);
                    }

                    for (Int32 i = 0; i < pHeader->Amount; i++)
                    {
                        Stream.Seek(MAX_NAMESIZE, SeekOrigin.Current);
                        Stream.Read(Buffer, 0, sizeof(Int16));

                        Int16 Amount = 0;

                        fixed(Byte *pBuffer = Buffer)
                        Amount = *((Int16 *)pBuffer);

                        Stream.Seek(-1 * (MAX_NAMESIZE + sizeof(Int16)), SeekOrigin.Current);

                        Int32 Length = (sizeof(Entry)) + (Amount * sizeof(Part));

                        Entry *pEntry = (Entry *)Kernel.calloc(Length);
                        Stream.Read(Buffer, 0, Length - 1);
                        Kernel.memcpy(pEntry, Buffer, Length - 1);

                        if (!Entries.ContainsKey(Kernel.cstring(pEntry->Name, MAX_NAMESIZE)))
                        {
                            Entries.Add(Kernel.cstring(pEntry->Name, MAX_NAMESIZE), (IntPtr)pEntry);
                        }
                    }
                }
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Load the specified MATR file (in plain format) into the dictionary.
        /// </summary>
        public void LoadFromTxt(String Path)
        {
            Clear();

            lock (Entries)
            {
                using (StreamReader Stream = new StreamReader(Path, Encoding.GetEncoding("UTF-8")))
                {
                    String Line  = null;
                    Int32  LineC = 0;
                    while ((Line = Stream.ReadLine()) != null)
                    {
                        if (LineC == 0) //material = X
                        {
                            LineC++;
                            continue;
                        }
                        LineC++;

                        String[] Parts  = Line.Split(' ');
                        Entry *  pEntry = (Entry *)Kernel.calloc(sizeof(Entry));

                        try
                        {
                            Byte *pName = stackalloc Byte[Parts[0].Length + 1];
                            Parts[0].ToPointer(pName);
                            Kernel.memcpy(pEntry->Name, pName, Math.Min(MAX_NAMESIZE - 1, Kernel.strlen(pName)));

                            pEntry->Param0 = UInt32.Parse(Parts[1], System.Globalization.NumberStyles.HexNumber);
                            pEntry->Param1 = UInt32.Parse(Parts[2], System.Globalization.NumberStyles.HexNumber);
                            pEntry->Param2 = UInt32.Parse(Parts[3], System.Globalization.NumberStyles.HexNumber);
                            pEntry->Param3 = UInt32.Parse(Parts[4], System.Globalization.NumberStyles.HexNumber);
                            pEntry->Param4 = UInt32.Parse(Parts[5], System.Globalization.NumberStyles.HexNumber);

                            Entries.Add((IntPtr)pEntry);
                        }
                        catch (Exception Exc)
                        {
                            Console.WriteLine("Error at line {0}.\n{1}", LineC, Exc);
                            Kernel.free(pEntry);
                        }
                    }
                }
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Load the specified MESH file (in plain format) into the dictionary.
        /// TODO: The function is really slow... A good optimization is needed!
        /// </summary>
        public void LoadFromTxt(String Path)
        {
            Clear();

            lock (Entries)
            {
                Ini Ini = new Ini(Path);
                using (StreamReader Stream = new StreamReader(Path, Encoding.GetEncoding("Windows-1252")))
                {
                    String Line = null;
                    while ((Line = Stream.ReadLine()) != null)
                    {
                        if (Line.StartsWith("["))
                        {
                            Int32 UniqId = Int32.Parse(Line.Substring(1, Line.IndexOf("]") - 1));
                            Int32 Amount = Ini.ReadInt32(UniqId.ToString(), "Part");

                            Int32  Length = sizeof(Entry) + Amount * sizeof(Part);
                            Entry *pEntry = (Entry *)Kernel.malloc(Length);

                            pEntry->UniqId = UniqId;
                            pEntry->Amount = Amount;

                            for (Int32 i = 0; i < Amount; i++)
                            {
                                ((Part *)pEntry->Parts)[i].Mesh     = Ini.ReadInt32(UniqId.ToString(), "Mesh" + i.ToString());
                                ((Part *)pEntry->Parts)[i].Texture  = Ini.ReadInt32(UniqId.ToString(), "Texture" + i.ToString());
                                ((Part *)pEntry->Parts)[i].MixTex   = Ini.ReadInt32(UniqId.ToString(), "MixTex" + i.ToString());
                                ((Part *)pEntry->Parts)[i].MixOpt   = Ini.ReadUInt8(UniqId.ToString(), "MixOpt" + i.ToString());
                                ((Part *)pEntry->Parts)[i].Asb      = Ini.ReadUInt8(UniqId.ToString(), "Asb" + i.ToString());
                                ((Part *)pEntry->Parts)[i].Adb      = Ini.ReadUInt8(UniqId.ToString(), "Adb" + i.ToString());
                                ((Part *)pEntry->Parts)[i].Material = Ini.ReadUInt8(UniqId.ToString(), "Material" + i.ToString());
                            }

                            if (!Entries.ContainsKey(pEntry->UniqId))
                            {
                                Entries.Add(pEntry->UniqId, (IntPtr)pEntry);
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 27
0
        /// <summary>
        /// Save all the dictionary to the specified RSDB_BIG file (in binary format).
        /// </summary>
        public void SaveToDat(String Path)
        {
            using (FileStream Stream = new FileStream(Path, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
            {
                Byte[]   Buffer   = new Byte[Kernel.MAX_BUFFER_SIZE];
                IntPtr[] Pointers = new IntPtr[0];

                lock (Entries)
                {
                    Pointers = new IntPtr[Entries.Count];
                    Entries.Values.CopyTo(Pointers, 0);
                }

                Header *pHeader = stackalloc Header[1];
                pHeader->Identifier = RSDB_BIG_IDENTIFIER;
                pHeader->Amount     = Pointers.Length;

                Kernel.memcpy(Buffer, pHeader, sizeof(Header));
                Stream.Write(Buffer, 0, sizeof(Header));

                UInt32 Offset = (UInt32)(sizeof(Header) + (pHeader->Amount * (sizeof(Entry) - 1)));
                for (Int32 i = 0; i < Pointers.Length; i++)
                {
                    Entry *pEntry = (Entry *)Pointers[i];
                    pEntry->Offset = Offset;
                    Offset        += (UInt32)Kernel.strlen(pEntry->Path) + 1;
                }

                for (Int32 i = 0; i < Pointers.Length; i++)
                {
                    Entry *pEntry = (Entry *)Pointers[i];
                    Kernel.memcpy(Buffer, pEntry, sizeof(Entry) - 1);
                    Stream.Write(Buffer, 0, sizeof(Entry) - 1);
                }

                for (Int32 i = 0; i < Pointers.Length; i++)
                {
                    Entry *pEntry = (Entry *)Pointers[i];
                    Kernel.memcpy(Buffer, pEntry->Path, Kernel.strlen(pEntry->Path) + 1);
                    Stream.Write(Buffer, 0, Kernel.strlen(pEntry->Path) + 1);
                }
            }
        }
Exemplo n.º 28
0
        /// <summary>
        /// Save all the dictionary to the specified RSDB_BIG file (in plain format).
        /// </summary>
        public void SaveToTxt(String Path)
        {
            using (StreamWriter Stream = new StreamWriter(Path, false, Encoding.GetEncoding("UTF-8")))
            {
                IntPtr[] Pointers = new IntPtr[0];

                lock (Entries)
                {
                    Pointers = new IntPtr[Entries.Count];
                    Entries.Values.CopyTo(Pointers, 0);
                }

                for (Int32 i = 0; i < Pointers.Length; i++)
                {
                    Entry *pEntry = (Entry *)Pointers[i];
                    Stream.WriteLine("{0}={1}", pEntry->UniqId, Kernel.cstring(pEntry->Path, Kernel.strlen(pEntry->Path) + 1));
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Instantiate the epoch table
        /// </summary>
        public LightEpoch()
        {
            // Over-allocate to do cache-line alignment
            tableRaw    = new Entry[kTableSize + 2];
            tableHandle = GCHandle.Alloc(tableRaw, GCHandleType.Pinned);
            long p = (long)tableHandle.AddrOfPinnedObject();

            // Force the pointer to align to 64-byte boundaries
            long p2 = (p + (Constants.kCacheLineBytes - 1)) & ~(Constants.kCacheLineBytes - 1);

            tableAligned = (Entry *)p2;

            CurrentEpoch       = 1;
            SafeToReclaimEpoch = 0;

            for (int i = 0; i < kDrainListSize; i++)
            {
                drainList[i].epoch = int.MaxValue;
            }
            drainCount = 0;
        }
Exemplo n.º 30
0
        /// <summary>
        /// Load the specified autoallot file (in binary format) into the dictionary.
        /// </summary>
        public void LoadFromDat(String Path)
        {
            Clear();

            lock (Entries)
            {
                using (FileStream Stream = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    Byte[] Buffer = new Byte[Kernel.MAX_BUFFER_SIZE];
                    Stream.Read(Buffer, 0, sizeof(Int32));

                    Int32 Amount = 0;

                    fixed(Byte *pBuffer = Buffer)
                    Amount = *((Int32 *)pBuffer);

                    Int32 Length = (Amount + 2) * sizeof(Int32);

                    Header *pHeader = (Header *)Kernel.malloc(Length);
                    Stream.Seek(0, SeekOrigin.Begin);
                    Stream.Read(Buffer, 0, Length);
                    Kernel.memcpy(pHeader, Buffer, Length);

                    Entries = new Dictionary <Int32, IntPtr[]>(Amount);
                    for (Int32 i = 0; i < pHeader->Amount; i++)
                    {
                        Entries.Add(pHeader->Professions[i], new IntPtr[pHeader->Level]);
                        for (Int32 j = 0; j < pHeader->Level; j++)
                        {
                            Entry *pEntry = (Entry *)Kernel.malloc(sizeof(Entry));
                            Stream.Read(Buffer, 0, sizeof(Entry));
                            Kernel.memcpy(pEntry, Buffer, sizeof(Entry));

                            Entries[pHeader->Professions[i]][j] = (IntPtr)pEntry;
                        }
                    }
                    Kernel.free(pHeader);
                }
            }
        }
Exemplo n.º 31
0
 public PriorityQueue(Entry* entries)
 {
     Entries = entries;
     Count = 0;
 }