Beispiel #1
0
        public static Region loadRegionFile(World world, Point regionID)
        {
            checkAndCreateFolder(world.getRegionPath());

            try
            {
                FileStream fileStream = new FileStream(world.getRegionPath() + "\\x" + regionID.X + ".y" + regionID.Y + ".region", FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Delete);
                return new Region(world, regionID, fileStream);
            }
            catch (IOException)
            {
                Console.WriteLine("region: x:" + regionID.X + " y:" + regionID.Y + " error");
            }
            return null;
        }
Beispiel #2
0
        public Region(World world, Point regionID, FileStream fileStream)
        {
            this.world = world;
            this.regionID = regionID;
            this.fileStream = fileStream;
            lastUsedTick = DateTime.Now.Ticks;

            chunkIsPresent = new byte[1024];
            chunkPositionInFile = new int[1024];
            chunkSizeInBytes = new int[1024];
            //tempCreateChunkScheme();
            //saveRegionScheme();
            loadRegionScheme();
            int test = 0;
        }
Beispiel #3
0
        public Chunk getChunk(World world, Point chunkCordinates)
        {
            Chunk alreadyLoadedChunk;
                Tuple<int, int> chunkCordinatesTuple = Tuple.Create(chunkCordinates.X, chunkCordinates.Y);
                if (chunkList.TryGetValue(chunkCordinatesTuple, out alreadyLoadedChunk))
                {
                    return alreadyLoadedChunk;
                }
                //Console.WriteLine("Regions in InternalServer regionList: "+regionList.Count);

                Point regionValue = Translation.chunkCoordsToRegionCoords(chunkCordinates);
                Region fetchedRegion;
                bool regionInDictionary = regionList.TryGetValue(Tuple.Create(regionValue.X, regionValue.Y), out fetchedRegion);
                if (regionInDictionary)
                {
                    //get chunk
                    Chunk newChunk = fetchedRegion.readChunk(chunkCordinates);
                    if (newChunk.terrainPopulated == 1)
                    {
                        chunkList.Add(chunkCordinatesTuple, newChunk);

                        return newChunk;
                    }
                    else
                    {
                        return null; //continue until found
                    }
                }
                else
                {
                    //load region
                    Region newRegion = FileLoader.loadRegionFile(world, regionValue);
                    if (newRegion != null)
                    {
                        regionList.Add(Tuple.Create(regionValue.X, regionValue.Y), newRegion);
                        Chunk newChunk = newRegion.readChunk(chunkCordinates);
                        if (newChunk != null)
                        {
                            if (newChunk.terrainPopulated == 1)
                            {
                                chunkList.Add(chunkCordinatesTuple, newChunk);
                                return newChunk;
                            }
                            else
                            {
                                return null;
                                throw new Exception("Could not load chunk.");
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Could not load region file.");
                    }
                }
                return null;
        }