Пример #1
0
 public MapHolder(MapHolder mapHolder)
 {
     sizeY = mapHolder.sizeY;
     sizeX = mapHolder.sizeX;
     x = mapHolder.x;
     y = mapHolder.y;
     map = cpMap(sizeX, sizeY,mapHolder.map);
 }
Пример #2
0
        public MapHolder getRequestedMapView(int topX, int topY, int sizeX, int sizeY)
        {
            //TODO: Throw exception
            if (topX < 0 || topY < 0 || sizeX < 0 || sizeY < 0)
            {
                throw new Exception("Values cannot be < 0");
            }

            if (currentMap != null && topX >= currentMap.X && topY >= currentMap.Y
                  && (topX + sizeX) <= (currentMap.X + currentMap.SizeX)
                  && (topY + sizeY) <= (currentMap.Y + currentMap.SizeY))
            {
                //This is part of current map
                int[,] map = new int[sizeX, sizeY];
                int dispX = topX - currentMap.X;
                int dispY = topY - currentMap.Y;

                for (int i = 0; i<sizeX; i++){
                    for (int j = 0; j<sizeY; j++){
                        map[i,j] = currentMap.Map[i+dispX,j+dispY];
                    }
                }

                return new MapHolder(sizeX,sizeY,map,topX,topY);
            }
            else
            {
                if (parent != null)
                {
                    //TODO: sync
                    parent.pushMapUpdate(currentMap);
                    currentMap = parent.getRequestedMapView(topX, topY, sizeX, sizeY);
                    initializeDirtyStatistics(currentMap);
                    return new MapHolder(currentMap);
                }
                else
                {
                    throw new Exception("No such map");
                }
            }
        }
Пример #3
0
 public void initializeMap(int sizeX, int sizeY)
 {
     int[,] map = prepareArray(sizeX, sizeY, UNKNOWN_MAP_STATE);
     currentMap = new MapHolder(sizeX, sizeY, map, 0, 0);
     initializeDirtyStatistics(currentMap);
 }
Пример #4
0
 private void initializeDirtyStatistics(MapHolder newMapHolder)
 {
     mapSize = newMapHolder.SizeX * newMapHolder.SizeY;
     mapDirtyCount = 0;
     dirtyState = prepareArray(newMapHolder.SizeX, newMapHolder.SizeY, 0);
 }
Пример #5
0
 public void pushMapUpdate(MapHolder update)
 {
     updateQueue.Enqueue(update);
 }