<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Techniques | Learn C Games Programming Blog</title>
	<atom:link href="https://learncgames.com/category/techniques/feed/" rel="self" type="application/rss+xml" />
	<link>https://learncgames.com</link>
	<description>A blog about C, programming games and my ebook(s).</description>
	<lastBuildDate>Thu, 04 Sep 2025 19:14:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://learncgames.com/wp-content/uploads/2020/03/cropped-favicon-32x32.png</url>
	<title>Techniques | Learn C Games Programming Blog</title>
	<link>https://learncgames.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">181446779</site>	<item>
		<title>Great mystery #1 solved!</title>
		<link>https://learncgames.com/great-mystery-1-solved/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=great-mystery-1-solved</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Thu, 04 Sep 2025 19:00:10 +0000</pubDate>
				<category><![CDATA[Other stuff]]></category>
		<category><![CDATA[Techniques]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3457</guid>

					<description><![CDATA[<p>It was kind of silly. I installed Debian 13 in hyper-V, just to see how different it is from Ubuntu.  Like Ubuntu, it starts in a default size. I looked in the settings and there was a Displays there so I tried it and got the screen resized to full screen size. So I then [&#8230;]</p>
The post <a href="https://learncgames.com/great-mystery-1-solved/">Great mystery #1 solved!</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>It was kind of silly. I installed Debian 13 in hyper-V, just to see how different it is from Ubuntu.  Like Ubuntu, it starts in a default size. I looked in the settings and there was a Displays there so I tried it and got the screen resized to full screen size.</p>
<p>So I then went back to Ubuntu and tried that, and it worked. I believe that what helped was having guest services ticked in the Hyper-v settings.</p>
<p><img fetchpriority="high" decoding="async" class="alignleft size-full wp-image-3458" src="https://learncgames.com/wp-content/uploads/2025/09/hypr-vsettings.png" alt="Hyper-V settings" width="454" height="558" srcset="https://learncgames.com/wp-content/uploads/2025/09/hypr-vsettings.png 454w, https://learncgames.com/wp-content/uploads/2025/09/hypr-vsettings-244x300.png 244w" sizes="(max-width: 454px) 100vw, 454px" /> <img decoding="async" class="alignleft size-full wp-image-3459" src="https://learncgames.com/wp-content/uploads/2025/09/hyper-v-displays.png" alt="Display settings in Ubuntu" width="1032" height="615" srcset="https://learncgames.com/wp-content/uploads/2025/09/hyper-v-displays.png 1032w, https://learncgames.com/wp-content/uploads/2025/09/hyper-v-displays-300x179.png 300w, https://learncgames.com/wp-content/uploads/2025/09/hyper-v-displays-1024x610.png 1024w, https://learncgames.com/wp-content/uploads/2025/09/hyper-v-displays-768x458.png 768w" sizes="(max-width: 1032px) 100vw, 1032px" /></p>The post <a href="https://learncgames.com/great-mystery-1-solved/">Great mystery #1 solved!</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3457</post-id>	</item>
		<item>
		<title>Ever do a sudo apt update on your Raspberry Pi?</title>
		<link>https://learncgames.com/ever-do-a-sudo-apt-update-on-your-raspberry-pi/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=ever-do-a-sudo-apt-update-on-your-raspberry-pi</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Fri, 13 Jun 2025 15:04:05 +0000</pubDate>
				<category><![CDATA[Errors]]></category>
		<category><![CDATA[raspberry-pi]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[hardware clock]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3435</guid>

					<description><![CDATA[<p>&#160; &#160; &#160; &#160; And you get this error message?  It says E: Release file for http://archive.raspberrypi.com/debian/dists/bookworm/InRelease is not valid yet (invalid for another 10h 37min 50s). Updates for this repository will not be applied. E: Release file for http://deb.debian.org/debian/dists/bookworm-updates/InRelease is not valid yet (invalid for another 12h 15min 47s). Updates for this repository will [&#8230;]</p>
The post <a href="https://learncgames.com/ever-do-a-sudo-apt-update-on-your-raspberry-pi/">Ever do a sudo apt update on your Raspberry Pi?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="alignleft size-full wp-image-3436" src="https://learncgames.com/wp-content/uploads/2025/06/update.png" alt="sudo apt update error message" width="681" height="203" srcset="https://learncgames.com/wp-content/uploads/2025/06/update.png 681w, https://learncgames.com/wp-content/uploads/2025/06/update-300x89.png 300w" sizes="(max-width: 681px) 100vw, 681px" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>And you get this error message?  It says</p>
<pre>E: Release file for http://archive.raspberrypi.com/debian/dists/bookworm/InRelease is not valid yet 
(invalid for another 10h 37min 50s). Updates for this repository will not be applied.
E: Release file for http://deb.debian.org/debian/dists/bookworm-updates/InRelease is not valid yet 
(invalid for another 12h 15min 47s). Updates for this repository will not be applied.</pre>
<p>If you do</p>
<pre>sudo hwclock -s</pre>
<p>It will fix it. Apparently it&#8217;s to do with the hardware clock having drifted and I&#8217;m guessing this causes an error condition. Still, its an easy fix!</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/ever-do-a-sudo-apt-update-on-your-raspberry-pi/">Ever do a sudo apt update on your Raspberry Pi?</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3435</post-id>	</item>
		<item>
		<title>Setting up SDL3 on Linux</title>
		<link>https://learncgames.com/setting-up-sdl3-on-linux/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=setting-up-sdl3-on-linux</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 26 May 2025 15:02:41 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[raspberry-pi]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[SDL3 on Linux]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3420</guid>

					<description><![CDATA[<p>I knew it wasn&#8217;t going to be easy, but it turned out to be quite a bit more difficult than I thought. The problem is, unlike SDL2, there are no dev versions of SDL3 etc. yet, so you have to build it from scratch. I&#8217;ll be honest, I&#8217;m not sure I could have done it [&#8230;]</p>
The post <a href="https://learncgames.com/setting-up-sdl3-on-linux/">Setting up SDL3 on Linux</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:17,&quot;href&quot;:&quot;https:\/\/github.com\/Ravbug\/sdl3-sample&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260112022859\/https:\/\/github.com\/Ravbug\/sdl3-sample&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:35:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 18:04:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 22:36:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-15 23:18:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 00:34:59&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-22 04:11:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 10:07:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 10:09:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 12:37:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-06 17:22:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 18:51:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 20:26:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 21:57:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-19 06:22:42&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-22 08:22:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-25 10:53:16&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 10:54:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 11:05:13&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-03-31 11:05:13&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:18,&quot;href&quot;:&quot;https:\/\/github.com\/Ravbug\/sdl3-sample\/wiki\/Setting-up-your-computer&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20250505154154\/https:\/\/github.com\/Ravbug\/sdl3-sample\/wiki\/Setting-up-your-computer&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:35:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 18:04:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 22:36:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-15 23:18:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 00:35:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-22 04:11:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 10:07:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 10:09:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 12:37:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-06 17:22:24&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 18:51:14&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 20:26:12&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 21:57:49&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-19 06:22:43&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-22 08:22:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-25 10:53:18&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 10:54:09&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-31 11:05:24&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-03-31 11:05:24&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3421" src="https://learncgames.com/wp-content/uploads/2025/05/sdl3-1.png" alt="SDL3 program running on Raspberry Pi." width="550" height="514" srcset="https://learncgames.com/wp-content/uploads/2025/05/sdl3-1.png 550w, https://learncgames.com/wp-content/uploads/2025/05/sdl3-1-300x280.png 300w" sizes="auto, (max-width: 550px) 100vw, 550px" /></p>
<p>I knew it wasn&#8217;t going to be easy, but it turned out to be quite a bit more difficult than I thought.</p>
<p>The problem is, unlike SDL2, there are no dev versions of SDL3 etc. yet, so you have to build it from scratch.</p>
<p>I&#8217;ll be honest, I&#8217;m not sure I could have done it without this <a title="Link to Ravbug's Setting up SDL3 sample on GitHub" href="https://github.com/Ravbug/sdl3-sample" target="_blank" rel="noopener">GitHub repository</a>. User <em>Ravbug</em> who is very busy person (<em>752 contributions on GitHub in the last year- I tip my hat to him or her!</em>) who provided that repository.</p>
<p>It sets up SDL3, SDL_image, sdl_mixer and SDL_ttf.</p>
<p>Follow his link to the <a title="Ravbug's instructions" href="https://github.com/Ravbug/sdl3-sample/wiki/Setting-up-your-computer" target="_blank" rel="noopener">Wiki page</a> Scroll down to the bottom for the Linux instructions. I can confirm that it works on Raspberry Pi as well.  You&#8217;ll need to install cmake first with</p>
<pre>sudo apt install cmake</pre>
<p>Then run his cmake to build everything and go for a coffee.<br />
Now go into the build folder under sdl3-sample and do</p>
<pre>make</pre>
<p>That only takes a second or so.</p>
<p>After you&#8217;ve done that you&#8217;ll end up with a load of files including an executable sdl-min that you can run. That&#8217;s what generated the Tiger&#8217;s head &#8211; it plays The Sting film&#8217;s theme (The Entertainer) music as well demonstrating that it&#8217;s using SDL_mixer as well as SDL3 and SDL_ttf (<em>I&#8217;m guessing</em>) and of course SDL_image.</p>
<h3>But that is just the start</h3>
<p>To use SDL3 etc in your C program, you need a bit more configuration than with SDL2. I&#8217;m in uncharted waters here but used an AI- Claude 4 to help me get through and it did.</p>
<p>The problem is you have to tell VS Code where the header files are located, the .so files and also the executable needs to know at runtime.</p>
<p>I set up Ravbug&#8217;s sdl3_sample in my home folder so all paths start <strong>/home/david/sdl3-sample. </strong></p>
<p>This is my tasks.json</p>
<p>&nbsp;</p>
<pre><code class="language-json" data-line="">{
    &quot;version&quot;: &quot;2.0.0&quot;,
    &quot;tasks&quot;: [
        {
            &quot;type&quot;: &quot;shell&quot;,
            &quot;label&quot;: &quot;clang-14.0 build active file&quot;,
            &quot;command&quot;: &quot;/usr/bin/clang-14&quot;,
            &quot;args&quot;: [
                &quot;-I/home/david/sdl3-sample/SDL/include&quot;,
                &quot;-I/home/david/sdl3-sample/SDL_image/include&quot;, 
                &quot;-I/home/david/sdl3-sample/SDL_mixer/include&quot;,
                &quot;-I/home/david/sdl3-sample/SDL_ttf/include&quot;,
                &quot;-g&quot;,
                &quot;${file}&quot;,&quot;${workspaceFolder}/hr_time.c&quot;,
                &quot;-L/home/david/sdl3-sample/build&quot;,	
                &quot;-Wl,-rpath,/home/david/sdl3-sample/build&quot;,				
                &quot;-o&quot;,
                &quot;${fileDirname}/${fileBasenameNoExtension}&quot;,
                &quot;-lSDL3&quot;,
                &quot;-lSDL3_image&quot;, 
                &quot;-lSDL3_ttf&quot;   

            ],
            &quot;options&quot;: {
                &quot;cwd&quot;: &quot;/usr/bin&quot;
            },
            &quot;group&quot;: {
                &quot;kind&quot;: &quot;build&quot;,
                &quot;isDefault&quot;: true
            }
        }
    ]
}</code></pre>
<p>The lines that are SDL3 specific include the -I&#8217;s to provide the include path. -L the path to the .so files and the -rpath line is the path to the runtime files which gets linked into the executable.</p>
<p>If you add these three lines into c_cpp_properties.json then you&#8217;ll also avoid the dreaded red squiggles.</p>
<pre><code class="language-json" data-line="">            &quot;includePath&quot;: [
                &quot;${workspaceFolder}/**&quot;,
                &quot;/home/david/sdl3-sample/SDL/include&quot;,
                &quot;/home/david/sdl3-sample/SDL_image/include&quot;,
                &quot;/home/david/sdl3-sample/SDL_ttf/include&quot;
            ],</code></pre>
<pre><code class="language-json" data-line="">
</code></pre>
<p>And your C&#8217;s #includes need the files prefixed like this :</p>
<pre>#include &lt;SDL3/SDL.h&gt;
#include &lt;SDL3_image/SDL_image.h&gt;
#include &lt;SDL3_ttf/SDL_ttf.h&gt;</pre>
<p>And here it is running on my Pi.</p>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-3422 size-large" src="https://learncgames.com/wp-content/uploads/2025/05/missilecommand_pi-1024x780.png" alt="Missile Command running on a Raspberry Pi 5 with SDL3" width="1024" height="780" srcset="https://learncgames.com/wp-content/uploads/2025/05/missilecommand_pi-1024x780.png 1024w, https://learncgames.com/wp-content/uploads/2025/05/missilecommand_pi-300x229.png 300w, https://learncgames.com/wp-content/uploads/2025/05/missilecommand_pi-768x585.png 768w, https://learncgames.com/wp-content/uploads/2025/05/missilecommand_pi.png 1108w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></p>The post <a href="https://learncgames.com/setting-up-sdl3-on-linux/">Setting up SDL3 on Linux</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3420</post-id>	</item>
		<item>
		<title>Converting from SDL2 to SDL3 on Windows</title>
		<link>https://learncgames.com/converting-from-sdl2-to-sdl3-on-windows/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=converting-from-sdl2-to-sdl3-on-windows</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sat, 24 May 2025 14:21:56 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[SDL]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[SDL2]]></category>
		<category><![CDATA[SDL3]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3414</guid>

					<description><![CDATA[<p>These notes were made when converting an existing C game that used SDL2 to SDL3 on Windows. The game was originally developed for Linux Format and I had got it running on Windows with SDL2. Windows include paths have been made consistent with Linux. The include files path for SDL3 need to be SDL3\&#8230; when [&#8230;]</p>
The post <a href="https://learncgames.com/converting-from-sdl2-to-sdl3-on-windows/">Converting from SDL2 to SDL3 on Windows</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="alignleft wp-image-3418" src="https://learncgames.com/wp-content/uploads/2025/05/SDL3-300x232.png" alt="Missile Command running with SDL3" width="600" height="463" srcset="https://learncgames.com/wp-content/uploads/2025/05/SDL3-300x232.png 300w, https://learncgames.com/wp-content/uploads/2025/05/SDL3-1024x790.png 1024w, https://learncgames.com/wp-content/uploads/2025/05/SDL3-768x593.png 768w, https://learncgames.com/wp-content/uploads/2025/05/SDL3.png 1026w" sizes="auto, (max-width: 600px) 100vw, 600px" /></p>
<p>These notes were made when converting an existing C game that used SDL2 to SDL3 on Windows. The game was originally developed for Linux Format and I had got it running on Windows with SDL2.</p>
<p>Windows include paths have been made consistent with Linux. The include files path for SDL3 need to be SDL3\&#8230; when setting them up. For SDL2, I had them in a folder c:\SDL2\include but noted that in SDL2.h include files were like this:</p>
<pre>#include "SDL_main.h"
#include "SDL_stdinc.h"</pre>
<p>While in SDL3&#8217;s SDL.h they are</p>
<pre>#include &lt;SDL3/SDL_stdinc.h&gt;
#include &lt;SDL3/SDL_assert.h&gt;</pre>
<p>So I put them c:\SDL3\SDL3</p>
<p>When you include them in your software they are like this:</p>
<pre>#include &lt;SDL3/SDL.h&gt;
#include &lt;SDL3/SDL_image.h&gt;</pre>
<p>Which is how they are in Linux.</p>
<p>The rest of these notes are taken from the differences between the SDL2 and SDL3 versions of the game. They are not complete but intended to give you an idea of some of the changes you may need to do.</p>
<h3>SDL_TTF</h3>
<p>TTF_RenderUTF8_Blended( is now TTF_RenderText_Blended with an extra text length parameter.</p>
<h3>SDL_Rects are mostly replaced by SDL_FRect</h3>
<p>This is a big change. Everywhere I was passing in an SDL_Rect became an SDL_Frect which is four floats rather than four ints.</p>
<p>SDL_RenderCopy is now SDL_RenderTexture and the last two params are now SDL_FRects.</p>
<p>To fix this I used a load of (float) casts.</p>
<p><strong>SDL_RenderDrawLine</strong> becomes <strong>SDL_RenderLine</strong> and has an SDL_FRect parameter instaed of SDL_Rect.</p>
<p>Same for <strong>SDL_RenderDrawPoint</strong> which becomes <strong>SDL_RenderPoint</strong>.</p>
<p><strong>SDL_GetMouseState</strong> keeps the same name but returns float * for both parameters now.</p>
<h3>Setup changes slightly</h3>
<p>There&#8217;s no <strong>SDL_SetMainReady()</strong> and SDL2main.lib is gone.</p>
<p>Also gone is <strong>SDL_INIT_EVERYTHING</strong> in <strong>SDL_Init()</strong>&#8211; you have to or the specific subunits. E.g. SDL_INIT_VIDEO | SDL_INIT_EVENTS</p>
<p>Also there&#8217;s no <strong>SDL_RENDERER_PRESENTVSYNC </strong>for SDL_CreateRenderer. Vsync is disabled by default as I found when my game ran about 30x faster and finished in a few seconds! Instead you need to call SDL_SetRenderVSync(renderer, 1) where 1 is syncing with each retrace, or 2 with every 2nd retrace.</p>
<p>Several of the events have been renamed, so SDL_KEYDOWN becomes SDL_EVENT_KEY_DOWN, SDL_MOUSEBUTTONDOWN becomes  SDL_EVENT_MOUSE_BUTTON_DOWN and similar for other events.  Also event.key.keysym.sym becomes event.key.key.</p>
<p>Finally SDL_FreeSurface( becomes SDL_DestroySurface.</p>
<p>I&#8217;m sure there are more but changing these was sufficent to get my game compiling and running correctly with SDL3.</p>The post <a href="https://learncgames.com/converting-from-sdl2-to-sdl3-on-windows/">Converting from SDL2 to SDL3 on Windows</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3414</post-id>	</item>
		<item>
		<title>Bit of a curiosity &#8211; Rust runs slower on Windows than Linux</title>
		<link>https://learncgames.com/bit-of-a-curiosity-rust-runs-slower-on-windows-than-linux/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=bit-of-a-curiosity-rust-runs-slower-on-windows-than-linux</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Fri, 28 Feb 2025 00:00:38 +0000</pubDate>
				<category><![CDATA[64-bit]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Rust]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[poker]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3317</guid>

					<description><![CDATA[<p>And it is a fair comparison because the Linux I&#8217;m running (Ubuntu 24.04 LTS) runs on my Windows 11 box in a hyper-V VM. I wrote a Poker hand evaluation program which loaded a text file containing lines of seven playing cards in text format TS 2C 4D sort of thing. It was seven cards [&#8230;]</p>
The post <a href="https://learncgames.com/bit-of-a-curiosity-rust-runs-slower-on-windows-than-linux/">Bit of a curiosity – Rust runs slower on Windows than Linux</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>And it is a fair comparison because the Linux I&#8217;m running (Ubuntu 24.04 LTS) runs on my Windows 11 box in a hyper-V VM. I wrote a Poker hand evaluation program which loaded a text file containing lines of seven playing cards in text format TS 2C 4D sort of thing. It was seven cards because there&#8217;s two in your hand and five on the table.</p>
<p>There were 1,000 lines of these and the program loaded the file into memory, holding the cards in a Vec&lt;Vec&lt;Card&gt;&gt;. Then it loops through the 1,000 elements and figures out the best hand for each set.  The bit that was timed was the loop not the loading the file into memory.</p>
<p>The source file is on GitHub. It has the project files plus some test cards. You can try it yourself. <strong>Note at the bottom of this article is a link to a much faster version.</strong></p>
<pre>https://github.com/David-H-Bolton/Projects/blob/main/rust_pokerhand.zip</pre>
<p>On my PC, the Windows one average time per hand is 768 ns. On Ubuntu is 540ns. Mad eh! The same program runs in 70% of the time on Linux compared to Windows. Both are run with this command from a terminal/command line.</p>
<pre>cargo run --release 1000_card_hads.txt</pre>
<p>You can also try the test_card_hands.txt but you need to enable the show_cards feature. That shows the cards but doesn&#8217;t do timing. The default is do the timing but don&#8217;t show the cards or the evaluation.</p>
<pre>cargo run --release --features show_card test_card_hands.txt</pre>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3319" src="https://learncgames.com/wp-content/uploads/2025/02/testcards.png" alt="Shows the Rust program with the feature" width="750" height="431" srcset="https://learncgames.com/wp-content/uploads/2025/02/testcards.png 750w, https://learncgames.com/wp-content/uploads/2025/02/testcards-300x172.png 300w" sizes="auto, (max-width: 750px) 100vw, 750px" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>The test cards say what each hand is and the output at the bottom is the program working out each hand.<br />
The file</p>
<pre>https://github.com/David-H-Bolton/Projects/blob/main/rust_pokerhand_faster.zip</pre>
<p>contains a much faster version. On Linux it takes about 127 ns per hand. On Windows it&#8217;s about 190 ns.</p>The post <a href="https://learncgames.com/bit-of-a-curiosity-rust-runs-slower-on-windows-than-linux/">Bit of a curiosity – Rust runs slower on Windows than Linux</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3317</post-id>	</item>
		<item>
		<title>Rust&#8217;s way of importing from other modules is bizarre</title>
		<link>https://learncgames.com/rusts-way-of-importing-from-other-modules-is-bizarre/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rusts-way-of-importing-from-other-modules-is-bizarre</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Mon, 17 Feb 2025 00:05:17 +0000</pubDate>
				<category><![CDATA[Rust]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[Delphi]]></category>
		<category><![CDATA[Struct]]></category>
		<category><![CDATA[unit]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3298</guid>

					<description><![CDATA[<p>I come from a background of Pascal and Delphi. From about 1989 Turbo Pascal 4 and subsequently Delphi had a really useful unit system for breaking a program down into multiple source files. A unit is the equivalent of Rust&#8217;s mod.  Anything you wish to export from a unit is put in the interface section [&#8230;]</p>
The post <a href="https://learncgames.com/rusts-way-of-importing-from-other-modules-is-bizarre/">Rust’s way of importing from other modules is bizarre</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<p>I come from a background of Pascal and Delphi. From about 1989 Turbo Pascal 4 and subsequently Delphi had a really useful unit system for breaking a program down into multiple source files. A unit is the equivalent of Rust&#8217;s mod.  Anything you wish to export from a unit is put in the interface section of the source file- consts, types, functions etc. Like making them pub in Rust. Then in the source file that wants to use these, you just put <em>using name-of-unit</em>. No hassles, very easy to use and it just works.</p>
<p>Now in Rust, they have a cockermanie system.  I had a main.rs that had several Structs (Card and Game) and decided to put it in another file poker.rs inside a mod poker {.</p>
<p>I made both Structs pub.  When compiling, there&#8217;s no errors in poker.rs but in the main.rs which has</p>
<pre><code class="language-rust" data-line="">pub mod poker;
use poker::{Card, Game};</code></pre>
<p>There&#8217;s red lines under Card and Game.</p>
<p>note:<em> struct `crate::poker::poker::Card` exists but is inaccessible</em> etc. Grrr.</p>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-3299 size-full" src="https://learncgames.com/wp-content/uploads/2025/02/poker.png" alt="Rust compile errors" width="509" height="232" srcset="https://learncgames.com/wp-content/uploads/2025/02/poker.png 509w, https://learncgames.com/wp-content/uploads/2025/02/poker-300x137.png 300w" sizes="auto, (max-width: 509px) 100vw, 509px" /></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Now, no doubt there is soime way to make this work but why make it so difficult?</p>The post <a href="https://learncgames.com/rusts-way-of-importing-from-other-modules-is-bizarre/">Rust’s way of importing from other modules is bizarre</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3298</post-id>	</item>
		<item>
		<title>Rust &#8211; Sometimes you don&#8217;t need to use HashMap or HashSet</title>
		<link>https://learncgames.com/rust-sometimes-you-dont-need-to-use-hashmap-or-hashset/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=rust-sometimes-you-dont-need-to-use-hashmap-or-hashset</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Fri, 14 Feb 2025 00:05:27 +0000</pubDate>
				<category><![CDATA[Rust]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[poker]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3291</guid>

					<description><![CDATA[<p>I wrote a Poker Hand evaluator. It read in a file of a 1,000 randomly generated sets of seven cards like this AC 8H JC &#8230;and figured out what was the best hand. It&#8217;s in Rust and on GitHub. That takes you to a projects folder and the whole rust project complete with two test [&#8230;]</p>
The post <a href="https://learncgames.com/rust-sometimes-you-dont-need-to-use-hashmap-or-hashset/">Rust – Sometimes you don’t need to use HashMap or HashSet</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:25,&quot;href&quot;:&quot;https:\/\/github.com\/David-H-Bolton\/Projects&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20240525100439\/https:\/\/github.com\/David-H-Bolton\/Projects&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 10:46:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 13:47:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-19 03:25:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-24 16:07:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 22:29:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 00:00:11&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-17 04:15:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-24 23:34:03&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 08:54:59&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-03-28 08:54:59&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-3292" src="https://learncgames.com/wp-content/uploads/2025/02/cards-300x66.png" alt="Seven playing cards" width="498" height="110" srcset="https://learncgames.com/wp-content/uploads/2025/02/cards-300x66.png 300w, https://learncgames.com/wp-content/uploads/2025/02/cards-768x170.png 768w, https://learncgames.com/wp-content/uploads/2025/02/cards.png 770w" sizes="auto, (max-width: 498px) 100vw, 498px" />I wrote a Poker Hand evaluator. It read in a file of a 1,000 randomly generated sets of seven cards like this AC 8H JC &#8230;and figured out what was the best hand. It&#8217;s in Rust and on <a href="https://github.com/David-H-Bolton/Projects">GitHub.</a> That takes you to a projects folder and the whole rust project complete with two test sets of cards are included. Look for the file Rust_pokerhand.zip.</p>
<p>Now in the Hand evaluation I used both a HashMap and HashSet.  Here for example is the code to count how many of each Rank there are.</p>
<pre><code class="language-rust" data-line="">    let mut rank_counts = HashMap::new();
    for card in cards.iter() {
        *rank_counts.entry(card.rank).or_insert(0) += 1;
    }
</code></pre>
<p>The program reads in the cards into a Vec&lt;Vec&lt;Card&gt;&gt; and then calculate the average time to evaluate a hand.</p>
<p>Now there&#8217;s nothing wrong with the program. One of the card sets is called test_card_hands.txt and has an instance of each hand type along with a comment.</p>
<pre>5H AS 2D 6C 3S KD 7C - High card
7H 3D 8S 7C 4H 9H JC - One Pair
AD 7H 8C AC 5S 8D KS - Two Pairs

</pre>
<p>You can run that with this command:</p>
<pre>cargo run --release --features "show_cards" test_card_hands.txt</pre>
<p>Or if you run the other test set with this, it doesn&#8217;t show the cards but does calculate the average time.</p>
<pre>cargo run --release 1000_card_hands.txt</pre>
<p>If I run this on Windows it evaluates a hand in 780 ns on average and on Ubuntu 24.04 on the same PC, (running under Hyper-V), it&#8217;s faster typically 550 ns.</p>
<p>So, I was looking for ways to speed it up and thought.  The HasmMap and HashSets are running on small numbers of Cards. 13 for Ranks and 4 for suits so what if I use them as arrays. Would it be faster?</p>
<p>It was, roughly <strong>four times faster</strong>.</p>
<p>As an example, the code above I replaced with this:</p>
<div>
<div>
<pre><code class="language-rust" data-line="">    let mut rank_counts = [0,0,0,0,0,0,0,0,0,0,0,0,0];
    for card in cards.iter() {
       rank_counts[&amp;card.rank.value()-2] += 1;
    }</code></pre>
</div>
</div>
<p>That needed a value() method that mapped all the Ranks starting at 2, onto 2-14.</p>
<p>I also redid the code for working out a straight.</p>
<p>The original is this, plus a bit more to check for A2345:</p>
<pre><code class="language-rust" data-line="">    let mut values: HashSet&lt;u8&gt; = cards.iter().map(|card| card.rank.value()).collect();
    let mut unique_values: Vec&lt;u8&gt; = values.drain().collect();
    unique_values.sort_unstable();

    let mut straight_length = 1;
    for i in 1..unique_values.len() {
        if unique_values[i] == unique_values[i - 1] + 1 {
            straight_length += 1;
            if straight_length == 5 {
                is_straight = true;
                break;
            }
        } else {
            straight_length = 1;
        }
    }</code></pre>
<pre>The improved version uses this constant

static STRAIGHTS: &amp;'static [i32]=&amp;[7936, 3968, 1984, 992, 496, 248, 124, 62, 31, 7681];</pre>
<p>Plus a binvalue function which maps the card Ranks onto 1,2,4,8 etc. Just or the Cards binValues together and &#8216;ands&#8217; (&amp;) it with the individual STRAIGHTS values.</p>
<pre><code class="language-rust" data-line="">      let mut bivalue=0;
      for card in cards.iter() {
        bivalue |= card.rank.binvalue();
      }   

      for i in 0..STRAIGHTS.len(){
        if &amp;binvalue &amp; STRAIGHTS[i]== STRAIGHTS[i] {
            is_straight= true;
            break;
        }
    }</code></pre>The post <a href="https://learncgames.com/rust-sometimes-you-dont-need-to-use-hashmap-or-hashset/">Rust – Sometimes you don’t need to use HashMap or HashSet</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3291</post-id>	</item>
		<item>
		<title>Debugging C# on Ubuntu and you get</title>
		<link>https://learncgames.com/debugging-c-on-ubuntu-and-you-get/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=debugging-c-on-ubuntu-and-you-get</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Fri, 07 Apr 2023 23:01:33 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3246</guid>

					<description><![CDATA[<p>So you&#8217;re trying to debug C# code on Linux, maybe Ubuntu. You&#8217;ve installed .NET 6 or 7, you&#8217;ve built your solution in Visual Studio on your Windows PC, published it then copied the files over to the Linux box. But when you run it, you get an error &#8220;Unable to find debugger script at&#8221;. It&#8217;s [&#8230;]</p>
The post <a href="https://learncgames.com/debugging-c-on-ubuntu-and-you-get/">Debugging C# on Ubuntu and you get</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:29,&quot;href&quot;:&quot;https:\/\/developercommunity.visualstudio.com\/t\/Failed-to-launch-debug-adapter-due-to-fa\/1359155&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260206110839\/https:\/\/developercommunity.visualstudio.com\/t\/Failed-to-launch-debug-adapter-due-to-fa\/1359155&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 12:35:50&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-09 15:01:05&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 19:49:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-16 18:55:07&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 02:01:57&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-23 16:01:17&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-27 00:17:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-03 00:09:08&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-06 02:18:16&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-10 04:32:06&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-13 08:50:47&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-16 15:02:52&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-20 00:37:25&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-24 00:39:09&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-28 00:36:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-01 03:18:28&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-01 03:18:28&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3249" src="https://learncgames.com/wp-content/uploads/2023/04/vs-debugger2.png" alt="vs-debugger-popup" width="420" height="190" srcset="https://learncgames.com/wp-content/uploads/2023/04/vs-debugger2.png 420w, https://learncgames.com/wp-content/uploads/2023/04/vs-debugger2-300x136.png 300w" sizes="auto, (max-width: 420px) 100vw, 420px" /></p>
<p>So you&#8217;re trying to debug C# code on Linux, maybe Ubuntu. You&#8217;ve installed .NET 6 or 7, you&#8217;ve built your solution in Visual Studio on your Windows PC, published it then copied the files over to the Linux box. But when you run it, you get an error &#8220;Unable to find debugger script at&#8221;. It&#8217;s time to debug your Linux app from your Windows Visual Studio.</p>
<p>Now there is a <a title="Link to Developer Community for Visual Studio" href="https://developercommunity.visualstudio.com/t/Failed-to-launch-debug-adapter-due-to-fa/1359155" target="_blank" rel="nofollow noopener">Microsoft support issue</a> for this and it&#8217;s less than helpful. Read below to see how I fixed it.</p>
<p>Only, as soon as it tries to attach over SSH (with username, password, IP etc), you get this popup on the left. &#8220;Computer says no&#8221;.</p>
<p>Looking in the VS Output folder you see the text below or something similar. For whatever reason, it failed to create a hidden folder in your home folder. To fix this, all you have to do is create that folder. It&#8217;s .vs-debugger under your home folder.</p>
<p>If you&#8217;re not familiar with .folders on Linux, note that the . at the front of the name means it&#8217;s a hidden folder. A simple <strong>ls</strong> command will not reveal it. If you use the File Manager, you can click the settings in the top right and tick the Show Hidden Files. Then you can do a <strong>cd ~</strong> followed by a <strong>mkdir .vs-debugger</strong>. And View in files to confirm that it&#8217;s there.</p>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3248" src="https://learncgames.com/wp-content/uploads/2023/04/vs-debugger1.png" alt="" width="641" height="144" srcset="https://learncgames.com/wp-content/uploads/2023/04/vs-debugger1.png 641w, https://learncgames.com/wp-content/uploads/2023/04/vs-debugger1-300x67.png 300w" sizes="auto, (max-width: 641px) 100vw, 641px" />Now the only pain with debugging is that the application must be running for Visual Studio to attach to it. I was debugging a utility that is run, does its business and closes. So to debug it, I added this as the first line in main() in program.cs</p>
<p>Console.ReadKey();</p>
<p>So run it, let it sit waiting for a key then attach visual studio&#8217;s debugger to your app over SSH, add your breakpoints and hit a key. Simples!</p>The post <a href="https://learncgames.com/debugging-c-on-ubuntu-and-you-get/">Debugging C# on Ubuntu and you get</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3246</post-id>	</item>
		<item>
		<title>New Linux Timing Code</title>
		<link>https://learncgames.com/new-linux-timing-code/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=new-linux-timing-code</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Sun, 26 Mar 2023 00:00:22 +0000</pubDate>
				<category><![CDATA[C]]></category>
		<category><![CDATA[Clang]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[timing]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3221</guid>

					<description><![CDATA[<p>For some time, I had a problem with my old Linux timing code. The units hr_time.h/c had to have the includes arranged in the right order and some flags set for it to compile. Plus it never seemed right having to do this in hr_time.h #include &#60;linux/time.h&#62; #define __timespec_defined 1 #define __itimerspec_defined 1 #define __timeval_defined [&#8230;]</p>
The post <a href="https://learncgames.com/new-linux-timing-code/">New Linux Timing Code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:30,&quot;href&quot;:&quot;https:\/\/solarianprogrammer.com\/2019\/04\/17\/c17-programming-measuring-execution-time-delaying-program&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251202052526\/https:\/\/solarianprogrammer.com\/2019\/04\/17\/c17-programming-measuring-execution-time-delaying-program\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:04:01&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-11 21:41:38&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-20 02:02:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-23 20:04:04&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-27 11:01:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-02 22:29:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-07 18:00:40&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 00:00:17&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-15 12:32:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 20:48:50&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-26 05:21:13&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-02 18:33:35&quot;,&quot;http_code&quot;:206}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-02 18:33:35&quot;,&quot;http_code&quot;:206},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft wp-image-3223 size-medium" src="https://learncgames.com/wp-content/uploads/2023/03/2yj6mbvj0sg-300x169.jpg" alt="silver and white round analog watch" width="300" height="169" srcset="https://learncgames.com/wp-content/uploads/2023/03/2yj6mbvj0sg-300x169.jpg 300w, https://learncgames.com/wp-content/uploads/2023/03/2yj6mbvj0sg-1024x576.jpg 1024w, https://learncgames.com/wp-content/uploads/2023/03/2yj6mbvj0sg-768x432.jpg 768w, https://learncgames.com/wp-content/uploads/2023/03/2yj6mbvj0sg-1536x864.jpg 1536w, https://learncgames.com/wp-content/uploads/2023/03/2yj6mbvj0sg.jpg 1600w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>For some time, I had a problem with my old Linux timing code. The units hr_time.h/c had to have the includes arranged in the right order and some flags set for it to compile. Plus it never seemed right having to do this in hr_time.h</p>
<pre><code class="language-c" data-line="">#include &lt;linux/time.h&gt;
#define __timespec_defined 1
#define __itimerspec_defined 1
#define __timeval_defined 1
</code></pre>
<p>But today I found some better code on this <a title="Link to entry on Solarianprogrammer.com" href="https://solarianprogrammer.com/2019/04/17/c17-programming-measuring-execution-time-delaying-program/" target="_blank" rel="nofollow noopener">Solarian</a>Programmer website and I&#8217;m always happy to give credit where it&#8217;s due. I&#8217;ve witched to using C17 which clang on Ubuntu (clang 14) and Raspberry Pi (clang 11) both seem to accept.</p>
<p>So now my hr_time.h looks like this:</p>
<p>hr_time.h</p>
<pre><code class="language-c" data-line="">#pragma once
#include &lt;stdlib.h&gt;
#include &lt;time.h&gt;

void startTimer();
void stopTimer();
double diff();</code></pre>
<p>hr_time.c</p>
<pre><code class="language-c" data-line="">#include &quot;hr_time.h&quot;
#include &lt;time.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;stdio.h&gt;

struct timespec start;
struct timespec end;

void startTimer() {
	if (timespec_get(&amp;start, TIME_UTC) != TIME_UTC) {
		printf(&quot;Error in calling timespec_get\n&quot;);
		exit(EXIT_FAILURE);
	}
};

void stopTimer() {
	if (timespec_get(&amp;end, TIME_UTC) != TIME_UTC) {
		printf(&quot;Error in calling timespec_get\n&quot;);
		exit(EXIT_FAILURE);
	}
};

double diff()
{
	return  (double)(end.tv_sec - start.tv_sec) + 
			((double)(end.tv_nsec - start.tv_nsec) / 1000000000L);
}</code></pre>
<p>I&#8217;m only ever using one timer, if you want to modify this to pass in a timer in the startTimer and stopTimer then it&#8217;s easy enough.</p>The post <a href="https://learncgames.com/new-linux-timing-code/">New Linux Timing Code</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3221</post-id>	</item>
		<item>
		<title>A free eBook about the Game of Life</title>
		<link>https://learncgames.com/a-free-ebook-about-the-game-of-life/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=a-free-ebook-about-the-game-of-life</link>
		
		<dc:creator><![CDATA[David]]></dc:creator>
		<pubDate>Fri, 17 Feb 2023 00:00:15 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[Techniques]]></category>
		<category><![CDATA[life]]></category>
		<guid isPermaLink="false">https://learncgames.com/?p=3210</guid>

					<description><![CDATA[<p>Remember the cellular automation Life? I covered it in previous blog entries John Conway&#8217;s Game of Life and also Portable Life in C. Well, Associate Professor Nathaniel Johnston (in the Department of Mathematics and Computer Science at Mount Allison University in New Brunswick, Canada) and Dave Greene wrote a book/eBook about Life. It&#8217;s N. Johnston [&#8230;]</p>
The post <a href="https://learncgames.com/a-free-ebook-about-the-game-of-life/">A free eBook about the Game of Life</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></description>
										<content:encoded><![CDATA[<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:31,&quot;href&quot;:&quot;https:\/\/www.njohnston.ca\/publications\/conways-game-of-life-mathematics-and-construction&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20260206110750\/https:\/\/njohnston.ca\/publications\/conways-game-of-life-mathematics-and-construction\/&quot;,&quot;redirect_href&quot;:&quot;https:\/\/njohnston.ca\/publications\/conways-game-of-life-mathematics-and-construction\/&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 19:09:59&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-09 20:19:23&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 22:35:42&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-16 19:52:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 02:02:03&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-24 16:45:44&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-01 17:04:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-06 23:03:48&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-11 04:41:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-14 16:16:29&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-20 13:33:46&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-24 12:58:00&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-27 21:49:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-03 02:45:38&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-03 02:45:38&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:32,&quot;href&quot;:&quot;https:\/\/sourceforge.net\/projects\/golly&quot;,&quot;archived_href&quot;:&quot;http:\/\/web-wp.archive.org\/web\/20251221195135\/https:\/\/sourceforge.net\/projects\/golly\/&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-02-06 11:04:10&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-09 20:19:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-12 22:35:41&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-16 19:52:37&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-20 02:01:59&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-02-24 00:15:22&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-02-27 00:41:45&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-03-03 20:07:33&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-06 21:54:31&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-10 18:30:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-14 16:16:30&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-18 16:51:22&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-22 08:32:15&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-26 13:35:42&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-03-30 20:41:02&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-04-03 02:45:38&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-04-03 02:45:38&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]'></div>
<p><img loading="lazy" decoding="async" class="alignleft size-full wp-image-3212" src="https://learncgames.com/wp-content/uploads/2023/02/Conways-game-of-life.png" alt="Front cover of Conway's Game of Life eBook." width="223" height="300" />Remember the cellular automation Life? I covered it in previous blog entries <a title="Link to blog entry about the Game of life by John Conway" href="https://learncgames.com/john-conways-game-of-life/" target="_blank" rel="noopener">John Conway&#8217;s Game of Life</a> and also <a title="Link to Portable Life in C blog entry" href="https://learncgames.com/portable-life-in-c/" target="_blank" rel="noopener">Portable Life in C</a>. Well, Associate Professor Nathaniel Johnston (in the Department of Mathematics and Computer Science at Mount Allison University in New Brunswick, Canada) and Dave Greene wrote a book/eBook about Life. It&#8217;s N. Johnston and D. Greene. <em>Conway’s Game of Life: Mathematics and Construction</em>.</p>
<p>The 474 page eBook is free <a title="Link to Page about the book on the author's website" href="https://www.njohnston.ca/publications/conways-game-of-life-mathematics-and-construction/" target="_blank" rel="noopener">on this page</a> or you can buy the coloured hardback book. On Amazon that&#8217;s a modest £59.99! The PDF is 93 MB in size.</p>
<p>Ever since Life was publicized in Scientific American in the 1970s, it&#8217;s held a fascination for many including myself. I wrote a program (in Basic) 45 years ago to run it, but it was quite slow. One of the fastest I ever saw was written in 6502 assembly language running on an Acorn Atom. A very comprehensive and fast open source Life is <a title="Link to Golly project on Sourceforge" href="https://sourceforge.net/projects/golly/" target="_blank" rel="nofollow noopener">Golly</a>, written in C++ and is scriptable in Python or Lua.</p>
<p>But back to the book. If you are a real life afficionado and know the difference between a Glider and an Oscillator then this book/eBook is definitely for you. It&#8217;s a detailed look at Life from an academic point of view.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>The post <a href="https://learncgames.com/a-free-ebook-about-the-game-of-life/">A free eBook about the Game of Life</a> first appeared on <a href="https://learncgames.com">Learn C Games Programming Blog</a>.]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3210</post-id>	</item>
	</channel>
</rss>
