diff --git a/OpenRA.Game/Primitives/CachedTransform.cs b/OpenRA.Game/Primitives/CachedTransform.cs new file mode 100644 index 0000000000..a1cf543d76 --- /dev/null +++ b/OpenRA.Game/Primitives/CachedTransform.cs @@ -0,0 +1,41 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * 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, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; + +namespace OpenRA.Primitives +{ + public class CachedTransform + { + readonly Func transform; + + bool initialized; + T lastInput; + U lastOutput; + + public CachedTransform(Func transform) + { + this.transform = transform; + } + + public U Update(T input) + { + if (initialized && ((input == null && lastInput == null) || (input != null && input.Equals(lastInput)))) + return lastOutput; + + lastInput = input; + lastOutput = transform(input); + initialized = true; + + return lastOutput; + } + } +} diff --git a/OpenRA.Game/Primitives/PredictedCachedTransform.cs b/OpenRA.Game/Primitives/PredictedCachedTransform.cs new file mode 100644 index 0000000000..dc6217f1e5 --- /dev/null +++ b/OpenRA.Game/Primitives/PredictedCachedTransform.cs @@ -0,0 +1,51 @@ +#region Copyright & License Information +/* + * Copyright (c) The OpenRA Developers and Contributors + * 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, either version 3 of + * the License, or (at your option) any later version. For more + * information, see COPYING. + */ +#endregion + +using System; + +namespace OpenRA.Primitives +{ + public class PredictedCachedTransform + { + readonly Func transform; + + bool initialized; + T lastInput; + U lastOutput; + + bool predicted; + U prediction; + + public PredictedCachedTransform(Func transform) + { + this.transform = transform; + } + + public void Predict(U value) + { + predicted = true; + prediction = value; + } + + public U Update(T input) + { + if ((predicted || initialized) && ((input == null && lastInput == null) || (input != null && input.Equals(lastInput)))) + return predicted ? prediction : lastOutput; + + predicted = false; + initialized = true; + lastInput = input; + lastOutput = transform(input); + + return lastOutput; + } + } +} diff --git a/OpenRA.Mods.Common/Traits/Render/WithTextControlGroupDecoration.cs b/OpenRA.Mods.Common/Traits/Render/WithTextControlGroupDecoration.cs index a1255a862b..2f69fe0cdd 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithTextControlGroupDecoration.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithTextControlGroupDecoration.cs @@ -13,7 +13,6 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Graphics; -using OpenRA.Mods.Common.Widgets; using OpenRA.Primitives; using OpenRA.Traits; diff --git a/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs b/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs index c20a1b61e5..b1331a1a5d 100644 --- a/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs +++ b/OpenRA.Mods.Common/Traits/World/TimeLimitManager.cs @@ -12,6 +12,7 @@ using System.Collections.Generic; using System.Linq; using OpenRA.Mods.Common.Widgets; +using OpenRA.Primitives; using OpenRA.Traits; using OpenRA.Widgets; diff --git a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs index aa52825639..9af0aad570 100644 --- a/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs +++ b/OpenRA.Mods.Common/Widgets/DropDownButtonWidget.cs @@ -13,6 +13,7 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Graphics; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets diff --git a/OpenRA.Mods.Common/Widgets/ImageWidget.cs b/OpenRA.Mods.Common/Widgets/ImageWidget.cs index 2558081087..425d1a9772 100644 --- a/OpenRA.Mods.Common/Widgets/ImageWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ImageWidget.cs @@ -11,6 +11,7 @@ using System; using OpenRA.Graphics; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugLogic.cs index 05ae19001f..d8eaae38ca 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugLogic.cs @@ -11,6 +11,7 @@ using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic.Ingame diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs index 6272561b9b..31ad307893 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/DebugMenuLogic.cs @@ -11,6 +11,7 @@ using System; using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; using OpenRA.Traits; using OpenRA.Widgets; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs index 4f4e00249c..53d7021dbd 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/GameTimerLogic.cs @@ -12,6 +12,7 @@ using System; using OpenRA.Mods.Common.Traits; using OpenRA.Network; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameCashCounterLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameCashCounterLogic.cs index daa9003fde..5c97eb05d0 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameCashCounterLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameCashCounterLogic.cs @@ -12,6 +12,7 @@ using System; using System.Globalization; using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs index 002fe47f56..d714ee4b9a 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/IngameChatLogic.cs @@ -15,6 +15,7 @@ using OpenRA.Mods.Common.Commands; using OpenRA.Mods.Common.Lint; using OpenRA.Mods.Common.Traits; using OpenRA.Network; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs index 20126bb270..54f08d4b6f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/DownloadPackageLogic.cs @@ -16,6 +16,7 @@ using System.Net.Http; using System.Threading; using System.Threading.Tasks; using OpenRA.FileSystem; +using OpenRA.Primitives; using OpenRA.Support; using OpenRA.Widgets; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromSourceLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromSourceLogic.cs index 943cf5c68a..0c391b9450 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromSourceLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Installation/InstallFromSourceLogic.cs @@ -15,6 +15,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using OpenRA.Mods.Common.Installer; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/Logic/IntroductionPromptLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/IntroductionPromptLogic.cs index 5bbc7371cb..7a34ef5f7b 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/IntroductionPromptLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/IntroductionPromptLogic.cs @@ -12,6 +12,7 @@ using System; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs index ef94ebf8a7..e4d174ab4e 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyLogic.cs @@ -15,6 +15,7 @@ using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; using OpenRA.Network; +using OpenRA.Primitives; using OpenRA.Traits; using OpenRA.Widgets; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs index 25de1151c5..e674b0186f 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/LobbyOptionsLogic.cs @@ -13,6 +13,7 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Network; +using OpenRA.Primitives; using OpenRA.Traits; using OpenRA.Widgets; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs index 75b0ca0028..8c2c1c2fb4 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/MapPreviewLogic.cs @@ -13,6 +13,7 @@ using System; using System.Collections.Generic; using System.Linq; using OpenRA.Network; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/Logic/Lobby/SpawnSelectorTooltipLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Lobby/SpawnSelectorTooltipLogic.cs index 771362f7fa..ea8cb2ec23 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Lobby/SpawnSelectorTooltipLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Lobby/SpawnSelectorTooltipLogic.cs @@ -11,6 +11,7 @@ using System; using System.Linq; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs index 2b68c50ab7..23a560d153 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/MapChooserLogic.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs index c671663d9e..763199512c 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/ReplayBrowserLogic.cs @@ -18,6 +18,7 @@ using System.Threading; using System.Threading.Tasks; using OpenRA.FileFormats; using OpenRA.Network; +using OpenRA.Primitives; using OpenRA.Traits; using OpenRA.Widgets; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs index ce31770756..4249ebd14d 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/AudioSettingsLogic.cs @@ -13,6 +13,7 @@ using System; using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs index ade63ee9aa..11989cb828 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/DisplaySettingsLogic.cs @@ -16,6 +16,7 @@ using System.Globalization; using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Traits; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs index 9796efa181..b447311f40 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Settings/InputSettingsLogic.cs @@ -11,6 +11,7 @@ using System; using System.Collections.Generic; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets.Logic diff --git a/OpenRA.Mods.Common/Widgets/ScrollItemWidget.cs b/OpenRA.Mods.Common/Widgets/ScrollItemWidget.cs index 965be627e7..bb72373b7b 100644 --- a/OpenRA.Mods.Common/Widgets/ScrollItemWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ScrollItemWidget.cs @@ -11,6 +11,7 @@ using System; using OpenRA.Graphics; +using OpenRA.Primitives; using OpenRA.Widgets; namespace OpenRA.Mods.Common.Widgets diff --git a/OpenRA.Mods.Common/Widgets/WidgetUtils.cs b/OpenRA.Mods.Common/Widgets/WidgetUtils.cs index 3ceaa541e1..a599d2fbf4 100644 --- a/OpenRA.Mods.Common/Widgets/WidgetUtils.cs +++ b/OpenRA.Mods.Common/Widgets/WidgetUtils.cs @@ -396,66 +396,4 @@ namespace OpenRA.Mods.Common.Widgets notificationWidget.Bounds.Width = boxWidth - notificationWidget.Bounds.X; } } - - public class CachedTransform - { - readonly Func transform; - - bool initialized; - T lastInput; - U lastOutput; - - public CachedTransform(Func transform) - { - this.transform = transform; - } - - public U Update(T input) - { - if (initialized && ((input == null && lastInput == null) || (input != null && input.Equals(lastInput)))) - return lastOutput; - - lastInput = input; - lastOutput = transform(input); - initialized = true; - - return lastOutput; - } - } - - public class PredictedCachedTransform - { - readonly Func transform; - - bool initialized; - T lastInput; - U lastOutput; - - bool predicted; - U prediction; - - public PredictedCachedTransform(Func transform) - { - this.transform = transform; - } - - public void Predict(U value) - { - predicted = true; - prediction = value; - } - - public U Update(T input) - { - if ((predicted || initialized) && ((input == null && lastInput == null) || (input != null && input.Equals(lastInput)))) - return predicted ? prediction : lastOutput; - - predicted = false; - initialized = true; - lastInput = input; - lastOutput = transform(input); - - return lastOutput; - } - } } diff --git a/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs b/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs index 939cf44f4e..e0f0d77081 100644 --- a/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs +++ b/OpenRA.Mods.D2k/Traits/Buildings/D2kActorPreviewPlaceBuildingPreview.cs @@ -15,7 +15,6 @@ using System.Linq; using OpenRA.Graphics; using OpenRA.Mods.Common.Orders; using OpenRA.Mods.Common.Traits; -using OpenRA.Mods.Common.Widgets; using OpenRA.Primitives; using OpenRA.Traits;