Exemplo n.º 1
0
    public bool playerIsInNewChunk()
    {
        int x = UMaths.scaledFloor(chunkSize, transform.position.x);
        int y = UMaths.scaledFloor(chunkSize, transform.position.z);

        if (lastChunkX != x || lastChunkY != y)
        {
            lastChunkX = x;
            lastChunkY = y;
            return(true);
        }
        return(false);
    }
Exemplo n.º 2
0
    public void drawPoints(float size = 1)
    {
        int x = UMaths.scaledFloor(chunkSize, transform.position.x);
        int y = UMaths.scaledFloor(chunkSize, transform.position.z);

        for (int i = -chunkAdjacentLayers; i <= chunkAdjacentLayers; i++)
        {
            for (int j = -chunkAdjacentLayers; j <= chunkAdjacentLayers; j++)
            {
                Vector3 chunkPos = new Vector3(x + (i * chunkSize), 0, y + (j * chunkSize));
                Gizmos.DrawSphere(chunkPos, size);
            }
        }
    }
Exemplo n.º 3
0
    void Update()
    {
        if (_clearHashMap)
        {
            clearHashMap();
            _clearHashMap = false;
        }

        if (playerIsInNewChunk())
        {
            /// chunk Position
            int x = UMaths.scaledFloor(chunkSize, transform.position.x);
            int y = UMaths.scaledFloor(chunkSize, transform.position.z);

            /// chunk number in the world starting from world position 0,0
            int xNum = (int)(x / chunkSize);
            int yNum = (int)(y / chunkSize);

            /// starting tile
            // Only for debug
            startTile = new USlippyTile(startLon, startLat, zoom);

            /// sapwn all the new needed chunks
            for (int i = -chunkAdjacentLayers; i <= chunkAdjacentLayers; i++)
            {
                for (int j = -chunkAdjacentLayers; j <= chunkAdjacentLayers; j++)
                {
                    USlippyTile sTile = new USlippyTile(xNum + i + startTile.x, yNum + j + startTile.y, zoom);

                    /// This line fix that world is flipped upside down
                    sTile.y = startTile.y + (startTile.y - sTile.y);

                    string key = genTerrainName(sTile.x, sTile.y);
                    if (!map.ContainsKey(key))
                    {
                        GameObject t = createTerrain(sTile, key);

                        Vector3 pos = new Vector3();
                        pos.Set(x + (i * chunkSize), 0, y + (j * chunkSize));
                        t.transform.position = pos;

                        map.Add(key, t);
                    }
                }
            }
            /// after spawning the new chunks, remove the olders that we dont need
            removeResidualChunks();
        }
    }
Exemplo n.º 4
0
    /*
     * public bool loadOSM(string filePath)
     * {
     *  // load OSM data
     *  string rawData = OSMLoader.loadFromFile(filePath);
     *  if (rawData == "") return false;
     *
     *  // initialize the parser
     *  parser = new OSMParser();
     *  parser.load(rawData);
     *  loadBounds();
     *
     *  return true;
     * }
     */

    private bool loadNodes()
    {
        nodes = parser.nodes;

        /// normalize
        double minX = UMaths.lon2x(minLon);
        double minY = UMaths.lat2y(minLat);

        /// Mercator
        foreach (DictionaryEntry e in nodes)
        {
            OSMNode n = (OSMNode)e.Value;
            n.pos.x = (float)UMaths.lon2x(n.lon) - (float)minX;
            n.pos.z = (float)UMaths.lat2y(n.lat) - (float)minY;
        }
        return(true);
    }
Exemplo n.º 5
0
 public static Int3 findChunk(float _x, float _y, float _z, float chunkSize)
 {
     return(new Int3((int)(UMaths.scaledFloor(chunkSize, _x) / chunkSize), (int)(UMaths.scaledFloor(chunkSize, _y) / chunkSize), (int)(UMaths.scaledFloor(chunkSize, _z) / chunkSize)));
 }
Exemplo n.º 6
0
 private void calculateDimensions()
 {
     width  = UMaths.lon2x(bounds[3]) - UMaths.lon2x(bounds[1]);
     height = UMaths.lat2y(bounds[2]) - UMaths.lat2y(bounds[0]);
 }