best way of removing duplication?? *delete*
git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1184 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -21,8 +21,6 @@ namespace OpenRa.Game
|
||||
Package TileMix;
|
||||
string TileSuffix;
|
||||
|
||||
const string mapName = "scm12ea.ini";
|
||||
|
||||
Dictionary<TileReference, SheetRectangle<Sheet>> tileMapping =
|
||||
new Dictionary<TileReference, SheetRectangle<Sheet>>();
|
||||
|
||||
@@ -35,14 +33,14 @@ namespace OpenRa.Game
|
||||
|
||||
void LoadTextures()
|
||||
{
|
||||
List<Sheet> tempSheets = new List<Sheet>();
|
||||
List<Sheet> sheets = new List<Sheet>();
|
||||
|
||||
Size pageSize = new Size(1024,512);
|
||||
|
||||
Provider<Sheet> sheetProvider = delegate
|
||||
{
|
||||
Sheet t = new Sheet( new Bitmap(pageSize.Width, pageSize.Height));
|
||||
tempSheets.Add(t);
|
||||
sheets.Add(t);
|
||||
return t;
|
||||
};
|
||||
|
||||
@@ -55,8 +53,9 @@ namespace OpenRa.Game
|
||||
|
||||
if (!tileMapping.ContainsKey(tileRef))
|
||||
{
|
||||
SheetRectangle<Sheet> rect = builder.AddImage(new Size(24, 24));
|
||||
Bitmap srcImage = tileSet.tiles[ tileRef.tile ].GetTile( tileRef.image );
|
||||
Bitmap srcImage = tileSet.tiles[tileRef.tile].GetTile(tileRef.image);
|
||||
SheetRectangle<Sheet> rect = builder.AddImage(srcImage.Size);
|
||||
|
||||
using (Graphics g = Graphics.FromImage(rect.sheet.bitmap))
|
||||
g.DrawImage(srcImage, rect.origin);
|
||||
|
||||
@@ -64,7 +63,7 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
foreach (Sheet s in tempSheets)
|
||||
foreach (Sheet s in sheets)
|
||||
s.LoadTexture(renderer.Device);
|
||||
|
||||
world = new World(renderer.Device);
|
||||
@@ -105,12 +104,22 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
public MainWindow()
|
||||
static Size GetResolution(Settings settings)
|
||||
{
|
||||
Size desktopResolution = Screen.PrimaryScreen.Bounds.Size;
|
||||
|
||||
return new Size(settings.GetValue("width", desktopResolution.Width),
|
||||
settings.GetValue("height", desktopResolution.Height));
|
||||
}
|
||||
|
||||
public MainWindow( Settings settings )
|
||||
{
|
||||
FormBorderStyle = FormBorderStyle.None;
|
||||
renderer = new Renderer(this, Screen.PrimaryScreen.Bounds.Size, false);
|
||||
renderer = new Renderer(this, GetResolution(settings), false);
|
||||
Visible = true;
|
||||
|
||||
string mapName = settings.GetValue("map", "scm12ea.ini");
|
||||
|
||||
IniFile mapFile = new IniFile(File.OpenRead("../../../" + mapName));
|
||||
map = new Map(mapFile);
|
||||
|
||||
|
||||
@@ -8,16 +8,21 @@ namespace OpenRa.Game
|
||||
{
|
||||
class Mcv : Actor
|
||||
{
|
||||
//int facing; // not currently used
|
||||
|
||||
public Mcv( PointF location )
|
||||
{
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
int GetFacing()
|
||||
{
|
||||
int x = (Environment.TickCount >> 6) % 64;
|
||||
|
||||
return x < 32 ? x : 63 - x;
|
||||
}
|
||||
|
||||
public override SheetRectangle<Sheet>[] CurrentImages
|
||||
{
|
||||
get { return new SheetRectangle<Sheet>[] { UnitSheetBuilder.McvSheet[ 0 ] }; }
|
||||
get { return new SheetRectangle<Sheet>[] { UnitSheetBuilder.McvSheet[ GetFacing() ] }; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Renderer.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
<Compile Include="Sheet.cs" />
|
||||
<Compile Include="Tree.cs" />
|
||||
<Compile Include="TreeCache.cs" />
|
||||
|
||||
@@ -8,14 +8,16 @@ namespace OpenRa.Game
|
||||
static class Program
|
||||
{
|
||||
[STAThread]
|
||||
static void Main()
|
||||
static void Main( string[] args )
|
||||
{
|
||||
try
|
||||
{
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault( false );
|
||||
|
||||
new MainWindow().Run();
|
||||
Settings settings = new Settings(args);
|
||||
|
||||
new MainWindow( settings ).Run();
|
||||
}
|
||||
catch( Exception e )
|
||||
{
|
||||
|
||||
45
OpenRa.Game/Settings.cs
Normal file
45
OpenRa.Game/Settings.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
class Settings
|
||||
{
|
||||
Dictionary<string, string> settings = new Dictionary<string, string>();
|
||||
|
||||
public Settings(IEnumerable<string> src)
|
||||
{
|
||||
Regex regex = new Regex("([^=]+)=(.*)");
|
||||
foreach (string s in src)
|
||||
{
|
||||
Match m = regex.Match(s);
|
||||
if (m == null || !m.Success)
|
||||
continue;
|
||||
|
||||
settings.Add(m.Groups[1].Value, m.Groups[2].Value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool Contains(string key)
|
||||
{
|
||||
return settings.ContainsKey(key);
|
||||
}
|
||||
|
||||
public string GetValue(string key, string defaultValue)
|
||||
{
|
||||
return Contains(key) ? settings[key] : defaultValue;
|
||||
}
|
||||
|
||||
public int GetValue(string key, int defaultValue)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (!int.TryParse(GetValue(key, defaultValue.ToString()), out result))
|
||||
result = defaultValue;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,12 +28,15 @@ namespace OpenRa.Game
|
||||
actors.Add(a); //todo: protect from concurrent modification
|
||||
}
|
||||
|
||||
// assumption: there is only one sheet!
|
||||
// some noob needs to fix this!
|
||||
|
||||
// assumption: its not going to hurt, to draw *all* units.
|
||||
// in reality, 500 tanks is going to hurt our perf.
|
||||
|
||||
// assumption: we dont skip around between sheets much. otherwise, our perf is going to SUCK.
|
||||
// this can be fixed by pooling vertex/index lists, except that breaks z-ordering
|
||||
// across sheets.
|
||||
|
||||
// assumption: when people fix these items, they might update the warning comment?
|
||||
|
||||
public void Draw(Renderer renderer)
|
||||
{
|
||||
int sprites = 0;
|
||||
|
||||
Reference in New Issue
Block a user