pass world into CheckSync. don't pass world into Widget.DrawInner

This commit is contained in:
Bob
2010-10-11 19:56:28 +13:00
parent ab1e930ba3
commit cb1deacbb2
32 changed files with 83 additions and 79 deletions

View File

@@ -100,7 +100,7 @@ namespace OpenRA.Graphics
renderer.BeginFrame(scrollPosition); renderer.BeginFrame(scrollPosition);
wr.Draw(); wr.Draw();
Widget.DoDraw(world); Widget.DoDraw();
var cursorName = Widget.RootWidget.GetCursorOuter(Viewport.LastMousePos) ?? "default"; var cursorName = Widget.RootWidget.GetCursorOuter(Viewport.LastMousePos) ?? "default";
var c = new Cursor(cursorName); var c = new Cursor(cursorName);

View File

@@ -105,7 +105,7 @@ namespace OpenRA.Graphics
world.OrderGenerator.RenderAfterWorld(this, world); world.OrderGenerator.RenderAfterWorld(this, world);
if (world.LocalPlayer != null) if (world.LocalPlayer != null)
world.LocalPlayer.Shroud.Draw(); world.LocalPlayer.Shroud.Draw( this );
Game.Renderer.DisableScissor(); Game.Renderer.DisableScissor();
} }

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Network
if( packet.Length == 5 && packet[ 4 ] == 0xBF ) if( packet.Length == 5 && packet[ 4 ] == 0xBF )
frameData.ClientQuit( clientId, frame ); frameData.ClientQuit( clientId, frame );
else if( packet.Length >= 5 && packet[ 4 ] == 0x65 ) else if( packet.Length >= 5 && packet[ 4 ] == 0x65 )
CheckSync( packet ); CheckSync( world, packet );
else if( frame == 0 ) else if( frame == 0 )
immediatePackets.Add( Pair.New( clientId, packet ) ); immediatePackets.Add( Pair.New( clientId, packet ) );
else else
@@ -94,7 +94,7 @@ namespace OpenRA.Network
Dictionary<int, byte[]> syncForFrame = new Dictionary<int, byte[]>(); Dictionary<int, byte[]> syncForFrame = new Dictionary<int, byte[]>();
void CheckSync(byte[] packet) void CheckSync(World world, byte[] packet)
{ {
var frame = BitConverter.ToInt32(packet, 0); var frame = BitConverter.ToInt32(packet, 0);
byte[] existingSync; byte[] existingSync;
@@ -116,7 +116,7 @@ namespace OpenRA.Network
if (i < SyncHeaderSize) if (i < SyncHeaderSize)
OutOfSync(frame, "Tick"); OutOfSync(frame, "Tick");
else else
OutOfSync(frame, (i - SyncHeaderSize) / 4); OutOfSync(world, frame, (i - SyncHeaderSize) / 4);
} }
} }
} }
@@ -125,9 +125,9 @@ namespace OpenRA.Network
syncForFrame.Add(frame, packet); syncForFrame.Add(frame, packet);
} }
void OutOfSync(int frame, int index) void OutOfSync( World world, int frame, int index)
{ {
var order = frameData.OrdersForFrame( Game.world, frame ).ElementAt(index); var order = frameData.OrdersForFrame( world, frame ).ElementAt(index);
throw new InvalidOperationException("Out of sync in frame {0}.\n {1}".F(frame, order.Order.ToString())); throw new InvalidOperationException("Out of sync in frame {0}.\n {1}".F(frame, order.Order.ToString()));
} }
@@ -166,9 +166,9 @@ namespace OpenRA.Network
var ss = sync.SerializeSync( FrameNumber ); var ss = sync.SerializeSync( FrameNumber );
Connection.Send( ss ); Connection.Send( ss );
syncReport.UpdateSyncReport(); syncReport.UpdateSyncReport( world );
CheckSync( ss ); CheckSync( world, ss );
++FrameNumber; ++FrameNumber;
} }

View File

@@ -19,21 +19,21 @@ namespace OpenRA.Network
syncReports[i] = new SyncReport.Report(); syncReports[i] = new SyncReport.Report();
} }
internal void UpdateSyncReport() internal void UpdateSyncReport( World world )
{ {
if (!Game.Settings.Debug.RecordSyncReports) if (!Game.Settings.Debug.RecordSyncReports)
return; return;
GenerateSyncReport(syncReports[curIndex]); GenerateSyncReport(world, syncReports[curIndex]);
curIndex = ++curIndex % numSyncReports; curIndex = ++curIndex % numSyncReports;
} }
void GenerateSyncReport(Report report) void GenerateSyncReport(World world, Report report)
{ {
report.Frame = Game.orderManager.FrameNumber; report.Frame = Game.orderManager.FrameNumber;
report.SyncedRandom = Game.world.SharedRandom.Last; report.SyncedRandom = world.SharedRandom.Last;
report.Traits.Clear(); report.Traits.Clear();
foreach (var a in Game.world.Queries.WithTraitMultiple<object>()) foreach (var a in world.Queries.WithTraitMultiple<object>())
{ {
var sync = Sync.CalculateSyncHash(a.Trait); var sync = Sync.CalculateSyncHash(a.Trait);
if (sync != 0) if (sync != 0)

View File

@@ -127,7 +127,7 @@ namespace OpenRA
return shadowBits[SpecialShroudTiles[u ^ uSides][v]]; return shadowBits[SpecialShroudTiles[u ^ uSides][v]];
} }
internal void Draw() internal void Draw( WorldRenderer wr )
{ {
if (disabled) if (disabled)
return; return;
@@ -150,13 +150,13 @@ namespace OpenRA
var minx = clipRect.Left; var minx = clipRect.Left;
var maxx = clipRect.Right; var maxx = clipRect.Right;
DrawShroud( minx, miny, maxx, maxy, fogSprites, "fog" ); DrawShroud( wr, minx, miny, maxx, maxy, fogSprites, "fog" );
DrawShroud( minx, miny, maxx, maxy, sprites, "shroud" ); DrawShroud( wr, minx, miny, maxx, maxy, sprites, "shroud" );
} }
void DrawShroud( int minx, int miny, int maxx, int maxy, Sprite[,] s, string pal ) void DrawShroud( WorldRenderer wr, int minx, int miny, int maxx, int maxy, Sprite[,] s, string pal )
{ {
var shroudPalette = Game.world.WorldRenderer.GetPaletteIndex(pal); var shroudPalette = wr.GetPaletteIndex(pal);
for (var j = miny; j < maxy; j++) for (var j = miny; j < maxy; j++)
{ {

View File

@@ -14,7 +14,7 @@ namespace OpenRA.Widgets
{ {
public readonly string Background = "dialog"; public readonly string Background = "dialog";
public override void DrawInner(World world) public override void DrawInner()
{ {
WidgetUtils.DrawPanel(Background, RenderBounds); WidgetUtils.DrawPanel(Background, RenderBounds);
} }

View File

@@ -62,7 +62,7 @@ namespace OpenRA.Widgets
return Depressed; return Depressed;
} }
public override void DrawInner(World world) public override void DrawInner()
{ {
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont; var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0); var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Widgets
: base(widget) { } : base(widget) { }
public override Rectangle EventBounds { get { return Rectangle.Empty; } } public override Rectangle EventBounds { get { return Rectangle.Empty; } }
public override void DrawInner(World world) public override void DrawInner()
{ {
var pos = RenderOrigin; var pos = RenderOrigin;
var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height); var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);

View File

@@ -24,7 +24,7 @@ namespace OpenRA.Widgets
bool composing = false; bool composing = false;
bool teamChat = false; bool teamChat = false;
public override void DrawInner(World world) public override void DrawInner()
{ {
if (composing) if (composing)
{ {

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Widgets
public bool Bold = false; public bool Bold = false;
public Func<bool> Checked = () => false; public Func<bool> Checked = () => false;
public override void DrawInner(World world) public override void DrawInner()
{ {
var font = Bold ? Game.Renderer.BoldFont : Game.Renderer.RegularFont; var font = Bold ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;
var pos = RenderOrigin; var pos = RenderOrigin;

View File

@@ -34,7 +34,7 @@ namespace OpenRA.Widgets
return new ColorBlockWidget(this); return new ColorBlockWidget(this);
} }
public override void DrawInner(World world) public override void DrawInner()
{ {
WidgetUtils.FillRectWithColor(RenderBounds, GetColor()); WidgetUtils.FillRectWithColor(RenderBounds, GetColor());
} }

View File

@@ -38,7 +38,7 @@ namespace OpenRA.Widgets
public override Widget Clone() { return new ImageWidget(this); } public override Widget Clone() { return new ImageWidget(this); }
public override void DrawInner(World world) public override void DrawInner()
{ {
var name = GetImageName(); var name = GetImageName();
var collection = GetImageCollection(); var collection = GetImageCollection();

View File

@@ -43,7 +43,7 @@ namespace OpenRA.Widgets
GetBackground = other.GetBackground; GetBackground = other.GetBackground;
} }
public override void DrawInner(World world) public override void DrawInner()
{ {
var bg = GetBackground(); var bg = GetBackground();

View File

@@ -44,8 +44,8 @@ namespace OpenRA.Widgets
DownPressed = other.DownPressed; DownPressed = other.DownPressed;
} }
public override void DrawInner(World world) {} public override void DrawInner() {}
public override void Draw(World world) public override void Draw()
{ {
if (!IsVisible()) if (!IsVisible())
return; return;
@@ -74,7 +74,7 @@ namespace OpenRA.Widgets
Game.Renderer.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight); Game.Renderer.EnableScissor(backgroundRect.X, backgroundRect.Y + HeaderHeight, backgroundRect.Width, backgroundRect.Height - HeaderHeight);
foreach (var child in Children) foreach (var child in Children)
child.Draw(world); child.Draw();
Game.Renderer.DisableScissor(); Game.Renderer.DisableScissor();
} }

View File

@@ -71,7 +71,7 @@ namespace OpenRA.Widgets
static Sprite UnownedSpawn = null; static Sprite UnownedSpawn = null;
static Sprite OwnedSpawn = null; static Sprite OwnedSpawn = null;
public override void DrawInner( World world ) public override void DrawInner()
{ {
if (UnownedSpawn == null) if (UnownedSpawn == null)
UnownedSpawn = ChromeProvider.GetImage("spawnpoints", "unowned"); UnownedSpawn = ChromeProvider.GetImage("spawnpoints", "unowned");

View File

@@ -18,7 +18,7 @@ namespace OpenRA.Widgets
{ {
public PerfGraphWidget() : base() { } public PerfGraphWidget() : base() { }
public override void DrawInner(World world) public override void DrawInner()
{ {
var rect = RenderBounds; var rect = RenderBounds;
float2 origin = Game.viewport.Location + new float2(rect.Right, rect.Bottom); float2 origin = Game.viewport.Location + new float2(rect.Right, rect.Bottom);

View File

@@ -93,7 +93,7 @@ namespace OpenRA.Widgets
Text = Text.Replace("\r", ""); Text = Text.Replace("\r", "");
} }
public override void DrawInner(World world) public override void DrawInner()
{ {
var bg = GetBackground(); var bg = GetBackground();

View File

@@ -48,7 +48,7 @@ namespace OpenRA.Widgets
Sprite sprite = null; Sprite sprite = null;
string cachedImage = null; string cachedImage = null;
int cachedFrame= -1; int cachedFrame= -1;
public override void DrawInner(World world) public override void DrawInner()
{ {
var image = GetImage(); var image = GetImage();
var frame = GetFrame(); var frame = GetFrame();

View File

@@ -165,7 +165,7 @@ namespace OpenRA.Widgets
} }
} }
public override void DrawInner(World world) public override void DrawInner()
{ {
if (!IsVisible()) if (!IsVisible())
return; return;

View File

@@ -107,7 +107,7 @@ namespace OpenRA.Widgets
base.Tick(world); base.Tick(world);
} }
public override void DrawInner(World world) public override void DrawInner()
{ {
int margin = 5; int margin = 5;
var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont; var font = (Bold) ? Game.Renderer.BoldFont : Game.Renderer.RegularFont;

View File

@@ -1,11 +1,11 @@
#region Copyright & License Information #region Copyright & License Information
/* /*
* Copyright 2007-2010 The OpenRA Developers (see AUTHORS) * Copyright 2007-2010 The OpenRA Developers (see AUTHORS)
* This file is part of OpenRA, which is free software. It is made * 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 * available to you under the terms of the GNU General Public License
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
* see LICENSE. * see LICENSE.
*/ */
#endregion #endregion
using System.Drawing; using System.Drawing;
@@ -20,13 +20,13 @@ namespace OpenRA.Widgets
public TimerWidget () public TimerWidget ()
{ {
IsVisible = () => Game.Settings.Game.MatchTimer; IsVisible = () => Game.Settings.Game.MatchTimer;
} }
public override void DrawInner(World world) public override void DrawInner()
{ {
var s = WorldUtils.FormatTime(Game.LocalTick); var s = WorldUtils.FormatTime(Game.LocalTick);
var size = Game.Renderer.TitleFont.Measure(s); var size = Game.Renderer.TitleFont.Measure(s);
Game.Renderer.TitleFont.DrawText(s, new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top - 20), Color.White); Game.Renderer.TitleFont.DrawText(s, new float2(RenderBounds.Left - size.X / 2, RenderBounds.Top - 20), Color.White);
} }
} }
} }

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Widgets
public ViewportScrollControllerWidget() : base() { } public ViewportScrollControllerWidget() : base() { }
protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget) : base(widget) {} protected ViewportScrollControllerWidget(ViewportScrollControllerWidget widget) : base(widget) {}
public override void DrawInner( World world ) {} public override void DrawInner() {}
public override bool HandleInputInner(MouseInput mi) public override bool HandleInputInner(MouseInput mi)
{ {

View File

@@ -6,11 +6,11 @@
* as published by the Free Software Foundation. For more information, * as published by the Free Software Foundation. For more information,
* see LICENSE. * see LICENSE.
*/ */
#endregion #endregion
using System; using System;
using System.Drawing; using System.Drawing;
using OpenRA.FileFormats; using OpenRA.FileFormats;
using OpenRA.Graphics; using OpenRA.Graphics;
using OpenRA.Support; using OpenRA.Support;
@@ -69,8 +69,8 @@ namespace OpenRA.Widgets
overlaySprite.sheet.Texture.SetData(overlay); overlaySprite.sheet.Texture.SetData(overlay);
} }
public override void DrawInner(World world) public override void DrawInner()
{ {
if (video == null) if (video == null)
return; return;

View File

@@ -269,15 +269,15 @@ namespace OpenRA.Widgets
return false; return false;
} }
public abstract void DrawInner( World world ); public abstract void DrawInner();
public virtual void Draw(World world) public virtual void Draw()
{ {
if (IsVisible()) if (IsVisible())
{ {
DrawInner( world ); DrawInner();
foreach (var child in Children) foreach (var child in Children)
child.Draw(world); child.Draw();
} }
} }
@@ -344,9 +344,9 @@ namespace OpenRA.Widgets
++Viewport.TicksSinceLastMove; ++Viewport.TicksSinceLastMove;
} }
public static void DoDraw(World world) public static void DoDraw()
{ {
RootWidget.Draw(world); RootWidget.Draw();
} }
} }
@@ -355,7 +355,7 @@ namespace OpenRA.Widgets
public ContainerWidget(Widget other) : base(other) { } public ContainerWidget(Widget other) : base(other) { }
public override void DrawInner( World world ) { } public override void DrawInner() { }
public override string GetCursor(int2 pos) { return null; } public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new ContainerWidget(this); } public override Widget Clone() { return new ContainerWidget(this); }

View File

@@ -26,7 +26,7 @@ namespace OpenRA.Widgets
this.world = world; this.world = world;
} }
public override void DrawInner( World world ) public override void DrawInner()
{ {
var selbox = SelectionBox; var selbox = SelectionBox;
if (selbox == null) return; if (selbox == null) return;

View File

@@ -20,8 +20,9 @@ namespace OpenRA.Widgets
{ {
public int TooltipDelay = 10; public int TooltipDelay = 10;
public WorldTooltipWidget() : base() { } public WorldTooltipWidget() : base() { }
public override void DrawInner(World world) public override void DrawInner()
{ {
var world = Game.world;
if (Viewport.TicksSinceLastMove < TooltipDelay || world == null || world.LocalPlayer == null) if (Viewport.TicksSinceLastMove < TooltipDelay || world == null || world.LocalPlayer == null)
return; return;

View File

@@ -47,11 +47,11 @@ namespace OpenRA.Mods.RA.Widgets
public readonly string BuildPaletteClose = "bleep13.aud"; public readonly string BuildPaletteClose = "bleep13.aud";
public readonly string TabClick = "ramenu1.aud"; public readonly string TabClick = "ramenu1.aud";
readonly World world; readonly World world;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public BuildPaletteWidget( [ObjectCreator.Param] World world ) public BuildPaletteWidget( [ObjectCreator.Param] World world )
{ {
this.world = world; this.world = world;
} }
public override void Initialize() public override void Initialize()
@@ -176,7 +176,7 @@ namespace OpenRA.Mods.RA.Widgets
int paletteHeight = 0; int paletteHeight = 0;
int numActualRows = 0; int numActualRows = 0;
public override void DrawInner(World world) public override void DrawInner()
{ {
if (!IsVisible()) return; if (!IsVisible()) return;
// todo: fix // todo: fix

View File

@@ -21,8 +21,9 @@ namespace OpenRA.Mods.RA.Widgets
public MoneyBinWidget() : base() { } public MoneyBinWidget() : base() { }
public override void DrawInner(World world) public override void DrawInner()
{ {
var world = Game.world;
if( world.LocalPlayer == null ) return; if( world.LocalPlayer == null ) return;
var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>(); var playerResources = world.LocalPlayer.PlayerActor.Trait<PlayerResources>();

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Widgets
GetLongDesc = () => LongDesc; GetLongDesc = () => LongDesc;
} }
public override void DrawInner (World world) public override void DrawInner()
{ {
var image = ChromeProvider.GetImage(Image + "-button", GetImage()); var image = ChromeProvider.GetImage(Image + "-button", GetImage());
var rect = new Rectangle(RenderBounds.X, RenderBounds.Y, (int)image.size.X, (int)image.size.Y); var rect = new Rectangle(RenderBounds.X, RenderBounds.Y, (int)image.size.X, (int)image.size.Y);

View File

@@ -25,8 +25,9 @@ namespace OpenRA.Mods.RA.Widgets
float? lastPowerDrainedPos; float? lastPowerDrainedPos;
string powerCollection; string powerCollection;
public override void DrawInner(World world) public override void DrawInner()
{ {
var world = Game.world;
if( world.LocalPlayer == null ) return; if( world.LocalPlayer == null ) return;
powerCollection = "power-" + world.LocalPlayer.Country.Race; powerCollection = "power-" + world.LocalPlayer.Country.Race;

View File

@@ -119,7 +119,7 @@ namespace OpenRA.Mods.RA.Widgets
get { return new Rectangle((int)mapRect.X, (int)mapRect.Y, (int)mapRect.Width, (int)mapRect.Height);} get { return new Rectangle((int)mapRect.X, (int)mapRect.Y, (int)mapRect.Width, (int)mapRect.Height);}
} }
public override void DrawInner(World world) public override void DrawInner()
{ {
if( world.LocalPlayer == null ) return; if( world.LocalPlayer == null ) return;

View File

@@ -63,8 +63,9 @@ namespace OpenRA.Mods.RA.Widgets
return false; return false;
} }
public override void DrawInner(World world) public override void DrawInner()
{ {
var world = Game.world;
buttons.Clear(); buttons.Clear();
if( world.LocalPlayer == null ) return; if( world.LocalPlayer == null ) return;