示例#1
0
        public bool LoadMapTile(uint tileX, uint tileY, VMapManager vm)
        {
            if (iTreeValues == null)
            {
                Log.outError(LogFilter.Server, "StaticMapTree.LoadMapTile() : tree has not been initialized [{0}, {1}]", tileX, tileY);
                return(false);
            }
            bool result = true;

            FileStream stream = OpenMapTileFile(VMapManager.VMapPath, iMapID, tileX, tileY, vm);

            if (stream == null)
            {
                iLoadedTiles[packTileID(tileX, tileY)] = false;
            }
            else
            {
                using (BinaryReader reader = new BinaryReader(stream))
                {
                    if (reader.ReadStringFromChars(8) != MapConst.VMapMagic)
                    {
                        return(false);
                    }

                    uint numSpawns = reader.ReadUInt32();

                    for (uint i = 0; i < numSpawns && result; ++i)
                    {
                        // read model spawns
                        ModelSpawn spawn;
                        result = ModelSpawn.readFromFile(reader, out spawn);
                        if (result)
                        {
                            // acquire model instance
                            WorldModel model = vm.acquireModelInstance(spawn.name, spawn.flags);
                            if (model == null)
                            {
                                Log.outError(LogFilter.Server, "StaticMapTree.LoadMapTile() : could not acquire WorldModel [{0}, {1}]", tileX, tileY);
                            }

                            // update tree
                            if (iSpawnIndices.ContainsKey(spawn.ID))
                            {
                                uint referencedVal = iSpawnIndices[spawn.ID];
                                if (!iLoadedSpawns.ContainsKey(referencedVal))
                                {
                                    if (referencedVal >= iNTreeValues)
                                    {
                                        Log.outError(LogFilter.Maps, "StaticMapTree.LoadMapTile() : invalid tree element ({0}/{1}) referenced in tile {2}", referencedVal, iNTreeValues, stream.Name);
                                        continue;
                                    }

                                    iTreeValues[referencedVal]   = new ModelInstance(spawn, model);
                                    iLoadedSpawns[referencedVal] = 1;
                                }
                                else
                                {
                                    ++iLoadedSpawns[referencedVal];
                                }
                            }
                            else
                            {
                                result = false;
                            }
                        }
                    }
                }
                iLoadedTiles[packTileID(tileX, tileY)] = true;
            }
            return(result);
        }
示例#2
0
        public LoadResult LoadMapTile(uint tileX, uint tileY, VMapManager vm)
        {
            if (iTreeValues == null)
            {
                Log.outError(LogFilter.Server, "StaticMapTree.LoadMapTile() : tree has not been initialized [{0}, {1}]", tileX, tileY);
                return(LoadResult.ReadFromFileFailed);
            }

            LoadResult result = LoadResult.FileNotFound;

            TileFileOpenResult fileResult = OpenMapTileFile(VMapManager.VMapPath, iMapID, tileX, tileY, vm);

            if (fileResult.File != null)
            {
                result = LoadResult.Success;
                using (BinaryReader reader = new(fileResult.File))
                {
                    if (reader.ReadStringFromChars(8) != MapConst.VMapMagic)
                    {
                        result = LoadResult.VersionMismatch;
                    }

                    if (result == LoadResult.Success)
                    {
                        uint numSpawns = reader.ReadUInt32();
                        for (uint i = 0; i < numSpawns && result == LoadResult.Success; ++i)
                        {
                            // read model spawns
                            if (ModelSpawn.ReadFromFile(reader, out ModelSpawn spawn))
                            {
                                // acquire model instance
                                WorldModel model = vm.AcquireModelInstance(spawn.name, spawn.flags);
                                if (model == null)
                                {
                                    Log.outError(LogFilter.Server, "StaticMapTree.LoadMapTile() : could not acquire WorldModel [{0}, {1}]", tileX, tileY);
                                }

                                // update tree
                                if (iSpawnIndices.ContainsKey(spawn.Id))
                                {
                                    uint referencedVal = iSpawnIndices[spawn.Id];
                                    if (!iLoadedSpawns.ContainsKey(referencedVal))
                                    {
                                        if (referencedVal >= iNTreeValues)
                                        {
                                            Log.outError(LogFilter.Maps, "StaticMapTree.LoadMapTile() : invalid tree element ({0}/{1}) referenced in tile {2}", referencedVal, iNTreeValues, fileResult.Name);
                                            continue;
                                        }

                                        iTreeValues[referencedVal]   = new ModelInstance(spawn, model);
                                        iLoadedSpawns[referencedVal] = 1;
                                    }
                                    else
                                    {
                                        ++iLoadedSpawns[referencedVal];
                                    }
                                }
                                else if (iMapID == fileResult.UsedMapId)
                                {
                                    // unknown parent spawn might appear in because it overlaps multiple tiles
                                    // in case the original tile is swapped but its neighbour is now (adding this spawn)
                                    // we want to not mark it as loading error and just skip that model
                                    Log.outError(LogFilter.Maps, $"StaticMapTree.LoadMapTile() : invalid tree element (spawn {spawn.Id}) referenced in tile fileResult.Name{fileResult.Name} by map {iMapID}");
                                    result = LoadResult.ReadFromFileFailed;
                                }
                            }
                            else
                            {
                                Log.outError(LogFilter.Maps, $"StaticMapTree.LoadMapTile() : cannot read model from file (spawn index {i}) referenced in tile {fileResult.Name} by map {iMapID}");
                                result = LoadResult.ReadFromFileFailed;
                            }
                        }
                    }
                    iLoadedTiles[PackTileID(tileX, tileY)] = true;
                }
            }
            else
            {
                iLoadedTiles[PackTileID(tileX, tileY)] = false;
            }

            return(result);
        }
示例#3
0
 public ModelInstance()
 {
     iInvScale = 0.0f;
     iModel    = null;
 }
示例#4
0
 public void setModel(WorldModel model)
 {
     iModel = model;
 }
示例#5
0
 public void SetUnloaded()
 {
     iModel = null;
 }