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);
wr.Draw();
Widget.DoDraw(world);
Widget.DoDraw();
var cursorName = Widget.RootWidget.GetCursorOuter(Viewport.LastMousePos) ?? "default";
var c = new Cursor(cursorName);

View File

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

View File

@@ -80,7 +80,7 @@ namespace OpenRA.Network
if( packet.Length == 5 && packet[ 4 ] == 0xBF )
frameData.ClientQuit( clientId, frame );
else if( packet.Length >= 5 && packet[ 4 ] == 0x65 )
CheckSync( packet );
CheckSync( world, packet );
else if( frame == 0 )
immediatePackets.Add( Pair.New( clientId, packet ) );
else
@@ -94,7 +94,7 @@ namespace OpenRA.Network
Dictionary<int, byte[]> syncForFrame = new Dictionary<int, byte[]>();
void CheckSync(byte[] packet)
void CheckSync(World world, byte[] packet)
{
var frame = BitConverter.ToInt32(packet, 0);
byte[] existingSync;
@@ -116,7 +116,7 @@ namespace OpenRA.Network
if (i < SyncHeaderSize)
OutOfSync(frame, "Tick");
else
OutOfSync(frame, (i - SyncHeaderSize) / 4);
OutOfSync(world, frame, (i - SyncHeaderSize) / 4);
}
}
}
@@ -125,9 +125,9 @@ namespace OpenRA.Network
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()));
}
@@ -166,9 +166,9 @@ namespace OpenRA.Network
var ss = sync.SerializeSync( FrameNumber );
Connection.Send( ss );
syncReport.UpdateSyncReport();
syncReport.UpdateSyncReport( world );
CheckSync( ss );
CheckSync( world, ss );
++FrameNumber;
}

View File

@@ -19,21 +19,21 @@ namespace OpenRA.Network
syncReports[i] = new SyncReport.Report();
}
internal void UpdateSyncReport()
internal void UpdateSyncReport( World world )
{
if (!Game.Settings.Debug.RecordSyncReports)
return;
GenerateSyncReport(syncReports[curIndex]);
GenerateSyncReport(world, syncReports[curIndex]);
curIndex = ++curIndex % numSyncReports;
}
void GenerateSyncReport(Report report)
void GenerateSyncReport(World world, Report report)
{
report.Frame = Game.orderManager.FrameNumber;
report.SyncedRandom = Game.world.SharedRandom.Last;
report.SyncedRandom = world.SharedRandom.Last;
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);
if (sync != 0)

View File

@@ -127,7 +127,7 @@ namespace OpenRA
return shadowBits[SpecialShroudTiles[u ^ uSides][v]];
}
internal void Draw()
internal void Draw( WorldRenderer wr )
{
if (disabled)
return;
@@ -150,13 +150,13 @@ namespace OpenRA
var minx = clipRect.Left;
var maxx = clipRect.Right;
DrawShroud( minx, miny, maxx, maxy, fogSprites, "fog" );
DrawShroud( minx, miny, maxx, maxy, sprites, "shroud" );
DrawShroud( wr, minx, miny, maxx, maxy, fogSprites, "fog" );
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++)
{

View File

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

View File

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

View File

@@ -32,7 +32,7 @@ namespace OpenRA.Widgets
: base(widget) { }
public override Rectangle EventBounds { get { return Rectangle.Empty; } }
public override void DrawInner(World world)
public override void DrawInner()
{
var pos = RenderOrigin;
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 teamChat = false;
public override void DrawInner(World world)
public override void DrawInner()
{
if (composing)
{

View File

@@ -21,7 +21,7 @@ namespace OpenRA.Widgets
public bool Bold = 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 pos = RenderOrigin;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -22,7 +22,7 @@ namespace OpenRA.Widgets
IsVisible = () => Game.Settings.Game.MatchTimer;
}
public override void DrawInner(World world)
public override void DrawInner()
{
var s = WorldUtils.FormatTime(Game.LocalTick);
var size = Game.Renderer.TitleFont.Measure(s);

View File

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

View File

@@ -69,7 +69,7 @@ namespace OpenRA.Widgets
overlaySprite.sheet.Texture.SetData(overlay);
}
public override void DrawInner(World world)
public override void DrawInner()
{
if (video == null)
return;

View File

@@ -269,15 +269,15 @@ namespace OpenRA.Widgets
return false;
}
public abstract void DrawInner( World world );
public abstract void DrawInner();
public virtual void Draw(World world)
public virtual void Draw()
{
if (IsVisible())
{
DrawInner( world );
DrawInner();
foreach (var child in Children)
child.Draw(world);
child.Draw();
}
}
@@ -344,9 +344,9 @@ namespace OpenRA.Widgets
++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 override void DrawInner( World world ) { }
public override void DrawInner() { }
public override string GetCursor(int2 pos) { return null; }
public override Widget Clone() { return new ContainerWidget(this); }

View File

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

View File

@@ -20,8 +20,9 @@ namespace OpenRA.Widgets
{
public int TooltipDelay = 10;
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)
return;

View File

@@ -176,7 +176,7 @@ namespace OpenRA.Mods.RA.Widgets
int paletteHeight = 0;
int numActualRows = 0;
public override void DrawInner(World world)
public override void DrawInner()
{
if (!IsVisible()) return;
// todo: fix

View File

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

View File

@@ -31,7 +31,7 @@ namespace OpenRA.Mods.RA.Widgets
GetLongDesc = () => LongDesc;
}
public override void DrawInner (World world)
public override void DrawInner()
{
var image = ChromeProvider.GetImage(Image + "-button", GetImage());
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;
string powerCollection;
public override void DrawInner(World world)
public override void DrawInner()
{
var world = Game.world;
if( world.LocalPlayer == null ) return;
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);}
}
public override void DrawInner(World world)
public override void DrawInner()
{
if( world.LocalPlayer == null ) return;

View File

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