Skip to content

Commit

Permalink
Home page formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusTomlinson committed Aug 23, 2024
1 parent 138e371 commit 6eec6a8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 57 deletions.
54 changes: 26 additions & 28 deletions docs/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ <h2><a class="anchor" id="create_component"></a>
<p>In order to create a new component, we must derive our component class from the <a class="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>
<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 &amp;&amp; input 2.</p>
<p>We begin by deriving our new "AndBool" component from Component:</p>
<div class="fragment"><div class="line"><span class="comment">// 1. Derive AndBool class from Component</span></div>
<div class="line"><span class="comment">// ======================================</span></div>
<div class="fragment"><div class="line"><span class="comment">// 1. Derive AndBool class from Component</span></div>
<div class="line"><span class="comment">// ======================================</span></div>
<div class="line"><span class="keyword">class </span>AndBool final : <span class="keyword">public</span> <a class="code hl_class" href="class_d_s_patch_1_1_component.html">DSPatch::Component</a></div>
<div class="line">{</div>
<div class="ttc" id="aclass_d_s_patch_1_1_component_html"><div class="ttname"><a href="class_d_s_patch_1_1_component.html">DSPatch::Component</a></div><div class="ttdoc">Abstract base class for DSPatch components.</div><div class="ttdef"><b>Definition</b> <a href="_component_8h_source.html#l00064">Component.h:65</a></div></div>
</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 class="fragment"><div class="line"><span class="keyword">public</span>:</div>
<div class="line"> <span class="comment">// 2. Configure component IO buses</span></div>
<div class="line"> <span class="comment">// ===============================</span></div>
<div class="line"><span class="comment">// 2. Configure component IO buses</span></div>
<div class="line"><span class="comment">// ===============================</span></div>
<div class="line"> AndBool()</div>
<div class="line"> {</div>
<div class="line"> <span class="comment">// add 2 inputs</span></div>
Expand All @@ -153,8 +153,8 @@ <h2><a class="anchor" id="create_component"></a>
</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>
<p>Our component's process method will look something like this:</p>
<div class="fragment"><div class="line"><span class="keyword">protected</span>:</div>
<div class="line"> <span class="comment">// 3. Implement virtual Process_() method</span></div>
<div class="line"> <span class="comment">// ======================================</span></div>
<div class="line"><span class="comment">// 3. Implement virtual Process_() method</span></div>
<div class="line"><span class="comment">// ======================================</span></div>
<div class="line"> <span class="keywordtype">void</span> Process_( <a class="code hl_class" href="class_d_s_patch_1_1_signal_bus.html">DSPatch::SignalBus</a>&amp; inputs, <a class="code hl_class" href="class_d_s_patch_1_1_signal_bus.html">DSPatch::SignalBus</a>&amp; outputs )<span class="keyword"> override</span></div>
<div class="line"><span class="keyword"> </span>{</div>
<div class="line"> <span class="comment">// create some local pointers to hold our input values</span></div>
Expand Down Expand Up @@ -183,43 +183,41 @@ <h2><a class="anchor" id="use_component"></a>
</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 class="fragment"><div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// 1. Create a circuit where we can route our components</span></div>
<div class="line"> <span class="comment">// =====================================================</span></div>
<div class="line"><span class="comment">// 1. Create a circuit where we can route our components</span></div>
<div class="line"><span class="comment">// =====================================================</span></div>
<div class="line"> <span class="keyword">auto</span> circuit = std::make_shared&lt;DSPatch::Circuit&gt;();</div>
<div class="line"> </div>
<div class="line"> <span class="comment">// 2. Create instances of the components needed for our circuit</span></div>
<div class="line"> <span class="comment">// ============================================================</span></div>
<div class="line"><span class="comment">// 2. Create instances of the components needed for our circuit</span></div>
<div class="line"><span class="comment">// ============================================================</span></div>
<div class="line"> <span class="keyword">auto</span> genBool1 = std::make_shared&lt;GenBool&gt;();</div>
<div class="line"> <span class="keyword">auto</span> genBool2 = std::make_shared&lt;GenBool&gt;();</div>
<div class="line"> <span class="keyword">auto</span> andBool = std::make_shared&lt;AndBool&gt;();</div>
<div class="line"> <span class="keyword">auto</span> printBool = std::make_shared&lt;PrintBool&gt;();</div>
</div><!-- fragment --><p>Now that we have a circuit and some components, lets add all of our components to the circuit:</p>
<div class="fragment"><div class="line"> <span class="comment">// 3. Add component instances to circuit</span></div>
<div class="line"> <span class="comment">// =====================================</span></div>
<div class="fragment"><div class="line"><span class="comment">// 3. Add component instances to circuit</span></div>
<div class="line"><span class="comment">// =====================================</span></div>
<div class="line"> circuit-&gt;AddComponent( genBool1 );</div>
<div class="line"> circuit-&gt;AddComponent( genBool2 );</div>
<div class="line"> circuit-&gt;AddComponent( andBool );</div>
<div class="line">_ circuit-&gt;AddComponent( printBool );</div>
<div class="line"> circuit-&gt;AddComponent( printBool );</div>
</div><!-- fragment --><p>We are now ready to begin wiring the circuit:</p>
<div class="fragment"><div class="line"> <span class="comment">// 4. Wire up the components inside the circuit</span></div>
<div class="line"> <span class="comment">// ============================================</span></div>
<div class="fragment"><div class="line"><span class="comment">// 4. Wire up the components inside the circuit</span></div>
<div class="line"><span class="comment">// ============================================</span></div>
<div class="line"> circuit-&gt;ConnectOutToIn( genBool1, 0, andBool, 0 );</div>
<div class="line"> circuit-&gt;ConnectOutToIn( genBool2, 0, andBool, 1 );</div>
<div class="line">_ circuit-&gt;ConnectOutToIn( andBool, 0, printBool, 0 );</div>
</div><!-- fragment --><p>The code above results in the following wiring configuration: </p><div class="fragment"><div class="line"> __________ _________</div>
<div class="line"> | | | |</div>
<div class="line"> | genBool1 |-0 ===&gt; 0-| | ___________</div>
<div class="line"> |__________| | | | |</div>
<div class="line"> __________ | andBool |-0 ===&gt; 0-| printBool |</div>
<div class="line"> | | | | |___________|</div>
<div class="line"> | genBool2 |-0 ===&gt; 1-| |</div>
<div class="line"> |__________| |_________|</div>
<div class="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 class="line"> circuit-&gt;ConnectOutToIn( andBool, 0, printBool, 0 );</div>
</div><!-- fragment --><p>The code above results in the following wiring configuration: </p><pre class="fragment"> __________ _________
| | | |
| genBool1 |-0 ===&gt; 0-| | ___________
|__________| | | | |
__________ | andBool |-0 ===&gt; 0-| printBool |
| | | | |___________|
| genBool2 |-0 ===&gt; 1-| |
|__________| |_________|</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>
<p>Furthermore, to boost performance in stream processing circuits like this one, multi-buffering can be enabled via the SetBufferCount() method:</p>
<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>
<div class="fragment"><div class="line"> <span class="comment">// 5. Tick the circuit</span></div>
<div class="line"> <span class="comment">// ===================</span></div>
<div class="fragment"><div class="line"><span class="comment">// 5. Tick the circuit</span></div>
<div class="line"><span class="comment">// ===================</span></div>
<div class="line"> </div>
<div class="line"> <span class="comment">// Circuit tick method 1: Manual</span></div>
<div class="line"> <span class="keywordflow">for</span>( <span class="keywordtype">int</span> i = 0; i &lt; 10; ++i )</div>
Expand Down
58 changes: 29 additions & 29 deletions include/DSPatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
We begin by deriving our new "AndBool" component from Component:
\code
// 1. Derive AndBool class from Component
// ======================================
// 1. Derive AndBool class from Component
// ======================================
class AndBool final : public DSPatch::Component
{
\endcode
Expand All @@ -116,8 +116,8 @@ class AndBool final : public DSPatch::Component
\code
public:
// 2. Configure component IO buses
// ===============================
// 2. Configure component IO buses
// ===============================
AndBool()
{
// add 2 inputs
Expand All @@ -137,8 +137,8 @@ class AndBool final : public DSPatch::Component
\code
protected:
// 3. Implement virtual Process_() method
// ======================================
// 3. Implement virtual Process_() method
// ======================================
void Process_( DSPatch::SignalBus& inputs, DSPatch::SignalBus& outputs ) override
{
// create some local pointers to hold our input values
Expand Down Expand Up @@ -184,12 +184,12 @@ class AndBool final : public DSPatch::Component
\code
int main()
{
// 1. Create a circuit where we can route our components
// =====================================================
// 1. Create a circuit where we can route our components
// =====================================================
auto circuit = std::make_shared<DSPatch::Circuit>();
// 2. Create instances of the components needed for our circuit
// ============================================================
// 2. Create instances of the components needed for our circuit
// ============================================================
auto genBool1 = std::make_shared<GenBool>();
auto genBool2 = std::make_shared<GenBool>();
auto andBool = std::make_shared<AndBool>();
Expand All @@ -199,36 +199,36 @@ int main()
Now that we have a circuit and some components, lets add all of our components to the circuit:
\code
// 3. Add component instances to circuit
// =====================================
// 3. Add component instances to circuit
// =====================================
circuit->AddComponent( genBool1 );
circuit->AddComponent( genBool2 );
circuit->AddComponent( andBool );
_ circuit->AddComponent( printBool );
circuit->AddComponent( printBool );
\endcode
We are now ready to begin wiring the circuit:
\code
// 4. Wire up the components inside the circuit
// ============================================
// 4. Wire up the components inside the circuit
// ============================================
circuit->ConnectOutToIn( genBool1, 0, andBool, 0 );
circuit->ConnectOutToIn( genBool2, 0, andBool, 1 );
_ circuit->ConnectOutToIn( andBool, 0, printBool, 0 );
circuit->ConnectOutToIn( andBool, 0, printBool, 0 );
\endcode
The code above results in the following wiring configuration:
\code
__________ _________
| | | |
| genBool1 |-0 ===> 0-| | ___________
|__________| | | | |
__________ | andBool |-0 ===> 0-| printBool |
| | | | |___________|
| genBool2 |-0 ===> 1-| |
|__________| |_________|
_
\endcode
\verbatim
__________ _________
| | | |
| genBool1 |-0 ===> 0-| | ___________
|__________| | | | |
__________ | andBool |-0 ===> 0-| printBool |
| | | | |___________|
| genBool2 |-0 ===> 1-| |
|__________| |_________|
\endverbatim
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,
Expand All @@ -245,8 +245,8 @@ _ circuit->ConnectOutToIn( andBool, 0, printBool, 0 );
improvement to be seen.
\code
// 5. Tick the circuit
// ===================
// 5. Tick the circuit
// ===================
// Circuit tick method 1: Manual
for( int i = 0; i < 10; ++i )
Expand Down

0 comments on commit 6eec6a8

Please sign in to comment.