Exemplo n.º 1
0
        public void NewGame()
        {
            WorldData = JsonUtility.FromJson <WorldData>(WorldDataAsset.text);
            WorldData.Init();

            _worldGenData = JsonUtility.FromJson <WorldGenData>(WorldGenAsset.text);

            Icosphere = Instantiate(IcospherePrefab, transform);
            Icosphere.Init(Subdivisions);

            StaticState = new StaticState();
            StaticState.Init(_worldGenData.Radius, Icosphere, WorldData);

            _simulation = new SimTick(StaticState);

            _tempState = new TempState(StaticState);


            int height = 3;

            for (int i = 0; i < _simStates.Length; i++)
            {
                _simStates[i] = new SimState();
                _simStates[i].Init(StaticState);
            }

            WorldGen.Generate(StaticState.Count, height, _worldGenData, _simStates[_curSimStateIndex], StaticState);
            _initialized = true;

            NewGameEvent?.Invoke(_simStates[_curSimStateIndex]);
        }
Exemplo n.º 2
0
        public void Init(int cellCount, StaticState staticState)
        {
            _maxFoliagePerCell = MaxFoliagePerCell;
            _foliage           = new GameObject[cellCount * _maxFoliagePerCell];
            _foliageData       = new NativeArray <FoliageData>(cellCount * _maxFoliagePerCell, Allocator.Persistent);
            _foliageState      = new NativeArray <FoliageState>(cellCount * _maxFoliagePerCell, Allocator.Persistent);
            _foliageTransform  = new NativeArray <FoliageTransform>(cellCount * _maxFoliagePerCell, Allocator.Persistent);

            var initFoliageJob = new InitFoliageJob()
            {
                Data = _foliageData,
                SphericalPosition          = staticState.SphericalPosition,
                FoliageTypes               = FoliagePrefabs.Count,
                FloraCoveragePowerForTrees = FloraCoveragePowerForTrees,
                GrowthDelayRange           = TreeGrowthDelayRange,
                GrowthSpeed       = TreeGrowthSpeed,
                GrowthSpeedRange  = TreeGrowthSpeedRange,
                MaxFoliagePerCell = _maxFoliagePerCell,
                PerturbDistance   = PerturbCellRadius * math.length(staticState.SphericalPosition[0] - staticState.SphericalPosition[staticState.Neighbors[0]]),
                RandomSeed        = 3452,
                Scale             = TreeScale,
                ScaleRange        = TreeScaleRange,
            };
            var handle = initFoliageJob.Schedule(_foliageData.Length, 100);

            handle.Complete();
        }
Exemplo n.º 3
0
        public void Init(StaticState staticState)
        {
            Temperature       = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            LandMass          = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            VaporMass         = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            CloudMass         = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            IceMass           = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            WaterMass         = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            SaltMass          = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            MineralMass       = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            CarbonDioxideMass = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            OxygenMass        = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            NitrogenMass      = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            OrganicMass       = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            Dirt       = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            Sand       = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            Vegetation = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            Current    = new NativeArray <float3>(staticState.Count, Allocator.Persistent);

            Elevation  = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            WaterDepth = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            Flow       = new NativeArray <float>(staticState.Count * StaticState.MaxNeighbors, Allocator.Persistent);

            Explored       = new NativeArray <float>(staticState.Count, Allocator.Persistent);
            AnimalPosition = new NativeArray <int>(staticState.AnimalCount, Allocator.Persistent);
            AnimalSpecies  = new NativeArray <int>(staticState.AnimalCount, Allocator.Persistent);

            _initialized = true;
        }
Exemplo n.º 4
0
 public TempState(StaticState staticState)
 {
     SurfaceElevation = new NativeArray <float>(staticState.Count, Allocator.Persistent);
     OutgoingFlow     = new NativeArray <float>(staticState.Count, Allocator.Persistent);
     FlowPercent      = new NativeArray <float>(staticState.Count * StaticState.MaxNeighbors, Allocator.Persistent);
     WaterDelta       = new NativeArray <float>(staticState.Count, Allocator.Persistent);
     FloraCoverage    = new NativeArray <float>(staticState.Count, Allocator.Persistent);
 }
Exemplo n.º 5
0
        static public void Generate(int columns, int height, WorldGenData worldGenData, SimState state, StaticState staticState)
        {
            state.Planet.Gravity        = worldGenData.Gravity;
            state.Planet.DistanceToSun  = worldGenData.DistanceToSun;
            state.Planet.Rotation       = math.radians(math.float3(worldGenData.TiltAngle, 0, 0));
            state.Planet.Position       = math.float3(1, 0, 0) * worldGenData.DistanceToSun;
            state.Planet.SpinSpeed      = math.PI * 2 / (worldGenData.SpinTime * 60 * 60);
            state.Planet.OrbitSpeed     = math.PI * 2 / worldGenData.OrbitTime;
            state.Planet.AngularSpeed   = math.PI * 2 / (worldGenData.SpinTime * 60 * 60);
            state.Planet.GeothermalHeat = worldGenData.GeothermalHeat;
            state.Planet.SolarRadiation = worldGenData.SolarRadiation;

            for (int i = 0; i < columns; i++)
            {
                var pos = staticState.SphericalPosition[i];
                state.Elevation[i]   = (0.5f * noise.snoise(pos) + 0.4f * noise.snoise(pos * 3) + 0.1f * noise.snoise(pos * 9)) * 12000f - 1000f;
                state.WaterDepth[i]  = math.max(0, -state.Elevation[i]);
                state.Dirt[i]        = math.max(0, -state.Elevation[i]);
                state.Sand[i]        = math.max(0, -state.Elevation[i]);
                state.Vegetation[i]  = math.max(0, -state.Elevation[i]);
                state.IceMass[i]     = noise.snoise(pos) * (math.saturate(state.Elevation[i]) + 1000) * math.abs(staticState.Coordinate[i].y) / 1000;
                state.Dirt[i]        = math.saturate(noise.snoise(pos));
                state.Sand[i]        = math.saturate(noise.snoise(pos + new float3(6567)));
                state.Vegetation[i]  = math.saturate(noise.snoise(pos + new float3(543252)));
                state.Temperature[i] = WorldData.FreezingTemperature;
                state.Explored[i]    = pos.x > 0.2f ? 1 : 0;
            }
        }
Exemplo n.º 6
0
        public JobHandle Tick(SimState lastState, SimState nextState, StaticState staticState, TempState tempState, WorldData worldData, JobHandle dependency)
        {
            float coriolisTerm = 2 * lastState.Planet.SpinSpeed;

            nextState.CarbonDioxideMass.CopyFrom(lastState.CarbonDioxideMass);
            nextState.CloudMass.CopyFrom(lastState.CloudMass);
            nextState.Current.CopyFrom(lastState.Current);
            nextState.IceMass.CopyFrom(lastState.IceMass);
            nextState.LandMass.CopyFrom(lastState.LandMass);
            nextState.MineralMass.CopyFrom(lastState.MineralMass);
            nextState.NitrogenMass.CopyFrom(lastState.NitrogenMass);
            nextState.OrganicMass.CopyFrom(lastState.OrganicMass);
            nextState.OxygenMass.CopyFrom(lastState.OxygenMass);
            nextState.SaltMass.CopyFrom(lastState.SaltMass);
            nextState.Temperature.CopyFrom(lastState.Temperature);
            nextState.VaporMass.CopyFrom(lastState.VaporMass);
            nextState.WaterMass.CopyFrom(lastState.WaterMass);

            nextState.WaterDepth.CopyFrom(lastState.WaterDepth);
            nextState.Flow.CopyFrom(lastState.Flow);
            nextState.Vegetation.CopyFrom(lastState.Vegetation);
            nextState.Sand.CopyFrom(lastState.Sand);
            nextState.Dirt.CopyFrom(lastState.Dirt);
            nextState.OrganicMass.CopyFrom(lastState.OrganicMass);
            nextState.Elevation.CopyFrom(lastState.Elevation);
            nextState.Explored.CopyFrom(lastState.Explored);

            nextState.AnimalSpecies.CopyFrom(lastState.AnimalSpecies);
            nextState.AnimalPosition.CopyFrom(lastState.AnimalPosition);

            nextState.Planet = lastState.Planet;



            bool sync = false;

            dependency = _columnJobHelper.Schedule(sync, 1, dependency,
                                                   new UpdateSurfaceElevationJob()
            {
                SurfaceElevation = tempState.SurfaceElevation,
                WaterDepth       = nextState.WaterDepth,
                Elevation        = nextState.Elevation
            });


            dependency = _neighborJobHelper.Schedule(sync, 1, dependency,
                                                     new UpdateFlowVelocityJob()
            {
                Flow                = nextState.Flow,
                LastFlow            = lastState.Flow,
                SurfaceElevation    = tempState.SurfaceElevation,
                WaterDepth          = nextState.WaterDepth,
                NeighborDistInverse = staticState.NeighborDistInverse,
                Neighbors           = staticState.Neighbors,
                SecondsPerTick      = worldData.SecondsPerTick,
                Gravity             = nextState.Planet.Gravity,
                Damping             = worldData.SurfaceWaterFlowDamping,
                ViscosityInverse    = 1.0f - worldData.WaterViscosity
            });
            dependency = _columnJobHelper.Schedule(sync, 1, dependency,
                                                   new SumOutgoingFlowJob()
            {
                OutgoingFlow = tempState.OutgoingFlow,
                Flow         = nextState.Flow,
            });
            dependency = _neighborJobHelper.Schedule(sync, 1, dependency,
                                                     new LimitOutgoingFlowJob()
            {
                Flow         = nextState.Flow,
                FlowPercent  = tempState.FlowPercent,
                OutgoingFlow = tempState.OutgoingFlow,
                WaterDepth   = nextState.WaterDepth,
                Neighbors    = staticState.Neighbors,
            });
            dependency = _columnJobHelper.Schedule(sync, 1, dependency,
                                                   new ApplyFlowWaterJob()
            {
                Delta              = tempState.WaterDelta,
                Depth              = nextState.WaterDepth,
                Positions          = staticState.SphericalPosition,
                Neighbors          = staticState.Neighbors,
                ReverseNeighbors   = staticState.ReverseNeighbors,
                FlowPercent        = tempState.FlowPercent,
                CoriolisMultiplier = staticState.CoriolisMultiplier,
                CoriolisTerm       = coriolisTerm,
                SecondsPerTick     = worldData.SecondsPerTick
            });
            dependency = _columnJobHelper.Schedule(sync, 1, dependency,
                                                   new ApplyWaterDeltaJob()
            {
                Depth = nextState.WaterDepth,
                Delta = tempState.WaterDelta,
            });

            dependency = _animalJobHelper.Schedule(sync, dependency, new UpdateExplorationJob()
            {
                Exploration     = nextState.Explored,
                AnimalSpecies   = nextState.AnimalSpecies,
                AnimalPositions = nextState.AnimalPosition,
            });

            return(dependency);
        }
Exemplo n.º 7
0
 public SimTick(StaticState staticState)
 {
     _columnJobHelper   = new JobHelper(staticState.Count);
     _neighborJobHelper = new JobHelper(staticState.Count * StaticState.MaxNeighbors);
     _animalJobHelper   = new JobHelper(staticState.AnimalCount);
 }
Exemplo n.º 8
0
        public JobHandle CreateViewStateFromSimState(SimState from, ViewState to, WorldData worldData, StaticState staticState, float terrainScale, JobHandle dependency)
        {
            //to.Ticks = from.PlanetState.Ticks;
            //to.Position = from.PlanetState.Position;
            //to.Rotation = math.degrees(from.PlanetState.Rotation);

            MeshOverlayData meshOverlay;
            bool            useMeshOverlay = GetMeshOverlayData(ActiveOverlay, from, staticState, worldData, out meshOverlay);

            var buildRenderStateJobHandle = _perCellJobHelper.Schedule(
                true, 1, dependency,
                new CreateViewStateJob()
            {
                TerrainColor     = to.TerrainColor,
                TerrainElevation = to.TerrainElevation,
                WaterColor       = to.WaterColor,
                WaterElevation   = to.WaterElevation,
                OverlayColor     = to.OverlayColor,
                TerrainState     = to.TerrainState,

                Elevation               = from.Elevation,
                WaterDepth              = from.WaterDepth,
                Dirt                    = from.Dirt,
                Sand                    = from.Sand,
                Vegetation              = from.Vegetation,
                Ice                     = from.IceMass,
                Explored                = from.Explored,
                MeshOverlayMin          = meshOverlay.Colors.Min,
                MeshOverlayInverseRange = meshOverlay.InverseRange,
                MeshOverlayData         = meshOverlay.Values,
                MeshOverlayColors       = meshOverlay.Colors.ColorValuePairs,
                MeshOverlayActive       = ActiveOverlay != MeshOverlay.None,
                PlanetRadius            = staticState.PlanetRadius,
                TerrainScale            = terrainScale,
            });

            return(buildRenderStateJobHandle);
        }