public ChunkModule(TrueCraftGame game) { Game = game; ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository); Game.Client.ChunkLoaded += Game_Client_ChunkLoaded; Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk); Game.Client.ChunkModified += Game_Client_ChunkModified; Game.Client.BlockChanged += Game_Client_BlockChanged; ChunkRenderer.MeshCompleted += MeshCompleted; ChunkRenderer.Start(); WorldLighting = new WorldLighting(Game.Client.World.World, Game.BlockRepository); OpaqueEffect = new BasicEffect(Game.GraphicsDevice); OpaqueEffect.TextureEnabled = true; OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); OpaqueEffect.FogEnabled = true; OpaqueEffect.FogStart = 0; OpaqueEffect.FogEnd = Game.Camera.Frustum.Far.D * 0.8f; OpaqueEffect.VertexColorEnabled = true; OpaqueEffect.LightingEnabled = true; TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice); TransparentEffect.AlphaFunction = CompareFunction.Greater; TransparentEffect.ReferenceAlpha = 127; TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); TransparentEffect.VertexColorEnabled = true; OpaqueEffect.LightingEnabled = true; ChunkMeshes = new List<ChunkMesh>(); IncomingChunks = new ConcurrentBag<Mesh>(); ActiveMeshes = new HashSet<Coordinates2D>(); }
public ChunkModule(TrueCraftGame game) { Game = game; ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository); Game.Client.ChunkLoaded += (sender, e) => ChunkRenderer.Enqueue(e.Chunk); Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk); Game.Client.ChunkModified += (sender, e) => ChunkRenderer.Enqueue(e.Chunk, true); ChunkRenderer.MeshCompleted += MeshCompleted; ChunkRenderer.Start(); OpaqueEffect = new BasicEffect(Game.GraphicsDevice); OpaqueEffect.TextureEnabled = true; OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); OpaqueEffect.FogEnabled = true; OpaqueEffect.FogStart = 512f; OpaqueEffect.FogEnd = 1000f; OpaqueEffect.FogColor = Color.CornflowerBlue.ToVector3(); OpaqueEffect.VertexColorEnabled = true; TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice); TransparentEffect.AlphaFunction = CompareFunction.Greater; TransparentEffect.ReferenceAlpha = 127; TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); TransparentEffect.VertexColorEnabled = true; ChunkMeshes = new List<ChunkMesh>(); IncomingChunks = new ConcurrentBag<Mesh>(); ActiveMeshes = new HashSet<Coordinates2D>(); }
public ChunkRenderer(ReadOnlyWorld world, TrueCraftGame game, IBlockRepository blockRepository) : base() { World = world; BlockRepository = blockRepository; Game = game; }
public ChunkModule(TrueCraftGame game) { Game = game; ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository); Game.Client.ChunkLoaded += Game_Client_ChunkLoaded; Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk); Game.Client.ChunkModified += Game_Client_ChunkModified; Game.Client.BlockChanged += Game_Client_BlockChanged; ChunkRenderer.MeshCompleted += MeshCompleted; ChunkRenderer.Start(); WorldLighting = new WorldLighting(Game.Client.World.World, Game.BlockRepository); OpaqueEffect = new BasicEffect(Game.GraphicsDevice); OpaqueEffect.TextureEnabled = true; OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); OpaqueEffect.FogEnabled = true; OpaqueEffect.FogStart = 0; OpaqueEffect.FogEnd = Game.Camera.Frustum.Far.D * 0.8f; OpaqueEffect.VertexColorEnabled = true; OpaqueEffect.LightingEnabled = true; TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice); TransparentEffect.AlphaFunction = CompareFunction.Greater; TransparentEffect.ReferenceAlpha = 127; TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); TransparentEffect.VertexColorEnabled = true; OpaqueEffect.LightingEnabled = true; ChunkMeshes = new List <ChunkMesh>(); IncomingChunks = new ConcurrentBag <Mesh>(); ActiveMeshes = new HashSet <Coordinates2D>(); }
/// <summary> /// /// </summary> /// <param name="chunk"></param> /// <param name="device"></param> /// <param name="vertices"></param> /// <param name="indices"></param> public ChunkMesh(ReadOnlyChunk chunk, TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int[] indices) : base(game, 1, true) { Chunk = chunk; Vertices = vertices; SetSubmesh(0, indices); }
public ChunkModule(TrueCraftGame game) { Game = game; ChunkRenderer = new ChunkRenderer(Game.Client.World, Game, Game.BlockRepository); Game.Client.ChunkLoaded += (sender, e) => ChunkRenderer.Enqueue(e.Chunk); Game.Client.ChunkUnloaded += (sender, e) => UnloadChunk(e.Chunk); Game.Client.ChunkModified += (sender, e) => ChunkRenderer.Enqueue(e.Chunk, true); ChunkRenderer.MeshCompleted += MeshCompleted; ChunkRenderer.Start(); OpaqueEffect = new BasicEffect(Game.GraphicsDevice); OpaqueEffect.TextureEnabled = true; OpaqueEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); OpaqueEffect.FogEnabled = true; OpaqueEffect.FogStart = 512f; OpaqueEffect.FogEnd = 1000f; OpaqueEffect.FogColor = Color.CornflowerBlue.ToVector3(); OpaqueEffect.VertexColorEnabled = true; TransparentEffect = new AlphaTestEffect(Game.GraphicsDevice); TransparentEffect.AlphaFunction = CompareFunction.Greater; TransparentEffect.ReferenceAlpha = 127; TransparentEffect.Texture = Game.TextureMapper.GetTexture("terrain.png"); TransparentEffect.VertexColorEnabled = true; ChunkMeshes = new List <ChunkMesh>(); IncomingChunks = new ConcurrentBag <Mesh>(); ActiveMeshes = new HashSet <Coordinates2D>(); }
/// <summary> /// /// </summary> /// <param name="chunk"></param> /// <param name="device"></param> /// <param name="vertices"></param> /// <param name="indices"></param> public ChunkMesh(ReadOnlyChunk chunk, TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int[] indices) : base(game, 1, true) { Chunk = chunk; Vertices = vertices; SetSubmesh(0, indices); }
/// <summary> /// /// </summary> /// <param name="chunk"></param> /// <param name="device"></param> /// <param name="vertices"></param> /// <param name="opaqueIndices"></param> /// <param name="transparentIndices"></param> public ChunkMesh(ReadOnlyChunk chunk, TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int[] opaqueIndices, int[] transparentIndices) : base(game, 2, true) { Chunk = chunk; Vertices = vertices; SetSubmesh(0, opaqueIndices); SetSubmesh(1, transparentIndices); }
/// <summary> /// /// </summary> /// <param name="chunk"></param> /// <param name="device"></param> /// <param name="vertices"></param> /// <param name="opaqueIndices"></param> /// <param name="transparentIndices"></param> public ChunkMesh(ReadOnlyChunk chunk, TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int[] opaqueIndices, int[] transparentIndices) : base(game, 2, true) { Chunk = chunk; Vertices = vertices; SetSubmesh(0, opaqueIndices); SetSubmesh(1, transparentIndices); }
public HUDModule(TrueCraftGame game, FontRenderer font) { Game = game; Font = font; SpriteBatch = new SpriteBatch(game.GraphicsDevice); GUI = game.TextureMapper.GetTexture("gui/gui.png"); Icons = game.TextureMapper.GetTexture("gui/icons.png"); Items = game.TextureMapper.GetTexture("gui/items.png"); }
public DebugInfoModule(TrueCraftGame game, FontRenderer font) { Game = game; Font = font; SpriteBatch = new SpriteBatch(Game.GraphicsDevice); #if DEBUG Enabled = true; #endif }
public DebugInfoModule(TrueCraftGame game, FontRenderer font) { Game = game; Font = font; SpriteBatch = new SpriteBatch(Game.GraphicsDevice); #if DEBUG Enabled = true; #endif }
public HUDModule(TrueCraftGame game, FontRenderer font) { Game = game; Font = font; SpriteBatch = new SpriteBatch(game.GraphicsDevice); GUI = game.TextureMapper.GetTexture("gui/gui.png"); Icons = game.TextureMapper.GetTexture("gui/icons.png"); Items = game.TextureMapper.GetTexture("gui/items.png"); }
private bool _recalculateBounds; // Whether this mesh should recalculate its bounding box when changed. #endregion Fields #region Constructors /// <summary> /// Creates a new mesh. /// </summary> /// <param name="graphicsDevice">The graphics device to store the mesh on.</param> /// <param name="submeshes">The number of submeshes in the mesh.</param> /// <param name="recalculateBounds">Whether the mesh should recalculate its bounding box when changed.</param> public Mesh(TrueCraftGame game, int submeshes = 1, bool recalculateBounds = true) { if ((submeshes < 0) || (submeshes >= Mesh.SubmeshLimit)) throw new ArgumentOutOfRangeException(); _game = game; _graphicsDevice = game.GraphicsDevice; _indices = new IndexBuffer[submeshes]; _recalculateBounds = recalculateBounds; }
public HighlightModule(TrueCraftGame game) { Game = game; HighlightEffect = new BasicEffect(Game.GraphicsDevice); HighlightEffect.VertexColorEnabled = true; DestructionEffect = new AlphaTestEffect(Game.GraphicsDevice); DestructionEffect.Texture = game.TextureMapper.GetTexture("terrain.png"); DestructionEffect.ReferenceAlpha = 1; GenerateProgressMesh(); }
public WindowModule(TrueCraftGame game, FontRenderer font) { Game = game; Font = font; SpriteBatch = new SpriteBatch(game.GraphicsDevice); Inventory = game.TextureMapper.GetTexture("gui/inventory.png"); Crafting = game.TextureMapper.GetTexture("gui/crafting.png"); Items = game.TextureMapper.GetTexture("gui/items.png"); SelectedSlot = -1; HeldItem = ItemStack.EmptyStack; }
public WindowModule(TrueCraftGame game, FontRenderer font) { Game = game; Font = font; SpriteBatch = new SpriteBatch(game.GraphicsDevice); Inventory = game.TextureMapper.GetTexture("gui/inventory.png"); Crafting = game.TextureMapper.GetTexture("gui/crafting.png"); Items = game.TextureMapper.GetTexture("gui/items.png"); SelectedSlot = -1; HeldItem = ItemStack.EmptyStack; }
public PlayerControlModule(TrueCraftGame game) { Game = game; Capture = true; Digging = false; Game.StartDigging = DateTime.MinValue; Game.EndDigging = DateTime.MaxValue; Game.TargetBlock = -Coordinates3D.One; NextAnimation = DateTime.MaxValue; GamePadState = GamePad.GetState(PlayerIndex.One); }
public PlayerControlModule(TrueCraftGame game) { Game = game; Capture = true; Digging = false; Game.StartDigging = DateTime.MinValue; Game.EndDigging = DateTime.MaxValue; Game.TargetBlock = -Coordinates3D.One; NextAnimation = DateTime.MaxValue; GamePadState = GamePad.GetState(PlayerIndex.One); }
public HighlightModule(TrueCraftGame game) { Game = game; HighlightEffect = new BasicEffect(Game.GraphicsDevice); HighlightEffect.VertexColorEnabled = true; DestructionEffect = new AlphaTestEffect(Game.GraphicsDevice); DestructionEffect.Texture = game.TextureMapper.GetTexture("terrain.png"); DestructionEffect.ReferenceAlpha = 1; GenerateProgressMesh(); }
/// <summary> /// Creates a new mesh. /// </summary> public Mesh(TrueCraftGame game, int submeshes = 1, bool recalculateBounds = true) { if ((submeshes < 0) || (submeshes >= Mesh.SubmeshLimit)) { throw new ArgumentOutOfRangeException(); } _game = game; _graphicsDevice = game.GraphicsDevice; _indices = new IndexBuffer[submeshes]; _recalculateBounds = recalculateBounds; }
public ChatModule(TrueCraftGame game, FontRenderer font) { Game = game; Font = font; Messages = new List <Message>(); Background = new Texture2D(Game.GraphicsDevice, 1, 1); Background.SetData <Color>(new[] { new Color(Color.Black, 160) }); SpriteBatch = new SpriteBatch(Game.GraphicsDevice); Watch = new Stopwatch(); Watch.Start(); Text = string.Empty; Game.Client.ChatMessage += (sender, e) => AddMessage(e.Message); }
public ChatModule(TrueCraftGame game, FontRenderer font) { Game = game; Font = font; Messages = new List<Message>(); Background = new Texture2D(Game.GraphicsDevice, 1, 1); Background.SetData<Color>(new[] { new Color(Color.Black, 160) }); SpriteBatch = new SpriteBatch(Game.GraphicsDevice); Watch = new Stopwatch(); Watch.Start(); Text = string.Empty; Game.Client.ChatMessage += (sender, e) => AddMessage(e.Message); }
public static void PrepareEffects(TrueCraftGame game) { RenderEffect = new BasicEffect(game.GraphicsDevice); RenderEffect.Texture = game.TextureMapper.GetTexture("terrain.png"); RenderEffect.TextureEnabled = true; RenderEffect.VertexColorEnabled = true; RenderEffect.LightingEnabled = true; RenderEffect.DirectionalLight0.Direction = new Vector3(10, -10, -0.8f); RenderEffect.DirectionalLight0.DiffuseColor = Color.White.ToVector3(); RenderEffect.DirectionalLight0.Enabled = true; RenderEffect.Projection = Matrix.CreateOrthographicOffCenter( 0, game.GraphicsDevice.Viewport.Width, 0, game.GraphicsDevice.Viewport.Height, 0.1f, 1000.0f); RenderEffect.View = Matrix.CreateLookAt(Vector3.UnitZ, Vector3.Zero, Vector3.Up); }
public static void RenderBlockIcon(TrueCraftGame game, IBlockProvider provider, byte metadata, Rectangle destination) { var mesh = BlockMeshes[provider.ID]; if (mesh != null) { RenderEffect.World = Matrix.Identity * Matrix.CreateScale(0.6f) * Matrix.CreateRotationY(-MathHelper.PiOver4) * Matrix.CreateRotationX(MathHelper.ToRadians(30)) * Matrix.CreateScale(new Vector3(destination.Width, destination.Height, 1)) * Matrix.CreateTranslation(new Vector3( destination.X, -(destination.Y - game.GraphicsDevice.Viewport.Height / 2) + game.GraphicsDevice.Viewport.Height / 2, 0)) * Matrix.CreateTranslation(new Vector3(destination.Width / 2, -destination.Height / 2, 0)); mesh.Draw(RenderEffect); } }
public static void PrepareEffects(TrueCraftGame game) { RenderEffect = new BasicEffect(game.GraphicsDevice); RenderEffect.Texture = game.TextureMapper.GetTexture("terrain.png"); RenderEffect.TextureEnabled = true; RenderEffect.VertexColorEnabled = true; RenderEffect.LightingEnabled = true; RenderEffect.DirectionalLight0.Direction = new Vector3(10, -10, -0.8f); RenderEffect.DirectionalLight0.DiffuseColor = Color.White.ToVector3(); RenderEffect.DirectionalLight0.Enabled = true; RenderEffect.Projection = Microsoft.Xna.Framework.Matrix.CreateOrthographicOffCenter( 0, game.GraphicsDevice.Viewport.Width, 0, game.GraphicsDevice.Viewport.Height, 0.1f, 1000.0f); RenderEffect.View = Microsoft.Xna.Framework.Matrix.CreateLookAt(Vector3.UnitZ, Vector3.Zero, Vector3.Up); }
public static void RenderBlockIcon(TrueCraftGame game, IBlockProvider provider, byte metadata, Rectangle destination) { var mesh = BlockMeshes[provider.ID]; if (mesh != null) { RenderEffect.World = Matrix.Identity * Matrix.CreateScale(0.6f) * Matrix.CreateRotationY(-MathHelper.PiOver4) * Matrix.CreateRotationX(MathHelper.ToRadians(30)) * Matrix.CreateScale(new Vector3(destination.Width, destination.Height, 1)) * Matrix.CreateTranslation(new Vector3( destination.X, -(destination.Y - game.GraphicsDevice.Viewport.Height / 2) + game.GraphicsDevice.Viewport.Height / 2, 0)) * Matrix.CreateTranslation(new Vector3(destination.Width / 2, -destination.Height / 2, 0)); mesh.Draw(RenderEffect); } }
public static void CreateBlocks(TrueCraftGame game, IBlockRepository repository) { for (int i = 0; i < 0x100; i++) { var provider = repository.GetBlockProvider((byte)i); if (provider == null || provider.GetIconTexture(0) != null) continue; int[] indicies; var verticies = BlockRenderer.RenderBlock(provider, new BlockDescriptor { ID = provider.ID }, VisibleFaces.All, new Vector3(-0.5f), 0, out indicies); var mesh = new Mesh(game, verticies, indicies); BlockMeshes[provider.ID] = mesh; } PrepareEffects(game); }
public SkyModule(TrueCraftGame game) { Game = game; CelestialPlaneEffect = new BasicEffect(Game.GraphicsDevice); CelestialPlaneEffect.TextureEnabled = true; SkyPlaneEffect = new BasicEffect(Game.GraphicsDevice); SkyPlaneEffect.VertexColorEnabled = false; SkyPlaneEffect.FogEnabled = true; SkyPlaneEffect.FogStart = 0; SkyPlaneEffect.FogEnd = 64 * 0.8f; SkyPlaneEffect.LightingEnabled = true; var plane = new[] { new VertexPositionColor(new Vector3(-64, 0, -64), Color.White), new VertexPositionColor(new Vector3(64, 0, -64), Color.White), new VertexPositionColor(new Vector3(-64, 0, 64), Color.White), new VertexPositionColor(new Vector3(64, 0, -64), Color.White), new VertexPositionColor(new Vector3(64, 0, 64), Color.White), new VertexPositionColor(new Vector3(-64, 0, 64), Color.White) }; SkyPlane = new VertexBuffer(Game.GraphicsDevice, VertexPositionColor.VertexDeclaration, plane.Length, BufferUsage.WriteOnly); SkyPlane.SetData <VertexPositionColor>(plane); var celestialPlane = new[] { new VertexPositionTexture(new Vector3(-60, 0, -60), new Vector2(0, 0)), new VertexPositionTexture(new Vector3(60, 0, -60), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(-60, 0, 60), new Vector2(0, 1)), new VertexPositionTexture(new Vector3(60, 0, -60), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(60, 0, 60), new Vector2(1, 1)), new VertexPositionTexture(new Vector3(-60, 0, 60), new Vector2(0, 1)) }; CelestialPlane = new VertexBuffer(Game.GraphicsDevice, VertexPositionTexture.VertexDeclaration, celestialPlane.Length, BufferUsage.WriteOnly); CelestialPlane.SetData <VertexPositionTexture>(celestialPlane); }
public static void CreateBlocks(TrueCraftGame game, IBlockRepository repository) { for (var i = 0; i < 0x100; i++) { var provider = repository.GetBlockProvider((byte)i); if (provider == null || provider.GetIconTexture(0) != null) { continue; } int[] indicies; var verticies = BlockRenderer.RenderBlock(provider, new BlockDescriptor { Id = provider.Id }, VisibleFaces.All, new Vector3(-0.5f), 0, out indicies); var mesh = new Mesh(game, verticies, indicies); BlockMeshes[provider.Id] = mesh; } PrepareEffects(game); }
public SkyModule(TrueCraftGame game) { Game = game; CelestialPlaneEffect = new BasicEffect(Game.GraphicsDevice); CelestialPlaneEffect.TextureEnabled = true; SkyPlaneEffect = new BasicEffect(Game.GraphicsDevice); SkyPlaneEffect.VertexColorEnabled = false; SkyPlaneEffect.FogEnabled = true; SkyPlaneEffect.FogStart = 0; SkyPlaneEffect.FogEnd = 64 * 0.8f; SkyPlaneEffect.LightingEnabled = true; var plane = new[] { new VertexPositionColor(new Vector3(-64, 0, -64), Color.White), new VertexPositionColor(new Vector3(64, 0, -64), Color.White), new VertexPositionColor(new Vector3(-64, 0, 64), Color.White), new VertexPositionColor(new Vector3(64, 0, -64), Color.White), new VertexPositionColor(new Vector3(64, 0, 64), Color.White), new VertexPositionColor(new Vector3(-64, 0, 64), Color.White) }; SkyPlane = new VertexBuffer(Game.GraphicsDevice, VertexPositionColor.VertexDeclaration, plane.Length, BufferUsage.WriteOnly); SkyPlane.SetData<VertexPositionColor>(plane); var celestialPlane = new[] { new VertexPositionTexture(new Vector3(-60, 0, -60), new Vector2(0, 0)), new VertexPositionTexture(new Vector3(60, 0, -60), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(-60, 0, 60), new Vector2(0, 1)), new VertexPositionTexture(new Vector3(60, 0, -60), new Vector2(1, 0)), new VertexPositionTexture(new Vector3(60, 0, 60), new Vector2(1, 1)), new VertexPositionTexture(new Vector3(-60, 0, 60), new Vector2(0, 1)) }; CelestialPlane = new VertexBuffer(Game.GraphicsDevice, VertexPositionTexture.VertexDeclaration, celestialPlane.Length, BufferUsage.WriteOnly); CelestialPlane.SetData<VertexPositionTexture>(celestialPlane); }
/// <summary> /// Creates a new mesh. /// </summary> public Mesh(TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int submeshes = 1, bool recalculateBounds = true) : this(game, submeshes, recalculateBounds) { Vertices = vertices; }
/// <summary> /// Creates a new mesh. /// </summary> public Mesh(TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int[] indices, bool recalculateBounds = true) : this(game, 1, recalculateBounds) { Vertices = vertices; SetSubmesh(0, indices); }
/// <summary> /// Creates a new mesh. /// </summary> public Mesh(TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int[] indices, bool recalculateBounds = true) : this(game, 1, recalculateBounds) { Vertices = vertices; SetSubmesh(0, indices); }
/// <summary> /// Creates a new mesh. /// </summary> public Mesh(TrueCraftGame game, VertexPositionNormalColorTexture[] vertices, int submeshes = 1, bool recalculateBounds = true) : this(game, submeshes, recalculateBounds) { Vertices = vertices; }
public ChunkRenderer(TrueCraftGame game, IBlockRepository blockRepository) : base() { BlockRepository = blockRepository; Game = game; }