From 7bbda6651ef42c798ca2b3acd0b801fddcaa31e6 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Fri, 19 Dec 2008 00:06:19 +0000 Subject: [PATCH] * Commit patch from cmickeyb. #2871. Optimized float array for the terrain heightfield to reduce cpu usage on new client significantly. Thanks cmickeyb! --- .../Modules/World/Terrain/TerrainChannel.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs index 5c3eb7d0fa..1534c4bf25 100644 --- a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs +++ b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs @@ -108,12 +108,20 @@ namespace OpenSim.Region.Environment.Modules.World.Terrain public float[] GetFloatsSerialised() { - float[] heights = new float[Width * Height]; - int i; + // Move the member variables into local variables, calling + // member variables 256*256 times gets expensive + int w = Width; + int h = Height; + float[] heights = new float[w * h]; - for (i = 0; i < Width * Height; i++) + int i, j; // map coordinates + int idx = 0; // index into serialized array + for (i = 0; i < h; i++) { - heights[i] = (float) map[i % Width, i / Width]; + for (j = 0; j < w; j++) + { + heights[idx++] = (float)map[j, i]; + } } return heights;