make more clear some magic numbers on SOP getnumberofsides(), reduce unnecessary calls to it on LSL api

0.9.0.1-postfixes
UbitUmarov 2018-03-05 16:36:39 +00:00
parent f579fbba0e
commit 18914fae64
2 changed files with 74 additions and 46 deletions

View File

@ -3914,9 +3914,9 @@ namespace OpenSim.Region.Framework.Scenes
{
// removed sides
int cut = (Shape.ProfileEnd + Shape.ProfileBegin);
if(cut > 50000)
if(cut > 50000) // range is 0 to 50000
cut = 50000;
cut /= 12500;
cut /= 12500; // ie 1/4
ret -= cut;
ret += 2; // both cut faces
}
@ -3927,9 +3927,9 @@ namespace OpenSim.Region.Framework.Scenes
{
// removed faces
int cut = (Shape.ProfileEnd + Shape.ProfileBegin);
if(cut >= 16667 )
if(cut >= 16667 ) // ie 1/3
ret--;
if(cut >= 33333 )
if(cut >= 33333 ) // ie 2/3
ret--;
ret += 2; // both cut faces
}
@ -3944,7 +3944,7 @@ namespace OpenSim.Region.Framework.Scenes
// cut faces exist if cut or skew or unequal twist limits
if (Shape.PathBegin > 0 || Shape.PathEnd > 0 || Shape.PathSkew != 0 || (Shape.PathTwistBegin != Shape.PathTwist))
ret += 2;
if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0 || Shape.ProfileHollow > 0) // dimple also if hollow
if (Shape.ProfileBegin > 0 || Shape.ProfileEnd > 0 || Shape.ProfileHollow > 0) // dimple faces also if hollow
ret += 2;
break;
case PrimType.TORUS:

View File

@ -1933,8 +1933,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return;
Primitive.TextureEntry tex = part.Shape.Textures;
int nsides = GetNumberOfSides(part);
Color4 texcolor;
if (face >= 0 && face < GetNumberOfSides(part))
if (face >= 0 && face < nsides)
{
texcolor = tex.CreateFace((uint)face).RGBA;
texcolor.R = Util.Clip((float)color.x, 0.0f, 1.0f);
@ -1946,7 +1948,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
else if (face == ScriptBaseClass.ALL_SIDES)
{
for (uint i = 0; i < GetNumberOfSides(part); i++)
for (uint i = 0; i < nsides; i++)
{
if (tex.FaceTextures[i] != null)
{
@ -2063,7 +2065,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (style == (int)ScriptBaseClass.PRIM_TEXGEN_PLANAR)
textype = MappingType.Planar;
if (face >= 0 && face < GetNumberOfSides(part))
int nsides = GetNumberOfSides(part);
if (face >= 0 && face < nsides)
{
tex.CreateFace((uint) face);
tex.FaceTextures[face].TexMapType = textype;
@ -2072,7 +2076,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
else if (face == ScriptBaseClass.ALL_SIDES)
{
for (uint i = 0; i < GetNumberOfSides(part); i++)
for (uint i = 0; i < nsides; i++)
{
if (tex.FaceTextures[i] != null)
{
@ -2091,7 +2095,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return;
Primitive.TextureEntry tex = part.Shape.Textures;
if (face >= 0 && face < GetNumberOfSides(part))
int nsides = GetNumberOfSides(part);
if (face >= 0 && face < nsides)
{
tex.CreateFace((uint) face);
tex.FaceTextures[face].Glow = glow;
@ -2100,7 +2106,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
else if (face == ScriptBaseClass.ALL_SIDES)
{
for (uint i = 0; i < GetNumberOfSides(part); i++)
for (uint i = 0; i < nsides; i++)
{
if (tex.FaceTextures[i] != null)
{
@ -2139,8 +2145,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
break;
}
int nsides = GetNumberOfSides(part);
Primitive.TextureEntry tex = part.Shape.Textures;
if (face >= 0 && face < GetNumberOfSides(part))
if (face >= 0 && face < nsides)
{
tex.CreateFace((uint) face);
tex.FaceTextures[face].Shiny = sval;
@ -2150,7 +2158,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
else if (face == ScriptBaseClass.ALL_SIDES)
{
for (uint i = 0; i < GetNumberOfSides(part); i++)
for (uint i = 0; i < nsides; i++)
{
if (tex.FaceTextures[i] != null)
{
@ -2170,8 +2178,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted)
return;
int nsides = GetNumberOfSides(part);
Primitive.TextureEntry tex = part.Shape.Textures;
if (face >= 0 && face < GetNumberOfSides(part))
if (face >= 0 && face < nsides)
{
tex.CreateFace((uint) face);
tex.FaceTextures[face].Fullbright = bright;
@ -2180,7 +2189,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
else if (face == ScriptBaseClass.ALL_SIDES)
{
for (uint i = 0; i < GetNumberOfSides(part); i++)
for (uint i = 0; i < nsides; i++)
{
if (tex.FaceTextures[i] != null)
{
@ -2203,15 +2212,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
protected LSL_Float GetAlpha(SceneObjectPart part, int face)
{
Primitive.TextureEntry tex = part.Shape.Textures;
int nsides = GetNumberOfSides(part);
if (face == ScriptBaseClass.ALL_SIDES)
{
int i;
double sum = 0.0;
for (i = 0 ; i < GetNumberOfSides(part); i++)
for (i = 0 ; i < nsides; i++)
sum += (double)tex.GetFace((uint)i).RGBA.A;
return sum;
}
if (face >= 0 && face < GetNumberOfSides(part))
if (face >= 0 && face < nsides)
{
return (double)tex.GetFace((uint)face).RGBA.A;
}
@ -2247,8 +2257,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return;
Primitive.TextureEntry tex = part.Shape.Textures;
int nsides = GetNumberOfSides(part);
Color4 texcolor;
if (face >= 0 && face < GetNumberOfSides(part))
if (face >= 0 && face < nsides)
{
texcolor = tex.CreateFace((uint)face).RGBA;
texcolor.A = Util.Clip((float)alpha, 0.0f, 1.0f);
@ -2258,7 +2270,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
else if (face == ScriptBaseClass.ALL_SIDES)
{
for (int i = 0; i < GetNumberOfSides(part); i++)
for (int i = 0; i < nsides; i++)
{
if (tex.FaceTextures[i] != null)
{
@ -2446,9 +2458,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return;
}
Primitive.TextureEntry tex = part.Shape.Textures;
if (face >= 0 && face < GetNumberOfSides(part))
Primitive.TextureEntry tex = part.Shape.Textures;
int nsides = GetNumberOfSides(part);
if (face >= 0 && face < nsides)
{
Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
texface.TextureID = textureID;
@ -2458,7 +2472,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
else if (face == ScriptBaseClass.ALL_SIDES)
{
for (uint i = 0; i < GetNumberOfSides(part); i++)
for (uint i = 0; i < nsides; i++)
{
if (tex.FaceTextures[i] != null)
{
@ -2485,7 +2499,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return;
Primitive.TextureEntry tex = part.Shape.Textures;
if (face >= 0 && face < GetNumberOfSides(part))
int nsides = GetNumberOfSides(part);
if (face >= 0 && face < nsides)
{
Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
texface.RepeatU = (float)u;
@ -2496,7 +2512,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
if (face == ScriptBaseClass.ALL_SIDES)
{
for (int i = 0; i < GetNumberOfSides(part); i++)
for (int i = 0; i < nsides; i++)
{
if (tex.FaceTextures[i] != null)
{
@ -2524,7 +2540,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return;
Primitive.TextureEntry tex = part.Shape.Textures;
if (face >= 0 && face < GetNumberOfSides(part))
int nsides = GetNumberOfSides(part);
if (face >= 0 && face < nsides)
{
Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
texface.OffsetU = (float)u;
@ -2535,7 +2553,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
if (face == ScriptBaseClass.ALL_SIDES)
{
for (int i = 0; i < GetNumberOfSides(part); i++)
for (int i = 0; i < nsides; i++)
{
if (tex.FaceTextures[i] != null)
{
@ -2563,7 +2581,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return;
Primitive.TextureEntry tex = part.Shape.Textures;
if (face >= 0 && face < GetNumberOfSides(part))
int nsides = GetNumberOfSides(part);
if (face >= 0 && face < nsides)
{
Primitive.TextureEntryFace texface = tex.CreateFace((uint)face);
texface.Rotation = (float)rotation;
@ -2573,7 +2593,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
if (face == ScriptBaseClass.ALL_SIDES)
{
for (int i = 0; i < GetNumberOfSides(part); i++)
for (int i = 0; i < nsides; i++)
{
if (tex.FaceTextures[i] != null)
{
@ -2595,12 +2615,14 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
protected LSL_String GetTexture(SceneObjectPart part, int face)
{
Primitive.TextureEntry tex = part.Shape.Textures;
int nsides = GetNumberOfSides(part);
if (face == ScriptBaseClass.ALL_SIDES)
{
face = 0;
}
if (face >= 0 && face < GetNumberOfSides(part))
if (face >= 0 && face < nsides)
{
Primitive.TextureEntryFace texface;
texface = tex.GetFace((uint)face);
@ -5459,7 +5481,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
{
m_host.AddScriptLPS(1);
return GetNumberOfSides(m_host);
return m_host.GetNumberOfSides();
}
protected int GetNumberOfSides(SceneObjectPart part)
@ -10836,6 +10858,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
public LSL_List GetPrimParams(SceneObjectPart part, LSL_List rules, ref LSL_List res)
{
int idx = 0;
int face;
Primitive.TextureEntry tex;
int nsides = GetNumberOfSides(part);
while (idx < rules.Length)
{
int code = (int)rules.GetLSLIntegerItem(idx++);
@ -10976,11 +11002,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
if (remain < 1)
return new LSL_List();
int face = (int)rules.GetLSLIntegerItem(idx++);
Primitive.TextureEntry tex = part.Shape.Textures;
face = (int)rules.GetLSLIntegerItem(idx++);
tex = part.Shape.Textures;
if (face == ScriptBaseClass.ALL_SIDES)
{
for (face = 0; face < GetNumberOfSides(part); face++)
for (face = 0; face < nsides; face++)
{
Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
@ -10996,7 +11023,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
else
{
if (face >= 0 && face < GetNumberOfSides(part))
if (face >= 0 && face < nsides)
{
Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
@ -11017,12 +11044,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
return new LSL_List();
face = (int)rules.GetLSLIntegerItem(idx++);
tex = part.Shape.Textures;
Color4 texcolor;
if (face == ScriptBaseClass.ALL_SIDES)
{
for (face = 0; face < GetNumberOfSides(part); face++)
for (face = 0; face < nsides; face++)
{
texcolor = tex.GetFace((uint)face).RGBA;
res.Add(new LSL_Vector(texcolor.R,
@ -11042,16 +11069,16 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
break;
case (int)ScriptBaseClass.PRIM_BUMP_SHINY:
{
if (remain < 1)
return new LSL_List();
face = (int)rules.GetLSLIntegerItem(idx++);
tex = part.Shape.Textures;
int shiny;
if (face == ScriptBaseClass.ALL_SIDES)
{
for (face = 0; face < GetNumberOfSides(part); face++)
for (face = 0; face < nsides; face++)
{
Shininess shinyness = tex.GetFace((uint)face).Shiny;
if (shinyness == Shininess.High)
@ -11097,8 +11124,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
res.Add(new LSL_Integer((int)tex.GetFace((uint)face).Bump));
}
break;
}
case (int)ScriptBaseClass.PRIM_FULLBRIGHT:
{
if (remain < 1)
return new LSL_List();
@ -11108,7 +11136,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
int fullbright;
if (face == ScriptBaseClass.ALL_SIDES)
{
for (face = 0; face < GetNumberOfSides(part); face++)
for (face = 0; face < nsides; face++)
{
if (tex.GetFace((uint)face).Fullbright == true)
{
@ -11134,7 +11162,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
res.Add(new LSL_Integer(fullbright));
}
break;
}
case (int)ScriptBaseClass.PRIM_FLEXIBLE:
PrimitiveBaseShape shape = part.Shape;
@ -11162,7 +11190,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
tex = part.Shape.Textures;
if (face == ScriptBaseClass.ALL_SIDES)
{
for (face = 0; face < GetNumberOfSides(part); face++)
for (face = 0; face < nsides; face++)
{
if (tex.GetFace((uint)face).TexMapType == MappingType.Planar)
{
@ -11212,7 +11240,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
float primglow;
if (face == ScriptBaseClass.ALL_SIDES)
{
for (face = 0; face < GetNumberOfSides(part); face++)
for (face = 0; face < nsides; face++)
{
primglow = tex.GetFace((uint)face).Glow;
res.Add(new LSL_Float(primglow));
@ -11306,7 +11334,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
tex = part.Shape.Textures;
if (face == ScriptBaseClass.ALL_SIDES)
{
for (face = 0; face < GetNumberOfSides(part); face++)
for (face = 0; face < nsides; face++)
{
Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
getLSLFaceMaterial(ref res, code, part, texface);
@ -11314,7 +11342,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
}
else
{
if (face >= 0 && face < GetNumberOfSides(part))
if (face >= 0 && face < nsides)
{
Primitive.TextureEntryFace texface = tex.GetFace((uint)face);
getLSLFaceMaterial(ref res, code, part, texface);