Merge pull request #3407 from pchote/voxel-fbo

Voxel refactoring
This commit is contained in:
Chris Forbes
2013-06-19 14:57:17 -07:00
66 changed files with 1157 additions and 553 deletions

View File

@@ -27,15 +27,15 @@ namespace OpenRA.Mods.RA.Activities
public override Activity Tick(Actor self)
{
if (IsCanceled || !target.IsValid)
if (IsCanceled || !target.IsValid || !target.IsActor)
return NextActivity;
var targetPlayer = target.Actor.Owner;
targetPlayer.PlayerActor.Trait<PlayerResources>().GiveCash(payload);
var targetActor = target.Actor;
targetActor.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(payload);
self.Destroy();
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
self.World.AddFrameEndTask(w => w.Add(new CashTick(payload, 30, 2, target.CenterLocation, targetPlayer.Color.RGB)));
self.World.AddFrameEndTask(w => w.Add(new CashTick(targetActor.CenterPosition, targetActor.Owner.Color.RGB, payload)));
return this;
}

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Mods.RA.Activities
ns.Sold(self);
if (refund > 0 && self.Owner.IsAlliedWith(self.World.RenderPlayer))
self.World.AddFrameEndTask(w => w.Add(new CashTick(refund, 30, 2, self.CenterLocation, self.Owner.Color.RGB)));
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, self.Owner.Color.RGB, refund)));
self.Destroy();
return this;

View File

@@ -101,7 +101,7 @@ namespace OpenRA.Mods.RA
cachedTileset = self.World.Map.Tileset;
var tileSize = new Size(Game.CellSize, Game.CellSize);
sprites = new Cache<TileReference<ushort,byte>, Sprite>(
x => Game.modData.SheetBuilder.Add(self.World.TileSet.GetBytes(x), tileSize, true));
x => Game.modData.SheetBuilder.Add(self.World.TileSet.GetBytes(x), tileSize));
}
// Cache templates and tiles for the different states

View File

@@ -73,6 +73,7 @@ namespace OpenRA.Mods.RA.Buildings
public void Render( WorldRenderer wr )
{
var pal = wr.Palette("terrain");
var cliprect = Game.viewport.WorldBounds(world);
foreach (var kv in tiles)
{
@@ -81,7 +82,7 @@ namespace OpenRA.Mods.RA.Buildings
if (world.ShroudObscures(kv.Key))
continue;
bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt(wr, kv.Key.ToPPos().ToFloat2(), "terrain");
bibSprites[kv.Value.type - 1][kv.Value.index].DrawAt(kv.Key.ToPPos().ToFloat2(), pal);
}
}
}

View File

@@ -23,10 +23,6 @@ namespace OpenRA.Mods.RA
public readonly int Amount = 15;
[Desc("Whether to show the cash tick indicators (+$15 rising from actor).")]
public readonly bool ShowTicks = true;
[Desc("How long the cash tick indicator should be shown for.")]
public readonly int TickLifetime = 30;
[Desc("Pixels/tick upward movement of the cash tick indicator.")]
public readonly int TickVelocity = 1;
[Desc("Amount of money awarded for capturing the actor.")]
public readonly int CaptureAmount = 0;
@@ -64,7 +60,7 @@ namespace OpenRA.Mods.RA
void MaybeAddCashTick(Actor self, int amount)
{
if (Info.ShowTicks)
self.World.AddFrameEndTask(w => w.Add(new CashTick(amount, Info.TickLifetime, Info.TickVelocity, self.CenterLocation, self.Owner.Color.RGB)));
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, self.Owner.Color.RGB, amount)));
}
}
}

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Mods.RA
collector.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(amount);
if ((info as GiveCashCrateActionInfo).UseCashTick)
w.Add(new CashTick(amount, 20, 1, collector.CenterLocation, collector.Owner.Color.RGB));
w.Add(new CashTick(collector.CenterPosition, collector.Owner.Color.RGB, amount));
});
base.Activate(collector);

View File

@@ -8,6 +8,7 @@
*/
#endregion
using System;
using System.Collections.Generic;
using System.Drawing;
using OpenRA.Effects;
@@ -18,41 +19,32 @@ namespace OpenRA.Mods.RA.Effects
{
class CashTick : IEffect
{
readonly string s;
int remaining;
readonly int velocity;
PPos pos;
readonly float2 offset;
readonly Color color;
readonly SpriteFont font;
readonly string text;
Color color;
int remaining = 30;
WPos pos;
static string FormatCashAmount(int x) { return "{0}${1}".F(x < 0 ? "-" : "+", x); }
public CashTick(int value, int lifetime, int velocity, PPos pos, Color color)
: this(FormatCashAmount(value), lifetime, velocity, pos, color) { }
public CashTick(string value, int lifetime, int velocity, PPos pos, Color color)
public CashTick(WPos pos, Color color, int value)
{
this.color = color;
this.velocity = velocity;
this.font = Game.Renderer.Fonts["TinyBold"];
this.pos = pos;
s = value;
font = Game.Renderer.Fonts["TinyBold"];
offset = 0.5f*font.Measure(s).ToFloat2();
remaining = lifetime;
this.color = color;
this.text = "{0}${1}".F(value < 0 ? "-" : "+", Math.Abs(value));
}
static readonly WVec velocity = new WVec(0,0,86);
public void Tick(World world)
{
if (--remaining <= 0)
world.AddFrameEndTask(w => w.Remove(this));
pos -= new PVecInt(0, velocity);
pos += velocity;
}
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
font.DrawTextWithContrast(s, Game.viewport.Zoom*(pos.ToFloat2() - Game.viewport.Location) - offset, color, Color.Black,1);
yield break;
yield return new TextRenderable(font, pos, 0, color, text);
}
}
}

View File

@@ -78,22 +78,21 @@ namespace OpenRA.Mods.RA.Effects
public IEnumerable<IRenderable> Render(WorldRenderer wr)
{
if (ticks < info.BeamDuration)
{
var src = new PPos(args.src.X, args.src.Y).ToWPos(args.srcAltitude);
var dest = new PPos(args.dest.X, args.dest.Y).ToWPos(args.destAltitude);
var rc = Color.FromArgb((info.BeamDuration - ticks)*255/info.BeamDuration, color);
yield return new BeamRenderable(src, 0, dest - src, info.BeamWidth, rc);
}
if (hitanim != null)
yield return new SpriteRenderable(hitanim.Image, args.dest.ToFloat2(),
wr.Palette("effect"), (int)args.dest.Y);
if (ticks >= info.BeamDuration)
yield break;
var rc = Color.FromArgb((info.BeamDuration - ticks)*255/info.BeamDuration, color);
var src = new PPos(args.src.X, args.src.Y - args.srcAltitude);
var dest = new PPos(args.dest.X, args.dest.Y - args.destAltitude);
var wlr = Game.Renderer.WorldLineRenderer;
wlr.LineWidth = info.BeamWidth;
wlr.DrawLine(src.ToFloat2(), dest.ToFloat2(), rc, rc);
wlr.Flush();
wlr.LineWidth = 1f;
}
}
}

View File

@@ -54,7 +54,7 @@ namespace OpenRA.Mods.RA
var bounty = cost * GetMultiplier(self) * info.Percentage / 10000;
if (bounty > 0 && e.Attacker.Owner.IsAlliedWith(self.World.RenderPlayer))
e.Attacker.World.AddFrameEndTask(w => w.Add(new CashTick(bounty, 20, 1, self.CenterLocation, e.Attacker.Owner.Color.RGB)));
e.Attacker.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, e.Attacker.Owner.Color.RGB, bounty)));
e.Attacker.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(bounty);
}

View File

@@ -44,8 +44,7 @@ namespace OpenRA.Mods.RA
Sound.PlayToPlayer(self.Owner, info.SoundToVictim);
self.World.AddFrameEndTask(w => w.Add(new CashTick(toGive, 30, 2, self.CenterLocation,
infiltrator.Owner.Color.RGB)));
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, infiltrator.Owner.Color.RGB, toGive)));
}
}
}

View File

@@ -108,8 +108,9 @@ namespace OpenRA.Mods.RA.Orders
cells.Add(t, isCloseEnough && world.IsCellBuildable(t, BuildingInfo) && res.GetResource(t) == null);
}
var pal = wr.Palette("terrain");
foreach (var c in cells)
(c.Value ? buildOk : buildBlocked).DrawAt(wr, c.Key.ToPPos().ToFloat2(), "terrain");
(c.Value ? buildOk : buildBlocked).DrawAt(c.Key.ToPPos().ToFloat2(), pal);
}
public string GetCursor(World world, CPos xy, MouseInput mi) { return "default"; }

View File

@@ -93,7 +93,7 @@ namespace OpenRA.Mods.RA
{
var temp = currentDisplayValue;
if (self.Owner.IsAlliedWith(self.World.RenderPlayer))
self.World.AddFrameEndTask(w => w.Add(new CashTick(temp, Info.TickLifetime, Info.TickVelocity, self.CenterLocation, self.Owner.Color.RGB)));
self.World.AddFrameEndTask(w => w.Add(new CashTick(self.CenterPosition, self.Owner.Color.RGB, temp)));
currentDisplayTick = Info.TickRate;
currentDisplayValue = 0;
}

View File

@@ -32,11 +32,10 @@ namespace OpenRA.Mods.RA.Render
[Desc("Change the image size.")]
public readonly float Scale = 10;
public readonly WAngle LightPitch = new WAngle(170); // 60 degrees
public readonly WAngle LightYaw = new WAngle(739); // 260 degrees
public readonly WAngle LightPitch = WAngle.FromDegrees(50);
public readonly WAngle LightYaw = WAngle.FromDegrees(240);
public readonly float[] LightAmbientColor = new float[] {0.6f, 0.6f, 0.6f};
public readonly float[] LightDiffuseColor = new float[] {0.4f, 0.4f, 0.4f};
public virtual object Create(ActorInitializer init) { return new RenderVoxels(init.self, this); }
}
@@ -55,7 +54,7 @@ namespace OpenRA.Mods.RA.Render
this.info = info;
body = self.Trait<IBodyOrientation>();
camera = new WRot(WAngle.Zero, body.CameraPitch - new WAngle(256), new WAngle(256));
lightSource = new WRot(WAngle.Zero, info.LightPitch, info.LightYaw - new WAngle(256));
lightSource = new WRot(WAngle.Zero,new WAngle(256) - info.LightPitch, info.LightYaw);
}
bool initializePalettes = true;

View File

@@ -151,8 +151,9 @@ namespace OpenRA.Mods.RA
{
var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos);
var tiles = world.FindTilesInCircle(xy, range);
var pal = wr.Palette("terrain");
foreach (var t in tiles)
tile.DrawAt( wr, t.ToPPos().ToFloat2(), "terrain" );
tile.DrawAt(t.ToPPos().ToFloat2(), pal);
}
public string GetCursor(World world, CPos xy, MouseInput mi)
@@ -230,14 +231,15 @@ namespace OpenRA.Mods.RA
public void RenderBeforeWorld(WorldRenderer wr, World world)
{
var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos);
var pal = wr.Palette("terrain");
// Source tiles
foreach (var t in world.FindTilesInCircle(sourceLocation, range))
sourceTile.DrawAt( wr, t.ToPPos().ToFloat2(), "terrain" );
sourceTile.DrawAt(t.ToPPos().ToFloat2(), pal);
// Destination tiles
foreach (var t in world.FindTilesInCircle(xy, range))
sourceTile.DrawAt( wr, t.ToPPos().ToFloat2(), "terrain" );
sourceTile.DrawAt(t.ToPPos().ToFloat2(), pal);
// Unit previews
foreach (var unit in power.UnitsInRange(sourceLocation))
@@ -257,7 +259,7 @@ namespace OpenRA.Mods.RA
var canEnter = ((manager.self.Owner.Shroud.IsExplored(targetCell) || manager.self.Owner.HasFogVisibility()) &&
unit.Trait<Chronoshiftable>().CanChronoshiftTo(unit,targetCell));
var tile = canEnter ? validTile : invalidTile;
tile.DrawAt(wr, targetCell.ToPPos().ToFloat2(), "terrain");
tile.DrawAt(targetCell.ToPPos().ToFloat2(), pal);
}
}
}

View File

@@ -98,8 +98,9 @@ namespace OpenRA.Mods.RA
public void RenderBeforeWorld(WorldRenderer wr, World world)
{
var xy = Game.viewport.ViewToWorld(Viewport.LastMousePos);
var pal = wr.Palette("terrain");
foreach (var t in world.FindTilesInCircle(xy, range))
tile.DrawAt( wr, t.ToPPos().ToFloat2(), "terrain" );
tile.DrawAt(t.ToPPos().ToFloat2(), pal);
}
public string GetCursor(World world, CPos xy, MouseInput mi)

View File

@@ -13,6 +13,7 @@ using System.Drawing;
using System.Reflection;
using System.Linq;
using OpenRA;
using OpenRA.Graphics;
using OpenRA.Traits;
using OpenRA.Widgets;
using XRandom = OpenRA.Thirdparty.Random;
@@ -68,6 +69,13 @@ namespace OpenRA.Mods.RA.Widgets.Logic
showMuzzlesCheckbox.OnClick = () => devTrait.ShowMuzzles ^= true;
}
var showGeometryCheckbox = widget.GetOrNull<CheckboxWidget>("SHOW_GEOMETRY");
if (showGeometryCheckbox != null)
{
showGeometryCheckbox.IsChecked = () => devTrait.ShowDebugGeometry;
showGeometryCheckbox.OnClick = () => devTrait.ShowDebugGeometry ^= true;
}
var allTechCheckbox = widget.GetOrNull<CheckboxWidget>("ENABLE_TECH");
if (allTechCheckbox != null)
{

View File

@@ -78,6 +78,8 @@ namespace OpenRA.Mods.RA
public void Render( WorldRenderer wr )
{
var cliprect = Game.viewport.WorldBounds(world);
var pal = wr.Palette("terrain");
foreach (var kv in tiles)
{
if (!cliprect.Contains(kv.Key.X,kv.Key.Y))
@@ -86,7 +88,7 @@ namespace OpenRA.Mods.RA
if (world.ShroudObscures(kv.Key))
continue;
smudgeSprites[kv.Value.type- 1][kv.Value.index].DrawAt(wr, kv.Key.ToPPos().ToFloat2(), "terrain");
smudgeSprites[kv.Value.type- 1][kv.Value.index].DrawAt(kv.Key.ToPPos().ToFloat2(), pal);
}
}
}