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(); }
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); }
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); }
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); }
public void OnTick() { Player?.OnTick(); Time++; if (DoDaylightcycle) { var tod = TimeOfDay; TimeOfDay = ((tod + 1) % 24000); } }
/// <inheritdoc /> public override void PlayerOnGroundChanged(Player player, bool onGround) { if (Client.ConnectionState != ConnectionState.Play) { return; } Client.SendPacket(new PlayerMovementPacket() { OnGround = onGround }); }
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++; } } }
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); }
public void Destroy() { if (_destroyed) { return; } _destroyed = true; EventDispatcher.UnregisterEvents(this); EntityManager.Dispose(); ChunkManager.Dispose(); Player.Dispose(); Ticker.Dispose(); }
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(); }
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); }
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; }
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); }
/// <inheritdoc /> public override void PlayerOnGroundChanged(Player player, bool onGround) { }
public abstract void PlayerOnGroundChanged(Player player, bool onGround);