<?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>28 bytes later</title>
	<atom:link href="http://28byteslater.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://28byteslater.com</link>
	<description>keeping wtf/m in line</description>
	<lastBuildDate>Thu, 30 Jul 2015 10:55:07 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.0.8</generator>
	<item>
		<title>&#8220;CALL OF DO IT&#8221; &#8211; SGJ2015 entry</title>
		<link>http://28byteslater.com/2015/07/30/call-of-do-it-sgj2015-entry/</link>
		<comments>http://28byteslater.com/2015/07/30/call-of-do-it-sgj2015-entry/#comments</comments>
		<pubDate>Thu, 30 Jul 2015 10:53:54 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gamejams]]></category>
		<category><![CDATA[games]]></category>

		<guid isPermaLink="false">http://28byteslater.com/?p=421</guid>
		<description><![CDATA[Last weekend I participated in the first edition of Slavic Game Jam. This year&#8217;s theme was &#8220;Just do it&#8221; (© Shia LaBeouf). I found a great team and we created a game called &#8220;CALL OF DO IT&#8221;. It&#8217;s a 3D &#8230; <a href="http://28byteslater.com/2015/07/30/call-of-do-it-sgj2015-entry/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img class="alignleft" src="http://warsztat.gd/imgcache/9d234ab7369c4a3f9eca58f9563ed649/400/2000/crop" alt="" width="400" height="250" /></p>
<p>Last weekend I participated in the first edition of <a href="http://slavicgamejam.org/">Slavic Game Jam</a>. This year&#8217;s theme was &#8220;Just do it&#8221; (© Shia LaBeouf). I found a great team and we created a game called &#8220;CALL OF DO IT&#8221;. It&#8217;s a 3D drone operator simulator, created with Godot Engine.</p>
<p>I think that the final result is quite nice, especially regarding the visuals and audio. You can check out the intro/gameplay video on Youtube:</p>
<p><iframe width="584" height="438" src="https://www.youtube.com/embed/rnhQjwE-kFI?feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>Downloads:</p>
<table>
<tbody>
<tr>
<td><img title="Wersja Windows" src="http://warsztat.gd/img/osicons/win.png" alt="Wersja Windows" /></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://28byteslater.com/pub/CallOfDoIt_win.zip">Windows</a></td>
</tr>
<tr>
<td><img title="Wersja OSX" src="http://warsztat.gd/img/osicons/apple.png" alt="Wersja OSX" /></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://28byteslater.com/pub/CallOfDoIt_osx.zip">OSX</a></td>
</tr>
<tr>
<td><img title="Wersja Linux 64b" src="http://warsztat.gd/img/osicons/linux.png" alt="Wersja Linux 64b" /></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://28byteslater.com/pub/CallOfDoIt_linux64.zip">Linux 64b</a></td>
</tr>
<tr>
<td><img title="Wersja Linux 32b" src="http://warsztat.gd/img/osicons/web.png" alt="Wersja Linux 32b" /></td>
<td>&nbsp;&nbsp;&nbsp;&nbsp;<a href="http://28byteslater.com/pub/CallOfDoIt_linux32.zip">Linux 32b</a></td>
</tr>
</tbody>
</table>
<p><a href="http://warsztat.gd/projects/call_of_do_it/info">Project info &#038; keys</a> (Polish only, but you&#8217;ll get it ;))</p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2015/07/30/call-of-do-it-sgj2015-entry/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Cinematic&#8221; 30 fps explained</title>
		<link>http://28byteslater.com/2014/12/07/cinematic-30-fps-explained/</link>
		<comments>http://28byteslater.com/2014/12/07/cinematic-30-fps-explained/#comments</comments>
		<pubDate>Sun, 07 Dec 2014 13:09:12 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[gfx]]></category>

		<guid isPermaLink="false">http://28byteslater.com/?p=403</guid>
		<description><![CDATA[There is an ongoing debate on console vs PC, 30 vs 60 fps gaming experience. While there is a little doubt about what feels better, there is also a lot of misunderstanding about the actual rendering methods and the &#8220;cinematic&#8221; experience &#8230; <a href="http://28byteslater.com/2014/12/07/cinematic-30-fps-explained/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>There is an ongoing debate on console vs PC, 30 vs 60 fps gaming experience. While there is a little doubt about what <em>feels</em> better, there is also a lot of misunderstanding about the actual rendering methods and the &#8220;cinematic&#8221; experience that 30 fps is supposed to provide (but doesn&#8217;t).</p>
<p>So let&#8217;s talk about photography first. In a digital world, to capture a photo you need to store light reaching the camera&#8217;s sensor. You open the shutter (a mechanical element blocking the light), record light for a specific amount of time (eg. 1/2000 s), close the shutter &#8211; all done. Recording a movie is not really much different &#8211; only that the exposure time is constant (1/fps, eg. 1/24 s) and no shutter movement is required.</p>
<p>So, let&#8217;s take a look at a photo captured using &#8220;cinematic&#8221; settings (1/24 s):<span id="more-403"></span></p>
<p><a href="http://28byteslater.com/wp-content/uploads/2014/12/cinema24.jpg"><img class="alignnone size-full wp-image-404" src="http://28byteslater.com/wp-content/uploads/2014/12/cinema24.jpg" alt="cinema24" width="700" /></a></p>
<p>As you can see, it is very, very blurry (regarding the moving parts)! And this is exactly what you see when you pause a movie. So, would &#8220;60fps&#8221; picture be sharp? Let&#8217;s see&#8230;</p>
<p><a href="http://28byteslater.com/wp-content/uploads/2014/12/cinema60.jpg"><img class="alignnone size-full wp-image-406" src="http://28byteslater.com/wp-content/uploads/2014/12/cinema60.jpg" alt="cinema60" width="700" /></a></p>
<p>While it <strong>is</strong> sharper than 1/24 s picture, there is still a significant amount of motion blur. Of course the faster an objects moves, the more blurry it will appear in a picture &#8211; and depending on the speed there is an exposure time that would freeze the motion completely.</p>
<p>But, in reality, this actually can be good for watching animated content (movies, games, etc). Because let&#8217;s take a look at the alternative:</p>
<p><a href="http://28byteslater.com/wp-content/uploads/2014/12/cinemainf.jpg"><img class="alignnone size-full wp-image-407" src="http://28byteslater.com/wp-content/uploads/2014/12/cinemainf.jpg" alt="cinemainf" width="700" /></a></p>
<p>While this was not captured with infinite speed (1/800 s actually), it was enough to freeze the motion. While is is certainly sharper when looking at, this doesn&#8217;t provide visual clues about the motion. Does the car move or is parked? How fast does it move? From a single picture we simply can&#8217;t tell!</p>
<p>Also, this is much closer to hardware rendering that consoles and PCs use for games. With classic polygonal rendering you <strong>always </strong>render a single point in time. Yes, you can apply different kinds of motion blur (camera blur, vector blur, skinning based vector blur etc) later in the post-processing, but these are approximation methods that don&#8217;t always capture the 100% correct motion.</p>
<p>So, in theory the best experience would be gained with a movie (game) with FPS as high as possible, with <strong>correct</strong> motion blur applied. Of course the higher the FPS, the less visible the motion blur would be (except for <em>really </em>high velocities).</p>
<p>But there are also two other important factors to consider:</p>
<p><strong>Input lag. </strong>While it&#8217;s not <em>necessarily</em> related to a specific FPS counter, it often is. Input lag measured how long does it take between you press a key or button and a relevant action is applied on screen. This is actually more complex than you might think, because of numerous steps in between (capturing input, processing input, processing game world/physics update, queueing and finally updating display buffer). In theory, a game with 30 fps visuals (and some motion blur perhaps?), 240 fps physics and immediate input processing could be perceived as <em>smoother </em>than a 60 fps game with 60 fps physics and 2-3 frame delayed input processing.</p>
<p><strong>Time for processing a single frame. </strong>This actually applies to both gaming and photography. In the latter the shorter the exposure is, the higher sensitivity you must set on the sensor and as a result, get a noisier picture. In gaming you have less and less time as the FPS gets higher, and this is not an excuse from a lousy developer &#8211; doing everything in mere 16 ms (for 60 fps games) is a real challenge, especially if the game world conditions can rapidly change.</p>
<p>Finally, I&#8217;ve created a simple animation to demonstrate low FPS with motion blur vs high FPS without motion blur to give a better understanding of the whole &#8220;cinematic experience&#8221; thing. I&#8217;ve made a super simple Blender animation with 240 fps, rendered 2.5 s (600 frames) of it and then:</p>
<p>30 fps with motion blur (average 8 frames to create motion blur):</p>
<p><div style="width: 584px; height: 329px; " class="wp-video"><!--[if lt IE 9]><script>document.createElement('video');</script><![endif]-->
<video class="wp-video-shortcode" id="video-403-1" width="584" height="329" loop="1" autoplay="1" preload="metadata" controls="controls"><source type="video/mp4" src="http://28byteslater.com/wp-content/uploads/2014/12/mm30.mp4?_=1" /><a href="http://28byteslater.com/wp-content/uploads/2014/12/mm30.mp4">http://28byteslater.com/wp-content/uploads/2014/12/mm30.mp4</a></video></div></p>
<p>60 fps without motion blur (take every 4th frame):</p>
<p><div style="width: 584px; height: 329px; " class="wp-video"><video class="wp-video-shortcode" id="video-403-2" width="584" height="329" loop="1" autoplay="1" preload="metadata" controls="controls"><source type="video/mp4" src="http://28byteslater.com/wp-content/uploads/2014/12/mm60.mp4?_=2" /><a href="http://28byteslater.com/wp-content/uploads/2014/12/mm60.mp4">http://28byteslater.com/wp-content/uploads/2014/12/mm60.mp4</a></video></div></p>
<p>This is of course a little different setup than car photos before (car is almost stable, the road changes), but you can see that correctly motion-blurred 30 fps <em>can </em>be actually easier to watch.</p>
<p>Also, two &#8220;corner cases&#8221;: really bad example (which probably causes this whole PC vs console, 60 vs 30 fps war), 30 fps with no blur:</p>
<p><div style="width: 584px; height: 329px; " class="wp-video"><video class="wp-video-shortcode" id="video-403-3" width="584" height="329" loop="1" autoplay="1" preload="auto" controls="controls"><source type="video/mp4" src="http://28byteslater.com/wp-content/uploads/2014/12/mm30bad.mp4?_=3" /><a href="http://28byteslater.com/wp-content/uploads/2014/12/mm30bad.mp4">http://28byteslater.com/wp-content/uploads/2014/12/mm30bad.mp4</a></video></div></p>
<p>And the &#8220;holy grail&#8221; (on 60 fps display, which is usually the case) which is 60 fps motion blurred version:</p>
<p><div style="width: 584px; height: 329px; " class="wp-video"><video class="wp-video-shortcode" id="video-403-4" width="584" height="329" loop="1" autoplay="1" preload="auto" controls="controls"><source type="video/mp4" src="http://28byteslater.com/wp-content/uploads/2014/12/mm60good.mp4?_=4" /><a href="http://28byteslater.com/wp-content/uploads/2014/12/mm60good.mp4">http://28byteslater.com/wp-content/uploads/2014/12/mm60good.mp4</a></video></div></p>
<p>So, now you are properly equipped to fight 30 fps battles. Have fun with gaming on your favorite platform! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2014/12/07/cinematic-30-fps-explained/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://28byteslater.com/wp-content/uploads/2014/12/mm30.mp4" length="117493" type="video/mp4" />
<enclosure url="http://28byteslater.com/wp-content/uploads/2014/12/mm60.mp4" length="138598" type="video/mp4" />
<enclosure url="http://28byteslater.com/wp-content/uploads/2014/12/mm30bad.mp4" length="118157" type="video/mp4" />
<enclosure url="http://28byteslater.com/wp-content/uploads/2014/12/mm60good.mp4" length="136140" type="video/mp4" />
		</item>
		<item>
		<title>Simple CSG library for C++</title>
		<link>http://28byteslater.com/2013/07/07/simple-csg-library-for-c/</link>
		<comments>http://28byteslater.com/2013/07/07/simple-csg-library-for-c/#comments</comments>
		<pubDate>Sun, 07 Jul 2013 17:37:44 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[libraries]]></category>

		<guid isPermaLink="false">http://28byteslater.com/?p=387</guid>
		<description><![CDATA[I needed CSG operations for my engine. Having no interest in writing one, I started to look for existing solutions. However, I found virtually no CSG library for C++ that was both licence-compatible (LGPL sucks for mobile dev, GPL just &#8230; <a href="http://28byteslater.com/2013/07/07/simple-csg-library-for-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img style="float:right" class="alignright size-thumbnail wp-image-389" alt="csg" src="http://28byteslater.com/wp-content/uploads/2013/07/csg-150x150.png" width="150" height="150" />I needed CSG operations for my engine. Having no interest in writing one, I started to look for existing solutions. However, I found virtually no CSG library for C++ that was both licence-compatible (LGPL sucks for mobile dev, GPL just sucks for anything not OS size) and reasonable in size. I love <a href="http://nothings.org/">stb_-style</a> single file libraries, but I can accept small solutions that I can just copy into my project workspace. Sadly, most CSG libraries I found were behemoths of several megabytes of code each. I&#8217;m not even trying to imagine what can they do besides the obvious. However, I found one neat solution: <a href="http://evanw.github.io/csg.js/">http://evanw.github.io/csg.js/</a> which only downside was the language choice. Javascript is not really friends with C++, but anyway I found csg.js quite easy to port to C++ as no weird JS features were used.</p>
<p>So, here you go: <a href="https://github.com/dabroz/csgjs-cpp">https://github.com/dabroz/csgjs-cpp</a></p>
<p>Single file, no dependencies outside STL. It&#8217;s able to do basic CSG operations, not super fast, no mesh optimization but only 0.5 KLOC which can be easily made into &lt;0.2 KLOC by removing comments and replacing conversions with engine-specific data. MIT licence, as the original library.</p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2013/07/07/simple-csg-library-for-c/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>iOS compatibility calculator</title>
		<link>http://28byteslater.com/2013/01/03/ios-compatibility-calculator/</link>
		<comments>http://28byteslater.com/2013/01/03/ios-compatibility-calculator/#comments</comments>
		<pubDate>Wed, 02 Jan 2013 22:29:50 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://28byteslater.com/?p=366</guid>
		<description><![CDATA[iOS offers (via UIRequiredDeviceCapabilities) possibility to require specific device capabilities, like GPS or camera. Unfortunately it doesn&#8217;t allow to select devices manually. For most applications this is not a problem, but there are apps like games that require specific performance &#8230; <a href="http://28byteslater.com/2013/01/03/ios-compatibility-calculator/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img class="size-full wp-image-368 alignleft" alt="iosc-thumb" src="http://28byteslater.com/wp-content/uploads/2013/01/iosc-thumb.png" width="150" height="138" />iOS offers (via UIRequiredDeviceCapabilities) possibility to require specific device capabilities, like GPS or camera. Unfortunately it doesn&#8217;t allow to select devices manually. For most applications this is not a problem, but there are apps like games that require specific performance level. And <a href="http://28byteslater.com/2012/12/30/relative-iphoneipad-performance/">performance varies on different iOS devices</a>. So in order to exclude some devices you need to provide more device feature requirements. Similar or maybe even worse situation is on Mac App Store.</p>
<p>&nbsp;</p>
<p>So I&#8217;ve created a tool to help calculate required capabilities. You can grab it here: <a href="http://28byteslater.com/ios-compatibility/">http://28byteslater.com/ios-compatibility/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2013/01/03/ios-compatibility-calculator/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Relative iPhone/iPad performance (update)</title>
		<link>http://28byteslater.com/2012/12/30/relative-iphoneipad-performance/</link>
		<comments>http://28byteslater.com/2012/12/30/relative-iphoneipad-performance/#comments</comments>
		<pubDate>Sat, 29 Dec 2012 23:35:46 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ios]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[stats]]></category>

		<guid isPermaLink="false">http://28byteslater.com/?p=326</guid>
		<description><![CDATA[Notes: I&#8217;ve been monitoring performance statistics for my first game Taste My Steel! currently it&#8217;s available on iOS devices and so are the stats this is a 2D game, OpenGL ES 2.0 with trivial shader uses texture atlas (game uses &#8230; <a href="http://28byteslater.com/2012/12/30/relative-iphoneipad-performance/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><img class="alignnone  wp-image-327" alt="ios-performance" src="http://28byteslater.com/wp-content/uploads/2012/12/ios-performance2.png" width="600" /></p>
<p>Notes:</p>
<ul>
<li>I&#8217;ve been monitoring performance statistics for my first game <a href="http://rockhardgames.com/tastemysteel/">Taste My Steel!</a></li>
<li>currently it&#8217;s available on iOS devices and so are the stats</li>
<li><span style="line-height: 13.316666603088379px;">this is a 2D game, OpenGL ES 2.0 with trivial shader</span></li>
<li>uses texture atlas (game uses 2 physical textures + 1 additional for GUI) and client-side vertex buffer (not too many vertices)</li>
<li>so, GPU side fillrate limited</li>
<li>uses native resolution everywhere (so it doesn&#8217;t compare raw performance)</li>
<li>works flawlessly on most devices, except for first iPad (HUGE leap between iPad 1 and iPad 2) and 4th generation iPhone/iPod touch (first devices with Retina resolution, 4x pixels but with the same GPU)</li>
<li>soon I&#8217;ll have stats for another game (this time 3D)</li>
<li>and for some Android devices (a.k.a. sea of madness)</li>
<li>we use different texture sizes for each device. Base resolution for HDPI/Retina tablets, half for Retina phones/regular tablets and 1/4 for low-end devices like pre-Retina iPhones.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2012/12/30/relative-iphoneipad-performance/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>28 bytes later&#8230;</title>
		<link>http://28byteslater.com/2012/12/30/28-bytes-later/</link>
		<comments>http://28byteslater.com/2012/12/30/28-bytes-later/#comments</comments>
		<pubDate>Sat, 29 Dec 2012 23:22:14 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[meta]]></category>
		<category><![CDATA[rockhard]]></category>
		<category><![CDATA[tms]]></category>

		<guid isPermaLink="false">http://28byteslater.com/?p=315</guid>
		<description><![CDATA[Many things happened recently. I&#8217;ve started my own company Rockhard. I&#8217;m going to create some fun games and at the same time turn some of the awesome technology I&#8217;ve build over the years into production-grade products. Having done that I&#8217;ll &#8230; <a href="http://28byteslater.com/2012/12/30/28-bytes-later/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Many things happened recently.</p>
<p><img class="alignleft" alt="lmvkwg_256_r" src="http://28byteslater.com/wp-content/uploads/2012/12/lmvkwg_256_r-150x150.png" width="90" height="90" /></p>
<p>I&#8217;ve started my own company <a href="http://rockhardgames.com/">Rockhard</a>. I&#8217;m going to create some fun games and at the same time turn some of the awesome technology I&#8217;ve build over the years into production-grade products. Having done that I&#8217;ll swiftly switch onto a cold fusion and rocket engines. Stay tuned!</p>
<p>&nbsp;</p>
<p><img class=" wp-image-319 alignleft" alt="ruagrk_256_r" src="http://28byteslater.com/wp-content/uploads/2012/12/ruagrk_256_r-150x150.png" width="90" height="90" /></p>
<p>I&#8217;ve also released my first game <a href="http://rockhardgames.com/tastemysteel/">Taste My Steel!</a> Not exactly a multi-platform AAA game one could expect, but I&#8217;ve learned many hard lessons on the way anyway. And apart from giving me countless topics to rant on this is also a really fun game which you&#8217;d have to be a grumpy cat not to like. Seriously!</p>
<p>&nbsp;</p>
<p>And last but not least, I&#8217;ve changed this blog&#8217;s title and address. dabroz.scythe.pl had little semantic value given that scythe.pl never made it out. So now we are <em>28 bytes later</em>. See semantics now?</p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2012/12/30/28-bytes-later/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Fast coding with C++?</title>
		<link>http://28byteslater.com/2012/12/09/fast-coding-with-c/</link>
		<comments>http://28byteslater.com/2012/12/09/fast-coding-with-c/#comments</comments>
		<pubDate>Sat, 08 Dec 2012 22:26:03 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[lua]]></category>
		<category><![CDATA[rant]]></category>

		<guid isPermaLink="false">http://dabroz.scythe.pl/?p=312</guid>
		<description><![CDATA[My friend Adam Sawicki posted an interesting blog post recently: C++ is Good for Fast Coding with which I couldn&#8217;t disagree more. While certainly you can do fast coding in C++ (especially being an experienced developer) there is just so much more in &#8230; <a href="http://28byteslater.com/2012/12/09/fast-coding-with-c/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>My friend Adam Sawicki posted an interesting blog post recently: <a href="http://asawicki.info/news_1518_c_is_good_for_fast_coding.html" target="_blank">C++ is Good for Fast Coding</a> with which I couldn&#8217;t disagree more. While certainly you can do fast coding in C++ (especially being an experienced developer) there is just so much more in the world.</p>
<p>Few examples: iteration time. With small and simple C++ codebase usage you can cut compilation, link and startup time to few seconds, and you need to switch between your game/app and IDE. With more dynamic languages you certainly can do better. Some languages like Lua (and, FWIW, Dab) allow easy hotswapping. I have a nice prototyping environment for Lua code &#8211; I have a game running on one screen, debugging info on another and the code itself (nothing fancy &#8211; Notepad++) on the third one. I trace changes in game source using WinAPI and simple Ctrl+S lets me to view my changes immediately (non-compiling code is rejected). This allows me to have like 3 iterations per second and when doing some finetuning every iteration counts. And I believe that I&#8217;d still be able to do better (like using some dedicated Lua editor). Code hotswapping in C++ is nontrivial and even with sophisticated framework with DLL swapping you probably won&#8217;t beat 0.3 IPS due to build time.</p>
<p>Another issue: language features. There is a lot that is easily doable with Lua and close to impossible for C++. While C++0x is picking up, most dynamic languages have had stuff like closures since always. You can have table proxies (have array of 20 enemies to update? update the array!) or functional programming stuff (map/reduce/filter etc -&gt; beat <tt>enemies.max("x")</tt> with C++!). This do matter if your app have an expected lifespan of a mayfly.</p>
<p>Of course most of this stuff isn&#8217;t very helpful for large projects. With 400KLOC project, weak linking alone will make you cry and run for your life. But with 400LOC project it&#8217;s just cool. I would even love to quietly call nils like Obj-C for that matter, but I guess you shouldn&#8217;t be greedy.</p>
<p>If you&#8217;re experienced enough you&#8217;ll probably be able to code small project in C++ (or any other language) in few hours &#8211; not because you use C++, but because it&#8217;s a small project and you are experienced. If you weren&#8217;t, you&#8217;d probably spend 3 hours to fix linker errors alone. And don&#8217;t be afraid to try out new stuff &#8211; especially if it&#8217;s a short home project. For example, until recently I didn&#8217;t know I love Ruby as a shell scripting language &#8211; but I&#8217;ve tried it and won&#8217;t look back.</p>
<p>TL;DR: if you say you can code fast small game in C++, try Lua and keep it real!</p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2012/12/09/fast-coding-with-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inbraker</title>
		<link>http://28byteslater.com/2012/08/14/inbraker/</link>
		<comments>http://28byteslater.com/2012/08/14/inbraker/#comments</comments>
		<pubDate>Mon, 13 Aug 2012 22:44:13 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rockhard]]></category>

		<guid isPermaLink="false">http://dabroz.scythe.pl/?p=306</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<p><a href="http://dabroz.scythe.pl/wp-content/uploads/2012/08/itb.jpg"><img class="alignnone  wp-image-307" title="itb" src="http://dabroz.scythe.pl/wp-content/uploads/2012/08/itb.jpg" alt="" width="720" height="512" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2012/08/14/inbraker/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>New project</title>
		<link>http://28byteslater.com/2012/08/08/new-project/</link>
		<comments>http://28byteslater.com/2012/08/08/new-project/#comments</comments>
		<pubDate>Wed, 08 Aug 2012 14:04:57 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[tbaproject]]></category>

		<guid isPermaLink="false">http://dabroz.scythe.pl/?p=302</guid>
		<description><![CDATA[Lately I&#8217;m working on a new mobile game. More info soon.]]></description>
				<content:encoded><![CDATA[<p>Lately I&#8217;m working on a new mobile game. More info soon.</p>
<p><img src="http://dabroz.scythe.pl/wp-content/uploads/2012/08/teaserblog.jpg" alt="" title="teaserblog" width="700" height="500" class="alignnone size-full wp-image-303" /></p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2012/08/08/new-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time loop</title>
		<link>http://28byteslater.com/2012/07/17/time-loop/</link>
		<comments>http://28byteslater.com/2012/07/17/time-loop/#comments</comments>
		<pubDate>Tue, 17 Jul 2012 21:29:31 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[meta]]></category>

		<guid isPermaLink="false">http://dabroz.scythe.pl/?p=287</guid>
		<description><![CDATA[Wow, I haven&#8217;t posted anything here since last year. Really, shame on me. And sure, posting meta entries just to keep blog alive is not the best way to go, but I have few technical rants as well. It is &#8230; <a href="http://28byteslater.com/2012/07/17/time-loop/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Wow, I haven&#8217;t posted anything here since last year. Really, shame on me. And sure, posting meta entries just to keep blog alive is not the best way to go, but I have few technical rants as well.</p>
<p>It is worth noting that this site started as a ordinary WordPress blog, that was later switched to hand-made C# app. Well, C# is quite a cool language (and not only for web, I&#8217;ve prototyped a lot of games with it!). Way more sane than PHP and/or WordPress itself. But, sadly, finding a reasonable .NET web hosting for a page my size is tricky at best. I wasn&#8217;t very happy with my hosting company and when my account expired I thought it would be a good moment to have some fun.</p>
<p>So, we&#8217;re back with WordPress. I&#8217;m still not a fan, but I managed to do some stuff on <a href="http://blog.lvxtechdemo.com/">Lvx website</a> with it, so I gave it another chance. I made a new theme and decided to do some crazy WebGL. And with ThreeJS framework it&#8217;s actually quite fun! And there has been a long time since I&#8217;ve coded nice 3D stuff.</p>
<p>Now I would like to write a little bit about my recent and distant projects and update some infos. Hope it won&#8217;t take me another 6 months to do so. There is a LOT of stuff to cover.</p>
<p>And, last but not least, I would love some feedback about new site/theme.</p>
<p><a href="/wp-content/uploads/2012/07/page-1.png"><img class="alignnone size-medium wp-image-288" title="Old blog" src="/wp-content/uploads/2012/07/page-1-300x240.png" alt="" width="300" height="240" /></a><a href="/wp-content/uploads/2012/07/page-2.png"><img class="alignnone size-medium wp-image-289" title="New blog" src="/wp-content/uploads/2012/07/page-2-300x240.png" alt="" width="300" height="240" /></a></p>
<p>Bye old blog. Hello new blog.</p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2012/07/17/time-loop/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysterious OpenGL debug window</title>
		<link>http://28byteslater.com/2011/12/09/mysterious-opengl-debug-window/</link>
		<comments>http://28byteslater.com/2011/12/09/mysterious-opengl-debug-window/#comments</comments>
		<pubDate>Fri, 09 Dec 2011 05:47:55 +0000</pubDate>
		<dc:creator><![CDATA[]]></dc:creator>
				<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://dabroz.scythe.pl/2011/12/09/mysterious-opengl-debug-window</guid>
		<description><![CDATA[Today I run my game and was very surprised about mysterious window: Console opened at 02:58:46 09-Dec-11 GL_CLAMP_VERTEX_COLOR_ARB is clamped. GL_CLAMP_FRAGMENT_COLOR_ARB is clamped. There are 0 constants bound by this program. Texture 0 uses an 32 bit floating point format. &#8230; <a href="http://28byteslater.com/2011/12/09/mysterious-opengl-debug-window/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Today I run my game and was very surprised about mysterious window:</p>
<p><img src="http://dabroz.scythe.pl/upload/2011/12/debug_output.png" alt="debug_output.png" /></p>
<pre>Console opened at 02:58:46 09-Dec-11
        GL_CLAMP_VERTEX_COLOR_ARB is clamped.
        GL_CLAMP_FRAGMENT_COLOR_ARB is clamped.
        There are 0 constants bound by this program.
        Texture 0 uses an 32 bit floating point format.
        Texture 0 is bound to texture target GL_TEXTURE_2D.
</pre>
<p>If you are wondering what is it, it seems that recent NVidia drivers added this feature if you enable debug flag in your OpenGL 3+ context. Also, debug output quality seems to be improving:</p>
<p><tt>OpenGL message 131218: Program/shader state performance warning: Fragment Shader is going to be recompiled because the shader key based on GL state mismatches. [source: API] [type: performance] [severity: medium]</tt></p>
<p>It&#8217;s nowhere near DirectX debugging tools, but hey, that&#8217;s still better than 4-color LED.</p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2011/12/09/mysterious-opengl-debug-window/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>First standalone Dab game</title>
		<link>http://28byteslater.com/2011/11/24/first-standalone-dab-game/</link>
		<comments>http://28byteslater.com/2011/11/24/first-standalone-dab-game/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 04:16:53 +0000</pubDate>
		<dc:creator><![CDATA[Tomasz Dąbrowski]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dablang]]></category>

		<guid isPermaLink="false">http://dabroz.scythe.pl/2011/11/24/first-standalone-dab-game</guid>
		<description><![CDATA[Notice: I&#8217;ve created Dab blog, but most post will be mirrored here. Few weeks passed since first release of Dab. I’ve been working on the codebase, refactoring a lot of code and adding static compilation (i.e. creating executable files). And &#8230; <a href="http://28byteslater.com/2011/11/24/first-standalone-dab-game/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p><strong>Notice: I&#8217;ve created <a href="http://blog.dablang.net">Dab blog</a>, but most post will be mirrored here.</strong></p>
<p>Few weeks passed since first release of Dab. I’ve been working on the codebase, refactoring a lot of code and adding static compilation (i.e. creating executable files). And finally I can introduce to you first standalone game written in Dab.</p>
<p><a href="http://www.dablang.net/samples/jitshooter">JIT Shooter</a> is a project that I was using to create first usable version of Dab. And now you can download its .exe binary that doesn’t need Dab IDE.</p>
<p><a href="https://github.com/downloads/dabroz/dablang-jitshooter/JIT-shooter-standalone.zip">Download JIT Shooter Standalone</a></p>
<p>However there are few issues:</p>
<ul>
<li>you need OpenGL 3.2+ (to save additional functions calls shaders use explicit attrib locations)</li>
<li>you need MS C runtime 7.1 (you can get it <a href="http://www.dll-files.com/dllindex/dll-files.shtml?msvcr71">here</a>, game uses few functions like fopen/fread)</li>
<li>game uses STB image to load textures, those are compiled as DLL</li>
</ul>
<p>But still, there is massive work ahead. I’ve removed few hacks just to add different hacks. However, next version (0.3) will feature proper handling of function pointers and few other modifications that will allow to reduce number of hard-coded tricks. Version 0.2 should happen in next few days.</p>
<p>BTW: I’m very happy with executable size. 39KB for playable native game is really not much. And with better loader (now all CRT/OpenGL calls are resolved in runtime very naively) it can be even smaller.</p>
<p>Other news: I’ve set up this blog as I’m not very happy with existing Dokuwiki site. I’ll probably experiment with wordpress wiki plugins instead.</p>
<p>I’ve also created <a href="https://plus.google.com/u/0/102978350117015169754">Dab Google+ profile</a>. Feel free to <del>like</del>+1!</p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2011/11/24/first-standalone-dab-game/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>TIL history of OpenGL error handling</title>
		<link>http://28byteslater.com/2011/11/08/til-history-of-opengl-error-handling/</link>
		<comments>http://28byteslater.com/2011/11/08/til-history-of-opengl-error-handling/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 22:06:24 +0000</pubDate>
		<dc:creator><![CDATA[]]></dc:creator>
				<category><![CDATA[OpenGL]]></category>

		<guid isPermaLink="false">http://dabroz.scythe.pl/2011/11/08/til-history-of-opengl-error-handling</guid>
		<description><![CDATA[Few months ago I&#8217;ve written a rant about OpenGL error handling. The bad news is that its debug capabilities haven&#8217;t improved much since. The good news is that now I know the history behind this completly insane interface. In late &#8230; <a href="http://28byteslater.com/2011/11/08/til-history-of-opengl-error-handling/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Few months ago I&#8217;ve written a rant about <a href="http://dabroz.scythe.pl/2010/08/28/opengl-debug-api">OpenGL error handling</a>. The bad news is that its debug capabilities haven&#8217;t improved much since. The good news is that now I know the history behind this completly insane interface.</p>
<p>In late &#8217;70, there was a computer called <a href="http://en.wikipedia.org/wiki/TRS-80">TRS-80</a> (from Wikipedia):</p>
<blockquote><p>Level I Basic was based on Li-Chen Wang&#8217;s free Tiny BASIC, additional functions added by Radio Shack.[8] It achieved a measure of noteworthiness due in large part to its outstanding manual,[5] written by David Lien, which presented lessons on programming with text and humorous graphics, making the subjects very easy to understand. It had only two string variables (A$ and B$), 26 numeric variables (A &#8211; Z) and one array, A(). Code for functions like SIN(), COS() and TAN() was not included in ROM but printed at the end of the book. <b>The only error messages were: &#8220;WHAT?&#8221; for syntax errors, &#8220;HOW?&#8221; for arithmetic errors such as division by zero, and &#8220;SORRY&#8221; for out of memory errors.</b></p></blockquote>
<p>Rings a bell?</p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2011/11/08/til-history-of-opengl-error-handling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simplicity Oriented Programming</title>
		<link>http://28byteslater.com/2011/07/16/simplicity-oriented-programming/</link>
		<comments>http://28byteslater.com/2011/07/16/simplicity-oriented-programming/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 18:51:54 +0000</pubDate>
		<dc:creator><![CDATA[]]></dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://dabroz.scythe.pl/2011/07/16/simplicity-oriented-programming</guid>
		<description><![CDATA[After few years on Warsztat (a Polish gamedev site) I&#8217;ve noticed an interesting phenomenon. Every now and then there are Compos (programming competitions) organized in two different flavours. Some compos are single-run events that last only few hours, others are &#8230; <a href="http://28byteslater.com/2011/07/16/simplicity-oriented-programming/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>After few years on <a href="http://warsztat.gd">Warsztat</a> (a Polish gamedev site) I&#8217;ve noticed an interesting phenomenon. Every now and then there are Compos (programming competitions) organized in two different flavours. Some compos are single-run events that last only few hours, others are long-term (several days/weeks). And as an extra catch, the former are usually restricted to basic APIs (SDL, OpenGL etc) while the latter are free-for-all (all sorts of engines, UDK/Unity allowed).</p>
<p>Now, results are somewhat shocking. Much more people participate in short compos than the long ones. But the best part is that quality of games created is just the same, no matter if the games was made in 2 hours or 4 weeks. Why?</p>
<ol>
<li>Well, creating game in 4 weeks doesn&#8217;t usually mean neither 672 nor 224 working hours. In extreme cases 4 week compo is just a 2-hours compo, with 2 hours located at the very end of 4 weeks.</li>
<li>A lot of game value is an idea. Fact: you won&#8217;t come up with better idea in 4 weeks than in 10 minutes.</li>
<li>Development process for 2-hours game is very dense. And most of the time is spent on improving core features (because there are no others).</li>
<li>On the other hand, in long-term projects people start to focus on insignificant features. The moment you start improving abstract communication between task pools, adding GUI widgets so that you can make a built-in MP3 player or making splash screen data-oriented, your project is screwed to hell.</li>
</ol>
<p>And this is probably the most important lesson to remember. If you need to do something very quick, code will be horrific, but also short, simple and fixable. With no time constraints, code will get new levels of complication, features and bugs. Time spent on maintaining won&#8217;t justify the result.</p>
<p>In 4 weeks, you can make several iterations of speed-coding, each time improving core features of the game. If you start with future proofness in mind, writing code and fixing bugs will consume most of the time. Sure, in 4 weeks you can make a ton of assets/levels, but how good are they is core gameplay is not good enough?</p>
<p>Finally, one solid C(++) tip: when adding new features, start with the smallest of available guns:</p>
<ol>
<li>Global function &#8212; if you need to display score, don&#8217;t hesitate to add void DisplayScore() somewhere.  If your game is single-player, store score as a global variable. See? You have just saved 10 minutes of writing getters, setters and designing communication between modules. If your game is multi-player then you will need to store and display scores per-player. But there is no reason to be able to display arbitrary score of arbitrary player if your game is not yet multiplayer. Believe me, you&#8217;ll have bigger problems than displaying score with that.</li>
<li>If your functions share common code or require helper functions, group them somewhere, possibly in separate file. Remember about static functions and variables &#8212; contrary to &#8220;OO&#8221; static, file static is about visibility. But it&#8217;s cool, because you can have a file for all font-related operations and store internal data in static global variable. Helper functions can be static, and public ones go to one shared header (if you write simple code, compilation time is never your enemy).</li>
<li>Promote functions to classes only when it&#8217;s relevant and useful. Remember, classes means objects, objects mean relations and relations means complexity. Is your gameplay so cool that you have time for code complexity?</li>
<li>Any design patterns or other exotic stuff is the last resort if none of above is good enough. Personally? Never got there.</li>
</ol>
<p><i>(from <a href="http://altdevblogaday.com/2011/07/16/simplicity-oriented-programming/">#altdevblogaday</a>)</i></p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2011/07/16/simplicity-oriented-programming/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Keep data close, part 1</title>
		<link>http://28byteslater.com/2011/05/17/keep-data-close-part-1/</link>
		<comments>http://28byteslater.com/2011/05/17/keep-data-close-part-1/#comments</comments>
		<pubDate>Tue, 17 May 2011 04:52:55 +0000</pubDate>
		<dc:creator><![CDATA[]]></dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://dabroz.scythe.pl/2011/05/17/keep-data-close-part-1</guid>
		<description><![CDATA[I would like to present a very cool technique, widely used in C libraries, yet almost completely forgotten in C++. We have a String class. It is a reference-counted, immutable string. Typical data structures in C++ would look like: struct &#8230; <a href="http://28byteslater.com/2011/05/17/keep-data-close-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I would like to present a very cool technique, widely used in C libraries, yet almost completely forgotten in C++.</p>
<p>We have a String class. It is a reference-counted, immutable string. Typical data structures in C++ would look like:</p>
<div class="wp_syntax">
<div class="code">
<pre class="cpp"><span class="kw4">struct</span> string
<span class="br0">&#123;</span>
  string_data <span class="sy2">*</span> data<span class="sy4">;</span>
<span class="br0">&#125;</span><span class="sy4">;</span>
&nbsp;

<span class="kw4">struct</span> string_data
<span class="br0">&#123;</span>
  <span class="kw4">int</span> refcount<span class="sy4">;</span>
  <span class="kw4">int</span> length<span class="sy4">;</span>
  <span class="kw4">char</span> <span class="sy2">*</span> data<span class="sy4">;</span>

<span class="br0">&#125;</span><span class="sy4">;</span></pre>
</div>
</div>
<p>So, string is merely a reference to actual string_data. Creating new string objects (<tt>string foo = "hello world"</tt>) looks like:</p>
<ol>
<li>string_constructor(const char *)
<li>allocate string_data
<li>string_data_constructor(const char *)
<li>allocate char[]
<li>copy data, set all other members
</ol>
<p>In memory, it would actually look like:</p>
<p><a href="http://altdevblogaday.org/wp-content/uploads/2011/05/po-i1.png"><img src="http://altdevblogaday.org/wp-content/uploads/2011/05/po-i1.png" alt="" width="580"  class="alignnone size-full wp-image-5990" /></a></p>
<p>So, we have one stack allocation, two dynamic allocations and our data is in three different places in memory. But in C++ terms it seems impossible to improve it. However, we can go C way and change <tt>string_data</tt> definition:</p>
<div class="wp_syntax">
<div class="code">
<pre class="cpp"><span class="kw4">struct</span> string_data
<span class="br0">&#123;</span>
  <span class="kw4">int</span> refcount<span class="sy4">;</span>
  <span class="kw4">int</span> length<span class="sy4">;</span>

  <span class="kw4">char</span> data<span class="br0">&#91;</span><span class="nu0">1</span><span class="br0">&#93;</span><span class="sy4">;</span>
<span class="br0">&#125;</span><span class="sy4">;</span></pre>
</div>
</div>
<p>Array of one character? I must be crazy, right?</p>
<p>Most C++ courses are not very precise about pointers and arrays. Especially, what is the difference of following instructions?</p>
<div class="wp_syntax">
<div class="code">
<pre class="cpp"><span class="kw4">const</span> <span class="kw4">char</span> <span class="sy2">*</span> string1 <span class="sy1">=</span> <span class="st0">&quot;hello world&quot;</span><span class="sy4">;</span>

<span class="kw4">const</span> <span class="kw4">char</span> string2<span class="br0">&#91;</span><span class="br0">&#93;</span> <span class="sy1">=</span> <span class="st0">&quot;hello, C++!&quot;</span><span class="sy4">;</span></pre>
</div>
</div>
<p>And what is the difference of those?</p>
<div class="wp_syntax">
<div class="code">
<pre class="cpp"><span class="kw4">int</span> foo<span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">char</span> <span class="sy2">*</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">printf</span><span class="br0">&#40;</span><span class="st0">&quot;*<span class="es1">\n</span>&quot;</span><span class="br0">&#41;</span><span class="sy4">;</span> <span class="br0">&#125;</span>

<span class="kw4">int</span> foo<span class="br0">&#40;</span><span class="kw4">const</span> <span class="kw4">char</span><span class="br0">&#91;</span><span class="br0">&#93;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> <span class="kw3">printf</span><span class="br0">&#40;</span><span class="st0">&quot;[]<span class="es1">\n</span>&quot;</span><span class="br0">&#41;</span><span class="sy4">;</span> <span class="br0">&#125;</span></pre>
</div>
</div>
<p>Unfortunately, in C++ world where really various things can be <i>static</i>, answers are different. In first case, string1 and string2 are something else. In second case, there is no difference &#8212; actually, that code won&#8217;t compile due to non-unique overload.</p>
<p>Maybe little investigation? Let&#8217;s print some data:</p>
<div class="wp_syntax">
<div class="code">
<pre class="cpp"><span class="kw3">printf</span><span class="br0">&#40;</span><span class="st0">&quot;%p %p %s<span class="es1">\n</span>&quot;</span>, string1, <span class="sy3">&amp;</span>string1, string1<span class="br0">&#41;</span><span class="sy4">;</span>
<span class="kw3">printf</span><span class="br0">&#40;</span><span class="st0">&quot;%p %p %s<span class="es1">\n</span>&quot;</span>, string2, <span class="sy3">&amp;</span>string2, string2<span class="br0">&#41;</span><span class="sy4">;</span></pre>
</div>
</div>
<p>What we do is printing expression as a pointer, address of this expression as a second pointer and null-terminated string pointed by expression. Results:</p>
<pre>0x08048650 0xbfddbfa4 hello world
0xbfddbf98 0xbfddbf98 hello, C++!</pre>
<p>Now you see magic behind it. 0xbf&#8230;&#8230; are stack addresses while 0&#215;08048650 comes from somewhere else (likely from static, read-only data section). So, while pointer types hold address inside, arrays points to themselves. And we can abuse it!</p>
<p>&#8220;Typical&#8221; C++ allocation of string_data would look like this:</p>
<div class="wp_syntax">
<div class="code">
<pre class="cpp">string_data <span class="sy2">*</span> foo <span class="sy1">=</span> <span class="kw3">new</span> string_data<span class="sy4">;</span></pre>
</div>
</div>
<p>It would allocate <tt>sizeof(string_data)</tt> bytes (9 + padding, probably 12). But in fact, we can allocate as much as we want! For example:</p>
<div class="wp_syntax">
<div class="code">
<pre class="cpp">string_data <span class="sy2">*</span> q <span class="sy1">=</span> <span class="br0">&#40;</span>string_data<span class="sy2">*</span><span class="br0">&#41;</span><span class="kw3">malloc</span><span class="br0">&#40;</span><span class="nu0">2</span> <span class="sy2">*</span> <span class="kw3">sizeof</span><span class="br0">&#40;</span><span class="kw4">int</span><span class="br0">&#41;</span> <span class="sy2">+</span> <span class="nu0">12</span><span class="br0">&#41;</span><span class="sy4">;</span>

<span class="kw3">new</span> <span class="br0">&#40;</span>q<span class="br0">&#41;</span> string_data<span class="sy4">;</span></pre>
</div>
</div>
<p>In this case &#8212; 2 ints and 12 bytes of string data. After successful allocation we need to manually invoke constructor, using placement new. Similarly, regular <tt>delete q</tt> won&#8217;t work &#8212; following code will:</p>
<div class="wp_syntax">
<div class="code">
<pre class="cpp">q<span class="sy2">-</span><span class="sy1">&gt;</span>~string_data<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy4">;</span>
<span class="kw3">free</span><span class="br0">&#40;</span>q<span class="br0">&#41;</span><span class="sy4">;</span></pre>
</div>
</div>
<p>Of course if data type is simple (built-in datatypes, relaxed POD, whatever) there is no need to call constructor and destructor (although those calls probably would be simply optimized away). And malloc/free can be replaced with custom allocation routines.</p>
<p>And after such allocation, we can use <tt>data</tt> like it was not a <tt>char[1]</tt> array but rather a <tt>char[as much as we have allocated]</tt> array! How does memory look like with this data structure?</p>
<p><a href="http://altdevblogaday.org/wp-content/uploads/2011/05/po-i2.png"><img src="http://altdevblogaday.org/wp-content/uploads/2011/05/po-i2.png" alt="" width="580"  class="alignnone size-full wp-image-5994" /></a></p>
<p>And there are numerous benefits of such approach:</p>
<ul>
<li>one dynamic allocation less
<li>data is less scattered in memory
<li>we saved some memory (how much? size of the pointer + size of allocation metadata)
</ul>
<p>In the next part, I&#8217;ll show how we can save even more allocations/memory.</p>
<p><i>(from <a href="http://altdevblogaday.org/2011/05/17/keep-data-close-part-1/">#altdevblogaday</a>)</i></p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2011/05/17/keep-data-close-part-1/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Cross-platform system info and why Windows rocks</title>
		<link>http://28byteslater.com/2011/05/13/cross-platform-system-info-and-why-windows-rocks/</link>
		<comments>http://28byteslater.com/2011/05/13/cross-platform-system-info-and-why-windows-rocks/#comments</comments>
		<pubDate>Fri, 13 May 2011 16:59:22 +0000</pubDate>
		<dc:creator><![CDATA[]]></dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[sysinfo]]></category>

		<guid isPermaLink="false">http://dabroz.scythe.pl/2011/05/13/cross-platform-system-info-and-why-windows-rocks</guid>
		<description><![CDATA[Recently I&#8217;m creating a base library for all my gamedev adventures. It contains both very low-level features (allocator, string, vector, hashmap, errors etc) and reasonably middle-level features (like HTTP requests). Grabbing system information is rather high-level but very important, especially &#8230; <a href="http://28byteslater.com/2011/05/13/cross-platform-system-info-and-why-windows-rocks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Recently I&#8217;m creating a base library for all my gamedev adventures. It contains both very low-level features (allocator, string, vector, hashmap, errors etc) and reasonably middle-level features (like HTTP requests). Grabbing system information is rather high-level but very important, especially for OpenGL developer. It&#8217;s very helpful if you can inform user that he just needs to update drivers.</p>
<p>Typical output:</p>
<pre>[23:12:26] CPU : 8 x 2806 (2806) MHz (Intel(R) Core(TM) i7 CPU         930  @ 2.80GHz, FPU MMX SSE SSE2 SSE3 SSSE3 EST SSE4.1 SSE4.2 POPCNT HTT)
[23:12:26] RAM : 7956MB/12278MB
[23:12:26] GPU : NVIDIA GeForce GTX 460 [8.17.12.6658, 1-7-2011] :: NVIDIA Corporation GeForce GTX 460/PCI/SSE2 using OpenGL 4.1.0
[23:12:26] OS  : Windows 7 (6.1 Service Pack 1) 64 bit</pre>
<p>Many folks complain on Windows API, it&#8217;s backwards compatiblity and overall misery. But while working on sysinfo program, I&#8217;ve actually learned how powerful it is. Few examples:</p>
<h3>Memory</h3>
<p>On <b>Windows</b> there is <a href="http://msdn.microsoft.com/en-us/library/aa366589%28v=vs.85%29.aspx">GlobalMemoryStatusEx</a> function that returns accurate results, in 64-bit format even for 32-bit applications.</p>
<p>On <b>Linux</b> there is <tt>/proc/meminfo</tt> but its results are very hard to interpret and are different than results of <tt>free</tt> command. In the end, I&#8217;ve used <tt>free -mo | head -n 2 | tail -n 1</tt>. Pure magic (and pure hope that <tt>free</tt> output format won&#8217;t change).</p>
<p><b>Mac OSX</b> amused me. As you may or may not know, I&#8217;m an iOS developer. I thought that Mac will be quite similar to its iOS counterpart, maybe with API like <tt>[[NSSystem&nbsp;sharedSystem]&nbsp;freeMemory]</tt>. Hell no! To obtain memory statistics, you need to access Mach (Mac OSX kernel) layer, like this:</p>
<pre>mach_port_t host_port;
mach_msg_type_number_t host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);
vm_size_t pagesize;
vm_statistics_data_t vm_stat;

host_port = mach_host_self();
host_page_size(host_port, &#038;pagesize);        
   
if (host_statistics(host_port, HOST_VM_INFO, (host_info_t)&#038;vm_stat, &#038;host_size) != KERN_SUCCESS) return;

natural_t mem_used = (vm_stat.active_count + vm_stat.inactive_count + vm_stat.wire_count) * pagesize;
mem_free = vm_stat.free_count * pagesize;
mem_total = mem_used + mem_free;
    
mem_free /= 1024 * 1024;
mem_total /= 1024 * 1024;</pre>
<h3>GPU</h3>
<p>On all platforms I query OpenGL for vendor, renderer and both (OGL and GLSL) version strings. But this doesn&#8217;t include driver information. And each vendor/platform has his own vision of those strings.</p>
<p>So, on <b>Windows</b> I use SetupAPI to obtain precise GPU information. With <a href="http://msdn.microsoft.com/en-us/library/ff551010.aspx">SetupDiEnumDeviceInfo</a> I search for <tt>FILE_DEVICE_VIDEO</tt> devices. This is useful, because it allows to check multi-GPU configurations or to bypass additional layers of (OpenGL) emulation (like for example screen capturing applications). And with SetupAPI there is standarized driver information available.</p>
<p>But on <b>Linux</b> it&#8217;s not so easy. I have no Linux-specific programming knowledge (not that I&#8217;ve used SetupAPI before). I didn&#8217;t even search for kernel API for this. I&#8217;ve just used <tt>lspci</tt> command and searched for <i>VGA compatible controller</i>. For NVIDIA cards I&#8217;ve found that I can obtain driver info from <tt>/proc/driver/nvidia/version</tt>. For ATI or other vendors &#8212; I have no idea. Fortunately, ATI seems to include driver information in OpenGL version string (like <i>3.3.<b>10237</b> Compatibility Profile Context</i>) so this should not be a problem. But if you know better solution, please let me know.</p>
<p>On <b>Mac OSX</b> I didn&#8217;t even try. In fact you can&#8217;t install or update GPU drivers on Mac, because those are not provided by NVIDIA or other IHV, but by Great Apple itself &#8212; and that also means that OpenGL stopped at 2.1 version. Hate you, Apple. There is a magic number in OpenGL version string: <i>2.1 NVIDIA-1.6.26</i> but I have no idea how could I compare this to Windows/Linux driver version.</p>
<h3>Conclusions</h3>
<p>There is other data as well, but as complex as examples above. For example to obtain OS data there is <a href="http://msdn.microsoft.com/en-us/library/ms724451%28v=vs.85%29.aspx">GetVersionEx</a> and <a href="http://msdn.microsoft.com/en-us/library/ms724340%28v=vs.85%29.aspx">GetNativeSystemInfo</a> in WinAPI (Native flavour returns 64-bit information for 32-bit apps on 64-bit Windows). On Linux/OSX I just use <tt>uname -a</tt> (Mac OSX have no variations, and on Linux it would be hard because each distribution has its own vision of versioning). CPU was fortunately mostly cross-platform, because I focus on <tt>__cpuid</tt> data (BTW &#8212; do you know how to obtain HTT and/or number of cores from <tt>__cpuid</tt>?).</p>
<p>So my verdict is: Windows rocks, other platforms are pure chaos. At least in grabbing system information. But really, WinAPI may be awkward or &quot;too backward compatible&quot; but at least is simple and powerful.</p>
<p>BTW, if you want to test sysinfo program on your PC, you can grab <a href="http://dabroz.scythe.pl/upload/2011/05/sysinfo_windows.zip">Windows</a>,<br />
<a href="http://dabroz.scythe.pl/upload/2011/05/sysinfo_linux.zip">Linux</a> or<br />
<a href="http://dabroz.scythe.pl/upload/2011/05/sysinfo_osx.zip">Mac OSX</a> version and share results in comments. This is not the most recent version but results would be helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://28byteslater.com/2011/05/13/cross-platform-system-info-and-why-windows-rocks/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
