Skip to content

Commit

Permalink
Building out new voxel geometry generation
Browse files Browse the repository at this point in the history
  • Loading branch information
Blecki committed Mar 10, 2020
1 parent 5fee4bc commit e2e52e5
Show file tree
Hide file tree
Showing 21 changed files with 8,053 additions and 7,518 deletions.
2 changes: 2 additions & 0 deletions DwarfCorp/DCMono.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,9 @@
<Compile Include="World\Rail\RailHelper.cs" />
<Compile Include="World\Rail\RailPiece.cs" />
<Compile Include="World\UpdateSystemFactoryAttribute.cs" />
<Compile Include="World\Voxels\AlternativeVoxelPrimitive.cs" />
<Compile Include="World\Voxels\BoxTransition.cs" />
<Compile Include="World\Voxels\ChunkBuilder\Face.cs" />
<Compile Include="World\Voxels\ChunkManager-Data.cs" />
<Compile Include="World\Voxels\ChunkManager.cs" />
<Compile Include="World\Voxels\ChunkRenderer.cs" />
Expand Down
1 change: 1 addition & 0 deletions DwarfCorp/Debugger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static class Switches
public static bool DrawInvisible = false;
public static bool ShowEntityInfo = false;
public static bool DrawTiledInstanceAtlas = false;
public static bool UseNewVoxelGeoGen = false;
}

public class Switch
Expand Down
1 change: 1 addition & 0 deletions DwarfCorp/DwarfCorpFNA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,7 @@
<Compile Include="Player\BodySelector.cs" />
<Compile Include="Player\BoxBrush.cs" />
<Compile Include="World\LanguageGenerator\Verb.cs" />
<Compile Include="World\Voxels\AlternativeVoxelPrimitive.cs" />
<Compile Include="World\Voxels\DecalLibrary.cs" />
<Compile Include="World\Voxels\DecalType.cs" />
<Compile Include="World\Voxels\VoxelListPrimitive-CalculateVertexLight.cs" />
Expand Down
8 changes: 8 additions & 0 deletions DwarfCorp/DwarfCorpXNA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,14 @@
<Compile Include="World\Overworld\OverworldGenerator.cs" />
<Compile Include="World\Potions\GatherPotionsTask.cs" />
<Compile Include="World\Potions\Potion.cs" />
<Compile Include="World\Voxels\ChunkBuilder\GeometryBuilder.cs" />
<Compile Include="World\Voxels\ChunkBuilder\VoxelPrimitive.cs" />
<Compile Include="World\Voxels\ChunkBuilder\FaceOrientation.cs" />
<Compile Include="World\Voxels\ChunkBuilder\Face.cs" />
<Compile Include="World\Voxels\ChunkBuilder\Geo\CreateQuad.cs" />
<Compile Include="World\Voxels\ChunkBuilder\Geo\Mesh.cs" />
<Compile Include="World\Voxels\ChunkBuilder\Geo\MeshPart.cs" />
<Compile Include="World\Voxels\ChunkBuilder\Geo\PartBasics.cs" />
<Compile Include="World\Voxels\ChunkManager-Data.cs" />
<Compile Include="Entities\Plants\Pumpkin.cs" />
<Compile Include="Entities\Plants\Cactus.cs" />
Expand Down
41 changes: 25 additions & 16 deletions DwarfCorp/GameStates/Play/CategoryMenuBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ public static SubCategoryMenuCreationResult CreateCategorySubMenu(
};
}

/// <summary>
///
/// </summary>
/// <param name="Crafts">The source of items to list.</param>
/// <param name="Filter">Filter determines which items to include.</param>
/// <param name="IconFactory"></param>
/// <param name="OnReturnClicked"></param>
/// <returns></returns>
public static CategoryMenuCreationResult CreateCategoryMenu(
IEnumerable<CraftableRecord> Crafts,
Func<CraftableRecord, bool> Filter,
Expand Down Expand Up @@ -119,31 +127,32 @@ public static CategoryMenuCreationResult CreateCategoryMenu(

menu.OnRefresh = (sender) =>
{
Dictionary<string, bool> placeCategoryExists = new Dictionary<string, bool>();
var placeRootObjects = new List<FlatToolTray.Icon>();
var categoryExists = new Dictionary<string, bool>();
var rootObjects = new List<FlatToolTray.Icon>();

foreach (var item in icons.Where(data => Filter(data.Tag as CraftableRecord)))
if (item.Tag is CraftableRecord craft)
if (string.IsNullOrEmpty(craft.GetCategory) || !placeCategoryExists.ContainsKey(craft.GetCategory))
if (string.IsNullOrEmpty(craft.GetCategory) || !categoryExists.ContainsKey(craft.GetCategory))
{
placeRootObjects.Add(item);
rootObjects.Add(item);
if (!string.IsNullOrEmpty(craft.GetCategory))
placeCategoryExists[craft.GetCategory] = true;
categoryExists[craft.GetCategory] = true;
}

(sender as IconTray).ItemSource = (new Widget[] { returnIcon }).Concat(placeRootObjects.Select(data =>
(sender as IconTray).ItemSource = (new Widget[] { returnIcon }).Concat(rootObjects.Select(data =>
{
if (data.Tag is CraftableRecord craft)
{
if (data.Tag is CraftableRecord craft)
{
if (string.IsNullOrEmpty(craft.GetCategory))
return data;
if (string.IsNullOrEmpty(craft.GetCategory) || Crafts.Count(c => c.GetCategory == craft.GetCategory) == 1)
return data;

var r = CreateCategorySubMenu(Crafts, Filter, craft.GetCategory, IconFactory, OnReturnClicked);
r.ReturnIcon.ReplacementMenu = menu;
return r.MenuIcon;
}
throw new InvalidOperationException();
}));
var r = CreateCategorySubMenu(Crafts, Filter, craft.GetCategory, IconFactory, OnReturnClicked);
r.ReturnIcon.ReplacementMenu = menu;

return r.MenuIcon;
}
throw new InvalidOperationException();
}));

(sender as IconTray).ResetItemsFromSource();
};
Expand Down
3 changes: 2 additions & 1 deletion DwarfCorp/GameStates/Play/PlayState-GUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public partial class PlayState : GameState
private Dictionary<uint, WorldPopup> LastWorldPopup = new Dictionary<uint, WorldPopup>();
private List<Widget> TogglePanels = new List<Widget>();



public Gui.MousePointer MousePointer = new Gui.MousePointer("mouse", 1, 0);

public void ShowTooltip(String Text)
Expand Down Expand Up @@ -1229,7 +1231,6 @@ public void CreateGUIComponents()
World.TaskManager.AddTask(new CraftResourceTask((data as CraftItem), 1, 1, buildInfo.GetSelectedResources()));

ShowToolPopup((data as CraftItem).Verb.PresentTense + " " + numRepeats.ToString() + " " + (numRepeats == 1 ? data.DisplayName : (data as CraftItem).PluralDisplayName));

}
}
},
Expand Down
4 changes: 4 additions & 0 deletions DwarfCorp/GameStates/Play/PlayState-Input.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,10 @@ public override void Update(DwarfTime gameTime)

#endregion

// Close the bottom menu if the only icon is the return icon.
if (BottomToolBar.Children.First(w => w.Hidden == false).Children.Count(c => c.Hidden == false) == 1)
(BottomToolBar.Children.First(w => w.Hidden == false) as FlatToolTray.Tray).Hotkey(FlatToolTray.Tray.Hotkeys[0]);

#region Handle slice hotkeys being held down

if (sliceDownheld)
Expand Down
93 changes: 10 additions & 83 deletions DwarfCorp/Graphics/Primitives/ExtendedVertex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,22 @@

namespace Microsoft.Xna.Framework.Graphics
{

// Summary:
// Describes a custom vertex format structure that contains position, color,
// and one set of texture coordinates.
[Serializable]
public struct ExtendedVertex : IVertexType
{
//
// Summary:
// XYZ position.
[SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")] public Vector3 Position;
//
// Summary:
// UV texture coordinates.
[SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")] public Vector2 TextureCoordinate;

// Summary:
// The vertex color.
[SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")] public Color Color;
[SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")] public Color VertColor;
[SuppressMessage("Microsoft.Design", "CA1051:DoNotDeclareVisibleInstanceFields")] public Vector4 TextureBounds;
public Vector3 Position;
public Vector2 TextureCoordinate;
public Color Color;
public Color VertColor;
public Vector4 TextureBounds;

//
// Summary:
// Vertex declaration, which defines per-vertex data.
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")] public static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration
(
//Position
public static readonly VertexDeclaration VertexDeclaration = new VertexDeclaration(
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
// Texture Coordinate
new VertexElement(SizeOf(Vector3.Zero), VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0),
// Color
new VertexElement(SizeOf(Vector3.Zero) + SizeOf(Vector2.Zero), VertexElementFormat.Color, VertexElementUsage.Color, 0),
// Vertex tint
new VertexElement(SizeOf(Vector3.Zero) + SizeOf(Vector2.Zero) + SizeOf(Color.White), VertexElementFormat.Color, VertexElementUsage.Color, 1),
// Texture bounds
new VertexElement(SizeOf(Vector3.Zero) + SizeOf(Vector2.Zero) + SizeOf(Color.White) * 2, VertexElementFormat.Vector4, VertexElementUsage.TextureCoordinate, 1)
);


new VertexElement(SizeOf(Vector3.Zero) + SizeOf(Vector2.Zero) + SizeOf(Color.White) * 2, VertexElementFormat.Vector4, VertexElementUsage.TextureCoordinate, 1));

public static int SizeOf<T>(T obj)
{
return System.Runtime.InteropServices.Marshal.SizeOf(obj);
Expand All @@ -54,19 +30,6 @@ VertexDeclaration IVertexType.VertexDeclaration
get { return VertexDeclaration; }
}

//
// Summary:
// Initializes a new instance of the VertexPositionColorTexture class.
//
// Parameters:
// position:
// Position of the vertex.
//
// color:
// Color of the vertex.
//
// textureCoordinate:
// Texture coordinate of the vertex.
public ExtendedVertex(Vector3 position, Color color, Color vertColor, Vector2 textureCoordinate, Vector4 textureBounds)
{
Position = position;
Expand All @@ -76,68 +39,33 @@ public ExtendedVertex(Vector3 position, Color color, Color vertColor, Vector2 te
TextureBounds = textureBounds;
}

// Summary:
// Compares two objects to determine whether they are different.
//
// Parameters:
// left:
// Object to the left of the inequality operator.
//
// right:
// Object to the right of the inequality operator.
public static bool operator !=(ExtendedVertex left, ExtendedVertex right)
{
return !(left.Color == right.Color && left.Position == right.Position
return !(left.Color == right.Color
&& left.Position == right.Position
&& left.TextureBounds == right.TextureBounds
&& left.TextureCoordinate == right.TextureCoordinate
&& left.VertColor == right.VertColor);
}

//
// Summary:
// Compares two objects to determine whether they are the same.
//
// Parameters:
// left:
// Object to the left of the equality operator.
//
// right:
// Object to the right of the equality operator.
public static bool operator ==(ExtendedVertex left, ExtendedVertex right)
{
return !(left != right);
}

// Summary:
// Returns a value that indicates whether the current instance is equal to a
// specified object.
//
// Parameters:
// obj:
// The Object to compare with the current VertexPositionColorTexture.
public override bool Equals(object obj)
{
if(obj is ExtendedVertex)
{
return this == (ExtendedVertex) obj;
}
else
{
return false;
}
}

//
// Summary:
// Gets the hash code for this instance.
public override int GetHashCode()
{
return Position.GetHashCode();
}

//
// Summary:
// Retrieves a string representation of this object.
public override string ToString()
{
return "Extended Vertex: " + Position.ToString();
Expand All @@ -157,7 +85,6 @@ public void Set(Vector3 position,
}
}


[Serializable]
public struct ThickLineVertex : IVertexType
{
Expand Down
4 changes: 0 additions & 4 deletions DwarfCorp/Graphics/Primitives/GeometricPrimitive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@

namespace DwarfCorp
{
/// <summary>
/// Simple class representing a geometric object with verticies, textures, and whatever else.
/// </summary>
[JsonObject(IsReference = true)]
public class GeometricPrimitive : IDisposable
{
public int IndexCount = 0;
Expand Down
3 changes: 1 addition & 2 deletions DwarfCorp/Gui/Root.cs
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,8 @@ private void CallOnMouseUp(Widget Widget, InputEventArgs Args)
private void CallOnClick(Widget Widget, InputEventArgs Args)
{
if (FocusItem != null && Widget != FocusItem)
{
SetFocus(null);
}

SafeCall(Widget.OnClick, Widget, Args);
var parent = Widget.Parent;
while (parent != null)
Expand Down
17 changes: 17 additions & 0 deletions DwarfCorp/World/Voxels/ChunkBuilder/Face.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DwarfCorp.GameStates;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;

namespace DwarfCorp.Voxels
{
public class Face
{
public Geo.Mesh Mesh;
public FaceOrientation Orientation;
}
}
21 changes: 21 additions & 0 deletions DwarfCorp/World/Voxels/ChunkBuilder/FaceOrientation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DwarfCorp.GameStates;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Newtonsoft.Json;

namespace DwarfCorp.Voxels
{
public enum FaceOrientation
{
Top,
Bottom,
North,
East,
South,
West
}
}
Loading

0 comments on commit e2e52e5

Please sign in to comment.