This commit is contained in:
Paul Chote
2011-06-17 16:45:52 +12:00
parent 63e77755b7
commit 7095f293ff
4 changed files with 36 additions and 14 deletions

View File

@@ -18,23 +18,45 @@ namespace OpenRA.FileFormats
public class ActionQueue public class ActionQueue
{ {
object syncRoot = new object(); object syncRoot = new object();
Action actions = () => { }; PriorityQueue<DelayedAction> actions = new PriorityQueue<DelayedAction>();
public void Add(Action a) public void Add(Action a) { Add(a, 0); }
public void Add(Action a, int delay)
{ {
lock (syncRoot) lock (syncRoot)
actions += a; actions.Add(new DelayedAction(a, Environment.TickCount + delay));
} }
public void PerformActions() public void PerformActions()
{ {
Action a; Action a = () => {};
lock (syncRoot) lock (syncRoot)
{ {
a = actions; var t = Environment.TickCount;
actions = () => { }; while (!actions.Empty && actions.Peek().Time <= t)
{
var da = actions.Pop();
a += da.Action;
}
} }
a(); a();
} }
} }
struct DelayedAction : IComparable<DelayedAction>
{
public int Time;
public Action Action;
public DelayedAction(Action action, int time)
{
Action = action;
Time = time;
}
public int CompareTo(DelayedAction other)
{
return Math.Sign(Time - other.Time);
}
}
} }

View File

@@ -62,6 +62,7 @@ namespace OpenRA.FileFormats
return At(lastLevel, lastIndex); return At(lastLevel, lastIndex);
} }
public T Peek() { return At(0,0); }
public T Pop() public T Pop()
{ {
if (level == 0 && index == 0) if (level == 0 && index == 0)

View File

@@ -123,8 +123,9 @@ namespace OpenRA
}, parent, id); }, parent, id);
} }
static ActionQueue afterTickActions = new ActionQueue(); static ActionQueue delayedActions = new ActionQueue();
public static void RunAfterTick(Action a) { afterTickActions.Add(a); } public static void RunAfterTick(Action a) { delayedActions.Add(a); }
public static void RunAfterDelay(int delay, Action a) { delayedActions.Add(a, delay); }
static void Tick( OrderManager orderManager, Viewport viewPort ) static void Tick( OrderManager orderManager, Viewport viewPort )
{ {
@@ -150,7 +151,7 @@ namespace OpenRA
PerfHistory.items["render_widgets"].Tick(); PerfHistory.items["render_widgets"].Tick();
PerfHistory.items["render_flip"].Tick(); PerfHistory.items["render_flip"].Tick();
afterTickActions.PerformActions(); delayedActions.PerformActions();
} }
static void Tick( OrderManager orderManager ) static void Tick( OrderManager orderManager )

View File

@@ -36,15 +36,13 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
{ {
Sound.Play("batlcon1.aud"); Sound.Play("batlcon1.aud");
resumeDisabled = true; resumeDisabled = true;
world.WorldActor.QueueActivity(new Wait(30)); Game.RunAfterDelay(1200, () => mpe.Fade(CncMenuPaletteEffect.EffectType.Black));
world.WorldActor.QueueActivity(new CallFunc(() => mpe.Fade(CncMenuPaletteEffect.EffectType.Black))); Game.RunAfterDelay(1200 + 40 * mpe.Info.FadeLength, () =>
world.WorldActor.QueueActivity(new Wait(mpe.Info.FadeLength));
world.WorldActor.QueueActivity(new CallFunc(() =>
{ {
Game.Disconnect(); Game.Disconnect();
Widget.ResetAll(); Widget.ResetAll();
Game.LoadShellMap(); Game.LoadShellMap();
})); });
}; };
Action doNothing = () => {}; Action doNothing = () => {};