Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BotModule sync check debug setting. #15942

Merged
merged 5 commits into from
Dec 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions OpenRA.Game/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ static void InnerLogicTick(OrderManager orderManager)
var integralTickTimestep = (uiTickDelta / Timestep) * Timestep;
Ui.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : Timestep;

Sync.CheckSyncUnchanged(world, Ui.Tick);
Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, Ui.Tick);
Cursor.Tick();
}

Expand All @@ -588,7 +588,7 @@ static void InnerLogicTick(OrderManager orderManager)
orderManager.LastTickTime += integralTickTimestep >= TimestepJankThreshold ? integralTickTimestep : worldTimestep;

Sound.Tick();
Sync.CheckSyncUnchanged(world, orderManager.TickImmediate);
Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, orderManager.TickImmediate);

if (world == null)
return;
Expand All @@ -607,7 +607,7 @@ static void InnerLogicTick(OrderManager orderManager)
if (isNetTick)
orderManager.Tick();

Sync.CheckSyncUnchanged(world, () =>
Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () =>
{
world.OrderGenerator.Tick(world);
world.Selection.Tick(world);
Expand All @@ -622,7 +622,7 @@ static void InnerLogicTick(OrderManager orderManager)

// Wait until we have done our first world Tick before TickRendering
if (orderManager.LocalFrameNumber > 0)
Sync.CheckSyncUnchanged(world, () => world.TickRender(worldRenderer));
Sync.RunUnsynced(Settings.Debug.SyncCheckUnsyncedCode, world, () => world.TickRender(worldRenderer));
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions OpenRA.Game/Input/InputHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ public void ModifierKeys(Modifiers mods)

public void OnKeyInput(KeyInput input)
{
Sync.CheckSyncUnchanged(world, () => Ui.HandleKeyPress(input));
Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, () => Ui.HandleKeyPress(input));
}

public void OnTextInput(string text)
{
Sync.CheckSyncUnchanged(world, () => Ui.HandleTextInput(text));
Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, () => Ui.HandleTextInput(text));
}

public void OnMouseInput(MouseInput input)
{
Sync.CheckSyncUnchanged(world, () => Ui.HandleInput(input));
Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, () => Ui.HandleInput(input));
}
}

Expand Down
40 changes: 31 additions & 9 deletions OpenRA.Game/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,28 +87,50 @@ public ServerSettings Clone()

public class DebugSettings
{
public bool BotDebug = false;
public bool LuaDebug = false;
[Desc("Display average FPS and tick/render times")]
public bool PerfText = false;
public bool PerfGraph = false;

[Desc("Amount of time required for triggering perf.log output.")]
public float LongTickThresholdMs = 1;
[Desc("Display a graph with various profiling traces")]
public bool PerfGraph = false;

public bool SanityCheckUnsyncedCode = false;
[Desc("Numer of samples to average over when calculating tick and render times.")]
public int Samples = 25;

public bool StrictActivityChecking = false;

[Desc("Check whether a newer version is available online.")]
public bool CheckVersion = true;

[Desc("Allow the collection of anonymous data such as Operating System, .NET runtime, OpenGL version and language settings.")]
public bool SendSystemInformation = true;

[Desc("Version of sysinfo that the player last opted in or out of.")]
public int SystemInformationVersionPrompt = 0;
public string UUID = System.Guid.NewGuid().ToString();

[Desc("Sysinfo anonymous user identifier.")]
public string UUID = Guid.NewGuid().ToString();

[Desc("Enable hidden developer settings in the Advanced settings tab.")]
public bool DisplayDeveloperSettings = false;

[Desc("Display bot debug messages in the game chat.")]
public bool BotDebug = false;

[Desc("Display Lua debug messages in the game chat.")]
public bool LuaDebug = false;

[Desc("Enable the chat field during replays to allow use of console commands.")]
public bool EnableDebugCommandsInReplays = false;

[Desc("Amount of time required for triggering perf.log output.")]
public float LongTickThresholdMs = 1;

[Desc("Throw an exception if the world sync hash changes while evaluating user input.")]
public bool SyncCheckUnsyncedCode = false;

[Desc("Throw an exception if the world sync hash changes while evaluating BotModules.")]
public bool SyncCheckBotModuleCode = false;

[Desc("Throw an exception if an actor activity is ticked after it has been marked as completed.")]
public bool StrictActivityChecking = false;
}

public class GraphicSettings
Expand Down
13 changes: 6 additions & 7 deletions OpenRA.Game/Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,19 @@ public static int HashUsingHashCode<T>(T t)
return t.GetHashCode();
}

public static void CheckSyncUnchanged(World world, Action fn)
public static void RunUnsynced(bool checkSyncHash, World world, Action fn)
{
CheckSyncUnchanged(world, () => { fn(); return true; });
RunUnsynced(checkSyncHash, world, () => { fn(); return true; });
}

static bool inUnsyncedCode = false;

public static T CheckSyncUnchanged<T>(World world, Func<T> fn)
public static T RunUnsynced<T>(bool checkSyncHash, World world, Func<T> fn)
{
if (world == null)
return fn();

var shouldCheckSync = Game.Settings.Debug.SanityCheckUnsyncedCode;
var sync = shouldCheckSync ? world.SyncHash() : 0;
var sync = checkSyncHash ? world.SyncHash() : 0;
var prevInUnsyncedCode = inUnsyncedCode;
inUnsyncedCode = true;

Expand All @@ -185,8 +184,8 @@ public static T CheckSyncUnchanged<T>(World world, Func<T> fn)
finally
{
inUnsyncedCode = prevInUnsyncedCode;
if (shouldCheckSync && sync != world.SyncHash())
throw new InvalidOperationException("CheckSyncUnchanged: sync-changing code may not run here");
if (checkSyncHash && sync != world.SyncHash())
throw new InvalidOperationException("RunUnsynced: sync-changing code may not run here");
}
}

Expand Down
36 changes: 23 additions & 13 deletions OpenRA.Mods.Common/AI/HackyAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,15 @@ void ITick.Tick(Actor self)

AssignRolesToIdleUnits(self);

// TODO: Add an option to include this in CheckSyncUnchanged.
// Checking sync for this is too expensive to include it by default,
// so it should be implemented as separate sub-option checkbox.
using (new PerfSample("bot_tick"))
foreach (var t in tickModules)
if (t.IsTraitEnabled())
t.BotTick(this);
{
Sync.RunUnsynced(Game.Settings.Debug.SyncCheckBotModuleCode, World, () =>
{
foreach (var t in tickModules)
if (t.IsTraitEnabled())
t.BotTick(this);
});
}

var ordersToIssueThisTick = Math.Min((orders.Count + Info.MinOrderQuotientPerTick - 1) / Info.MinOrderQuotientPerTick, orders.Count);
for (var i = 0; i < ordersToIssueThisTick; i++)
Expand Down Expand Up @@ -543,11 +545,14 @@ void InitializeBase(Actor self, bool chooseLocation)
if (mcv == null)
return;

foreach (var n in positionsUpdatedModules)
Sync.RunUnsynced(Game.Settings.Debug.SyncCheckBotModuleCode, World, () =>
{
n.UpdatedBaseCenter(mcv.Location);
n.UpdatedDefenseCenter(mcv.Location);
}
foreach (var n in positionsUpdatedModules)
{
n.UpdatedBaseCenter(mcv.Location);
n.UpdatedDefenseCenter(mcv.Location);
}
});
}

void IBotPositionsUpdated.UpdatedBaseCenter(CPos newLocation)
Expand Down Expand Up @@ -650,9 +655,14 @@ void INotifyDamage.Damaged(Actor self, AttackInfo e)
// Checking sync for this is too expensive to include it by default,
// so it should be implemented as separate sub-option checkbox.
using (new PerfSample("bot_attack_response"))
foreach (var t in attackResponseModules)
if (t.IsTraitEnabled())
t.RespondToAttack(this, self, e);
{
Sync.RunUnsynced(Game.Settings.Debug.SyncCheckBotModuleCode, World, () =>
{
foreach (var t in attackResponseModules)
if (t.IsTraitEnabled())
t.RespondToAttack(this, self, e);
});
}

if (e.Attacker == null || e.Attacker.Disposed)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public LoadIngamePlayerOrObserverUILogic(Widget widget, World world)

var optionsButton = playerRoot.GetOrNull<MenuButtonWidget>("OPTIONS_BUTTON");
if (optionsButton != null)
Sync.CheckSyncUnchanged(world, optionsButton.OnClick);
Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, world, optionsButton.OnClick);
};
}
}
Expand Down
19 changes: 14 additions & 5 deletions OpenRA.Mods.Common/Widgets/Logic/SettingsLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -480,20 +480,28 @@ Action InitAdvancedPanel(Widget panel)
var ss = Game.Settings.Server;
var gs = Game.Settings.Game;

// Advanced
BindCheckboxPref(panel, "NAT_DISCOVERY", ss, "DiscoverNatDevices");
BindCheckboxPref(panel, "PERFTEXT_CHECKBOX", ds, "PerfText");
BindCheckboxPref(panel, "PERFGRAPH_CHECKBOX", ds, "PerfGraph");
BindCheckboxPref(panel, "CHECKUNSYNCED_CHECKBOX", ds, "SanityCheckUnsyncedCode");
BindCheckboxPref(panel, "BOTDEBUG_CHECKBOX", ds, "BotDebug");
BindCheckboxPref(panel, "FETCH_NEWS_CHECKBOX", gs, "FetchNews");
BindCheckboxPref(panel, "LUADEBUG_CHECKBOX", ds, "LuaDebug");
BindCheckboxPref(panel, "SENDSYSINFO_CHECKBOX", ds, "SendSystemInformation");
BindCheckboxPref(panel, "CHECK_VERSION_CHECKBOX", ds, "CheckVersion");
BindCheckboxPref(panel, "REPLAY_COMMANDS_CHECKBOX", ds, "EnableDebugCommandsInReplays");

var ssi = panel.Get<CheckboxWidget>("SENDSYSINFO_CHECKBOX");
ssi.IsDisabled = () => !gs.FetchNews;

// Developer
BindCheckboxPref(panel, "BOTDEBUG_CHECKBOX", ds, "BotDebug");
BindCheckboxPref(panel, "LUADEBUG_CHECKBOX", ds, "LuaDebug");
BindCheckboxPref(panel, "REPLAY_COMMANDS_CHECKBOX", ds, "EnableDebugCommandsInReplays");
BindCheckboxPref(panel, "CHECKUNSYNCED_CHECKBOX", ds, "SyncCheckUnsyncedCode");
BindCheckboxPref(panel, "CHECKBOTSYNC_CHECKBOX", ds, "SyncCheckBotModuleCode");
BindCheckboxPref(panel, "STRICTACTIVITY_CHECKBOX", ds, "StrictActivityChecking");

panel.Get("DEBUG_OPTIONS").IsVisible = () => ds.DisplayDeveloperSettings;
panel.Get("DEBUG_HIDDEN_LABEL").IsVisible = () => !ds.DisplayDeveloperSettings;

return () => { };
}

Expand All @@ -509,7 +517,8 @@ Action ResetAdvancedPanel(Widget panel)
ss.DiscoverNatDevices = dss.DiscoverNatDevices;
ds.PerfText = dds.PerfText;
ds.PerfGraph = dds.PerfGraph;
ds.SanityCheckUnsyncedCode = dds.SanityCheckUnsyncedCode;
ds.SyncCheckUnsyncedCode = dds.SyncCheckUnsyncedCode;
ds.SyncCheckBotModuleCode = dds.SyncCheckBotModuleCode;
ds.BotDebug = dds.BotDebug;
ds.LuaDebug = dds.LuaDebug;
ds.SendSystemInformation = dds.SendSystemInformation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ void ApplyOrders(World world, MouseInput mi)

public override string GetCursor(int2 screenPos)
{
return Sync.CheckSyncUnchanged(World, () =>
return Sync.RunUnsynced(Game.Settings.Debug.SyncCheckUnsyncedCode, World, () =>
{
// Always show an arrow while selecting
if (IsValidDragbox)
Expand Down
91 changes: 63 additions & 28 deletions mods/cnc/chrome/settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -571,36 +571,71 @@ Container@SETTINGS_PANEL:
Y: 200
Width: PARENT_RIGHT
Font: Bold
Text: Debug
Text: Developer
Align: Center
Checkbox@BOTDEBUG_CHECKBOX:
X: 15
Y: 220
Width: 300
Height: 20
Font: Regular
Text: Show Bot Debug Messages
Checkbox@CHECKUNSYNCED_CHECKBOX:
X: 15
Container@DEBUG_HIDDEN_LABEL:
Y: 250
Width: 300
Height: 20
Font: Regular
Text: Check Sync around Unsynced Code
Checkbox@LUADEBUG_CHECKBOX:
X: 310
Y: 220
Width: 300
Height: 20
Font: Regular
Text: Show Map Debug Messages
Checkbox@REPLAY_COMMANDS_CHECKBOX:
X: 310
Y: 250
Width: 300
Height: 20
Font: Regular
Text: Enable Debug Commands in Replays
Width: PARENT_RIGHT
Children:
Label@A:
Width: PARENT_RIGHT
Height: 20
Font: Regular
Text: Additional developer-specific options can be enabled via the
Align: Center
Label@B:
Y: 20
Width: PARENT_RIGHT
Height: 20
Font: Regular
Text: Debug.DisplayDeveloperSettings setting or launch flag
Align: Center
Container@DEBUG_OPTIONS:
Width: PARENT_RIGHT
Height: PARENT_BOTTOM
Children:
Checkbox@BOTDEBUG_CHECKBOX:
X: 15
Y: 220
Width: 300
Height: 20
Font: Regular
Text: Show Bot Debug Messages
Checkbox@CHECKUNSYNCED_CHECKBOX:
X: 15
Y: 250
Width: 300
Height: 20
Font: Regular
Text: Check Sync around Unsynced Code
Checkbox@CHECKBOTSYNC_CHECKBOX:
X: 15
Y: 280
Width: 300
Height: 20
Font: Regular
Text: Check Sync around BotModule Code
Checkbox@LUADEBUG_CHECKBOX:
X: 310
Y: 220
Width: 300
Height: 20
Font: Regular
Text: Show Map Debug Messages
Checkbox@REPLAY_COMMANDS_CHECKBOX:
X: 310
Y: 250
Width: 300
Height: 20
Font: Regular
Text: Enable Debug Commands in Replays
Checkbox@STRICTACTIVITY_CHECKBOX:
X: 310
Y: 280
Width: 300
Height: 20
Font: Regular
Text: Strict Activity checking
Button@BACK_BUTTON:
Key: escape
Y: 393
Expand Down
Loading