コード例 #1
0
    public WindowMapTest()
    {
        npatch = new NoisePatch(new NoiseCoord(0, 0), chman);
//		wmap = new WindowMap(npatch);

        npatch.Start();

        while (!npatch.Update())
        {
        }
    }
コード例 #2
0
    public CoordSurfaceStatus worldCoordIsAboveSurface(Coord woco)
    {
        NoisePatch np = noisePatchAtWorldCoord(woco);

        if (np == null)
        {
            throw new Exception("trying to get a heights list for which we don't have a noise patch");
            return(CoordSurfaceStatus.ABOVE_SURFACE);
        }

        return(np.worldCoordIsAboveSurface(woco));
    }
コード例 #3
0
    public float ligtValueAtWorldCoord(Coord woco, Direction dir)
    {
        NoisePatch np = noisePatchAtWorldCoord(woco);

        if (np == null)
        {
            throw new Exception("trying to get a heights list for which we don't have a noise patch");
            return(0f);
        }

        return(np.lightValueAtPatchRelativeCoord(CoordUtil.PatchRelativeBlockCoordForWorldBlockCoord(woco), dir));
    }
コード例 #4
0
    public List <Range1D> heightsListAtWorldCoord(Coord woco)
    {
        NoisePatch np = noisePatchAtWorldCoord(woco);

        if (np == null)
        {
            throw new Exception("trying to get a heights list for which we don't have a noise patch");
            return(null);
        }

        return(np.heightsListAtWorldCoord(woco));
    }
コード例 #5
0
    public Vector4 lightDataForQuadFloat(Quad quad, Direction dir, int normalOffset)
    {
//		if (debugLinesAssistant == null)
//			debugLinesAssistant = ChunkManager.debugLinesAssistant; //BUG ON SEP THREAD // CompareBaseObjectsInternal can only be called from the main thread

        if (m_noisePatch == null)
        {
            m_noisePatch = m_chunk.m_noisePatch;
        }


//		AssertUtil.Assert(m_noisePatch != null, "what? noisepatch still null?");

        Coord chunkRelCoOfOrigin = chunkRelativeCoordFrom(quad, dir, normalOffset) + DirectionUtil.NudgeCoordForDirection(dir);

        // check the nine blocks right in front.
        // for those that are not solid
        // check the windows.

        CoordSurfaceStatus surfaceStatus;

        int[] rows = new int[4];

        for (int i = 0; i < quad.dimensions.s; ++i)
        {
            for (int j = 0; j < quad.dimensions.t; ++j)
            {
                Coord quadOffset = DirectionUtil.CoordForPTwoAndNormalDirectionWithFaceAggregatorRules(new PTwo(i, j), dir);

                Coord thePatchRelCo = CoordUtil.PatchRelativeChunkCoordForChunkCoord(this.chunkCoord) * (int)ChunkManager.CHUNKLENGTH + chunkRelCoOfOrigin + quadOffset;
                surfaceStatus = m_noisePatch.patchRelativeCoordIsAboveSurface(thePatchRelCo);

                int lightValue = NUM_LIGHT_LEVELS - 1;
                if (surfaceStatus != CoordSurfaceStatus.ABOVE_SURFACE)
                {
                    lightValue = (int)(m_noisePatch.lightValueAtPatchRelativeCoord(thePatchRelCo, dir) * LIGHT_VALUE_CONVERTER);
                }

                //SET THE VALUES IN THE WAY THAT THE SHADER EXPECTS THEM
                //EXAMPLE: IF QUAD.ORIGIN.S = 7, I = 0,
                //THE SHADER WILL TAKE THE VALUE FROM COMPONENT WITH 'INDEX' 3 (7 % 4 => 3)
                rows[(quad.origin.s + i) % FaceSet.MAX_DIMENSIONS.s] |= colorValueFloatWith((quad.origin.t + j)
                                                                                            % FaceSet.MAX_DIMENSIONS.t, lightValue);
            }
        }

        return(new Vector4((float)rows[0], (float)rows[1], (float)rows[2], (float)rows[3]));
    }
コード例 #6
0
    //get the light columns at any woco that exists...

    public DiscreteDomainRangeList <LightColumn> lightColumnsAtWoco(int x, int z, NoiseCoord _noiseCoord)
    {
        Coord      woconoco = CoordUtil.WorldCoordFromNoiseCoord(_noiseCoord);
        NoiseCoord nco      = CoordUtil.NoiseCoordForWorldCoord(new Coord(x, 0, z) + woconoco);
        NoisePatch npatch   = m_chunkManager.blocks.noisePatchAtNoiseCoord(nco);

        if (npatch == null)
        {
            return(null);
        }

        Coord pRelCo = CoordUtil.PatchRelativeBlockCoordForWorldBlockCoord(new Coord(x, 0, z));

        // noisepatch return lightcol map at rel co
        return(npatch.lightColumnsAt(PTwo.PTwoXZFromCoord(pRelCo)));
    }
コード例 #7
0
    public void addNoisePatchAt(NoiseCoord nco, NoisePatch _npatch)
    {
        m_noisePatches.Add(nco, _npatch);
        //domain limits
        if (Quad.Equal(this.domain, Quad.theErsatzNullQuad()))
        {
            //first time
            domain = new Quad(new PTwo(nco.x, nco.z), PTwo.PTwoOne());
        }
        else
        {
            domain = domain.expandedToContainPoint(new PTwo(nco.x, nco.z));
        }

        ChunkManager.debugLinesAssistant.debugQuad = domain;
    }
コード例 #8
0
    public Block this[Coord woco]
    {
        get
        {
            NoiseCoord nco = noiseCoordForWorldCoord(woco);
            if (!m_noisePatches.ContainsKey(nco))
            {
                return(null);
            }
            NoisePatch np = m_noisePatches [nco];

            return(np.blockAtWorldBlockCoord(woco));
        }
        set
        {
            NoisePatch np = m_noisePatches [noiseCoordForWorldCoord(woco)];
            np.setBlockAtWorldCoord(value, woco);
        }
    }
コード例 #9
0
    public void destroyPatchAt(NoiseCoord nco)
    {
        if (m_noisePatches.ContainsKey(nco))
        {
            NoisePatch npToDestroy = m_noisePatches[nco];
            if (npToDestroy.hasStarted || !npToDestroy.IsDone)
            {
                return;
            }

            bool destroyed = m_noisePatches.Remove(nco);

            if (!destroyed)
            {
                throw new Exception("failed to destroy..." + nco.toString());
            }
        }
        else
        {
            b.bug("we don't have the key: " + nco.toString());
        }
    }
コード例 #10
0
    public static void drawDebugCubesForAllCreatedNoisePatches(NoiseCoord currentTargetedForCreationNoiseCo, Dictionary <NoiseCoord, NoisePatch> noisePatchDictionary)
    {
        if (!noisePatchDictionary.ContainsKey(currentTargetedForCreationNoiseCo))
        {
            return;
        }
        // current to be created n patch
        NoisePatch curTargeted = noisePatchDictionary[currentTargetedForCreationNoiseCo];

//		Color tarCol = curTargeted.generatedBlockAlready ? Color.gray : Color.yellow;
        Color tarCol = curTargeted.IsDone ? Color.gray : Color.yellow;

        tarCol = curTargeted.hasStarted ? new Color(.3f, 1f, .9f, 1f) : tarCol;

        //TODO: create a coroutine for getting rid of noisepatches that are far away?

        drawDebugLinesForNoisePatch(currentTargetedForCreationNoiseCo, tarCol);

        foreach (KeyValuePair <NoiseCoord, NoisePatch> npatch in noisePatchDictionary)
        {
            NoiseCoord nco = npatch.Key;
            if (NoiseCoord.Equal(nco, currentTargetedForCreationNoiseCo))
            {
                continue;
            }

            NoisePatch np  = npatch.Value;
            Color      col = np.hasStarted ? Color.magenta : Color.cyan;
            if (np.IsDone)
            {
                col = Color.green;
            }

            drawDebugLinesForNoisePatch(nco, col);
        }
    }
コード例 #11
0
    public Color32 lightDataForQuad(Quad quad, Direction dir, int normalOffset)
    {
//		if (debugLinesAssistant == null)
//			debugLinesAssistant = ChunkManager.debugLinesAssistant;

        if (m_noisePatch == null)
        {
            m_noisePatch = m_chunk.m_noisePatch;
        }

        if (m_noisePatch == null)
        {
            throw new Exception("what? noisepatch still null?");
        }

        Coord chunkRelCoOfOrigin = chunkRelativeCoordFrom(quad, dir, normalOffset);

        if (dir != Direction.xpos && dir != Direction.zpos)
        {
            chunkRelCoOfOrigin += DirectionUtil.NudgeCoordForDirection(dir);
        }

        // check the nine blocks right in front.
        // for those that are not solid
        // check the windows.

//		Coord noisePatchRelCo = CoordUtil.PatchRelativeCoordWithChunkCoordOffset(chunkRelCoOfOrigin, new Coord(0));

        int[] rows = new int[4];

//		for (int i = 0; i < quad.dimensions.s; ++i)
//		{
//			for (int j = 0; j < quad.dimensions.t; ++j)
//			{
//				Coord quadOffset = DirectionUtil.CoordForPTwoAndNormalDirectionWithFaceAggregatorRules(new PTwo(i,j), dir);
//				int  lightValue = (int) ( m_noisePatch.lightValueAtPatchRelativeCoord(noisePatchRelCo + quadOffset) * LIGHT_VALUE_CONVERTER);
//
//			}
//		}


//		Coord chunkWoco = CoordUtil.WorldCoordForChunkCoord(this.chunkCoord);

        CoordSurfaceStatus surfaceStatus = m_noisePatch.coordIsAboveSurface(this.chunkCoord, chunkRelCoOfOrigin);

//		if (surfaceStatus == CoordSurfaceStatus.ABOVE_SURFACE)
        if (surfaceStatus == CoordSurfaceStatus.ABOVE_SURFACE)
        {
            return(new Color32(255, 255, 255, 255));
            //for now...origin above == all above
        }

        //for now....
        return(new Color32(0, 0, 0, 0));

        // ********************************* //

//		int[] rows = new int[4];

        for (int i = 0; i < quad.dimensions.s; ++i)
        {
            for (int j = 0; j < quad.dimensions.t; ++j)
            {
                Coord quadOffset = DirectionUtil.CoordForPTwoAndNormalDirectionWithFaceAggregatorRules(new PTwo(i, j), dir);
                byte  lightVal   = lightValueAt(this.chunkCoord, chunkRelCoOfOrigin + quadOffset, dir);
                rows[i] |= colorValueWith(j, lightVal);
            }
        }

        return(new Color32((byte)rows[0], (byte)rows[1], (byte)rows[2], (byte)rows[3]));
    }
コード例 #12
0
 public LightDataProvider(Chunk _m_chunk)
 {
     m_chunk      = _m_chunk;
     m_noisePatch = _m_chunk.m_noisePatch;
 }
コード例 #13
0
ファイル: WindowMap.cs プロジェクト: melsov/ICB_INMC_TWOO
    public WindowMap(NoisePatch _npatch)
    {
        m_noisePatch = _npatch;
//		m_lightColumnCalculator = new LightColumnCalculator(_npatch); // FOR DBG give npatch
    }
コード例 #14
0
 public LightColumnCalculator(NoisePatch npatch)
 {
     m_noisePatch          = npatch;
     debugOrigNoiseCoord   = m_noisePatch.coord;
     this.m_lightColumnMap = new LightColumnMap(this);
 }
コード例 #15
0
    public Texture2D textureForTerrainAtXEqualsZero()
    {
        List <Color> colorData = new List <Color> ();

        Color[][] colorAr = new Color[ChunkManager.CHUNKHEIGHT] [];

        for (int i = 0; i < colorAr.Length; ++i)
        {
            colorAr [i] = new Color[ChunkManager.CHUNKLENGTH * NoisePatch.CHUNKDIMENSION];
        }

        int lowestZCoord  = 0;
        int highestZCoord = 0;

        int patchCount = 0;

        foreach (KeyValuePair <NoiseCoord, NoisePatch> npatch in noisePatches)
        {
            NoiseCoord nco = npatch.Key;

            if (nco.x != 0)
            {
                continue;
            }

            lowestZCoord  = nco.z < lowestZCoord ? nco.z : lowestZCoord;
            highestZCoord = nco.z > highestZCoord ? nco.z : highestZCoord;
        }

        //get patch count
        for (int zi = lowestZCoord; zi <= highestZCoord; zi++)
        {
            NoiseCoord nco = new NoiseCoord(0, zi);
            if (!noisePatches.ContainsKey(nco))
            {
                continue;
            }
            NoisePatch np = noisePatches [nco];
            if (np.terrainSlice != null)
            {
                patchCount++;
            }
        }

        bug("patch count was: " + patchCount);
        int       patchWidth = (int)(ChunkManager.CHUNKLENGTH * NoisePatch.CHUNKDIMENSION);
        int       tex2DWidth = (int)patchWidth * patchCount;
        Texture2D result     = new Texture2D(tex2DWidth, (int)(ChunkManager.CHUNKHEIGHT));

        int iterations = 0;

        for (int zi = lowestZCoord; zi <= highestZCoord; zi++, iterations++)
        {
            NoiseCoord nco = new NoiseCoord(0, zi);
            if (!noisePatches.ContainsKey(nco))
            {
                continue;
            }
            NoisePatch np = noisePatches [nco];
            if (np.terrainSlice != null)
            {
                int texSliceWidth = np.terrainSlice.GetLength(1);

                for (int j = 0; j < np.terrainSlice.GetLength(0); ++j)
                {
                    for (int k = 0; k < texSliceWidth; ++k)
                    {
                        result.SetPixel(k + patchWidth * iterations, j, np.terrainSlice [j, k]);
                    }
                }
            }
        }

        return(result);
    }