Skip to content

Commit 4610b7a

Browse files
karimnaajimatteblair
authored andcommitted
Convert tabs to 4 spaces and apply code style (#12)
* Convert tabs to 4 spaces and apply code style policy * Add code formatting policy for MonoDevelop
1 parent d9c6e97 commit 4610b7a

17 files changed

+996
-761
lines changed

Assets/AsyncWorker.cs

Lines changed: 94 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -2,95 +2,98 @@
22
using System.Threading;
33
using System.Collections.Generic;
44

5-
public class AsyncWorker {
6-
public delegate void Task();
7-
private Thread[] threads;
8-
private bool stopped;
9-
private Queue<Task> tasks;
10-
11-
public AsyncWorker(int nThreads)
12-
{
13-
tasks = new Queue<Task>();
14-
threads = new Thread[nThreads];
15-
stopped = false;
16-
17-
for (int i = 0; i < threads.Length; ++i)
18-
{
19-
threads[i] = new Thread(new ThreadStart(this.ThreadMain));
20-
threads[i].Start();
21-
}
22-
}
23-
24-
public void RunAsync(Task task)
25-
{
26-
if (stopped)
27-
{
28-
return;
29-
}
30-
31-
lock (this)
32-
{
33-
tasks.Enqueue(task);
34-
35-
// Awaken one waiting thread
36-
Monitor.Pulse(this);
37-
}
38-
}
39-
40-
public int RemainingTasks()
41-
{
42-
int tasksSize;
43-
44-
lock (this)
45-
{
46-
tasksSize = tasks.Count;
47-
}
48-
49-
return tasksSize;
50-
}
51-
52-
public void JoinAll()
53-
{
54-
stopped = true;
55-
56-
lock (this)
57-
{
58-
// Awaken all waiting threads
59-
Monitor.PulseAll(this);
60-
}
61-
62-
for (int i = 0; i < threads.Length; ++i)
63-
{
64-
threads[i].Join();
65-
}
66-
}
67-
68-
private void ThreadMain()
69-
{
70-
while (!stopped)
71-
{
72-
Task task = null;
73-
74-
lock (this)
75-
{
76-
// If a thread calls Pulse when no other threads are waiting, the Pulse is lost,
77-
// make sure that this threads keep consuming tasks unless the queue is empty.
78-
if (tasks.Count == 0)
79-
{
80-
Monitor.Wait(this);
81-
}
82-
83-
// This thread might be awaken from a JoinAll() call with an empty queue
84-
if (tasks.Count > 0)
85-
{
86-
task = tasks.Dequeue();
87-
}
88-
}
89-
90-
if (task != null)
91-
{
92-
task.Invoke();
93-
}
94-
}
95-
}
5+
public class AsyncWorker
6+
{
7+
public delegate void Task();
8+
9+
private Thread[] threads;
10+
private bool stopped;
11+
private Queue<Task> tasks;
12+
13+
public AsyncWorker(int nThreads)
14+
{
15+
tasks = new Queue<Task>();
16+
threads = new Thread[nThreads];
17+
stopped = false;
18+
19+
for (int i = 0; i < threads.Length; ++i)
20+
{
21+
threads[i] = new Thread(new ThreadStart(this.ThreadMain));
22+
threads[i].Start();
23+
}
24+
}
25+
26+
public void RunAsync(Task task)
27+
{
28+
if (stopped)
29+
{
30+
return;
31+
}
32+
33+
lock (this)
34+
{
35+
tasks.Enqueue(task);
36+
37+
// Awaken one waiting thread
38+
Monitor.Pulse(this);
39+
}
40+
}
41+
42+
public int RemainingTasks()
43+
{
44+
int tasksSize;
45+
46+
47+
lock (this)
48+
{
49+
tasksSize = tasks.Count;
50+
}
51+
52+
return tasksSize;
53+
}
54+
55+
public void JoinAll()
56+
{
57+
stopped = true;
58+
59+
lock (this)
60+
{
61+
// Awaken all waiting threads
62+
Monitor.PulseAll(this);
63+
}
64+
65+
for (int i = 0; i < threads.Length; ++i)
66+
{
67+
threads[i].Join();
68+
}
69+
}
70+
71+
private void ThreadMain()
72+
{
73+
while (!stopped)
74+
{
75+
Task task = null;
76+
77+
lock (this)
78+
{
79+
// If a thread calls Pulse when no other threads are waiting, the Pulse is lost,
80+
// make sure that this threads keep consuming tasks unless the queue is empty.
81+
if (tasks.Count == 0)
82+
{
83+
Monitor.Wait(this);
84+
}
85+
86+
// This thread might be awaken from a JoinAll() call with an empty queue
87+
if (tasks.Count > 0)
88+
{
89+
task = tasks.Dequeue();
90+
}
91+
}
92+
93+
if (task != null)
94+
{
95+
task.Invoke();
96+
}
97+
}
98+
}
9699
}

Assets/Builder.cs

Lines changed: 76 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -5,80 +5,80 @@
55

66
public class Builder
77
{
8-
public static MeshData TesselatePolygon(Geometry geometry, Color color, float height)
9-
{
10-
var meshData = new MeshData();
11-
var tess = new Tess();
12-
13-
int pointIndex = 0;
14-
foreach (var ringSize in geometry.rings)
15-
{
16-
var contour = new ContourVertex[ringSize];
17-
18-
for (int i = pointIndex, contourIndex = 0; i < pointIndex + ringSize; ++i, ++contourIndex)
19-
{
20-
var point = geometry.points[i];
21-
contour[contourIndex].Position = new Vec3 { X = point.x, Y = height, Z = point.y };
22-
}
23-
24-
pointIndex += ringSize;
25-
26-
tess.AddContour(contour, ContourOrientation.Original);
27-
}
28-
29-
tess.Tessellate(WindingRule.NonZero, ElementType.Polygons, 3);
30-
31-
for (int i = 0; i < tess.ElementCount * 3; ++i)
32-
{
33-
meshData.indices.Add(tess.Elements[i]);
34-
}
35-
36-
for (int i = 0; i < tess.VertexCount; ++i)
37-
{
38-
var position = tess.Vertices[i].Position;
39-
meshData.vertices.Add(new Vector3(position.X, position.Y, position.Z));
40-
meshData.colors.Add(color);
41-
}
42-
43-
return meshData;
44-
}
45-
46-
public static MeshData TesselatePolygonExtrusion(Geometry geometry, Color color, float minHeight, float height)
47-
{
48-
var meshData = new MeshData();
49-
int pointIndex = 0;
50-
int indexOffset = 0;
51-
52-
foreach (var ringSize in geometry.rings)
53-
{
54-
for (int i = pointIndex; i < pointIndex + ringSize - 1; i++)
55-
{
56-
var p0 = geometry.points[i];
57-
var p1 = geometry.points[i+1];
58-
59-
meshData.vertices.Add(new Vector3(p0.x, height, p0.y));
60-
meshData.vertices.Add(new Vector3(p1.x, height, p1.y));
61-
meshData.vertices.Add(new Vector3(p0.x, minHeight, p0.y));
62-
meshData.vertices.Add(new Vector3(p1.x, minHeight, p1.y));
63-
64-
for (int colorIndex = 0; colorIndex < 4; ++colorIndex)
65-
{
66-
meshData.colors.Add(color);
67-
}
68-
69-
meshData.indices.Add(indexOffset + 2);
70-
meshData.indices.Add(indexOffset + 3);
71-
meshData.indices.Add(indexOffset + 1);
72-
meshData.indices.Add(indexOffset + 2);
73-
meshData.indices.Add(indexOffset + 1);
74-
meshData.indices.Add(indexOffset + 0);
75-
76-
indexOffset += 4;
77-
}
78-
79-
pointIndex += ringSize;
80-
}
81-
82-
return meshData;
83-
}
8+
public static MeshData TesselatePolygon(Geometry geometry, Color color, float height)
9+
{
10+
var meshData = new MeshData();
11+
var tess = new Tess();
12+
13+
int pointIndex = 0;
14+
foreach (var ringSize in geometry.rings)
15+
{
16+
var contour = new ContourVertex[ringSize];
17+
18+
for (int i = pointIndex, contourIndex = 0; i < pointIndex + ringSize; ++i, ++contourIndex)
19+
{
20+
var point = geometry.points[i];
21+
contour[contourIndex].Position = new Vec3 { X = point.x, Y = height, Z = point.y };
22+
}
23+
24+
pointIndex += ringSize;
25+
26+
tess.AddContour(contour, ContourOrientation.Original);
27+
}
28+
29+
tess.Tessellate(WindingRule.NonZero, ElementType.Polygons, 3);
30+
31+
for (int i = 0; i < tess.ElementCount * 3; ++i)
32+
{
33+
meshData.indices.Add(tess.Elements[i]);
34+
}
35+
36+
for (int i = 0; i < tess.VertexCount; ++i)
37+
{
38+
var position = tess.Vertices[i].Position;
39+
meshData.vertices.Add(new Vector3(position.X, position.Y, position.Z));
40+
meshData.colors.Add(color);
41+
}
42+
43+
return meshData;
44+
}
45+
46+
public static MeshData TesselatePolygonExtrusion(Geometry geometry, Color color, float minHeight, float height)
47+
{
48+
var meshData = new MeshData();
49+
int pointIndex = 0;
50+
int indexOffset = 0;
51+
52+
foreach (var ringSize in geometry.rings)
53+
{
54+
for (int i = pointIndex; i < pointIndex + ringSize - 1; i++)
55+
{
56+
var p0 = geometry.points[i];
57+
var p1 = geometry.points[i + 1];
58+
59+
meshData.vertices.Add(new Vector3(p0.x, height, p0.y));
60+
meshData.vertices.Add(new Vector3(p1.x, height, p1.y));
61+
meshData.vertices.Add(new Vector3(p0.x, minHeight, p0.y));
62+
meshData.vertices.Add(new Vector3(p1.x, minHeight, p1.y));
63+
64+
for (int colorIndex = 0; colorIndex < 4; ++colorIndex)
65+
{
66+
meshData.colors.Add(color);
67+
}
68+
69+
meshData.indices.Add(indexOffset + 2);
70+
meshData.indices.Add(indexOffset + 3);
71+
meshData.indices.Add(indexOffset + 1);
72+
meshData.indices.Add(indexOffset + 2);
73+
meshData.indices.Add(indexOffset + 1);
74+
meshData.indices.Add(indexOffset + 0);
75+
76+
indexOffset += 4;
77+
}
78+
79+
pointIndex += ringSize;
80+
}
81+
82+
return meshData;
83+
}
8484
}

0 commit comments

Comments
 (0)