Merge pull request #3886 from pchote/ppos-cleanup

Remove legacy PPos type.
This commit is contained in:
Matthias Mailänder
2013-09-29 02:13:23 -07:00
29 changed files with 199 additions and 388 deletions

View File

@@ -32,7 +32,6 @@ namespace OpenRA
public IOccupySpace OccupiesSpace { get { return occupySpace.Value; } }
public CPos Location { get { return occupySpace.Value.TopLeft; } }
public PPos CenterLocation { get { return PPos.FromWPos(occupySpace.Value.CenterPosition); } }
public WPos CenterPosition { get { return occupySpace.Value.CenterPosition; } }
public WRot Orientation

View File

@@ -80,12 +80,12 @@ namespace OpenRA
public SubCell Value(World world) { return (SubCell)value; }
}
public class CenterLocationInit : IActorInit<PPos>
public class CenterPositionInit : IActorInit<WPos>
{
[FieldFromYamlKey] public readonly int2 value = int2.Zero;
public CenterLocationInit() { }
public CenterLocationInit(PPos init) { value = init.ToInt2(); }
public PPos Value(World world) { return (PPos)value; }
[FieldFromYamlKey] public readonly WPos value = WPos.Zero;
public CenterPositionInit() { }
public CenterPositionInit(WPos init) { value = init; }
public WPos Value(World world) { return value; }
}
public class OwnerInit : IActorInit<Player>

View File

@@ -39,7 +39,6 @@ namespace OpenRA
public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(X, Y); }
public PPos ToPPos() { return new PPos(Game.CellSize * X, Game.CellSize * Y); }
public WPos CenterPosition { get { return new WPos(1024 * X + 512, 1024 * Y + 512, 0); } }
public WPos TopLeft { get { return new WPos(1024 * X, 1024 * Y, 0); } }

View File

@@ -137,8 +137,8 @@ namespace OpenRA
using (new PerfSample("render"))
{
++RenderFrame;
viewport.DrawRegions(worldRenderer, new DefaultInputHandler( orderManager.world ));
Sound.SetListenerPosition(viewport.CenterLocation);
viewport.DrawRegions(worldRenderer, new DefaultInputHandler(orderManager.world));
Sound.SetListenerPosition(worldRenderer.Position(viewport.CenterLocation.ToInt2()));
}
PerfHistory.items["render"].Tick();

View File

@@ -93,7 +93,7 @@ namespace OpenRA.Graphics
public void BeforeRender(WorldRenderer wr) {}
public void Render(WorldRenderer wr)
{
sprite.DrawAt(ScreenPosition(wr), palette, scale);
Game.Renderer.WorldSpriteRenderer.DrawSprite(sprite, ScreenPosition(wr), palette, sprite.size*scale);
}
public void RenderDebugGeometry(WorldRenderer wr)

View File

@@ -184,24 +184,26 @@ namespace OpenRA.Graphics
if (starti != i)
{
s[starti, j].DrawAt(
// Stretch a solid black sprite over the rows above
// TODO: This doesn't make sense for isometric terrain
Game.Renderer.WorldSpriteRenderer.DrawSprite(
s[starti, j],
Game.CellSize * new float2(starti, j),
pal,
new float2(Game.CellSize * (i - starti), Game.CellSize));
starti = i + 1;
}
s[i, j].DrawAt(
Game.CellSize * new float2(i, j),
pal);
Game.Renderer.WorldSpriteRenderer.DrawSprite(s[i, j], Game.CellSize * new float2(i, j), pal);
starti = i + 1;
last = s[i, j];
}
// Stretch a solid black sprite over the rows to the left
// TODO: This doesn't make sense for isometric terrain
if (starti < clip.Right)
s[starti, j].DrawAt(
Game.CellSize * new float2(starti, j),
pal,
Game.Renderer.WorldSpriteRenderer.DrawSprite(s[starti, j],
Game.CellSize * new float2(starti, j), pal,
new float2(Game.CellSize * (clip.Right - starti), Game.CellSize));
}
}

View File

@@ -55,21 +55,6 @@ namespace OpenRA.Graphics
{
return textureCoords[k];
}
public void DrawAt(float2 location, PaletteReference pal)
{
Game.Renderer.WorldSpriteRenderer.DrawSprite(this, location, pal, size);
}
public void DrawAt(float2 location, PaletteReference pal, float scale)
{
Game.Renderer.WorldSpriteRenderer.DrawSprite(this, location, pal, size*scale);
}
public void DrawAt(float2 location, PaletteReference pal, float2 size)
{
Game.Renderer.WorldSpriteRenderer.DrawSprite(this, location, pal, size);
}
}
public enum TextureChannel

View File

@@ -149,8 +149,8 @@ namespace OpenRA.Graphics
return (CPos)( (1f / Game.CellSize) * (1f/Zoom*loc.ToFloat2() + Location) ).ToInt2();
}
public PPos ViewToWorldPx(int2 loc) { return (PPos)(1f/Zoom*loc.ToFloat2() + Location).ToInt2(); }
public PPos ViewToWorldPx(MouseInput mi) { return ViewToWorldPx(mi.Location); }
public int2 ViewToWorldPx(int2 loc) { return (1f/Zoom*loc.ToFloat2() + Location).ToInt2(); }
public int2 WorldToViewPx(int2 loc) { return (Zoom * (loc.ToFloat2() - Location)).ToInt2(); }
public void Center(float2 loc)
{
@@ -159,12 +159,10 @@ namespace OpenRA.Graphics
public void Center(IEnumerable<Actor> actors)
{
if (!actors.Any()) return;
if (!actors.Any())
return;
var avgPos = actors
.Select(a => (PVecInt)a.CenterLocation)
.Aggregate((a, b) => a + b) / actors.Count();
scrollPosition = NormalizeScrollPosition((avgPos.ToFloat2() - (1f / (2 * Zoom) * screenSize.ToFloat2())).ToInt2());
Center(actors.Select(a => a.CenterPosition).Average().ToCPos().ToFloat2());
}
// Rectangle (in viewport coords) that contains things to be drawn

View File

@@ -75,8 +75,8 @@ namespace OpenRA.Graphics
{
var comparer = new RenderableComparer(this);
var vb = Game.viewport.ViewBounds(world);
var tl = Game.viewport.ViewToWorldPx(new int2(vb.Left, vb.Top)).ToInt2();
var br = Game.viewport.ViewToWorldPx(new int2(vb.Right, vb.Bottom)).ToInt2();
var tl = Game.viewport.ViewToWorldPx(new int2(vb.Left, vb.Top));
var br = Game.viewport.ViewToWorldPx(new int2(vb.Right, vb.Bottom));
var actors = world.ScreenMap.ActorsInBox(tl, br)
.Append(world.WorldActor)
.ToList();
@@ -155,21 +155,21 @@ namespace OpenRA.Graphics
var pos = ScreenPxPosition(a.CenterPosition);
var bounds = a.Bounds.Value;
var xy = pos + new float2(bounds.Left, bounds.Top);
var Xy = pos + new float2(bounds.Right, bounds.Top);
var xY = pos + new float2(bounds.Left, bounds.Bottom);
var XY = pos + new float2(bounds.Right, bounds.Bottom);
var tl = pos + new float2(bounds.Left, bounds.Top);
var tr = pos + new float2(bounds.Right, bounds.Top);
var bl = pos + new float2(bounds.Left, bounds.Bottom);
var br = pos + new float2(bounds.Right, bounds.Bottom);
var wlr = Game.Renderer.WorldLineRenderer;
wlr.DrawLine(xy, xy + new float2(4, 0), c, c);
wlr.DrawLine(xy, xy + new float2(0, 4), c, c);
wlr.DrawLine(Xy, Xy + new float2(-4, 0), c, c);
wlr.DrawLine(Xy, Xy + new float2(0, 4), c, c);
wlr.DrawLine(tl, tl + new float2(4, 0), c, c);
wlr.DrawLine(tl, tl + new float2(0, 4), c, c);
wlr.DrawLine(tr, tr + new float2(-4, 0), c, c);
wlr.DrawLine(tr, tr + new float2(0, 4), c, c);
wlr.DrawLine(xY, xY + new float2(4, 0), c, c);
wlr.DrawLine(xY, xY + new float2(0, -4), c, c);
wlr.DrawLine(XY, XY + new float2(-4, 0), c, c);
wlr.DrawLine(XY, XY + new float2(0, -4), c, c);
wlr.DrawLine(bl, bl + new float2(4, 0), c, c);
wlr.DrawLine(bl, bl + new float2(0, -4), c, c);
wlr.DrawLine(br, br + new float2(-4, 0), c, c);
wlr.DrawLine(br, br + new float2(0, -4), c, c);
}
public void DrawRollover(Actor unit)
@@ -179,24 +179,6 @@ namespace OpenRA.Graphics
selectable.DrawRollover(this, unit);
}
public void DrawLocus(Color c, CPos[] cells)
{
var dict = cells.ToDictionary(a => a, a => 0);
var wlr = Game.Renderer.WorldLineRenderer;
foreach (var t in dict.Keys)
{
if (!dict.ContainsKey(t + new CVec(-1, 0)))
wlr.DrawLine(t.ToPPos().ToFloat2(), (t + new CVec(0, 1)).ToPPos().ToFloat2(), c, c);
if (!dict.ContainsKey(t + new CVec(1, 0)))
wlr.DrawLine((t + new CVec(1, 0)).ToPPos().ToFloat2(), (t + new CVec(1, 1)).ToPPos().ToFloat2(), c, c);
if (!dict.ContainsKey(t + new CVec(0, -1)))
wlr.DrawLine(t.ToPPos().ToFloat2(), (t + new CVec(1, 0)).ToPPos().ToFloat2(), c, c);
if (!dict.ContainsKey(t + new CVec(0, 1)))
wlr.DrawLine((t + new CVec(0, 1)).ToPPos().ToFloat2(), (t + new CVec(1, 1)).ToPPos().ToFloat2(), c, c);
}
}
public void DrawRangeCircle(Color c, float2 location, float range)
{
for (var i = 0; i < 32; i++)
@@ -210,9 +192,10 @@ namespace OpenRA.Graphics
public void DrawRangeCircleWithContrast(Color fg, float2 location, float range, Color bg, int offset)
{
if (offset > 0) {
DrawRangeCircle(bg, location, range + (float) offset/Game.CellSize);
DrawRangeCircle(bg, location, range - (float) offset/Game.CellSize);
if (offset > 0)
{
DrawRangeCircle(bg, location, range + (float)offset / Game.CellSize);
DrawRangeCircle(bg, location, range - (float)offset / Game.CellSize);
}
DrawRangeCircle(fg, location, range);
@@ -227,8 +210,8 @@ namespace OpenRA.Graphics
// Conversion between world and screen coordinates
public float2 ScreenPosition(WPos pos)
{
var c = Game.CellSize/1024f;
return new float2(c*pos.X, c*(pos.Y - pos.Z));
var c = Game.CellSize / 1024f;
return new float2(c * pos.X, c * (pos.Y - pos.Z));
}
public int2 ScreenPxPosition(WPos pos)
@@ -241,8 +224,8 @@ namespace OpenRA.Graphics
// For scaling vectors to pixel sizes in the voxel renderer
public float[] ScreenVector(WVec vec)
{
var c = Game.CellSize/1024f;
return new float[] {c*vec.X, c*vec.Y, c*vec.Z, 1};
var c = Game.CellSize / 1024f;
return new float[] { c * vec.X, c * vec.Y, c * vec.Z, 1 };
}
public int2 ScreenPxOffset(WVec vec)
@@ -252,6 +235,14 @@ namespace OpenRA.Graphics
return new int2((int)Math.Round(px[0]), (int)Math.Round(px[1] - px[2]));
}
public float ScreenZPosition(WPos pos, int zOffset) { return (pos.Y + pos.Z + zOffset)*Game.CellSize/1024f; }
public float ScreenZPosition(WPos pos, int offset)
{
return (pos.Y + pos.Z + offset) * Game.CellSize / 1024f;
}
public WPos Position(int2 screenPx)
{
return new WPos(1024 * screenPx.X / Game.CellSize, 1024 * screenPx.Y / Game.CellSize, 0);
}
}
}

View File

@@ -85,8 +85,6 @@
<Compile Include="ActorInitializer.cs" />
<Compile Include="ActorReference.cs" />
<Compile Include="Graphics\QuadRenderer.cs" />
<Compile Include="PVecInt.cs" />
<Compile Include="PPos.cs" />
<Compile Include="Download.cs" />
<Compile Include="Effects\DelayedAction.cs" />
<Compile Include="Effects\FlashTarget.cs" />

View File

@@ -1,107 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Drawing;
namespace OpenRA
{
/// <summary>
/// Pixel coordinate position in the world (fine).
/// </summary>
public struct PPos
{
public readonly int X, Y;
public PPos(int x, int y) { X = x; Y = y; }
public static readonly PPos Zero = new PPos(0, 0);
public static PPos FromWPos(WPos pos)
{
return new PPos(Game.CellSize*pos.X/1024, Game.CellSize*pos.Y/1024);
}
// Temporary hack for things that throw away altitude and
// cache screen positions directly. This can go once all
// the callers understand world coordinates
public static PPos FromWPosHackZ(WPos pos)
{
return new PPos(Game.CellSize*pos.X/1024, Game.CellSize*(pos.Y - pos.Z)/1024);
}
public static explicit operator PPos(int2 a) { return new PPos(a.X, a.Y); }
public static explicit operator PVecInt(PPos a) { return new PVecInt(a.X, a.Y); }
public static PPos operator +(PPos a, PVecInt b) { return new PPos(a.X + b.X, a.Y + b.Y); }
public static PVecInt operator -(PPos a, PPos b) { return new PVecInt(a.X - b.X, a.Y - b.Y); }
public static PPos operator -(PPos a, PVecInt b) { return new PPos(a.X - b.X, a.Y - b.Y); }
public static bool operator ==(PPos me, PPos other) { return (me.X == other.X && me.Y == other.Y); }
public static bool operator !=(PPos me, PPos other) { return !(me == other); }
public static PPos Max(PPos a, PPos b) { return new PPos(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
public static PPos Min(PPos a, PPos b) { return new PPos(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); }
public static PPos Lerp(PPos a, PPos b, int mul, int div)
{
return a + ((PVecInt)(b - a) * mul / div);
}
public static PPos Average(params PPos[] list)
{
if (list == null || list.Length == 0)
throw new ArgumentException("PPos: Cannot calculate average of empty list.");
var x = 0;
var y = 0;
foreach(var pos in list)
{
x += pos.X;
y += pos.Y;
}
x /= list.Length;
y /= list.Length;
return new PPos(x,y);
}
public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(X, Y); }
public CPos ToCPos() { return new CPos((int)(1f / Game.CellSize * X), (int)(1f / Game.CellSize * Y)); }
public PPos Clamp(Rectangle r)
{
return new PPos(Math.Min(r.Right, Math.Max(X, r.Left)),
Math.Min(r.Bottom, Math.Max(Y, r.Top)));
}
public WPos ToWPos(int z)
{
return new WPos(1024*X/Game.CellSize,
1024*Y/Game.CellSize,
1024*z/Game.CellSize);
}
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
public override bool Equals(object obj)
{
if (obj == null)
return false;
PPos o = (PPos)obj;
return o == this;
}
public override string ToString() { return "{0},{1}".F(X, Y); }
}
}

View File

@@ -1,79 +0,0 @@
#region Copyright & License Information
/*
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made
* available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information,
* see COPYING.
*/
#endregion
using System;
using System.Drawing;
namespace OpenRA
{
/// <summary>
/// Pixel coordinate vector (fine; integer)
/// </summary>
public struct PVecInt
{
public readonly int X, Y;
public PVecInt(int x, int y) { X = x; Y = y; }
public PVecInt(Size p) { X = p.Width; Y = p.Height; }
public static readonly PVecInt Zero = new PVecInt(0, 0);
public static PVecInt OneCell { get { return new PVecInt(Game.CellSize, Game.CellSize); } }
public static explicit operator PVecInt(int2 a) { return new PVecInt(a.X, a.Y); }
public static PVecInt FromRadius(int r) { return new PVecInt(r, r); }
public static PVecInt operator +(PVecInt a, PVecInt b) { return new PVecInt(a.X + b.X, a.Y + b.Y); }
public static PVecInt operator -(PVecInt a, PVecInt b) { return new PVecInt(a.X - b.X, a.Y - b.Y); }
public static PVecInt operator *(int a, PVecInt b) { return new PVecInt(a * b.X, a * b.Y); }
public static PVecInt operator *(PVecInt b, int a) { return new PVecInt(a * b.X, a * b.Y); }
public static PVecInt operator /(PVecInt a, int b) { return new PVecInt(a.X / b, a.Y / b); }
public static PVecInt operator -(PVecInt a) { return new PVecInt(-a.X, -a.Y); }
public static bool operator ==(PVecInt me, PVecInt other) { return (me.X == other.X && me.Y == other.Y); }
public static bool operator !=(PVecInt me, PVecInt other) { return !(me == other); }
public static PVecInt Max(PVecInt a, PVecInt b) { return new PVecInt(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)); }
public static PVecInt Min(PVecInt a, PVecInt b) { return new PVecInt(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)); }
public static int Dot(PVecInt a, PVecInt b) { return a.X * b.X + a.Y * b.Y; }
public PVecInt Sign() { return new PVecInt(Math.Sign(X), Math.Sign(Y)); }
public PVecInt Abs() { return new PVecInt(Math.Abs(X), Math.Abs(Y)); }
public int LengthSquared { get { return X * X + Y * Y; } }
public int Length { get { return (int)Math.Sqrt(LengthSquared); } }
public float2 ToFloat2() { return new float2(X, Y); }
public int2 ToInt2() { return new int2(X, Y); }
public CVec ToCVec() { return new CVec(X / Game.CellSize, Y / Game.CellSize); }
public PVecInt Clamp(Rectangle r)
{
return new PVecInt(
Math.Min(r.Right, Math.Max(X, r.Left)),
Math.Min(r.Bottom, Math.Max(Y, r.Top))
);
}
public override int GetHashCode() { return X.GetHashCode() ^ Y.GetHashCode(); }
public override bool Equals(object obj)
{
if (obj == null)
return false;
PVecInt o = (PVecInt)obj;
return o == this;
}
public override string ToString() { return "{0},{1}".F(X, Y); }
}
}

View File

@@ -91,7 +91,7 @@ namespace OpenRA
return defaultDevices.Concat(alDevices).ToArray();
}
public static void SetListenerPosition(float2 position) { soundEngine.SetListenerPosition(position); }
public static void SetListenerPosition(WPos position) { soundEngine.SetListenerPosition(position); }
static ISound Play(Player player, string name, bool headRelative, WPos pos, float volumeModifier)
{
@@ -101,7 +101,7 @@ namespace OpenRA
return null;
return soundEngine.Play2D(sounds[name],
false, headRelative, PPos.FromWPosHackZ(pos).ToFloat2(),
false, headRelative, pos,
InternalSoundVolume * volumeModifier, true);
}
@@ -115,7 +115,7 @@ namespace OpenRA
public static void PlayVideo(byte[] raw)
{
rawSource = LoadSoundRaw(raw);
video = soundEngine.Play2D(rawSource, false, true, float2.Zero, InternalSoundVolume, false);
video = soundEngine.Play2D(rawSource, false, true, WPos.Zero, InternalSoundVolume, false);
}
public static void PlayVideo()
@@ -174,7 +174,7 @@ namespace OpenRA
if (sound == null)
return;
music = soundEngine.Play2D(sound, false, true, float2.Zero, MusicVolume, false);
music = soundEngine.Play2D(sound, false, true, WPos.Zero, MusicVolume, false);
currentMusic = m;
MusicPlaying = true;
}
@@ -322,7 +322,7 @@ namespace OpenRA
if (!String.IsNullOrEmpty(name) && (p == null || p == p.World.LocalPlayer))
soundEngine.Play2D(sounds[name],
false, true, float2.Zero,
false, true, WPos.Zero,
InternalSoundVolume, attentuateVolume);
return true;
@@ -354,13 +354,13 @@ namespace OpenRA
interface ISoundEngine
{
ISoundSource AddSoundSourceFromMemory(byte[] data, int channels, int sampleBits, int sampleRate);
ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume, bool attenuateVolume);
ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume);
float Volume { get; set; }
void PauseSound(ISound sound, bool paused);
void StopSound(ISound sound);
void SetAllSoundsPaused(bool paused);
void StopAllSounds();
void SetListenerPosition(float2 position);
void SetListenerPosition(WPos position);
void SetSoundVolume(float volume, ISound music, ISound video);
}
@@ -397,7 +397,7 @@ namespace OpenRA
{
public bool isActive;
public int frameStarted;
public float2 pos;
public WPos pos;
public bool isRelative;
public ISoundSource sound;
}
@@ -507,10 +507,10 @@ namespace OpenRA
}
const int maxInstancesPerFrame = 3;
const int groupDistance = 64;
const int groupDistance = 2730;
const int groupDistanceSqr = groupDistance * groupDistance;
public ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume, bool attenuateVolume)
public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume)
{
if (sound == null)
{
@@ -635,11 +635,12 @@ namespace OpenRA
}
}
public void SetListenerPosition(float2 position)
public void SetListenerPosition(WPos position)
{
var orientation = new[] { 0f, 0f, 1f, 0f, -1f, 0f };
// Move the listener out of the plane so that sounds near the middle of the screen aren't too positional
Al.alListener3f(Al.AL_POSITION, position.X, position.Y, position.Z + 5*1024);
Al.alListener3f(Al.AL_POSITION, position.X, position.Y, 50);
var orientation = new[] { 0f, 0f, 1f, 0f, -1f, 0f };
Al.alListenerfv(Al.AL_ORIENTATION, ref orientation[0]);
Al.alListenerf(Al.AL_METERS_PER_UNIT, .01f);
}
@@ -669,19 +670,20 @@ namespace OpenRA
public readonly int source = -1;
float volume = 1f;
public OpenAlSound(int source, int buffer, bool looping, bool relative, float2 pos, float volume)
public OpenAlSound(int source, int buffer, bool looping, bool relative, WPos pos, float volume)
{
if (source == -1) return;
this.source = source;
Al.alSourcef(source, Al.AL_PITCH, 1f);
Volume = volume;
Al.alSource3f(source, Al.AL_POSITION, pos.X, pos.Y, 0f);
Al.alSource3f(source, Al.AL_POSITION, pos.X, pos.Y, pos.Z);
Al.alSource3f(source, Al.AL_VELOCITY, 0f, 0f, 0f);
Al.alSourcei(source, Al.AL_BUFFER, buffer);
Al.alSourcei(source, Al.AL_LOOPING, looping ? Al.AL_TRUE : Al.AL_FALSE);
Al.alSourcei(source, Al.AL_SOURCE_RELATIVE, relative ? 1 : 0);
Al.alSourcef(source, Al.AL_REFERENCE_DISTANCE, 160);
Al.alSourcef(source, Al.AL_MAX_DISTANCE, 3200 / Game.viewport.Zoom);
Al.alSourcef(source, Al.AL_REFERENCE_DISTANCE, Game.viewport.WorldRect.Width / 8);
Al.alSourcef(source, Al.AL_MAX_DISTANCE, 2*Game.viewport.WorldRect.Width);
Al.alSourcePlay(source);
}
@@ -728,7 +730,7 @@ namespace OpenRA
return new NullSoundSource();
}
public ISound Play2D(ISoundSource sound, bool loop, bool relative, float2 pos, float volume, bool attenuateVolume)
public ISound Play2D(ISoundSource sound, bool loop, bool relative, WPos pos, float volume, bool attenuateVolume)
{
return new NullSound();
}
@@ -737,7 +739,7 @@ namespace OpenRA
public void StopSound(ISound sound) {}
public void SetAllSoundsPaused(bool paused) {}
public void StopAllSounds() {}
public void SetListenerPosition(float2 position) {}
public void SetListenerPosition(WPos position) {}
public void SetSoundVolume(float volume, ISound music, ISound video) {}
public float Volume { get; set; }

View File

@@ -36,8 +36,6 @@ namespace OpenRA
{typeof(int2), ((Func<int2, int>)hash_int2).Method},
{typeof(CPos), ((Func<CPos, int>)hash_CPos).Method},
{typeof(CVec), ((Func<CVec, int>)hash_CVec).Method},
{typeof(PPos), ((Func<PPos, int>)hash_PPos).Method},
{typeof(PVecInt), ((Func<PVecInt, int>)hash_PVecInt).Method},
{typeof(WRange), ((Func<WRange, int>)hash<WRange>).Method},
{typeof(WPos), ((Func<WPos, int>)hash<WPos>).Method},
{typeof(WVec), ((Func<WVec, int>)hash<WVec>).Method},
@@ -115,16 +113,6 @@ namespace OpenRA
{
return ((i2.X * 5) ^ (i2.Y * 3)) / 4;
}
public static int hash_PPos(PPos i2)
{
return ((i2.X * 5) ^ (i2.Y * 3)) / 4;
}
public static int hash_PVecInt(PVecInt i2)
{
return ((i2.X * 5) ^ (i2.Y * 3)) / 4;
}
public static int hash_tdict(TypeDictionary d)
{

View File

@@ -54,7 +54,9 @@ namespace OpenRA.Traits
var pipImages = new Animation("pips");
pipImages.PlayFetchIndex("groups", () => (int)group);
pipImages.Tick();
pipImages.Image.DrawAt(basePosition + new float2(-8, 1), wr.Palette("chrome"));
var pos = (basePosition + new float2(-8, 1) + 0.5f * pipImages.Image.size).ToInt2();
pipImages.Render(wr.Position(pos), wr.Palette("chrome")).Do(r => r.Render(wr));
}
void DrawPips(WorldRenderer wr, Actor self, float2 basePosition)
@@ -90,8 +92,10 @@ namespace OpenRA.Traits
pipxyOffset.Y -= pipSize.Y;
}
pipImages.PlayRepeating(pipStrings[(int)pip]);
pipImages.Image.DrawAt(pipxyBase + pipxyOffset, pal);
pipxyOffset += new float2(pipSize.X, 0);
var pos = (pipxyBase + pipxyOffset + 0.5f * pipSize).ToInt2();
pipImages.Render(wr.Position(pos), pal).Do(r => r.Render(wr));
}
// Increment row
@@ -106,8 +110,7 @@ namespace OpenRA.Traits
return;
// If a mod wants to implement a unit with multiple tags, then they are placed on multiple rows
var tagxyBase = basePosition + new float2(-16, 2); // Correct for the offset in the shp file
var tagxyOffset = new float2(0, 0); // Correct for offset due to multiple rows
var tagxyOffset = new float2(-16, 2); // Correct in the shp file and multiple rows
var pal = wr.Palette("chrome");
foreach (var tags in self.TraitsImplementing<ITags>())
{
@@ -118,7 +121,8 @@ namespace OpenRA.Traits
var tagImages = new Animation("pips");
tagImages.PlayRepeating(tagStrings[(int)tag]);
tagImages.Image.DrawAt(tagxyBase + tagxyOffset, pal);
var pos = (basePosition + tagxyOffset + 0.5f * tagImages.Image.size).ToInt2();
tagImages.Render(wr.Position(pos), pal).Do(r => r.Render(wr));
// Increment row
tagxyOffset.Y += 8;

View File

@@ -48,11 +48,8 @@ namespace OpenRA.Traits
var c = render[x, y];
if (c.Image != null)
{
var tile = c.Image[c.Density];
var px = wr.ScreenPxPosition(pos.CenterPosition) - 0.5f * tile.size;
tile.DrawAt(px, c.Type.info.PaletteRef);
}
new SpriteRenderable(c.Image[c.Density], pos.CenterPosition,
WVec.Zero, -511, c.Type.info.PaletteRef, 1f, true).Render(wr);
}
}
}

View File

@@ -127,9 +127,6 @@ namespace OpenRA.Traits
.Select(kv => kv.Key);
}
// Legacy fallback
public IEnumerable<Actor> ActorsAt(PPos pxPos) { return ActorsAt(pxPos.ToInt2()); }
public IEnumerable<Actor> ActorsInBox(int2 a, int2 b)
{
return ActorsInBox(Rectangle.FromLTRB(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y), Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)));
@@ -142,18 +139,14 @@ namespace OpenRA.Traits
var top = (r.Top / info.BinSize).Clamp(0, rows - 1);
var bottom = (r.Bottom / info.BinSize).Clamp(0, rows - 1);
var actorsInBox = new List<Actor>();
for (var j = top; j <= bottom; j++)
{
for (var i = left; i <= right; i++)
{
var ret = actors[j * cols + i]
actorsInBox.AddRange(actors[j * cols + i]
.Where(kv => kv.Key.IsInWorld && kv.Value.IntersectsWith(r))
.Select(kv => kv.Key);
.Select(kv => kv.Key));
foreach (var a in ret)
yield return a;
}
}
return actorsInBox.Distinct();
}
}
}

View File

@@ -11,16 +11,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using OpenRA.Graphics;
namespace OpenRA.Traits
{
public class ScreenShakerInfo : TraitInfo<ScreenShaker> { }
public class ScreenShaker : ITick
public class ScreenShaker : ITick, IWorldLoaded
{
WorldRenderer worldRenderer;
List<ShakeEffect> shakeEffects = new List<ShakeEffect>();
int ticks = 0;
public void WorldLoaded(World w, WorldRenderer wr) { worldRenderer = wr; }
public void Tick(Actor self)
{
if (shakeEffects.Any())
@@ -46,7 +50,7 @@ namespace OpenRA.Traits
float GetIntensity()
{
var cp = ((PPos)Game.viewport.CenterLocation.ToInt2()).ToWPos(0);
var cp = worldRenderer.Position(Game.viewport.CenterLocation.ToInt2());
var intensity = 100 * 1024 * 1024 * shakeEffects.Sum(
e => (float)e.Intensity / (e.Position - cp).LengthSquared);

View File

@@ -23,6 +23,7 @@ namespace OpenRA.Widgets
{
protected readonly World world;
readonly WorldRenderer worldRenderer;
int2 dragStart, dragEnd;
[ObjectCreator.UseCtor]
public WorldInteractionControllerWidget(World world, WorldRenderer worldRenderer)
@@ -47,11 +48,10 @@ namespace OpenRA.Widgets
worldRenderer.DrawRollover(u);
}
PPos dragStart, dragEnd;
public override bool HandleMouseInput(MouseInput mi)
{
var xy = Game.viewport.ViewToWorldPx(mi);
var xy = Game.viewport.ViewToWorldPx(mi.Location);
var UseClassicMouseStyle = Game.Settings.Game.UseClassicMouseStyle;
@@ -127,7 +127,7 @@ namespace OpenRA.Widgets
}
public Pair<PPos, PPos>? SelectionBox
public Pair<int2, int2>? SelectionBox
{
get
{
@@ -136,33 +136,38 @@ namespace OpenRA.Widgets
}
}
public void ApplyOrders(World world, PPos xy, MouseInput mi)
void ApplyOrders(World world, int2 xy, MouseInput mi)
{
if (world.OrderGenerator == null) return;
var orders = world.OrderGenerator.Order(world, xy.ToCPos(), mi).ToArray();
var pos = worldRenderer.Position(xy);
var orders = world.OrderGenerator.Order(world, pos.ToCPos(), mi).ToArray();
orders.Do(o => world.IssueOrder(o));
world.PlayVoiceForOrders(orders);
}
public override string GetCursor(int2 pos)
public override string GetCursor(int2 screenPos)
{
return Sync.CheckSyncUnchanged(world, () =>
{
// Always show an arrow while selecting
if (SelectionBox != null)
return null; /* always show an arrow while selecting */
return null;
var xy = Game.viewport.ViewToWorldPx(screenPos);
var pos = worldRenderer.Position(xy);
var cell = pos.ToCPos();
var mi = new MouseInput
{
Location = pos,
Location = screenPos,
Button = Game.mouseButtonPreference.Action,
Modifiers = Game.GetModifierKeys()
};
// TODO: fix this up.
return world.OrderGenerator.GetCursor(world, Game.viewport.ViewToWorld(mi), mi);
} );
return world.OrderGenerator.GetCursor(world, cell, mi);
});
}
public override bool HandleKeyPress(KeyInput e)
@@ -183,9 +188,9 @@ namespace OpenRA.Widgets
}
static readonly Actor[] NoActors = {};
IEnumerable<Actor> SelectActorsInBox(World world, PPos a, PPos b, Func<Actor, bool> cond)
IEnumerable<Actor> SelectActorsInBox(World world, int2 a, int2 b, Func<Actor, bool> cond)
{
return world.ScreenMap.ActorsInBox(a.ToInt2(), b.ToInt2())
return world.ScreenMap.ActorsInBox(a, b)
.Where(x => x.HasTrait<Selectable>() && x.Trait<Selectable>().Info.Selectable && !world.FogObscures(x) && cond(x))
.GroupBy(x => x.GetSelectionPriority())
.OrderByDescending(g => g.Key)

View File

@@ -27,7 +27,7 @@ namespace OpenRA
if (world.RenderPlayer == null)
return NoFrozenActors;
return world.ScreenMap.FrozenActorsAt(world.RenderPlayer, Game.viewport.ViewToWorldPx(mouseLocation).ToInt2());
return world.ScreenMap.FrozenActorsAt(world.RenderPlayer, Game.viewport.ViewToWorldPx(mouseLocation));
}
public static IEnumerable<Actor> FindActorsInBox(this World world, CPos tl, CPos br)

View File

@@ -121,7 +121,7 @@ namespace OpenRA.Mods.RA
var bounds = self.Bounds.Value;
bounds.Offset(pos.X, pos.Y);
var effectPos = new PPos(bounds.Right, bounds.Bottom - 2).ToWPos(0);
var effectPos = wr.Position(new int2(bounds.Right, bounds.Bottom - 2));
yield return new SpriteRenderable(RankAnim.Image, effectPos, WVec.Zero, 0, wr.Palette("effect"), 1f, true);
}
}

View File

@@ -42,7 +42,7 @@ namespace OpenRA.Mods.RA
this.self = init.self;
TopLeft = init.Get<LocationInit, CPos>();
CenterPosition = init.Contains<CenterLocationInit>() ? init.Get<CenterLocationInit, PPos>().ToWPos(0) : TopLeft.CenterPosition;
CenterPosition = init.Contains<CenterPositionInit>() ? init.Get<CenterPositionInit, WPos>() : TopLeft.CenterPosition;
Facing = init.Contains<FacingInit>() ? init.Get<FacingInit, int>() : 128;
var speed = init.Contains<HuskSpeedInit>() ? init.Get<HuskSpeedInit, int>() : 0;

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Mods.RA
{
new ParentActorInit(self),
new LocationInit(self.Location),
new CenterLocationInit(self.CenterLocation),
new CenterPositionInit(self.CenterPosition),
new OwnerInit(self.Owner),
new SkipMakeAnimsInit()
};

View File

@@ -34,28 +34,34 @@ namespace OpenRA.Mods.RA
public CPos[] minefield = null;
[Sync] CPos minefieldStart;
Actor self;
Sprite tile;
public Minelayer(Actor self) { this.self = self; }
public Minelayer(Actor self)
{
this.self = self;
var tileset = self.World.TileSet.Id.ToLower();
tile = SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
}
public IEnumerable<IOrderTargeter> Orders
{
get { yield return new BeginMinefieldOrderTargeter(); }
}
public Order IssueOrder( Actor self, IOrderTargeter order, Target target, bool queued )
public Order IssueOrder(Actor self, IOrderTargeter order, Target target, bool queued)
{
if( order is BeginMinefieldOrderTargeter )
{
var start = target.CenterPosition.ToCPos();
self.World.OrderGenerator = new MinefieldOrderGenerator( self, start );
return new Order("BeginMinefield", self, false) { TargetLocation = start };
}
return null;
if (!(order is BeginMinefieldOrderTargeter))
return null;
var start = target.CenterPosition.ToCPos();
self.World.OrderGenerator = new MinefieldOrderGenerator(self, start);
return new Order("BeginMinefield", self, false) { TargetLocation = start };
}
public void ResolveOrder(Actor self, Order order)
{
if( order.OrderString == "BeginMinefield" )
if (order.OrderString == "BeginMinefield")
minefieldStart = order.TargetLocation;
if (order.OrderString == "PlaceMinefield")
@@ -91,12 +97,33 @@ namespace OpenRA.Mods.RA
yield return new CPos(i, j);
}
public void RenderAfterWorld(WorldRenderer wr)
{
if (self.Owner != self.World.LocalPlayer || minefield == null)
return;
var pal = wr.Palette("terrain");
foreach (var c in minefield)
new SpriteRenderable(tile, c.CenterPosition,
WVec.Zero, -511, pal, 1f, true).Render(wr);
}
class MinefieldOrderGenerator : IOrderGenerator
{
readonly Actor minelayer;
readonly CPos minefieldStart;
readonly Sprite tileOk;
readonly Sprite tileBlocked;
public MinefieldOrderGenerator(Actor self, CPos xy ) { minelayer = self; minefieldStart = xy; }
public MinefieldOrderGenerator(Actor self, CPos xy)
{
minelayer = self;
minefieldStart = xy;
var tileset = self.World.TileSet.Id.ToLower();
tileOk = SequenceProvider.GetSequence("overlay", "build-valid-{0}".F(tileset)).GetSprite(0);
tileBlocked = SequenceProvider.GetSequence("overlay", "build-invalid").GetSprite(0);
}
public IEnumerable<Order> Order(World world, CPos xy, MouseInput mi)
{
@@ -134,24 +161,20 @@ namespace OpenRA.Mods.RA
var movement = minelayer.Trait<IPositionable>();
var minefield = GetMinefieldCells(minefieldStart, lastMousePos,
minelayer.Info.Traits.Get<MinelayerInfo>().MinefieldDepth)
.Where(p => movement.CanEnterCell(p)).ToArray();
minelayer.Info.Traits.Get<MinelayerInfo>().MinefieldDepth);
wr.DrawLocus(Color.Cyan, minefield);
var pal = wr.Palette("terrain");
foreach (var c in minefield)
{
var tile = movement.CanEnterCell(c) ? tileOk : tileBlocked;
new SpriteRenderable(tile, c.CenterPosition,
WVec.Zero, -511, pal, 1f, true).Render(wr);
}
}
public string GetCursor(World world, CPos xy, MouseInput mi) { lastMousePos = xy; return "ability"; } /* TODO */
}
public void RenderAfterWorld(WorldRenderer wr)
{
if (self.Owner != self.World.LocalPlayer)
return;
if (minefield != null)
wr.DrawLocus(Color.Cyan, minefield);
}
class BeginMinefieldOrderTargeter : IOrderTargeter
{
public string OrderID { get { return "BeginMinefield"; } }

View File

@@ -112,7 +112,8 @@ namespace OpenRA.Mods.RA.Orders
foreach (var c in cells)
{
var tile = c.Value ? buildOk : buildBlocked;
tile.DrawAt(wr.ScreenPxPosition(c.Key.CenterPosition) - 0.5f * tile.size, pal);
new SpriteRenderable(tile, c.Key.CenterPosition,
WVec.Zero, -511, pal, 1f, true).Render(wr);
}
}

View File

@@ -128,14 +128,15 @@ namespace OpenRA.Mods.RA
var c = -float2.Dot(from, q);
var rs = new List<IRenderable>();
var z = from;
var pal = wr.Palette("effect");
while ((to - z).X > 5 || (to - z).X < -5 || (to - z).Y > 5 || (to - z).Y < -5)
{
var step = steps.Where(t => (to - (z + new float2(t[0], t[1]))).LengthSquared < (to - z).LengthSquared)
.OrderBy(t => Math.Abs(float2.Dot(z + new float2(t[0], t[1]), q) + c)).First();
var pos = new PPos((int)(z.X + step[2]), (int)(z.Y + step[3])).ToWPos(0);
rs.Add(new SpriteRenderable(s.GetSprite(step[4]), pos, WVec.Zero, 0, wr.Palette("effect"), 1f, true));
var pos = wr.Position((z + new float2(step[2], step[3])).ToInt2());
rs.Add(new SpriteRenderable(s.GetSprite(step[4]), pos, WVec.Zero, 0, pal, 1f, true));
z += new float2(step[0], step[1]);
if (rs.Count >= 1000)

View File

@@ -42,11 +42,13 @@ namespace OpenRA.Mods.RA.Widgets
Sprite shroudSprite;
readonly World world;
readonly WorldRenderer worldRenderer;
[ObjectCreator.UseCtor]
public RadarWidget(World world)
public RadarWidget(World world, WorldRenderer worldRenderer)
{
this.world = world;
this.worldRenderer = worldRenderer;
}
public override void Initialize(WidgetArgs args)
@@ -80,16 +82,17 @@ namespace OpenRA.Mods.RA.Widgets
if (world == null || !hasRadar)
return null;
var loc = MinimapPixelToCell(pos);
var cell = MinimapPixelToCell(pos);
var location = Game.viewport.WorldToViewPx(worldRenderer.ScreenPxPosition(cell.CenterPosition));
var mi = new MouseInput
{
Location = loc.ToInt2(),
Location = location,
Button = MouseButton.Right,
Modifiers = Game.GetModifierKeys()
};
var cursor = world.OrderGenerator.GetCursor(world, loc, mi);
var cursor = world.OrderGenerator.GetCursor(world, cell, mi);
if (cursor == null)
return "default";
@@ -104,19 +107,21 @@ namespace OpenRA.Mods.RA.Widgets
if (!hasRadar)
return true;
var loc = MinimapPixelToCell(mi.Location);
var cell = MinimapPixelToCell(mi.Location);
var pos = cell.CenterPosition;
if ((mi.Event == MouseInputEvent.Down || mi.Event == MouseInputEvent.Move) && mi.Button == MouseButton.Left)
Game.viewport.Center(loc.ToFloat2());
Game.viewport.Center(cell.ToFloat2());
if (mi.Event == MouseInputEvent.Down && mi.Button == MouseButton.Right)
{
// fake a mousedown/mouseup here
var location = Game.viewport.WorldToViewPx(worldRenderer.ScreenPxPosition(pos));
var fakemi = new MouseInput
{
Event = MouseInputEvent.Down,
Button = MouseButton.Right,
Modifiers = mi.Modifiers,
Location = (loc.ToPPos().ToFloat2() - Game.viewport.Location).ToInt2()
Location = location
};
if (WorldInteractionController != null)

View File

@@ -46,37 +46,37 @@ namespace OpenRA.Mods.RA
public void Render(WorldRenderer wr)
{
if (!Visible) return;
if (!Visible)
return;
var qr = Game.Renderer.WorldQuadRenderer;
bool doDim = refreshTick - world.FrameNumber <= 0;
var doDim = refreshTick - world.FrameNumber <= 0;
if (doDim) refreshTick = world.FrameNumber + 20;
var viewBounds = Game.viewport.WorldBounds(world);
var mapBounds = world.Map.Bounds;
foreach (var pair in layers)
{
Color c = (pair.Key != null) ? pair.Key.Color.RGB : Color.PaleTurquoise;
var c = (pair.Key != null) ? pair.Key.Color.RGB : Color.PaleTurquoise;
var layer = pair.Value;
for (int j = mapBounds.Top; j <= mapBounds.Bottom; ++j)
for (int i = mapBounds.Left; i <= mapBounds.Right; ++i)
// Only render quads in viewing range:
for (var j = viewBounds.Top; j <= viewBounds.Bottom; ++j)
{
for (var i = viewBounds.Left; i <= viewBounds.Right; ++i)
{
if (layer[i, j] <= 0) continue;
if (layer [i, j] <= 0)
continue;
var w = Math.Max(0, Math.Min(layer[i, j], 128));
var w = Math.Max(0, Math.Min(layer [i, j], 128));
if (doDim)
{
layer[i, j] = layer[i, j] * 5 / 6;
}
layer [i, j] = layer [i, j] * 5 / 6;
if (!viewBounds.Contains(i, j)) continue;
// Only render quads in viewing range:
var ploc = new CPos(i, j).ToPPos();
qr.FillRect(new RectangleF(ploc.X, ploc.Y, Game.CellSize, Game.CellSize), Color.FromArgb(w, c));
// TODO: This doesn't make sense for isometric terrain
var tl = wr.ScreenPxPosition(new CPos(i, j).CenterPosition) - new int2(Game.CellSize, Game.CellSize);
qr.FillRect(new RectangleF(tl.X, tl.Y, Game.CellSize, Game.CellSize), Color.FromArgb(w, c));
}
}
}
}
}

View File

@@ -106,7 +106,9 @@ namespace OpenRA.Mods.RA
if (world.ShroudObscures(kv.Key))
continue;
smudgeSprites[kv.Value.Type - 1][kv.Value.Index].DrawAt(kv.Key.ToPPos().ToFloat2(), pal);
var tile = smudgeSprites[kv.Value.Type - 1][kv.Value.Index];
new SpriteRenderable(tile, kv.Key.CenterPosition,
WVec.Zero, -511, pal, 1f, true).Render(wr);
}
}
}