-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathPooling.cs
112 lines (100 loc) · 3.24 KB
/
Pooling.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Threading;
using System;
using System.IO;
namespace Quixel
{
internal static class ChunkPool
{
/// <summary>A list of unused chunk objects</summary>
public static List<GameObject> chunkList = new List<GameObject>();
public static int totalCreated = 0;
/// <summary>
/// Gets a chunk from the chunk pool, creates one if the chunk pool is empty
/// </summary>
/// <returns></returns>
public static GameObject getChunk()
{
if (chunkList.Count == 0)
{
totalCreated++;
GameObject obj = (GameObject)GameObject.Instantiate(MeshFactory.chunkObj);
obj.transform.parent = MeshFactory.terrainObj.transform;
return obj;
}
GameObject chunk = chunkList[0];
chunkList.RemoveAt(0);
chunk.SetActive(true);
return chunk;
}
/// <summary>
/// Recycles a chunk gameobject to the chunk pool
/// </summary>
/// <param name="chunk"></param>
public static void recycleChunk(GameObject chunk)
{
chunk.GetComponent<MeshFilter>().sharedMesh = null;
chunk.GetComponent<MeshCollider>().sharedMesh = null;
chunk.SetActive(false);
chunkList.Add(chunk);
}
}
internal static class DensityPool
{
/// <summary>
/// A pool of reusable density arrays.
/// </summary>
//private static Queue<DensityData> densityPool = new Queue<DensityData>();
//private static Queue<DensityData> densityRecycleList = new Queue<DensityData>();
private static DensityThread densityThread;
/// <summary>
/// Initializes the density pool, starts the recycle thread.
/// </summary>
public static void init()
{
//densityThread = new DensityThread();
}
/// <summary>
/// Updates the density pool.
/// </summary>
public static void update()
{
return;
/*
DensityData d;
while ((d = densityThread.getFinishedDensity()) != null)
{
lock(densityPool)
densityPool.Enqueue(d);
}
*/
}
/// <summary>
/// Attempts to pull a recycled array of densities from the pool. Creates one if none found.
/// </summary>
/// <returns></returns>
public static DensityData getDensityData()
{
return new DensityData();
//See: recycleDensityData
/*
if (densityPool.Count == 0)
return new DensityData();
lock (densityPool)
return densityPool.Dequeue();
*/
}
/// <summary>
/// Recycles (threaded) a density data array.
/// </summary>
/// <param name="arr"></param>
public static void recycleDensityData(DensityData arr)
{
//Visual bug caused by recycling densities
//densityThread.queueRecycleDensity(arr);
return;
}
}
}