diff options
author | UbitUmarov | 2019-01-21 08:03:24 +0000 |
---|---|---|
committer | UbitUmarov | 2019-01-21 08:03:24 +0000 |
commit | d7d5f9f77534087d2205dcdc554d535c6359bdff (patch) | |
tree | e2a0508b667d5254fad205015b6b5b57b05fb550 /OpenSim | |
parent | another missing file (diff) | |
download | opensim-SC-d7d5f9f77534087d2205dcdc554d535c6359bdff.zip opensim-SC-d7d5f9f77534087d2205dcdc554d535c6359bdff.tar.gz opensim-SC-d7d5f9f77534087d2205dcdc554d535c6359bdff.tar.bz2 opensim-SC-d7d5f9f77534087d2205dcdc554d535c6359bdff.tar.xz |
change float to byte rounding
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | 132 |
1 files changed, 88 insertions, 44 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs index 2969060..48c3812 100644 --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs | |||
@@ -8342,7 +8342,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8342 | { | 8342 | { |
8343 | cut.x = 0f; | 8343 | cut.x = 0f; |
8344 | } | 8344 | } |
8345 | if (cut.x > 1f) | 8345 | else if (cut.x > 1f) |
8346 | { | 8346 | { |
8347 | cut.x = 1f; | 8347 | cut.x = 1f; |
8348 | } | 8348 | } |
@@ -8350,7 +8350,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8350 | { | 8350 | { |
8351 | cut.y = 0f; | 8351 | cut.y = 0f; |
8352 | } | 8352 | } |
8353 | if (cut.y > 1f) | 8353 | else if (cut.y > 1f) |
8354 | { | 8354 | { |
8355 | cut.y = 1f; | 8355 | cut.y = 1f; |
8356 | } | 8356 | } |
@@ -8395,7 +8395,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8395 | { | 8395 | { |
8396 | twist.x = -1.0f; | 8396 | twist.x = -1.0f; |
8397 | } | 8397 | } |
8398 | if (twist.x > 1.0f) | 8398 | else if (twist.x > 1.0f) |
8399 | { | 8399 | { |
8400 | twist.x = 1.0f; | 8400 | twist.x = 1.0f; |
8401 | } | 8401 | } |
@@ -8403,23 +8403,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8403 | { | 8403 | { |
8404 | twist.y = -1.0f; | 8404 | twist.y = -1.0f; |
8405 | } | 8405 | } |
8406 | if (twist.y > 1.0f) | 8406 | else if (twist.y > 1.0f) |
8407 | { | 8407 | { |
8408 | twist.y = 1.0f; | 8408 | twist.y = 1.0f; |
8409 | } | 8409 | } |
8410 | // A fairly large precision error occurs for some calculations, | 8410 | tempFloat = 100.0f * (float)twist.x; |
8411 | // if a float or double is directly cast to a byte or sbyte | 8411 | if (tempFloat >= 0) |
8412 | // variable, in both .Net and Mono. In .Net, coding | 8412 | tempFloat += 0.5f; |
8413 | // "(sbyte)(float)(some expression)" corrects the precision | 8413 | else |
8414 | // errors. But this does not work for Mono. This longer coding | 8414 | tempFloat -= 0.5f; |
8415 | // form of creating a tempoary float variable from the | ||
8416 | // expression first, then casting that variable to a byte or | ||
8417 | // sbyte, works for both .Net and Mono. These types of | ||
8418 | // assignments occur in SetPrimtiveBlockShapeParams and | ||
8419 | // SetPrimitiveShapeParams in support of llSetPrimitiveParams. | ||
8420 | tempFloat = (float)(100.0d * twist.x); | ||
8421 | shapeBlock.PathTwistBegin = (sbyte)tempFloat; | 8415 | shapeBlock.PathTwistBegin = (sbyte)tempFloat; |
8422 | tempFloat = (float)(100.0d * twist.y); | 8416 | |
8417 | tempFloat = 100.0f * (float)twist.y; | ||
8418 | if (tempFloat >= 0) | ||
8419 | tempFloat += 0.5f; | ||
8420 | else | ||
8421 | tempFloat -= 0.5f; | ||
8423 | shapeBlock.PathTwist = (sbyte)tempFloat; | 8422 | shapeBlock.PathTwist = (sbyte)tempFloat; |
8424 | 8423 | ||
8425 | shapeBlock.ObjectLocalID = part.LocalId; | 8424 | shapeBlock.ObjectLocalID = part.LocalId; |
@@ -8443,7 +8442,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8443 | { | 8442 | { |
8444 | taper_b.x = 0f; | 8443 | taper_b.x = 0f; |
8445 | } | 8444 | } |
8446 | if (taper_b.x > 2f) | 8445 | else if (taper_b.x > 2f) |
8447 | { | 8446 | { |
8448 | taper_b.x = 2f; | 8447 | taper_b.x = 2f; |
8449 | } | 8448 | } |
@@ -8451,19 +8450,29 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8451 | { | 8450 | { |
8452 | taper_b.y = 0f; | 8451 | taper_b.y = 0f; |
8453 | } | 8452 | } |
8454 | if (taper_b.y > 2f) | 8453 | else if (taper_b.y > 2f) |
8455 | { | 8454 | { |
8456 | taper_b.y = 2f; | 8455 | taper_b.y = 2f; |
8457 | } | 8456 | } |
8458 | tempFloat = (float)(100.0d * (2.0d - taper_b.x)); | 8457 | tempFloat = 100.0f * (2.0f - (float)taper_b.x); |
8458 | if (tempFloat >= 0) | ||
8459 | tempFloat += 0.5f; | ||
8460 | else | ||
8461 | tempFloat -= 0.5f; | ||
8459 | shapeBlock.PathScaleX = (byte)tempFloat; | 8462 | shapeBlock.PathScaleX = (byte)tempFloat; |
8460 | tempFloat = (float)(100.0d * (2.0d - taper_b.y)); | 8463 | |
8464 | tempFloat = 100.0f * (2.0f - (float)taper_b.y); | ||
8465 | if (tempFloat >= 0) | ||
8466 | tempFloat += 0.5f; | ||
8467 | else | ||
8468 | tempFloat -= 0.5f; | ||
8461 | shapeBlock.PathScaleY = (byte)tempFloat; | 8469 | shapeBlock.PathScaleY = (byte)tempFloat; |
8470 | |||
8462 | if (topshear.x < -0.5f) | 8471 | if (topshear.x < -0.5f) |
8463 | { | 8472 | { |
8464 | topshear.x = -0.5f; | 8473 | topshear.x = -0.5f; |
8465 | } | 8474 | } |
8466 | if (topshear.x > 0.5f) | 8475 | else if (topshear.x > 0.5f) |
8467 | { | 8476 | { |
8468 | topshear.x = 0.5f; | 8477 | topshear.x = 0.5f; |
8469 | } | 8478 | } |
@@ -8471,13 +8480,22 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8471 | { | 8480 | { |
8472 | topshear.y = -0.5f; | 8481 | topshear.y = -0.5f; |
8473 | } | 8482 | } |
8474 | if (topshear.y > 0.5f) | 8483 | else if (topshear.y > 0.5f) |
8475 | { | 8484 | { |
8476 | topshear.y = 0.5f; | 8485 | topshear.y = 0.5f; |
8477 | } | 8486 | } |
8478 | tempFloat = (float)(100.0d * topshear.x); | 8487 | tempFloat = 100.0f * (float)topshear.x; |
8488 | if (tempFloat >= 0) | ||
8489 | tempFloat += 0.5f; | ||
8490 | else | ||
8491 | tempFloat -= 0.5f; | ||
8479 | shapeBlock.PathShearX = (byte)tempFloat; | 8492 | shapeBlock.PathShearX = (byte)tempFloat; |
8480 | tempFloat = (float)(100.0d * topshear.y); | 8493 | |
8494 | tempFloat = 100.0f * (float)topshear.y; | ||
8495 | if (tempFloat >= 0) | ||
8496 | tempFloat += 0.5f; | ||
8497 | else | ||
8498 | tempFloat -= 0.5f; | ||
8481 | shapeBlock.PathShearY = (byte)tempFloat; | 8499 | shapeBlock.PathShearY = (byte)tempFloat; |
8482 | 8500 | ||
8483 | part.Shape.SculptEntry = false; | 8501 | part.Shape.SculptEntry = false; |
@@ -8505,7 +8523,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8505 | { | 8523 | { |
8506 | dimple.x = 0f; | 8524 | dimple.x = 0f; |
8507 | } | 8525 | } |
8508 | if (dimple.x > 1f) | 8526 | else if (dimple.x > 1f) |
8509 | { | 8527 | { |
8510 | dimple.x = 1f; | 8528 | dimple.x = 1f; |
8511 | } | 8529 | } |
@@ -8513,7 +8531,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8513 | { | 8531 | { |
8514 | dimple.y = 0f; | 8532 | dimple.y = 0f; |
8515 | } | 8533 | } |
8516 | if (dimple.y > 1f) | 8534 | else if (dimple.y > 1f) |
8517 | { | 8535 | { |
8518 | dimple.y = 1f; | 8536 | dimple.y = 1f; |
8519 | } | 8537 | } |
@@ -8539,7 +8557,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8539 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) | 8557 | if (part == null || part.ParentGroup == null || part.ParentGroup.IsDeleted) |
8540 | return; | 8558 | return; |
8541 | 8559 | ||
8542 | float tempFloat; // Use in float expressions below to avoid byte cast precision issues. | 8560 | float tempFloat; // Use in float expressions below to avoid byte cast precision issues. |
8543 | ObjectShapePacket.ObjectDataBlock shapeBlock; | 8561 | ObjectShapePacket.ObjectDataBlock shapeBlock; |
8544 | 8562 | ||
8545 | shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve); | 8563 | shapeBlock = SetPrimitiveBlockShapeParams(part, holeshape, cut, hollow, twist, profileshape, pathcurve); |
@@ -8552,47 +8570,59 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8552 | { | 8570 | { |
8553 | holesize.x = 0.01f; | 8571 | holesize.x = 0.01f; |
8554 | } | 8572 | } |
8555 | if (holesize.x > 1f) | 8573 | else if (holesize.x > 1f) |
8556 | { | 8574 | { |
8557 | holesize.x = 1f; | 8575 | holesize.x = 1f; |
8558 | } | 8576 | } |
8577 | tempFloat = 100.0f * (2.0f - (float)holesize.x) + 0.5f; | ||
8578 | shapeBlock.PathScaleX = (byte)tempFloat; | ||
8579 | |||
8559 | if (holesize.y < 0.01f) | 8580 | if (holesize.y < 0.01f) |
8560 | { | 8581 | { |
8561 | holesize.y = 0.01f; | 8582 | holesize.y = 0.01f; |
8562 | } | 8583 | } |
8563 | if (holesize.y > 0.5f) | 8584 | else if (holesize.y > 0.5f) |
8564 | { | 8585 | { |
8565 | holesize.y = 0.5f; | 8586 | holesize.y = 0.5f; |
8566 | } | 8587 | } |
8567 | tempFloat = (float)(100.0d * (2.0d - holesize.x)); | 8588 | tempFloat = 100.0f * (2.0f - (float)holesize.y) + 0.5f; |
8568 | shapeBlock.PathScaleX = (byte)tempFloat; | ||
8569 | tempFloat = (float)(100.0d * (2.0d - holesize.y)); | ||
8570 | shapeBlock.PathScaleY = (byte)tempFloat; | 8589 | shapeBlock.PathScaleY = (byte)tempFloat; |
8590 | |||
8571 | if (topshear.x < -0.5f) | 8591 | if (topshear.x < -0.5f) |
8572 | { | 8592 | { |
8573 | topshear.x = -0.5f; | 8593 | topshear.x = -0.5f; |
8574 | } | 8594 | } |
8575 | if (topshear.x > 0.5f) | 8595 | else if (topshear.x > 0.5f) |
8576 | { | 8596 | { |
8577 | topshear.x = 0.5f; | 8597 | topshear.x = 0.5f; |
8578 | } | 8598 | } |
8599 | tempFloat = (float)(100.0d * topshear.x); | ||
8600 | if (tempFloat >= 0) | ||
8601 | tempFloat += 0.5f; | ||
8602 | else | ||
8603 | tempFloat -= 0.5f; | ||
8604 | shapeBlock.PathShearX = (byte)tempFloat; | ||
8605 | |||
8579 | if (topshear.y < -0.5f) | 8606 | if (topshear.y < -0.5f) |
8580 | { | 8607 | { |
8581 | topshear.y = -0.5f; | 8608 | topshear.y = -0.5f; |
8582 | } | 8609 | } |
8583 | if (topshear.y > 0.5f) | 8610 | else if (topshear.y > 0.5f) |
8584 | { | 8611 | { |
8585 | topshear.y = 0.5f; | 8612 | topshear.y = 0.5f; |
8586 | } | 8613 | } |
8587 | tempFloat = (float)(100.0d * topshear.x); | ||
8588 | shapeBlock.PathShearX = (byte)tempFloat; | ||
8589 | tempFloat = (float)(100.0d * topshear.y); | 8614 | tempFloat = (float)(100.0d * topshear.y); |
8615 | if (tempFloat >= 0) | ||
8616 | tempFloat += 0.5f; | ||
8617 | else | ||
8618 | tempFloat -= 0.5f; | ||
8590 | shapeBlock.PathShearY = (byte)tempFloat; | 8619 | shapeBlock.PathShearY = (byte)tempFloat; |
8620 | |||
8591 | if (profilecut.x < 0f) | 8621 | if (profilecut.x < 0f) |
8592 | { | 8622 | { |
8593 | profilecut.x = 0f; | 8623 | profilecut.x = 0f; |
8594 | } | 8624 | } |
8595 | if (profilecut.x > 1f) | 8625 | else if (profilecut.x > 1f) |
8596 | { | 8626 | { |
8597 | profilecut.x = 1f; | 8627 | profilecut.x = 1f; |
8598 | } | 8628 | } |
@@ -8600,7 +8630,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8600 | { | 8630 | { |
8601 | profilecut.y = 0f; | 8631 | profilecut.y = 0f; |
8602 | } | 8632 | } |
8603 | if (profilecut.y > 1f) | 8633 | else if (profilecut.y > 1f) |
8604 | { | 8634 | { |
8605 | profilecut.y = 1f; | 8635 | profilecut.y = 1f; |
8606 | } | 8636 | } |
@@ -8623,18 +8653,28 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8623 | { | 8653 | { |
8624 | taper_a.x = 1f; | 8654 | taper_a.x = 1f; |
8625 | } | 8655 | } |
8656 | tempFloat = 100.0f * (float)taper_a.x; | ||
8657 | if (tempFloat >= 0) | ||
8658 | tempFloat += 0.5f; | ||
8659 | else | ||
8660 | tempFloat -= 0.5f; | ||
8661 | shapeBlock.PathTaperX = (sbyte)tempFloat; | ||
8662 | |||
8626 | if (taper_a.y < -1f) | 8663 | if (taper_a.y < -1f) |
8627 | { | 8664 | { |
8628 | taper_a.y = -1f; | 8665 | taper_a.y = -1f; |
8629 | } | 8666 | } |
8630 | if (taper_a.y > 1f) | 8667 | else if (taper_a.y > 1f) |
8631 | { | 8668 | { |
8632 | taper_a.y = 1f; | 8669 | taper_a.y = 1f; |
8633 | } | 8670 | } |
8634 | tempFloat = (float)(100.0d * taper_a.x); | 8671 | tempFloat = 100.0f * (float)taper_a.y; |
8635 | shapeBlock.PathTaperX = (sbyte)tempFloat; | 8672 | if (tempFloat >= 0) |
8636 | tempFloat = (float)(100.0d * taper_a.y); | 8673 | tempFloat += 0.5f; |
8674 | else | ||
8675 | tempFloat -= 0.5f; | ||
8637 | shapeBlock.PathTaperY = (sbyte)tempFloat; | 8676 | shapeBlock.PathTaperY = (sbyte)tempFloat; |
8677 | |||
8638 | if (revolutions < 1f) | 8678 | if (revolutions < 1f) |
8639 | { | 8679 | { |
8640 | revolutions = 1f; | 8680 | revolutions = 1f; |
@@ -8643,7 +8683,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8643 | { | 8683 | { |
8644 | revolutions = 4f; | 8684 | revolutions = 4f; |
8645 | } | 8685 | } |
8646 | tempFloat = 66.66667f * (revolutions - 1.0f); | 8686 | tempFloat = 66.66667f * (revolutions - 1.0f) + 0.5f; |
8647 | shapeBlock.PathRevolutions = (byte)tempFloat; | 8687 | shapeBlock.PathRevolutions = (byte)tempFloat; |
8648 | // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1 | 8688 | // limits on radiusoffset depend on revolutions and hole size (how?) seems like the maximum range is 0 to 1 |
8649 | if (radiusoffset < 0f) | 8689 | if (radiusoffset < 0f) |
@@ -8654,7 +8694,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8654 | { | 8694 | { |
8655 | radiusoffset = 1f; | 8695 | radiusoffset = 1f; |
8656 | } | 8696 | } |
8657 | tempFloat = 100.0f * radiusoffset; | 8697 | tempFloat = 100.0f * radiusoffset + 0.5f; |
8658 | shapeBlock.PathRadiusOffset = (sbyte)tempFloat; | 8698 | shapeBlock.PathRadiusOffset = (sbyte)tempFloat; |
8659 | if (skew < -0.95f) | 8699 | if (skew < -0.95f) |
8660 | { | 8700 | { |
@@ -8665,6 +8705,10 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api | |||
8665 | skew = 0.95f; | 8705 | skew = 0.95f; |
8666 | } | 8706 | } |
8667 | tempFloat = 100.0f * skew; | 8707 | tempFloat = 100.0f * skew; |
8708 | if (tempFloat >= 0) | ||
8709 | tempFloat += 0.5f; | ||
8710 | else | ||
8711 | tempFloat -= 0.5f; | ||
8668 | shapeBlock.PathSkew = (sbyte)tempFloat; | 8712 | shapeBlock.PathSkew = (sbyte)tempFloat; |
8669 | 8713 | ||
8670 | part.Shape.SculptEntry = false; | 8714 | part.Shape.SculptEntry = false; |