git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1953 993157c7-ee19-0410-b2c4-bb4e9862e678

This commit is contained in:
chrisf
2008-03-25 00:45:43 +00:00
parent eb7094d49e
commit 33e856345f
16 changed files with 126 additions and 179 deletions

View File

@@ -47,18 +47,19 @@ namespace OpenRa.FileFormats
bool ProcessEntry( string line )
{
Match m = entryPattern.Match( line );
if( m == null || !m.Success )
int comment = line.IndexOf(';');
if (comment >= 0)
line = line.Substring(0, comment);
int eq = line.IndexOf('=');
if (eq < 0)
return false;
if( currentSection == null )
throw new InvalidOperationException( "No current INI section" );
string keyName = m.Groups[ 1 ].Value;
string keyValue = m.Groups[ 2 ].Value;
currentSection.Add( keyName, keyValue );
if (currentSection == null)
throw new InvalidOperationException("No current INI section");
currentSection.Add(line.Substring(0, eq),
line.Substring(eq + 1, line.Length - eq - 1));
return true;
}

View File

@@ -2,7 +2,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</ProjectGuid>
<OutputType>Library</OutputType>
@@ -14,6 +14,7 @@
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@@ -23,6 +24,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
@@ -31,6 +33,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Reference Include="MixDecrypt, Version=0.0.0.0, Culture=neutral, processorArchitecture=x86">

View File

@@ -13,20 +13,30 @@ namespace OpenRa.FileFormats
public class Package : IFolder
{
readonly string filename;
readonly List<PackageEntry> index;
readonly Dictionary<uint, PackageEntry> index;
readonly bool isRmix, isEncrypted;
readonly long dataStart;
readonly Stream s;
public ICollection<PackageEntry> Content
//public ICollection<PackageEntry> Content
//{
// get { return index.AsReadOnly(); }
//}
public static Dictionary<K, V> MakeDict<K,V>(IEnumerable<V> values, Converter<V, K> keyFunc)
{
get { return index.AsReadOnly(); }
var dict = new Dictionary<K, V>();
foreach (var v in values)
dict.Add(keyFunc(v), v);
return dict;
}
public Package(string filename)
{
this.filename = filename;
using (Stream s = FileSystem.Open(filename))
{
s = FileSystem.Open(filename);
BinaryReader reader = new BinaryReader(s);
uint signature = reader.ReadUInt32();
@@ -37,15 +47,14 @@ namespace OpenRa.FileFormats
isEncrypted = 0 != (signature & (uint)MixFileFlags.Encrypted);
if( isEncrypted )
{
index = ParseRaHeader( s, out dataStart );
index = MakeDict(ParseRaHeader( s, out dataStart ), x => x.Hash );
return;
}
}
isEncrypted = false;
s.Seek(0, SeekOrigin.Begin);
index = ParseTdHeader(s, out dataStart);
}
index = MakeDict(ParseTdHeader(s, out dataStart), x => x.Hash );
}
const long headerStart = 84;
@@ -121,20 +130,15 @@ namespace OpenRa.FileFormats
public Stream GetContent(uint hash)
{
foreach( PackageEntry e in index )
if (e.Hash == hash)
{
using (Stream s = FileSystem.Open(filename))
{
PackageEntry e;
if (!index.TryGetValue(hash, out e))
return null;
s.Seek( dataStart + e.Offset, SeekOrigin.Begin );
byte[] data = new byte[ e.Length ];
s.Read( data, 0, (int)e.Length );
return new MemoryStream(data);
}
}
return null;
}
public Stream GetContent(string filename)
{

View File

@@ -39,13 +39,11 @@ namespace OpenRa.FileFormats
MemoryStream ms = new MemoryStream(Encoding.ASCII.GetBytes(name));
BinaryReader reader = new BinaryReader(ms);
int len = name.Length >> 2;
uint result = 0;
try
{
while(true)
while (len-- != 0)
result = ((result << 1) | (result >> 31)) + reader.ReadUInt32();
}
catch (EndOfStreamException) { }
return result;
}

View File

@@ -71,10 +71,13 @@
<Compile Include="Building.cs" />
<Compile Include="Game.cs" />
<Compile Include="IOrderGenerator.cs" />
<Compile Include="Item.cs" />
<Compile Include="Network\Packet.cs" />
<Compile Include="Player.cs" />
<Compile Include="PlayerOwned.cs" />
<Compile Include="Race.cs" />
<Compile Include="Rules.cs" />
<Compile Include="SharedResources.cs" />
<Compile Include="Sheet.cs" />
<Compile Include="Log.cs" />
<Compile Include="Network\Network.cs" />
@@ -99,6 +102,7 @@
<Compile Include="Sprite.cs" />
<Compile Include="SpriteRenderer.cs" />
<Compile Include="SpriteSheetBuilder.cs" />
<Compile Include="TechTree.cs" />
<Compile Include="TerrainCosts.cs" />
<Compile Include="TerrainRenderer.cs" />
<Compile Include="Tree.cs" />
@@ -121,10 +125,6 @@
<Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project>
<Name>OpenRa.FileFormats</Name>
</ProjectReference>
<ProjectReference Include="..\OpenRa.TechTree\OpenRa.TechTree.csproj">
<Project>{2BFC3861-E90E-4F77-B254-8FB8285E43AC}</Project>
<Name>OpenRa.TechTree</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">

View File

@@ -12,7 +12,7 @@ namespace OpenRa.Game
static Rules()
{
IniFile rulesIni = new IniFile(FileSystem.Open("rules.ini"));
var rulesIni = SharedResources.Rules;
foreach (string line in Util.ReadAllLines(FileSystem.Open("units.txt")))
{

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;
using OpenRa.FileFormats;
using IjwFramework.Types;
namespace OpenRa.Game
{
class SharedResources
{
static Lazy<IniFile> rules = new Lazy<IniFile>( () => new IniFile( FileSystem.Open( "rules.ini" )));
public static IniFile Rules { get { return rules.Value; } }
}
}

View File

@@ -13,6 +13,8 @@ namespace OpenRa.Game
public readonly RectangleF uv;
public readonly float2 size;
readonly float2[] uvhax;
internal Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
{
this.bounds = bounds;
@@ -25,6 +27,14 @@ namespace OpenRa.Game
(float)(bounds.Width) / sheet.Size.Width,
(float)(bounds.Height) / sheet.Size.Height);
uvhax = new float2[]
{
MapTextureCoords( new float2(0,0) ),
MapTextureCoords( new float2(1,0) ),
MapTextureCoords( new float2(0,1) ),
MapTextureCoords( new float2(1,1) ),
};
this.size = new float2(bounds.Size);
}
@@ -35,7 +45,10 @@ namespace OpenRa.Game
p.Y > 0 ? uv.Bottom : uv.Top);
}
public float2 Size { get { return size; } }
public float2 FastMapTextureCoords(int k)
{
return uvhax[k];
}
}
public enum TextureChannel

View File

@@ -4,14 +4,12 @@ using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using OpenRa.FileFormats;
using OpenRa.Game;
namespace OpenRa.TechTree
{
public class TechTree
{
static IniFile rules;
static IniFile Rules { get { return rules ?? (rules = new IniFile(FileSystem.Open("rules.ini"))); } }
Dictionary<string, Item> objects = new Dictionary<string, Item>();
public ICollection<string> built = new List<string>();
@@ -61,8 +59,10 @@ namespace OpenRa.TechTree
Lines("buildings.txt", true),
Lines("units.txt", false));
var rules = SharedResources.Rules;
foreach (Tuple<string, string, bool> p in definitions)
objects.Add(p.a, new Item(p.a, p.b, Rules.GetSection(p.a), p.c));
objects.Add(p.a, new Item(p.a, p.b, rules.GetSection(p.a), p.c));
}
public bool Build(string key, bool force)

View File

@@ -36,7 +36,7 @@ namespace OpenRa.Game
static TerrainCosts()
{
IniFile file = new IniFile(FileSystem.Open("rules.ini"));
IniFile file = SharedResources.Rules;
for( int i = 0 ; i < 10 ; i++ )
{

View File

@@ -17,17 +17,24 @@ namespace OpenRa.Game
return new float2(paletteLine / 16.0f, channelSelect[(int)channel]);
}
public static Vertex MakeVertex(float2 o, float2 uv, Sprite r, int palette)
static float2 KLerp(float2 o, float2 d, int k)
{
return new Vertex(
float2.Lerp( o, o + r.Size, uv ),
r.MapTextureCoords(uv),
EncodeVertexAttributes(r.channel, palette));
switch (k)
{
case 0: return o;
case 1: return new float2(o.X + d.X, o.Y);
case 2: return new float2(o.X, o.Y + d.Y);
case 3: return new float2(o.X + d.X, o.Y + d.Y);
default: throw new InvalidOperationException();
}
}
static float Lerp(float a, float b, float t)
static Vertex MakeVertex(float2 o, int k, Sprite r, float2 attrib)
{
return (1 - t) * a + t * b;
return new Vertex(
KLerp( o, r.size, k ),
r.FastMapTextureCoords(k),
attrib);
}
public static string[] ReadAllLines(Stream s)
@@ -49,28 +56,27 @@ namespace OpenRa.Game
return result;
}
static float2[] uv =
{
new float2( 0,0 ),
new float2( 1,0 ),
new float2( 0,1 ),
new float2( 1,1 ),
};
public static void CreateQuad(List<Vertex> vertices, List<ushort> indices, float2 o, Sprite r, int palette)
{
ushort offset = (ushort)vertices.Count;
float2 attrib = EncodeVertexAttributes(r.channel, palette);
foreach( float2 p in uv )
vertices.Add(Util.MakeVertex(o, p, r, palette));
Vertex[] v = new Vertex[]
{
Util.MakeVertex(o, 0, r, attrib),
Util.MakeVertex(o, 1, r, attrib),
Util.MakeVertex(o, 2, r, attrib),
Util.MakeVertex(o, 3, r, attrib),
};
indices.Add(offset);
indices.Add((ushort)(offset + 1));
indices.Add((ushort)(offset + 2));
vertices.AddRange(v);
indices.Add((ushort)(offset + 1));
indices.Add((ushort)(offset + 3));
indices.Add((ushort)(offset + 2));
ushort[] i = new ushort[]
{
offset, (ushort)(offset + 1), (ushort)(offset + 2), (ushort)(offset + 1), (ushort)(offset + 3), (ushort)(offset + 2)
};
indices.AddRange(i);
}
public static void FastCopyIntoChannel(Sprite dest, byte[] src)

View File

@@ -1,65 +0,0 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{2BFC3861-E90E-4F77-B254-8FB8285E43AC}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>OpenRa.TechTree</RootNamespace>
<AssemblyName>OpenRa.TechTree</AssemblyName>
<FileUpgradeFlags>
</FileUpgradeFlags>
<OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation>
</UpgradeBackupLocation>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Item.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Race.cs" />
<Compile Include="TechTree.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRa.DataStructures\OpenRa.DataStructures.csproj">
<Project>{2F9E7A23-56C0-4286-9C8E-1060A9B2F073}</Project>
<Name>OpenRa.DataStructures</Name>
</ProjectReference>
<ProjectReference Include="..\OpenRa.FileFormats\OpenRa.FileFormats.csproj">
<Project>{BDAEAB25-991E-46A7-AF1E-4F0E03358DAA}</Project>
<Name>OpenRa.FileFormats</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -1,15 +0,0 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("OpenRa.TechTree")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("IJW Software")]
[assembly: AssemblyProduct("OpenRa.TechTree")]
[assembly: AssemblyCopyright("Copyright © IJW Software 2007")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -10,8 +10,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.FileFormats", "OpenR
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.Game", "OpenRa.Game\OpenRa.Game.csproj", "{0DFB103F-2962-400F-8C6D-E2C28CCBA633}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.TechTree", "OpenRa.TechTree\OpenRa.TechTree.csproj", "{2BFC3861-E90E-4F77-B254-8FB8285E43AC}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRa.DataStructures", "OpenRa.DataStructures\OpenRa.DataStructures.csproj", "{2F9E7A23-56C0-4286-9C8E-1060A9B2F073}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PaletteUsage", "PaletteUsage\PaletteUsage.csproj", "{54577061-E2D2-4336-90A2-A9A7106A30CD}"
@@ -56,16 +54,6 @@ Global
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{0DFB103F-2962-400F-8C6D-E2C28CCBA633}.Release|Win32.ActiveCfg = Release|Any CPU
{2BFC3861-E90E-4F77-B254-8FB8285E43AC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2BFC3861-E90E-4F77-B254-8FB8285E43AC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2BFC3861-E90E-4F77-B254-8FB8285E43AC}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{2BFC3861-E90E-4F77-B254-8FB8285E43AC}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{2BFC3861-E90E-4F77-B254-8FB8285E43AC}.Debug|Win32.ActiveCfg = Debug|Any CPU
{2BFC3861-E90E-4F77-B254-8FB8285E43AC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2BFC3861-E90E-4F77-B254-8FB8285E43AC}.Release|Any CPU.Build.0 = Release|Any CPU
{2BFC3861-E90E-4F77-B254-8FB8285E43AC}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{2BFC3861-E90E-4F77-B254-8FB8285E43AC}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{2BFC3861-E90E-4F77-B254-8FB8285E43AC}.Release|Win32.ActiveCfg = Release|Any CPU
{2F9E7A23-56C0-4286-9C8E-1060A9B2F073}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F9E7A23-56C0-4286-9C8E-1060A9B2F073}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F9E7A23-56C0-4286-9C8E-1060A9B2F073}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU