public void UpdateSphereMap()
    {
        MapDisplay display = FindObjectOfType <MapDisplay>();

        noiseMap = updatedMap;
        Debug.Log(latestTimeProcessRequested + "updating map");
        mapTexture = GetMapTexture(renderType, noiseMap);
        display.DrawMesh(SphereMagic.CreatePlanet(PlanetItterations, radius, baseModule, heightMultiplier, regions), mapTexture);
        noiseMapUpdateAvailable = false;
    }
    //map generation script
    public void GenerateMap()
    {
        #region variables and setup
        //this is the base noise module that will be manipulated
        baseModule = null;
        //this is the noisemap that will be generated
        noiseMap = null;
        MapDisplay display = FindObjectOfType <MapDisplay>();

        if (!useRandomSeed)
        {
            seedValue = seed.GetHashCode();
        }
        else
        {
            seedValue = UnityEngine.Random.Range(0, 10000000);
        }
        #endregion

        #region Noise Function Setup
        for (int i = 0; i < noiseFunctions.Length; i++)
        {
            noiseFunctions[i].seed = seedValue + i;
        }

        //generates noise for every noisefunction
        for (int i = 0; i < noiseFunctions.Length; i++)
        {
            if (noiseFunctions[i].enabled)
            {
                noiseFunctions[i].MakeNoise();
            }
        }

        //manipulates the base module based on the noise modules
        for (int i = 0; i < noiseFunctions.Length; i++)
        {
            //for first valid noise pattern simply pass the noise function
            if (baseModule == null && noiseFunctions[i].enabled)
            {
                baseModule = noiseFunctions[i].moduleBase;
            }

            //all others valid add to the previous iteration of the baseModule
            else if (noiseFunctions[i].enabled)
            {
                baseModule = new Add(baseModule, noiseFunctions[i].moduleBase);
            }
        }

        //clamps the module to between 1 and 0
        if (clamped)
        {
            baseModule = new Clamp(0, 1, baseModule);
        }

        noiseMap = new Noise2D(mapWidth, mapHeight, baseModule);
        #endregion

        #region Planet Generator
        if (mapType == MapType.Planet)
        {
            noiseMap.GenerateSpherical(-90, 90, -180, 180);
            Color[] colorMap = new Color[noiseMap.Width * noiseMap.Height];
            textures[0] = new Texture2D(noiseMap.Width, noiseMap.Height);
            if (renderType == RenderType.Greyscale)
            {
                textures[0] = noiseMap.GetTexture(LibNoise.Unity.Gradient.Grayscale);
            }
            else
            {
                for (int y = 0; y < noiseMap.Height; y++)
                {
                    for (int x = 0; x < noiseMap.Width; x++)
                    {
                        float currentHeight = noiseMap[x, y];
                        for (int i = 0; i < regions.Length; i++)
                        {
                            if (currentHeight <= regions[i].height)
                            {
                                colorMap[y * noiseMap.Width + x] = regions[i].color;
                                break;
                            }
                        }
                    }
                }

                textures[0].SetPixels(colorMap);
            }
            textures[0].Apply();

            Mesh newMesh = SphereMagic.CreatePlanet(PlanetItterations, radius, baseModule, heightMultiplier, regions);

            display.DrawMesh(newMesh, textures[0]);
        }
        #endregion

        #region Flat Terrain
        else if (mapType == MapType.FlatTerrain)
        {
            display.TextureRender = FindObjectOfType <Renderer>();
            textures[0]           = noiseMap.GetTexture(LibNoise.Unity.Gradient.Grayscale);
            Color[] colorMap = new Color[noiseMap.Width * noiseMap.Height];
            for (int y = 0; y < noiseMap.Height; y++)
            {
                for (int x = 0; x < noiseMap.Width; x++)
                {
                    float currentHeight = noiseMap[x, y];
                    for (int i = 0; i < regions.Length; i++)
                    {
                        if (currentHeight <= regions[i].height)
                        {
                            colorMap[y * noiseMap.Width + x] = regions[i].color;
                            break;
                        }
                    }
                }
            }

            textures[0].SetPixels(colorMap);
            textures[0].Apply();

            display.DrawMesh(FlatMeshGenerator.GenerateTerrainMesh(noiseMap, heightMultiplier, heightAdjuster), textures[0]);
        }
        #endregion
    }
    /// <summary>
    /// The Core Map Generation Method, in essence this method
    /// takes the stack of noise methods and processes them
    /// sequentially and generates a resultant noise map.
    /// It then calls a function to generate the Mesh (or 3D object)
    /// and applies the noise to the mesh inside of the function
    /// to draw the mesh.
    ///
    /// Also in this located in this region is the map texture generator,
    /// which actually makes up a signifigant bulk of the computational
    /// cost of most map generation schemas I've found useful.
    /// -RGS
    /// </summary>
    public void GenerateMap()
    {
        //MFU Need to work on the hiearchy / code reduction
        //in this method in particular.

        //MFU After reorganization add easier initial generation
        //calls with different types of arguments (files / settings mixtures).

        #region variables and setup
        //autoUpdate saftey catch disabled after implementing multithreading, may be added again if this is pulled back out.
        //if (autoUpdate && (mapWidth > 400 || mapHeight > 200))
        //{
        //    mapWidth = 400;
        //    mapHeight = 200;
        //     Debug.Log("Texture resolution reduced to 400x200 max during Auto Update!");
        //}

        //this is the base noise module that will be manipulated
        baseModule = null;

        //this is the noisemap that will be generated
        noiseMap = null;

        //next two commands interface with multithreaded renderer
        HaltThreads();
        reset = true;


        MapDisplay display = FindObjectOfType <MapDisplay>();


        if (!useRandomSeed)
        {
            seedValue = seed.GetHashCode();
        }
        else
        {
            seedValue = UnityEngine.Random.Range(0, 10000000);
        }


        #endregion

        #region Noise Function Setup
        for (int i = 0; i < noiseFunctions.Length; i++)
        {
            noiseFunctions[i].seed = seedValue + i;
            noiseFunctions[i].MakeNoise();

            //for first valid noise pattern simply pass the noise function
            if (baseModule == null && noiseFunctions[i].enabled)
            {
                baseModule = noiseFunctions[i].moduleBase;
            }

            //all others valid add to the previous iteration of the baseModule
            else if (noiseFunctions[i].enabled)
            {
                //this is where I want to do blend mode adjustments using
                //libNoise add, blend, subtract, multiply etc as an effect (along with falloffs maybe)
                baseModule = new Add(baseModule, noiseFunctions[i].moduleBase);
            }
        }

        //clamps the module to between 1 and 0, sort of...
        //because of the way coherent noise works, it's not possible to completely
        //eliminate the possibility that a value will fall outside these ranges.

        if (clamped)
        {
            baseModule = new Clamp(0, 1, baseModule);
        }
        noiseMap = new Noise2D(mapWidth, mapHeight, baseModule);
        #endregion

        #region Planet Generator
        if (mapType == MapType.Planet)
        {
            mapHeight  = mapWidth / 2;
            renderType = RenderType.Color;

            noiseMap = new Noise2D(100, 100, baseModule);
            noiseMap.GenerateSpherical(-90, 90, -180, 180);
            mapTexture = GetMapTexture(renderType, noiseMap);
            if ((oceans) && (!waterMesh.activeSelf))
            {
                waterMesh.SetActive(true);
            }
            if (waterMesh != null)
            {
                //MFU better Sea Level Autoupdate / switch
                waterMesh.transform.localScale = 2 * (new Vector3(radius + seaLevelOffset, radius + seaLevelOffset, radius + seaLevelOffset));

                if (!oceans)
                {
                    waterMesh.SetActive(false);
                }
            }
            display.DrawMesh(SphereMagic.CreatePlanet(PlanetItterations, radius, baseModule, heightMultiplier, regions), mapTexture);
        }
        #endregion

        #region Flat Terrain Generator
        //non functional

        else if (mapType == MapType.FlatTerrain)
        {
            noiseMap = new Noise2D(100, 100, baseModule);
            noiseMap.GeneratePlanar(-1, 1, -1, 1, seamless);
            display.TextureRender = FindObjectOfType <Renderer>();
            mapTexture            = GetMapTexture(renderType, noiseMap);
            display.DrawMesh(FlatMeshGenerator.GenerateTerrainMesh(noiseMap, heightMultiplier, heightAdjuster), mapTexture);
        }
        #endregion

        #region Start Multithreaded Noisemapping
        if (drawInProgress)
        {
            HaltThreads();
        }

        latestTimeProcessRequested = DateTime.Now.GetHashCode();
        drawInProgress             = true;
        stop = false;
        StartCoroutine(TextureRefiner());
        #endregion
    }