[Fixing indentation]

This commit is contained in:
Bob
2009-11-19 15:02:04 +13:00
parent e427e6b16e
commit a17296ff8a
13 changed files with 244 additions and 249 deletions

View File

@@ -118,7 +118,7 @@ namespace OpenRa.FileFormats
for( int i = 0 ; i < 128 ; i++ )
for( int j = 0 ; j < 128 ; j++ )
{
MapTiles[j, i].image = (byte)ms.ReadByte();
MapTiles[j, i].image = (byte)ms.ReadByte();
if( MapTiles[ j, i ].tile == 0xff || MapTiles[ j, i ].tile == 0xffff )
MapTiles[ j, i ].image = (byte)( i % 4 + ( j % 4 ) * 4 );
}

View File

@@ -17,14 +17,14 @@ namespace OpenRa.FileFormats
readonly Dictionary<uint, PackageEntry> index;
readonly bool isRmix, isEncrypted;
readonly long dataStart;
readonly Stream s;
readonly Stream s;
public Package(string filename)
{
this.filename = filename;
s = FileSystem.Open(filename);
s = FileSystem.Open(filename);
BinaryReader reader = new BinaryReader(s);
BinaryReader reader = new BinaryReader(s);
uint signature = reader.ReadUInt32();
isRmix = 0 == (signature & ~(uint)(MixFileFlags.Checksum | MixFileFlags.Encrypted));
@@ -50,7 +50,7 @@ namespace OpenRa.FileFormats
{
BinaryReader reader = new BinaryReader(s);
byte[] keyblock = reader.ReadBytes(80);
byte[] blowfishKey = new BlowfishKeyProvider().DecryptKey(keyblock);
byte[] blowfishKey = new BlowfishKeyProvider().DecryptKey(keyblock);
uint[] h = ReadUints(reader, 2);
@@ -117,9 +117,9 @@ namespace OpenRa.FileFormats
public Stream GetContent(uint hash)
{
PackageEntry e;
if (!index.TryGetValue(hash, out e))
return null;
PackageEntry e;
if (!index.TryGetValue(hash, out e))
return null;
s.Seek( dataStart + e.Offset, SeekOrigin.Begin );
byte[] data = new byte[ e.Length ];

View File

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

View File

@@ -109,7 +109,7 @@ namespace OpenRa.FileFormats
}
h.Image = CopyImageData( h.RefImage.Image );
Format40.DecodeInto(ReadCompressedData(stream, h), h.Image);
Format40.DecodeInto(ReadCompressedData(stream, h), h.Image);
break;
}
case Format.Format80:

View File

@@ -1,49 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
using IjwFramework.Types;
using OpenRa.Game.Graphics;
namespace OpenRa.Game
{
interface IEffect
{
void Tick();
IEnumerable<Tuple<Sprite, float2, int>> Render();
Player Owner { get; }
}
class Bullet : IEffect
{
public Player Owner { get; private set; }
readonly Actor FiredBy;
readonly WeaponInfo Weapon;
readonly ProjectileInfo Projectile;
readonly WarheadInfo Warhead;
readonly int2 Src;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OpenRa.Game.GameRules;
using IjwFramework.Types;
using OpenRa.Game.Graphics;
namespace OpenRa.Game
{
interface IEffect
{
void Tick();
IEnumerable<Tuple<Sprite, float2, int>> Render();
Player Owner { get; }
}
class Bullet : IEffect
{
public Player Owner { get; private set; }
readonly Actor FiredBy;
readonly WeaponInfo Weapon;
readonly ProjectileInfo Projectile;
readonly WarheadInfo Warhead;
readonly int2 Src;
readonly int2 Dest;
readonly int2 VisualDest;
int t = 0;
Animation anim;
const int BaseBulletSpeed = 100; /* pixels / 40ms frame */
/* src, dest are *pixel* coords */
public Bullet(string weapon, Player owner, Actor firedBy,
int2 src, int2 dest)
{
Owner = owner;
FiredBy = firedBy;
Src = src;
readonly int2 VisualDest;
int t = 0;
Animation anim;
const int BaseBulletSpeed = 100; /* pixels / 40ms frame */
/* src, dest are *pixel* coords */
public Bullet(string weapon, Player owner, Actor firedBy,
int2 src, int2 dest)
{
Owner = owner;
FiredBy = firedBy;
Src = src;
Dest = dest;
VisualDest = Dest + new int2(
Game.CosmeticRandom.Next(-10, 10),
Game.CosmeticRandom.Next(-10, 10));
Weapon = Rules.WeaponInfo[weapon];
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
Game.CosmeticRandom.Next(-10, 10));
Weapon = Rules.WeaponInfo[weapon];
Projectile = Rules.ProjectileInfo[Weapon.Projectile];
Warhead = Rules.WarheadInfo[Weapon.Warhead];
if (Projectile.Image != null && Projectile.Image != "none")
@@ -56,19 +56,19 @@ namespace OpenRa.Game
anim.CurrentSequence.Length));
else
anim.PlayRepeating("idle");
}
}
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
public void Tick()
{
if (t == 0)
Game.PlaySound(Weapon.Report + ".aud", false);
t += 40;
if (t > TotalTime()) /* remove finished bullets */
}
}
int TotalTime() { return (Dest - Src).Length * BaseBulletSpeed / Weapon.Speed; }
public void Tick()
{
if (t == 0)
Game.PlaySound(Weapon.Report + ".aud", false);
t += 40;
if (t > TotalTime()) /* remove finished bullets */
{
Game.world.AddFrameEndTask(w =>
{
@@ -86,19 +86,19 @@ namespace OpenRa.Game
if (impact != null)
Game.PlaySound(impact+ ".aud", false);
});
var maxSpread = GetMaximumSpread();
var hitActors = Game.FindUnitsInCircle(Dest, GetMaximumSpread());
foreach (var victim in hitActors)
victim.InflictDamage(FiredBy, this, (int)GetDamageToInflict(victim));
}
});
var maxSpread = GetMaximumSpread();
var hitActors = Game.FindUnitsInCircle(Dest, GetMaximumSpread());
foreach (var victim in hitActors)
victim.InflictDamage(FiredBy, this, (int)GetDamageToInflict(victim));
}
}
const float height = .1f;
public IEnumerable<Tuple<Sprite, float2, int>> Render()
const float height = .1f;
public IEnumerable<Tuple<Sprite, float2, int>> Render()
{
if (anim != null)
{
@@ -119,25 +119,25 @@ namespace OpenRa.Game
}
else
yield return Tuple.New(anim.Image, pos, Owner.Palette);
}
}
float GetMaximumSpread()
{
return (int)(Warhead.Spread * Math.Log(Weapon.Damage, 2));
}
float GetDamageToInflict(Actor target)
}
}
float GetMaximumSpread()
{
return (int)(Warhead.Spread * Math.Log(Weapon.Damage, 2));
}
float GetDamageToInflict(Actor target)
{
if( target.unitInfo == null ) // tree or other doodad
return 0;
/* todo: some things can't be damaged AT ALL by certain weapons! */
var distance = (target.CenterLocation - Dest).Length;
var rawDamage = Weapon.Damage * (float)Math.Exp(-distance / Warhead.Spread);
var multiplier = Warhead.EffectivenessAgainst(target.unitInfo.Armor);
return rawDamage * multiplier;
}
}
}
return 0;
/* todo: some things can't be damaged AT ALL by certain weapons! */
var distance = (target.CenterLocation - Dest).Length;
var rawDamage = Weapon.Damage * (float)Math.Exp(-distance / Warhead.Spread);
var multiplier = Warhead.EffectivenessAgainst(target.unitInfo.Armor);
return rawDamage * multiplier;
}
}
}

View File

@@ -8,59 +8,59 @@ using System.Drawing;
namespace OpenRa.Game.Graphics
{
class LineRenderer
{
Renderer renderer;
FvfVertexBuffer<Vertex> vertexBuffer;
IndexBuffer indexBuffer; /* kindof a waste of space, but the GPU likes indexing, oh well */
class LineRenderer
{
Renderer renderer;
FvfVertexBuffer<Vertex> vertexBuffer;
IndexBuffer indexBuffer; /* kindof a waste of space, but the GPU likes indexing, oh well */
const int linesPerBatch = 1024;
const int linesPerBatch = 1024;
Vertex[] vertices = new Vertex[2 * linesPerBatch];
ushort[] indices = new ushort[2 * linesPerBatch];
int lines = 0;
int nv = 0, ni = 0;
Vertex[] vertices = new Vertex[ 2 * linesPerBatch ];
ushort[] indices = new ushort[ 2 * linesPerBatch ];
int lines = 0;
int nv = 0, ni = 0;
public LineRenderer(Renderer renderer)
{
this.renderer = renderer;
vertexBuffer = new FvfVertexBuffer<Vertex>(renderer.Device, vertices.Length, Vertex.Format);
indexBuffer = new IndexBuffer(renderer.Device, indices.Length);
}
public LineRenderer( Renderer renderer )
{
this.renderer = renderer;
vertexBuffer = new FvfVertexBuffer<Vertex>( renderer.Device, vertices.Length, Vertex.Format );
indexBuffer = new IndexBuffer( renderer.Device, indices.Length );
}
public void Flush()
{
if (lines > 0)
{
renderer.LineShader.Render(() =>
{
vertexBuffer.SetData(vertices);
indexBuffer.SetData(indices);
renderer.DrawBatch(vertexBuffer, indexBuffer,
nv, ni / 2, null, PrimitiveType.LineList);
});
public void Flush()
{
if( lines > 0 )
{
renderer.LineShader.Render( () =>
{
vertexBuffer.SetData( vertices );
indexBuffer.SetData( indices );
renderer.DrawBatch( vertexBuffer, indexBuffer,
nv, ni / 2, null, PrimitiveType.LineList );
} );
nv = 0; ni = 0;
lines = 0;
}
}
nv = 0; ni = 0;
lines = 0;
}
}
public void DrawLine(float2 start, float2 end, Color startColor, Color endColor)
{
indices[ni++] = (ushort)nv;
vertices[nv++] = new Vertex(start,
new float2(startColor.R / 255.0f, startColor.G / 255.0f),
new float2(startColor.B / 255.0f, startColor.A / 255.0f));
public void DrawLine( float2 start, float2 end, Color startColor, Color endColor )
{
indices[ ni++ ] = (ushort)nv;
indices[ni++] = (ushort)nv;
vertices[ nv++ ] = new Vertex( start,
new float2( startColor.R / 255.0f, startColor.G / 255.0f ),
new float2( startColor.B / 255.0f, startColor.A / 255.0f ) );
vertices[nv++] = new Vertex(end,
new float2(endColor.R / 255.0f, endColor.G / 255.0f),
new float2(endColor.B / 255.0f, endColor.A / 255.0f));
indices[ ni++ ] = (ushort)nv;
if (++lines >= linesPerBatch)
Flush();
}
}
vertices[ nv++ ] = new Vertex( end,
new float2( endColor.R / 255.0f, endColor.G / 255.0f ),
new float2( endColor.B / 255.0f, endColor.A / 255.0f ) );
if( ++lines >= linesPerBatch )
Flush();
}
}
}

View File

@@ -70,14 +70,14 @@ namespace OpenRa.Game.Graphics
Range<int> vertexRange, Range<int> indexRange, Texture texture, PrimitiveType type, Shader shader)
where T : struct
{
shader.SetValue("DiffuseTexture", texture);
shader.SetValue( "DiffuseTexture", texture );
shader.Commit();
vertices.Bind(0);
vertices.Bind( 0 );
indices.Bind();
device.DrawIndexedPrimitives(type,
vertexRange, indexRange);
device.DrawIndexedPrimitives( type,
vertexRange, indexRange );
}
public void DrawBatch<T>(FvfVertexBuffer<T> vertices, IndexBuffer indices,

View File

@@ -13,7 +13,7 @@ namespace OpenRa.Game.Graphics
public readonly RectangleF uv;
public readonly float2 size;
readonly float2[] uvhax;
readonly float2[] uvhax;
internal Sprite(Sheet sheet, Rectangle bounds, TextureChannel channel)
{
@@ -27,22 +27,22 @@ namespace OpenRa.Game.Graphics
(float)(bounds.Width) / sheet.Size.Width,
(float)(bounds.Height) / sheet.Size.Height);
uvhax = new float2[]
{
new float2( uv.Left, uv.Top ),
new float2( uv.Right, uv.Top ),
new float2( uv.Left, uv.Bottom ),
new float2( uv.Right, uv.Bottom ),
};
uvhax = new float2[]
{
new float2( uv.Left, uv.Top ),
new float2( uv.Right, uv.Top ),
new float2( uv.Left, uv.Bottom ),
new float2( uv.Right, uv.Bottom ),
};
this.size = new float2(bounds.Size);
}
public float2 FastMapTextureCoords(int k)
{
return uvhax[k];
}
}
public float2 FastMapTextureCoords( int k )
{
return uvhax[ k ];
}
}
public enum TextureChannel
{

View File

@@ -16,12 +16,12 @@ namespace OpenRa.Game.Graphics
const int spritesPerBatch = 1024;
Vertex[] vertices = new Vertex[4 * spritesPerBatch];
ushort[] indices = new ushort[6 * spritesPerBatch];
Vertex[] vertices = new Vertex[4 * spritesPerBatch];
ushort[] indices = new ushort[6 * spritesPerBatch];
Sheet currentSheet = null;
int sprites = 0;
ShaderQuality quality;
int nv = 0, ni = 0;
int nv = 0, ni = 0;
public SpriteRenderer(Renderer renderer, bool allowAlpha, Shader shader)
{
@@ -41,19 +41,19 @@ namespace OpenRa.Game.Graphics
{
if (sprites > 0)
{
shader.Quality = quality;
shader.Render(() =>
{
vertexBuffer.SetData(vertices);
indexBuffer.SetData(indices);
renderer.DrawBatch(vertexBuffer, indexBuffer,
new Range<int>(0, nv),
new Range<int>(0, ni),
currentSheet.Texture, PrimitiveType.TriangleList,
shader);
});
shader.Quality = quality;
shader.Render(() =>
{
vertexBuffer.SetData(vertices);
indexBuffer.SetData(indices);
renderer.DrawBatch(vertexBuffer, indexBuffer,
new Range<int>(0, nv),
new Range<int>(0, ni),
currentSheet.Texture, PrimitiveType.TriangleList,
shader);
});
nv = 0; ni = 0;
nv = 0; ni = 0;
currentSheet = null;
sprites = 0;
}
@@ -66,7 +66,7 @@ namespace OpenRa.Game.Graphics
currentSheet = s.sheet;
Util.FastCreateQuad(vertices, indices, location, s, palette, nv, ni);
nv += 4; ni += 6;
nv += 4; ni += 6;
if (++sprites >= spritesPerBatch)
Flush();
}

View File

@@ -25,28 +25,28 @@ namespace OpenRa.Game.Graphics
tileSet = new TileSet( map.TileSuffix );
Size tileSize = new Size( Game.CellSize, Game.CellSize );
Size tileSize = new Size( Game.CellSize, Game.CellSize );
SheetBuilder.ForceNewSheet();
var tileMapping = new Cache<TileReference, Sprite>(
x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize));
var tileMapping = new Cache<TileReference, Sprite>(
x => SheetBuilder.Add(tileSet.GetBytes(x), tileSize));
Vertex[] vertices = new Vertex[4 * map.Height * map.Width];
ushort[] indices = new ushort[6 * map.Height * map.Width];
Vertex[] vertices = new Vertex[4 * map.Height * map.Width];
ushort[] indices = new ushort[6 * map.Height * map.Width];
int nv = 0;
int ni = 0;
int nv = 0;
int ni = 0;
for( int j = map.YOffset ; j < map.YOffset + map.Height ; j++ )
for( int i = map.XOffset ; i < map.XOffset + map.Width; i++ )
{
Sprite tile = tileMapping[map.MapTiles[i, j]];
Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni);
nv += 4;
ni += 6;
}
for( int i = map.XOffset ; i < map.XOffset + map.Width; i++ )
{
Sprite tile = tileMapping[map.MapTiles[i, j]];
Util.FastCreateQuad(vertices, indices, Game.CellSize * new float2(i, j), tile, 0, nv, ni);
nv += 4;
ni += 6;
}
terrainSheet = tileMapping[map.MapTiles[map.XOffset, map.YOffset]].sheet;
terrainSheet = tileMapping[map.MapTiles[map.XOffset, map.YOffset]].sheet;
vertexBuffer = new FvfVertexBuffer<Vertex>( renderer.Device, vertices.Length, Vertex.Format );
vertexBuffer.SetData( vertices );
@@ -71,12 +71,12 @@ namespace OpenRa.Game.Graphics
if (firstRow < 0) firstRow = 0;
if (lastRow > map.Height) lastRow = map.Height;
renderer.SpriteShader.Quality = ShaderQuality.Low;
renderer.SpriteShader.Render(() =>
renderer.DrawBatch(vertexBuffer, indexBuffer,
new Range<int>(verticesPerRow * firstRow, verticesPerRow * lastRow),
new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow),
terrainSheet.Texture, PrimitiveType.TriangleList, renderer.SpriteShader));
renderer.SpriteShader.Quality = ShaderQuality.Low;
renderer.SpriteShader.Render(() =>
renderer.DrawBatch(vertexBuffer, indexBuffer,
new Range<int>(verticesPerRow * firstRow, verticesPerRow * lastRow),
new Range<int>(indicesPerRow * firstRow, indicesPerRow * lastRow),
terrainSheet.Texture, PrimitiveType.TriangleList, renderer.SpriteShader));
overlayRenderer.Draw();
}

View File

@@ -63,22 +63,22 @@ namespace OpenRa.Game.Graphics
cursorFrame += 0.5f;
}
IHandleInput dragRegion = null;
public void DispatchMouseInput(MouseInput mi)
{
IHandleInput dragRegion = null;
public void DispatchMouseInput(MouseInput mi)
{
if (mi.Event == MouseInputEvent.Move)
mousePos = mi.Location;
if (dragRegion != null) {
dragRegion.HandleInput( mi );
if (mi.Event == MouseInputEvent.Up) dragRegion = null;
return;
}
if (dragRegion != null) {
dragRegion.HandleInput( mi );
if (mi.Event == MouseInputEvent.Up) dragRegion = null;
return;
}
dragRegion = regions.FirstOrDefault(r => r.HandleInput(mi));
if (mi.Event != MouseInputEvent.Down)
dragRegion = null;
}
dragRegion = regions.FirstOrDefault(r => r.HandleInput(mi));
if (mi.Event != MouseInputEvent.Down)
dragRegion = null;
}
public float2 ViewToWorld(MouseInput mi)
{

View File

@@ -23,11 +23,6 @@ namespace OpenRa.Game.Graphics
{
terrainRenderer = new TerrainRenderer(renderer, Game.map);
// TODO: this is layout policy. it belongs at a higher level than this.
//region = Region.Create(Game.viewport, DockStyle.Left,
// Game.viewport.Width, Draw, Game.controller.HandleInput);
//Game.viewport.AddRegion(Game.controller);
this.renderer = renderer;
spriteRenderer = new SpriteRenderer(renderer, true);
lineRenderer = new LineRenderer(renderer);

View File

@@ -85,18 +85,18 @@ namespace OpenRa.Game
int2 lastPos;
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
lastPos = new int2(e.Location);
protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
lastPos = new int2(e.Location);
Game.viewport.DispatchMouseInput(new MouseInput
{
Button = e.Button,
Event = MouseInputEvent.Down,
Location = new int2(e.Location)
});
}
Game.viewport.DispatchMouseInput(new MouseInput
{
Button = e.Button,
Event = MouseInputEvent.Down,
Location = new int2(e.Location)
});
}
protected override void OnMouseMove(MouseEventArgs e)
{
@@ -109,25 +109,25 @@ namespace OpenRa.Game
lastPos = p;
}
Game.viewport.DispatchMouseInput(new MouseInput
{
Button = e.Button,
Event = MouseInputEvent.Move,
Location = new int2(e.Location)
});
Game.viewport.DispatchMouseInput(new MouseInput
{
Button = e.Button,
Event = MouseInputEvent.Move,
Location = new int2(e.Location)
});
}
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
protected override void OnMouseUp(MouseEventArgs e)
{
base.OnMouseUp(e);
Game.viewport.DispatchMouseInput(new MouseInput
{
Button = e.Button,
Event = MouseInputEvent.Up,
Location = new int2(e.Location)
});
}
Game.viewport.DispatchMouseInput(new MouseInput
{
Button = e.Button,
Event = MouseInputEvent.Up,
Location = new int2(e.Location)
});
}
protected override void OnKeyPress(KeyPressEventArgs e)
{
@@ -140,12 +140,12 @@ namespace OpenRa.Game
}
}
struct MouseInput
{
public MouseInputEvent Event;
public int2 Location;
public MouseButtons Button;
}
struct MouseInput
{
public MouseInputEvent Event;
public int2 Location;
public MouseButtons Button;
}
enum MouseInputEvent { Down, Move, Up };
enum MouseInputEvent { Down, Move, Up };
}