Esempio n. 1
0
    public void setDensity(int x, int y, int z)
    {
        int chunkSize = TerrainBrain.chunkSize;

        int absX = Math.Abs(x);
        int absY = Math.Abs(y);
        int absZ = Math.Abs(z);

        int modX = x < 0 ? (chunkSize - absX % chunkSize) % chunkSize : x % chunkSize;
        int modY = y < 0 ? (chunkSize - absY % chunkSize) % chunkSize : y % chunkSize;
        int modZ = z < 0 ? (chunkSize - absZ % chunkSize) % chunkSize : z % chunkSize;

        int ciX = x - modX;
        int ciY = y - modY;
        int ciZ = z - modZ;

        IntCoords coords = new IntCoords(ciX, ciY, ciZ);

        // Shouldn't be altering the density of unloaded chunks anyway, eh?
        if (!m_data.ContainsKey(coords))
        {
            Debug.Log("Couldn't find coords: " + coords.ToString());
            return;
        }

        //Debug.Log("Setting chunk " + coords.ToString() + ", index (" + modX.ToString() + ", " + modY.ToString() + ", " + modZ.ToString() + ") to nil.");
        m_data[coords][modX, modY, modZ] = 0;
    }
Esempio n. 2
0
    public int[,,] getChunk(int x, int y, int z)
    {
        IntCoords coords = new IntCoords(x, y, z);

        if (coords.Equals(m_lastCoords))
        {
            return(m_lastData);
        }

        m_lastCoords = coords;

        if (m_data.ContainsKey(coords))
        {
            m_lastData = m_data[coords];
            return(m_lastData);
        }

        int chunkSize = TerrainBrain.chunkSize;

        m_lastData = new int[chunkSize, chunkSize, chunkSize];
        TerrainBrain tb = TerrainBrain.Instance();

        for (int t = 0; t < chunkSize; t++)
        {
            for (int u = 0; u < chunkSize; u++)
            {
                for (int v = 0; v < chunkSize; v++)
                {
                    Vector3 loc = new Vector3((float)(x + t), (float)(y + u), (float)(z + v)) / TerrainBrain.noiseMultiplier;
                    //Vector3 cpos = new Vector3((float)t, (float)u, (float)v);

                    m_lastData[t, u, v] = tb.getDensity(loc);
                }
            }
        }

        //Debug.Log("Stored cache:" + coords.ToString());
        m_data[coords] = m_lastData;
        return(m_lastData);
    }