public override void Dispose() { TerrainRenderer.Dispose(); TerrainUpdater.Dispose(); TerrainSerializer.Dispose(); Terrain.Dispose(); }
public override void OnInspectorGUI() { DrawDefaultInspector(); TerrainUpdater _target = (TerrainUpdater)target; if (GUILayout.Button("Build Terrain")) { _target.EditorCreateMesh(); } }
public void ChangeCell(int x, int y, int z, int value, bool updateModificationCounter = true) { if (!Terrain.IsCellValid(x, y, z)) { return; } int cellValueFast = Terrain.GetCellValueFast(x, y, z); value = Terrain.ReplaceLight(value, 0); cellValueFast = Terrain.ReplaceLight(cellValueFast, 0); if (value == cellValueFast) { return; } Terrain.SetCellValueFast(x, y, z, value); TerrainChunk chunkAtCell = Terrain.GetChunkAtCell(x, z); if (chunkAtCell != null) { if (updateModificationCounter) { chunkAtCell.ModificationCounter++; } TerrainUpdater.DowngradeChunkNeighborhoodState(chunkAtCell.Coords, 1, TerrainChunkState.InvalidLight, forceGeometryRegeneration: false); } m_modifiedCells[new Point3(x, y, z)] = true; int num = Terrain.ExtractContents(cellValueFast); int num2 = Terrain.ExtractContents(value); if (num2 != num) { SubsystemBlockBehavior[] blockBehaviors = m_subsystemBlockBehaviors.GetBlockBehaviors(num); for (int i = 0; i < blockBehaviors.Length; i++) { blockBehaviors[i].OnBlockRemoved(cellValueFast, value, x, y, z); } SubsystemBlockBehavior[] blockBehaviors2 = m_subsystemBlockBehaviors.GetBlockBehaviors(num2); for (int j = 0; j < blockBehaviors2.Length; j++) { blockBehaviors2[j].OnBlockAdded(value, cellValueFast, x, y, z); } } else { SubsystemBlockBehavior[] blockBehaviors3 = m_subsystemBlockBehaviors.GetBlockBehaviors(num2); for (int k = 0; k < blockBehaviors3.Length; k++) { blockBehaviors3[k].OnBlockModified(value, cellValueFast, x, y, z); } } }
//====== ctors public GameLogic(Size terrainSize, GameTime gameTime) : base(gameTime) { terrain = new Terrain(terrainSize); snakeBody = new SnakeBody(new Point(terrain.Size.Width / 2, terrain.Size.Height / 2)); speed = new SnakeSpeed(); applesGenerator = new AppleGenerator(terrain, gameTime); applesConsumer = new AppleConsumer(terrain, snakeBody, gameTime); terrainUpdater = new TerrainUpdater(terrain, snakeBody, gameTime); gameOverConditions = new GameOverConditions(snakeBody, terrain, applesGenerator, gameTime); score = new Score(); moveQueue = new SnakeMoveQueue(); updater = new GameObjectsUpdater(); SetupGameObjectsUpdater(); applesConsumer.Consumed += AppleConsumer_AppleConsumed; }
public void Draw(Camera camera, int drawOrder) { if (TerrainRenderingEnabled) { if (drawOrder == m_drawOrders[0]) { TerrainUpdater.PrepareForDrawing(camera); TerrainRenderer.PrepareForDrawing(camera); TerrainRenderer.DrawOpaque(camera); TerrainRenderer.DrawAlphaTested(camera); } else if (drawOrder == m_drawOrders[1]) { TerrainRenderer.DrawTransparent(camera); } } }
public override void Load(ValuesDictionary valuesDictionary) { m_subsystemViews = base.Project.FindSubsystem <SubsystemGameWidgets>(throwOnError: true); SubsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemParticles = base.Project.FindSubsystem <SubsystemParticles>(throwOnError: true); m_subsystemPickables = base.Project.FindSubsystem <SubsystemPickables>(throwOnError: true); m_subsystemBlockBehaviors = base.Project.FindSubsystem <SubsystemBlockBehaviors>(throwOnError: true); SubsystemAnimatedTextures = base.Project.FindSubsystem <SubsystemAnimatedTextures>(throwOnError: true); SubsystemFurnitureBlockBehavior = base.Project.FindSubsystem <SubsystemFurnitureBlockBehavior>(throwOnError: true); SubsystemPalette = base.Project.FindSubsystem <SubsystemPalette>(throwOnError: true); Terrain = new Terrain(); TerrainRenderer = new TerrainRenderer(this); TerrainUpdater = new TerrainUpdater(this); TerrainSerializer = new TerrainSerializer22(Terrain, SubsystemGameInfo.DirectoryName); BlockGeometryGenerator = new BlockGeometryGenerator(Terrain, this, base.Project.FindSubsystem <SubsystemElectricity>(throwOnError: true), SubsystemFurnitureBlockBehavior, base.Project.FindSubsystem <SubsystemMetersBlockBehavior>(throwOnError: true), SubsystemPalette); if (string.CompareOrdinal(SubsystemGameInfo.WorldSettings.OriginalSerializationVersion, "2.1") <= 0) { TerrainGenerationMode terrainGenerationMode = SubsystemGameInfo.WorldSettings.TerrainGenerationMode; if (terrainGenerationMode == TerrainGenerationMode.FlatContinent || terrainGenerationMode == TerrainGenerationMode.FlatIsland) { TerrainContentsGenerator = new TerrainContentsGeneratorFlat(this); } else { TerrainContentsGenerator = new TerrainContentsGenerator21(this); } } else { TerrainGenerationMode terrainGenerationMode2 = SubsystemGameInfo.WorldSettings.TerrainGenerationMode; if (terrainGenerationMode2 == TerrainGenerationMode.FlatContinent || terrainGenerationMode2 == TerrainGenerationMode.FlatIsland) { TerrainContentsGenerator = new TerrainContentsGeneratorFlat(this); } else { TerrainContentsGenerator = new TerrainContentsGenerator22(this); } } }
//void Awake(){ // instance = this; //} //public ObjectPlacer objTest; //private int awayLOD; void Start() { //seed = (int)System.DateTime.Now.Ticks; //awayLOD = LOD; falloffMap = FallOffGenerator.GenerateFalloffMap(textQual); if (player != null) { distThread = new TerrainUpdater(); } //QualitySettings.shadowDistance = radius; for (int i = 0; i < lodLevel.Length; i++) { lodLevel [i].distance *= radius; } if (psh == null) { psh = gameObject.GetComponent <SpawningManager> (); } GenerateMap(true); // if (placeOnStart) // createTrees (); }
public static void GenerateChunkVertices(TerrainUpdater updater, TerrainChunk chunk, int x1, int z1, int x2, int z2) { if (chunk.ThreadState == TerrainChunkState.InvalidVertices1) { Data.Remove(chunk.Coords); } Terrain terrain = updater.m_terrain; TerrainChunk chunkAtCoords = terrain.GetChunkAtCoords(chunk.Coords.X - 1, chunk.Coords.Y - 1); TerrainChunk chunkAtCoords2 = terrain.GetChunkAtCoords(chunk.Coords.X, chunk.Coords.Y - 1); TerrainChunk chunkAtCoords3 = terrain.GetChunkAtCoords(chunk.Coords.X + 1, chunk.Coords.Y - 1); TerrainChunk chunkAtCoords4 = terrain.GetChunkAtCoords(chunk.Coords.X - 1, chunk.Coords.Y); TerrainChunk chunkAtCoords5 = terrain.GetChunkAtCoords(chunk.Coords.X + 1, chunk.Coords.Y); TerrainChunk chunkAtCoords6 = terrain.GetChunkAtCoords(chunk.Coords.X - 1, chunk.Coords.Y + 1); TerrainChunk chunkAtCoords7 = terrain.GetChunkAtCoords(chunk.Coords.X, chunk.Coords.Y + 1); TerrainChunk chunkAtCoords8 = terrain.GetChunkAtCoords(chunk.Coords.X + 1, chunk.Coords.Y + 1); if (chunkAtCoords4 == null) { x1 = MathUtils.Max(x1, 1); } if (chunkAtCoords2 == null) { z1 = MathUtils.Max(z1, 1); } if (chunkAtCoords5 == null) { x2 = MathUtils.Min(x2, 15); } if (chunkAtCoords7 == null) { z2 = MathUtils.Min(z2, 15); } for (int i = x1; i < x2; i++) { for (int j = z1; j < z2; j++) { switch (i) { case 0: if ((j == 0 && chunkAtCoords == null) || (j == 15 && chunkAtCoords6 == null)) { continue; } break; case 15: if ((j == 0 && chunkAtCoords3 == null) || (j == 15 && chunkAtCoords8 == null)) { continue; } break; } int num = i + chunk.Origin.X; int num2 = j + chunk.Origin.Y; int bottomHeightFast = chunk.GetBottomHeightFast(i, j); int bottomHeight = terrain.GetBottomHeight(num - 1, num2); int bottomHeight2 = terrain.GetBottomHeight(num + 1, num2); int bottomHeight3 = terrain.GetBottomHeight(num, num2 - 1); int bottomHeight4 = terrain.GetBottomHeight(num, num2 + 1); int x3 = MathUtils.Min(bottomHeightFast - 1, MathUtils.Min(bottomHeight, bottomHeight2, bottomHeight3, bottomHeight4)); int topHeightFast = chunk.GetTopHeightFast(i, j); int num3 = MathUtils.Max(x3, 1); topHeightFast = MathUtils.Min(topHeightFast, 126); int num4 = TerrainChunk.CalculateCellIndex(i, 0, j); for (int k = num3; k <= topHeightFast; k++) { int cellValueFast = chunk.GetCellValueFast(num4 + k); int num5 = Terrain.ExtractContents(cellValueFast); if (num5 != 0) { BlocksManager.Blocks[num5].GenerateTerrainVertices(updater.m_subsystemTerrain.BlockGeometryGenerator, chunk.Geometry, cellValueFast, num, k, num2); chunk.GeometryMinY = MathUtils.Min(chunk.GeometryMinY, k); chunk.GeometryMaxY = MathUtils.Max(chunk.GeometryMaxY, k); } } } } }
// Use this for initialization void Start() { networkManager = GameObject.FindObjectOfType <NetworkManager>(); tu = GameObject.FindObjectOfType <TerrainUpdater>(); }
public void Update(float dt) { TerrainUpdater.Update(); ProcessModifiedCells(); }
private void Awake() { updater = GetComponent <TerrainUpdater>(); }