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

Commit

Permalink
No idea how these files got corrupt, fixing them.
Browse files Browse the repository at this point in the history
  • Loading branch information
LogicAndTrick committed Feb 5, 2013
1 parent 0e42ca9 commit c84d874
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 253 deletions.
86 changes: 45 additions & 41 deletions Sledge.DataStructures.Rendering/SolidVertexArray.cs
Expand Up @@ -8,8 +8,8 @@
namespace Sledge.DataStructures.Rendering
{
/// <summary>
/// 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.
/// A solid vertex array collects and stores a VBO for all solids in the map.
/// Faces are grouped by texture and then split into subsets for optimised rendering later on.
/// </summary>
public class SolidVertexArray
{
Expand All @@ -33,7 +33,8 @@ 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, Vublic Dictionary<Entity, int> Entity private readonly Dictionary<object, VertexArray<float>> _arrays;
public Dictionary<Entity, int> EntityOffsets { get; private set; }
private readonly Dictionary<object, VertexArray<float>> _arrays;

public void Bind(object context, int index)
{
Expand Down Expand Up @@ -64,10 +65,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 wirefrEntityOffsets = new Dictionary<Entity, int>eIndices, TextureSubsets, WireframeSubsets, FaceOffsets);
EntityOffsets = new Dictionary<Entity, int>();
GetArrayData(objects, out count, out array, out indices, out wireframeIndices, TextureSubsets, WireframeSubsets, FaceOffsets, EntityOffsets);

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

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

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

public void UpdatePartial(IEnumerable<MapObject> objects)
{
UpdatePartial(objects.OfType<Solid>().SelectMany(x => x.Faces));
UpdatePartial(objects.OfType<Entity>().Where(x => x.Children.Count == 0));
}

public void UpdatePartial(IEnumerable<Face> 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)
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 @@ -108,9 +111,7 @@ 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)
public void UpdatePartial(IEnumerable<Entity> entities)
{
var list = new float[6 * 4 * SpecSize];
foreach (var entity in entities)
Expand All @@ -122,7 +123,12 @@ public void UpdatePartial(IEnumerable<Entity> entities)
{
idx = WriteFace(list, idx, face);
}
Array.UpdatePartial(offset, list.Length calculates array data and the subsets
Array.UpdatePartial(offset, list.Length, list);
}
}

/// <summary>
/// Does a loop around the map objects and 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 @@ -132,19 +138,21 @@ public void UpdatePartial(IEnumerable<Entity> entities)
/// <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, 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 , Dictionary<Entity, int> entityOffsets)
/// <param name="entityOffsets"> </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, 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 entities = obj.OfType<Entity>().Where(x => x.Children.Count == 0).ToList();
var indexList = new List<uint>();
var wireframeIndexList = new List<uint>();
uint index = 0;
var idx = 0;
array = new float[SpecSize * faces.Sum(x => x.Vertices.Count)];
var 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];
var subsetStart = 0;
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 }))
var wireframeSubsetStart = 0;
foreach (var group in faces.GroupBy(x => new { x.Texture.Texture }))
{
foreach (var face in group)
{
Expand All @@ -171,12 +179,7 @@ private static void GetArrayData(IEnumerable<MapObject> objects, out int count,
wireframeSubsets.Add(new VertexArraySubset<object>(null, wireframeSubsetStart, wireframeIndexList.Count - wireframeSubsetStart));
wireframeSubsetStart = wireframeIndexList.Count;
}
indices = indexList.ToArray();
wireframeIndices = wireframeIndexList.ToArray();
count = indices.Length;
}

private staforeach (var entity in entities)
foreach (var entity in entities)
{
entityOffsets.Add(entity, idx);
foreach (var face in entity.GetFaces())
Expand All @@ -189,22 +192,28 @@ private staforeach (var entity in entities)
indexList.Add(index);
indexList.Add(index + i);
indexList.Add(index + i + 1);
}i = (uint) ((i + 1) % face.Vertices.Count);
}
}
for (uint i = 0; i < face.Vertices.Count; i++)
{
var ni = (uint)((i + 1) % face.Vertices.Count);
wireframeIndexList.Add(index + i);
wireframeIndexList.Add(index+ ni);
wireframeIndexList.Add(index + ni);
}
index += (uint) face.Vertices.Count;
}

subsets.Add(new VertexArraySubset<ITexture>(group.Key.Texture, subsetStart, indexList.Count face.Vertices.Count;
index += (uint)face.Vertices.Count;
}
}
if (entities.Any())
{
subsets.Add(new VertexArraySubset<ITexture>(null, subsetStart, indexList.Count - subsetStart)); wireframeSubsetStart = wireframeIndexList.Count;
subsets.Add(new VertexArraySubset<ITexture>(null, subsetStart, indexList.Count - subsetStart));
wireframeSubsets.Add(new VertexArraySubset<object>(null, wireframeSubsetStart, wireframeIndexList.Count - wireframeSubsetStart));
}
indices = indexList.ToArray();
wireframeIndices = wireframeIndexL private static int WriteFace(float[] array, int idx, Face face)
wireframeIndices = wireframeIndexList.ToArray();
count = indices.Length;
}

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 @@ -225,12 +234,7 @@ private staforeach (var entity in entities)
array[idx++] = (r);
array[idx++] = (g);
array[idx++] = (b);
array[idx++] = (face.IsSelected || face.Parent.IsSelected ? 1 : 0);
}
return idx;
}
}
}(face.Parent != null && face.Parent.IsSelected) ? 1 : 0);
array[idx++] = (face.IsSelected || (face.Parent != null && face.Parent.IsSelected) ? 1 : 0);
}
return idx;
}
Expand Down
6 changes: 3 additions & 3 deletions Sledge.DataStructures/MapObjects/Entity.cs
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using Sledge.DatCommonusing Sledge.DataStructures.GameData;
using Sledge.Common;
using Sledge.DataStructures.GameData;
using Sledge.DataStructures.Geometric;
using Sledge.DataStructures.Transformations;

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

publi public ITexture Sprite}
public ITexture Sprite { get; set; }

public Entity(long id) : base(id)
{
Expand Down
10 changes: 7 additions & 3 deletions Sledge.DataStructures/MapObjects/Map.cs
Expand Up @@ -58,9 +58,10 @@ public void PostLoadProcess(GameData.GameData gameData, Func<string, ITexture> t
IDGenerator.Reset(maxObjectId, maxFaceId);

// todo visgroups
// WorldSpawn.ForEach(x => x.IsVisgroupHidden, x => x.IsVisgroupHidden = true, true);

// Purge empty groups
foreach (var // WorldSpawn.ForEach(x => x.IsVisgroupHidden, x => x.IsVisgroupHidden = true, true);r emptyGroup in WorldSpawn.Find(x => x is Group && !x.Children.Any()))
foreach (var emptyGroup in WorldSpawn.Find(x => x is Group && !x.Children.Any()))
{
emptyGroup.Parent.Children.Remove(emptyGroup);
}
Expand All @@ -78,12 +79,15 @@ public void PartialPostLoadProcess(Predicate<MapObject> matcher, GameData.GameDa
{
if (obj is Entity)
{
((Entity)obj).GameData = gameData.Classes.FirstOrDefault(x => x.Name == ((Entityvar gd = gameData.Classes.FirstOrDefault(x => x.Name == ((Entity) obj).EntityData.Name);
var 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)
((Entity) obj).Sprite = t;
obj.UpdateBoundingBox();
}
else if (obj is Solid)
{
((Solid)obj).Faces.ForEach(f =>
{
Expand Down
9 changes: 6 additions & 3 deletions Sledge.Editor/Documents/Document.cs
Expand Up @@ -12,13 +12,14 @@
using Sledge.Editor.Tools;
using Sledge.Editor.UI;
using Sledge.Editor.Visgroups;
using Sledge.Graphics;
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.PaSledge.UItem.IO.Path;
using Sledge.UI;
using Path = System.IO.Path;

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

public bool HideFaceMask { get; set; }

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

public SelectionManager Selection { get; private set; }
public HistoryManager History { get; private set; }

private readonly DocumentSubscriptions _subscriptions;
Expand Down
23 changes: 12 additions & 11 deletions Sledge.Editor/Sledge.Editor.csproj
Expand Up @@ -107,14 +107,14 @@
<Compile Include="Documents\Document.cs" />
<Compile Include="Documents\DocumentManager.cs" />
<Compile Include="Documents\DocumentSubscriptions.cs" />
<Compile Include="Documents\RenderManager.cs" />
<Compile Include="Editing\SelectionManager.cs" />
<Compile Include="EdMenu\IMenuBuilder.cs" />
<Compile Include="Menu\IMenuBuilder.cs" />
<Compile Include="Menu\MenuManager.cs" />
<Compile Include="Menu\MenuSplitter.cs" />
<Compile Include="Menu\RecentFilesMenu.cs" />
<Compile Include="Menu\SimpleMenuBuilder.cs" />
<Compile Include="Renderingtor.cs" />
<Compile Include="Rendering\RenderManager.cs" />
<Compile Include="Editing\SelectionManager.cs" />
<Compile Include="EditorMediator.cs" />
<Compile Include="Error.cs" />
<Compile Include="Extensions\EnumExtensions.cs" />
<Compile Include="GameFiles\SteamGame.cs" />
Expand Down Expand Up @@ -143,11 +143,11 @@
<SubType>Code</SubType>
</Compile>
<Compile Include="Rendering\MapDisplayLists.cs" />
<Compile Include="Rendering\RenderManagerRenderable.cs" />
<Compile Include="Rendering\ToolRenderable.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="Rendering\TransformedDisplayListRenderable.cs" />
RenderManagerRenderableansformedDisplayListRenderable.cs" />
<Compile Include="Rendering\WidgetLinesRenderable.cs" />
<Compile Include="Settings\Elevate.cs" />
<Compile Include="SledgeCursors.cs" />
Expand Down Expand Up @@ -326,19 +326,20 @@
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<None Include="Sprites\lightbulb.spr">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Sprites\speaker.spr">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Sledge.Common\Sledge.Common.csproj">
<Project>{5D414AC8-8B93-489F-9960-877923400FED}</Project>
<Name>Sledge.Common</Name>
</ProjectReference>
<ProjectReference Include="..\Sledge.Database\Sledge.Database.csproj">
<Project>{FC8A5448-0F8 <None Include="Sprites\lightbulb.spr">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Sprites\speaker.spr">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Non48-0F8B-4828-AC49-8D6138E20254}</Project>
<Project>{FC8A5448-0F8B-4828-AC49-8D6138E20254}</Project>
<Name>Sledge.Database</Name>
</ProjectReference>
<ProjectReference Include="..\Sledge.DataStructures.Rendering\Sledge.DataStructures.Rendering.csproj">
Expand Down

0 comments on commit c84d874

Please sign in to comment.