示例#1
0
        private void LevelFinalizeInit()
        {
            InitDummySim();

            WeatherDataAtPlayer   = getWeatherDataReaderPreLoad();
            WeatherDataSlowAccess = getWeatherDataReader();

            simSounds.Initialize();
            simParticles.Initialize();
            cloudRenderer = new CloudRenderer(capi, this);

            smoothedLightLevel = capi.World.BlockAccessor.GetLightLevel(capi.World.Player.Entity.Pos.AsBlockPos, EnumLightLevelType.OnlySunLight);


            capi.Ambient.CurrentModifiers.InsertBefore("serverambient", "weather", WeatherDataAtPlayer.BlendedWeatherData.Ambient);
            haveLevelFinalize = true;

            // Pre init the clouds.
            capi.Ambient.UpdateAmbient(0.1f);
            CloudRenderer renderer = this.cloudRenderer as CloudRenderer;

            renderer.blendedCloudDensity          = capi.Ambient.BlendedCloudDensity;
            renderer.blendedGlobalCloudBrightness = capi.Ambient.BlendedCloudBrightness;
            renderer.CloudTick(0.1f);
        }
示例#2
0
        public CloudRenderer(ICoreClientAPI capi, WeatherSystemClient weatherSys)
        {
            this.capi           = capi;
            this.weatherSys     = weatherSys;
            this.wreaderpreload = weatherSys.getWeatherDataReaderPreLoad();
            rand = new Random(capi.World.Seed);

            capi.Event.RegisterRenderer(this, EnumRenderStage.OIT, "clouds");
            capi.Event.ReloadShader += LoadShader;

            LoadShader();



            double time = capi.World.Calendar.TotalHours * 60;

            windOffsetX += 2f * time;
            windOffsetZ += 0.1f * time;

            mainThreadState.WindTileOffsetX += (int)(windOffsetX / CloudTileSize);
            windOffsetX %= CloudTileSize;

            mainThreadState.WindTileOffsetZ += (int)(windOffsetZ / CloudTileSize);
            windOffsetZ %= CloudTileSize;

            offThreadState.Set(mainThreadState);
            committedState.Set(mainThreadState);

            InitCloudTiles((8 * capi.World.Player.WorldData.DesiredViewDistance));
            LoadCloudModel();


            capi.Settings.AddWatcher <int>("viewDistance", OnViewDistanceChanged);
            capi.Settings.AddWatcher <bool>("renderClouds", (val) => renderClouds = val);

            renderClouds = capi.Settings.Bool["renderClouds"];

            InitCustomDataBuffers(updateMesh);

            capi.Event.LeaveWorld += () =>
            {
                isShuttingDown = true;
            };

            cloudTileUpdThread = new Thread(new ThreadStart(() =>
            {
                while (!isShuttingDown)
                {
                    if (!newStateRready)
                    {
                        int winddx = (int)windOffsetX / CloudTileSize;
                        int winddz = (int)windOffsetZ / CloudTileSize;

                        int prevx = offThreadState.CenterTilePos.X;
                        int prevz = offThreadState.CenterTilePos.Z;
                        offThreadState.Set(mainThreadState);

                        offThreadState.WindTileOffsetX += winddx;
                        offThreadState.WindTileOffsetZ += winddz;

                        int dx = winddx + prevx - offThreadState.CenterTilePos.X;
                        int dz = winddz + prevz - offThreadState.CenterTilePos.Z;
                        if (dx != 0 || dz != 0)
                        {
                            MoveCloudTilesOffThread(dx, dz);
                        }

                        UpdateCloudTilesOffThread(instantTileBlend ? short.MaxValue : cloudTileBlendSpeed);

                        instantTileBlend = false;
                        newStateRready   = true;
                    }

                    Thread.Sleep(40);
                }
            }));

            cloudTileUpdThread.IsBackground = true;
        }