git-svn-id: svn://svn.ijw.co.nz/svn/OpenRa@1330 993157c7-ee19-0410-b2c4-bb4e9862e678
This commit is contained in:
@@ -15,31 +15,31 @@ namespace OpenRa.Game
|
||||
public readonly PathFinder pathFinder;
|
||||
public readonly Network network;
|
||||
|
||||
public Game( string mapName, Renderer renderer, int2 clientSize )
|
||||
public Game(string mapName, Renderer renderer, int2 clientSize)
|
||||
{
|
||||
map = new Map( new IniFile( FileSystem.Open( mapName ) ) );
|
||||
FileSystem.Mount( new Package( "../../../" + map.Theater + ".mix" ) );
|
||||
map = new Map(new IniFile(FileSystem.Open(mapName)));
|
||||
FileSystem.Mount(new Package("../../../" + map.Theater + ".mix"));
|
||||
|
||||
viewport = new Viewport( clientSize, new float2( map.Size ), renderer );
|
||||
|
||||
terrain = new TerrainRenderer( renderer, map, viewport );
|
||||
world = new World( renderer, viewport );
|
||||
treeCache = new TreeCache( renderer.Device, map );
|
||||
viewport = new Viewport(clientSize, map.Size, renderer);
|
||||
|
||||
foreach( TreeReference treeReference in map.Trees )
|
||||
world.Add( new Tree( treeReference, treeCache, map ) );
|
||||
terrain = new TerrainRenderer(renderer, map, viewport);
|
||||
world = new World(renderer, viewport);
|
||||
treeCache = new TreeCache(renderer.Device, map);
|
||||
|
||||
pathFinder = new PathFinder( map, terrain.tileSet );
|
||||
foreach (TreeReference treeReference in map.Trees)
|
||||
world.Add(new Tree(treeReference, treeCache, map));
|
||||
|
||||
pathFinder = new PathFinder(map, terrain.tileSet);
|
||||
|
||||
network = new Network();
|
||||
}
|
||||
|
||||
public void Tick()
|
||||
{
|
||||
viewport.DrawRegions( this );
|
||||
viewport.DrawRegions(this);
|
||||
}
|
||||
|
||||
public void Issue( IOrder order )
|
||||
public void Issue(IOrder order)
|
||||
{
|
||||
order.Apply();
|
||||
}
|
||||
|
||||
@@ -8,22 +8,14 @@ using OpenRa.FileFormats;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
// todo: synthesize selection color, and generate duplicate palette block!
|
||||
public class HardwarePalette
|
||||
class HardwarePalette : Sheet
|
||||
{
|
||||
const int maxEntries = 16; // dont need anything like this many,
|
||||
// but the hardware likes square textures better
|
||||
|
||||
Bitmap bitmap = new Bitmap(256, maxEntries);
|
||||
GraphicsDevice device;
|
||||
const int maxEntries = 16;
|
||||
int allocated = 0;
|
||||
|
||||
Texture paletteTexture;
|
||||
|
||||
public HardwarePalette(GraphicsDevice device, Map map)
|
||||
public HardwarePalette(Renderer renderer, Map map)
|
||||
: base(renderer,new Size(256, maxEntries))
|
||||
{
|
||||
this.device = device;
|
||||
|
||||
Palette pal = new Palette(FileSystem.Open(map.Theater + ".pal"));
|
||||
AddPalette(pal);
|
||||
|
||||
@@ -31,30 +23,10 @@ namespace OpenRa.Game
|
||||
AddPalette(new Palette(pal, new PaletteRemap(FileSystem.Open(remap + ".rem"))));
|
||||
}
|
||||
|
||||
void Resolve()
|
||||
{
|
||||
const string filename = "../../../palette-cache.png";
|
||||
bitmap.Save(filename);
|
||||
|
||||
using (Stream s = File.OpenRead(filename))
|
||||
paletteTexture = Texture.Create(s, device);
|
||||
}
|
||||
|
||||
public Texture PaletteTexture
|
||||
{
|
||||
get
|
||||
{
|
||||
if (paletteTexture == null)
|
||||
Resolve();
|
||||
|
||||
return paletteTexture;
|
||||
}
|
||||
}
|
||||
|
||||
int AddPalette(Palette p)
|
||||
{
|
||||
for (int i = 0; i < 256; i++)
|
||||
bitmap.SetPixel(i, allocated, p.GetColor(i));
|
||||
this[new Point(i, allocated)] = p.GetColor(i);
|
||||
|
||||
return allocated++;
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace OpenRa.Game
|
||||
|
||||
bool windowed = !settings.GetValue("fullscreeen", false);
|
||||
renderer = new Renderer(this, GetResolution(settings), windowed);
|
||||
SheetBuilder.Initialize( renderer.Device );
|
||||
SheetBuilder.Initialize( renderer );
|
||||
|
||||
game = new Game( settings.GetValue( "map", "scm12ea.ini" ), renderer, new int2( ClientSize ) );
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace OpenRa.Game
|
||||
|
||||
sidebar = new Sidebar(Race.Soviet, renderer, game.viewport);
|
||||
|
||||
renderer.SetPalette( new HardwarePalette( renderer.Device, game.map ) );
|
||||
renderer.SetPalette( new HardwarePalette( renderer, game.map ) );
|
||||
}
|
||||
|
||||
internal void Run()
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
<Compile Include="Animation.cs" />
|
||||
<Compile Include="Building.cs" />
|
||||
<Compile Include="Game.cs" />
|
||||
<Compile Include="Sheet.cs" />
|
||||
<Compile Include="Harvester.cs" />
|
||||
<Compile Include="Log.cs" />
|
||||
<Compile Include="Network\Network.cs" />
|
||||
@@ -65,7 +66,6 @@
|
||||
<Compile Include="Refinery.cs" />
|
||||
<Compile Include="Renderer.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
<Compile Include="Sheet.cs" />
|
||||
<Compile Include="Sidebar.cs" />
|
||||
<Compile Include="Sprite.cs" />
|
||||
<Compile Include="SpriteRenderer.cs" />
|
||||
|
||||
@@ -46,9 +46,6 @@ namespace OpenRa.Game
|
||||
queue.Add( new PathDistance( estimator( startLocation - offset ), startLocation ) );
|
||||
cellInfo[ startLocation.X, startLocation.Y ].MinCost = 0;
|
||||
|
||||
int seenCount = 0;
|
||||
int impassableCount = 0;
|
||||
|
||||
while( !queue.Empty )
|
||||
{
|
||||
PathDistance p = queue.Pop();
|
||||
@@ -63,15 +60,9 @@ namespace OpenRa.Game
|
||||
int2 newHere = here + d;
|
||||
|
||||
if( cellInfo[ newHere.X, newHere.Y ].Seen )
|
||||
{
|
||||
++seenCount;
|
||||
continue;
|
||||
}
|
||||
if( passableCost[ newHere.X, newHere.Y ] == double.PositiveInfinity )
|
||||
{
|
||||
++impassableCount;
|
||||
continue;
|
||||
}
|
||||
|
||||
double cellCost = ( ( d.X * d.Y != 0 ) ? 1.414213563 : 1.0 ) * passableCost[ newHere.X, newHere.Y ];
|
||||
double newCost = cellInfo[ here.X, here.Y ].MinCost + cellCost;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace OpenRa.Game
|
||||
|
||||
public void SetPalette(HardwarePalette hp)
|
||||
{
|
||||
shader.SetTexture(paletteHandle, hp.PaletteTexture);
|
||||
shader.SetTexture(paletteHandle, hp.Texture);
|
||||
}
|
||||
|
||||
public Renderer(Control host, Size resolution, bool windowed)
|
||||
|
||||
@@ -1,28 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Drawing;
|
||||
using BluntDirectX.Direct3D;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Drawing.Imaging;
|
||||
|
||||
namespace OpenRa.Game
|
||||
{
|
||||
class Sheet
|
||||
{
|
||||
public readonly Bitmap bitmap;
|
||||
|
||||
readonly GraphicsDevice device;
|
||||
readonly Renderer renderer;
|
||||
protected readonly Bitmap bitmap;
|
||||
|
||||
Texture texture;
|
||||
static int suffix = 0;
|
||||
|
||||
string filename = string.Format("../../../block-cache-{0}.png", suffix++);
|
||||
|
||||
public Size Size { get { return bitmap.Size; } }
|
||||
|
||||
public Sheet(Size size, GraphicsDevice d)
|
||||
public Sheet(Renderer renderer, Size size)
|
||||
{
|
||||
bitmap = new Bitmap(size.Width, size.Height);
|
||||
device = d;
|
||||
this.renderer = renderer;
|
||||
this.bitmap = new Bitmap(size.Width, size.Height);
|
||||
}
|
||||
|
||||
void Resolve()
|
||||
{
|
||||
string filename = string.Format("../../../sheet-{0}.png", suffix++);
|
||||
bitmap.Save(filename);
|
||||
|
||||
using (Stream s = File.OpenRead(filename))
|
||||
texture = Texture.Create(s, renderer.Device);
|
||||
}
|
||||
|
||||
public Texture Texture
|
||||
@@ -30,20 +35,18 @@ namespace OpenRa.Game
|
||||
get
|
||||
{
|
||||
if (texture == null)
|
||||
LoadTexture();
|
||||
Resolve();
|
||||
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
|
||||
void LoadTexture()
|
||||
public Size Size { get { return bitmap.Size; } }
|
||||
|
||||
public Color this[Point p]
|
||||
{
|
||||
bitmap.Save(filename);
|
||||
|
||||
using( Stream s = File.OpenRead(filename) )
|
||||
texture = Texture.Create(s, device);
|
||||
get { return bitmap.GetPixel(p.X, p.Y); }
|
||||
set { bitmap.SetPixel(p.X, p.Y, value); }
|
||||
}
|
||||
|
||||
static int suffix = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,9 +9,9 @@ namespace OpenRa.Game
|
||||
{
|
||||
static class SheetBuilder
|
||||
{
|
||||
public static void Initialize(GraphicsDevice d)
|
||||
public static void Initialize(Renderer r)
|
||||
{
|
||||
device = d;
|
||||
renderer = r;
|
||||
}
|
||||
|
||||
public static Sprite Add(byte[] src, Size size)
|
||||
@@ -30,12 +30,9 @@ namespace OpenRa.Game
|
||||
return Add(data, size);
|
||||
}
|
||||
|
||||
static Sheet NewSheet()
|
||||
{
|
||||
return new Sheet(new Size(512, 512), device);
|
||||
}
|
||||
static Sheet NewSheet() { return new Sheet(renderer, new Size(512, 512)); }
|
||||
|
||||
static GraphicsDevice device;
|
||||
static Renderer renderer;
|
||||
static Sheet current = null;
|
||||
static int rowHeight = 0;
|
||||
static Point p;
|
||||
|
||||
@@ -114,16 +114,6 @@ namespace OpenRa.Game
|
||||
return true;
|
||||
}
|
||||
|
||||
public virtual IOrder Order( int2 xy )
|
||||
{
|
||||
return new MoveOrder( this, xy );
|
||||
}
|
||||
|
||||
public int2 Location
|
||||
{
|
||||
get { return toCell; }
|
||||
}
|
||||
|
||||
public override float2 RenderLocation
|
||||
{
|
||||
get
|
||||
@@ -135,9 +125,8 @@ namespace OpenRa.Game
|
||||
}
|
||||
}
|
||||
|
||||
public override Sprite[] CurrentImages
|
||||
{
|
||||
get { return animation.Images; }
|
||||
}
|
||||
public int2 Location { get { return toCell; } }
|
||||
public virtual IOrder Order(int2 xy) { return new MoveOrder(this, xy); }
|
||||
public override Sprite[] CurrentImages { get { return animation.Images; } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -91,8 +91,7 @@ namespace OpenRa.Game
|
||||
{
|
||||
Point p = new Point(dest.bounds.Left + i, dest.bounds.Top + j);
|
||||
byte b = src[i + dest.bounds.Width * j];
|
||||
Color original = dest.sheet.bitmap.GetPixel(p.X, p.Y);
|
||||
dest.sheet.bitmap.SetPixel(p.X, p.Y, ReplaceChannel(original, dest.channel, b));
|
||||
dest.sheet[p] = ReplaceChannel(dest.sheet[p], dest.channel, b);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user