Exemplo n.º 1
0
        public bool InitMap(string fname)
        {
            bool   success  = false;
            string fullname = _basePath + fname;

            if (!File.Exists(fullname))
            {
                return(false);
            }

            using (BinaryReader binaryReader = new BinaryReader(File.Open(fullname, FileMode.Open, FileAccess.Read, FileShare.Read)))
            {
                if (binaryReader.ReadStringFromChars(8) == SharedConst.VMAP_MAGIC)
                {
                    if (binaryReader.ReadStringFromChars(4) == "NODE" && _tree.readFromFile(binaryReader))
                    {
                        _nTreeValues = _tree.primCount();
                        _treeValues  = new ModelInstance[_nTreeValues];
                        success      = true;
                    }
                }

                if (success)
                {
                    success = binaryReader.ReadStringFromChars(4) == "SIDX";
                    if (success)
                    {
                        uint spawnIndicesSize = binaryReader.ReadUInt32();
                        for (uint i = 0; i < spawnIndicesSize; ++i)
                        {
                            uint spawnId    = binaryReader.ReadUInt32();
                            uint spawnIndex = binaryReader.ReadUInt32();
                            _spawnIndices[spawnId] = spawnIndex;
                        }
                    }
                }
            }
            return(success);
        }
Exemplo n.º 2
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);
        }