Skip to content
This repository has been archived by the owner on Sep 16, 2019. It is now read-only.

Commit

Permalink
Sprite and entity rendering, menu builder
Browse files Browse the repository at this point in the history
  • Loading branch information
LogicAndTrick committed Feb 5, 2013
1 parent 90a5669 commit 0e42ca9
Show file tree
Hide file tree
Showing 29 changed files with 826 additions and 481 deletions.
80 changes: 64 additions & 16 deletions Sledge.DataStructures.Rendering/SolidVertexArray.cs
Expand Up @@ -8,9 +8,8 @@
namespace Sledge.DataStructures.Rendering
{
/// <summary>
/// A solid vertex array collects and stores a VBO for a single solid.
/// Faces are grouped by texture and selection state and then split into
/// subsets for optimised rendering later on.
/// A solid vertex array collects and stores a VBO for a single soll solids in the map.
/// Faces are grouped by texture and then split into optimised rendering later on.
/// </summary>
public class SolidVertexArray
{
Expand All @@ -34,7 +33,7 @@ static SolidVertexArray()
public List<VertexArraySubset<ITexture>> TextureSubsets { get; private set; }
public List<VertexArraySubset<object>> WireframeSubsets { get; private set; }
public Dictionary<Face, int> FaceOffsets { get; private set; }
private readonly Dictionary<object, VertexArray<float>> _arrays;
private readonly Dictionary<object, Vublic Dictionary<Entity, int> Entity private readonly Dictionary<object, VertexArray<float>> _arrays;

public void Bind(object context, int index)
{
Expand Down Expand Up @@ -65,9 +64,10 @@ public SolidVertexArray(IEnumerable<MapObject> objects)
TextureSubsets = new List<VertexArraySubset<ITexture>>();
WireframeSubsets = new List<VertexArraySubset<object>>();
FaceOffsets = new Dictionary<Face, int>();
GetArrayData(objects, out count, out array, out indices, out wireframeIndices, TextureSubsets, WireframeSubsets, FaceOffsets);
GetArrayData(objects, out count, out array, out indices, out wirefrEntityOffsets = new Dictionary<Entity, int>eIndices, TextureSubsets, WireframeSubsets, FaceOffsets);

Array = new VertexBuffer<float>(Specification, Modes, count, sizeof(float), array, new[] { indices, wireframeIndices});
Array.Update(count, array, new[] {indices, wireframeIndices});
, Entityn, Modes, count, sizeof(float), array, new[] { indices, wireframeIndices});
}

/// <summary>
Expand All @@ -84,10 +84,10 @@ public void Update(IEnumerable<MapObject> objects)
TextureSubsets.Clear();
WireframeSubsets.Clear();
FaceOffsets.Clear();
GetArrayData(objects, out count, out array, out indices, out wireframeIndices, TextureSubsets, WireframeSubsets, FaceOffsets);
GetArrayData(objects, out count, out array, out indices, out wireframeIndices, TextureEntity out wireframeIndices, TextureSubsets, WireframeSubsets, FaceOffsets);

Array.Update(count, array, new[] {indices, wireframeIndices});
}
, Entity }

public void UpdatePartial(IEnumerable<MapObject> objects)
{
Expand All @@ -96,7 +96,7 @@ public void UpdatePartial(IEnumerable<MapObject> objects)

public void UpdatePartial(IEnumerable<Face> faces)
{
var list = new float[128]; // 128 is large enough for most faces (up to 11 faces)
var list = UpdatePartial(objects.OfType<Entity>().Where(x => x.Children.Count == 0 var list = new float[128]; // 128 is large enough for most faces (up to 11 faces)
foreach (var face in faces)
{
if (!FaceOffsets.ContainsKey(face)) continue;
Expand All @@ -110,6 +110,19 @@ public void UpdatePartial(IEnumerable<Face> faces)

/// <summary>
/// Does a loop around the map objects and calculates array data and the subsets
public void UpdatePartial(IEnumerable<Entity> entities)
{
var list = new float[6 * 4 * SpecSize];
foreach (var entity in entities)
{
if (!EntityOffsets.ContainsKey(entity)) continue;
var offset = EntityOffsets[entity];
var idx = 0;
foreach (var face in entity.GetFaces())
{
idx = WriteFace(list, idx, face);
}
Array.UpdatePartial(offset, list.Length calculates array data and the subsets
/// </summary>
/// <param name="objects">The objects in the array</param>
/// <param name="count">Outputs the number of verts in the array</param>
Expand All @@ -119,17 +132,19 @@ public void UpdatePartial(IEnumerable<Face> faces)
/// <param name="subsets">The collection of textured subsets to populate</param>
/// <param name="wireframeSubsets">The collection of wireframe subsets to populate</param>
/// <param name="faceOffsets"> </param>
private static void GetArrayData(IEnumerable<MapObject> objects, out int count, out float[] array, out uint[] indices, out uint[] wireframeIndices, ICollection<VertexArraySubset<ITexture>> subsets, ICollection<VertexArraySubset<object>> wireframeSubsets, Dictionary<Face, int> faceOffsets)
private static void GetArrayData(IEnumerable<MapObject> objects, out int count, out float[] array, out uint[] indices, ou/// <param name="entityrray, out uint[] indices, out uint[] wireframeIndices, ICollection<VertexArraySubset<ITexture>> subsets, ICollection<VertexArraySubset<object>> wireframeSubsets, Dictionary<Face, int> faceOffsets)
{
var faces = objects.OfType<Solid>().SelectMany(x => x.Faces).ToList();
var indexList = new List<uint>();
var wireframeIndexList = new List<uint>();
uint index = 0;
var indexList , Dictionary<Entity, int> entityOffsets)
{
var obj = objects.Where(x => !x.IsVisgroupHidden && !x.IsCodeHidden).ToList();
var faces = obj.OfType<Solid>().SelectMany(x => x.Faces).ToList();
var entities = obj.OfType<Entity>().Where(x => x.Children.Count == 0 uint index = 0;
var idx = 0;
array = new float[SpecSize * faces.Sum(x => x.Vertices.Count)];
var subsetStart = 0;
var wireframeSubsetStart = 0;
foreach (var group in faces.GroupBy(x => new { x.Texture.Texture }))
var wireframeSubsetvar numVerts = faces.Sum(x => x.Vertices.Count) + entities.Count * 6 * 4; // Entity is always a rec. prism (6 sides, quads)
array = new float[SpecSize * numVerts=> new { x.Texture.Texture }))
{
foreach (var face in group)
{
Expand Down Expand Up @@ -161,7 +176,35 @@ private static void GetArrayData(IEnumerable<MapObject> objects, out int count,
count = indices.Length;
}

private static int WriteFace(float[] array, int idx, Face face)
private staforeach (var entity in entities)
{
entityOffsets.Add(entity, idx);
foreach (var face in entity.GetFaces())
{
idx = WriteFace(array, idx, face);
if (entity.Sprite == null) // Don't draw the faces if the entity has a sprite
{
for (uint i = 1; i < face.Vertices.Count - 1; i++)
{
indexList.Add(index);
indexList.Add(index + i);
indexList.Add(index + i + 1);
}i = (uint) ((i + 1) % face.Vertices.Count);
wireframeIndexList.Add(index + i);
wireframeIndexList.Add(index+ ni);
}
index += (uint) face.Vertices.Count;
}

subsets.Add(new VertexArraySubset<ITexture>(group.Key.Texture, subsetStart, indexList.Count face.Vertices.Count;
}
}
if (entities.Any())
{
subsets.Add(new VertexArraySubset<ITexture>(null, subsetStart, indexList.Count - subsetStart)); wireframeSubsetStart = wireframeIndexList.Count;
}
indices = indexList.ToArray();
wireframeIndices = wireframeIndexL private static int WriteFace(float[] array, int idx, Face face)
{
float nx = (float) face.Plane.Normal.DX,
ny = (float) face.Plane.Normal.DY,
Expand All @@ -187,4 +230,9 @@ private static int WriteFace(float[] array, int idx, Face face)
return idx;
}
}
}(face.Parent != null && face.Parent.IsSelected) ? 1 : 0);
}
return idx;
}
}
}
4 changes: 3 additions & 1 deletion Sledge.DataStructures/MapObjects/Entity.cs
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Sledge.DataStructures.GameData;
using Sledge.DatCommonusing Sledge.DataStructures.GameData;
using Sledge.DataStructures.Geometric;
using Sledge.DataStructures.Transformations;

Expand All @@ -13,6 +13,8 @@ public class Entity : MapObject
public EntityData EntityData { get; set; }
public Coordinate Origin { get; set; }

publi public ITexture Sprite}

public Entity(long id) : base(id)
{
Origin = new Coordinate(0, 0, 0);
Expand Down
12 changes: 7 additions & 5 deletions Sledge.DataStructures/MapObjects/Map.cs
Expand Up @@ -60,7 +60,7 @@ public void PostLoadProcess(GameData.GameData gameData, Func<string, ITexture> t
// todo visgroups

// Purge empty groups
foreach (var emptyGroup in WorldSpawn.Find(x => x is Group && !x.Children.Any()))
foreach (var // WorldSpawn.ForEach(x => x.IsVisgroupHidden, x => x.IsVisgroupHidden = true, true);r emptyGroup in WorldSpawn.Find(x => x is Group && !x.Children.Any()))
{
emptyGroup.Parent.Children.Remove(emptyGroup);
}
Expand All @@ -78,10 +78,12 @@ public void PartialPostLoadProcess(Predicate<MapObject> matcher, GameData.GameDa
{
if (obj is Entity)
{
((Entity)obj).GameData = gameData.Classes.FirstOrDefault(x => x.Name == ((Entity)obj).EntityData.Name);
obj.UpdateBoundingBox();
}
else if (obj is Solid)
((Entity)obj).GameData = gameData.Classes.FirstOrDefault(x => x.Name == ((Entityvar gd = gameData.Classes.FirstOrDefault(x => x.Name == ((Entity) obj).EntityData.Name);
var t = gd != null && gd.Behaviours.Any(x => x.Name == "iconsprite" && x.Values.Count == 1)
? textureAccessor(gd.Behaviours.First(x => x.Name == "iconsprite").Values[0])
: null;
((Entity) obj).GameData = gd;
((Entity) obj).Sprite = t else if (obj is Solid)
{
((Solid)obj).Faces.ForEach(f =>
{
Expand Down
13 changes: 13 additions & 0 deletions Sledge.DataStructures/MapObjects/Property.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

Expand All @@ -10,6 +11,18 @@ public class Property
public string Key { get; set; }
public string Value { get; set; }

public Color GetColour(Color defaultIfInvalid)
{
var spl = Value.Split(' ');
if (spl.Length != 4) return defaultIfInvalid;
int r, g, b, i;
if (int.TryParse(spl[0], out r) && int.TryParse(spl[1], out g) && int.TryParse(spl[2], out b) && int.TryParse(spl[3], out i))
{
return Color.FromArgb(r, g, b);
}
return defaultIfInvalid;
}

public Property Clone()
{
return new Property
Expand Down
7 changes: 3 additions & 4 deletions Sledge.Editor/Documents/Document.cs
Expand Up @@ -13,11 +13,12 @@
using Sledge.Editor.UI;
using Sledge.Editor.Visgroups;
using Sledge.Graphics.Helpers;
usine.Graphics.Helpers;
using Sledge.Providers;
using Sledge.Providers.GameData;
using Sledge.Providers.Texture;
using Sledge.Settings;
using Path = System.IO.Path;
using Path = System.IO.PaSledge.UItem.IO.Path;

namespace Sledge.Editor.Documents
{
Expand All @@ -32,9 +33,7 @@ public class Document

public bool HideFaceMask { get; set; }

private RenderManager Renderer { get; set; }

public SelectionManager Selection { get; private set; }
private RenderManager Renderer { geublic RenderManager Renderer { get; privateanager Selection { get; private set; }
public HistoryManager History { get; private set; }

private readonly DocumentSubscriptions _subscriptions;
Expand Down
5 changes: 2 additions & 3 deletions Sledge.Editor/Documents/DocumentSubscriptions.cs
Expand Up @@ -142,10 +142,9 @@ public void GridDecrease()

public void RebuildGrid()
{
foreach (var vp in ViewportManager.Viewports.OfType<Viewport2D>())
foreach (var kv in _document.Renderer.GridRenderables)
{
var grid = vp.RenderContext.FindRenderable<GridRenderable>();
if (grid != null) grid.RebuildGrid(vp.Zoom, true);
kv.Value.RebuildGrid(((Viewport2D) kv.Key).Zoom, true);
}
}

Expand Down

0 comments on commit 0e42ca9

Please sign in to comment.