public void SetWorldParams(ITerrainGenerator terrainGenerator, ILODSpec lodSpec) { InitShadowParams(); this.terrainGenerator = terrainGenerator; this.lodSpec = lodSpec; }
public void GeneratePoints(Vector3 offset, int worldSize, float scale, ITerrainGenerator generator, float noiseScale, Vector3 noiseOffset) { points = new Point?[worldSize * worldSize * worldSize]; for (int z = 0; z < worldSize; z++) { for (int y = 0; y < worldSize; y++) { for (int x = 0; x < worldSize; x++) { int idx = x + y * worldSize + z * worldSize * worldSize; Vector3 pos = (new Vector3(x, y, z) + (offset * (worldSize - 1))) / (worldSize - 1); Vector3 p = pos * scale; points[idx] = new Point { x = p.x, y = p.y, z = p.z, val = generator.genVal(noiseScale * (pos.x * (worldSize - 1) - (worldSize - 1) / 2f) + noiseOffset.x, noiseScale * (pos.y * (worldSize - 1) - (worldSize - 1) / 2f + noiseOffset.y), noiseScale * (pos.z * (worldSize - 1) - (worldSize - 1) / 2f) + noiseOffset.z) }; } } } }
public override void Execute() { ITerrainGenerator generator = mChunk.mTerrain.mTerrainGenerator; int X = mChunk.mChunkID.X * VoxelChunk.ChunkWidth; int Z = mChunk.mChunkID.Z * VoxelChunk.ChunkWidth; for (int x = 0; x < VoxelChunk.ChunkWidth; ++x) { for (int y = 0; y < VoxelChunk.ChunkHeight; ++y) { for (int z = 0; z < VoxelChunk.ChunkWidth; ++z) { if (bIsAborted) { return; } ushort meta; mChunk.Set(x, y, z, generator.GetVoxel(X + x, y, Z + z, out meta), meta); } } } }
public void Setup(ITerrainGenerator terrainGenerator, ShipConfiguration shipConfiguration) { this.terrainGenerator = terrainGenerator; this.shipConfiguration = shipConfiguration; entityManager = World.Active.EntityManager; SetupFloatingSystem(); }
public void Awake() { generator = new TerrainGenerator() .RegisterDecorator(new BiomeDecorator()) .RegisterDecorator(new HeightmapDecorator(noiseScale: 5, biomePower: 2.3f)) .RegisterDecorator(new BiomeSplatMapDecorator()) .RegisterDecorator(new TreePlacerDecorator(worldHeight: 600)); }
// Start is called before the first frame update public TreeManager(IPlacementController placementController, ITerrainGenerator terrainGenerator) { _placementController = placementController; _terrainGenerator = terrainGenerator; _coastModel = Resources.Load <GameObject>(Util.PathTo("Tree_Coast")); _flatlandModel = Resources.Load <GameObject>(Util.PathTo("Tree_Flatland")); _hillModel = Resources.Load <GameObject>(Util.PathTo("Tree_Hill")); _mountainModel = Resources.Load <GameObject>(Util.PathTo("Tree_Mountain")); }
/// <summary> /// Initializes a new instance of the <see cref="ChunkCache"/> class. /// </summary> /// <param name="game">The game.</param> /// <param name="maxMapsInMemory">The maximum maps in memory.</param> public ChunkCache(int maxMapsInMemory = 100) // TODO: Don't leave it at 100 { // Setters MaxChunksInMemory = maxMapsInMemory; _chunkWidth = Core.Engine.Instance.Configuration.Chunk.WidthInTiles * 32; // 32 pixels _chunkHeight = Core.Engine.Instance.Configuration.Chunk.HeightInTiles * 32; // 32 pixels _chunkGenerator = new SimpleTerrain(); ChunkStorage = new ChunkStorage(); }
public World(WorldData worldData, ITerrainGenerator terrainGenerator, ILightProcessor lightProcessor, IMeshGenerator meshGenerator, IWorldDecorator worldDecorator) { m_WorldData = worldData; m_LightProcessor = lightProcessor; m_MeshGenerator = meshGenerator; m_WorldDecorator = worldDecorator; m_TerrainGenerator = terrainGenerator; }
public World(WorldData worldData, ITerrainGenerator terrainGenerator, ILightProcessor lightProcessor, IMeshDataGenerator meshDataGenerator, IWorldDecorator worldDecorator, IChunkProcessor chunkProcessor) { m_WorldData = worldData; m_LightProcessor = lightProcessor; m_MeshDataGenerator = meshDataGenerator; m_WorldDecorator = worldDecorator; m_ChunkProcessor = chunkProcessor; m_TerrainGenerator = terrainGenerator; ContinueProcessingChunks = true; }
public World(WorldData worldData, ITerrainGenerator terrainGenerator, ILightProcessor lightProcessor, IMeshDataGenerator meshDataGenerator, IWorldDecorator worldDecorator, IChunkProcessor chunkProcessor) { m_WorldData = worldData; m_LightProcessor = lightProcessor; m_MeshDataGenerator = meshDataGenerator; m_WorldDecorator = worldDecorator; m_ChunkProcessor = chunkProcessor; m_TerrainGenerator = terrainGenerator; ContinueProcessingChunks = true; }
public PathFinder(ITerrainGenerator terrainGenerator) { _pathFindingAlgorithms = new Dictionary <PathType, AbstractPathFindingAlgorithm> { { PathType.Road, new NetworkAStarPathFinding() }, { PathType.Rail, new RailAStarPathFinding() }, { PathType.Water, new TileAStarPathFinding(terrainGenerator, TerrainGenerator.TerrainType.Ocean) }, { PathType.Air, new AirPathFinding() } }; }
/// <summary> /// This implementation turns the given placeable in a square around it's starting position until a valid position is found. /// </summary> /// <param name="placementController"></param> /// <param name="terrainGenerator"></param> /// <param name="placeable"></param> /// <returns></returns> public static ThreadsafePlaceable MoveToPlaceablePosition(IPlacementController placementController, ITerrainGenerator terrainGenerator, ThreadsafePlaceable placeable) { while (!terrainGenerator.IsReady(placeable.Position)) { Thread.Sleep(50); } int stepSize = 2; int targetXMove = 0; int targetYMove = 0; int currentXMove = 0; int currentYMove = 0; int direction = -1; // Moves the cityPlaceable in a growing square around the starting position until a suitable location is found while (!placementController.IsPlaceable(placeable.Position, placeable.NeededSpaces)) { // Move one step at a time if (currentXMove > 0) { placeable.Translate(direction * stepSize, 0, 0); currentXMove--; continue; } if (currentYMove > 0) { placeable.Translate(0, 0, direction * stepSize); currentYMove--; continue; } // Control step Amount if (targetXMove == targetYMove) { direction = -direction; targetXMove++; currentXMove = targetXMove; } else { targetYMove = targetXMove; currentYMove = targetYMove; } } return(placeable); }
private Engine() { this.enemies = EnemiesProvider.Instance; this.terrain = TerrainProvider.Instance; this.terrainGenerator = TerrainGenerator.Instance; this.drawer = new ConsoleDrawer(); this.projectileFactory = new ProjectileFactory(); this.terrain.Terrain = terrainGenerator.GenerateRandomMap(Constants.TerrainCountOnMap).ToList(); this.mover = Mover.Instance; this.firstPlayer = this.terrainGenerator.GenerateFirstPlayer(); this.secondPlayer = this.terrainGenerator.GenerateSecondPlayer(); }
private void CreateTerrainGenerator() { switch (terrainGeneratorType) { case TerrainGeneratorType.TerrainGenerator: terrainGenerator = new TerrainGenerator(TerrainSettings); break; case TerrainGeneratorType.TerrainGeneratorJobs: terrainGenerator = new TerrainGeneratorJobs(TerrainSettings); break; case TerrainGeneratorType.TerrainGeneratorThreads: terrainGenerator = new TerrainGeneratorThreads(TerrainSettings); break; } }
void Update() { SceneView.duringSceneGui += OnSceneGUI; if (update) { update = false; } else { return; } worldSize = (int)(chunkSize / (blockSize > 0 ? blockSize : 1)); generator = new PerlinGenerator();// if (regenerate) { CleanChunks(); GameObject worldObject = GameObject.Find("World"); Material defaultMat = GetComponent <MeshRenderer>().material; chunks = new Chunk[numChunks.x, numChunks.y, numChunks.z]; regenerate = false; for (int x = 0; x < numChunks.x; x++) { for (int y = 0; y < numChunks.y; y++) { for (int z = 0; z < numChunks.z; z++) { GameObject gm = new GameObject($"chunk {x},{y},{z}"); Chunk chunk = gm.AddComponent <Chunk>(); gm.AddComponent <MeshFilter>(); gm.AddComponent <MeshCollider>(); gm.AddComponent <MeshRenderer>(); chunk.GeneratePoints(new Vector3(x, y, z), worldSize, scale, generator, noiseScale, noiseOffset); chunk.BuildMesh(defaultMat, computeShader, doubleSidedMesh, invertMesh, wireFrame, tolerance, chunkComputeShader, worldSize); gm.transform.parent = worldObject.transform; chunks[x, y, z] = chunk; } } } } }
private HommMapGenerator( IMazeGenerator mazeGenerator, ITerrainGenerator terrainGenerator, params ISpawner[] entitiesGenerators) { if (mazeGenerator == null) { throw new InvalidOperationException("should select one IMazeGenerator"); } if (terrainGenerator == null) { throw new InvalidOperationException("should select one ITerrainGenerator"); } this.mazeGenerator = mazeGenerator; this.terrainGenerator = terrainGenerator; this.entitiesGenerators = entitiesGenerators; }
private void Start() { _progressionManager = new ProgressionManager(); _vehicleManager = new VehicleManager(); if (_gameSettings == null) { _gameSettings = Resources.Load <GameSettings>(Util.PathTo("GameSettings")); } _threadedDataRequester = new ThreadedDataRequester(); // Terrain Generator MeshSettings meshSettings = Resources.Load <MeshSettings>(Util.PathTo("MeshSettings")); HeightMapSettings heightMapSettings = Resources.Load <HeightMapSettings>(Util.PathTo("HeightMapSettings")); Material terrainMaterial = Resources.Load <Material>(Util.PathTo("TerrainMeshMaterial")); Transform viewer = _terrainViewer; _terrainGenerator = new TerrainGenerator(meshSettings, heightMapSettings, viewer, terrainMaterial, _gameSettings.MapSize); _buildingManager = new BuildingManager(); _placementController = new PlacementController(_buildingManager, _terrainGenerator); _cityCityManager = new CityManager(_placementController, heightMapSettings.noiseSettings.seed); _treeManager = new TreeManager(_placementController, _terrainGenerator); _transportRouteManager = new TransportRouteManager(new PathFinder(_terrainGenerator), _vehicleManager); }
public TileAStarPathFinding(ITerrainGenerator terrainGenerator, TerrainGenerator.TerrainType terrainType) { _terrainGenerator = terrainGenerator; TerrainType = terrainType; }
public OverWorld(IPlayer player, ITerrainGenerator terrainGenerator) { Player = player; this.terrainGenerator = terrainGenerator; }
/// <summary> /// Initialize the world manager /// </summary> public void Initialize(SceneManager sceneManager, ITerrainGenerator gen, ILODSpec clientLodSpec, SceneNode root) { Debug.Assert(!initialized, "Attempt to initialize already initialized TerrainManager"); scene = sceneManager; terrainGenerator = gen; terrainGenerator.TerrainChanged += TerrainGenerator_OnTerrainChanged; lodSpec = clientLodSpec ?? defaultLODSpec; pageSize = lodSpec.PageSize; visPageRadius = lodSpec.VisiblePageRadius; pageArraySize = (visPageRadius * 2) + 1; // Compute the size of a "subPage", which is the same as the smalles tile size. // We assume that the page containing the camera will have the smallest sized tiles. subPageSize = pageSize / TilesPerPage(0); minMetersPerSample = lodSpec.MetersPerSample(Vector3.Zero, 0, 0); maxMetersPerSample = lodSpec.MetersPerSample(Vector3.Zero, visPageRadius, visPageRadius * pageSize / subPageSize); rootSceneNode = root; worldRootSceneNode = rootSceneNode.CreateChildSceneNode("TerrainRoot"); oceanSceneNode = rootSceneNode.CreateChildSceneNode("OceanNode"); terrainMaterialConfig = new AutoSplatConfig(); terrainDecalManager = new TerrainDecalManager(pageArraySize); shadowConfig = new ShadowConfig(scene); oceanConfig = new OceanConfig(); oceanConfig.ConfigChange += OceanConfigChanged; ocean = new OceanPage(oceanConfig); oceanSceneNode.AttachObject(ocean); //ocean.ShowBoundingBox = true; showOcean = true; detailVeg = new DetailVeg(65, rootSceneNode); // allocate the page array pages = new Page[pageArraySize, pageArraySize]; InitPages(); heightFieldsCreated = false; boundaries = new List<Boundary>(); roads = new Roads(); SpeedTreeWrapper.SetDropToBillboard(true); // make sure variables based on camera location are up to date CameraLocation = cameraLocation; // set up material used by water boundaries waterMaterial = MaterialManager.Instance.GetByName("MVSMWater"); if (waterMaterial != null) waterMaterial.Load(); initialized = true; }
private void TerrainGenerator_OnTerrainChanged(ITerrainGenerator generator, int worldXMeters, int worldZMeters, int sizeXMeters, int sizeZMeters) { int topLeftPageXMeters = (int) (pages[0, 0].Location.x/oneMeter); int topLeftPageZMeters = (int) (pages[0, 0].Location.z/oneMeter); int pageSizeMeters = pageSize; // Find out which pages are affectd by the changed region and recreate them. int pageStartX = (worldXMeters - topLeftPageXMeters) / pageSizeMeters; int pageStartZ = (worldZMeters - topLeftPageZMeters)/pageSizeMeters; int pageEndX = (worldXMeters - topLeftPageXMeters + sizeXMeters) / pageSizeMeters; int pageEndZ = (worldZMeters - topLeftPageZMeters + sizeZMeters) / pageSizeMeters; // Recreate the modified pages for (int z = pageStartZ; z <= pageEndZ; z++) { for (int x = pageStartX; x <= pageEndX; x++) { Page modifiedPage = LookupPage(x, z); if (modifiedPage != null) { // Console.WriteLine("Updating page: [" + x + "," + z + "] at: " + pages[x, z].Location); pages[x, z].TerrainPage.ResetHeightMaps(); } } } }
public static ThreadsafePlaceable FindForrestPosition(IPlacementController placementController, ITerrainGenerator terrainGenerator, ThreadsafePlaceable placeable, float[,] values) { while (!terrainGenerator.IsReady(placeable.Position)) { Thread.Sleep(50); } List <NeededSpace> coastNeededSpace = new List <NeededSpace> { new NeededSpace(Vector3Int.zero, TerrainGenerator.TerrainType.Coast) }; List <NeededSpace> flatLandNeededSpace = new List <NeededSpace> { new NeededSpace(Vector3Int.zero, TerrainGenerator.TerrainType.Flatland) }; List <NeededSpace> hillNeededSpace = new List <NeededSpace> { new NeededSpace(Vector3Int.zero, TerrainGenerator.TerrainType.Hill) }; List <NeededSpace> mountainNeededSpace = new List <NeededSpace> { new NeededSpace(Vector3Int.zero, TerrainGenerator.TerrainType.Mountain) }; float limit = 0.1f; for (int x = 0; x < values.GetLength(0) - 3; x++) { for (int y = 0; y < values.GetLength(1) - 3; y++) { Vector3Int relativePosition = new Vector3Int(x - values.GetLength(0) / 2 + 1, 0, y - values.GetLength(1) / 2 + 1); Vector3 absolutePosition = relativePosition + placeable.Position; bool isThreshold = (values[x, y] > limit - 0.05f && values[x, y] < limit + 0.05f); if (!isThreshold) { continue; } TerrainGenerator.TerrainType terrainType = terrainGenerator.GetTerrainType(absolutePosition.x, absolutePosition.z); bool isPlaceable = false; switch (terrainType) { case TerrainGenerator.TerrainType.Flatland: isPlaceable = placementController.IsPlaceable(absolutePosition, flatLandNeededSpace); break; case TerrainGenerator.TerrainType.Coast: isPlaceable = placementController.IsPlaceable(absolutePosition, coastNeededSpace); break; case TerrainGenerator.TerrainType.Hill: isPlaceable = placementController.IsPlaceable(absolutePosition, hillNeededSpace); break; case TerrainGenerator.TerrainType.Mountain: isPlaceable = placementController.IsPlaceable(absolutePosition, mountainNeededSpace); break; } if (!isPlaceable) { continue; } placeable.NeededSpaces.Add(new ProceduralNeededSpace(relativePosition, terrainType, values[x, y])); } } return(placeable); }
// Start is called before the first frame update private void Start() { var points = new List <Point>(); try { Debug.Log(Application.dataPath); Debug.Log(Application.persistentDataPath); _mapObject = new GameObject("Map"); if (LoadMapFromCache()) { return; } _hexGrid = new HexGrid(Height, Width, HexTile); _map = new HexMap(Height, Width); _organisationFactory = new OrganisationFactory(); _mapOrganizationGenerator = new MapOrganizationGenerator(_mapObject, _organisationFactory); _countryGenerator = new CountryGenerator(_organisationFactory, _mapOrganizationGenerator); var heightMapGenerator = new HeightMapGenerator(MountainRatio); _terrainGenerator = new TerrainGenerator(heightMapGenerator); _terrainGenerator.DesertBelt = DesertBelt; _terrainGenerator.PoleBelt = PoleBelt; var voronoiMap = GenerateMap(); points = voronoiMap.Where(g => g is Site).Select(s => s.Point).ToList(); _provinceFactory = new ProvinceFactory(_map, _lines, Instantiate, Province, _organisationFactory); _regions = _provinceFactory.CreateProvinces(points); Debug.Log("Map check after region detection"); CheckMap(points); var majorCountryNames = SettingsLoader.Instance.MajorCountryNames; var minorCountryNames = SettingsLoader.Instance.MinorCountryNames; _countryNames = majorCountryNames.Union(minorCountryNames).ToList(); _countryGenerator.GenerateCountries(_regions, _map, MajorCountries, MinorCountries, ProvincesMajorCountries, ProvincesMinorCountries, majorCountryNames, minorCountryNames, Instantiate, Country, CountryColors); _mapOrganizationGenerator.GenerateContinentsList(Instantiate, Continent, _regions, _map, _mapObject); _terrainGenerator.GenerateTerrain(_map); var resources = SettingsLoader.Instance.ResourceSettings; ResourceService.Instance.SpreadResources(_map, resources); if (MapMode == MapMode.InGame) { SkinMap(); } else { ColorCountries(); } StoreMapIntoCache(); var siteCommands = string.Join(", ", points.Select(p => $"new Point({p.X}, {p.Y})")); var siteListComand = $"var points = new List<Point> {{ {siteCommands} }};"; Debug.Log(siteListComand); } catch (Exception e) { Debug.LogError(e); LogMap(); var siteCommands = string.Join(", ", points.Select(p => $"new Point({p.X}, {p.Y})")); var siteListComand = $"var points = new List<Point> {{ {siteCommands} }};"; Debug.Log(siteListComand); Debug.Log("var lines = new List<Position>()"); Debug.Log("{"); foreach (var line in _lines) { Debug.Log($"new Position({line.X}, {line.Y})"); } Debug.Log("}"); } }
public static ITerrainGenerator Over(this ITerrainGenerator top, ITerrainGenerator bottom) { return(new AggregatedTerrainGenerator(top, bottom)); }
internal BuilderOnSelectEntities( IMazeGenerator mazeGenerator, ITerrainGenerator terrainGenerator) { this.mazeGenerator = mazeGenerator; this.terrainGenerator = terrainGenerator; }
public HommMapGenerator And(ITerrainGenerator terrainGenerator) { return(new HommMapGenerator(mazeGenerator, terrainGenerator)); }
public void Setup(ITerrainGenerator terrainGenerator, ShipConfiguration shipConfiguration) { this.terrainGenerator = terrainGenerator; this.shipConfiguration = shipConfiguration; }
public void Setup(ITerrainGenerator terrainGenerator) { this.terrainGenerator = terrainGenerator; }
public Terrain(Game game, GraphicsDevice graphicsDevice, ITerrainGenerator generator, BaseCamera camera) : base(game) { this.graphicsDevice = graphicsDevice; this.generator = generator; this.camera = camera; }
public BuilderOnSelectEntities With(ITerrainGenerator terrainGenerator) { return(new BuilderOnSelectEntities(mazeGenerator, terrainGenerator)); }
public void SetWorldParams(ITerrainGenerator terrainGenerator, ILODSpec lodSpec) { InitShadowParams(); this.terrainGenerator = terrainGenerator; this.lodSpec = lodSpec; }