// World Zone created on a chunk, and expended after
    public WorldZone(WorldChunk chunk, WorldChunkComputed.WorldChunkZone zone)
    {
        this.randomInt    = (int)Random.Range(1f, 100f);
        this.randomColor  = new Color(Random.Range(0f, 1f), Random.Range(0f, 1f), Random.Range(0f, 1f));
        this.type         = zone.type;
        this.isMainGround = false;
        this.isDeleted    = false;

        if (zone.IsOnChunkBorder())
        {
            this.state            = WorldZoneStates.Created;
            this.requireZoneState = (chunk.requireState >= ChunkStates.Merged) ? WorldZoneStates.Merged : WorldZoneStates.Created;

            /*
             * for (int e = 0; e < Coord.directions.Length; e++) {
             *      Direction direction = Coord.directions [e];
             *      Coord directionCoord = chunk.coord.GetDirection (direction);
             *      if (zone.isDirectionChunkBorder [direction]) {
             *              this.missingChunks.Add (directionCoord);
             *      }
             * }*/
        }
        else
        {
            this.state            = WorldZoneStates.Merged;
            this.requireZoneState = WorldZoneStates.Merged;
        }
        // Have chunk border
        this.chunks.Add(chunk.coord);

        // ref to this zone
        this.chunkZones[chunk.coord] = new List <WorldChunkComputed.WorldChunkZone>();
        this.chunkZones [chunk.coord].Add(zone);          // Add a ref to it
    }
    void UpdateCursor(WorldChunk _chunk, WorldChunkSettings setting, WorldChunkZone zone, Coord coord, Coord lastCoordDirection)
    {
        this.countTest++;
        if (coord.x < 0 || coord.y < 0 || coord.x >= setting.scaledSize || coord.y >= setting.scaledSize)
        {
            // Is out of chunk!
            return;
        }
        // First already contains on the current zone (ex: [0;0] -> [0;1] -> [0;0] will append offen)
        if (zone.coords.Contains(coord))
        {
            return;
        }
        // Test zone type (get the type based on heightMap)
        WorldZoneTypes coordType = _chunk.chunkData.GetZoneType(coord, setting);

        if (coordType != zone.type)
        {
            // It's not the same region (add it only one time)
            if (!this.HasZone(coord) && !this.availableCoords.Contains(coord))
            {
                this.availableCoords.Add(coord);
            }
            return;
        }

        // It's a new on the same zone, add
        zone.AddCoord(coord, setting);
        // If the coord is on the free coord list (for future next list)
        if (this.availableCoords.Contains(coord))
        {
            this.availableCoords.Remove(coord);
        }

        // Test all sides (but avoid returning on same than previous)
        if (lastCoordDirection != Coord.Top)
        {
            UpdateCursor(_chunk, setting, zone, coord.GetDirection(Direction.Top), Coord.Bottom);
        }
        if (lastCoordDirection != Coord.Bottom)
        {
            UpdateCursor(_chunk, setting, zone, coord.GetDirection(Direction.Bottom), Coord.Top);
        }
        if (lastCoordDirection != Coord.Left)
        {
            UpdateCursor(_chunk, setting, zone, coord.GetDirection(Direction.Left), Coord.Right);
        }
        if (lastCoordDirection != Coord.Right)
        {
            UpdateCursor(_chunk, setting, zone, coord.GetDirection(Direction.Right), Coord.Left);
        }
        return;
    }
    // Main Ground
    public WorldZone(WorldZoneTypes type)
    {
        this.type         = type;
        this.isMainGround = true;         // Main Ground !
        this.isDeleted    = false;

        this.state            = WorldZoneStates.Merged;
        this.requireZoneState = WorldZoneStates.Merged;

        this.randomInt   = 0;
        this.randomColor = new Color(1f, 245f / 255f, 0f);        // yellow
    }
        public List <Coord> missingChunks = new List <Coord> ();                                                            // missing chunk next to complete

        // Default Constructor
        public WorldChunkZone(WorldZoneTypes _type)
        {
            this.type = _type;

            this.containAllCoords = false;
            this.worldZoneRef     = null;

            for (int e = 0; e < Coord.directions.Length; e++)
            {
                isDirectionChunkBorder[Coord.directions[e]]     = false;
                directionChunkBorderCoords[Coord.directions[e]] = new List <int>();
            }
        }
示例#5
0
    public static float GetRealHeight(float noiseHeight, WorldZoneTypes zoneType, WorldChunkSettings setting)
    {
        float height;

        if (zoneType == WorldZoneTypes.Water)
        {
            float delta = (noiseHeight) * (1 / (setting.water));
            return(Mathf.Lerp(0f, .3f, delta));             //.29f;
        }
        else if (zoneType == WorldZoneTypes.Ground)
        {
            float delta = (noiseHeight - setting.water) * (1 / (setting.mountain - setting.water));
            return(Mathf.Lerp(.3f, .5f, delta));
        }
        else         /*if (zoneType == WorldZoneTypes.Mountain) */
        {
            float delta = (noiseHeight - setting.mountain) * (1 / (1 - setting.mountain));
            return(Mathf.Lerp(.5f, 1.5f, delta));
        }
    }