Merge branch 'master' of git://github.com/beedee/OpenRA

This commit is contained in:
Chris Forbes
2009-10-15 07:27:29 +13:00
14 changed files with 37 additions and 22 deletions

View File

@@ -23,7 +23,7 @@ namespace OpenRa.Game
{
unitInfo = Rules.UnitInfo[ name ];
Location = location;
CenterLocation = new float2( 12, 12 ) + 24 * (float2)Location;
CenterLocation = new float2( 12, 12 ) + Game.CellSize * (float2)Location;
Owner = owner;
switch( name )

View File

@@ -42,9 +42,9 @@ namespace OpenRa.Game
if (!(orderGenerator is PlaceBuilding))
{
if (dragStart != xy)
orderGenerator = new UnitOrderGenerator( game.FindUnits( 24 * dragStart, 24 * xy ) ); /* band-box select */
orderGenerator = new UnitOrderGenerator( game.FindUnits( Game.CellSize * dragStart, Game.CellSize * xy ) ); /* band-box select */
else
orderGenerator = new UnitOrderGenerator( game.FindUnits( 24 * xy, 24 * xy ) ); /* click select */
orderGenerator = new UnitOrderGenerator( game.FindUnits( Game.CellSize * xy, Game.CellSize * xy ) ); /* click select */
}
dragStart = dragEnd;
@@ -67,7 +67,7 @@ namespace OpenRa.Game
get
{
if (dragStart == dragEnd) return null;
return Pair.New(24 * dragStart, 24 * dragEnd);
return Pair.New(Game.CellSize * dragStart, Game.CellSize * dragEnd);
}
}
}

View File

@@ -10,7 +10,9 @@ using IjwFramework.Collections;
namespace OpenRa.Game
{
class Game
{
{
public static readonly int CellSize = 24;
public readonly World world;
public readonly Map map;
readonly TreeCache treeCache;

View File

@@ -41,13 +41,18 @@ namespace OpenRa.Game.GameRules
var footprint = Rules.Footprint.GetFootprint(name);
var j = 0;
int maxWidth = 0;
foreach (var row in footprint)
if (row.Length > maxWidth)
maxWidth = row.Length;
foreach (var row in footprint)
{
var i = 0;
foreach (var c in row)
{
if (c != '_')
yield return position + new int2(i, j);
yield return position + new int2(i, j) - new int2(maxWidth / 2, footprint.Length / 2);
++i;
}
++j;

View File

@@ -74,7 +74,7 @@ namespace OpenRa.Game.Graphics
spriteIndex = 11;
else if( overlayIsGems[ map.MapTiles[ x, y ].overlay ] )
spriteIndex = 2;
spriteRenderer.DrawSprite( sprites[ spriteIndex ], 24 * (float2)( location - map.Offset ), 0 );
spriteRenderer.DrawSprite( sprites[ spriteIndex ], Game.CellSize * (float2)( location - map.Offset ), 0 );
}
}
}

View File

@@ -30,7 +30,7 @@ namespace OpenRa.Game.Graphics
tileSet = new TileSet( map.TileSuffix );
Size tileSize = new Size( 24, 24 );
Size tileSize = new Size( Game.CellSize, Game.CellSize );
var tileMapping = new Cache<TileReference, Sprite>(
x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize));
@@ -44,7 +44,7 @@ namespace OpenRa.Game.Graphics
for (int i = 0; i < map.Width; i++)
{
Sprite tile = tileMapping[map.MapTiles[i + map.XOffset, j + map.YOffset]];
Util.FastCreateQuad(vertices, indices, 24 * new float2(i, j), tile, 0, nv, ni);
Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni);
nv += 4;
ni += 6;
}

View File

@@ -25,7 +25,7 @@ namespace OpenRa.Game.Graphics
public Viewport(float2 size, float2 mapSize, Renderer renderer)
{
this.size = size;
this.mapSize = 24 * mapSize - size + new float2(128, 0);
this.mapSize = Game.CellSize * mapSize - size + new float2(128, 0);
this.renderer = renderer;
}

View File

@@ -214,7 +214,15 @@ namespace OpenRa.Game
game.world.AddFrameEndTask(_ =>
{
Log.Write("Player \"{0}\" builds {1}", building.Owner.PlayerName, building.Name);
game.world.Add(new Actor(building.Name, xy, building.Owner));
//Adjust placement for cursor to be in middle
var footprint = Rules.Footprint.GetFootprint(building.Name);
int maxWidth = 0;
foreach (var row in footprint)
if (row.Length > maxWidth)
maxWidth = row.Length;
game.world.Add(new Actor(building.Name, xy - new int2(maxWidth / 2, footprint.Length / 2), building.Owner));
game.controller.orderGenerator = null;
game.worldRenderer.uiOverlay.KillOverlay();

View File

@@ -17,7 +17,7 @@ namespace OpenRa.Game.Traits
if (first && self.Owner == game.LocalPlayer)
{
self.Owner.TechTree.Build(self.unitInfo.Name, true);
self.CenterLocation = 24 * (float2)self.Location + 0.5f * self.SelectedSize;
self.CenterLocation = Game.CellSize * (float2)self.Location + 0.5f * self.SelectedSize;
}
first = false;
}

View File

@@ -59,7 +59,7 @@ namespace OpenRa.Game.Traits
void UpdateCenterLocation()
{
float fraction = (moveFraction > 0) ? (float)moveFraction / moveFractionTotal : 0f;
self.CenterLocation = new float2(12, 12) + 24 * float2.Lerp(fromCell, toCell, fraction);
self.CenterLocation = new float2(12, 12) + Game.CellSize * float2.Lerp(fromCell, toCell, fraction);
}
public void Tick(Actor self, Game game, int dt)

View File

@@ -25,7 +25,7 @@ namespace OpenRa.Game.Traits
{
var mobile = self.traits.Get<Mobile>();
float fraction = (mobile.moveFraction > 0) ? (float)mobile.moveFraction / mobile.moveFractionTotal : 0f;
var centerLocation = new float2(12, 12) + 24 * float2.Lerp(mobile.fromCell, mobile.toCell, fraction);
var centerLocation = new float2(12, 12) + Game.CellSize * float2.Lerp(mobile.fromCell, mobile.toCell, fraction);
yield return Centered(anim.Image, centerLocation);
}
}

View File

@@ -18,7 +18,7 @@ namespace OpenRa.Game.Traits
public IEnumerable<Pair<Sprite, float2>> Render(Actor self)
{
yield return Pair.New(Image, 24 * (float2)self.Location);
yield return Pair.New(Image, Game.CellSize * (float2)self.Location);
}
}
}

View File

@@ -7,7 +7,7 @@ namespace OpenRa.Game.Traits
{
class Turreted : ITick // temporary.
{
public int turretFacing = 24;
public int turretFacing = Game.CellSize;
public Turreted(Actor self)
{

View File

@@ -23,13 +23,13 @@ namespace OpenRa.Game
static Sprite SynthesizeTile(byte paletteIndex)
{
byte[] data = new byte[24 * 24];
byte[] data = new byte[Game.CellSize * Game.CellSize];
for (int i = 0; i < 24; i++)
for (int j = 0; j < 24; j++)
data[i * 24 + j] = ((i + j) % 4 < 2) ? (byte)0 : paletteIndex;
for (int i = 0; i < Game.CellSize; i++)
for (int j = 0; j < Game.CellSize; j++)
data[i * Game.CellSize + j] = ((i + j) % 4 < 2) ? (byte)0 : paletteIndex;
return SheetBuilder.Add( data, new Size(24,24) );
return SheetBuilder.Add( data, new Size(Game.CellSize,Game.CellSize) );
}
public void Draw()
@@ -38,7 +38,7 @@ namespace OpenRa.Game
return;
foreach (var t in Footprint.Tiles(name,position))
spriteRenderer.DrawSprite(game.IsCellBuildable(t) ? buildOk : buildBlocked, 24 * t, 0);
spriteRenderer.DrawSprite(game.IsCellBuildable(t) ? buildOk : buildBlocked, Game.CellSize * t, 0);
spriteRenderer.Flush();
}