reduce potencial useless float casts from list items

This commit is contained in:
UbitUmarov
2023-03-15 11:29:35 +00:00
parent 3dd1dd2f76
commit d345288efa
3 changed files with 64 additions and 26 deletions

View File

@@ -275,7 +275,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.sunMoonPosition = (float)rules.GetLSLFloatItem(idx);
wl.sunMoonPosition = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -322,7 +322,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.blurMultiplier = (float)rules.GetLSLFloatItem(idx);
wl.blurMultiplier = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -345,7 +345,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.cloudCoverage = (float)rules.GetLSLFloatItem(idx);
wl.cloudCoverage = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -368,7 +368,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.cloudScale = (float)rules.GetLSLFloatItem(idx);
wl.cloudScale = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -379,7 +379,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.cloudScrollX = (float)rules.GetLSLFloatItem(idx);
wl.cloudScrollX = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -401,7 +401,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.cloudScrollY = (float)rules.GetLSLFloatItem(idx);
wl.cloudScrollY = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -412,7 +412,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.cloudScrollYLock = rules.GetIntegerItem(idx) == 1 ? true : false;
wl.cloudScrollYLock = rules.GetIntegerItem(idx) != 0;
}
catch (InvalidCastException)
{
@@ -435,7 +435,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.densityMultiplier = (float)rules.GetLSLFloatItem(idx);
wl.densityMultiplier = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -446,7 +446,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.distanceMultiplier = (float)rules.GetLSLFloatItem(idx);
wl.distanceMultiplier = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -457,7 +457,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.drawClassicClouds = rules.GetIntegerItem(idx) == 1 ? true : false;
wl.drawClassicClouds = rules.GetIntegerItem(idx) != 0;
}
catch (InvalidCastException)
{
@@ -468,7 +468,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.eastAngle = (float)rules.GetLSLFloatItem(idx);
wl.eastAngle = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -479,7 +479,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.fresnelOffset = (float)rules.GetLSLFloatItem(idx);
wl.fresnelOffset = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -490,7 +490,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.fresnelScale = (float)rules.GetLSLFloatItem(idx);
wl.fresnelScale = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -501,7 +501,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.hazeDensity = (float)rules.GetLSLFloatItem(idx);
wl.hazeDensity = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -512,7 +512,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.hazeHorizon = (float)rules.GetLSLFloatItem(idx);
wl.hazeHorizon = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -581,7 +581,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.refractScaleAbove = (float)rules.GetLSLFloatItem(idx);
wl.refractScaleAbove = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -592,7 +592,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.refractScaleBelow = (float)rules.GetLSLFloatItem(idx);
wl.refractScaleBelow = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -603,7 +603,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.sceneGamma = (float)rules.GetLSLFloatItem(idx);
wl.sceneGamma = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -614,7 +614,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.starBrightness = (float)rules.GetLSLFloatItem(idx);
wl.starBrightness = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -625,7 +625,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.sunGlowFocus = (float)rules.GetLSLFloatItem(idx);
wl.sunGlowFocus = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -636,7 +636,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.sunGlowSize = (float)rules.GetLSLFloatItem(idx);
wl.sunGlowSize = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -659,7 +659,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.underwaterFogModifier = (float)rules.GetLSLFloatItem(idx);
wl.underwaterFogModifier = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{
@@ -682,7 +682,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
idx++;
try
{
wl.waterFogDensityExponent = (float)rules.GetLSLFloatItem(idx);
wl.waterFogDensityExponent = rules.GetStrictFloatItem(idx);
}
catch (InvalidCastException)
{

View File

@@ -895,9 +895,11 @@ namespace OpenSim.Region.ScriptEngine.Shared
public LSL_Types.LSLFloat GetLSLFloatItem(int itemIndex)
{
object o = Data[itemIndex];
if (o is LSL_Types.LSLFloat lfo)
return lfo;
if (o is LSL_Types.LSLInteger lio)
return new LSL_Types.LSLFloat(lio.value);
if (o is Int32 io)
if (o is int io)
return new LSL_Types.LSLFloat(io);
if (o is float fo)
return new LSL_Types.LSLFloat(fo);
@@ -908,6 +910,42 @@ namespace OpenSim.Region.ScriptEngine.Shared
return (LSL_Types.LSLFloat)o;
}
public float GetFloatItem(int itemIndex)
{
object o = Data[itemIndex];
if (o is LSL_Types.LSLFloat lfo)
return (float)lfo.value;
if (o is LSL_Types.LSLInteger lio)
return lio.value;
if (o is int io)
return io;
if (o is float fo)
return fo;
if (o is Double dov)
return (float)dov;
if (o is LSL_Types.LSLString lso)
return Convert.ToSingle(lso.m_string);
return Convert.ToSingle(o.ToString());
}
public float GetStrictFloatItem(int itemIndex)
{
object o = Data[itemIndex];
if (o is LSL_Types.LSLFloat lfo)
return (float)lfo.value;
if (o is LSL_Types.LSLInteger lio)
return lio.value;
if (o is int io)
return io;
if (o is float fo)
return fo;
if (o is double dov)
return (float)dov;
if (o is LSL_Types.LSLString lso)
return Convert.ToSingle(lso.m_string);
throw new InvalidCastException(@"LSL float expected but {o is not null ? o.GetType().Name : ""null"")} given");
}
public LSL_Types.LSLString GetLSLStringItem(int itemIndex)
{
object o = Data[itemIndex];