<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>C/C++ on My Universe</title><link>https://www.my-universe.com/tags/c/c++/</link><description>Recent content in C/C++ on My Universe</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Wed, 27 Sep 2023 00:00:00 +0000</lastBuildDate><atom:link href="https://www.my-universe.com/tags/c/c++/index.xml" rel="self" type="application/rss+xml"/><item><title>Dataref Caching Revisited</title><link>https://www.my-universe.com/2023/09/27/dataref-caching-revisited/</link><pubDate>Wed, 27 Sep 2023 00:00:00 +0000</pubDate><guid>https://www.my-universe.com/2023/09/27/dataref-caching-revisited/</guid><description>&lt;p>Earlier this year I wrote about &lt;a href="https://www.my-universe.com/2023/04/20/cache-your-datarefs/">caching datarefs&lt;/a>. Back then we only looked at caching single datarefs, which quickly leads to bloated code once applied in a wider context. So here we are again, taking a closer look at caching &lt;em>many&lt;/em> datarefs efficiently.&lt;/p>
&lt;h4 id="what-about-trees">What About Trees&lt;/h4>
&lt;blockquote>
&lt;p>&amp;ldquo;Are we going to leave those poor little Datarefs here in this horrid, dark, dank, tree-infested &amp;mdash; I mean&amp;hellip; charming, quite charming, forest?&amp;rdquo;&lt;/p>
&lt;p>&amp;mdash; unknown dwarf coder&lt;/p></description></item><item><title>Configuration File with XPPL</title><link>https://www.my-universe.com/2023/09/23/configuration-file-with-xppl/</link><pubDate>Sat, 23 Sep 2023 00:00:00 +0000</pubDate><guid>https://www.my-universe.com/2023/09/23/configuration-file-with-xppl/</guid><description>&lt;p>In this blog post we&amp;rsquo;re looking into using &lt;a href="https://github.com/daemotron/xppl/">XPPL&lt;/a> to enhance a plugin with a configuration file. Working with XPPL&amp;rsquo;s configuration module is follows this five-step sequence:&lt;/p>
&lt;ol>
&lt;li>initialize a configuration context&lt;/li>
&lt;li>register configuration properties&lt;/li>
&lt;li>load the configuration file&lt;/li>
&lt;li>access the configuration values&lt;/li>
&lt;li>clean up&lt;/li>
&lt;/ol>
&lt;p>First, we need a configuration context. Since we will need to keep it alive throughout the whole plugin life cycle, we declare it as static, global variable:&lt;/p></description></item><item><title>Introducing XPPL</title><link>https://www.my-universe.com/2023/09/22/introducing-xppl/</link><pubDate>Fri, 22 Sep 2023 00:00:00 +0000</pubDate><guid>https://www.my-universe.com/2023/09/22/introducing-xppl/</guid><description>&lt;p>Are you tired of (re-)writing the same boilerplace code for every &lt;a href="https://www.x-plane.com">X-Plane&lt;/a> plugin project &amp;mdash; over and over again? Well, at least that&amp;rsquo;s how I felt when I started my fourth or fifth plugin. Sure, I reused a lot of my boilerplate code, but with every project, I refined and enhanced it. Backporting those changes to older plugins became a tedious task though; therefore I started the X-Plane Plugin Library (&lt;a href="https://github.com/daemotron/xppl">XPPL&lt;/a>).&lt;/p></description></item><item><title>Cache Your Datarefs</title><link>https://www.my-universe.com/2023/04/20/cache-your-datarefs/</link><pubDate>Thu, 20 Apr 2023 22:20:48 +0200</pubDate><guid>https://www.my-universe.com/2023/04/20/cache-your-datarefs/</guid><description>&lt;p>Nearly every X-Plane plugin accesses one or several of X-Plane&amp;rsquo;s &lt;a href="https://developer.x-plane.com/datarefs/">datarefs&lt;/a> at runtime. It&amp;rsquo;s not uncommon to find code like this:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#282a36;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-c" data-lang="c">&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">1&lt;/span>&lt;span>&lt;span style="color:#8be9fd">void&lt;/span> &lt;span style="color:#50fa7b">set_data&lt;/span>(&lt;span style="color:#8be9fd">float&lt;/span> value)
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">2&lt;/span>&lt;span>{
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">3&lt;/span>&lt;span> XPLMDataRef dref &lt;span style="color:#ff79c6">=&lt;/span> &lt;span style="color:#50fa7b">XPLMFindDataRef&lt;/span>(&lt;span style="color:#f1fa8c">&amp;#34;what/ever/data/ref/we/need&amp;#34;&lt;/span>);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">4&lt;/span>&lt;span> &lt;span style="color:#50fa7b">XPLMSetDataf&lt;/span>(dref, value);
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span style="white-space:pre;-webkit-user-select:none;user-select:none;margin-right:0.4em;padding:0 0.4em 0 0.4em;color:#7f7f7f">5&lt;/span>&lt;span>}
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Admittedly this works. However, there are a couple of reasons why the code above is not the best idea, if you&amp;rsquo;re seeking to write a solid and well-performing plugin:&lt;/p></description></item><item><title>Talk to the Log</title><link>https://www.my-universe.com/2023/01/14/talk-to-the-log/</link><pubDate>Sat, 14 Jan 2023 19:51:48 +0100</pubDate><guid>https://www.my-universe.com/2023/01/14/talk-to-the-log/</guid><description>&lt;p>Making an &lt;a href="https://www.x-plane.com/">X-Plane&lt;/a> plugin &amp;ldquo;talk&amp;rdquo; to us is one of the boilerplate tasks when setting up a new plugin project. X-Plane has its own log file, &lt;code>log.txt&lt;/code>, which is found in X-Plane&amp;rsquo;s root folder. The file gets reset every time X-Plane starts, so there&amp;rsquo;s no need to rotate or trim it from time to time. As a plugin author, we have the choice to either write our own log file, or to jump on X-Plane&amp;rsquo;s bandwagon and use its logging system for our purposes. While I can see the benefits of having a dedicated logfile for a plugin, personally I prefer to use X-Plane&amp;rsquo;s built in logging mechanism &amp;ndash; there are technical reasons, but mostly it&amp;rsquo;s a comfort and usability decision: most X-Plane users will immediately think of the central &lt;code>log.txt&lt;/code> file when a developer asks them to provide their log file (e.g. when reporting an issue).&lt;/p></description></item><item><title>CMake Linux Hack</title><link>https://www.my-universe.com/2023/01/11/cmake-linux-hack/</link><pubDate>Wed, 11 Jan 2023 00:16:46 +0100</pubDate><guid>https://www.my-universe.com/2023/01/11/cmake-linux-hack/</guid><description>&lt;p>Beginning with its most recent version (3.25 at the time of writing this post), &lt;a href="https://cmake.org/">CMake&lt;/a> provides the &lt;a href="https://cmake.org/cmake/help/latest/variable/LINUX.html">LINUX&lt;/a> variable, which I used in &lt;a href="https://www.my-universe.com/2023/01/04/x-plane-plugin-boilerplate/">my previous post&lt;/a>. Of course, developers on Linux tend to use the version of CMake they can install from their distribution&amp;rsquo;s package manager. On Ubuntu 22.04 LTS that would be 3.22, and even on the most recent Ubuntu version (22.10) we&amp;rsquo;re at 3.24 &amp;mdash; meaning this variable is not available in these CMake versions.&lt;/p></description></item><item><title>X-Plane Plugin Boilerplate</title><link>https://www.my-universe.com/2023/01/04/x-plane-plugin-boilerplate/</link><pubDate>Wed, 04 Jan 2023 15:28:28 +0100</pubDate><guid>https://www.my-universe.com/2023/01/04/x-plane-plugin-boilerplate/</guid><description>&lt;p>&lt;a href="https://www.x-plane.com">X-Plane&lt;/a> has a well-documented, accessible &lt;a href="https://developer.x-plane.com/sdk/">API&lt;/a>, making it relatively easy to write plugins for the simulator. In this post I&amp;rsquo;m going to demonstrate how a basic plugin boilerplate can look like, and how to build it on different platforms.&lt;/p>
&lt;p>Let&amp;rsquo;s get started with some basics: X-Plane plugins are dynamically linked libraries, which are loaded by X-Plane at runtime. They have to provide an API as defined by the X-Plane SDK, so X-Plane can access the plugin via defined entry points. The &lt;a href="https://developer.x-plane.com/sdk/">API documentation&lt;/a> explains all this, and also provides examples for basic and more advanced plugins. For this post I am going to use a very barebone plugin which does nothing except existing in X-Plane.&lt;/p></description></item></channel></rss>