Skip to content

Commit 1a1f542

Browse files
committed
Merging projects part 1
1 parent 1e56c46 commit 1a1f542

40 files changed

+315
-265
lines changed

MonoGameStateMachine/Api/BuilderFluent.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525
// For more information, please refer to <http://unlicense.org>
2626
// ***************************************************************************
2727

28-
using JetBrains.Annotations;
29-
3028
namespace MonoGameStateMachine.Api
3129
{
32-
[PublicAPI]
3330
public interface BuilderFluent<TS, TT, TD>
3431
{
3532
/// <summary>

MonoGameStateMachine/Api/FluentImplementation.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,8 @@ public FluentImplementation(TS startState) : base(startState)
5353

5454
public TransitionStateFluent<TS, TT, GameTime> After(float amount, TimeUnit timeUnit)
5555
{
56-
List<Timer<TS>> l;
57-
var key = currentTransition;
58-
if (!AfterEntries.TryGetValue(key, out l))
56+
var key = currentTransition;
57+
if (!AfterEntries.TryGetValue(key, out var l))
5958
{
6059
l = new List<Timer<TS>>();
6160
AfterEntries.Add(key, l);

MonoGameStateMachine/Api/GlobalTransitionBuilderFluent.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@
2525
// For more information, please refer to <http://unlicense.org>
2626
// ***************************************************************************
2727

28-
using JetBrains.Annotations;
29-
3028
namespace MonoGameStateMachine.Api
3129
{
32-
[PublicAPI]
3330
public interface GlobalTransitionBuilderFluent<TS, TT, TD> :
3431
GlobalTransitionFluent<TS, TT, TD>, BuilderFluent<TS, TT, TD>
3532
{

MonoGameStateMachine/Api/GlobalTransitionFluent.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@
2626
// ***************************************************************************
2727

2828
using System;
29-
using JetBrains.Annotations;
3029
using StateMachine.Events;
3130

3231
namespace MonoGameStateMachine.Api
3332
{
34-
[PublicAPI]
3533
public interface GlobalTransitionFluent<TS, TT, TD>
3634
{
3735
/// <summary>

MonoGameStateMachine/Api/StateFluent.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@
2626
// ***************************************************************************
2727

2828
using System;
29-
using JetBrains.Annotations;
3029
using StateMachine.Events;
3130

3231
namespace MonoGameStateMachine.Api
3332
{
34-
[PublicAPI]
3533
public interface StateFluent<TS, TT, TD> : BuilderFluent<TS, TT, TD>
3634
{
3735
/// <summary>

MonoGameStateMachine/Api/TransitionFluent.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@
2626
// ***************************************************************************
2727

2828
using System;
29-
using JetBrains.Annotations;
3029
using StateMachine.Events;
3130

3231
namespace MonoGameStateMachine.Api
3332
{
34-
[PublicAPI]
3533
public interface TransitionFluent<TS, TT, TD>
3634
{
3735
/// <summary>

MonoGameStateMachine/DataObject.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@
2525
// For more information, please refer to <http://unlicense.org>
2626
// ***************************************************************************
2727

28-
using JetBrains.Annotations;
2928
using Microsoft.Xna.Framework;
3029

3130
namespace MonoGameStateMachine
3231
{
33-
[PublicAPI]
3432
public struct DataObject<T>
3533
{
3634
public T Data { get; set; }

MonoGameStateMachine/Fsm.cs

Lines changed: 94 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -27,116 +27,105 @@
2727

2828
using System;
2929
using System.Collections.Generic;
30-
using JetBrains.Annotations;
3130
using Microsoft.Xna.Framework;
3231
using MonoGameStateMachine.Api;
3332
using StateMachine;
3433
using StateMachine.Events;
3534

3635
namespace MonoGameStateMachine
3736
{
38-
[PublicAPI]
39-
public class Fsm<TS, TT> : Fsm<TS, TT, GameTime>
40-
{
41-
private GameTime gt = new GameTime();
42-
43-
public Dictionary<Tuple<TS, TS>, List<Timer<TS>>> AfterEntries { get; set; } = new Dictionary<Tuple<TS, TS>, List<Timer<TS>>>();
44-
public List<Timer<TS>> GlobalAfterEntries { get; set; } = new List<Timer<TS>>();
45-
46-
public Fsm(FsmModel<TS, TT, GameTime> model) : base(model)
47-
{
48-
}
49-
50-
public Fsm(State<TS, TT, GameTime> current, bool stackEnabled = false) : base(current, stackEnabled)
51-
{
52-
}
53-
54-
/// <summary>
55-
/// Gets you a builder for a Finite-State-Machine (FSM).
56-
/// </summary>
57-
/// <param name="startState">The start state's key.</param>
58-
/// <returns></returns>
59-
public new static BuilderFluent<TS, TT, GameTime> Builder(TS startState)
60-
{
61-
return new FluentImplementation<TS, TT>(startState);
62-
}
63-
64-
private void ResetCurrentAfterEntries()
65-
{
66-
foreach (var k in Current.Model.Transitions.Keys)
67-
{
68-
List<Timer<TS>> currentAfterEntries;
69-
if (AfterEntries.TryGetValue(new Tuple<TS, TS>(Current.Identifier, k), out currentAfterEntries))
70-
{
71-
for (int i = 0; i < currentAfterEntries.Count; i++)
72-
{
73-
Timer<TS> e = currentAfterEntries[i];
74-
e.Reset();
75-
currentAfterEntries[i] = e;
76-
}
77-
}
78-
}
79-
}
80-
81-
protected override void Entered(StateChangeArgs<TS, TT, GameTime> args)
82-
{
83-
ResetCurrentAfterEntries();
84-
base.Entered(args);
85-
}
86-
87-
public new void Update(GameTime gameTime)
88-
{
89-
// After-entries on transitions.
90-
foreach (var k in Current.Model.Transitions.Keys)
91-
{
92-
List<Timer<TS>> currentAfterEntries;
93-
if (AfterEntries.TryGetValue(new Tuple<TS, TS>(Current.Identifier, k), out currentAfterEntries))
94-
{
95-
if (CheckAfterEntries(currentAfterEntries, Current.Model.Transitions, gameTime))
96-
{
97-
return;
98-
}
99-
}
100-
}
101-
102-
// Global after-entries.
103-
if (CheckAfterEntries(GlobalAfterEntries, Model.GlobalTransitions, gameTime))
104-
{
105-
return;
106-
}
107-
108-
Model.Current.RaiseUpdated(new UpdateArgs<TS, TT, GameTime>(this, Current, gameTime));
109-
}
110-
111-
private bool CheckAfterEntries(List<Timer<TS>> afterEntries,
112-
Dictionary<TS, Transition<TS, TT, GameTime>> transitions, GameTime g)
113-
{
114-
for (int i = 0; i < afterEntries.Count; i++)
115-
{
116-
Timer<TS> e = afterEntries[i];
117-
Transition<TS, TT, GameTime> t;
118-
if (transitions.TryGetValue(e.Target, out t))
119-
{
120-
if (t.ConditionsMet(Current.Identifier))
121-
{
122-
double timerMax = e.Time;
123-
double? r = e.Tick(g.ElapsedGameTime.TotalMilliseconds);
124-
afterEntries[i] = e;
125-
if (r.HasValue)
126-
{
127-
// It triggered.
128-
DoTransition(e.Target, default(TT), t.Pop);
129-
gt.IsRunningSlowly = g.IsRunningSlowly;
130-
gt.TotalGameTime = g.TotalGameTime.Subtract(TimeSpan.FromMilliseconds(timerMax));
131-
gt.ElapsedGameTime =
132-
g.ElapsedGameTime.Subtract(TimeSpan.FromMilliseconds(timerMax));
133-
Update(gt);
134-
return true;
135-
}
136-
}
137-
}
138-
}
139-
return false;
140-
}
141-
}
37+
public class Fsm<TS, TT> : Fsm<TS, TT, GameTime>
38+
{
39+
private readonly GameTime gt = new GameTime();
40+
41+
public Dictionary<Tuple<TS, TS>, List<Timer<TS>>> AfterEntries { get; set; } =
42+
new Dictionary<Tuple<TS, TS>, List<Timer<TS>>>();
43+
44+
public List<Timer<TS>> GlobalAfterEntries { get; set; } = new List<Timer<TS>>();
45+
46+
public Fsm(FsmModel<TS, TT, GameTime> model) : base(model)
47+
{
48+
}
49+
50+
public Fsm(State<TS, TT, GameTime> current, bool stackEnabled = false) : base(current, stackEnabled)
51+
{
52+
}
53+
54+
/// <summary>
55+
/// Gets you a builder for a Finite-State-Machine (FSM).
56+
/// </summary>
57+
/// <param name="startState">The start state's key.</param>
58+
/// <returns></returns>
59+
public new static BuilderFluent<TS, TT, GameTime> Builder(TS startState)
60+
{
61+
return new FluentImplementation<TS, TT>(startState);
62+
}
63+
64+
private void ResetCurrentAfterEntries()
65+
{
66+
foreach (var k in Current.Model.Transitions.Keys)
67+
{
68+
if (!AfterEntries.TryGetValue(new Tuple<TS, TS>(Current.Identifier, k), out var currentAfterEntries)) continue;
69+
for (var i = 0; i < currentAfterEntries.Count; i++)
70+
{
71+
var e = currentAfterEntries[i];
72+
e.Reset();
73+
currentAfterEntries[i] = e;
74+
}
75+
}
76+
}
77+
78+
protected override void Entered(StateChangeArgs<TS, TT, GameTime> args)
79+
{
80+
ResetCurrentAfterEntries();
81+
base.Entered(args);
82+
}
83+
84+
public new void Update(GameTime gameTime)
85+
{
86+
// After-entries on transitions.
87+
foreach (var k in Current.Model.Transitions.Keys)
88+
{
89+
if (!AfterEntries.TryGetValue(new Tuple<TS, TS>(Current.Identifier, k), out var currentAfterEntries)) continue;
90+
if (CheckAfterEntries(currentAfterEntries, Current.Model.Transitions, gameTime))
91+
return;
92+
}
93+
94+
// Global after-entries.
95+
if (CheckAfterEntries(GlobalAfterEntries, Model.GlobalTransitions, gameTime))
96+
{
97+
return;
98+
}
99+
100+
Model.Current.RaiseUpdated(new UpdateArgs<TS, TT, GameTime>(this, Current, gameTime));
101+
}
102+
103+
private bool CheckAfterEntries(List<Timer<TS>> afterEntries,
104+
Dictionary<TS, Transition<TS, TT, GameTime>> transitions, GameTime g)
105+
{
106+
for (var i = 0; i < afterEntries.Count; i++)
107+
{
108+
var e = afterEntries[i];
109+
if (!transitions.TryGetValue(e.Target, out var t)) continue;
110+
if (!t.ConditionsMet(Current.Identifier)) continue;
111+
112+
var timerMax = e.Time;
113+
var r = e.Tick(g.ElapsedGameTime.TotalMilliseconds);
114+
afterEntries[i] = e;
115+
116+
if (!r.HasValue) continue;
117+
118+
// It triggered.
119+
DoTransition(e.Target, default(TT), t.Pop);
120+
gt.IsRunningSlowly = g.IsRunningSlowly;
121+
gt.TotalGameTime = g.TotalGameTime.Subtract(TimeSpan.FromMilliseconds(timerMax));
122+
gt.ElapsedGameTime =
123+
g.ElapsedGameTime.Subtract(TimeSpan.FromMilliseconds(timerMax));
124+
Update(gt);
125+
return true;
126+
}
127+
128+
return false;
129+
}
130+
}
142131
}

MonoGameStateMachine/MonoGameStateMachine.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@
4949
<Compile Include="Api\TransitionFluent.cs" />
5050
</ItemGroup>
5151
<ItemGroup>
52-
<Reference Include="JetBrains.Annotations, Version=11.1.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325, processorArchitecture=MSIL">
53-
<HintPath>..\packages\JetBrains.Annotations.11.1.0\lib\net20\JetBrains.Annotations.dll</HintPath>
54-
<Private>True</Private>
55-
</Reference>
5652
<Reference Include="MonoGame.Framework, Version=3.6.0.1625, Culture=neutral, processorArchitecture=MSIL">
5753
<HintPath>..\packages\MonoGame.Framework.Portable.3.6.0.1625\lib\portable-net45+win8+wpa81\MonoGame.Framework.dll</HintPath>
5854
<Private>True</Private>

MonoGameStateMachine/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Reflection;
2-
using System.Runtime.CompilerServices;
32
using System.Runtime.InteropServices;
43

54
// General Information about an assembly is controlled through the following
@@ -32,5 +31,5 @@
3231
// You can specify all the values or you can default the Build and Revision Numbers
3332
// by using the '*' as shown below:
3433
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("1.1.2.1")]
36-
[assembly: AssemblyFileVersion("1.1.2.1")]
34+
[assembly: AssemblyVersion("1.1.3.1")]
35+
[assembly: AssemblyFileVersion("1.1.3.1")]

0 commit comments

Comments
 (0)