Allow mods and maps to define voxel sequences.
This commit is contained in:
@@ -20,7 +20,7 @@ namespace OpenRA.FileFormats
|
|||||||
{
|
{
|
||||||
public readonly string[]
|
public readonly string[]
|
||||||
Mods, Folders, Rules, ServerTraits,
|
Mods, Folders, Rules, ServerTraits,
|
||||||
Sequences, Cursors, Chrome, Assemblies, ChromeLayout,
|
Sequences, VoxelSequences, Cursors, Chrome, Assemblies, ChromeLayout,
|
||||||
Weapons, Voices, Notifications, Music, Movies, TileSets,
|
Weapons, Voices, Notifications, Music, Movies, TileSets,
|
||||||
ChromeMetrics, PackageContents;
|
ChromeMetrics, PackageContents;
|
||||||
|
|
||||||
@@ -42,6 +42,7 @@ namespace OpenRA.FileFormats
|
|||||||
Rules = YamlList(yaml, "Rules");
|
Rules = YamlList(yaml, "Rules");
|
||||||
ServerTraits = YamlList(yaml, "ServerTraits");
|
ServerTraits = YamlList(yaml, "ServerTraits");
|
||||||
Sequences = YamlList(yaml, "Sequences");
|
Sequences = YamlList(yaml, "Sequences");
|
||||||
|
VoxelSequences = YamlList(yaml, "VoxelSequences");
|
||||||
Cursors = YamlList(yaml, "Cursors");
|
Cursors = YamlList(yaml, "Cursors");
|
||||||
Chrome = YamlList(yaml, "Chrome");
|
Chrome = YamlList(yaml, "Chrome");
|
||||||
Assemblies = YamlList(yaml, "Assemblies");
|
Assemblies = YamlList(yaml, "Assemblies");
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ namespace OpenRA.Graphics
|
|||||||
{
|
{
|
||||||
SheetBuilder sheetBuilder;
|
SheetBuilder sheetBuilder;
|
||||||
|
|
||||||
|
Cache<Pair<string,string>, Voxel> voxels;
|
||||||
IVertexBuffer<Vertex> vertexBuffer;
|
IVertexBuffer<Vertex> vertexBuffer;
|
||||||
List<Vertex[]> vertices;
|
List<Vertex[]> vertices;
|
||||||
int totalVertexCount;
|
int totalVertexCount;
|
||||||
@@ -42,6 +43,7 @@ namespace OpenRA.Graphics
|
|||||||
|
|
||||||
public VoxelLoader()
|
public VoxelLoader()
|
||||||
{
|
{
|
||||||
|
voxels = new Cache<Pair<string,string>, Voxel>(LoadFile);
|
||||||
vertices = new List<Vertex[]>();
|
vertices = new List<Vertex[]>();
|
||||||
totalVertexCount = 0;
|
totalVertexCount = 0;
|
||||||
cachedVertexCount = 0;
|
cachedVertexCount = 0;
|
||||||
@@ -190,5 +192,17 @@ namespace OpenRA.Graphics
|
|||||||
return vertexBuffer;
|
return vertexBuffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Voxel LoadFile(Pair<string,string> files)
|
||||||
|
{
|
||||||
|
var vxl = new VxlReader(FileSystem.OpenWithExts(files.First, ".vxl"));
|
||||||
|
var hva = new HvaReader(FileSystem.OpenWithExts(files.Second, ".hva"));
|
||||||
|
return new Voxel(this, vxl, hva);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Voxel Load(string vxl, string hva)
|
||||||
|
{
|
||||||
|
return voxels[Pair.New(vxl, hva)];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
88
OpenRA.Game/Graphics/VoxelProvider.cs
Normal file
88
OpenRA.Game/Graphics/VoxelProvider.cs
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.FileFormats;
|
||||||
|
|
||||||
|
namespace OpenRA.Graphics
|
||||||
|
{
|
||||||
|
public static class VoxelProvider
|
||||||
|
{
|
||||||
|
static Dictionary<string, Dictionary<string, Voxel>> units;
|
||||||
|
|
||||||
|
public static void Initialize(string[] voxelFiles, List<MiniYamlNode> voxelNodes)
|
||||||
|
{
|
||||||
|
units = new Dictionary<string, Dictionary<string, Voxel>>();
|
||||||
|
|
||||||
|
var sequences = voxelFiles
|
||||||
|
.Select(s => MiniYaml.FromFile(s))
|
||||||
|
.Aggregate(voxelNodes, MiniYaml.MergeLiberal);
|
||||||
|
|
||||||
|
foreach (var s in sequences)
|
||||||
|
LoadVoxelsForUnit(s.Key, s.Value);
|
||||||
|
|
||||||
|
Game.modData.VoxelLoader.RefreshBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
static Voxel LoadVoxel(string unit, string name, MiniYaml info)
|
||||||
|
{
|
||||||
|
var vxl = unit;
|
||||||
|
var hva = unit;
|
||||||
|
if (info.Value != null)
|
||||||
|
{
|
||||||
|
var fields = info.Value.Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (fields.Length >= 1)
|
||||||
|
vxl = hva = fields[0].Trim();
|
||||||
|
|
||||||
|
if (fields.Length >= 2)
|
||||||
|
hva = fields[1].Trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Game.modData.VoxelLoader.Load(vxl, hva);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void LoadVoxelsForUnit(string unit, MiniYaml sequences)
|
||||||
|
{
|
||||||
|
Game.modData.LoadScreen.Display();
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var seq = sequences.NodesDict.ToDictionary(x => x.Key, x => LoadVoxel(unit,x.Key,x.Value));
|
||||||
|
units.Add(unit, seq);
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException) {} // Do nothing; we can crash later if we actually wanted art
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Voxel GetVoxel(string unitName, string voxelName)
|
||||||
|
{
|
||||||
|
try { return units[unitName][voxelName]; }
|
||||||
|
catch (KeyNotFoundException)
|
||||||
|
{
|
||||||
|
if (units.ContainsKey(unitName))
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Unit `{0}` does not have a voxel `{1}`".F(unitName, voxelName));
|
||||||
|
else
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Unit `{0}` does not have any voxels defined.".F(unitName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool HasVoxel(string unit, string seq)
|
||||||
|
{
|
||||||
|
if (!units.ContainsKey(unit))
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Unit `{0}` does not have any voxels defined.".F(unit));
|
||||||
|
|
||||||
|
return units[unit].ContainsKey(seq);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,6 +59,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public List<MiniYamlNode> Rules = new List<MiniYamlNode>();
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> Sequences = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public List<MiniYamlNode> Sequences = new List<MiniYamlNode>();
|
||||||
|
[FieldLoader.Ignore] public List<MiniYamlNode> VoxelSequences = new List<MiniYamlNode>();
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> Weapons = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public List<MiniYamlNode> Weapons = new List<MiniYamlNode>();
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> Voices = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public List<MiniYamlNode> Voices = new List<MiniYamlNode>();
|
||||||
[FieldLoader.Ignore] public List<MiniYamlNode> Notifications = new List<MiniYamlNode>();
|
[FieldLoader.Ignore] public List<MiniYamlNode> Notifications = new List<MiniYamlNode>();
|
||||||
@@ -150,6 +151,7 @@ namespace OpenRA
|
|||||||
|
|
||||||
Rules = NodesOrEmpty(yaml, "Rules");
|
Rules = NodesOrEmpty(yaml, "Rules");
|
||||||
Sequences = NodesOrEmpty(yaml, "Sequences");
|
Sequences = NodesOrEmpty(yaml, "Sequences");
|
||||||
|
VoxelSequences = NodesOrEmpty(yaml, "VoxelSequences");
|
||||||
Weapons = NodesOrEmpty(yaml, "Weapons");
|
Weapons = NodesOrEmpty(yaml, "Weapons");
|
||||||
Voices = NodesOrEmpty(yaml, "Voices");
|
Voices = NodesOrEmpty(yaml, "Voices");
|
||||||
Notifications = NodesOrEmpty(yaml, "Notifications");
|
Notifications = NodesOrEmpty(yaml, "Notifications");
|
||||||
@@ -206,6 +208,7 @@ namespace OpenRA
|
|||||||
root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList<SmudgeReference>( Smudges.Value )));
|
root.Add(new MiniYamlNode("Smudges", MiniYaml.FromList<SmudgeReference>( Smudges.Value )));
|
||||||
root.Add(new MiniYamlNode("Rules", null, Rules));
|
root.Add(new MiniYamlNode("Rules", null, Rules));
|
||||||
root.Add(new MiniYamlNode("Sequences", null, Sequences));
|
root.Add(new MiniYamlNode("Sequences", null, Sequences));
|
||||||
|
root.Add(new MiniYamlNode("VoxelSequences", null, VoxelSequences));
|
||||||
root.Add(new MiniYamlNode("Weapons", null, Weapons));
|
root.Add(new MiniYamlNode("Weapons", null, Weapons));
|
||||||
root.Add(new MiniYamlNode("Voices", null, Voices));
|
root.Add(new MiniYamlNode("Voices", null, Voices));
|
||||||
root.Add(new MiniYamlNode("Notifications", null, Notifications));
|
root.Add(new MiniYamlNode("Notifications", null, Notifications));
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ namespace OpenRA
|
|||||||
SpriteLoader = new SpriteLoader(Rules.TileSets[map.Tileset].Extensions, SheetBuilder);
|
SpriteLoader = new SpriteLoader(Rules.TileSets[map.Tileset].Extensions, SheetBuilder);
|
||||||
// TODO: Don't load the sequences for assets that are not used in this tileset. Maybe use the existing EditorTilesetFilters.
|
// TODO: Don't load the sequences for assets that are not used in this tileset. Maybe use the existing EditorTilesetFilters.
|
||||||
SequenceProvider.Initialize(Manifest.Sequences, map.Sequences);
|
SequenceProvider.Initialize(Manifest.Sequences, map.Sequences);
|
||||||
|
VoxelProvider.Initialize(Manifest.VoxelSequences, map.VoxelSequences);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -229,6 +229,7 @@
|
|||||||
<Compile Include="Graphics\Voxel.cs" />
|
<Compile Include="Graphics\Voxel.cs" />
|
||||||
<Compile Include="Graphics\VoxelRenderer.cs" />
|
<Compile Include="Graphics\VoxelRenderer.cs" />
|
||||||
<Compile Include="Graphics\VoxelLoader.cs" />
|
<Compile Include="Graphics\VoxelLoader.cs" />
|
||||||
|
<Compile Include="Graphics\VoxelProvider.cs" />
|
||||||
<Compile Include="Traits\BodyOrientation.cs" />
|
<Compile Include="Traits\BodyOrientation.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user