public OptionsProvider(IStorageSystem storage) { _storage = storage; AlexOptions = new AlexOptions(); Load(); }
public void Load() { if (_storage.TryRead(StorageKey, out AlexOptions options)) { AlexOptions = options; } }
public World(Alex alex, GraphicsDevice graphics, AlexOptions options, Camera camera, INetworkProvider networkProvider) { Alex = alex; Graphics = graphics; Camera = camera; Options = options; PhysicsEngine = new PhysicsManager(alex, this); ChunkManager = new ChunkManager(alex, graphics, options, this); EntityManager = new EntityManager(graphics, this, networkProvider); Ticker = new TickManager(this); PlayerList = new PlayerList(); ChunkManager.Start(); var profileService = alex.Services.GetService <IPlayerProfileService>(); string username = string.Empty; Skin skin = profileService?.CurrentProfile?.Skin; if (skin == null) { alex.Resources.ResourcePack.TryGetBitmap("entity/alex", out Bitmap 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, alex, username, this, skin, networkProvider, PlayerIndex.One); Player.KnownPosition = new PlayerLocation(GetSpawnPoint()); Camera.MoveTo(Player.KnownPosition, Vector3.Zero); Options.FieldOfVision.ValueChanged += FieldOfVisionOnValueChanged; Camera.FOV = Options.FieldOfVision.Value; PhysicsEngine.AddTickable(Player); 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!"); } }
public ChunkManager(Alex alex, GraphicsDevice graphics, AlexOptions option, IWorld world) { Game = alex; Graphics = graphics; World = world; Options = option; ProfilerService = alex.Services.GetService <ProfilerService>(); Chunks = new ConcurrentDictionary <ChunkCoordinates, IChunkColumn>(); var fogStart = 0; TransparentEffect = new AlphaTestEffect(Graphics) { Texture = alex.Resources.Atlas.GetStillAtlas(), VertexColorEnabled = true, World = Matrix.Identity, AlphaFunction = CompareFunction.Greater, ReferenceAlpha = 127, FogStart = fogStart, FogEnabled = false }; AnimatedEffect = new AlphaTestEffect(Graphics) { Texture = alex.Resources.Atlas.GetAtlas(0), VertexColorEnabled = true, World = Matrix.Identity, AlphaFunction = CompareFunction.Greater, ReferenceAlpha = 127, FogStart = fogStart, FogEnabled = false }; OpaqueEffect = new BasicEffect(Graphics) { TextureEnabled = true, Texture = alex.Resources.Atlas.GetStillAtlas(), FogStart = fogStart, VertexColorEnabled = true, LightingEnabled = true, FogEnabled = false }; //if (alex.) FrameCount = alex.Resources.Atlas.GetFrameCount(); ChunkManagementThread = new Thread(ChunkUpdateThread) { IsBackground = true, Name = "Chunk Management" }; HighestPriority = new ConcurrentQueue <ChunkCoordinates>(); }
public void Load() { if (_storage.TryRead(StorageKey, out AlexOptions options)) { AlexOptions = options; } else { Log.Warn($"Could not read from storage."); } }
public void Load() { if (_optionsLoaded) { return; } if (_storage.TryReadJson(StorageKey, out AlexOptions options)) { AlexOptions = options; } else { Log.Warn($"Could not read from storage."); } _optionsLoaded = true; }
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); }