2007-09-03 02:33:47 +02:00
|
|
|
|
/*
|
2024-12-06 23:43:18 +01:00
|
|
|
|
NodeFeed(Test) - verify render node data feeds
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
2024-12-06 23:43:18 +01:00
|
|
|
|
2025, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** is free software; you can redistribute it and/or modify it
|
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
|
Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
|
|
option) any later version. See the file COPYING for further details.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2007-09-03 02:33:47 +02:00
|
|
|
|
|
2024-12-06 23:43:18 +01:00
|
|
|
|
/** @file node-feed-test.cpp
|
|
|
|
|
|
** Feeding into and retrieving data from render nodes is covered by \ref NodeFeed_test.
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2007-09-03 02:33:47 +02:00
|
|
|
|
|
2008-12-18 04:47:41 +01:00
|
|
|
|
#include "lib/test/run.hpp"
|
2024-12-26 21:42:32 +01:00
|
|
|
|
#include "steam/engine/proc-node.hpp"
|
|
|
|
|
|
#include "steam/engine/node-builder.hpp"
|
2024-12-28 21:41:08 +01:00
|
|
|
|
#include "steam/engine/media-weaving-pattern.hpp"
|
2024-12-28 23:16:55 +01:00
|
|
|
|
#include "steam/engine/param-weaving-pattern.hpp"
|
2024-12-26 21:42:32 +01:00
|
|
|
|
#include "steam/engine/turnout-system.hpp"
|
|
|
|
|
|
#include "steam/engine/turnout.hpp"
|
|
|
|
|
|
#include "steam/engine/diagnostic-buffer-provider.hpp"
|
2024-12-29 03:23:59 +01:00
|
|
|
|
#include "steam/asset/meta/time-grid.hpp"
|
2024-12-26 21:42:32 +01:00
|
|
|
|
#include "lib/several-builder.hpp"
|
2024-12-29 03:23:59 +01:00
|
|
|
|
#include "lib/time/timecode.hpp"
|
2024-12-30 01:56:18 +01:00
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2024-12-26 21:42:32 +01:00
|
|
|
|
#include "lib/test/diagnostic-output.hpp"/////////////////////TODO
|
2008-12-18 04:47:41 +01:00
|
|
|
|
//#include "lib/util.hpp"
|
2007-09-03 02:33:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
2024-12-26 21:42:32 +01:00
|
|
|
|
using lib::Several;
|
|
|
|
|
|
using lib::makeSeveral;
|
2024-12-29 03:23:59 +01:00
|
|
|
|
using lib::time::Time;
|
2024-12-30 01:56:18 +01:00
|
|
|
|
using lib::time::FrameNr;
|
|
|
|
|
|
using lib::test::showType;
|
2025-01-04 19:28:58 +01:00
|
|
|
|
using std::make_tuple;
|
|
|
|
|
|
using std::get;
|
2007-09-03 02:33:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
namespace steam {
|
2009-08-31 00:49:08 +02:00
|
|
|
|
namespace engine{
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-07 18:15:44 +01:00
|
|
|
|
/************************************************************************//**
|
|
|
|
|
|
* @test demonstrate how to feed data into, through and out of render nodes.
|
2025-02-19 23:27:52 +01:00
|
|
|
|
* @todo 2/2025 unfinished -- add cases to cover media data feeds
|
2009-08-31 00:49:08 +02:00
|
|
|
|
*/
|
2024-12-06 23:43:18 +01:00
|
|
|
|
class NodeFeed_test : public Test
|
2007-09-03 02:33:47 +02:00
|
|
|
|
{
|
2024-12-07 18:15:44 +01:00
|
|
|
|
virtual void
|
|
|
|
|
|
run (Arg)
|
2009-08-31 00:49:08 +02:00
|
|
|
|
{
|
2024-12-30 01:56:18 +01:00
|
|
|
|
seedRand();
|
2024-12-07 18:15:44 +01:00
|
|
|
|
feedParam();
|
2024-12-28 21:41:08 +01:00
|
|
|
|
feedParamNode();
|
2024-12-07 18:15:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-26 21:42:32 +01:00
|
|
|
|
|
|
|
|
|
|
/** @test demonstrate internal setup to invoke a simple output-only function,
|
|
|
|
|
|
* passing an additional invocation parameter generated from a parameter-functor
|
|
|
|
|
|
* - embed the processing-functor and parameter-functor into a FeedPrototype
|
|
|
|
|
|
* - construct the type of the »Weaving Pattern« to use for invocation
|
|
|
|
|
|
* - setup an empty wiring (output-only, thus no predecessor ports)
|
|
|
|
|
|
* - setup a single BuffDesrc for a result puffer to pass to the processing-functor
|
|
|
|
|
|
* - create a Turnout, which implements the Port interface, using the Weaving-Pattern
|
|
|
|
|
|
* - for the actual invocation, setup a TurnoutSystem, initialised with a nominal time
|
|
|
|
|
|
* - invoke the Port::weave() function and retrieve the result from the buffer.
|
|
|
|
|
|
* @remark this is a semi-integrated setup to demonstrate the interplay of the
|
|
|
|
|
|
* internal components within a Render Node, without the _outer shell_
|
|
|
|
|
|
* provided by the NodeBuilder and the ProcNode itself
|
|
|
|
|
|
*/
|
2024-12-07 18:15:44 +01:00
|
|
|
|
void
|
|
|
|
|
|
feedParam()
|
2024-12-26 21:42:32 +01:00
|
|
|
|
{
|
|
|
|
|
|
auto procFun = [](ushort param, uint* buff){ *buff = param; };
|
|
|
|
|
|
auto paramFun = [](TurnoutSystem&){ return LIFE_AND_UNIVERSE_4EVER; };
|
|
|
|
|
|
|
|
|
|
|
|
auto feedPrototype = FeedPrototype{move(procFun), move(paramFun)};
|
|
|
|
|
|
using Prototype = decltype(feedPrototype);
|
|
|
|
|
|
using WeavingPattern = MediaWeavingPattern<Prototype>;
|
|
|
|
|
|
using TurnoutWeaving = Turnout<WeavingPattern>;
|
|
|
|
|
|
|
|
|
|
|
|
BufferProvider& provider = DiagnosticBufferProvider::build();
|
|
|
|
|
|
|
|
|
|
|
|
Several<PortRef> noLeadPorts; // ◁————————— empty predecessor-port-sequence
|
|
|
|
|
|
Several<BuffDescr> outBuffDescr = makeSeveral({provider.getDescriptor<uint>()})
|
|
|
|
|
|
.build(); // ◁————————— a single output buffer to hold an `uint`
|
|
|
|
|
|
uint resultSlot{0};
|
|
|
|
|
|
|
|
|
|
|
|
TurnoutWeaving port{ProcID::describe ("SimpleNode","procFun()")
|
|
|
|
|
|
, move (noLeadPorts)
|
|
|
|
|
|
, move (outBuffDescr)
|
|
|
|
|
|
, resultSlot
|
|
|
|
|
|
, move (feedPrototype)
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// setup for invocation...
|
|
|
|
|
|
Time nomTime =Time::ZERO;
|
|
|
|
|
|
TurnoutSystem turnoutSys{nomTime};
|
|
|
|
|
|
BuffHandle result = port.weave (turnoutSys); // ◁————————— paramFun invoked here, then procFun
|
|
|
|
|
|
CHECK (LIFE_AND_UNIVERSE_4EVER == result.accessAs<uint>());// and procFun wrote param-value into result buffer
|
|
|
|
|
|
result.release();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-30 01:56:18 +01:00
|
|
|
|
|
2025-01-04 19:28:58 +01:00
|
|
|
|
|
2024-12-30 01:56:18 +01:00
|
|
|
|
/** @test create extended parameter data for use in recursive Node invocation.
|
|
|
|
|
|
* - demonstrate the mechanism of param-functor invocation,
|
|
|
|
|
|
* and how a Param-Spec is built to create and hold those functors
|
|
|
|
|
|
* - then instantiate an actual TurnoutSystem, as is done for a Node invocation,
|
|
|
|
|
|
* with an embedded »absolute nominal time« parameter value
|
|
|
|
|
|
* - can then invoke the param-functors and materialise results into a Param-Data-Block
|
|
|
|
|
|
* - which then can be linked internally to be reachable through the TurnoutSystem
|
|
|
|
|
|
* - other code further down the call-stack can thus access those parameter values.
|
|
|
|
|
|
* - The second part of the test uses the same scheme embedded into a Param(Agent)Node
|
|
|
|
|
|
*/
|
2024-12-26 21:42:32 +01:00
|
|
|
|
void
|
|
|
|
|
|
feedParamNode()
|
2024-12-07 18:15:44 +01:00
|
|
|
|
{
|
2025-01-04 19:28:58 +01:00
|
|
|
|
// Assuming that somewhere in the system a 1-seconds time grid was predefined...
|
|
|
|
|
|
steam::asset::meta::TimeGrid::build ("grid_sec", 1);
|
|
|
|
|
|
|
|
|
|
|
|
//_______________________________________________
|
|
|
|
|
|
// Demo-1: demonstrate the access mechanism directly;
|
|
|
|
|
|
// create and link an extended parameter block.
|
2024-12-29 03:23:59 +01:00
|
|
|
|
|
2025-01-04 19:28:58 +01:00
|
|
|
|
// This test will create an extension data block with two parameters,
|
|
|
|
|
|
// one of these is generated from time-quantisation into a 1-seconds-grid
|
|
|
|
|
|
auto createParmFun = [](TurnoutSystem& turnoutSys) -> long
|
|
|
|
|
|
{
|
|
|
|
|
|
return FrameNr::quant (turnoutSys.getNomTime(), "grid_sec");
|
|
|
|
|
|
};
|
2024-12-29 03:23:59 +01:00
|
|
|
|
|
2025-01-04 19:28:58 +01:00
|
|
|
|
// The »Param-Spec« is used to coordinate type-safe access
|
2024-12-30 01:56:18 +01:00
|
|
|
|
// and also is used as a blueprint for building a Param(Agent)Node
|
2025-01-04 19:28:58 +01:00
|
|
|
|
// Note the builder syntax to add several parameter »slots«...
|
2024-12-29 03:23:59 +01:00
|
|
|
|
auto spec = buildParamSpec()
|
|
|
|
|
|
.addValSlot (LIFE_AND_UNIVERSE_4EVER)
|
2025-01-04 19:28:58 +01:00
|
|
|
|
.addSlot (createParmFun)
|
2024-12-29 03:23:59 +01:00
|
|
|
|
;
|
|
|
|
|
|
|
2025-01-04 19:28:58 +01:00
|
|
|
|
// Implied type of the parameter-tuple to generate
|
2024-12-30 01:56:18 +01:00
|
|
|
|
using ParamTup = decltype(spec)::ParamTup;
|
|
|
|
|
|
CHECK (showType<ParamTup>() == "tuple<uint, long>"_expect);
|
|
|
|
|
|
|
2025-01-04 19:28:58 +01:00
|
|
|
|
auto acc0 = spec.makeAccessor<0>(); // can now store accessor-functors for later use....
|
2025-01-02 03:08:34 +01:00
|
|
|
|
auto acc1 = spec.makeAccessor<1>();
|
2024-12-30 01:56:18 +01:00
|
|
|
|
|
2025-01-04 19:28:58 +01:00
|
|
|
|
// Prepare for invocation....
|
|
|
|
|
|
Time nomTime{rani(10'000),0}; // drive test with a random »nominal Time« <10s with ms granularity
|
|
|
|
|
|
TurnoutSystem turnoutSys{nomTime}; // build minimal TurnoutSystem for invocation, just with this time parameter
|
|
|
|
|
|
auto v0 = spec.invokeParamFun<0> (turnoutSys); // can now immediately invoke the embedded parameter-functors
|
2025-01-02 03:08:34 +01:00
|
|
|
|
auto v1 = spec.invokeParamFun<1> (turnoutSys);
|
2025-01-04 19:28:58 +01:00
|
|
|
|
CHECK (v0 == LIFE_AND_UNIVERSE_4EVER); // ◁————————— the first paramFun yields the configured fixed value
|
|
|
|
|
|
CHECK (v1 == FrameNr::quant (nomTime, "grid_sec")); // ◁————————— the second paramFun accesses the time via TurnoutSystem
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-01-02 03:08:34 +01:00
|
|
|
|
// after all setup of further accessor functors is done
|
2025-01-04 19:28:58 +01:00
|
|
|
|
// finally transform the ParamSpec into a storage-block-builder
|
|
|
|
|
|
auto blockBuilder = spec.clone().makeBlockBuilder(); // (use clone() since we're re-using the same spec in Demo-2 below)
|
2025-01-02 03:08:34 +01:00
|
|
|
|
|
2024-12-30 01:56:18 +01:00
|
|
|
|
{ // Now build an actual storage block in local scope,
|
|
|
|
|
|
// thereby invoking the embedded parameter-functors...
|
2025-01-02 03:08:34 +01:00
|
|
|
|
auto paramBlock = blockBuilder.buildParamDataBlock (turnoutSys);
|
2025-01-04 19:28:58 +01:00
|
|
|
|
CHECK (v0 == paramBlock.get<0>()); // Values are now materialised into paramBlock
|
2024-12-30 01:56:18 +01:00
|
|
|
|
CHECK (v1 == paramBlock.get<1>());
|
|
|
|
|
|
|
2025-01-04 19:28:58 +01:00
|
|
|
|
turnoutSys.attachChainBlock(paramBlock); // link this extension block into the parameter-chain in TurnoutSystem;
|
|
|
|
|
|
CHECK (v0 == acc0.getParamVal (turnoutSys)); // Can now access the parameter values through the TurnoutSystem as front-End
|
|
|
|
|
|
CHECK (v1 == acc1.getParamVal (turnoutSys)); // ...using the pre-configured accessor-functors stored above
|
2024-12-30 01:56:18 +01:00
|
|
|
|
|
2025-01-04 19:28:58 +01:00
|
|
|
|
turnoutSys.detachChainBlock(paramBlock); // should detach extension block before leaving scope
|
|
|
|
|
|
}// extension block is gone...
|
|
|
|
|
|
|
|
|
|
|
|
{ // Demonstrate the same access mechanism
|
|
|
|
|
|
// but integrated into a Weaving-Pattern
|
|
|
|
|
|
using Spec = decltype(spec);
|
|
|
|
|
|
using WeavingPattern = ParamWeavingPattern<Spec>;
|
|
|
|
|
|
using Feed = WeavingPattern::Feed;
|
2024-12-30 01:56:18 +01:00
|
|
|
|
|
2025-01-04 19:28:58 +01:00
|
|
|
|
Feed feed;
|
|
|
|
|
|
feed.emplaceParamDataBlock (blockBuilder, turnoutSys);
|
|
|
|
|
|
// note that the param-data-block is embedded into the feed,
|
|
|
|
|
|
// so that it can be easily placed into the current stack frame
|
|
|
|
|
|
CHECK (v0 == feed.block().get<0>());
|
|
|
|
|
|
CHECK (v1 == feed.block().get<1>());
|
2024-12-30 01:56:18 +01:00
|
|
|
|
}
|
2025-01-04 19:28:58 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//_________________________________________________
|
|
|
|
|
|
// Demo-2: perform exactly the same access scheme,
|
|
|
|
|
|
// but now embedded into a Render Node graph.
|
|
|
|
|
|
using Param = tuple<int,int>;
|
|
|
|
|
|
|
|
|
|
|
|
// The processing function uses two parameter values
|
|
|
|
|
|
auto processFun = [](Param par, long* buff)
|
|
|
|
|
|
{
|
|
|
|
|
|
*buff = get<0>(par) + get<1>(par);
|
|
|
|
|
|
};
|
|
|
|
|
|
// These parameter values are picked up from the extended TurnoutSystem,
|
|
|
|
|
|
// relying on the accessor objects, which were created from the ParamSpec
|
|
|
|
|
|
auto accessParam = [acc0,acc1]
|
|
|
|
|
|
(TurnoutSystem& turnoutSys) -> Param
|
|
|
|
|
|
{
|
2025-02-18 23:55:58 +01:00
|
|
|
|
return make_tuple (turnoutSys.get(acc0)
|
|
|
|
|
|
,turnoutSys.get(acc1));
|
2025-01-04 19:28:58 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ProcNode delegate{prepareNode("Delegate")
|
|
|
|
|
|
.preparePort()
|
|
|
|
|
|
.invoke("proc()", processFun)
|
|
|
|
|
|
.attachParamFun (accessParam)
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
|
|
|
|
|
|
|
|
|
|
|
ProcNode paramAgent{prepareNode("Param")
|
|
|
|
|
|
.preparePort()
|
|
|
|
|
|
.computeParam (move(spec))
|
|
|
|
|
|
.delegateLead (delegate) // ◁————————— linked to the Delegate-Node
|
|
|
|
|
|
.completePort()
|
|
|
|
|
|
.build()};
|
2024-12-29 18:27:05 +01:00
|
|
|
|
|
2025-01-04 19:28:58 +01:00
|
|
|
|
// Prepare result buffer for invocation
|
|
|
|
|
|
BufferProvider& provider = DiagnosticBufferProvider::build();
|
|
|
|
|
|
BuffHandle buff = provider.lockBufferFor<long> (-55);
|
|
|
|
|
|
CHECK (-55 == buff.accessAs<long>());
|
|
|
|
|
|
|
|
|
|
|
|
// Invoke Port#0 on the top-level Node (≙ the ParamAgent)
|
|
|
|
|
|
buff = paramAgent.getPort(0).weave(turnoutSys, buff); // ◁————————— generate Param-Values, link into TurnoutSystem, invoke Delegate
|
|
|
|
|
|
CHECK (v0+v1 == buff.accessAs<long>());
|
|
|
|
|
|
|
|
|
|
|
|
buff.release();
|
2024-12-07 18:15:44 +01:00
|
|
|
|
}
|
2009-08-31 00:49:08 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
2024-12-06 23:43:18 +01:00
|
|
|
|
LAUNCHER (NodeFeed_test, "unit node");
|
2009-08-31 00:49:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
}}} // namespace steam::engine::test
|