From efe780833564412c81fe911f9ad133360a50d649 Mon Sep 17 00:00:00 2001 From: xLinka Date: Sat, 20 Jul 2024 23:56:42 +0100 Subject: [PATCH] Added Node based on https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/2642 https://github.com/Yellow-Dog-Man/Resonite-Issues/issues/2642 --- .../ProtoFlux/Math/Random/RandomFloatQ.cs | 25 +++++++++++++++++++ .../ProtoFlux/RandomXExtensions.cs | 23 +++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 ProjectObsidian/ProtoFlux/Math/Random/RandomFloatQ.cs create mode 100644 ProjectObsidian/ProtoFlux/RandomXExtensions.cs diff --git a/ProjectObsidian/ProtoFlux/Math/Random/RandomFloatQ.cs b/ProjectObsidian/ProtoFlux/Math/Random/RandomFloatQ.cs new file mode 100644 index 0000000..8dfe0b2 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/Math/Random/RandomFloatQ.cs @@ -0,0 +1,25 @@ +using Elements.Core; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Obsidian; + + +namespace ProtoFlux.Runtimes.Execution.Nodes.Obsidian.Math.Random +{ + + [NodeCategory("Obsidian/Math/Random")] + [ContinuouslyChanging] + public class RandomFloatQ : ValueFunctionNode + { + public readonly ValueInput Min; + public readonly ValueInput Max; + + protected override floatQ Compute(ExecutionContext context) + { + floatQ min = Min.Evaluate(context); + floatQ max = Max.Evaluate(context); + + return RandomXExtensions.Range(min, max); + } + } +} \ No newline at end of file diff --git a/ProjectObsidian/ProtoFlux/RandomXExtensions.cs b/ProjectObsidian/ProtoFlux/RandomXExtensions.cs new file mode 100644 index 0000000..212a910 --- /dev/null +++ b/ProjectObsidian/ProtoFlux/RandomXExtensions.cs @@ -0,0 +1,23 @@ +using System; +using Elements.Core; + +namespace Obsidian +{ + public static class RandomXExtensions + { + private static RandomXGenerator r = new RandomXGenerator(); + + public static floatQ Range(floatQ min, floatQ max) + { + lock (r) + { + return new floatQ( + r.Range(min.x, max.x), + r.Range(min.y, max.y), + r.Range(min.z, max.z), + r.Range(min.w, max.w) + ); + } + } + } +}