From 518c19fd2b58d9a7a5d99a3c56e606179d12b7a8 Mon Sep 17 00:00:00 2001 From: Sergey Sklyarov Date: Tue, 8 Jul 2025 17:57:11 +0300 Subject: [PATCH] Update RealMode.cs --- DroneSimulator/RealMode.cs | 165 +++++++++++++++++++------------------ 1 file changed, 84 insertions(+), 81 deletions(-) diff --git a/DroneSimulator/RealMode.cs b/DroneSimulator/RealMode.cs index 39079e8..d55daf8 100644 --- a/DroneSimulator/RealMode.cs +++ b/DroneSimulator/RealMode.cs @@ -162,6 +162,24 @@ namespace DroneSimulator public void Update(Vector3 value, uint time) { + Vector3 v = value; + + int noise = (int)(Noise * 1000); + v.X += ((float)rand.Next(-noise, noise)) / 1000; + v.Y += ((float)rand.Next(-noise, noise)) / 1000; + v.Z += ((float)rand.Next(-noise, noise)) / 1000; + + uint clock = (uint)(Lateness * 1000); + + uint tick = time - last; + last = time; + while (tick != 0) + { + tick--; + laten[index++] = v; + if (index >= clock) index = 0; + } + if (!Enable) { result = Vector3.NaN; @@ -176,29 +194,12 @@ namespace DroneSimulator return; } - int noise = (int)(Noise * 1000); - value.X += ((float)rand.Next(-noise, noise)) / 1000; - value.Y += ((float)rand.Next(-noise, noise)) / 1000; - value.Z += ((float)rand.Next(-noise, noise)) / 1000; - - uint clock = (uint)(Lateness * 1000); - - uint tick = time - last; - last = time; - while (tick != 0) - { - tick--; - laten[index++] = value; - if (index >= clock) index = 0; - } - - value = laten[index]; + v = laten[index]; uint freq = 1000 / Freq; - if (timer + freq <= time) { - result = value; + result = v; timer = time; } } @@ -227,9 +228,24 @@ namespace DroneSimulator public void Update(float value, uint time) { - //value = Pressure - value * 12.15f; value = Pressure * MathF.Exp(-0.02896f * 9.81f * value / (8.314f * (Temperature + 273.15f))); + float v = value; + + int noise = (int)(Noise * 1000); + v += ((float)rand.Next(-noise, noise)) / 1000; + + uint clock = (uint)(Lateness * 1000); + + uint tick = time - last; + last = time; + while (tick != 0) + { + tick--; + laten[index++] = v; + if (index >= clock) index = 0; + } + if (!Enable) { result = float.NaN; @@ -241,30 +257,15 @@ namespace DroneSimulator { result = value; timer = time; - return; + return; } - int noise = (int)(Noise * 1000); - value += ((float)rand.Next(-noise, noise)) / 1000; - - uint clock = (uint)(Lateness * 1000); - - uint tick = time - last; - last = time; - while (tick != 0) - { - tick--; - laten[index++] = value; - if (index >= clock) index = 0; - } - - value = laten[index]; + v = laten[index]; uint freq = 1000 / Freq; - if (timer + freq <= time) { - result = value; + result = v; timer = time; } } @@ -296,6 +297,27 @@ namespace DroneSimulator { value *= Lens; + Vector2 v = value; + + if (Range > MaxHeight) v = Vector2.Zero; + else + { + int noise = (int)(Noise * 1000); + v.X += ((float)rand.Next(-noise, noise)) / 1000; + v.Y += ((float)rand.Next(-noise, noise)) / 1000; + } + + uint clock = (uint)(Lateness * 1000); + + uint tick = time - last; + last = time; + while (tick != 0) + { + tick--; + laten[index++] = v; + if (index >= clock) index = 0; + } + if (!Enable) { result = Vector2.NaN; @@ -310,32 +332,12 @@ namespace DroneSimulator return true; } - if (Range > MaxHeight) value = Vector2.Zero; - else - { - int noise = (int)(Noise * 1000); - value.X += ((float)rand.Next(-noise, noise)) / 1000; - value.Y += ((float)rand.Next(-noise, noise)) / 1000; - } - - uint clock = (uint)(Lateness * 1000); - - uint tick = time - last; - last = time; - while (tick != 0) - { - tick--; - laten[index++] = value; - if (index >= clock) index = 0; - } - - value = laten[index]; + v = laten[index]; uint freq = 1000 / Freq; - if (timer + freq <= time) { - result = value; + result = v; timer = time; return true; } @@ -366,6 +368,26 @@ namespace DroneSimulator public void Update(float value, uint time) { + float v = value; + + if (v > MaxHeight) v = -1; + else + { + int noise = (int)(Noise * 1000); + v += ((float)rand.Next(-noise, noise)) / 1000; + } + + uint clock = (uint)(Lateness * 1000); + + uint tick = time - last; + last = time; + while (tick != 0) + { + tick--; + laten[index++] = v; + if (index >= clock) index = 0; + } + if (!Enable) { result = float.NaN; @@ -380,31 +402,12 @@ namespace DroneSimulator return; } - if (value > MaxHeight) value = -1; - else - { - int noise = (int)(Noise * 1000); - value += ((float)rand.Next(-noise, noise)) / 1000; - } - - uint clock = (uint)(Lateness * 1000); - - uint tick = time - last; - last = time; - while (tick != 0) - { - tick--; - laten[index++] = value; - if (index >= clock) index = 0; - } - - value = laten[index]; + v = laten[index]; uint freq = 1000 / Freq; - if (timer + freq <= time) { - result = value; + result = v; timer = time; } }