Skip to content

Commit 125ee93

Browse files
committed
delete legacy cpu code
1 parent eb7b531 commit 125ee93

File tree

2 files changed

+16
-551
lines changed

2 files changed

+16
-551
lines changed

Assets/Scripts/FluidController.cs

Lines changed: 12 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ public class FluidController : MonoBehaviour
2626
[HideInInspector]
2727
public Int3 gridSize;
2828

29+
private HashSet<Int3> _currUpdateMCBlocks;
30+
private float _timer;
31+
2932
private void Start()
3033
{
3134
//ExampleMc()
@@ -35,12 +38,6 @@ private void Start()
3538
gridSize._x, gridSize._y, gridSize._z, shaderSPH,
3639
shaderRadixSort);
3740

38-
//CreateTest25Square();
39-
//CreateDirFlow();
40-
//CreateTest125Cube();
41-
//CreateTest1000Cube();
42-
//CreateTwoCollisionFlow();
43-
//CreatePenetrateWall();
4441
//CreateTest125CubeGPU();
4542
CreateTest1000CubeGPU();
4643

@@ -50,10 +47,8 @@ private void Start()
5047
mcEngine.engineScale = (float)gridSize._x / (float)mcEngine.width;
5148
mcEngine.Init(sphSolver);
5249

53-
//if (sphSolver.currParticleNum > 0)
54-
// StartCoroutine(Simulate_CR());
55-
if (sphSolver.currParticleNum > 0)
56-
StartCoroutine(SimulatorOnGPU_CR());
50+
_currUpdateMCBlocks = new HashSet<Int3>();
51+
_timer = 0f;
5752
}
5853

5954
private void OnDestroy()
@@ -63,25 +58,6 @@ private void OnDestroy()
6358
}
6459

6560
#region Test Cases
66-
private void CreateTest25Square()
67-
{
68-
for (int x = 0; x < 5; ++x)
69-
for (int z = 0; z < 5; ++z)
70-
{
71-
sphSolver.CreateParticle(1, new Vector3d(5 + 0.1 * x, 4.9, 5 + 0.1 * z), Vector3d.zero);
72-
}
73-
}
74-
75-
private void CreateTest125Cube()
76-
{
77-
for (int x = 0; x < 5; ++x)
78-
for (int y = 0; y < 5; ++y)
79-
for (int z = 0; z < 5; ++z)
80-
{
81-
sphSolver.CreateParticle(1, new Vector3d(5 + 0.1 * x, 5 + 0.1 * y, 5 + 0.1 * z), Vector3d.zero);
82-
}
83-
}
84-
8561
private void CreateTest125CubeGPU()
8662
{
8763
for (int x = 0; x < 5; ++x)
@@ -92,17 +68,6 @@ private void CreateTest125CubeGPU()
9268
}
9369
}
9470

95-
private void CreateTest1000Cube()
96-
{
97-
for (int x = 0; x < 10; ++x)
98-
for (int y = 0; y < 10; ++y)
99-
for (int z = 0; z < 10; ++z)
100-
{
101-
sphSolver.CreateParticle(1, new Vector3d(4 + 0.2 * x, 4 + 0.2 * y, 4 + 0.2 * z), Vector3d.zero);
102-
}
103-
}
104-
105-
10671
private void CreateTest1000CubeGPU()
10772
{
10873
for (int x = 0; x < 10; ++x)
@@ -112,99 +77,27 @@ private void CreateTest1000CubeGPU()
11277
sphSolver.CreateGPUParticle(1, new Vector3(4f + 0.2f * x, 4f + 0.2f * y, 4f + 0.2f * z), Vector3.zero);
11378
}
11479
}
115-
116-
private void CreateDirFlow()
117-
{
118-
for (int x = 0; x < 20; ++x)
119-
sphSolver.CreateParticle(1, new Vector3d(5 + 0.1 * x, 4.9, 5), new Vector3d(5,0,0));
120-
}
121-
122-
private void CreateTwoCollisionFlow()
123-
{
124-
for (int x = 0; x < 50; ++x)
125-
sphSolver.CreateParticle(1, new Vector3d(Vector3.one * Random.value * 0.2f) + new Vector3d(3 + 0.1 * x, 5, 5), new Vector3d(3 + Random.Range(0, 2f), 0, 0));
126-
127-
for (int x = 0; x < 50; ++x)
128-
sphSolver.CreateParticle(1, new Vector3d(Vector3.one * Random.value * 0.2f) + new Vector3d(7 - 0.1 * x, 7, 5), new Vector3d(-3 - Random.Range(0, 2f), -5, 0));
129-
}
130-
131-
private void CreatePenetrateWall()
132-
{
133-
for (int x = 0; x < 10; ++x)
134-
for (int y = 0; y < 10; ++y)
135-
sphSolver.CreateParticle(1, new Vector3d(4 + 0.2 * x, 4 + 0.2 * y, 5), Vector3d.zero);
136-
137-
for (int z = 0; z < 10; ++z)
138-
sphSolver.CreateParticle(1, new Vector3d(5, 5, 1 + 0.05 * z), new Vector3d(0, 0, 5 + Random.Range(0, 2f)));
139-
}
140-
14180
#endregion
14281

143-
private IEnumerator SimulatorOnGPU_CR()
82+
private void Update()
14483
{
145-
HashSet<Int3> currUpdateMCBlocks = new HashSet<Int3>();
146-
while (true)
84+
_timer += Time.deltaTime;
85+
if (_timer > updateInterval)
14786
{
148-
yield return new WaitForSeconds(updateInterval);
149-
//yield return null;
150-
//if (!Input.GetKeyDown(KeyCode.S))
151-
//continue;
152-
//Debug.Log("wa");
153-
//#if UNITY_EDITOR
154-
// float startTime = Time.realtimeSinceStartup;
155-
//#endif
87+
_timer -= updateInterval;
15688
sphSolver.StepOnGPU();
157-
//update MarchingCubeEngine
158-
currUpdateMCBlocks.Clear();
89+
_currUpdateMCBlocks.Clear();
15990
for (int i = 0; i < sphSolver.currParticleNum; ++i)
16091
{
16192
if (sphSolver._allCSParticlesContainer[i].onSurface)
16293
{
16394
Vector3 blockOffset = (sphSolver._allCSParticlesContainer[i].position /*- mcEngine.engineOrigin*/) /
16495
(mcEngine.engineScale * MarchingCubeEngine.blockSize);
16596
Int3 blockIdx = new Int3(Mathf.FloorToInt(blockOffset.x), Mathf.FloorToInt(blockOffset.y), Mathf.FloorToInt(blockOffset.z));
166-
currUpdateMCBlocks.Add(blockIdx);
97+
_currUpdateMCBlocks.Add(blockIdx);
16798
}
16899
}
169-
170-
//#if UNITY_EDITOR
171-
// print("Time taken: " + (Time.realtimeSinceStartup - startTime) * 1000.0f);
172-
//#endif
173-
mcEngine.BatchUpdate(new List<Int3>(currUpdateMCBlocks));
174-
}
175-
}
176-
177-
178-
private IEnumerator Simulate_CR()
179-
{
180-
HashSet<Int3> currUpdateMCBlocks = new HashSet<Int3>();
181-
while (true)
182-
{
183-
yield return new WaitForSeconds(updateInterval);
184-
//yield return null;
185-
//if (!Input.GetKeyDown(KeyCode.S))
186-
// continue;
187-
188-
//#if UNITY_EDITOR
189-
// float startTime = Time.realtimeSinceStartup;
190-
//#endif
191-
sphSolver.Step();
192-
//update MarchingCubeEngine
193-
currUpdateMCBlocks.Clear();
194-
for (int i = 0; i < sphSolver.currParticleNum; ++i)
195-
{
196-
if (sphSolver.allParticles[i].onSurface)
197-
{
198-
Vector3d blockOffset = (sphSolver.allParticles[i].position /*- mcEngine.engineOrigin*/) /
199-
(mcEngine.engineScale * MarchingCubeEngine.blockSize);
200-
currUpdateMCBlocks.Add(Vector3d.FloorToInt3(blockOffset));
201-
}
202-
}
203-
204-
//#if UNITY_EDITOR
205-
// print("Time taken: " + (Time.realtimeSinceStartup - startTime) * 1000.0f);
206-
//#endif
207-
mcEngine.BatchUpdate(new List<Int3>(currUpdateMCBlocks));
100+
mcEngine.BatchUpdate(new List<Int3>(_currUpdateMCBlocks));
208101
}
209102
}
210103

@@ -217,18 +110,6 @@ private void OnDrawGizmos()
217110
Gizmos.DrawWireCube(center, extent * 2);
218111
Gizmos.color = Color.white;
219112

220-
//if (sphSolver != null && sphSolver.allParticles != null && sphSolver.allParticles.Count > 0)
221-
//{
222-
// for (int i = 0; i < sphSolver.allParticles.Count; ++i)
223-
// {
224-
// Vector3 pos = transform.position;
225-
// pos += new Vector3((float)sphSolver.allParticles[i].position.x,
226-
// (float)sphSolver.allParticles[i].position.y,
227-
// (float)sphSolver.allParticles[i].position.z);
228-
// Gizmos.DrawWireSphere(pos, 0.2f);
229-
// }
230-
//}
231-
232113
//if (sphSolver != null && sphSolver._allCSParticlesContainer != null && sphSolver._allCSParticlesContainer.Length > 0)
233114
//{
234115
// for (int i = 0; i < sphSolver._allCSParticlesContainer.Length; ++i)

0 commit comments

Comments
 (0)