From 7bbda6651ef42c798ca2b3acd0b801fddcaa31e6 Mon Sep 17 00:00:00 2001 From: Teravus Ovares Date: Fri, 19 Dec 2008 00:06:19 +0000 Subject: * 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 | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs b/OpenSim/Region/Environment/Modules/World/Terrain/TerrainChannel.cs index 5c3eb7d..1534c4b 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; - - for (i = 0; i < Width * Height; 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]; + + 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; -- cgit v1.1