Exemplo n.º 1
0
        public void UnloadMapTile(uint tileX, uint tileY, VMapManager2 vm)
        {
            uint tileID = PackTileID(tileX, tileY);

            if (!_loadedTiles.ContainsKey(tileID))
            {
                Console.WriteLine("StaticMapTree.UnloadMapTile() : trying to unload non-loaded tile - Map:{iMapID} X:{tileX} Y:{tileY}");
                return;
            }

            var tile = _loadedTiles.LookupByKey(tileID);

            if (tile) // file associated with tile
            {
                string tilefile = _basePath + GetTileFileName(_mapId, tileX, tileY);
                if (File.Exists(tilefile))
                {
                    using BinaryReader binaryReader = new(File.Open(tilefile, FileMode.Open, FileAccess.Read, FileShare.Read));
                    bool result = true;
                    if (binaryReader.ReadStringFromChars(8) != SharedConst.VMAP_MAGIC)
                    {
                        result = false;
                    }

                    uint numSpawns = binaryReader.ReadUInt32();
                    for (uint i = 0; i < numSpawns && result; ++i)
                    {
                        // read model spawns
                        result = ModelSpawn.ReadFromFile(binaryReader, out ModelSpawn spawn);
                        if (result)
                        {
                            // release model instance
                            vm.ReleaseModelInstance(spawn.name);

                            // update tree
                            if (!_spawnIndices.ContainsKey(spawn.ID))
                            {
                                result = false;
                            }
                            else
                            {
                                uint referencedVal = _spawnIndices[spawn.ID];
                                if (!_loadedSpawns.ContainsKey(referencedVal))
                                {
                                    Console.WriteLine($"StaticMapTree.UnloadMapTile() : trying to unload non-referenced model '{spawn.name}' (ID:{spawn.ID})");
                                }
                                else if (--_loadedSpawns[referencedVal] == 0)
                                {
                                    _treeValues[referencedVal].SetUnloaded();
                                    _loadedSpawns.Remove(referencedVal);
                                }
                            }
                        }
                    }
                }
            }
            _loadedTiles.Remove(tileID);
            //TC_METRIC_EVENT("map_events", "UnloadMapTile", "Map: " + std::to_string(iMapID) + " TileX: " + std::to_string(tileX) + " TileY: " + std::to_string(tileY));
        }
Exemplo n.º 2
0
        static void ExtractMMaps()
        {
            if (!Directory.Exists("maps") || Directory.GetFiles("maps").Length == 0)
            {
                Console.WriteLine("'maps' directory is empty or does not exist");
                return;
            }

            if (!Directory.Exists("vmaps") || Directory.GetFiles("vmaps").Length == 0)
            {
                Console.WriteLine("'vmaps' directory is empty or does not exist");
                return;
            }

            CreateDirectory("mmaps");

            Console.WriteLine("Extracting MMap files...");
            var vm = new Framework.Collision.VMapManager2();

            MultiMap <uint, uint> mapData = new MultiMap <uint, uint>();

            foreach (var record in CliDB.MapStorage.Values)
            {
                if (record.ParentMapID != -1)
                {
                    mapData.Add((uint)record.ParentMapID, record.Id);
                }
            }

            vm.Initialize(mapData);

            MapBuilder builder = new MapBuilder(vm);

            var watch = System.Diagnostics.Stopwatch.StartNew();

            builder.buildAllMaps();

            Console.WriteLine($"Finished. MMAPS were built in {watch.ElapsedMilliseconds} ms!");
        }
Exemplo n.º 3
0
        static void ExtractMMaps(string[] args)
        {
            if (!Directory.Exists("maps") || Directory.GetFiles("maps").Length == 0)
            {
                Console.WriteLine("'maps' directory is empty or does not exist");
                return;
            }

            if (!Directory.Exists("vmaps") || Directory.GetFiles("vmaps").Length == 0)
            {
                Console.WriteLine("'vmaps' directory is empty or does not exist");
                return;
            }

            CreateDirectory("mmaps_new");

            //handle args
            bool debugMaps = false;
            int  mapId     = -1;

            for (var i = 1; i < args.Length; ++i)
            {
                switch (args[i].ToLower())
                {
                case "-debug":
                    CreateDirectory("mmaps/meshes");
                    debugMaps = true;
                    break;

                case "-id":
                    mapId = int.Parse(args[i + 1]);
                    i++;
                    break;
                }
            }

            Console.WriteLine("Extracting MMap files...");
            var vm = new Framework.Collision.VMapManager2();

            var mapStorage = DBReader.Read <MapRecord>("DBFilesClient\\Map.db2");

            if (mapStorage == null)
            {
                Console.WriteLine("Fatal error: Invalid Map.db2 file format!\n");
                return;
            }

            MultiMap <uint, uint> mapData = new MultiMap <uint, uint>();

            foreach (var record in mapStorage.Values)
            {
                if (record.ParentMapID != -1)
                {
                    mapData.Add((uint)record.ParentMapID, record.Id);
                }
            }

            vm.Initialize(mapData);

            MapBuilder builder = new MapBuilder(vm, debugMaps);

            var watch = System.Diagnostics.Stopwatch.StartNew();

            if (mapId != -1)
            {
                builder.buildMap((uint)mapId);
            }
            else
            {
                builder.buildAllMaps();
            }

            Console.WriteLine($"Finished. MMAPS were built in {watch.ElapsedMilliseconds} ms!");
        }
Exemplo n.º 4
0
        public bool LoadMapTile(uint tileX, uint tileY, VMapManager2 vm)
        {
            if (_treeValues == null)
            {
                Console.WriteLine("StaticMapTree.LoadMapTile() : tree has not been initialized [{tileX}, {tileY}]");
                return(false);
            }

            string tilefile = _basePath + GetTileFileName(_mapId, tileX, tileY);

            if (File.Exists(tilefile))
            {
                using (BinaryReader binaryReader = new BinaryReader(File.Open(tilefile, FileMode.Open, FileAccess.Read, FileShare.Read)))
                {
                    if (binaryReader.ReadStringFromChars(8) != SharedConst.VMAP_MAGIC)
                    {
                        return(false);
                    }

                    uint numSpawns = binaryReader.ReadUInt32();
                    for (uint i = 0; i < numSpawns; ++i)
                    {
                        // read model spawns
                        ModelSpawn spawn;
                        var        result = ModelSpawn.ReadFromFile(binaryReader, out spawn);
                        if (result)
                        {
                            // acquire model instance
                            WorldModel model = vm.AcquireModelInstance(_basePath, spawn.name);
                            if (model == null)
                            {
                                Console.WriteLine($"StaticMapTree.LoadMapTile() : could not acquire WorldModel pointer [{tileX}, {tileY}]");
                            }

                            // update tree
                            if (_spawnIndices.ContainsKey(spawn.ID))
                            {
                                uint referencedVal = _spawnIndices[spawn.ID];
                                if (!_loadedSpawns.ContainsKey(referencedVal))
                                {
                                    if (referencedVal > _nTreeValues)
                                    {
                                        Console.WriteLine($"StaticMapTree.LoadMapTile() : invalid tree element ({referencedVal}/{_nTreeValues}) referenced in tile {tilefile}");
                                        continue;
                                    }

                                    _treeValues[referencedVal]   = new ModelInstance(spawn, model);
                                    _loadedSpawns[referencedVal] = 1;
                                }
                                else
                                {
                                    ++_loadedSpawns[referencedVal];
                                }
                            }
                        }
                    }
                    _loadedTiles[PackTileID(tileX, tileY)] = true;
                }
            }
            else
            {
                _loadedTiles[PackTileID(tileX, tileY)] = false;
            }

            //TC_METRIC_EVENT("map_events", "LoadMapTile", "Map: " + std::to_string(iMapID) + " TileX: " + std::to_string(tileX) + " TileY: " + std::to_string(tileY));
            return(true);
        }