{\r
if (e.Simulator.Handle == Client.Network.CurrentSim.Handle)\r
{\r
- TerrainModified = true;\r
+ terrainModified = true;\r
}\r
}\r
\r
#endregion Keyboard\r
\r
#region Terrain\r
- bool TerrainModified = true;\r
+ bool terrainModified = true;\r
float[,] heightTable = new float[256, 256];\r
Face terrainFace;\r
ushort[] terrainIndices;\r
Bitmap terrainImage = null;\r
int terrainVBO = -1;\r
int terrainIndexVBO = -1;\r
+ bool terrainInProgress = false;\r
+ bool terrainTextureNeedsUpdate = false;\r
+ float terrainTimeSinceUpdate = RenderSettings.MinimumTimeBetweenTerrainUpdated + 1f; // Update terrain om first run\r
\r
private void ResetTerrain()\r
{\r
}\r
\r
fetchingTerrainTexture = false;\r
- TerrainModified = true;\r
+ terrainModified = true;\r
}\r
\r
private void UpdateTerrain()\r
{\r
if (Client.Network.CurrentSim == null || Client.Network.CurrentSim.Terrain == null) return;\r
- int step = 1;\r
\r
- for (int x = 0; x < 255; x += step)\r
+ ThreadPool.QueueUserWorkItem(sync =>\r
{\r
- for (int y = 0; y < 255; y += step)\r
+ int step = 1;\r
+\r
+ for (int x = 0; x < 255; x += step)\r
{\r
- float z = 0;\r
- int patchNr = ((int)x / 16) * 16 + (int)y / 16;\r
- if (Client.Network.CurrentSim.Terrain[patchNr] != null\r
- && Client.Network.CurrentSim.Terrain[patchNr].Data != null)\r
+ for (int y = 0; y < 255; y += step)\r
{\r
- float[] data = Client.Network.CurrentSim.Terrain[patchNr].Data;\r
- z = data[(int)x % 16 * 16 + (int)y % 16];\r
+ float z = 0;\r
+ int patchNr = ((int)x / 16) * 16 + (int)y / 16;\r
+ if (Client.Network.CurrentSim.Terrain[patchNr] != null\r
+ && Client.Network.CurrentSim.Terrain[patchNr].Data != null)\r
+ {\r
+ float[] data = Client.Network.CurrentSim.Terrain[patchNr].Data;\r
+ z = data[(int)x % 16 * 16 + (int)y % 16];\r
+ }\r
+ heightTable[x, y] = z;\r
}\r
- heightTable[x, y] = z;\r
}\r
- }\r
\r
- terrainFace = renderer.TerrainMesh(heightTable, 0f, 255f, 0f, 255f);\r
- terrainVertices = new ColorVertex[terrainFace.Vertices.Count];\r
- for (int i = 0; i < terrainFace.Vertices.Count; i++)\r
- {\r
- byte[] part = Utils.IntToBytes(i);\r
- terrainVertices[i] = new ColorVertex()\r
+ terrainFace = renderer.TerrainMesh(heightTable, 0f, 255f, 0f, 255f);\r
+ terrainVertices = new ColorVertex[terrainFace.Vertices.Count];\r
+ for (int i = 0; i < terrainFace.Vertices.Count; i++)\r
{\r
- Vertex = terrainFace.Vertices[i],\r
- Color = new Color4b()\r
+ byte[] part = Utils.IntToBytes(i);\r
+ terrainVertices[i] = new ColorVertex()\r
{\r
- R = part[0],\r
- G = part[1],\r
- B = part[2],\r
- A = 253 // terrain picking\r
- }\r
- };\r
- }\r
- terrainIndices = terrainFace.Indices.ToArray();\r
- TerrainModified = false;\r
+ Vertex = terrainFace.Vertices[i],\r
+ Color = new Color4b()\r
+ {\r
+ R = part[0],\r
+ G = part[1],\r
+ B = part[2],\r
+ A = 253 // terrain picking\r
+ }\r
+ };\r
+ }\r
+ terrainIndices = terrainFace.Indices.ToArray();\r
+ terrainInProgress = false;\r
+ terrainModified = false;\r
+ terrainTextureNeedsUpdate = true;\r
+ terrainTimeSinceUpdate = 0f;\r
+ });\r
}\r
\r
void UpdateTerrainTexture()\r
new float[] { sim.TerrainHeightRange00, sim.TerrainHeightRange01, sim.TerrainHeightRange10, sim.TerrainHeightRange11 });\r
\r
fetchingTerrainTexture = false;\r
+ terrainTextureNeedsUpdate = false;\r
});\r
}\r
}\r
\r
private void RenderTerrain(RenderPass pass)\r
{\r
+ terrainTimeSinceUpdate += lastFrameTime;\r
+\r
+ if (terrainModified && terrainTimeSinceUpdate > RenderSettings.MinimumTimeBetweenTerrainUpdated)\r
+ {\r
+ if (!terrainInProgress)\r
+ {\r
+ terrainInProgress = true;\r
+ ResetTerrain(false);\r
+ UpdateTerrain();\r
+ }\r
+ }\r
+\r
+ if (terrainTextureNeedsUpdate)\r
+ {\r
+ UpdateTerrainTexture();\r
+ }\r
+\r
+ if (terrainIndices == null || terrainVertices == null) return;\r
+\r
GL.Color3(1f, 1f, 1f);\r
GL.EnableClientState(ArrayCap.VertexArray);\r
GL.EnableClientState(ArrayCap.TextureCoordArray);\r
GL.ShadeModel(ShadingModel.Flat);\r
}\r
\r
- if (TerrainModified)\r
- {\r
- ResetTerrain(false);\r
- UpdateTerrain();\r
- UpdateTerrainTexture();\r
- }\r
-\r
if (terrainImage != null)\r
{\r
if (terrainTexture != -1)\r
GL.BindBuffer(BufferTarget.ArrayBuffer, 0);\r
GL.BindBuffer(BufferTarget.ElementArrayBuffer, 0);\r
}\r
-\r
+ \r
if (pass == RenderPass.Picking)\r
{\r
GL.DisableClientState(ArrayCap.ColorArray);\r