code aesthetics and simplification

0.9.1.0-post-fixes
UbitUmarov 2018-11-17 18:52:16 +00:00
parent 852e20a5a7
commit 87a723cbc8
1 changed files with 56 additions and 122 deletions

View File

@ -1026,117 +1026,109 @@ namespace OpenSim.Framework
{ {
// m_log.DebugFormat("[EXTRAPARAMS]: Called ExtraParamsToBytes()"); // m_log.DebugFormat("[EXTRAPARAMS]: Called ExtraParamsToBytes()");
ushort FlexiEP = 0x10; const byte FlexiEP = 0x10;
ushort LightEP = 0x20; const byte LightEP = 0x20;
ushort SculptEP = 0x30; const byte SculptEP = 0x30;
ushort ProjectionEP = 0x40; const byte ProjectionEP = 0x40;
int i = 0; int TotalBytesLength = 1; // ExtraParamsNum
uint TotalBytesLength = 1; // ExtraParamsNum
uint ExtraParamsNum = 0; uint ExtraParamsNum = 0;
if (_flexiEntry) if (_flexiEntry)
{ {
ExtraParamsNum++; ExtraParamsNum++;
TotalBytesLength += 16;// data TotalBytesLength += 16 + 2 + 4;// data
TotalBytesLength += 2 + 4; // type
} }
if (_lightEntry) if (_lightEntry)
{ {
ExtraParamsNum++; ExtraParamsNum++;
TotalBytesLength += 16;// data TotalBytesLength += 16 + 2 + 4; // data
TotalBytesLength += 2 + 4; // type
} }
if (_sculptEntry) if (_sculptEntry)
{ {
ExtraParamsNum++; ExtraParamsNum++;
TotalBytesLength += 17;// data TotalBytesLength += 17 + 2 + 4;// data
TotalBytesLength += 2 + 4; // type
} }
if (_projectionEntry) if (_projectionEntry)
{ {
ExtraParamsNum++; ExtraParamsNum++;
TotalBytesLength += 28;// data TotalBytesLength += 28 + 2 + 4; // data
TotalBytesLength += 2 + 4;// type
} }
byte[] returnbytes = new byte[TotalBytesLength]; byte[] returnBytes = new byte[TotalBytesLength];
// uint paramlength = ExtraParamsNum; returnBytes[0] = (byte)ExtraParamsNum;
// Stick in the number of parameters if(ExtraParamsNum == 0)
returnbytes[i++] = (byte)ExtraParamsNum; return returnBytes;
int i = 1;
if (_flexiEntry) if (_flexiEntry)
{ {
byte[] FlexiData = GetFlexiBytes(); returnBytes[i] = FlexiEP; // 2 bytes id code
i += 2;
returnBytes[i] = 16; // 4 bytes size
i += 4;
returnbytes[i++] = (byte)(FlexiEP % 256); // Softness is packed in the upper bits of tension and drag
returnbytes[i++] = (byte)((FlexiEP >> 8) % 256); returnBytes[i] = (byte)((_flexiSoftness & 2) << 6);
returnBytes[i + 1] = (byte)((_flexiSoftness & 1) << 7);
returnbytes[i++] = (byte)(FlexiData.Length % 256); returnBytes[i++] |= (byte)((byte)(_flexiTension * 10.01f) & 0x7F);
returnbytes[i++] = (byte)((FlexiData.Length >> 8) % 256); returnBytes[i++] |= (byte)((byte)(_flexiDrag * 10.01f) & 0x7F);
returnbytes[i++] = (byte)((FlexiData.Length >> 16) % 256); returnBytes[i++] = (byte)((_flexiGravity + 10.0f) * 10.01f);
returnbytes[i++] = (byte)((FlexiData.Length >> 24) % 256); returnBytes[i++] = (byte)(_flexiWind * 10.01f);
Array.Copy(FlexiData, 0, returnbytes, i, FlexiData.Length); Vector3 lForce = new Vector3(_flexiForceX, _flexiForceY, _flexiForceZ);
i += FlexiData.Length; lForce.GetBytes().CopyTo(returnBytes, i);
i += 12;
} }
if (_lightEntry) if (_lightEntry)
{ {
byte[] LightData = GetLightBytes(); returnBytes[i] = LightEP;
i += 2;
returnBytes[i] = 16;
i += 4;
returnbytes[i++] = (byte)(LightEP % 256); // Alpha channel in color is intensity
returnbytes[i++] = (byte)((LightEP >> 8) % 256); Color4 tmpColor = new Color4(_lightColorR, _lightColorG, _lightColorB, _lightIntensity);
tmpColor.GetBytes().CopyTo(returnBytes, i);
returnbytes[i++] = (byte)(LightData.Length % 256); Utils.FloatToBytes(_lightRadius).CopyTo(returnBytes, i + 4);
returnbytes[i++] = (byte)((LightData.Length >> 8) % 256); Utils.FloatToBytes(_lightCutoff).CopyTo(returnBytes, i + 8);
returnbytes[i++] = (byte)((LightData.Length >> 16) % 256); Utils.FloatToBytes(_lightFalloff).CopyTo(returnBytes, i + 12);
returnbytes[i++] = (byte)((LightData.Length >> 24) % 256); i += 16;
Array.Copy(LightData, 0, returnbytes, i, LightData.Length);
i += LightData.Length;
} }
if (_sculptEntry) if (_sculptEntry)
{ {
byte[] SculptData = GetSculptBytes(); returnBytes[i] = SculptEP;
i += 2;
returnBytes[i] = 17;
i += 4;
returnbytes[i++] = (byte)(SculptEP % 256); _sculptTexture.GetBytes().CopyTo(returnBytes, i);
returnbytes[i++] = (byte)((SculptEP >> 8) % 256); i += 16;
returnBytes[i++] = _sculptType;
returnbytes[i++] = (byte)(SculptData.Length % 256);
returnbytes[i++] = (byte)((SculptData.Length >> 8) % 256);
returnbytes[i++] = (byte)((SculptData.Length >> 16) % 256);
returnbytes[i++] = (byte)((SculptData.Length >> 24) % 256);
Array.Copy(SculptData, 0, returnbytes, i, SculptData.Length);
i += SculptData.Length;
} }
if (_projectionEntry) if (_projectionEntry)
{ {
byte[] ProjectionData = GetProjectionBytes(); returnBytes[i] = ProjectionEP;
i += 2;
returnBytes[i] = 28;
i += 4;
returnbytes[i++] = (byte)(ProjectionEP % 256); _projectionTextureID.GetBytes().CopyTo(returnBytes, i);
returnbytes[i++] = (byte)((ProjectionEP >> 8) % 256); Utils.FloatToBytes(_projectionFOV).CopyTo(returnBytes, i + 16);
returnbytes[i++] = (byte)((ProjectionData.Length) % 256); Utils.FloatToBytes(_projectionFocus).CopyTo(returnBytes, i + 20);
returnbytes[i++] = (byte)((ProjectionData.Length >> 16) % 256); Utils.FloatToBytes(_projectionAmb).CopyTo(returnBytes, i + 24);
returnbytes[i++] = (byte)((ProjectionData.Length >> 20) % 256);
returnbytes[i++] = (byte)((ProjectionData.Length >> 24) % 256);
Array.Copy(ProjectionData, 0, returnbytes, i, ProjectionData.Length);
i += ProjectionData.Length;
} }
if (!_flexiEntry && !_lightEntry && !_sculptEntry && !_projectionEntry) return returnBytes;
{
byte[] returnbyte = new byte[1];
returnbyte[0] = 0;
return returnbyte;
}
return returnbytes;
} }
public void ReadInUpdateExtraParam(ushort type, bool inUse, byte[] data) public void ReadInUpdateExtraParam(ushort type, bool inUse, byte[] data)
@ -1283,16 +1275,6 @@ namespace OpenSim.Framework
//m_log.Info("[SCULPT]:" + SculptUUID.ToString()); //m_log.Info("[SCULPT]:" + SculptUUID.ToString());
} }
public byte[] GetSculptBytes()
{
byte[] data = new byte[17];
_sculptTexture.GetBytes().CopyTo(data, 0);
data[16] = (byte)_sculptType;
return data;
}
public void ReadFlexiData(byte[] data, int pos) public void ReadFlexiData(byte[] data, int pos)
{ {
if (data.Length-pos >= 16) if (data.Length-pos >= 16)
@ -1324,25 +1306,6 @@ namespace OpenSim.Framework
} }
} }
public byte[] GetFlexiBytes()
{
byte[] data = new byte[16];
int i = 0;
// Softness is packed in the upper bits of tension and drag
data[i] = (byte)((_flexiSoftness & 2) << 6);
data[i + 1] = (byte)((_flexiSoftness & 1) << 7);
data[i++] |= (byte)((byte)(_flexiTension * 10.01f) & 0x7F);
data[i++] |= (byte)((byte)(_flexiDrag * 10.01f) & 0x7F);
data[i++] = (byte)((_flexiGravity + 10.0f) * 10.01f);
data[i++] = (byte)(_flexiWind * 10.01f);
Vector3 lForce = new Vector3(_flexiForceX, _flexiForceY, _flexiForceZ);
lForce.GetBytes().CopyTo(data, i);
return data;
}
public void ReadLightData(byte[] data, int pos) public void ReadLightData(byte[] data, int pos)
{ {
if (data.Length - pos >= 16) if (data.Length - pos >= 16)
@ -1373,21 +1336,6 @@ namespace OpenSim.Framework
} }
} }
public byte[] GetLightBytes()
{
byte[] data = new byte[16];
// Alpha channel in color is intensity
Color4 tmpColor = new Color4(_lightColorR,_lightColorG,_lightColorB,_lightIntensity);
tmpColor.GetBytes().CopyTo(data, 0);
Utils.FloatToBytes(_lightRadius).CopyTo(data, 4);
Utils.FloatToBytes(_lightCutoff).CopyTo(data, 8);
Utils.FloatToBytes(_lightFalloff).CopyTo(data, 12);
return data;
}
public void ReadProjectionData(byte[] data, int pos) public void ReadProjectionData(byte[] data, int pos)
{ {
byte[] ProjectionTextureUUID = new byte[16]; byte[] ProjectionTextureUUID = new byte[16];
@ -1412,19 +1360,6 @@ namespace OpenSim.Framework
} }
} }
public byte[] GetProjectionBytes()
{
byte[] data = new byte[28];
_projectionTextureID.GetBytes().CopyTo(data, 0);
Utils.FloatToBytes(_projectionFOV).CopyTo(data, 16);
Utils.FloatToBytes(_projectionFocus).CopyTo(data, 20);
Utils.FloatToBytes(_projectionAmb).CopyTo(data, 24);
return data;
}
/// <summary> /// <summary>
/// Creates a OpenMetaverse.Primitive and populates it with converted PrimitiveBaseShape values /// Creates a OpenMetaverse.Primitive and populates it with converted PrimitiveBaseShape values
/// </summary> /// </summary>
@ -1436,7 +1371,6 @@ namespace OpenSim.Framework
new Quaternion(0.0f, 0.0f, 0.0f, 1.0f)); new Quaternion(0.0f, 0.0f, 0.0f, 1.0f));
} }
/// <summary> /// <summary>
/// Creates a OpenMetaverse.Primitive and populates it with converted PrimitiveBaseShape values /// Creates a OpenMetaverse.Primitive and populates it with converted PrimitiveBaseShape values
/// </summary> /// </summary>