private static void CreateImage(NoiseConfig config, HeightmapLayer layer, WaterLayer waterLayer) { var bmp = new Bitmap(config.Size, config.Size); var maxDepth = waterLayer.Waterline - layer.MinHeight; var maxHeight = layer.MaxHeight - waterLayer.Waterline; for (var x = 0; x < config.Size; x++) { for (var y = 0; y < config.Size; y++) { if (waterLayer.GetCell(x, y)) { var depth = waterLayer.Waterline - layer.GetCell(x, y); var g = 255 - (byte)(255 * (depth / maxDepth)); var b = 255 - (byte)(100 * (depth / maxDepth)); bmp.SetPixel(x, y, Color.FromArgb(0, g, b)); } else { var height = layer.GetCell(x, y) - waterLayer.Waterline; var b = (byte)(50 * height / maxHeight); var r = (byte)(255 * height / maxHeight); var g = 175 - (byte)(50 * height / maxHeight); bmp.SetPixel(x, y, Color.FromArgb(r, g, b)); } } } var codec = GetEncoder(ImageFormat.Jpeg); var filename = "test.jpg"; bmp.Save(filename, codec, GetEncoderParameters()); }
public void SetValues( SizingConfig sizingConfig, NoiseConfig noiseConfig, FalloffConfig falloffConfig, ColorConfig colorConfig, BackgroundColorConfig backgroundColorConfig, OutlineConfig outlineConfig, SymmetryConfig symmetryConfig, SymmetryConfig3D symmetryConfig3D, ScalingConfig scalingConfig, AnimationConfig animationConfig, ShadingConfig shadingConfig, CleanupConfig cleanupConfig, NormalsConfig normalsConfig ) { this.sizingConfig = sizingConfig; this.noiseConfig = noiseConfig; this.falloffConfig = falloffConfig; this.colorConfig = colorConfig; this.backgroundColorConfig = backgroundColorConfig; this.outlineConfig = outlineConfig; this.symmetryConfig = symmetryConfig; this.symmetryConfig3D = symmetryConfig3D; this.scalingConfig = scalingConfig; this.animationConfig = animationConfig; this.shadingConfig = shadingConfig; this.cleanupConfig = cleanupConfig; this.normalsConfig = normalsConfig; }
private void GenerateResources(NoiseConfig noiseConfig) { noiseMap = NoiseUtils.GenerateNoiseMap(width, height, noiseConfig); for (int x = 0; x < noiseMap.GetLength(0); x++) { for (int z = 0; z < noiseMap.GetLength(1); z++) { if (tiles[x, z] != TileType.Empty) { continue; } else if (MathUtils.InRange(Settings.World_Gen_CopperNoiseRangeFrom, Settings.World_Gen_CopperNoiseRangeTo, noiseMap[x, z])) { SetTile(x, z, TileType.CopperNode); } else if (MathUtils.InRange(Settings.World_Gen_IronNoiseRangeFrom, Settings.World_Gen_IronNoiseRangeTo, noiseMap[x, z])) { SetTile(x, z, TileType.IronNode); } else if (MathUtils.InRange(Settings.World_Gen_FoodNoiseRangeFrom, Settings.World_Gen_FoodNoiseRangeTo, noiseMap[x, z])) { SetTile(x, z, TileType.FoodNode); } //else //Debug.Log("Wierd noise value: " + noiseMap[x, y]); } } }
public IEnumerator AwaitConfig() { for (;;) { if (Config._instance != null) { if (!Serialization.ReadConfig()) { ApplyDefaultConfig(); } else { defaultCoroutineTiming = Config.Settings.coroutineTiming; } if (!Serialization.ReadNoiseConfig()) { NoiseConfig.ApplyDefaults(); } setOptions.SetResolution(Config.Settings.resolution); Config.QualityLevel = Config.QualityLevel; Config.WorldSize = Config.Settings.worldSize; setOptions.SetMusicLevel(Config.MusicVolume * 0.01f); setOptions.SetSfxLevel(Config.SfxVolume * 0.01f); break; } else { yield return(null); } } }
public Texture2D GetNoise(NoiseConfig noiseConfig, int spritePixelSize, Vector2 desiredOrigin) { var tex = new Texture2D(spritePixelSize, spritePixelSize); tex.SetPixels(CalcNoise(noiseConfig, spritePixelSize, desiredOrigin)); return(tex); }
static void Main(string[] args) { //var dsConfig = new DiamondSquareConfig(12, 0.67f); var pnConfig1 = new NoiseConfig(2000, 0.7); var generator1 = new Noise(pnConfig1); var h1 = generator1.GenerateAsync(); var pnConfig2 = new NoiseConfig(2000, 0.25); var generator2 = new Noise(pnConfig2); var h2 = generator2.GenerateAsync(); var hlayer1 = new HeightmapLayer(h1.Result); var hlayer2 = new HeightmapLayer(h2.Result); var hlayerCells = HeightmapLayer.Overlay(hlayer1, hlayer2, new OverlayFloatSum()); var hlayer = new HeightmapLayer( HeightmapLayer.NormalizeHeights( new HeightmapLayer(hlayerCells))); var stopWatch = new Stopwatch(); stopWatch.Start(); var m = new Map(); m.AddLayer <HeightmapLayer, float>(hlayer); var waterLine = WaterLayer.GetWaterlineFromPercentage(hlayer, 0.35f); var waterLayer = new WaterLayer(hlayer, waterLine); m.AddLayer <WaterLayer, bool>(waterLayer); CreateImage(pnConfig1, hlayer, waterLayer); stopWatch.Stop(); Debug.WriteLine(stopWatch.Elapsed); }
public Vector2 GetOriginWithOffset(int frame, NoiseConfig config, EvolutionConfig evolutionConfig) { var sourceOriginThisFrame = evolutionConfig.evolutionSource[frame].origin; origin = new Vector2(sourceOriginThisFrame.x + (evolutionConfig.offsetFromSource.x * noisePerEvolutionStep), sourceOriginThisFrame.y + (evolutionConfig.offsetFromSource.y * noisePerEvolutionStep)); return(origin); }
public void updateNoiseConfig(NoiseConfig noiseConfig) { var noiseConfigQuery = (from a in context.noiseConfig where a.idNoiseConfig == 1 select a).FirstOrDefault(); noiseConfigQuery.onNoiseConfig = noiseConfig.OnNoiseConfig; noiseConfigQuery.timeSendInfoNoiseConfig = noiseConfig.TimeSendInfoNoiseConfig; context.SaveChanges(); }
private void SetNoise(NoiseConfig config) { topRigNoise.m_AmplitudeGain = config.amplitudeGain; topRigNoise.m_FrequencyGain = config.frequencyGain; midRigNoise.m_AmplitudeGain = config.amplitudeGain; midRigNoise.m_FrequencyGain = config.frequencyGain; botRigNoise.m_AmplitudeGain = config.amplitudeGain; botRigNoise.m_FrequencyGain = config.frequencyGain; }
public void Copy(ConfigurationAsset source) { sizingConfig = source.sizingConfig; noiseConfig = source.noiseConfig; falloffConfig = source.falloffConfig; colorConfig = source.colorConfig; backgroundColorConfig = source.backgroundColorConfig; outlineConfig = source.outlineConfig; symmetryConfig = source.symmetryConfig; symmetryConfig3D = source.symmetryConfig3D; scalingConfig = source.scalingConfig; animationConfig = source.animationConfig; shadingConfig = source.shadingConfig; cleanupConfig = source.cleanupConfig; normalsConfig = source.normalsConfig; }
public void BuildWorld(int maxPlayers, NoiseConfig noiseConfig) { worldBuilder = new WorldBuilder(width, height, maxPlayers, noiseConfig); for (int x = 0; x < width; x++) { for (int z = 0; z < height; z++) { InventoryItem itemFromTileType = InventoryItem(worldBuilder.Tiles[x, z]); if (itemFromTileType != null) { SpawnResourceNode(itemFromTileType, x, z); } } } }
public WorldBuilder(int width, int height, int maxPlayers, NoiseConfig noiseConfig) { this.width = width; this.height = height; tiles = new TileType[width, height]; for (int i = 0; i < maxPlayers; i++) { GeneratePlayerArea(); } if (noiseConfig != null) { GenerateResources(noiseConfig); } }
public Vector2 GetOrigin(int frame, NoiseConfig config) { if (frame == 0) { origin = config.randomOrigin ? new Vector2(RandomValue(config.randomOriginBound), RandomValue(config.randomOriginBound)) : config.manualOrigin; } else { origin = new Vector2( origin.x + config.animationFrameNoiseOffset * frame, origin.y + config.animationFrameNoiseOffset * frame); } return(origin); }
Color[] CalcNoise(NoiseConfig config, int spritePixelSize, Vector2 origin) { var size = spritePixelSize; var colors = new Color[size * size]; var frequencies = new float[config.octaves.Count]; if (config.randomizeFrequency) { var totalFrequency = 0f; while (totalFrequency < .9f) { var availableFrequency = maxFrequencySum; for (int i = 0; i < config.octaves.Count; i++) { var frequency = Random.Range(0, availableFrequency); frequencies[i] = frequency; availableFrequency -= frequency; totalFrequency += frequency; } } } else { for (int i = 0; i < config.octaves.Count; i++) { frequencies[i] = config.octaves[i].frequency; } } for (var octaveIndex = 0; octaveIndex < config.octaves.Count; octaveIndex++) { for (var row = 0f; row < size; row++) { for (var column = 0f; column < size; column++) { var xCoordinate = origin.x + row / size * config.octaves[octaveIndex].scale; var yCoordinate = origin.y + column / size * config.octaves[octaveIndex].scale; var sample = Mathf.PerlinNoise(xCoordinate, yCoordinate); colors[(int)column * size + (int)row] += new Color(sample, sample, sample) * frequencies[octaveIndex]; } } } return(colors); }
public void TestOverlay() { var pnConfig1 = new NoiseConfig(100, 0.7); var generator1 = new Noise(pnConfig1); var h1 = generator1.GenerateAsync(); var pnConfig2 = new NoiseConfig(100, 0.25); var generator2 = new Noise(pnConfig2); var h2 = generator2.GenerateAsync(); var hlayer1 = new HeightmapLayer(h1.Result); var hlayer2 = new HeightmapLayer(h2.Result); var hlayerCells = HeightmapLayer.Overlay(hlayer1, hlayer2, new OverlayFloatSum()); var hlayer = new HeightmapLayer(hlayerCells); Assert.Equal(h1.Result[50, 50] + hlayer2.GetCell(50, 50), hlayer.GetCell(50, 50)); }
public Vector3 GetOrigin3D(NoiseConfig config, int depthLayer) { if (depthLayer == 0) { origin3D = new Vector3( RandomValue(config.randomOriginBound), RandomValue(config.randomOriginBound), RandomValue(config.randomOriginBound)); } else { origin3D = new Vector3( origin3D.x + config.animationFrameNoiseOffset * depthLayer, origin3D.y + config.animationFrameNoiseOffset * depthLayer, origin3D.z + config.animationFrameNoiseOffset * depthLayer); } return(origin3D); }
public static void StartGame() { int width = Convert.ToInt32(NetworkPanel.instance.worldWidthField.text); int height = Convert.ToInt32(NetworkPanel.instance.worldHeightField.text); GameObject worldControllerGameObject = GameObject.Instantiate(CustomNetworkManager.instance.worldControllerPrefab, new Vector3(0, 0, 0), Quaternion.identity); WorldController.instance.SetDimensions(width, height); // Set before network spawning world controller so width and height syncs for client correctly InfectionManager.instance.Initialize(width, height); NetworkServer.Spawn(worldControllerGameObject); NoiseConfig noiseConfig = new NoiseConfig() { Scale = 0.99f, Octaves = 4, Persistance = 0.3f, Lacunarity = 0.55f }; WorldController.instance.BuildWorld(NetworkPanel.instance.MaxPlayers(), noiseConfig); WorldController.instance.GetComponent <ScavengerSpawner>().enabled = true; WorldController.instance.GetComponent <WinLoseChecker>().enabled = true; WorldController.instance.GetComponent <WorldTickController>().enabled = true; foreach (NetworkConnection conn in NetworkServer.connections) { LobbyPlayer lobbyPlayer = players.FirstOrDefault(p => p.ConnectionID == conn.connectionId); if (lobbyPlayer != null) { WorldController.instance.SpawnPlayer(conn, lobbyPlayer.Nick); SendToClient(conn, Event.ServerStartedGame); } else { Debug.LogWarning("Could not find lobby player object for connectionID " + conn.connectionId); } } for (int i = 0; i < (int)NetworkPanel.instance.aiCountSlider.value; i++) { WorldController.instance.SpawnAI("AI " + (i + 1)); } hasGameStarted = true; }
public void SetupDemoWorld() { DestroyDemoWorld(); if (transform.childCount > 0) { return; } NoiseConfig noiseConfig = new NoiseConfig() { Scale = scale, Octaves = octaves, Persistance = persistance, Lacunarity = lacunarity }; GameObject worldControllerGameObject = (GameObject)Instantiate(worldControllerPrefab, new Vector3(0, 0, 0), Quaternion.identity); worldControllerGameObject.transform.parent = transform; worldControllerGameObject.GetComponent <WorldController>().BuildWorldDemoWorld(width, height, transform, noiseConfig); }
public Texture3D GetNoise3D(NoiseConfig noiseConfig, int spritePixelSize, ref Vector2 generatedVoxelOrigin) { var modelData = new Texture3D(spritePixelSize, spritePixelSize, spritePixelSize, DefaultFormat.LDR, TextureCreationFlags.None); var colors = new Color[spritePixelSize * spritePixelSize * spritePixelSize]; // generate a 2D texture at every vertical layer of the 3D texture, stacking them on top of each other for (var i = 0; i < modelData.depth; i++) { var currentLayerOrigin = GetOrigin3D(noiseConfig, i); var noise = CalcNoise(noiseConfig, spritePixelSize, currentLayerOrigin); noise.CopyTo(colors, i * spritePixelSize * spritePixelSize); if (i == 0) { generatedVoxelOrigin = currentLayerOrigin; } } modelData.SetPixels(colors); return(modelData); }
public Texture3D GetNoise3D(NoiseConfig noiseConfig, Vector3Int voxelSize, ref Vector2 generatedVoxelOrigin) { var modelData = new Texture3D(voxelSize.x, voxelSize.y, voxelSize.z, DefaultFormat.LDR, TextureCreationFlags.None); var colors = new Color[voxelSize.x * voxelSize.y * voxelSize.z]; // generate a 2D texture at every vertical layer of the 3D texture, stacking them on top of each other for (var i = 0; i < modelData.width; i++) { var currentLayerOrigin = GetOrigin3D(noiseConfig, i); var noise = CalcNoise(noiseConfig, voxelSize.y, voxelSize.z, currentLayerOrigin); var colorStartIndex = i * noise.Length; noise.CopyTo(colors, colorStartIndex); if (i == 0) { generatedVoxelOrigin = currentLayerOrigin; } } modelData.SetPixels(colors); return(modelData); }
protected NoiseConfig(NoiseConfig cfg) : this(cfg.Invert, cfg.MinThreshold, cfg.MaxThreshold, cfg.Round, cfg.Scale, cfg.OutputGrayscale, cfg.Seed) { }
public void updateNoiseConfig(NoiseConfig noiseConfig) { noiseDB.updateNoiseConfig(noiseConfig); }
/// <summary> /// Read description on other method. TODO: Se if summary can inherit from other method /// </summary> public static float[,] GenerateNoiseMap(int mapWidth, int mapHeight, NoiseConfig config) { return(GenerateNoiseMap(mapWidth, mapHeight, config.Scale, config.Octaves, config.Persistance, config.Lacunarity)); }
public void BuildWorldDemoWorld(int width, int height, Transform demoWorldParent, NoiseConfig noiseConfig) { classIsUsedAsDemo = true; worldParent = demoWorldParent; SetDimensions(width, height); BuildWorld(10, noiseConfig); SpawnAndAdjustGround(); }
public string _initialize(string seed) { if (String.IsNullOrEmpty(seed)) { if (String.IsNullOrEmpty(randomWord)) { seed = GameUtils.GenerateSeed(5).Trim(); } else { seed = randomWord; } } else { seed = seed.ToUpper().Trim(); } int n; if (int.TryParse(seed, out n)) { UnityEngine.Random.InitState(n); } else { UnityEngine.Random.InitState(seed.GetHashCode()); } // these two must happen before anything else kicks off GameUtils.SetHash(); GameUtils.CreateSeedTable(); // start generating world parameters NoiseConfig.Initialize(); ColorFactory.GeneratePalette(); Blocks.Initialize(); cosmos.CreateSky(); World.Seed = seed; Serialization.Decompress(); // These populate the object pools ChunkData.SetLoadOrder(); World.Spawn.Initialize(firstRun); // Initialize graphics edgeDetect.enabled = Config.Outlines; edgeDetect.sampleDist = ((float)Screen.height / 1080f) * 1.4f; hbao = mainCamera.GetComponent <HBAO>(); hbao.enabled = Config.ContactShadows; RenderSettings.fog = true; if (Config.ShadowsEnabled) { if (Config.QualityLevel == Quality.Ultra) { sun.shadows = LightShadows.Soft; moon.shadows = LightShadows.Soft; } else { sun.shadows = LightShadows.Soft; moon.shadows = LightShadows.Soft; } } else { sun.shadows = LightShadows.None; moon.shadows = LightShadows.None; } RenderSettings.ambientIntensity = 0f; sun.intensity = 0f; boids.StartBoids(); firstRun = false; return(seed); }
public CylinderConfig(float frequency, NoiseConfig cfg ) : base(cfg) { Frequency = frequency; }
// PUT: api/NoiseConfig/5 public void Put([FromBody] NoiseConfig noiseConfig) { noiseBusiness.updateNoiseConfig(noiseConfig); }