public void LoadNewMapPart(int x, int y)
        {
            //Console.WriteLine("Loading mappart: " + x + ", " + y);

            long sizeinbytes = (gridSize * gridSize) / 8; //Divide by 8 because of 8



            Boolean foundMap = false;

            //Check if current cyclething contains the new map
            for (int i = 0; i < mapParts.Length; i++)
            {
                var mapToCheck = mapParts[i];

                if (mapToCheck != null && mapToCheck.StartX == x * gridSize && mapToCheck.StartY == y * gridSize && mapToCheck.EndX == (x + 1) * gridSize && mapToCheck.EndY == (y + 1) * gridSize)
                {
                    //Console.WriteLine("From memory");
                    //Thread.Sleep(2000);
                    currentMapPart = mapToCheck;
                    //currentMapCycleFactor = i;
                    foundMap = true;
                    break;
                }
            }

            if (!foundMap)
            {
                //Console.WriteLine("From HD");
                //Thread.Sleep(2000);

                //Check if there's room for more
                if (mapParts[currentMapCycleFactor] != null)
                {
                    //If not save the oldest one
                    var oldone = mapParts[currentMapCycleFactor];

                    long posToStoreAt = sizeinbytes * (long)(Width / gridSize) * (long)(oldone.StartY / gridSize) + (long)sizeinbytes * (long)(oldone.StartX / gridSize);
                    //Console.WriteLine("Storing at: " + posToStoreAt);
                    //Thread.Sleep(5000);
                    oldone.Store(posToStoreAt);
                }



                //Load a new one
                currentMapPart = new HybridInnerMapPart(x * gridSize, y * gridSize, (x + 1) * gridSize, (y + 1) * gridSize, completeHDArray);

                long posToLoadFrom = sizeinbytes * (long)(Width / gridSize) * (long)y + (long)(sizeinbytes * x);
                //Thread.Sleep(1000);
                //Console.WriteLine(posToLoadFrom);

                currentMapPart.Load(posToLoadFrom);



                //place it at the place of the old one
                mapParts[currentMapCycleFactor] = currentMapPart;

                //Turn the cyclething
                currentMapCycleFactor++;
                if (currentMapCycleFactor >= amountOfMapPartsLoadedMax)
                {
                    currentMapCycleFactor = 0;
                }
            }
        }
예제 #2
0
        public void LoadNewMapPart(int x, int y)
        {
            //Console.WriteLine("Loading mappart: " + x + ", " + y);

            long sizeinbytes = (gridSize * gridSize) / 8; //Divide by 8 because of 8

            Boolean foundMap = false;

            //Check if current cyclething contains the new map
            for (int i = 0; i < mapParts.Length; i++)
            {
                var mapToCheck = mapParts[i];

                if (mapToCheck != null && mapToCheck.StartX == x * gridSize && mapToCheck.StartY == y * gridSize && mapToCheck.EndX == (x + 1) * gridSize && mapToCheck.EndY == (y + 1) * gridSize)
                {
                    //Console.WriteLine("From memory");
                    //Thread.Sleep(2000);
                    currentMapPart = mapToCheck;
                    //currentMapCycleFactor = i;
                    foundMap = true;
                    break;
                }
            }

            if (!foundMap)
            {
                //Console.WriteLine("From HD");
                //Thread.Sleep(2000);

                //Check if there's room for more
                if (mapParts[currentMapCycleFactor] != null)
                {
                    //If not save the oldest one
                    var oldone = mapParts[currentMapCycleFactor];

                    long posToStoreAt = sizeinbytes * (long)(Width / gridSize) * (long)(oldone.StartY / gridSize) + (long)sizeinbytes * (long)(oldone.StartX / gridSize);
                    //Console.WriteLine("Storing at: " + posToStoreAt);
                    //Thread.Sleep(5000);
                    oldone.Store(posToStoreAt);
                }

                //Load a new one
                currentMapPart = new HybridInnerMapPart(x * gridSize, y * gridSize, (x + 1) * gridSize, (y + 1) * gridSize, completeHDArray);

                long posToLoadFrom = sizeinbytes * (long)(Width / gridSize) * (long)y + (long)(sizeinbytes * x);
                //Thread.Sleep(1000);
                //Console.WriteLine(posToLoadFrom);

                currentMapPart.Load(posToLoadFrom);

                //place it at the place of the old one
                mapParts[currentMapCycleFactor] = currentMapPart;

                //Turn the cyclething
                currentMapCycleFactor++;
                if (currentMapCycleFactor >= amountOfMapPartsLoadedMax)
                {
                    currentMapCycleFactor = 0;
                }
            }
        }