From 084adc9e2c94fcfc70de018f2fb545681c210ba6 Mon Sep 17 00:00:00 2001 From: Owen Green Date: Tue, 13 Dec 2022 22:28:39 +0000 Subject: [PATCH] Fix/params maxima (#148) * Readme: Correct C++ version * Wrapper: constrain runtime param maxima --- include/FluidSCWrapper.hpp | 5 ++-- include/wrapper/ArgsFromClient.hpp | 42 +++++++++++++++++++++--------- include/wrapper/NonRealtime.hpp | 14 +++++----- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/include/FluidSCWrapper.hpp b/include/FluidSCWrapper.hpp index ac4ae03..0a82411 100644 --- a/include/FluidSCWrapper.hpp +++ b/include/FluidSCWrapper.hpp @@ -85,8 +85,9 @@ public: using Reportage = decltype(static_cast(x)->mReportage); Reportage* reportage = initialized ? &(static_cast(x)->mReportage) : new Reportage(); - - p.template setParameterValuesRT(verbose ? reportage: nullptr , x, inputs, alloc); + + p.template setParameterValuesRT( + verbose ? reportage : nullptr, x, inputs, p, alloc); if (constrain) p.constrainParameterValuesRT(verbose ? reportage : nullptr); if(verbose) { diff --git a/include/wrapper/ArgsFromClient.hpp b/include/wrapper/ArgsFromClient.hpp index 30a80ad..5a8b898 100644 --- a/include/wrapper/ArgsFromClient.hpp +++ b/include/wrapper/ArgsFromClient.hpp @@ -126,12 +126,13 @@ struct ParamReader auto id = fromArgs(x, args, index{}, 0); return {id >= 0 ? std::to_string(id).c_str() : "" }; } - - static auto fromArgs(Unit*,Controls& args,typename LongRuntimeMaxT::type&, int) + + static auto fromArgs(Unit*, Controls& args, typename LongRuntimeMaxT::type&, + int) { - return typename LongRuntimeMaxT::type{static_cast(args.next()), static_cast(args.next())}; + return typename LongRuntimeMaxT::type{static_cast(args.next()), + static_cast(args.next())}; } - }; // NRT case: we're decoding data from sc_msg_iter*, there will be a World*, we can't have LocalBufs @@ -329,11 +330,13 @@ struct ClientParams{ /// Grizzly enable_if hackage coming up. Need to brute force an int from incoming data into a string param for FluidDataSet / FluidLabelSet. - /// This will go away one day + /// This will go away one day - template - std::enable_if_t || Number!=0, typename T::type> - operator()(Context* x, ArgType& args, Allocator& alloc) + template + std::enable_if_t || Number != 0, + typename T::type> + operator()(Context* x, ArgType& args, Params& p, Allocator& alloc) { // Just return default if there's nothing left to grab if (args.remain() == 0) @@ -351,12 +354,25 @@ struct ClientParams{ a[i] = static_cast( ParamReader::fromArgs(x, args, a[0], 0)); - return a.value(); + /// He said "I don't like it, but I have to go along with it" + /// Make sure that the maximum for LongRuntimeMax params is + /// properly constrained *as soon as possible* + if constexpr (std::is_same_v) + { + auto param = a.value(); + index maximum = param.maxRaw(); + maximum = p.template applyConstraintToMax(maximum); + return LongRuntimeMaxParam(param(), maximum); + } + else + return a.value(); } - - template - std::enable_if_t && Number==0, typename T::type> - operator()(Context* x, ArgType& args, Allocator& alloc) + + template + std::enable_if_t && Number == 0, + typename T::type> + operator()(Context* x, ArgType& args, Params&, Allocator& alloc) { // Just return default if there's nothing left to grab if (args.remain() == 0) diff --git a/include/wrapper/NonRealtime.hpp b/include/wrapper/NonRealtime.hpp index 60a6b69..f427f5d 100644 --- a/include/wrapper/NonRealtime.hpp +++ b/include/wrapper/NonRealtime.hpp @@ -272,8 +272,8 @@ private: : NRTCommand{world, args, replyAddr, !IsNamedShared_v}, mParams{Client::getParameterDescriptors(), NRTCommand::allocator()} { - mParams.template setParameterValuesRT(nullptr, world, - *args, NRTCommand::allocator()); + mParams.template setParameterValuesRT( + nullptr, world, *args, mParams, NRTCommand::allocator()); } CommandNew(index id, World* world, FloatControlsIter& args, Unit* x) @@ -281,7 +281,7 @@ private: NRTCommand::allocator()} { mParams.template setParameterValuesRT( - nullptr, x, args, NRTCommand::allocator()); + nullptr, x, args, mParams, NRTCommand::allocator()); } static const char* name() @@ -364,8 +364,8 @@ private: if (auto ptr = get(NRTCommand::mID).lock()) { ptr->mDone.store(false, std::memory_order_release); - mParams.template setParameterValuesRT(nullptr, world, - ar, NRTCommand::allocator()); + mParams.template setParameterValuesRT( + nullptr, world, ar, mParams, NRTCommand::allocator()); mSynchronous = static_cast(ar.geti()); } // if this fails, we'll hear about it in stage2 anyway } @@ -716,7 +716,7 @@ private: if (auto ptr = get(NRTCommand::mID).lock()) { ptr->mParams.template setParameterValuesRT( - nullptr, world, ar, NRTCommand::allocator()); + nullptr, world, ar, ptr->mParams, NRTCommand::allocator()); Result result = validateParameters(ptr->mParams); ptr->mClient.setParams(ptr->mParams); } @@ -747,7 +747,7 @@ private: if (auto ptr = get(NRTCommand::mID).lock()) { ptr->mParams.template setParameterValues( - true, world, mArgs, FluidDefaultAllocator()); + true, world, mArgs, ptr->mParams, FluidDefaultAllocator()); Result result = validateParameters(ptr->mParams); ptr->mClient.setParams(ptr->mParams); }