Esempio n. 1
0
        public TileMatrix(InstallLocation install, int fileIndex, int mapID, int width, int height)
        {
            _width       = width;
            _height      = height;
            _blockWidth  = width >> 3;
            _blockHeight = height >> 3;

            if (fileIndex != 0x7F)
            {
                var mapPath = install.GetPath("map{0}.mul", fileIndex);

                if (File.Exists(mapPath))
                {
                    _map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                }
                else
                {
                    mapPath = install.GetPath("map{0}LegacyMUL.uop", fileIndex);

                    if (File.Exists(mapPath))
                    {
                        _map      = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        _mapIndex = new UOPIndex(_map);
                    }
                }

                var indexPath = install.GetPath("staidx{0}.mul", fileIndex);

                if (File.Exists(indexPath))
                {
                    _fileIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    _reader    = new BinaryReader(_fileIndex);
                }

                var staticsPath = install.GetPath("statics{0}.mul", fileIndex);

                if (File.Exists(staticsPath))
                {
                    _staticsStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
            }

            _emptyStaticBlock = new HuedTile[8][][];

            for (var i = 0; i < 8; ++i)
            {
                _emptyStaticBlock[i] = new HuedTile[8][];

                for (var j = 0; j < 8; ++j)
                {
                    _emptyStaticBlock[i][j] = new HuedTile[0];
                }
            }

            _invalidLandBlock = new Tile[196];
        }
Esempio n. 2
0
        internal static void Initialize(string dataFolder, int cacheLevel)
        {
            fileStreamLock = new object();
            switch (cacheLevel)
            {
                case 0:
                    myCacheStaticIndices = false;
                    myCacheStatics = false;
                    break;
                case 1:
                    myCacheStaticIndices = true;
                    myCacheStatics = false;
                    break;
                case 2:
                    myCacheStaticIndices = true;
                    myCacheStatics = true;
                    break;
            }

            string staidx0Path = Path.Combine(dataFolder, "staidx0.mul");
            string staidx1Path = Path.Combine(dataFolder, "staidx1.mul");
            string staidx2Path = Path.Combine(dataFolder, "staidx2.mul");
            string staidx3Path = Path.Combine(dataFolder, "staidx3.mul");
            string staidx4Path = Path.Combine(dataFolder, "staidx4.mul");
            string staidx5Path = Path.Combine(dataFolder, "staidx5.mul");

            string statics0Path = Path.Combine(dataFolder, "statics0.mul");
            string statics1Path = Path.Combine(dataFolder, "statics1.mul");
            string statics2Path = Path.Combine(dataFolder, "statics2.mul");
            string statics3Path = Path.Combine(dataFolder, "statics3.mul");
            string statics4Path = Path.Combine(dataFolder, "statics4.mul");
            string statics5Path = Path.Combine(dataFolder, "statics5.mul");

            string map0Path = Path.Combine(dataFolder, "map0.mul");
            string map1Path = Path.Combine(dataFolder, "map1.mul");
            string map2Path = Path.Combine(dataFolder, "map2.mul");
            string map3Path = Path.Combine(dataFolder, "map3.mul");
            string map4Path = Path.Combine(dataFolder, "map4.mul");
            string map5Path = Path.Combine(dataFolder, "map5.mul");

            string map0UOPPath = Path.Combine(dataFolder, "map0LegacyMUL.uop");
            string map1UOPPath = Path.Combine(dataFolder, "map1LegacyMUL.uop");
            string map2UOPPath = Path.Combine(dataFolder, "map2LegacyMUL.uop");
            string map3UOPPath = Path.Combine(dataFolder, "map3LegacyMUL.uop");
            string map4UOPPath = Path.Combine(dataFolder, "map4LegacyMUL.uop");
            string map5UOPPath = Path.Combine(dataFolder, "map5LegacyMUL.uop");

            if (myCacheStaticIndices)
            {
                LoadStaticIndex(staidx0Path, ref myStaticsIndex0);
                LoadStaticIndex(staidx1Path, ref myStaticsIndex1);
                LoadStaticIndex(staidx2Path, ref myStaticsIndex2);
                LoadStaticIndex(staidx3Path, ref myStaticsIndex3);
                LoadStaticIndex(staidx4Path, ref myStaticsIndex4);
                LoadStaticIndex(staidx5Path, ref myStaticsIndex5);
            }
            else
            {
                if (File.Exists(staidx0Path))
                    myStaticIndex0Reader = File.OpenRead(staidx0Path);
                if (File.Exists(staidx1Path))
                    myStaticIndex1Reader = File.OpenRead(staidx1Path);
                if (File.Exists(staidx2Path))
                    myStaticIndex2Reader = File.OpenRead(staidx2Path);
                if (File.Exists(staidx3Path))
                    myStaticIndex3Reader = File.OpenRead(staidx3Path);
                if (File.Exists(staidx4Path))
                    myStaticIndex4Reader = File.OpenRead(staidx4Path);
                if (File.Exists(staidx5Path))
                    myStaticIndex5Reader = File.OpenRead(staidx5Path);
            }

            if (myCacheStatics)
            {
                if (myStaticsIndex0 != null)
                {
                    myStaticItems0 = new StaticRecord[myStaticsIndex0.Length][];
                    LoadStatics(statics0Path, ref myStaticsIndex0, ref myStaticItems0);
                }

                if (myStaticsIndex1 != null)
                {
                    myStaticItems1 = new StaticRecord[myStaticsIndex1.Length][];
                    LoadStatics(statics1Path, ref myStaticsIndex1, ref myStaticItems1);
                }

                if (myStaticsIndex2 != null)
                {
                    myStaticItems2 = new StaticRecord[myStaticsIndex2.Length][];
                    LoadStatics(statics2Path, ref myStaticsIndex2, ref myStaticItems2);
                }

                if (myStaticsIndex3 != null)
                {
                    myStaticItems3 = new StaticRecord[myStaticsIndex3.Length][];
                    LoadStatics(statics3Path, ref myStaticsIndex3, ref myStaticItems3);
                }

                if (myStaticsIndex4 != null)
                {
                    myStaticItems4 = new StaticRecord[myStaticsIndex4.Length][];
                    LoadStatics(statics4Path, ref myStaticsIndex4, ref myStaticItems4);
                }

                if (myStaticsIndex5 != null)
                {
                    myStaticItems5 = new StaticRecord[myStaticsIndex5.Length][];
                    LoadStatics(statics5Path, ref myStaticsIndex5, ref myStaticItems5);
                }

            }
            else
            {
                if (File.Exists(statics0Path))
                {
                    myStatics0Reader = File.OpenRead(statics0Path);
                }

                if (File.Exists(statics1Path))
                {
                    myStatics1Reader = File.OpenRead(statics1Path);
                }

                if (File.Exists(statics2Path))
                {
                    myStatics2Reader = File.OpenRead(statics2Path);
                }

                if (File.Exists(statics3Path))
                {
                    myStatics3Reader = File.OpenRead(statics3Path);
                }

                if (File.Exists(statics4Path))
                {
                    myStatics4Reader = File.OpenRead(statics4Path);
                }

                if (File.Exists(statics5Path))
                {
                    myStatics5Reader = File.OpenRead(statics5Path);
                }
            }

            if (File.Exists(map0UOPPath))
            {
                myMap0Reader = File.OpenRead(map0UOPPath);
                myMap0Index = new UOPIndex(myMap0Reader);
            }
            else if (File.Exists(map0Path))
            {
                myMap0Reader = File.OpenRead(map0Path);
            }

            if (File.Exists(map1UOPPath))
            {
                myMap1Reader = File.Open(map1UOPPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                myMap1Index = new UOPIndex(myMap1Reader);
            }
            else if (File.Exists(map1Path))
            {
                myMap1Reader = File.OpenRead(map1Path);
            }

            if (File.Exists(map2UOPPath))
            {
                myMap2Reader = File.OpenRead(map2UOPPath);
                myMap2Index = new UOPIndex(myMap2Reader);
            }
            else if (File.Exists(map2Path))
            {
                myMap2Reader = File.OpenRead(map2Path);
            }

            if (File.Exists(map3UOPPath))
            {
                myMap3Reader = File.OpenRead(map3UOPPath);
                myMap3Index = new UOPIndex(myMap3Reader);
            }
            else if (File.Exists(map3Path))
            {
                myMap3Reader = File.OpenRead(map3Path);
            }

            if (File.Exists(map4UOPPath))
            {
                myMap4Reader = File.OpenRead(map4UOPPath);
                myMap4Index = new UOPIndex(myMap4Reader);
            }
            else if (File.Exists(map4Path))
            {
                myMap4Reader = File.OpenRead(map4Path);
            }

            if (File.Exists(map5UOPPath))
            {
                myMap5Reader = File.OpenRead(map5UOPPath);
                myMap5Index = new UOPIndex(myMap5Reader);
            }
            else if (File.Exists(map5Path))
            {
                myMap5Reader = File.OpenRead(map5Path);
            }

            if (myMap0Reader != null && myMap0Reader.Length == myNewMap0Len)
                myUsingNewMaps = true;
            else myUsingNewMaps = false;

            GC.Collect(); //if full caching enabled this will free a lot of memory
        }
Esempio n. 3
0
        public TileMatrix(InstallLocation install, int fileIndex, int mapID, int width, int height)
        {
            _install     = install;
            _width       = width;
            _height      = height;
            _blockWidth  = width >> 3;
            _blockHeight = height >> 3;

            if (fileIndex != 0x7F)
            {
                string mapPath = install.GetPath("map{0}.mul", fileIndex);

                if (File.Exists(mapPath))
                {
                    _map = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                }
                else
                {
                    mapPath = install.GetPath("map{0}LegacyMUL.uop", fileIndex);

                    if (File.Exists(mapPath))
                    {
                        _map      = new FileStream(mapPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                        _mapIndex = new UOPIndex(_map);
                    }
                }

                string indexPath = install.GetPath("staidx{0}.mul", fileIndex);

                if (File.Exists(indexPath))
                {
                    _fileIndex = new FileStream(indexPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                    _reader    = new BinaryReader(_fileIndex);
                }

                string staticsPath = install.GetPath("statics{0}.mul", fileIndex);

                if (File.Exists(staticsPath))
                {
                    _staticsStream = new FileStream(staticsPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                }
            }

            _emptyStaticBlock = new HuedTile[8][][];

            for (int i = 0; i < 8; ++i)
            {
                _emptyStaticBlock[i] = new HuedTile[8][];

                for (int j = 0; j < 8; ++j)
                {
                    _emptyStaticBlock[i][j] = new HuedTile[0];
                }
            }

            _invalidLandBlock = new Tile[196];

            _landTiles   = new Tile[_blockWidth][][];
            _staticTiles = new HuedTile[_blockWidth][][][][];

            _patch = new TileMatrixPatch(this, install, mapID);

            /*for ( int i = 0; i < m_BlockWidth; ++i )
             * {
             *  m_LandTiles[i] = new Tile[m_BlockHeight][];
             *  m_StaticTiles[i] = new Tile[m_BlockHeight][][][];
             * }*/
        }