Beispiel #1
0
        public MapPieceDB[] GetMapPieces(List <Vec2i> chunkCoords)
        {
            MapPieceDB[] pieces = new MapPieceDB[chunkCoords.Count];
            for (int i = 0; i < chunkCoords.Count; i++)
            {
                getMapPieceCmd.Parameters["@pos"].Value = chunkCoords[i].ToChunkIndex();
                using (SQLiteDataReader sqlite_datareader = getMapPieceCmd.ExecuteReader())
                {
                    while (sqlite_datareader.Read())
                    {
                        object data = sqlite_datareader["data"];
                        if (data == null)
                        {
                            return(null);
                        }

                        pieces[i] = SerializerUtil.Deserialize <MapPieceDB>(data as byte[]);
                    }
                }
            }

            return(pieces);
        }
Beispiel #2
0
        public override void OnOffThreadTick(float dt)
        {
            genAccum += dt;
            if (genAccum < 0.1)
            {
                return;
            }
            genAccum = 0;

            int quantityToGen = chunksToGen.Count;

            while (quantityToGen > 0)
            {
                if (mapSink.IsShuttingDown)
                {
                    break;
                }

                quantityToGen--;
                Vec2i cord;

                lock (chunksToGenLock)
                {
                    if (chunksToGen.Count == 0)
                    {
                        break;
                    }
                    cord = chunksToGen.Dequeue();
                }

                if (!api.World.BlockAccessor.IsValidPos(cord.X * chunksize, 1, cord.Y * chunksize))
                {
                    continue;
                }

                IMapChunk mc = api.World.BlockAccessor.GetMapChunk(cord);
                if (mc == null)
                {
                    //api.Logger.Notification("From DB @{0}/{1}", cord.X, cord.Y);
                    MapPieceDB piece = mapdb.GetMapPiece(cord);
                    if (piece?.Pixels != null)
                    {
                        loadFromChunkPixels(cord, piece.Pixels);
                    }

                    continue;
                }

                //api.Logger.Notification("Genpixels @{0}/{1}", cord.X, cord.Y);

                int[] pixels = (int[])GenerateChunkImage(cord, mc)?.Clone();

                if (pixels == null)
                {
                    lock (chunksToGenLock)
                    {
                        chunksToGen.Enqueue(cord);
                    }

                    continue;
                }

                toSaveList[cord.Copy()] = new MapPieceDB()
                {
                    Pixels = pixels
                };


                /// North: Negative Z
                /// East: Positive X
                /// South: Positive Z
                /// West: Negative X

                /*bool north = !api.World.LoadedMapChunkIndices.Contains(MapUtil.Index2dL(cord.X, cord.Y - 1, chunkmapSizeX));
                 * bool east = !api.World.LoadedMapChunkIndices.Contains(MapUtil.Index2dL(cord.X + 1, cord.Y, chunkmapSizeX));
                 * bool south = !api.World.LoadedMapChunkIndices.Contains(MapUtil.Index2dL(cord.X, cord.Y + 1, chunkmapSizeX));
                 * bool west = !api.World.LoadedMapChunkIndices.Contains(MapUtil.Index2dL(cord.X - 1, cord.Y, chunkmapSizeX));*/

                loadFromChunkPixels(cord, pixels /*, (north ? 1 : 0 ) | (east ? 2 : 0) | (south ? 4 : 0) | (west ? 8 : 0)*/);
            }

            if (toSaveList.Count > 100 || diskSaveAccum > 4f)
            {
                diskSaveAccum = 0;
                mapdb.SetMapPieces(toSaveList);
                toSaveList.Clear();
            }
        }