mostly fixes openra startup time

git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1928 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
chrisf
2008-03-13 02:28:58 +00:00
parent 88adf25113
commit 25ece92b1f
6 changed files with 83 additions and 32 deletions

View File

@@ -22,7 +22,7 @@ namespace OpenRa.FileFormats
} }
} }
Regex sectionPattern = new Regex( @"\[([^]]*)\]" ); Regex sectionPattern = new Regex( @"^\[([^]]*)\]" );
Regex entryPattern = new Regex( @"([^=;]+)=([^;]*)" ); Regex entryPattern = new Regex( @"([^=;]+)=([^;]*)" );
bool ProcessSection( string line ) bool ProcessSection( string line )
@@ -40,6 +40,9 @@ namespace OpenRa.FileFormats
bool ProcessEntry( string line ) bool ProcessEntry( string line )
{ {
if (string.IsNullOrEmpty(line) || line.StartsWith(";"))
return false;
Match m = entryPattern.Match( line ); Match m = entryPattern.Match( line );
if( m == null || !m.Success ) if( m == null || !m.Success )
return false; return false;

View File

@@ -2,7 +2,7 @@
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion> <ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</ProjectGuid> <ProjectGuid>{0DFB103F-2962-400F-8C6D-E2C28CCBA633}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
@@ -14,6 +14,21 @@
<OldToolsVersion>2.0</OldToolsVersion> <OldToolsVersion>2.0</OldToolsVersion>
<UpgradeBackupLocation> <UpgradeBackupLocation>
</UpgradeBackupLocation> </UpgradeBackupLocation>
<PublishUrl>publish\</PublishUrl>
<Install>true</Install>
<InstallFrom>Disk</InstallFrom>
<UpdateEnabled>false</UpdateEnabled>
<UpdateMode>Foreground</UpdateMode>
<UpdateInterval>7</UpdateInterval>
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
<UpdatePeriodically>false</UpdatePeriodically>
<UpdateRequired>false</UpdateRequired>
<MapFileExtensions>true</MapFileExtensions>
<ApplicationRevision>0</ApplicationRevision>
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
<IsWebBootstrapper>false</IsWebBootstrapper>
<UseApplicationTrust>false</UseApplicationTrust>
<BootstrapperEnabled>true</BootstrapperEnabled>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols> <DebugSymbols>true</DebugSymbols>
@@ -24,6 +39,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<UseVSHostingProcess>false</UseVSHostingProcess> <UseVSHostingProcess>false</UseVSHostingProcess>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
@@ -109,6 +125,23 @@
<Name>OpenRa.TechTree</Name> <Name>OpenRa.TechTree</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Framework.2.0">
<Visible>False</Visible>
<ProductName>.NET Framework 2.0 %28x86%29</ProductName>
<Install>true</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.0">
<Visible>False</Visible>
<ProductName>.NET Framework 3.0 %28x86%29</ProductName>
<Install>false</Install>
</BootstrapperPackage>
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5">
<Visible>False</Visible>
<ProductName>.NET Framework 3.5</ProductName>
<Install>false</Install>
</BootstrapperPackage>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. <!-- 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. Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -48,5 +48,7 @@ namespace OpenRa.Game
get { return bitmap.GetPixel(p.X, p.Y); } get { return bitmap.GetPixel(p.X, p.Y); }
set { bitmap.SetPixel(p.X, p.Y, value); } set { bitmap.SetPixel(p.X, p.Y, value); }
} }
public Bitmap Bitmap { get { return bitmap; } } // for perf
} }
} }

View File

@@ -16,7 +16,8 @@ namespace OpenRa.Game
public static Sprite Add(byte[] src, Size size) public static Sprite Add(byte[] src, Size size)
{ {
Sprite rect = AddImage(size); Sprite rect = AddImage(size);
Util.CopyIntoChannel(rect, src); //Util.CopyIntoChannel(rect, src);
Util.FastCopyIntoChannel(rect, src);
return rect; return rect;
} }

View File

@@ -10,30 +10,23 @@ namespace OpenRa.Game
public readonly Rectangle bounds; public readonly Rectangle bounds;
public readonly Sheet sheet; public readonly Sheet sheet;
public readonly TextureChannel channel; public readonly TextureChannel channel;
public readonly RectangleF uv;
internal Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel) internal Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
{ {
this.bounds = bounds; this.bounds = bounds;
this.sheet = sheet; this.sheet = sheet;
this.channel = channel; this.channel = channel;
}
RectangleF TextureCoords uv = new RectangleF(
{
get
{
return new RectangleF(
(float)(bounds.Left + 0.5f) / sheet.Size.Width, (float)(bounds.Left + 0.5f) / sheet.Size.Width,
(float)(bounds.Top + 0.5f) / sheet.Size.Height, (float)(bounds.Top + 0.5f) / sheet.Size.Height,
(float)(bounds.Width) / sheet.Size.Width, (float)(bounds.Width) / sheet.Size.Width,
(float)(bounds.Height) / sheet.Size.Height); (float)(bounds.Height) / sheet.Size.Height);
}
} }
public float2 MapTextureCoords(float2 p) public float2 MapTextureCoords(float2 p)
{ {
RectangleF uv = TextureCoords;
return new float2( return new float2(
p.X > 0 ? uv.Right : uv.Left, p.X > 0 ? uv.Right : uv.Left,
p.Y > 0 ? uv.Bottom : uv.Top); p.Y > 0 ? uv.Bottom : uv.Top);
@@ -42,9 +35,9 @@ namespace OpenRa.Game
public enum TextureChannel public enum TextureChannel
{ {
Red, Red = 0,
Green, Green = 1,
Blue, Blue = 2,
Alpha, Alpha = 3,
} }
} }

View File

@@ -4,6 +4,7 @@ using System.Text;
using OpenRa.FileFormats; using OpenRa.FileFormats;
using System.Drawing; using System.Drawing;
using System.IO; using System.IO;
using System.Drawing.Imaging;
namespace OpenRa.Game namespace OpenRa.Game
{ {
@@ -83,29 +84,47 @@ namespace OpenRa.Game
indices.Add((ushort)(offset + 2)); indices.Add((ushort)(offset + 2));
} }
public static void CopyIntoChannel(Sprite dest, byte[] src) public static void FastCopyIntoChannel(Sprite dest, byte[] src)
{ {
for (int i = 0; i < dest.bounds.Width; i++) var bitmap = dest.sheet.Bitmap;
for (int j = 0; j < dest.bounds.Height; j++) BitmapData bits = null;
uint[] channelMasks = { 0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000 };
uint mask = channelMasks[(int)dest.channel];
try
{
bits = bitmap.LockBits(dest.bounds, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
int width = dest.bounds.Width;
int height = dest.bounds.Height;
for (int j = 0; j < height; j++)
{ {
Point p = new Point(dest.bounds.Left + i, dest.bounds.Top + j); unsafe
byte b = src[i + dest.bounds.Width * j]; {
dest.sheet[p] = ReplaceChannel(dest.sheet[p], dest.channel, b); uint* p = (uint*)(bits.Scan0.ToInt32() + j * bits.Stride);
for (int i = 0; i < width; i++, p++)
*p = ReplaceChannel(*p, mask, src[i + width * j]);
}
} }
}
finally
{
bitmap.UnlockBits(bits);
}
} }
static Color ReplaceChannel(Color o, TextureChannel channel, byte p) static uint ReplaceChannel(uint o, uint mask, byte p)
{ {
switch (channel) uint pp = (uint)p;
{
case TextureChannel.Red: return Color.FromArgb(o.A, p, o.G, o.B);
case TextureChannel.Green: return Color.FromArgb(o.A, o.R, p, o.B);
case TextureChannel.Blue: return Color.FromArgb(o.A, o.R, o.G, p);
case TextureChannel.Alpha: return Color.FromArgb(p, o.R, o.G, o.B);
default: pp |= pp << 8; // copy into all channels
throw new ArgumentException(); pp |= pp << 16;
}
o &= ~mask;
o |= (mask & pp);
return o;
} }
} }
} }