예제 #1
0
        public void Destroy()
        {
            if (_destroyed)
            {
                return;
            }
            _destroyed = true;

            foreach (var disposable in _disposables)
            {
                disposable.Dispose();
            }
            _disposables.Clear();

            Ticker.UnregisterTicked(this);
            Ticker.UnregisterTicked(EntityManager);
            Ticker.UnregisterTicked(PhysicsEngine);
            Ticker.UnregisterTicked(ChunkManager);

            BackgroundWorker?.Dispose();

            EntityManager.Dispose();
            EntityManager = null;

            ChunkManager.Dispose();
            ChunkManager = null;

            Player.Dispose();
            Ticker.Dispose();
        }
예제 #2
0
        public void Render(IRenderArgs args)
        {
            Graphics.DepthStencilState = DepthStencilState.Default;
            Graphics.SamplerStates[0]  = SamplerState.PointWrap;

            if (UseDepthMap)
            {
                ChunkManager.Draw(args, true);
            }

            SkyRenderer.Draw(args);
            ChunkManager.Draw(args, false);

            EntityManager.Render(args);

            //TestItemRender.Render(args.GraphicsDevice, (Camera.Position + (Camera.Direction * 2.5f)));

            if (Camera is ThirdPersonCamera)
            {
                Player.RenderEntity = true;
            }
            else
            {
                Player.RenderEntity = false;
            }

            Player.Camera = Camera;
            Player.Render(args);
        }
예제 #3
0
파일: World.cs 프로젝트: K4mey/Alex
        public void Render(IRenderArgs args)
        {
            Graphics.DepthStencilState = DepthStencilState.Default;
            Graphics.SamplerStates[0]  = SamplerState.PointWrap;

            if (UseDepthMap)
            {
                ChunkManager.Draw(args, true);
            }

            SkyRenderer.Draw(args);

            ChunkManager.Draw(args,
                              false,
                              RenderStage.OpaqueFullCube,
                              RenderStage.Opaque);

            EntityManager.Render(args);

            ChunkManager.Draw(args, false,
                              RenderStage.Transparent,
                              RenderStage.Translucent,
                              RenderStage.Animated,
                              RenderStage.AnimatedTranslucent,
                              RenderStage.Liquid);

            //TestItemRender.Render(args.GraphicsDevice, (Camera.Position + (Camera.Direction * 2.5f)));

            //Player.Camera = Camera;
            Player.Render(args);
        }
예제 #4
0
        public void Render(IRenderArgs args)
        {
            if (_destroyed)
            {
                return;
            }

            args.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            args.GraphicsDevice.SamplerStates[0]  = SamplerState.PointWrap;

            SkyBox.Draw(args);

            ChunkManager.Draw(args,
                              RenderStage.OpaqueFullCube,
                              RenderStage.Opaque);

            EntityManager.Render(args);

            ChunkManager.Draw(args,
                              RenderStage.Transparent,
                              RenderStage.Translucent,
                              RenderStage.Animated,
                              RenderStage.Liquid);

            Player.Render(args);
        }
예제 #5
0
파일: World.cs 프로젝트: PocketGold-MP/Alex
        public void OnTick()
        {
            Player?.OnTick();

            Time++;

            if (DoDaylightcycle)
            {
                var tod = TimeOfDay;
                TimeOfDay = ((tod + 1) % 24000);
            }
        }
예제 #6
0
        /// <inheritdoc />
        public override void PlayerOnGroundChanged(Player player, bool onGround)
        {
            if (Client.ConnectionState != ConnectionState.Play)
            {
                return;
            }

            Client.SendPacket(new PlayerMovementPacket()
            {
                OnGround = onGround
            });
        }
예제 #7
0
파일: World.cs 프로젝트: K4mey/Alex
        public void Update(UpdateArgs args)
        {
            var camera = Camera;

            args.Camera = camera;
            if (Player.FOVModifier != _fovModifier)
            {
                _fovModifier = Player.FOVModifier;

                camera.FOV += _fovModifier;
                camera.UpdateProjectionMatrix();
                camera.FOV -= _fovModifier;
            }
            camera.Update(args);

            BrightnessMod = SkyRenderer.BrightnessModifier;

            SkyRenderer.Update(args);
            ChunkManager.Update(args);
            EntityManager.Update(args, SkyRenderer);
            PhysicsEngine.Update(args.GameTime);

            var diffuseColor = Color.White.ToVector3() * SkyRenderer.BrightnessModifier;

            ChunkManager.AmbientLightColor = diffuseColor;

            if (Math.Abs(ChunkManager.BrightnessModifier - SkyRenderer.BrightnessModifier) > 0f)
            {
                ChunkManager.BrightnessModifier = SkyRenderer.BrightnessModifier;
            }

            Player.ModelRenderer.DiffuseColor = diffuseColor;
            Player.Update(args);

            if (Player.IsInWater)
            {
                ChunkManager.FogColor    = new Vector3(0.2666667F, 0.6862745F, 0.9607844F) * BrightnessModifier;
                ChunkManager.FogDistance = (float)Math.Pow(Options.VideoOptions.RenderDistance, 2) * 0.15f;
            }
            else
            {
                ChunkManager.FogColor    = SkyRenderer.WorldFogColor.ToVector3();
                ChunkManager.FogDistance = (float)Options.VideoOptions.RenderDistance * 16f * 0.8f;
            }

            if (Ticker.Update(args))
            {
                if (DoDaylightcycle)
                {
                    Time++;
                }
            }
        }
예제 #8
0
        public void Update(UpdateArgs args)
        {
            if (_destroyed)
            {
                return;
            }

            var camera = Camera;

            args.Camera = camera;

            /*if (Math.Abs(Player.FOVModifier - _fovModifier) > 0f)
             * {
             *      _fovModifier = Player.FOVModifier;
             *
             *      camera.FOV += _fovModifier;
             *      camera.UpdateProjectionMatrix();
             *      camera.FOV -= _fovModifier;
             * }*/
            camera.Update(args);

            //_brightnessMod = SkyRenderer.BrightnessModifier;

            SkyBox.Update(args);
            ChunkManager.Update(args);

            EntityManager.Update(args);
            PhysicsEngine.Update(args.GameTime);

            if (Math.Abs(_brightnessMod - SkyBox.BrightnessModifier) > 0f)
            {
                _brightnessMod = SkyBox.BrightnessModifier;

                var diffuseColor = Color.White.ToVector3() * SkyBox.BrightnessModifier;
                ChunkManager.AmbientLightColor = diffuseColor;

                if (Math.Abs(ChunkManager.Shaders.BrightnessModifier - SkyBox.BrightnessModifier) > 0f)
                {
                    ChunkManager.Shaders.BrightnessModifier = SkyBox.BrightnessModifier;
                }

                var modelRenderer = Player?.ModelRenderer;

                if (modelRenderer != null)
                {
                    modelRenderer.DiffuseColor = diffuseColor;
                }
            }

            Player?.Update(args);
        }
예제 #9
0
파일: World.cs 프로젝트: PocketGold-MP/Alex
        public void Destroy()
        {
            if (_destroyed)
            {
                return;
            }
            _destroyed = true;

            EventDispatcher.UnregisterEvents(this);

            EntityManager.Dispose();
            ChunkManager.Dispose();

            Player.Dispose();
            Ticker.Dispose();
        }
예제 #10
0
        public void Destroy()
        {
            if (_destroyed)
            {
                return;
            }
            _destroyed = true;

            Ticker.UnregisterTicked(this);
            Ticker.UnregisterTicked(EntityManager);
            Ticker.UnregisterTicked(PhysicsEngine);
            Ticker.UnregisterTicked(ChunkManager);

            BackgroundWorker?.Dispose();

            EntityManager.Dispose();
            ChunkManager.Dispose();

            Player.Dispose();
            Ticker.Dispose();
        }
예제 #11
0
파일: World.cs 프로젝트: PocketGold-MP/Alex
        public void Render(IRenderArgs args)
        {
            Graphics.DepthStencilState = DepthStencilState.Default;
            Graphics.SamplerStates[0]  = SamplerState.PointWrap;

            SkyRenderer.Draw(args);

            ChunkManager.Draw(args,
                              RenderStage.OpaqueFullCube,
                              RenderStage.Opaque);

            EntityManager.Render(args);

            ChunkManager.Draw(args,
                              RenderStage.Transparent,
                              RenderStage.Translucent,
                              RenderStage.Animated,
                              //    RenderStage.AnimatedTranslucent,
                              RenderStage.Liquid);

            Player.Render(args);
        }
예제 #12
0
        public World(IServiceProvider serviceProvider, GraphicsDevice graphics, AlexOptions options, Camera camera,
                     INetworkProvider networkProvider)
        {
            Graphics = graphics;
            Camera   = camera;
            Options  = options;

            PhysicsEngine = new PhysicsManager(this);
            ChunkManager  = new ChunkManager(serviceProvider, graphics, this);
            EntityManager = new EntityManager(graphics, this, networkProvider);
            Ticker        = new TickManager();
            PlayerList    = new PlayerList();

            ChunkManager.Start();
            var settings       = serviceProvider.GetRequiredService <IOptionsProvider>();
            var profileService = serviceProvider.GetRequiredService <IPlayerProfileService>();
            var resources      = serviceProvider.GetRequiredService <ResourceManager>();

            EventDispatcher = serviceProvider.GetRequiredService <IEventDispatcher>();

            string username = string.Empty;
            Skin   skin     = profileService?.CurrentProfile?.Skin;

            if (skin == null)
            {
                resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture);
                var t = TextureUtils.BitmapToTexture2D(graphics, rawTexture);
                skin = new Skin()
                {
                    Texture = t,
                    Slim    = true
                };
            }

            if (!string.IsNullOrWhiteSpace(profileService?.CurrentProfile?.Username))
            {
                username = profileService.CurrentProfile.Username;
            }

            Player = new Player(graphics, serviceProvider.GetRequiredService <Alex>().InputManager, username, this, skin, networkProvider, PlayerIndex.One, camera);

            Player.KnownPosition = new PlayerLocation(GetSpawnPoint());
            Camera.MoveTo(Player.KnownPosition, Vector3.Zero);

            Options.FieldOfVision.ValueChanged += FieldOfVisionOnValueChanged;
            Camera.FOV = Options.FieldOfVision.Value;

            PhysicsEngine.AddTickable(Player);

            if (networkProvider is BedrockClient)
            {
                Player.SetInventory(new BedrockInventory(46));
            }
            //	Player.Inventory.IsPeInventory = true;

            /*if (ItemFactory.TryGetItem("minecraft:diamond_sword", out var sword))
             * {
             *      Player.Inventory[Player.Inventory.SelectedSlot] = sword;
             *      Player.Inventory.MainHand = sword;
             * }
             * else
             * {
             *      Log.Warn($"Could not get diamond sword!");
             * }*/

            EventDispatcher.RegisterEvents(this);

            FormManager = new BedrockFormManager(networkProvider, serviceProvider.GetRequiredService <GuiManager>(), serviceProvider.GetService <Alex>().InputManager);

            SkyRenderer = new SkyBox(serviceProvider, graphics, this);
            //SkyLightCalculations = new SkyLightCalculations();

            UseDepthMap = options.VideoOptions.Depthmap;
            options.VideoOptions.Depthmap.Bind((old, newValue) => { UseDepthMap = newValue; });

            ServerType = (networkProvider is BedrockClient) ? ServerType.Bedrock : ServerType.Java;
        }
예제 #13
0
파일: World.cs 프로젝트: PocketGold-MP/Alex
        public World(IServiceProvider serviceProvider, GraphicsDevice graphics, AlexOptions options,
                     NetworkProvider networkProvider)
        {
            Graphics = graphics;
            Options  = options;

            PhysicsEngine = new PhysicsManager(this);
            ChunkManager  = new ChunkManager(serviceProvider, graphics, this);
            EntityManager = new EntityManager(graphics, this, networkProvider);
            Ticker        = new TickManager();
            PlayerList    = new PlayerList();

            Ticker.RegisterTicked(this);
            Ticker.RegisterTicked(EntityManager);
            //Ticker.RegisterTicked(PhysicsEngine);
            Ticker.RegisterTicked(ChunkManager);

            ChunkManager.Start();
            var profileService = serviceProvider.GetRequiredService <IPlayerProfileService>();
            var resources      = serviceProvider.GetRequiredService <ResourceManager>();

            EventDispatcher = serviceProvider.GetRequiredService <IEventDispatcher>();

            string          username = string.Empty;
            PooledTexture2D texture;

            if (Alex.PlayerTexture != null)
            {
                texture = TextureUtils.BitmapToTexture2D(graphics, Alex.PlayerTexture);
            }
            else
            {
                resources.ResourcePack.TryGetBitmap("entity/alex", out var rawTexture);
                texture = TextureUtils.BitmapToTexture2D(graphics, rawTexture);
            }

            Skin skin = profileService?.CurrentProfile?.Skin;

            if (skin == null)
            {
                skin = new Skin()
                {
                    Texture = texture,
                    Slim    = true
                };
            }

            if (!string.IsNullOrWhiteSpace(profileService?.CurrentProfile?.Username))
            {
                username = profileService.CurrentProfile.Username;
            }

            Player = new Player(graphics, serviceProvider.GetRequiredService <Alex>().InputManager, username, this, skin, networkProvider, PlayerIndex.One);
            Camera = new EntityCamera(Player);

            if (Alex.PlayerModel != null)
            {
                EntityModelRenderer modelRenderer = new EntityModelRenderer(Alex.PlayerModel, texture);

                if (modelRenderer.Valid)
                {
                    Player.ModelRenderer = modelRenderer;
                }
            }

            Player.KnownPosition = new PlayerLocation(GetSpawnPoint());

            Options.FieldOfVision.ValueChanged += FieldOfVisionOnValueChanged;
            Camera.FOV = Options.FieldOfVision.Value;

            PhysicsEngine.AddTickable(Player);

            EventDispatcher.RegisterEvents(this);

            var guiManager = serviceProvider.GetRequiredService <GuiManager>();

            InventoryManager = new InventoryManager(guiManager);

            SkyRenderer = new SkyBox(serviceProvider, graphics, this);

            options.VideoOptions.RenderDistance.Bind(
                (old, newValue) =>
            {
                Camera.SetRenderDistance(newValue);
            });
            Camera.SetRenderDistance(options.VideoOptions.RenderDistance);
        }
예제 #14
0
 /// <inheritdoc />
 public override void PlayerOnGroundChanged(Player player, bool onGround)
 {
 }
예제 #15
0
 public abstract void PlayerOnGroundChanged(Player player, bool onGround);