<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>William A Adams</title>
	<atom:link href="http://williamaadams.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://williamaadams.wordpress.com</link>
	<description>Musings of a Creator</description>
	<lastBuildDate>Thu, 23 Feb 2012 23:04:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='williamaadams.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>William A Adams</title>
		<link>http://williamaadams.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://williamaadams.wordpress.com/osd.xml" title="William A Adams" />
	<atom:link rel='hub' href='http://williamaadams.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Banate Core Windows Routines</title>
		<link>http://williamaadams.wordpress.com/2012/02/23/banate-core-windows-routines/</link>
		<comments>http://williamaadams.wordpress.com/2012/02/23/banate-core-windows-routines/#comments</comments>
		<pubDate>Thu, 23 Feb 2012 23:04:19 +0000</pubDate>
		<dc:creator>williamaadams</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://williamaadams.wordpress.com/?p=514</guid>
		<description><![CDATA[Following on the slenderizing process, I&#8217;ve created a new git repository for core windows routines. BanateCoreWin32, is the barest most minimal amount of code required to interop with Windows, to get a window up on the screen, and do some bare metal graphics.  It includes various amounts of: user32, gdi32, kernel32, opengl, avicaps32 A very [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=514&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Following on the slenderizing process, I&#8217;ve created a new git repository for core windows routines.</p>
<p><a href="https://github.com/Wiladams/BanateCoreWin32">BanateCoreWin32</a>, is the barest most minimal amount of code required to interop with Windows, to get a window up on the screen, and do some bare metal graphics.  It includes various amounts of:</p>
<p>user32, gdi32, kernel32, opengl, avicaps32</p>
<p>A very large part of interacting with things on Windows has to do with interop through COM.  Well, that&#8217;s a whole other beast in and of itself.  I could use LuaCom, but that code seems a bit out of date.  What I really want access to is the USB port, to get at things like Kinect and web cameras.  Ideally, I&#8217;ll just read the USB port directly, totally avoiding things like DirectShow and the myriad other layers of left behind APIs that are in Windows.  But, this will take some time.</p>
<p>In the meanwhile, if what you want to do is put a window up on the screen using LuaJit code from the beginning, then this library will help you do it.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/williamaadams.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/williamaadams.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/williamaadams.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/williamaadams.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/williamaadams.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/williamaadams.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/williamaadams.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/williamaadams.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/williamaadams.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/williamaadams.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/williamaadams.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/williamaadams.wordpress.com/514/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/williamaadams.wordpress.com/514/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/williamaadams.wordpress.com/514/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=514&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://williamaadams.wordpress.com/2012/02/23/banate-core-windows-routines/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/04af4800b5b7667a0a64023d8c7a1dd5?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">williamaadams</media:title>
		</media:content>
	</item>
		<item>
		<title>Kicking Dependencies</title>
		<link>http://williamaadams.wordpress.com/2012/02/22/kicking-dependencies/</link>
		<comments>http://williamaadams.wordpress.com/2012/02/22/kicking-dependencies/#comments</comments>
		<pubDate>Wed, 22 Feb 2012 22:04:25 +0000</pubDate>
		<dc:creator>williamaadams</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://williamaadams.wordpress.com/?p=510</guid>
		<description><![CDATA[I&#8217;ve been relatively happy with LuaJit, and using GLFW as a basic UI framework piece has made things relativelly easy.  But still, it&#8217;s just one more piece of code that I have to compile and include in a release.  I don&#8217;t own that piece of code, so I have to make sure the licensing is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=510&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been relatively happy with LuaJit, and using GLFW as a basic UI framework piece has made things relativelly easy.  But still, it&#8217;s just one more piece of code that I have to compile and include in a release.  I don&#8217;t own that piece of code, so I have to make sure the licensing is right, and the code is kept up to date, etc.</p>
<p>The great benefit is that it&#8217;s cross platform.  But, the downside is a 46K glfw.dll file that I have to carry around.  Well, what is GLFW in the first place?  It gives me a nice easy way to get a window, with a OpenGL device context already made and ready to go.  It also handles mouse and keyboard actions in a coherent way.  Besides that, it does a little bit of text handling, and can load Targa images.  By design, that&#8217;s about all it does.</p>
<p>For the most part, it&#8217;s wrapping functions that are already in the underlying OS.  So, I thought, why not just write those wrappers in Lua itself?  I&#8217;m already doing wrappers for GDI calls, so User32 is not any harder.  It was kicking my behind though, and I was having problems getting CreateWindowEx to work correctly.  Here&#8217;s one of those places where the &#8220;magic of Windows&#8221; kind of screws with you.  On Windows, when you make a call like &#8216;CreateWindowEx&#8217;, you don&#8217;t actually call a function by that name.  The wisdom of Windows will determine whether you need to be calling the ASCII version (CreateWindowA) or the Unicode version (CreateWindowW).  As long as you&#8217;re using Microsoft environments, this magic is figured out automatically.  When you&#8217;re on the frontier, doing your own interop, you have to be explicit about what you&#8217;re calling.  Well, I finally got all that straightened out, and I can finally put a window up on the screen:</p>
<p><a href="http://williamaadams.files.wordpress.com/2012/02/luawindow.png"><img class="alignnone size-full wp-image-511" title="luawindow" src="http://williamaadams.files.wordpress.com/2012/02/luawindow.png?w=590" alt=""   /></a></p>
<p>Now that I can actually display a window, it&#8217;s a small step to be able to create my own GL context within that Window as well, all from Lua.  The amount of wrapper code can be counted in the hundreds of lines of Lua code.  The FFI of LuaJit makes this a relatively painless process.  Just grab sections out of a header file, put them into a ffi.cdef[[]] block, and start calling your functions as usual.</p>
<p>Having used this LuaJit FFI stuff, I really can&#8217;t see using any other mechanism.  The previous forms of interop to C from Lua were very challenging, and I&#8217;m very relieved that FFI reduces the challenge to simple copy/paste.</p>
<p>At any rate, that&#8217;s a savings of 46K for the release.  Now I can go spend that on some other new features.</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/williamaadams.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/williamaadams.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/williamaadams.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/williamaadams.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/williamaadams.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/williamaadams.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/williamaadams.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/williamaadams.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/williamaadams.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/williamaadams.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/williamaadams.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/williamaadams.wordpress.com/510/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/williamaadams.wordpress.com/510/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/williamaadams.wordpress.com/510/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=510&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://williamaadams.wordpress.com/2012/02/22/kicking-dependencies/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/04af4800b5b7667a0a64023d8c7a1dd5?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">williamaadams</media:title>
		</media:content>

		<media:content url="http://williamaadams.files.wordpress.com/2012/02/luawindow.png" medium="image">
			<media:title type="html">luawindow</media:title>
		</media:content>
	</item>
		<item>
		<title>The Stream&#8217;s the thing</title>
		<link>http://williamaadams.wordpress.com/2012/02/21/the-streams-the-thing/</link>
		<comments>http://williamaadams.wordpress.com/2012/02/21/the-streams-the-thing/#comments</comments>
		<pubDate>Tue, 21 Feb 2012 23:13:46 +0000</pubDate>
		<dc:creator>williamaadams</dc:creator>
				<category><![CDATA[Lua]]></category>

		<guid isPermaLink="false">http://williamaadams.wordpress.com/?p=508</guid>
		<description><![CDATA[Way back in the day, along with the dawning of man, came the UNIX pipe.  Pipes are great for easily funneling the output of one process to the next: cat file &#124; more Much later, C# continued the theme with streams.  Not quite at the process level, but within programs themselves.  Streams are great because [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=508&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Way back in the day, along with the dawning of man, came the UNIX pipe.  Pipes are great for easily funneling the output of one process to the next:</p>
<p>cat file | more</p>
<p>Much later, C# continued the theme with streams.  Not quite at the process level, but within programs themselves.  Streams are great because they provide a simple common interface to just about anything:</p>
<p>stream.WriteByte(abyte); stream.Write(somebytes); stream.WriteTo(stream)</p>
<p>Well, this is great.  A nice abstraction for packaging things up and sending them somewhere else.  Although Lua has a simple io library, which has a nice enough interface, it&#8217;s missing a couple of things.  At the very lowest level, I want a stream on a chunk of memory.  In the .net frameworks, that&#8217;s provided by the MemoryStream class.  You tell it how much memory, and then you can do Read(), Write() to that memory as if it were any other stream.</p>
<p>This is a pattern that shows up a lot in network programming as well.  I&#8217;ve got data, and I need to encapsulate it into a chunk of memory, and then send it out over a connection of some sort.  It sure would be nice to have that MemoryStream in Lua.</p>
<p>So, I created a MemoryStream object.  But, fefore I could create that, I had to first create the ByteArray object.  It&#8217;s nothing more than a length, and &#8216;unsigned char *&#8217;, for the actual data.  You can allocate one like this:</p>
<p>ba = BufferArray():new(256)</p>
<p>This is possible with LuaJit.  You can do it in regular Lua, but not so easily, and not without writing a bit of C code I believe.  The interface to this thing is simple, you just access the data directly:</p>
<p>ba.data[0] = 23</p>
<p>under the covers, my allocation code is doing this:</p>
<p>self.data = ffi.new(&#8216;unsigned char[?]&#8216;, size)</p>
<p>Through the magic of LuaJit, this will allocate exactly 256 bytes.  If I were using a regular Lua table and did this, it would allocate 8 times the amount, as lua numbers are actually doubles (8 bytes each).</p>
<p>Now, armed with this simple ByteArray, I can build the MemoryStream:</p>
<p>ms = MemoryStream(256)</p>
<p>ms:WriteByte(35);</p>
<p>ms:WriteByte(66);</p>
<p>ms:WriteByte(67);</p>
<p>To write &#8216;A&#8217;,'B&#8217;,'C&#8217; into the memory buffer.  But, if I&#8217;m just going to write characters, that would be of limited usefulness.  I really want to deal with integers, and fractions thereof.  So, I can also do this:</p>
<p>ms:WriteInt32(527)</p>
<p>ms:WriteFloat(37.5)</p>
<p>And likewise for all the other numerical types.  Well, now we&#8217;re talking!  The MemoryStream will automatically write the value as the appropriate number of bytes in network byte order (big endian).  That&#8217;s useful because now I can write out the attached ByteArray as a single chunk, using whatever socket library I happen to have.</p>
<p>It&#8217;s just one of those fundamental building block sorts of things for me.  A ByteArray, a streaming interface, that makes it relatively easy to do something like chaining streams together, just like with UNIX pipes.  Now that I have an easily managed chunk of memory, I can go back and look at the PixelBuffer class I created, and refactor it to just use a ByteArray at its base.  That means eliminating more code!</p>
<p>Meanwhile, back at the graphics ranch, I managed to squeeze 1200 bytes out of my glsl.lua code.  Basically just refactoring the routines to utilize a couple of common base routines.  That&#8217;s 1200 bytes I can now allocate to improving the ray tracer, or adding in some other feature.  I&#8217;m thinking the ray tracer will be the best place to spend these newfound bites.</p>
<p>I&#8217;ve also decided that I don&#8217;t need to have the ability to read all file formats known to man for text maps.  I&#8217;ll have Targa built in, because I wrote code for that a long time ago, and not only is it an easy format to deal with, but the run length codec it uses can be repurposed, which saves more code.</p>
<p>With that, the only real hard dependency I have, beyond LuaJit itself, is the glfw framework/library, and LuaSocket.  For now, I&#8217;ll stick with both of these as they are cross platform, and not too onerous.  With all this work, surely a new release is in the offing!</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/williamaadams.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/williamaadams.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/williamaadams.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/williamaadams.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/williamaadams.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/williamaadams.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/williamaadams.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/williamaadams.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/williamaadams.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/williamaadams.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/williamaadams.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/williamaadams.wordpress.com/508/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/williamaadams.wordpress.com/508/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/williamaadams.wordpress.com/508/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=508&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://williamaadams.wordpress.com/2012/02/21/the-streams-the-thing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/04af4800b5b7667a0a64023d8c7a1dd5?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">williamaadams</media:title>
		</media:content>
	</item>
		<item>
		<title>Ye Olde GDI</title>
		<link>http://williamaadams.wordpress.com/2012/02/19/ye-olde-gdi/</link>
		<comments>http://williamaadams.wordpress.com/2012/02/19/ye-olde-gdi/#comments</comments>
		<pubDate>Sun, 19 Feb 2012 18:25:41 +0000</pubDate>
		<dc:creator>williamaadams</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://williamaadams.wordpress.com/2012/02/19/ye-olde-gdi/</guid>
		<description><![CDATA[So, the switch to LuaJIT has been going well.  I was having one challenge with trying to get a User32 based window up on the screen, then I thought, I&#8217;ll just use GLFW because they&#8217;ve already figured this out across platforms.  And it&#8217;s working like a charm! So, what can I do?  I have a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=507&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>So, the switch to LuaJIT has been going well.  I was having one challenge with trying to get a User32 based window up on the screen, then I thought, I&#8217;ll just use GLFW because they&#8217;ve already figured this out across platforms.  And it&#8217;s working like a charm!</p>
<p>So, what can I do?  I have a window, it has a GL Context associated with it, and other than the core GLFW, everything is actually Lua.  That&#8217;s the power of simple interop.  There are other things I want to interop with though.  Some number of years ago, I wrote this screen capture code.  If you go digging around my <a href="https://github.com/Wiladams/NewTOAPIA">C# archives</a>, you can find the <a href="https://github.com/Wiladams/NewTOAPIA/tree/master/SampleTOAPIA">Snapper</a> example.  It&#8217;s a very simple application that takes a snapshot of the screen.  It uses the underlying GDI stuff that&#8217;s been in Windows since time immemorial.  I wrote it about 5 years ago I think, to teach people how to do some rudimentary programming, with interop, on Windows.</p>
<p>It&#8217;s a good example case of how to do some simple things in Windows.  It involves GDI DibSections, Device Context, BitBLT.  And that&#8217;s just to get a copy of the screen.  I want to go a step further though.  I want to be able to share my screen (collaboration).  So, there are two things that need to be done.  First, I simply need to be able to display what I&#8217;ve captured into the GL Window.  That&#8217;s a relatively easy task now.  I first capture into the DIB Section.  Then I copy those bits to a GLTexture object, which is displayed by applying the texture to a quad in GL, and there you have it.  Without doing any sort of compression tricks, I can get about 24 frames/second capturing at 1920&#215;1080 on my monitor.  That&#8217;s pretty darned good considering how slow this was when I first did it 5 years ago.</p>
<p>But, let&#8217;s say you want to do something more interesting that mirroring between two monitors on your desktop.  Let&#8217;s say you want to share your screen with someone, or multiple someones, in a classroom, or on iPads, across the internet, etc.  Well, now you have the basics.  But, the math isn&#8217;t looking too good.  At 1920&#215;1080, that&#8217;s 2073600 pixels you have to shove down the pipe.  Given the typical RGB, that&#8217;s 6220800 bytes, and at 24 frames per second, that&#8217;s 149299200 (roughly 145Mb), or 1Gbit/second.  No problem, as long as you&#8217;re connected to a hard wired router that handles that kind of speed.</p>
<p>But, I want to reduce that somewhat.  The first thing I want to do is switch from RGB to YUV (4:2:0).  the YUV color model is such that luminance gets more bits than chrominance.  In this particular configuration, I can take a 4&#215;4 pixel area, and instead of using 12 bytes, as I would for RGB, I can use only 6 bytes, and not really lose too much in terms of image quality.  That&#8217;s a 2:1 compression right there.  Another trick I can do is to reduce the size of the image by simple decimation.  In this case, I can reduce by half in each direction, and still be happy with the outcome.  So, down to 960&#215;540 = 518400 bytes per frame, or 12441600 bytes per second at 24 fps (roughly  12Mb), or 120Mbits per second.  Divide by half for switching to YUV, and you get a bitrate of roughly 60mbits.  That&#8217;s much more reasonable for hard wired networks running at 100Mbit.</p>
<p>Now that I&#8217;m in a more reasonable realm, it&#8217;s time to do some serious compression.  H.264 seems to be the compression technique of the day (wave to WebM and others).  As it is designed to deliver the likes of YouTube and others, it is certainly adequate to the task of sharing desktop snapshots.  So, back to LuaJIT.</p>
<p>Next task is to write the FFI for x264.  That should be straight forward as it has a nice clean interface to play with.  If I can run x264 in realtime on a quad i7, then I think I have a chance of sharing my desktop out in realtime over wireless networks.  So, that&#8217;s my next task.</p>
<p>Using LuaJIT makes this stuff really easy.  It&#8217;s fairly hard to deal with all those various libraries.  Mostly dealing with memory management as is typical with non GC based languages.  As well, dealing with differing interfaces such as C vs C++, exceptions, etc.  LuaJIT provides a fairly streamlined view of all those as the FFI layer kind of deals with a lot of it for you.  Of particular usefulness is the FFI figures out stdcall vs fastcall vs whatever, and that can be a pain in and of itself.</p>
<p>So, along with my desktop, I&#8217;ll be hooking up the webcam programs like <a href="https://github.com/Wiladams/NewTOAPIA/tree/master/SampleTOAPIA/CameraServe">Camera Serve</a>.  That&#8217;s a nice little program that takes the stream of pictures from whatever webcam you specify, and streams it out so that others can view.</p>
<p>None of this is rocket science or new.  These are merely exercises to play with the LuaJIT/FFI interfaces.  But, along the way, I&#8217;m finding that the code is becoming much simpler, smaller, and it&#8217;s just so darned quick to throw things together, once you&#8217;ve worked out some basics.</p>
<p>I would put up a picture of my shared screen, but without actually seeing it shared across the monitors, that&#8217;s kind of pointless.  So, it will have to wait until I get x264 working so I can make a movie of the experience.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/williamaadams.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/williamaadams.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/williamaadams.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/williamaadams.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/williamaadams.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/williamaadams.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/williamaadams.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/williamaadams.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/williamaadams.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/williamaadams.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/williamaadams.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/williamaadams.wordpress.com/507/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/williamaadams.wordpress.com/507/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/williamaadams.wordpress.com/507/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=507&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://williamaadams.wordpress.com/2012/02/19/ye-olde-gdi/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/04af4800b5b7667a0a64023d8c7a1dd5?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">williamaadams</media:title>
		</media:content>
	</item>
		<item>
		<title>More LuaJIT Madness</title>
		<link>http://williamaadams.wordpress.com/2012/02/16/more-luajit-madness/</link>
		<comments>http://williamaadams.wordpress.com/2012/02/16/more-luajit-madness/#comments</comments>
		<pubDate>Thu, 16 Feb 2012 20:18:42 +0000</pubDate>
		<dc:creator>williamaadams</dc:creator>
				<category><![CDATA[Lua]]></category>

		<guid isPermaLink="false">http://williamaadams.wordpress.com/?p=415</guid>
		<description><![CDATA[I first joined the dark side when I picked up Lua in favor of the more traditional &#8216;C&#8217; based languages.  Learning new languages is always a slog, and this has been no exception.  But, the concept count is fairly low, and the process from code to run is extremely short, so it&#8217;s not very hard [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=415&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I first joined the dark side when I picked up Lua in favor of the more traditional &#8216;C&#8217; based languages.  Learning new languages is always a slog, and this has been no exception.  But, the concept count is fairly low, and the process from code to run is extremely short, so it&#8217;s not very hard to try things out.</p>
<p>My environment of choice right now is <a href="http://www.scintilla.org/SciTE.html">SciTE</a>.  As Integrated Development Environts (IDEs) go, this is not much more than a nice editor with syntax highlighting.  It has some debug capability, but honestly, I haven&#8217;t even tried it as yet.  My favorite &#8220;Print&#8221; debugger works the same as it has for the past 25 years, so I&#8217;ll stick with it until absolutely necessary.</p>
<p>Lua does satisfy many of the constraints I&#8217;ve given myself in terms of platform availability, succinct code, flexibility, and the like.  Of particular value is the ability to run on really small devices like microcontrollers, cell phones, TVs, and whatnot.</p>
<p>Although I&#8217;ve been satisfied to date, speed is also a concern.  Previously, I made a note about using LuaJIT, and that is the path that I am traveling down as well.  It&#8217;s like throwing off training wheels.  At the same time that I go down the LuaJIT path, I am contemplating my dependency chain.  The various libraries that I use.  I currently use iup (for basic UI) and IM (for imaging).  I also use LuaSocket for collaboration.  The challenge with iup is that it&#8217;s not easily on all platforms.  Works great for Linux and Windows, not so much for Mac.  I&#8217;ve also reconsidered my need to use IM.  I don&#8217;t need to be able to read every type of image file that exists in the world.  I&#8217;m just going to pick a few.</p>
<p>So, I&#8217;m changing things up.  I&#8217;ve switched to using <a href="http://www.glfw.org/">glfw</a> as my core UI library.  GLFW is the most bare minimum UI framework glue you could hope for.  It combines being able to get a handle on a window with being able to get a GL context.  Add in simple mouse/keyboard/joystick events, and you&#8217;re done.  It does not try to solve all programming challenges like larger frameworks.  So, this is very good.  It works on Windows, Mac SO X, and many Unix-like systems using X Windows.  Well, that&#8217;s a good start.  Perhaps I can add the Android and iOS portions if they&#8217;re not already there, and call it a day.</p>
<p>This is great.  Now that I&#8217;m using LuaJIT, and I&#8217;m takinig up GLFW, I get full access to the entirety of the OpenGL/ES API.  I found a nice ready made set of FFI based interop stubs in this project <a href="https://github.com/malkia/ufo">UFO</a>.  Dimiter &#8220;malkia&#8221; stanve has done a great job of going down the path of providing interop to many different libraries, and across multiple platforms, including iOS and Android.  That&#8217;s nice.  Now I can truly write once, and run anywhere.  That&#8217;s the benefit of the Lua talking.</p>
<p>One of the challenges I was facing when using the more pure lua (not LuaJIT) was the interop story.  It&#8217;s extremely hard to write those perfect interop layers.  As such, I was dreading having to write the fully expanded OpenGL API so that I could do some shader programning.  Now, with LuaJIT and UFO, I have ready access to all the nice shader functionality.  That&#8217;s really cool.</p>
<p>Now to try things out.  LuaJIT is supposed to be fairly fast.  So, I&#8217;m going to test that speed by doing some simple compressed target tests.  That&#8217;s an easy task because Targa (.tga files) files use a simple run-length encoding scheme.  So, let&#8217;s see, take a snapshot, compress, send over the net, decompress.  Yep, that aught to about do it.</p>
<p>At any rate, you can go an extremely long way by using these modern tools.  I&#8217;m weening myself and reeducating my expectations as to what can be done with a &#8220;scripting&#8221; language.  I have found myself to be much more productive, able to write new bugs faster than ever before!  This is great, and I&#8217;m sure as more people head down this path (just like with JavaScript), we&#8217;ll see a lot more interesting and dynamic stuff coming online.</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/williamaadams.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/williamaadams.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/williamaadams.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/williamaadams.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/williamaadams.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/williamaadams.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/williamaadams.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/williamaadams.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/williamaadams.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/williamaadams.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/williamaadams.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/williamaadams.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/williamaadams.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/williamaadams.wordpress.com/415/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=415&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://williamaadams.wordpress.com/2012/02/16/more-luajit-madness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/04af4800b5b7667a0a64023d8c7a1dd5?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">williamaadams</media:title>
		</media:content>
	</item>
		<item>
		<title>You can call me Ray</title>
		<link>http://williamaadams.wordpress.com/2012/02/13/you-can-call-me-ray/</link>
		<comments>http://williamaadams.wordpress.com/2012/02/13/you-can-call-me-ray/#comments</comments>
		<pubDate>Mon, 13 Feb 2012 17:22:37 +0000</pubDate>
		<dc:creator>williamaadams</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://williamaadams.wordpress.com/?p=411</guid>
		<description><![CDATA[What is that?  Well, it&#8217;s a bunch of spheres that have been RayTraced in BanateCAD! I&#8217;ve been going on a very interesting trip of late.  What I have been pondering on my walkabout is the following: Is it possible to support &#8211; 3D CSG, Isosurface, Solid Modeling, Perspective, Orthographic, Arbitrary Bump Mapped surfaces, collaboration, and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=411&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://williamaadams.files.wordpress.com/2012/02/raytrace.png"><img class="alignnone size-full wp-image-412" title="raytrace" src="http://williamaadams.files.wordpress.com/2012/02/raytrace.png?w=590" alt=""   /></a></p>
<p>What is that?  Well, it&#8217;s a bunch of spheres that have been RayTraced in BanateCAD!</p>
<p>I&#8217;ve been going on a very interesting trip of late.  What I have been pondering on my walkabout is the following:</p>
<p>Is it possible to support &#8211; 3D CSG, Isosurface, Solid Modeling, Perspective, Orthographic, Arbitrary Bump Mapped surfaces, collaboration, and 2D UI, all in a single environment, written almost exclusively in Lua, in less than 256K of source code?</p>
<p>It&#8217;s a challenging endeavor.  Every new feature adds code.  I&#8217;ve been following a simple principle.  For every expansion of code, there must be an equal and opposite constriction of code.</p>
<p>I am looking at Ray Tracing as a relatively quick way to display a scene.  The first time I even played with ray tracing was probably back in 1994, playing with whatever version of POV-Ray was available at that time.  On my standard issue PC of the day, I would setup a semi-translucent sphere on checkered floor scene, and let it run overnight!  Wow, how times have changed.  Given all the processor performance doubling in the intervening years, machines are certainly capable of rendering much more complex scenes in a fraction of the time.  My thinking is, Ray tracing is the way to go for instant display, and I don&#8217;t deal with meshes at all until I absolutely need to.  That might only be at export time in most cases.  At the same time, it will make displaying isosurfaces in general much easier.</p>
<p>When it comes to the simple &#8216;scenes&#8217; in 3D modeling, a fraction of a second to render an interesting model should not be unheard of.</p>
<p>Ray tracing is interesting.  Similar to 3D modeling, there are some core geometries that you want to deal with.  Ellipsoid, cube, cylinder, etc, and of course some interesting surfaces.  This implies a certain kind of &#8216;world&#8217; model.  Some sort of data structure that exists so that when it comes time to cast rays, you can walk that structure, calling an &#8220;intersect()&#8221; function for each object.</p>
<p>Similarly, you have the same thing for 3D modeling, but you&#8217;re a bit more concerned with a mesh representation, as you&#8217;re going for 2-manifold solids so you can actually print things out.  That implies a representation that favors some mesh like thing.</p>
<p>And finally, there&#8217;s the 2D UI world.  Not 2-manifold, so no mesh required, and instead of a &#8220;hit&#8221;, which is concerned with hit a boundary of an element, you have &#8220;contains()&#8221;, which is concerned with whether a mouse click is &#8216;inside&#8217; or &#8216;outside&#8217; the object in question.</p>
<p>Yep, quite a lot to balance there.</p>
<p>There are essentially three different kinds of renderers, and at least 2 different types of UI interactors (2D vs 3D).</p>
<p>So, some basic things will help here.  First of all, there needs to be a fundamental way of organizing &#8216;scenes&#8217; that&#8217;s universal.  I can default to the 3D representation because I can always assume &#8216;z==0&#8242; for the 2D world, with some arbitrary non-zero thickness.  That&#8217;s nice.  And how about the actual structure itself?  How about a k-d tree?  That seems to be a nice universal structure that can be applied to the 3D scene. It can nicely deal with quickly isolating which objects are in which part of a scene, without having to traverse the whole scene graph.  This is critical for fast rendering updates.  OK, that&#8217;s good, and I can reduce a lot of code.</p>
<p>How about basic data structures?  Well, I started out with a &#8216;vec&#8217; object.  A basic one dimensional array that deals with doing some basic linear algebra.  Then I added Vector3D, Point3D, Normal3D, and Ray3D.  All very similar, but slightly different.  And then, I added the Matrix class, which deals with 1D or 2D arrays (1D being a degenerate case).  Well, there&#8217;s really no difference between the Matrix class and the vec class, so I think the vec class can disappear, or rather simply become a wrapper for the Matrix class.  Same goes for the other ones, although, they are presently just wrappers for vec anyway.  So, more reduction.</p>
<p>At present, the ray tracer is so rudimentary it&#8217;s not even worth calling it a ray tracer, but it is extremely small (80 lines of code).  As it expands in features, it will more than double, and perhaps triple in size.  Given that I won&#8217;t need to introduce any new geometry, this expansion is not that bad.  I&#8217;ll pay for the expansion through consolidation of the aforementioned vector/matrix objects, and savings elsewhere.</p>
<p>In other news, I&#8217;ve been playing with LuaJIT some more, and have a basic Pixel/PixelBuffer thing working.  It&#8217;s fast as can be, and can already be used as an output surface for any of the 3D modeling that I&#8217;m currently doing.  This bodes well since I can cut the number of dependencies (CD and IM Libraries), which makes the code that much smaller and portable.</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/williamaadams.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/williamaadams.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/williamaadams.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/williamaadams.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/williamaadams.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/williamaadams.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/williamaadams.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/williamaadams.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/williamaadams.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/williamaadams.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/williamaadams.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/williamaadams.wordpress.com/411/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/williamaadams.wordpress.com/411/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/williamaadams.wordpress.com/411/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=411&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://williamaadams.wordpress.com/2012/02/13/you-can-call-me-ray/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/04af4800b5b7667a0a64023d8c7a1dd5?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">williamaadams</media:title>
		</media:content>

		<media:content url="http://williamaadams.files.wordpress.com/2012/02/raytrace.png" medium="image">
			<media:title type="html">raytrace</media:title>
		</media:content>
	</item>
		<item>
		<title>Too LuaJIT to quit</title>
		<link>http://williamaadams.wordpress.com/2012/02/11/too-luajit-to-quit/</link>
		<comments>http://williamaadams.wordpress.com/2012/02/11/too-luajit-to-quit/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 08:33:06 +0000</pubDate>
		<dc:creator>williamaadams</dc:creator>
				<category><![CDATA[Lua]]></category>

		<guid isPermaLink="false">http://williamaadams.wordpress.com/?p=409</guid>
		<description><![CDATA[I&#8217;ve been happily trundling along with Lua these past few months, and gotten a fair bit of experience with it.  Before using Lua, I was a hard core C# zealot.  I have a github repository of a ton of C# stuff that I&#8217;ve done in the past.  A huge bulk of that library of stuff [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=409&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been happily trundling along with Lua these past few months, and gotten a fair bit of experience with it.  Before using Lua, I was a hard core C# zealot.  I have a github repository of<a href="https://github.com/Wiladams/NewTOAPIA"> a ton of C# stuff </a>that I&#8217;ve done in the past.  A huge bulk of that library of stuff is interop calls to other parts of Windows, OpenGL, and various other obscure libraries that will never have formal .net framework support.</p>
<p>I love C# as a language.  Really I love well done garbage collection, otherwise, it&#8217;s just another in a long line of &#8216;C&#8217; inspired languages.</p>
<p>One thing I find particularly challenging with C# is that there isn&#8217;t always an interop library available for the latest and greatest cool thing.  Nowadays, invariably it will show up, but still, not always.  For example, the very first attempts at interop with a Kinect were not using C#.  In addition, C# is limited in that it is not really native to all platforms on the planet.</p>
<p>So, what about Lua?  Well, Lua, although it works fairly nicely with C interop, is a bit much to deal with.  In order to write a simple wrapper might require quite a few likely error prone steps.  The state of things is such that it&#8217;s best done using a tool, such as tolua, or tolua++.  These tools will invariably write a bit of C code that wraps the library call in question with some  more goo, dealing with marshalling parameters if necessary, and the like.</p>
<p>Then, along comes <a href="http://luajit.org/">LuaJIT</a>.  There are a number of good things about LuaJIT.  One of the most important is that it runs much faster than the standard Lua distribution.  In some cases, the code runs as fast as standard compiled C code does.  At the very least, I believe it runs faster than any of the other scripting language environments, including the V8 processor for JavaScript.</p>
<p>The thing that got me to look at it though was not just the speed, although that&#8217;s a great bonus.  The other thing is the easier interop to libraries.  With LuaJIT, there is this FFI technology that allows you to make library calls by doing nothing more than taking the standard C definitions of those functions and putting them within some brackets.  The LuaJIT parser can read the standard C declaratons, and generate the appropriate stub call, do the marshalling of parameters, and all that stuff.</p>
<p>Well gee!  That&#8217;s just a godsend.  I was really dreading having to write all that wrapper good, bloating my code in the process.  With LuaJIT, I don&#8217;t have to.  I just need to make sure my declarations are exactly right, and then make calls to functions almost as easily as if they were just Lua calls.</p>
<p>Another bonus is the easy treatment of structure types.  You can use the familiar:</p>
<p>typedef struct { int x,y;} POINT;</p>
<p>And that works just fine.  Similarly, if you want to create an array of rgb pixels: typedef struct {byte r,g,b;} pixel_rgb</p>
<p>And you&#8217;re all set.  This latter one is useful if you&#8217;re doing any rendering, because from Lua I can now do &#8220;direct access&#8221; to stuff, like I do in C, although there is still managed memory safety.  This reduces the memory footprint of my code, and speeds things up dramatically, particularly when I&#8217;m transferring from a pixel buffer to a texture object for display on the screen.</p>
<p>LuaJIT is a departure from the normal Lua distribution, which just recently had a release.  I for one welcome the departure.  It allows for much more flexibility in how to do things.</p>
<p>One thing that I discovered as I was trying out LuaJIT.  The first library I connected to was the gdi32.dll on Windows.  I wanted to get a device context for the screen, and then draw lines, ellipse, and rectangles.  Easy enough.  I did discover something along the way though.  I thought Rectangle() would be really fast, hardware accelerated goodness.  As it turns out, it took many seconds to draw a few hundred on the screen.  I thought that was rather odd, so I tried out RoundedRect() to see how much worse that was going to perform.  Given the same number of rectangles, it displayed in the blink of an eye!  Go figure.  I guess somewhere in the graphics pipeline, rounded rectangles got optimized, and straight ones did not.  that&#8217;s a good fact to know.</p>
<p>One thing that makes this interesting to me is the ease with which this little experiment can be achieved.  Since it&#8217;s Lua, it&#8217;s a small matter of script to get things going.  There is no explicit &#8220;compile&#8221; phase.  Just write a little script and run it, and see what happens.</p>
<p>Given the speed, the interop capabilities, and the general ease of use of Lua, I&#8217;m wondering if I ever really need to use anything else to do system type programming.  I did write all those libraries in C#, but maintaining, and extending them is quite a chore, an art and science, and a generally error prone activity to get them absolutely right.</p>
<p>The next thing I&#8217;ll try, after finishing up some more of GDI and User32, is hook up the USB port functions to see how hard it will be to Kinect.</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/williamaadams.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/williamaadams.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/williamaadams.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/williamaadams.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/williamaadams.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/williamaadams.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/williamaadams.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/williamaadams.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/williamaadams.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/williamaadams.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/williamaadams.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/williamaadams.wordpress.com/409/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/williamaadams.wordpress.com/409/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/williamaadams.wordpress.com/409/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=409&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://williamaadams.wordpress.com/2012/02/11/too-luajit-to-quit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/04af4800b5b7667a0a64023d8c7a1dd5?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">williamaadams</media:title>
		</media:content>
	</item>
		<item>
		<title>Eventus Obscuricus</title>
		<link>http://williamaadams.wordpress.com/2012/02/09/eventus-obscuricus/</link>
		<comments>http://williamaadams.wordpress.com/2012/02/09/eventus-obscuricus/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 20:34:57 +0000</pubDate>
		<dc:creator>williamaadams</dc:creator>
				<category><![CDATA[Banate CAD]]></category>
		<category><![CDATA[HeadsUp]]></category>

		<guid isPermaLink="false">http://williamaadams.wordpress.com/?p=405</guid>
		<description><![CDATA[There always comes a time in a programmer&#8217;s life when they must deal with an &#8220;event loop&#8221;.  Since the dawn of the teletype, programmers have had to deal with the age old question &#8220;should I poll for events, or should I be notified asynchronously&#8221;.  This very question is baked deeply into our CPU architectures with [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=405&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>There always comes a time in a programmer&#8217;s life when they must deal with an &#8220;event loop&#8221;.  Since the dawn of the teletype, programmers have had to deal with the age old question &#8220;should I poll for events, or should I be notified asynchronously&#8221;.  This very question is baked deeply into our CPU architectures with things like interrupts and queues.  It&#8217;s simply unavoidable.  So, here I sit, at the precipice of unification (2D and 3D) and the question arises, should I poll, or should I be notified.</p>
<p>Well, I&#8217;m actually in favor of asynchronous processing because that&#8217;s the way the world works in general.  Sure, we drive towards things, but more often than not, we are responding to something in our environment.  I figure the same should be true of a program.  Yes, it has some goals in mind, but largely it should be responsive to activities that occur on the periphery.</p>
<p>HeadsUp is the 2D aspect of BanateCAD.  This is where events like mouse and keyboard interaction enter the system.  Up until recently, I dealt with these events in a synchronous sort of way, with a typical event loop.  Now, I do a hybrid.  Yes, there is a fundamental message pump that pulls messages out of the system&#8217;s message queue, but then that pump turns around and stuffs them into an asynchronous queue, which is handled by a coroutine (cooperative multitasking).  That&#8217;s handy for a couple of reasons.</p>
<p>First of all, the message pump does not have to be completely synchronous with the rest of the program.  It can just pull messages out of the pipe, and stick them into the queue, rinse and repeat.  That makes the message pump very simple, and easily separable from the rest of the program.  Second, the part of the program that deals with processing messages does not have to know anything about the mechanics of the message pump.  All it knows it that it will be notified when there are messages to be processed.  It can then go pull as many messages from the async queue as it likes, and deal with them at its leisure.</p>
<p>Perhaps it&#8217;s only a point an asynchronous programmer could love.</p>
<p>Now that there&#8217;s a generic queue that can process commands, I want to make everything into commands.  So, here&#8217;s an example of a very typical case.  When I want to draw a line, there is typically some interface connected to the graphics API that looks like this:</p>
<p>Graphics:DrawLine(pt1, pt2)</p>
<p>That will talk to the rendering engine directly, and a line will magically appear.  But, what if under the covers, what was really happening was this:</p>
<p><code><br />
void Graphics:DrawLine(pt1, pt2)<br />
local cmd = Graphics:CreateDrawLine(pt1, pt2)<br />
outboundqueue:Enque(cmd)<br />
end<br />
</code></p>
<p>From the programmer&#8217;s perspective, there&#8217;s nothing different in their conceptual model.  They call DrawLine(), and that&#8217;s the end of it.  They assume a line is drawn, and it will be drawn, eventually.</p>
<p>From the system&#8217;s perspective, a whole world of possibilities just opened up.  Now that the command is packaged up and stuck into a queue, it could be immediately removed from the queue, and really executed against the graphics system, or it could be stored off in some persistent store somewhere, possibly on a distant part of the planet.  And, as long as you&#8217;ve got commands all packaged up and ready to go, you could ship them to other renderers while you&#8217;re at it.  That might be interesting and useful.</p>
<p>At any rate, it&#8217;s a fairly fundamental question to deal with.  Should you poll, or be notified, along with, should you call directly, or issue commands.  In the case of BanateCAD, there is a hybrid of poll/notify, and commands are definitely the way to go.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/williamaadams.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/williamaadams.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/williamaadams.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/williamaadams.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/williamaadams.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/williamaadams.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/williamaadams.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/williamaadams.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/williamaadams.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/williamaadams.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/williamaadams.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/williamaadams.wordpress.com/405/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/williamaadams.wordpress.com/405/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/williamaadams.wordpress.com/405/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=405&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://williamaadams.wordpress.com/2012/02/09/eventus-obscuricus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/04af4800b5b7667a0a64023d8c7a1dd5?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">williamaadams</media:title>
		</media:content>
	</item>
		<item>
		<title>HeadsUp February 6, 2012 Release</title>
		<link>http://williamaadams.wordpress.com/2012/02/06/headsup-february-6-2012-release/</link>
		<comments>http://williamaadams.wordpress.com/2012/02/06/headsup-february-6-2012-release/#comments</comments>
		<pubDate>Tue, 07 Feb 2012 02:32:57 +0000</pubDate>
		<dc:creator>williamaadams</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://williamaadams.wordpress.com/?p=401</guid>
		<description><![CDATA[Here is a new release of HeadsUp.  In this release, there&#8217;s a lot more development of the actor/control system.  Also, the animation system has gotten a freshening up, eliminating some wasteful bitmap copies.  As seen in the picture, running at 20 fps is no problem.  You can go up to about 30 fps, then the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=401&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here is a <a href="https://github.com/Wiladams/BanateCAD/downloads/HeadsUp_20120206.zip">new release of HeadsUp</a>.  In this release, there&#8217;s a lot more development of the actor/control system.  Also, the animation system has gotten a freshening up, eliminating some wasteful bitmap copies.  As seen in the picture, running at 20 fps is no problem.  You can go up to about 30 fps, then the natural throttling that Windows is doing kicks in.</p>
<p>&nbsp;</p>
<p><a href="http://williamaadams.files.wordpress.com/2012/02/frames.png"><img class="alignnone size-full wp-image-402" title="Frames" src="http://williamaadams.files.wordpress.com/2012/02/frames.png?w=590" alt=""   /></a></p>
<p>The samples included in the download show how to do various things from animations to simple controls.</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/williamaadams.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/williamaadams.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/williamaadams.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/williamaadams.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/williamaadams.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/williamaadams.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/williamaadams.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/williamaadams.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/williamaadams.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/williamaadams.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/williamaadams.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/williamaadams.wordpress.com/401/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/williamaadams.wordpress.com/401/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/williamaadams.wordpress.com/401/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=401&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://williamaadams.wordpress.com/2012/02/06/headsup-february-6-2012-release/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/04af4800b5b7667a0a64023d8c7a1dd5?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">williamaadams</media:title>
		</media:content>

		<media:content url="http://williamaadams.files.wordpress.com/2012/02/frames.png" medium="image">
			<media:title type="html">Frames</media:title>
		</media:content>
	</item>
		<item>
		<title>Assembling Bits and Pieces</title>
		<link>http://williamaadams.wordpress.com/2012/02/06/assembling-bits-and-pieces/</link>
		<comments>http://williamaadams.wordpress.com/2012/02/06/assembling-bits-and-pieces/#comments</comments>
		<pubDate>Mon, 06 Feb 2012 16:22:41 +0000</pubDate>
		<dc:creator>williamaadams</dc:creator>
				<category><![CDATA[Banate CAD]]></category>
		<category><![CDATA[HeadsUp]]></category>
		<category><![CDATA[Lua]]></category>

		<guid isPermaLink="false">http://williamaadams.wordpress.com/?p=396</guid>
		<description><![CDATA[If those monkeys pound on those keyboards enough, eventually a masterpiece will emerge&#8230;  Well, software development can be like that sometimes.  I&#8217;ve been spending quite a lot of time on 2D graphics. Part of doing 3D CAD is being able to create a surface of revolution (revoloid).  Well, in order to create a revoloid, I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=396&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If those monkeys pound on those keyboards enough, eventually a masterpiece will emerge&#8230;  Well, software development can be like that sometimes.  I&#8217;ve been spending quite a lot of time on 2D graphics.</p>
<p><a href="http://williamaadams.files.wordpress.com/2012/02/polybuilder.png"><img class="alignnone size-full wp-image-397" title="PolyBuilder" src="http://williamaadams.files.wordpress.com/2012/02/polybuilder.png?w=590&#038;h=483" alt="" width="590" height="483" /></a></p>
<p>Part of doing 3D CAD is being able to create a surface of revolution (revoloid).  Well, in order to create a revoloid, I need to be able to draw a curve, which will then be rotated around an axis.  Well, in order to create a curve, I need to have a nice grid I can use as a guide, and I need control points, and mouse control of those points, etc.</p>
<p>So, I create those various bits and pieces.  I think the grid thing is really cool.  You can specify the distance between the light and dark lines.  You can specify the colors as well.  It becomes useful when you need a backdrop for drawing, or displaying stuff in general to scale.</p>
<p><a href="http://williamaadams.files.wordpress.com/2012/02/graphicarrow.png"><img class="alignnone size-full wp-image-398" title="GraphicArrow" src="http://williamaadams.files.wordpress.com/2012/02/graphicarrow.png?w=590" alt=""   /></a></p>
<p>There have been other graphics along the way as well.  This arrow thing is useful in that the dark gray area can hold other graphics and controls.  Perhaps it doesn&#8217;t make sense sitting there on its own, but it does when it&#8217;s combined with other things.</p>
<p><a href="http://williamaadams.files.wordpress.com/2012/02/tabshelf.png"><img class="alignnone size-full wp-image-399" title="TabShelf" src="http://williamaadams.files.wordpress.com/2012/02/tabshelf.png?w=590" alt=""   /></a></p>
<p>Of course, no UI toolkit these days would be complete without having tabbed views.  So, there they are&#8230;  Of course, since the tabs are created using the ShapeBuilder object, you can get rounded corners instead of those sharp corners if you like.  Since these are just graphics objects, you can also fairly easily do drop shadows, glowing backgrounds, and the like.  And, since they are &#8220;Actor&#8221; objects, they can respond to &#8220;Update&#8221; messages, and change with time, if that&#8217;s useful.</p>
<p>I recently purchased a <a href="http://beagleboard.org/bone">BeagleBone</a>.  A nifty little piece of kit that one.  It uses a TI AM3358 ARM Cortex-A8 based microprocessor.  The board has ethernet and USB built in.  One of the benefits of the little board is that you can run an Android distribution on it.  Also, it has some graphics capabilities, including support for a VNC host, so you can see what&#8217;s on it&#8217;s &#8220;screen&#8221;.</p>
<p>I fully intend to put BanateCAD on this little device.  The Beaglebone is good in that it represents a fairly constrained system.  It has a 4Gb micro SD card, and 256Mb of RAM.  It runs at 700Mhz.  I&#8217;m thinking this should be a beefy enough spec to run a simple 3D CAD modeling program such as BanateCAD.  Also, if I can run on this little device, then certainly I can run on any Android device.  I&#8217;ll see how it goes.</p>
<p>At any rate, things progress.  2D UI, 3D shapes, monkeys on typewriters&#8230;  Soon enough something interesting will pop out of this little exercise.</p>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/williamaadams.wordpress.com/396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/williamaadams.wordpress.com/396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/williamaadams.wordpress.com/396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/williamaadams.wordpress.com/396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/williamaadams.wordpress.com/396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/williamaadams.wordpress.com/396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/williamaadams.wordpress.com/396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/williamaadams.wordpress.com/396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/williamaadams.wordpress.com/396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/williamaadams.wordpress.com/396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/williamaadams.wordpress.com/396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/williamaadams.wordpress.com/396/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/williamaadams.wordpress.com/396/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/williamaadams.wordpress.com/396/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=williamaadams.wordpress.com&amp;blog=19598958&amp;post=396&amp;subd=williamaadams&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://williamaadams.wordpress.com/2012/02/06/assembling-bits-and-pieces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/04af4800b5b7667a0a64023d8c7a1dd5?s=96&#38;d=identicon&#38;r=PG" medium="image">
			<media:title type="html">williamaadams</media:title>
		</media:content>

		<media:content url="http://williamaadams.files.wordpress.com/2012/02/polybuilder.png" medium="image">
			<media:title type="html">PolyBuilder</media:title>
		</media:content>

		<media:content url="http://williamaadams.files.wordpress.com/2012/02/graphicarrow.png" medium="image">
			<media:title type="html">GraphicArrow</media:title>
		</media:content>

		<media:content url="http://williamaadams.files.wordpress.com/2012/02/tabshelf.png" medium="image">
			<media:title type="html">TabShelf</media:title>
		</media:content>
	</item>
	</channel>
</rss>
