You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>In order to create a new component, we must derive our component class from the <aclass="el" href="class_d_s_patch_1_1_component.html" title="Abstract base class for DSPatch components.">DSPatch::Component</a> base class, configure component IO, and implement the inherited virtual "Process_()" method.</p>
134
134
<p>Lets take a look at how we would go about creating a very simple boolean logic "AND" component. This component will accept 2 boolean input values and output the result of: input 1 && input 2.</p>
135
135
<p>We begin by deriving our new "AndBool" component from Component:</p>
136
-
<divclass="fragment"><divclass="line"><spanclass="comment">// 1. Derive AndBool class from Component</span></div>
<divclass="line"><spanclass="keyword">class </span>AndBool final : <spanclass="keyword">public</span><aclass="code hl_class" href="class_d_s_patch_1_1_component.html">DSPatch::Component</a></div>
139
139
<divclass="line">{</div>
140
140
<divclass="ttc" id="aclass_d_s_patch_1_1_component_html"><divclass="ttname"><ahref="class_d_s_patch_1_1_component.html">DSPatch::Component</a></div><divclass="ttdoc">Abstract base class for DSPatch components.</div><divclass="ttdef"><b>Definition</b><ahref="_component_8h_source.html#l00064">Component.h:65</a></div></div>
141
141
</div><!-- fragment --><p>The next step is to configure our component's input and output buses. This is achieved by calling the base protected methods: SetInputCount_() and SetOutputCount_() respectively from our component's constructor. In our component's case, we require 2 inputs and 1 output, therefore our constructor code will look like this:</p>
</div><!-- fragment --><p>Lastly, our component must implement the virtual Process_() method. This is where our component does its work. The Process_() method provides us with 2 arguments: the input bus and the output bus. It is our duty as the component designer to pull the inputs we require out of the input bus, process them accordingly, then populate the output bus with the results.</p>
154
154
<p>Our component's process method will look something like this:</p>
</div><!-- fragment --><p>Next, we must instantiate our circuit object and all component objects needed for our circuit. Lets say we had 2 other components included with "AndBool" (from the first tutorial): "GenBool" (generates a random boolean value then outputs the result) and "PrintBool" (receives a boolean value and outputs it to the console):</p>
</div><!-- fragment --><p>The code above results in the following wiring configuration: </p><divclass="fragment"><divclass="line"> __________ _________</div>
</div><!-- fragment --><p>Lastly, in order for our circuit to do any work it must be ticked. This is performed by repeatedly calling the circuit's Tick() method. This method can be called manually in a loop, or alternatively, by calling StartAutoTick(), a seperate thread will spawn, automatically calling Tick() continuously.</p>
</div><!-- fragment --><p>The code above results in the following wiring configuration: </p><preclass="fragment"> __________ _________
210
+
| | | |
211
+
| genBool1 |-0 ===> 0-| | ___________
212
+
|__________| | | | |
213
+
__________ | andBool |-0 ===> 0-| printBool |
214
+
| | | | |___________|
215
+
| genBool2 |-0 ===> 1-| |
216
+
|__________| |_________|</pre><p>Lastly, in order for our circuit to do any work it must be ticked. This is performed by repeatedly calling the circuit's Tick() method. This method can be called manually in a loop, or alternatively, by calling StartAutoTick(), a seperate thread will spawn, automatically calling Tick() continuously.</p>
219
217
<p>Furthermore, to boost performance in stream processing circuits like this one, multi-buffering can be enabled via the SetBufferCount() method:</p>
220
218
<p><b>NOTE:</b> If none of the parallel branches in your circuit are time-consuming (⪆10μs), multi-buffering (or even zero buffering) will almost always outperform multi-threading (via SetThreadCount()). The contention overhead caused by multiple threads processing a single tick must be made negligible by time-consuming parallel components for any performance improvement to be seen.</p>
221
-
<divclass="fragment"><divclass="line"><spanclass="comment">// 5. Tick the circuit</span></div>
0 commit comments