Skip to content

Commit 81e65d0

Browse files
committed
Improve path smoothing and fix important waypoints being culled out;
Refactor BehaviourHelper (add EarlyInitialize) to fix GridSettingsSaver not applying settings before grid generation; Various refactors and fixes
1 parent 4426353 commit 81e65d0

File tree

12 files changed

+299
-249
lines changed

12 files changed

+299
-249
lines changed

Core/Game/Abilities/BehaviourHelper/BehaviourHelper.cs

Lines changed: 123 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -5,121 +5,131 @@
55
using System;
66

77
namespace Lockstep
8-
{
9-
public abstract class BehaviourHelper : MonoBehaviour, IBehaviourHelper
10-
{
11-
12-
public BehaviourHelper()
13-
{
14-
15-
}
16-
17-
private static FastList<BehaviourHelper> _behaviourHelpers = new FastList<BehaviourHelper>();
18-
private static HashSet<Type> _createdTypes = new HashSet<Type>();
19-
20-
public static FastList<BehaviourHelper> BehaviourHelpers { get { return _behaviourHelpers; } }
21-
public static HashSet<Type> CreatedTypes { get { return _createdTypes; } }
22-
23-
public ushort CachedListenInput { get; private set; }
24-
25-
public virtual ushort ListenInput
26-
{
27-
get { return 0; }
28-
}
29-
30-
31-
public void Initialize()
32-
{
33-
CachedListenInput = ListenInput;
34-
OnInitialize();
35-
}
36-
37-
38-
protected virtual void OnInitialize()
39-
{
40-
}
41-
42-
public void LateInitialize()
43-
{
44-
this.OnLateInitialize();
45-
}
46-
47-
protected virtual void OnLateInitialize()
48-
{
49-
50-
}
51-
52-
public void Simulate()
53-
{
54-
OnSimulate();
55-
}
56-
57-
protected virtual void OnSimulate()
58-
{
59-
}
60-
61-
public void LateSimulate()
62-
{
63-
OnLateSimulate();
64-
}
65-
66-
protected virtual void OnLateSimulate()
67-
{
68-
69-
}
8+
{
9+
public abstract class BehaviourHelper : MonoBehaviour, IBehaviourHelper
10+
{
11+
12+
public BehaviourHelper()
13+
{
14+
15+
}
16+
17+
private static FastList<BehaviourHelper> _behaviourHelpers = new FastList<BehaviourHelper>();
18+
private static HashSet<Type> _createdTypes = new HashSet<Type>();
19+
20+
public static FastList<BehaviourHelper> BehaviourHelpers { get { return _behaviourHelpers; } }
21+
public static HashSet<Type> CreatedTypes { get { return _createdTypes; } }
22+
23+
public ushort CachedListenInput { get; private set; }
24+
25+
public virtual ushort ListenInput {
26+
get { return 0; }
27+
}
28+
29+
30+
public void Initialize()
31+
{
32+
OnInitialize();
33+
}
7034

71-
public void Visualize()
72-
{
73-
OnVisualize();
74-
}
35+
public void EarlyInitialize()
36+
{
37+
CachedListenInput = ListenInput;
7538

76-
protected virtual void OnVisualize()
77-
{
78-
}
79-
public void LateVisualize () {
80-
OnLateVisualize ();
39+
OnEarlyInitialize();
8140
}
82-
protected virtual void OnLateVisualize () {
83-
41+
protected virtual void OnEarlyInitialize()
42+
{
43+
44+
}
45+
46+
protected virtual void OnInitialize()
47+
{
48+
}
49+
50+
public void LateInitialize()
51+
{
52+
this.OnLateInitialize();
53+
}
54+
55+
protected virtual void OnLateInitialize()
56+
{
57+
58+
}
59+
60+
public void Simulate()
61+
{
62+
OnSimulate();
63+
}
64+
65+
protected virtual void OnSimulate()
66+
{
67+
}
68+
69+
public void LateSimulate()
70+
{
71+
OnLateSimulate();
72+
}
73+
74+
protected virtual void OnLateSimulate()
75+
{
76+
77+
}
78+
79+
public void Visualize()
80+
{
81+
OnVisualize();
82+
}
83+
84+
protected virtual void OnVisualize()
85+
{
8486
}
85-
86-
public void GlobalExecute(Command com)
87-
{
88-
OnExecute(com);
89-
}
90-
91-
protected virtual void OnExecute(Command com)
92-
{
93-
}
94-
95-
public void RawExecute(Command com)
96-
{
97-
OnRawExecute(com);
98-
}
99-
100-
protected virtual void OnRawExecute(Command com)
101-
{
102-
103-
}
104-
105-
public void GameStart()
106-
{
107-
OnGameStart();
108-
}
109-
110-
protected virtual void OnGameStart()
111-
{
112-
113-
}
114-
115-
public void Deactivate()
116-
{
117-
OnDeactivate();
118-
}
119-
120-
protected virtual void OnDeactivate()
121-
{
122-
123-
}
124-
}
87+
public void LateVisualize()
88+
{
89+
OnLateVisualize();
90+
}
91+
protected virtual void OnLateVisualize()
92+
{
93+
94+
}
95+
96+
public void GlobalExecute(Command com)
97+
{
98+
OnExecute(com);
99+
}
100+
101+
protected virtual void OnExecute(Command com)
102+
{
103+
}
104+
105+
public void RawExecute(Command com)
106+
{
107+
OnRawExecute(com);
108+
}
109+
110+
protected virtual void OnRawExecute(Command com)
111+
{
112+
113+
}
114+
115+
public void GameStart()
116+
{
117+
OnGameStart();
118+
}
119+
120+
protected virtual void OnGameStart()
121+
{
122+
123+
}
124+
125+
public void Deactivate()
126+
{
127+
OnDeactivate();
128+
}
129+
130+
protected virtual void OnDeactivate()
131+
{
132+
133+
}
134+
}
125135
}

Core/Game/Abilities/BehaviourHelper/BehaviourHelperManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ public static class BehaviourHelperManager {
88
public static void Initialize (BehaviourHelper[] helpers) {
99
Helpers = helpers;
1010
foreach (BehaviourHelper helper in Helpers) {
11-
helper.Initialize ();
11+
helper.EarlyInitialize ();
1212
}
1313
}
1414

1515
public static void LateInitialize () {
16+
foreach (BehaviourHelper helper in Helpers) {
17+
helper.Initialize();
18+
}
1619
foreach (BehaviourHelper helper in Helpers) {
1720
helper.LateInitialize();
1821
}

Core/Game/Managers/LockstepManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ internal static void Initialize (GameManager gameManager)
183183

184184
FrameCount = 0;
185185
InfluenceFrameCount = 0;
186+
InitializeHelpers();
186187

187188
ClientManager.Initialize (MainGameManager.MainNetworkHelper);
188189

@@ -203,7 +204,6 @@ internal static void Initialize (GameManager gameManager)
203204
ProjectileManager.Initialize ();
204205

205206
DefaultMessageRaiser.LateInitialize ();
206-
InitializeHelpers ();
207207
BehaviourHelperManager.LateInitialize ();
208208
if (onInitialize != null)
209209
onInitialize ();

Core/Game/Player/RTSInterfacing.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ namespace Lockstep
66
{
77
public static class RTSInterfacing
88
{
9-
public static Camera mainCamera { get; private set; }
9+
public static Camera mainCamera { get { return Camera.main; } }
1010

1111
public static void Initialize ()
1212
{
13-
mainCamera = Camera.main;
1413
CachedDidHit = false;
1514
}
1615

@@ -76,6 +75,7 @@ public static void Visualize ()
7675
public static bool CachedDidHit { get; private set; }
7776

7877
public static Vector2d GetWorldPosHeight (Vector2 screenPos, float height = 0) {
78+
if (Camera.main == null) return Vector2d.zero;
7979
Ray ray = Camera.main.ScreenPointToRay (screenPos);
8080
RaycastHit hit;
8181

Core/Simulation/Grid/Core/GridNode.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,15 @@ public void CalculateHeuristic ()
302302
this.hCost = dstY * 141 + (dstX - dstY) * 100;
303303
else
304304
this.hCost = dstX * 141 + (dstY - dstX) * 100;
305-
306-
#elif false
305+
306+
#elif false
307307
//euclidean
308308
dstX = HeuristicTargetX - gridX;
309309
dstY = HeuristicTargetY - gridY;
310310
double d = dstX * dstX + dstY * dstY;
311311
d = Math.Sqrt(d);
312312
hCost = (int)(d * 100);
313-
#endif
313+
#endif
314314

315315
fCost = gCost + hCost;
316316

Core/Simulation/Grid/Settings/GridSettingsSaver.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ protected override void OnSave()
3030
{
3131
//this._mapCenter = new Vector2d(transform.position);
3232
}
33+
3334
protected override void OnApply()
3435
{
3536
GridManager.Settings = new GridSettings(this.MapWidth,this.MapHeight,this.Offset.x,this.Offset.y, this.UseDiagonalConnetions);
3637
}
3738

39+
40+
3841
#if UNITY_EDITOR
3942
public bool Show;
4043

Core/Simulation/Math/FixedMath.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,23 @@ public static long Min(this long f1, long f2)
271271
{
272272
return f1 <= f2 ? f1 : f2;
273273
}
274+
public static long Min(long f1, long f2, long f3, long f4)
275+
{
276+
f1 = Min(f1, f2);
277+
f3 = Min(f3, f4);
278+
return Min(f1, f3);
279+
}
274280

275281
public static long Max(this long f1, long f2)
276282
{
277283
return f1 >= f2 ? f1 : f2;
278284
}
285+
public static long Max(long f1, long f2, long f3, long f4)
286+
{
287+
f1 = Max(f1, f2);
288+
f3 = Max(f3, f4);
289+
return Max(f1, f3);
290+
}
279291
public static long Clamp(this long f1, long min, long max)
280292
{
281293
if (f1 < min) return min;

Core/Simulation/Math/Vector2d.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -349,15 +349,15 @@ public static long Cross(long v1x, long v1y, long v2x, long v2y)
349349
/// Note: Not deterministic. Use only for serialization and sending in Commands.
350350
/// </summary>
351351
/// <returns>The from angle.</returns>
352-
/// <param name="angle">Angle.</param>
353-
public static Vector2d CreateRotation(double angle)
352+
/// <param name="angleRadians">Angle.</param>
353+
public static Vector2d CreateRotation(double angleRadians)
354354
{
355-
return new Vector2d(Math.Cos(angle), Math.Sin(angle));
355+
return new Vector2d(Math.Cos(angleRadians), Math.Sin(angleRadians));
356356
}
357357

358-
public static Vector2d CreateRotation(float angle)
358+
public static Vector2d CreateRotation(float angleRadians)
359359
{
360-
return CreateRotation((double)angle);
360+
return CreateRotation((double)angleRadians);
361361
}
362362

363363
/// <summary>

0 commit comments

Comments
 (0)