Skip to content

Commit 01b0351

Browse files
committed
Clean Code
1 parent aa99d78 commit 01b0351

15 files changed

+176
-8
lines changed

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@
1010
/[Ll]ogs/
1111
/[Uu]ser[Ss]ettings/
1212

13+
Packages/Microsoft.CodeAnalysis.FxCopAnalyzers.3.0.0/
14+
Packages/Microsoft.CodeAnalysis.VersionCheckAnalyzer.3.0.0/
15+
Packages/Microsoft.CodeQuality.Analyzers.3.0.0/
16+
Packages/Microsoft.NetCore.Analyzers.3.0.0/
17+
Packages/Microsoft.NetFramework.Analyzers.3.0.0/
18+
1319
# MemoryCaptures can get excessive in size.
1420
# They also could contain extremely sensitive data
1521
/[Mm]emoryCaptures/
@@ -67,4 +73,6 @@ crashlytics-build.properties
6773

6874
# Temporary auto-generated Android Assets
6975
/[Aa]ssets/[Ss]treamingAssets/aa.meta
70-
/[Aa]ssets/[Ss]treamingAssets/aa/*
76+
/[Aa]ssets/[Ss]treamingAssets/aa/*
77+
.editorconfig
78+
packages.config

Assets/Scripts/Common.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
public interface IIntegrator
2+
{
3+
void StepOneFrame(PhysicalScene scene);
4+
}

Assets/Scripts/Common/IIntegrator.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/PhysicalScene.cs renamed to Assets/Scripts/Common/PhysicalScene.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ public class PhysicalScene : MonoBehaviour
1212
public GameObject particlePrefab;
1313
public GameObject linePrefab;
1414

15+
[System.NonSerialized]
16+
public string integratorType = "";
1517
[System.NonSerialized]
1618
public int objectCount = 0;
1719

@@ -157,6 +159,19 @@ public void Load(TextAsset scene)
157159
edgeList.Add(lineRenderer);
158160
edgeIndexList.Add(new Vector2Int(i, j));
159161
}
162+
163+
// Frame Rate
164+
XmlNodeList integrators = xmlDoc.GetElementsByTagName("integrator");
165+
if(integrators.Count > 0)
166+
{
167+
XmlNode integrator = integrators[0];
168+
float dt = float.Parse(integrator.Attributes["dt"]?.InnerText);
169+
integratorType = integrator.Attributes["type"]?.InnerText;
170+
171+
Debug.Log("Target Delta Time Is " + dt.ToString());
172+
Debug.Log("Integrator Type Is " + integratorType);
173+
Application.targetFrameRate = (int)(1.0f / dt);
174+
}
160175
}
161176

162177
public void Dispose()
File renamed without changes.

Assets/Scripts/Runner.cs renamed to Assets/Scripts/Common/Runner.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,25 @@
1010
public class Runner : MonoBehaviour
1111
{
1212
PhysicalScene scene;
13-
ExplicitEulerIntegrator explicitEuler = new ExplicitEulerIntegrator();
13+
IIntegrator integrator;
1414

1515
void Awake()
1616
{
1717
scene = GetComponent<PhysicalScene>();
1818
scene.Load();
19+
20+
if (scene.integratorType == "explicit-euler")
21+
{
22+
integrator = new ExplicitEulerIntegrator();
23+
}
24+
else if (scene.integratorType == "symplectic-euler")
25+
{
26+
integrator = new SymplecticEulerIntegrator();
27+
}
28+
else
29+
{
30+
Debug.Assert(false, "Can Not Find Any Suitable Integrator.");
31+
}
1932
}
2033

2134
void OnDestroy()
@@ -26,7 +39,7 @@ void OnDestroy()
2639
// Update is called once per frame
2740
void Update()
2841
{
29-
explicitEuler.StepOneFrame(scene);
42+
integrator.StepOneFrame(scene);
3043
scene.Frame();
3144
}
3245

File renamed without changes.

Assets/Scripts/Integrator.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/ExplicitEulerIntegrator.cs renamed to Assets/Scripts/Integrator/ExplicitEulerIntegrator.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using UnityEngine;
1+
using UnityEngine;
42
using Unity.Jobs;
53
using UnityEngine.Jobs;
64
using Unity.Collections;
7-
using System.Xml;
85

9-
public class ExplicitEulerIntegrator
6+
public class ExplicitEulerIntegrator: IIntegrator
107
{
118
// By Order
129
SimpleGravityJob m_GravityGradiantJob;

0 commit comments

Comments
 (0)