diff options
author | UbitUmarov | 2015-08-21 20:19:04 +0100 |
---|---|---|
committer | UbitUmarov | 2015-08-21 20:19:04 +0100 |
commit | 17082da0daedf375d2965170d72a60919d8b0a53 (patch) | |
tree | b98db6c4dd919f69f1530343a0cfc377ea42aa9f /OpenSim/Region/CoreModules/World/Terrain | |
parent | dont use SendTerrainUpdatesByViewDistance option, code executes as true. (diff) | |
download | opensim-SC-17082da0daedf375d2965170d72a60919d8b0a53.zip opensim-SC-17082da0daedf375d2965170d72a60919d8b0a53.tar.gz opensim-SC-17082da0daedf375d2965170d72a60919d8b0a53.tar.bz2 opensim-SC-17082da0daedf375d2965170d72a60919d8b0a53.tar.xz |
"uglyfy" GetModifiedPatchesInViewDistance. Also make it use camera or
avatar position
Diffstat (limited to 'OpenSim/Region/CoreModules/World/Terrain')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | 99 |
1 files changed, 71 insertions, 28 deletions
diff --git a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs index 024c29b..dfafcad 100644 --- a/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs +++ b/OpenSim/Region/CoreModules/World/Terrain/TerrainModule.cs | |||
@@ -1031,47 +1031,90 @@ namespace OpenSim.Region.CoreModules.World.Terrain | |||
1031 | { | 1031 | { |
1032 | List<PatchesToSend> ret = new List<PatchesToSend>(); | 1032 | List<PatchesToSend> ret = new List<PatchesToSend>(); |
1033 | 1033 | ||
1034 | int npatchs = 0; | ||
1035 | |||
1034 | ScenePresence presence = pups.Presence; | 1036 | ScenePresence presence = pups.Presence; |
1035 | if (presence == null) | 1037 | if (presence == null) |
1036 | return ret; | 1038 | return ret; |
1037 | 1039 | ||
1040 | float minz = presence.AbsolutePosition.Z; | ||
1041 | if (presence.CameraPosition.Z < minz) | ||
1042 | minz = presence.CameraPosition.Z; | ||
1043 | |||
1044 | // this limit should be max terrainheight + max draw | ||
1045 | if (minz > 1500f) | ||
1046 | return ret; | ||
1047 | |||
1048 | int DrawDistance = (int)presence.DrawDistance; | ||
1049 | |||
1050 | DrawDistance = DrawDistance / Constants.TerrainPatchSize; | ||
1051 | |||
1052 | int testposX; | ||
1053 | int testposY; | ||
1054 | |||
1055 | if (Math.Abs(presence.AbsolutePosition.X - presence.CameraPosition.X) > 30 | ||
1056 | || Math.Abs(presence.AbsolutePosition.Y - presence.CameraPosition.Y) > 30) | ||
1057 | { | ||
1058 | testposX = (int)presence.CameraPosition.X / Constants.TerrainPatchSize; | ||
1059 | testposY = (int)presence.CameraPosition.Y / Constants.TerrainPatchSize; | ||
1060 | } | ||
1061 | else | ||
1062 | { | ||
1063 | testposX = (int)presence.AbsolutePosition.X / Constants.TerrainPatchSize; | ||
1064 | testposY = (int)presence.AbsolutePosition.Y / Constants.TerrainPatchSize; | ||
1065 | } | ||
1066 | int limitX = (int)m_scene.RegionInfo.RegionSizeX / Constants.TerrainPatchSize; | ||
1067 | int limitY = (int)m_scene.RegionInfo.RegionSizeY / Constants.TerrainPatchSize; | ||
1068 | |||
1038 | // Compute the area of patches within our draw distance | 1069 | // Compute the area of patches within our draw distance |
1039 | int startX = (((int) (presence.AbsolutePosition.X - presence.DrawDistance))/Constants.TerrainPatchSize) - 2; | 1070 | int startX = testposX - DrawDistance; |
1040 | startX = Math.Max(startX, 0); | 1071 | if (startX < 0) |
1041 | startX = Math.Min(startX, (int)m_scene.RegionInfo.RegionSizeX/Constants.TerrainPatchSize); | 1072 | startX = 0; |
1042 | int startY = (((int) (presence.AbsolutePosition.Y - presence.DrawDistance))/Constants.TerrainPatchSize) - 2; | 1073 | else if (startX > limitX) |
1043 | startY = Math.Max(startY, 0); | 1074 | startX = limitX; |
1044 | startY = Math.Min(startY, (int)m_scene.RegionInfo.RegionSizeY/Constants.TerrainPatchSize); | 1075 | |
1045 | int endX = (((int) (presence.AbsolutePosition.X + presence.DrawDistance))/Constants.TerrainPatchSize) + 2; | 1076 | int startY = testposY - DrawDistance; |
1046 | endX = Math.Max(endX, 0); | 1077 | if (startY < 0) |
1047 | endX = Math.Min(endX, (int)m_scene.RegionInfo.RegionSizeX/Constants.TerrainPatchSize); | 1078 | startY = 0; |
1048 | int endY = (((int) (presence.AbsolutePosition.Y + presence.DrawDistance))/Constants.TerrainPatchSize) + 2; | 1079 | else if (startY > limitY) |
1049 | endY = Math.Max(endY, 0); | 1080 | startY = limitY; |
1050 | endY = Math.Min(endY, (int)m_scene.RegionInfo.RegionSizeY/Constants.TerrainPatchSize); | 1081 | |
1051 | // m_log.DebugFormat("{0} GetModifiedPatchesInViewDistance. rName={1}, ddist={2}, apos={3}, start=<{4},{5}>, end=<{6},{7}>", | 1082 | int endX = testposX + DrawDistance; |
1052 | // LogHeader, m_scene.RegionInfo.RegionName, | 1083 | if (endX < 0) |
1053 | // presence.DrawDistance, presence.AbsolutePosition, | 1084 | endX = 0; |
1054 | // startX, startY, endX, endY); | 1085 | else if (endX > limitX) |
1086 | endX = limitX; | ||
1087 | |||
1088 | int endY = testposY + DrawDistance; | ||
1089 | if (endY < 0) | ||
1090 | endY = 0; | ||
1091 | else if (endY > limitY) | ||
1092 | endY = limitY; | ||
1093 | |||
1094 | int distx; | ||
1095 | int disty; | ||
1096 | int distsq; | ||
1097 | |||
1098 | DrawDistance *= DrawDistance; | ||
1099 | |||
1055 | for (int x = startX; x < endX; x++) | 1100 | for (int x = startX; x < endX; x++) |
1056 | { | 1101 | { |
1057 | for (int y = startY; y < endY; y++) | 1102 | for (int y = startY; y < endY; y++) |
1058 | { | 1103 | { |
1059 | //Need to make sure we don't send the same ones over and over | ||
1060 | Vector3 presencePos = presence.AbsolutePosition; | ||
1061 | Vector3 patchPos = new Vector3(x * Constants.TerrainPatchSize, y * Constants.TerrainPatchSize, presencePos.Z); | ||
1062 | if (pups.GetByPatch(x, y)) | 1104 | if (pups.GetByPatch(x, y)) |
1063 | { | 1105 | { |
1064 | //Check which has less distance, camera or avatar position, both have to be done. | 1106 | distx = x - testposX; |
1065 | //Its not a radius, its a diameter and we add 50 so that it doesn't look like it cuts off | 1107 | disty = y - testposY; |
1066 | if (Util.DistanceLessThan(presencePos, patchPos, presence.DrawDistance + 50) | 1108 | distsq = distx * distx + disty * disty; |
1067 | || Util.DistanceLessThan(presence.CameraPosition, patchPos, presence.DrawDistance + 50)) | 1109 | if (distsq < DrawDistance) |
1068 | { | 1110 | { |
1069 | //They can see it, send it to them | ||
1070 | pups.SetByPatch(x, y, false); | 1111 | pups.SetByPatch(x, y, false); |
1071 | float dist = Vector3.DistanceSquared(presencePos, patchPos); | 1112 | ret.Add(new PatchesToSend(x, y, (float)distsq)); |
1072 | ret.Add(new PatchesToSend(x, y, dist)); | 1113 | if (npatchs++ > 65536) |
1073 | //Wait and send them all at once | 1114 | { |
1074 | // pups.client.SendLayerData(x, y, null); | 1115 | y = endY; |
1116 | x = endX; | ||
1117 | } | ||
1075 | } | 1118 | } |
1076 | } | 1119 | } |
1077 | } | 1120 | } |