<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Voyage Games</title>
    <link>http://www.voyagegames.com/blog/</link>
    <description>Game Development on a New Frontier</description>
    <language>en-us</language>
    <copyright>Devan Stormont</copyright>
    <lastBuildDate>Wed, 30 Jul 2008 03:51:06 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.0.7226.0</generator>
    <managingEditor>stormont@voyagegames.com</managingEditor>
    <webMaster>stormont@voyagegames.com</webMaster>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=4880f1f2-866e-488e-a46f-aaf789deb6e6</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,4880f1f2-866e-488e-a46f-aaf789deb6e6.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,4880f1f2-866e-488e-a46f-aaf789deb6e6.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=4880f1f2-866e-488e-a46f-aaf789deb6e6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Yes, I'm aware it's been quite a while
since my last post.  I've been caught up with moving to a <a href="http://www.cityofreno.com/">fun
new city</a>, working a <a href="http://www.pc-doctor.com/">fantastic new job</a>,
and buying a house.<br /><br />
I stumbled across a problem recently at work dealing with <a href="http://en.wikipedia.org/wiki/Singleton_pattern">singletons</a> and
cleaning up resources in C++.  There are two common methods of creating a singleton,
the first being not thread-safe:<br /><pre><br />
public class Singleton<br />
{<br />
public:<br />
   static Singleton* getInstance()<br />
   {<br />
      // The following static will be created once per thread!<br />
      static Singleton instance;<br />
      return &amp;instance;<br />
   }<br /><br />
private:<br />
   Singleton() {}<br />
};<br /></pre><br />
The second being (mostly) thread-safe:<br /><pre><br />
public class Singleton<br />
{<br />
public:<br />
   static Singleton* getInstance()<br />
   {<br />
      if (!m_instance)<br />
      {<br />
         m_instance = new Singleton();<br />
      }<br /><br />
      return m_instance;<br />
   }<br /><br />
private:<br />
   static Singleton* m_instance = NULL;<br />
   Singleton() {}<br />
};<br /></pre><br />
This second case provides a thread-friendly method of creating only a single instance
of the class.  (There is a small race condition in that the conditional may be
entered by one thread, then having another thread get swapped in before the instance
is actually created, but the time window for such a race condition is small enough
to generally be safe for use.)  However, sharper viewers may have noticed a small
problem:  The new'ed instance memory is never freed!  The intertubes are <a href="http://www.codeproject.com/KB/cpp/singletonrvs.aspx">ablaze
with debate</a> about this problem.<br /><br />
On the one hand, it seems to be common (and downright sloppy) practice to rely upon
the OS to free the memory when the application shuts down.  That's all fine and
dandy when you only work on a "modern" OS, but what if you're working on an embedded
system?  Or if your singleton is consuming system (or third-party) resources
that need to be released?  My take on the issue is that you should always clean
up after yourself; don't rely on the OS to pick up your mess.<br /><br />
So, what can we do about it?  Some people suggest creating some <a href="http://www.castle-cadenza.demon.co.uk/single.htm">sort
of dispose method</a> that the programmer is required to call before exiting the program. 
While it's a step in the right direction, this is still a bad idea.  For any
of you who work with more than a couple of programmers, you know how hard it is to
maintain a large code base on such "assumptions" of what you are supposed to do (nevermind
the problem of your Singleton class being part of a library that is referenced by
third-party applications).  But what can we do about it?<br /><br />
The solution is rather simple.  Make a class to clean up your mess:<br /><pre><br />
private class SingletonCleaner<br />
{<br />
   ~SingletonCleaner()<br />
   {<br />
      Singleton::getInstance()-&gt;dispose();<br />
   }<br />
}<br /><br />
public class Singleton<br />
{<br />
friend class SingletonCleaner;<br />
public:<br />
   static Singleton* getInstance()<br />
   {<br />
      if (!m_instance)<br />
      {<br />
         m_instance = new Singleton();<br />
      }<br /><br />
      return m_instance;<br />
   }<br /><br />
private:<br />
   static Singleton* m_instance = NULL;<br /><br />
   Singleton()<br />
   {<br />
      static SingletonCleaner cleaner;<br />
   }<br /><br />
   static void dispose()<br />
   {<br />
      if (m_instance)<br />
      {<br />
         // Clean up any other used resources
here as well<br />
         delete m_instance;<br />
         m_instance = NULL;<br />
      }<br />
   }<br /><br />
};<br /></pre><br />
What's going on here?  We're simply creating a static instance of a friendly
class in our Singleton constructor.  We don't have to worry about making the
cleaner instance thread-safe, as our Singleton will only enter it's constructor once
per process.  By making it static, it will survive until the process exits, at
which point its own destructor will be called.  This, in turn, will call the
private and static dispose() method of Singleton, cleaning up the Singleton instance
and freeing any other system resources it may have acquired.  Simple and easy!<br /><br />
Let me hear your thoughts, questions, concerns, and arguments.  I think it's
a pretty solid design, quick and easy, and self-maintaining.<br /><br />
(Bear with me if I've made any compiler errors.  I'm writing this up on a system
that does not currently have a C++ compiler.)<br /><br />
Cheers!<br /><br />
Devan<img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=4880f1f2-866e-488e-a46f-aaf789deb6e6" /></body>
      <title>Cleaning Up a Singleton in C++</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,4880f1f2-866e-488e-a46f-aaf789deb6e6.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/07/30/CleaningUpASingletonInC.aspx</link>
      <pubDate>Wed, 30 Jul 2008 03:51:06 GMT</pubDate>
      <description>Yes, I'm aware it's been quite a while since my last post.&amp;nbsp; I've been caught up with moving to a &lt;a href="http://www.cityofreno.com/"&gt;fun
new city&lt;/a&gt;, working a &lt;a href="http://www.pc-doctor.com/"&gt;fantastic new job&lt;/a&gt;,
and buying a house.&lt;br&gt;
&lt;br&gt;
I stumbled across a problem recently at work dealing with &lt;a href="http://en.wikipedia.org/wiki/Singleton_pattern"&gt;singletons&lt;/a&gt; and
cleaning up resources in C++.&amp;nbsp; There are two common methods of creating a singleton,
the first being not thread-safe:&lt;br&gt;
&lt;pre&gt;
&lt;br&gt;
public class Singleton&lt;br&gt;
{&lt;br&gt;
public:&lt;br&gt;
&amp;nbsp;&amp;nbsp; static Singleton* getInstance()&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // The following static will be created once per thread!&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static Singleton instance;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return &amp;amp;instance;&lt;br&gt;
&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
private:&lt;br&gt;
&amp;nbsp;&amp;nbsp; Singleton() {}&lt;br&gt;
};&lt;br&gt;
&lt;/pre&gt;
&lt;br&gt;
The second being (mostly) thread-safe:&lt;br&gt;
&lt;pre&gt;
&lt;br&gt;
public class Singleton&lt;br&gt;
{&lt;br&gt;
public:&lt;br&gt;
&amp;nbsp;&amp;nbsp; static Singleton* getInstance()&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!m_instance)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_instance = new Singleton();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return m_instance;&lt;br&gt;
&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
private:&lt;br&gt;
&amp;nbsp;&amp;nbsp; static Singleton* m_instance = NULL;&lt;br&gt;
&amp;nbsp;&amp;nbsp; Singleton() {}&lt;br&gt;
};&lt;br&gt;
&lt;/pre&gt;
&lt;br&gt;
This second case provides a thread-friendly method of creating only a single instance
of the class.&amp;nbsp; (There is a small race condition in that the conditional may be
entered by one thread, then having another thread get swapped in before the instance
is actually created, but the time window for such a race condition is small enough
to generally be safe for use.)&amp;nbsp; However, sharper viewers may have noticed a small
problem:&amp;nbsp; The new'ed instance memory is never freed!&amp;nbsp; The intertubes are &lt;a href="http://www.codeproject.com/KB/cpp/singletonrvs.aspx"&gt;ablaze
with debate&lt;/a&gt; about this problem.&lt;br&gt;
&lt;br&gt;
On the one hand, it seems to be common (and downright sloppy) practice to rely upon
the OS to free the memory when the application shuts down.&amp;nbsp; That's all fine and
dandy when you only work on a "modern" OS, but what if you're working on an embedded
system?&amp;nbsp; Or if your singleton is consuming system (or third-party) resources
that need to be released?&amp;nbsp; My take on the issue is that you should always clean
up after yourself; don't rely on the OS to pick up your mess.&lt;br&gt;
&lt;br&gt;
So, what can we do about it?&amp;nbsp; Some people suggest creating some &lt;a href="http://www.castle-cadenza.demon.co.uk/single.htm"&gt;sort
of dispose method&lt;/a&gt; that the programmer is required to call before exiting the program.&amp;nbsp;
While it's a step in the right direction, this is still a bad idea.&amp;nbsp; For any
of you who work with more than a couple of programmers, you know how hard it is to
maintain a large code base on such "assumptions" of what you are supposed to do (nevermind
the problem of your Singleton class being part of a library that is referenced by
third-party applications).&amp;nbsp; But what can we do about it?&lt;br&gt;
&lt;br&gt;
The solution is rather simple.&amp;nbsp; Make a class to clean up your mess:&lt;br&gt;
&lt;pre&gt;
&lt;br&gt;
private class SingletonCleaner&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp; ~SingletonCleaner()&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Singleton::getInstance()-&amp;gt;dispose();&lt;br&gt;
&amp;nbsp;&amp;nbsp; }&lt;br&gt;
}&lt;br&gt;
&lt;br&gt;
public class Singleton&lt;br&gt;
{&lt;br&gt;
friend class SingletonCleaner;&lt;br&gt;
public:&lt;br&gt;
&amp;nbsp;&amp;nbsp; static Singleton* getInstance()&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (!m_instance)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_instance = new Singleton();&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return m_instance;&lt;br&gt;
&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
private:&lt;br&gt;
&amp;nbsp;&amp;nbsp; static Singleton* m_instance = NULL;&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp; Singleton()&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; static SingletonCleaner cleaner;&lt;br&gt;
&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp; static void dispose()&lt;br&gt;
&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (m_instance)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // Clean up any other used resources
here as well&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; delete m_instance;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m_instance = NULL;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;br&gt;
};&lt;br&gt;
&lt;/pre&gt;
&lt;br&gt;
What's going on here?&amp;nbsp; We're simply creating a static instance of a friendly
class in our Singleton constructor.&amp;nbsp; We don't have to worry about making the
cleaner instance thread-safe, as our Singleton will only enter it's constructor once
per process.&amp;nbsp; By making it static, it will survive until the process exits, at
which point its own destructor will be called.&amp;nbsp; This, in turn, will call the
private and static dispose() method of Singleton, cleaning up the Singleton instance
and freeing any other system resources it may have acquired.&amp;nbsp; Simple and easy!&lt;br&gt;
&lt;br&gt;
Let me hear your thoughts, questions, concerns, and arguments.&amp;nbsp; I think it's
a pretty solid design, quick and easy, and self-maintaining.&lt;br&gt;
&lt;br&gt;
(Bear with me if I've made any compiler errors.&amp;nbsp; I'm writing this up on a system
that does not currently have a C++ compiler.)&lt;br&gt;
&lt;br&gt;
Cheers!&lt;br&gt;
&lt;br&gt;
Devan&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=4880f1f2-866e-488e-a46f-aaf789deb6e6" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,4880f1f2-866e-488e-a46f-aaf789deb6e6.aspx</comments>
      <category>C++</category>
    </item>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=a094b75b-3579-4121-ab88-e53d2fb85ae7</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,a094b75b-3579-4121-ab88-e53d2fb85ae7.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,a094b75b-3579-4121-ab88-e53d2fb85ae7.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=a094b75b-3579-4121-ab88-e53d2fb85ae7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I discovered today that <a href="http://code.google.com/p/monoxna/">there's
a port</a> for XNA to run on Mono (powered by OpenGL).  I'm not sure how up-to-date
the port is (there doesn't seem to be much recent activity in the group discussions),
but I may look into this once I pull my spare box out of storage (and load Linux on
it).  It's been a few years since I played with Mono and I'm guessing it's much
more stable now than when I first toyed with it (back in the days of .Net 1.1). 
I'd like the idea of being able to port my games over to Linux and Mac OS X as well.<br /><br />
But it looks to be an encouraging idea of a port!<br /><br />
Also, I ran across <a href="http://www.lua.inf.puc-rio.br/luanet/lua2il/">this compiler
for Lua to Microsoft IL</a>.  It may just solve <a href="http://www.voyagegames.com/blog/2008/04/18/LuaImplementationInC.aspx">those
problems</a> about using Lua on the XBOX 360.  Again, something to look into
and report back on.<br /><br />
Cheers!<br /><br />
Devan<br /><p></p><img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=a094b75b-3579-4121-ab88-e53d2fb85ae7" /></body>
      <title>XNA and Mono (and Converting Lua to IL)</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,a094b75b-3579-4121-ab88-e53d2fb85ae7.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/04/26/XNAAndMonoAndConvertingLuaToIL.aspx</link>
      <pubDate>Sat, 26 Apr 2008 02:01:09 GMT</pubDate>
      <description>I discovered today that &lt;a href="http://code.google.com/p/monoxna/"&gt;there's a port&lt;/a&gt; for
XNA to run on Mono (powered by OpenGL).&amp;nbsp; I'm not sure how up-to-date the port
is (there doesn't seem to be much recent activity in the group discussions), but I
may look into this once I pull my spare box out of storage (and load Linux on it).&amp;nbsp;
It's been a few years since I played with Mono and I'm guessing it's much more stable
now than when I first toyed with it (back in the days of .Net 1.1).&amp;nbsp; I'd like
the idea of being able to port my games over to Linux and Mac OS X as well.&lt;br&gt;
&lt;br&gt;
But it looks to be an encouraging idea of a port!&lt;br&gt;
&lt;br&gt;
Also, I ran across &lt;a href="http://www.lua.inf.puc-rio.br/luanet/lua2il/"&gt;this compiler
for Lua to Microsoft IL&lt;/a&gt;.&amp;nbsp; It may just solve &lt;a href="http://www.voyagegames.com/blog/2008/04/18/LuaImplementationInC.aspx"&gt;those
problems&lt;/a&gt; about using Lua on the XBOX 360.&amp;nbsp; Again, something to look into
and report back on.&lt;br&gt;
&lt;br&gt;
Cheers!&lt;br&gt;
&lt;br&gt;
Devan&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=a094b75b-3579-4121-ab88-e53d2fb85ae7" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,a094b75b-3579-4121-ab88-e53d2fb85ae7.aspx</comments>
      <category>XNA</category>
      <category>Mono</category>
      <category>Lua</category>
    </item>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=902aad28-f172-4517-b05e-a5109fd4ae00</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,902aad28-f172-4517-b05e-a5109fd4ae00.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,902aad28-f172-4517-b05e-a5109fd4ae00.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=902aad28-f172-4517-b05e-a5109fd4ae00</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <a href="http://en.wikipedia.org/wiki/Unit_test">Unit
testing</a> can create some problems when working with GUI applications, like an XNA
game.  How do you verify that something looks right when you're running automated
tests?<br /><br />
I've been working with building a simple game engine (so far I've got sprite rendering,
collision testing, quadtree culling, and a <a href="http://www.voyagegames.com/blog/2008/03/10/ExtendedXNAConsoleComponentWithLuaVirtualMachine.aspx">Lua
console</a>) and I bumped up against the unit test problem.  I'm afraid I attacked
it from the wrong direction.  I started with some automated tests, but I started
to devolve into using a patchwork system of visual (non-automated) unit testing. 
It's my plan this weekend to go about and fix the issues I've encountered.<br /><br />
Lessons learned:<br /><br />
You should generally only visually test (as an independent test) the elements of your
application that actually involve drawing.  I failed this by creating a test
that simply draws my sprite (a valid use of the test), then creating another that
updates the sprite's properties.  Updating properties and other non-visual changes
should be tested in automated tests; you'll be much more productive.  The only
time you should create a new visual test when you're testing something new about the
drawing process.  Assuming your automated tests passed okay (and that you are
testing for the right things), your visual tests shouldn't care about whether the
same code was done properly, only that the rendering looks okay.<br /><br />
It's just been one of those weeks where you start thinking along one line, get distracted,
and before you know it, you're lost in the urban wilderness.  :-P<br /><br />
Cheers!<br /><br />
Devan<br /><p></p><img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=902aad28-f172-4517-b05e-a5109fd4ae00" /></body>
      <title>XNA and Unit Testing</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,902aad28-f172-4517-b05e-a5109fd4ae00.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/04/26/XNAAndUnitTesting.aspx</link>
      <pubDate>Sat, 26 Apr 2008 01:54:27 GMT</pubDate>
      <description>&lt;a href="http://en.wikipedia.org/wiki/Unit_test"&gt;Unit testing&lt;/a&gt; can create some
problems when working with GUI applications, like an XNA game.&amp;nbsp; How do you verify
that something looks right when you're running automated tests?&lt;br&gt;
&lt;br&gt;
I've been working with building a simple game engine (so far I've got sprite rendering,
collision testing, quadtree culling, and a &lt;a href="http://www.voyagegames.com/blog/2008/03/10/ExtendedXNAConsoleComponentWithLuaVirtualMachine.aspx"&gt;Lua
console&lt;/a&gt;) and I bumped up against the unit test problem.&amp;nbsp; I'm afraid I attacked
it from the wrong direction.&amp;nbsp; I started with some automated tests, but I started
to devolve into using a patchwork system of visual (non-automated) unit testing.&amp;nbsp;
It's my plan this weekend to go about and fix the issues I've encountered.&lt;br&gt;
&lt;br&gt;
Lessons learned:&lt;br&gt;
&lt;br&gt;
You should generally only visually test (as an independent test) the elements of your
application that actually involve drawing.&amp;nbsp; I failed this by creating a test
that simply draws my sprite (a valid use of the test), then creating another that
updates the sprite's properties.&amp;nbsp; Updating properties and other non-visual changes
should be tested in automated tests; you'll be much more productive.&amp;nbsp; The only
time you should create a new visual test when you're testing something new about the
drawing process.&amp;nbsp; Assuming your automated tests passed okay (and that you are
testing for the right things), your visual tests shouldn't care about whether the
same code was done properly, only that the rendering looks okay.&lt;br&gt;
&lt;br&gt;
It's just been one of those weeks where you start thinking along one line, get distracted,
and before you know it, you're lost in the urban wilderness.&amp;nbsp; :-P&lt;br&gt;
&lt;br&gt;
Cheers!&lt;br&gt;
&lt;br&gt;
Devan&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=902aad28-f172-4517-b05e-a5109fd4ae00" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,902aad28-f172-4517-b05e-a5109fd4ae00.aspx</comments>
      <category>XNA</category>
    </item>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=b3ed9a64-13df-483a-947f-eab548a0c17b</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,b3ed9a64-13df-483a-947f-eab548a0c17b.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,b3ed9a64-13df-483a-947f-eab548a0c17b.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=b3ed9a64-13df-483a-947f-eab548a0c17b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I've been studying <a href="http://www.lua.org">Lua</a> more
in depth lately and I've been turning over a more difficult question in my head: 
How can you combine <a href="http://creators.xna.com">XNA</a>, with it's inherent
constrictions due to the XBOX 360, and a scripting language such as Lua?<br /><br />
The problem is that, at runtime, Lua uses JIT compiling of unmanaged C code. 
Unmanaged code can not be run on the XBOX 360 alongside XNA.  There is the possibility
of using C# scripting; however, the necessary functionality for building the scripts
on-the-fly are not included in the version of the .NET Framework running on the XBOX
360.  As described <a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=635814&amp;SiteID=1">here</a>,
it <i>is</i> possible to pre-compile your scripts and load them as an assembly.... 
But that is not particularly helpful for debugging/development.  Is there a solution
to this problem?<br /><br />
I've been tossing the idea around of writing a Lua-like implementation in C# that
would not need to be compiled; it would simply be parsed at runtime by an assembly
written for such a purpose.  However, there are two main concerns that have leapt
out to me so far:<br /><ul><li>
The obvious, performance issues.  It may be possible to work out a method for
this.  I haven't spent the time on this yet, however.</li><li>
Functions.  I could use delegates, but I'm not sure yet how to handle the variable
number of arguments into a function.</li></ul>
Of course, it may be better just to go with the pre-compiled C# scripts to begin with. 
Thoughts?<br /><br />
Cheers!<br /><br />
Devan<br /><p></p><img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=b3ed9a64-13df-483a-947f-eab548a0c17b" /></body>
      <title>Lua Implementation in C#</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,b3ed9a64-13df-483a-947f-eab548a0c17b.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/04/18/LuaImplementationInC.aspx</link>
      <pubDate>Fri, 18 Apr 2008 02:28:59 GMT</pubDate>
      <description>I've been studying &lt;a href="http://www.lua.org"&gt;Lua&lt;/a&gt; more in depth lately and I've
been turning over a more difficult question in my head:&amp;nbsp; How can you combine &lt;a href="http://creators.xna.com"&gt;XNA&lt;/a&gt;,
with it's inherent constrictions due to the XBOX 360, and a scripting language such
as Lua?&lt;br&gt;
&lt;br&gt;
The problem is that, at runtime, Lua uses JIT compiling of unmanaged C code.&amp;nbsp;
Unmanaged code can not be run on the XBOX 360 alongside XNA.&amp;nbsp; There is the possibility
of using C# scripting; however, the necessary functionality for building the scripts
on-the-fly are not included in the version of the .NET Framework running on the XBOX
360.&amp;nbsp; As described &lt;a href="http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=635814&amp;amp;SiteID=1"&gt;here&lt;/a&gt;,
it &lt;i&gt;is&lt;/i&gt; possible to pre-compile your scripts and load them as an assembly....&amp;nbsp;
But that is not particularly helpful for debugging/development.&amp;nbsp; Is there a solution
to this problem?&lt;br&gt;
&lt;br&gt;
I've been tossing the idea around of writing a Lua-like implementation in C# that
would not need to be compiled; it would simply be parsed at runtime by an assembly
written for such a purpose.&amp;nbsp; However, there are two main concerns that have leapt
out to me so far:&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
The obvious, performance issues.&amp;nbsp; It may be possible to work out a method for
this.&amp;nbsp; I haven't spent the time on this yet, however.&lt;/li&gt;
&lt;li&gt;
Functions.&amp;nbsp; I could use delegates, but I'm not sure yet how to handle the variable
number of arguments into a function.&lt;/li&gt;
&lt;/ul&gt;
Of course, it may be better just to go with the pre-compiled C# scripts to begin with.&amp;nbsp;
Thoughts?&lt;br&gt;
&lt;br&gt;
Cheers!&lt;br&gt;
&lt;br&gt;
Devan&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=b3ed9a64-13df-483a-947f-eab548a0c17b" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,b3ed9a64-13df-483a-947f-eab548a0c17b.aspx</comments>
      <category>XNA</category>
    </item>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=edcf158a-ef01-4b26-8531-aa0cf40f2efb</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,edcf158a-ef01-4b26-8531-aa0cf40f2efb.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,edcf158a-ef01-4b26-8531-aa0cf40f2efb.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=edcf158a-ef01-4b26-8531-aa0cf40f2efb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I've got the first attempt at a <a href="http://www.voyagegames.com/blog/2008/04/03/XNAAnd3dsMAXsParticleFlow.aspx">XNA
state-machine driven particle system</a> up and running, but it has some issues. 
Taking a second look at the way I integrated the particles into the more generic state
machine, I'm not happy with my implementation.<br /><br />
I think I'll keep the foundation of my state machine, but re-design the interface
with the particle system.  Right now, I'm having some problems differentiating
the different states of the independent particles because I built the "current" state
into the state machine, rather than into the particles themselves.  Thus, when
one particle changes states, they all change states.<br /><br />
This is an easy enough fix, but the way the particle system is tied to the state machine
bothers me.  I think I'll use the core state machine as a foundation class (I
think I designed it rather well as a generic state machine system), but I'll create
an inherited class that implements the particle system specifically.  That part
of my design wasn't so clean the first time around - that's what I get for trying
to rush and get it done in one sitting!<br /><br />
One problem I ran into with the generic state machine is how to modify settings within
the StateObject class that is passed into the StateMachine.  I ended up creating
a Hashtable of attributes within the StateObject.  In the State object, an attribute
can be set to change and is looked up by its identifier string.  It's a fairly
expandable system (attributes can easily be created and modified at will), but I'm
not 100% sure that I like it - there is some overhead with looking up into the Hashtable
for existing attributes, as well as not providing very elegant ways to process that
information.  Time will tell.  I may end up replacing it with a static system
within the various inherited implementations of the StateMachine (the ParticleStateMachine,
for instance, would know that the Particle objects have an "Age" attribute). 
On the other hand, I may decide that I'm adding so much to the Particles that the
Hashtable turns out to be handy!  We'll see.<br /><br />
Right now, the basic system looks like this:<br /><br />
StateMachine - Contains the different states, as well as system-wide settings (maximum
particles to create, how often to create them, etc. - specific examples for the ParticleStateMachine).<br />
State - Contains processing details about a specific state (changes attributes, performs
if less than/greater than checks, tells the StateObject to switch to another state
contained in the parent StateMachine, etc.).<br />
StateObject - A generic interface into an object being passed through the StateMachine. 
Each inherited implementation of the StateMachine will expand upon this as needed
(i.e., the ParticleStateObject will contain an "Age" attribute as mentioned previously).<br /><br />
Knowing that I'm going to be changing the implementation, I'll hold off on posting
code till I clean up the system a bit.  I wouldn't want just everyone to see
my messy coding!  ;-)<br /><br />
Cheers!<br /><br />
Devan<br /><p></p><img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=edcf158a-ef01-4b26-8531-aa0cf40f2efb" /></body>
      <title>State of a Particle</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,edcf158a-ef01-4b26-8531-aa0cf40f2efb.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/04/09/StateOfAParticle.aspx</link>
      <pubDate>Wed, 09 Apr 2008 02:49:29 GMT</pubDate>
      <description>I've got the first attempt at a &lt;a href="http://www.voyagegames.com/blog/2008/04/03/XNAAnd3dsMAXsParticleFlow.aspx"&gt;XNA
state-machine driven particle system&lt;/a&gt; up and running, but it has some issues.&amp;nbsp;
Taking a second look at the way I integrated the particles into the more generic state
machine, I'm not happy with my implementation.&lt;br&gt;
&lt;br&gt;
I think I'll keep the foundation of my state machine, but re-design the interface
with the particle system.&amp;nbsp; Right now, I'm having some problems differentiating
the different states of the independent particles because I built the "current" state
into the state machine, rather than into the particles themselves.&amp;nbsp; Thus, when
one particle changes states, they all change states.&lt;br&gt;
&lt;br&gt;
This is an easy enough fix, but the way the particle system is tied to the state machine
bothers me.&amp;nbsp; I think I'll use the core state machine as a foundation class (I
think I designed it rather well as a generic state machine system), but I'll create
an inherited class that implements the particle system specifically.&amp;nbsp; That part
of my design wasn't so clean the first time around - that's what I get for trying
to rush and get it done in one sitting!&lt;br&gt;
&lt;br&gt;
One problem I ran into with the generic state machine is how to modify settings within
the StateObject class that is passed into the StateMachine.&amp;nbsp; I ended up creating
a Hashtable of attributes within the StateObject.&amp;nbsp; In the State object, an attribute
can be set to change and is looked up by its identifier string.&amp;nbsp; It's a fairly
expandable system (attributes can easily be created and modified at will), but I'm
not 100% sure that I like it - there is some overhead with looking up into the Hashtable
for existing attributes, as well as not providing very elegant ways to process that
information.&amp;nbsp; Time will tell.&amp;nbsp; I may end up replacing it with a static system
within the various inherited implementations of the StateMachine (the ParticleStateMachine,
for instance, would know that the Particle objects have an "Age" attribute).&amp;nbsp;
On the other hand, I may decide that I'm adding so much to the Particles that the
Hashtable turns out to be handy!&amp;nbsp; We'll see.&lt;br&gt;
&lt;br&gt;
Right now, the basic system looks like this:&lt;br&gt;
&lt;br&gt;
StateMachine - Contains the different states, as well as system-wide settings (maximum
particles to create, how often to create them, etc. - specific examples for the ParticleStateMachine).&lt;br&gt;
State - Contains processing details about a specific state (changes attributes, performs
if less than/greater than checks, tells the StateObject to switch to another state
contained in the parent StateMachine, etc.).&lt;br&gt;
StateObject - A generic interface into an object being passed through the StateMachine.&amp;nbsp;
Each inherited implementation of the StateMachine will expand upon this as needed
(i.e., the ParticleStateObject will contain an "Age" attribute as mentioned previously).&lt;br&gt;
&lt;br&gt;
Knowing that I'm going to be changing the implementation, I'll hold off on posting
code till I clean up the system a bit.&amp;nbsp; I wouldn't want just everyone to see
my messy coding!&amp;nbsp; ;-)&lt;br&gt;
&lt;br&gt;
Cheers!&lt;br&gt;
&lt;br&gt;
Devan&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=edcf158a-ef01-4b26-8531-aa0cf40f2efb" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,edcf158a-ef01-4b26-8531-aa0cf40f2efb.aspx</comments>
      <category>XNA</category>
    </item>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=7a7c746d-7d20-4b64-95f6-b913e9d792be</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,7a7c746d-7d20-4b64-95f6-b913e9d792be.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,7a7c746d-7d20-4b64-95f6-b913e9d792be.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=7a7c746d-7d20-4b64-95f6-b913e9d792be</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Sitting <a href="http://www.voyagegames.com/blog/2008/04/04/MicrosoftsHereosHappenHereProductReleaseConference.aspx">bored </a>in
the Data Platform session of Microsoft's <a href="http://www.microsoft.com/heroeshappenhere/default.mspx">Heroes
Happen Here</a> conference, I began formulating how my <a href="http://www.voyagegames.com/blog/2008/04/03/XNAAnd3dsMAXsParticleFlow.aspx">state
machine-driven particle system for XNA</a> is going to be structured.  Here is
what I've come up with so far:<br /><br />
The <i>ParticleSystem </i>class:  This class will be the top-level system, containing
both the state machine that drives the system, as well as performance optimizations
for rendering (under the initial assumption that the particles will be rendered as
point sprites).  During creation of the ParticleSystem, a maximum number of particles
will be specified and a dynamic vertex buffer will be created to arrange for them. 
That's the basic rendering part.  The real joy of the system will be in the state
machine.....<br /><br />
Every elementary particle state machine will have three basic states: Creation, Processing,
and Death.  Every pass through an Update, the particle system will make each
particle start at it's current state and run through all the states it possibly can
until it is not directed to process another state.  At this point, it stops being
processed until the next pass, at which point it starts back at the top of the last
state it had entered.  To make this more clear, I'll demonstrate with some pseudocode
how the different states work:<br /><br />
Creation:<br />
  - Create the particle.<br />
  - Go to the Process state (and continue processing during this pass).<br /><br />
Process:<br />
  - Check if the particle has reached it's age limit:<br />
       - If so, go to the Death state (and continue
processing during this pass).<br />
  - If processing gets this far, the particle's still alive and may perform additional
manipulation.  Once it's out of actions to perform, it will stop being processed
for this pass and the next pass will start at the top of this state.<br /><br />
Death:<br />
  - Remove the particle (and stops processing).<br /><br />
I'll start pounding out a system for this over the weekend.  I may forgo the
point sprites for now in favor of just a quick and dirty normal sprite rendering centered
at the particle's location until I get the state machine working.<br /><br />
Cheers!<br /><br />
Devan<br /><p></p><img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=7a7c746d-7d20-4b64-95f6-b913e9d792be" /></body>
      <title>Anatomy of a State-Driven Particle System</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,7a7c746d-7d20-4b64-95f6-b913e9d792be.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/04/04/AnatomyOfAStateDrivenParticleSystem.aspx</link>
      <pubDate>Fri, 04 Apr 2008 04:13:21 GMT</pubDate>
      <description>Sitting &lt;a href="http://www.voyagegames.com/blog/2008/04/04/MicrosoftsHereosHappenHereProductReleaseConference.aspx"&gt;bored &lt;/a&gt;in
the Data Platform session of Microsoft's &lt;a href="http://www.microsoft.com/heroeshappenhere/default.mspx"&gt;Heroes
Happen Here&lt;/a&gt; conference, I began formulating how my &lt;a href="http://www.voyagegames.com/blog/2008/04/03/XNAAnd3dsMAXsParticleFlow.aspx"&gt;state
machine-driven particle system for XNA&lt;/a&gt; is going to be structured.&amp;nbsp; Here is
what I've come up with so far:&lt;br&gt;
&lt;br&gt;
The &lt;i&gt;ParticleSystem &lt;/i&gt;class:&amp;nbsp; This class will be the top-level system, containing
both the state machine that drives the system, as well as performance optimizations
for rendering (under the initial assumption that the particles will be rendered as
point sprites).&amp;nbsp; During creation of the ParticleSystem, a maximum number of particles
will be specified and a dynamic vertex buffer will be created to arrange for them.&amp;nbsp;
That's the basic rendering part.&amp;nbsp; The real joy of the system will be in the state
machine.....&lt;br&gt;
&lt;br&gt;
Every elementary particle state machine will have three basic states: Creation, Processing,
and Death.&amp;nbsp; Every pass through an Update, the particle system will make each
particle start at it's current state and run through all the states it possibly can
until it is not directed to process another state.&amp;nbsp; At this point, it stops being
processed until the next pass, at which point it starts back at the top of the last
state it had entered.&amp;nbsp; To make this more clear, I'll demonstrate with some pseudocode
how the different states work:&lt;br&gt;
&lt;br&gt;
Creation:&lt;br&gt;
&amp;nbsp; - Create the particle.&lt;br&gt;
&amp;nbsp; - Go to the Process state (and continue processing during this pass).&lt;br&gt;
&lt;br&gt;
Process:&lt;br&gt;
&amp;nbsp; - Check if the particle has reached it's age limit:&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; - If so, go to the Death state (and continue
processing during this pass).&lt;br&gt;
&amp;nbsp; - If processing gets this far, the particle's still alive and may perform additional
manipulation.&amp;nbsp; Once it's out of actions to perform, it will stop being processed
for this pass and the next pass will start at the top of this state.&lt;br&gt;
&lt;br&gt;
Death:&lt;br&gt;
&amp;nbsp; - Remove the particle (and stops processing).&lt;br&gt;
&lt;br&gt;
I'll start pounding out a system for this over the weekend.&amp;nbsp; I may forgo the
point sprites for now in favor of just a quick and dirty normal sprite rendering centered
at the particle's location until I get the state machine working.&lt;br&gt;
&lt;br&gt;
Cheers!&lt;br&gt;
&lt;br&gt;
Devan&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=7a7c746d-7d20-4b64-95f6-b913e9d792be" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,7a7c746d-7d20-4b64-95f6-b913e9d792be.aspx</comments>
      <category>XNA</category>
    </item>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=51c7421d-9f07-4f83-a598-150e298f2297</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,51c7421d-9f07-4f83-a598-150e298f2297.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,51c7421d-9f07-4f83-a598-150e298f2297.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=51c7421d-9f07-4f83-a598-150e298f2297</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">I had the opportunity to escape from work
today and attend Microsoft's <a href="http://www.microsoft.com/heroeshappenhere/default.mspx">Heroes
Happen Here</a> conference in Las Vegas.  For those unaware, it is essentially
a produce release conference that Microsoft is doing all over the country through
the end of June.  They are giving away free copies of Windows Server 2008, SQL
Server 2008, and Visual Studio 2008, well worth the attendance even without the speaking
sessions.  However, I did attend both the Data Platform (database-oriented) and
Developer sessions.<br /><br />
My thoughts:<br /><br />
Data Platform session:  There was really nothing that wowed me here.  Granted,
I'm a coder, but I have enough background in database management that it's not all
just noise to me.  However, I thought the presentation was poorly arranged and
delivered.  There seemed to be a couple of neat things (Resource Management,
for one), but I didn't see many demos.  Our speaker's delivery was fairly awful;
he was rather weak-voiced, wasn't very exciting to listen to, and would basically
stop talking when something didn't go right, which happened often.  He appeared
to be trying to run too much on his machine at once, which meant that all his demo
time was sucked up trying to get the various application windows to switch back and
forth.  The first two hours had a <i>lot</i> of dead air time that was making
me think I should like to go eat a real breakfast rather than listen to him saying
things like "it worked last night".  Skip this one if you have a chance.<br /><br />
Developer session:  Blew me away.  The speaker, Rob Bagby, was an incredible
speaker, keeping the audience riveted, cracking jokes, and flying through code samples
so fast it was almost difficult to follow him (almost).  He pretty much skipped
over the boring marketing-type presentation slides and would go straight to the meat. 
Plus, he demonstrated <i>many</i> different cool elements of .NET 3.5, including WPF,
LINQ, extending Office applications, and web service-driven solutions.  He actually
tied all of his demos into one continuous demonstration, building upon the system
throughout the entire four-hour talk.  It was amazing and I learned a lot of
new things, plus good reference material for replicating his process (he mentioned
a screencast of the talk would be on his <a href="http://www.robbagby.com">blog</a>). 
Despite his fast talk and fast coding, he did run out of time, provoking a mystery
organizer to grab a mic and announce "This is not God, but it is 4:30".  Rob
wrapped up nicely and left me excited to get home and play with my new software.<br /><br />
I highly encourage everyone to attend the Heroes event nearest to them, for the software,
and for the Developer talk if possible.<br /><br />
Cheers!<br /><br />
Devan<br /><p></p><img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=51c7421d-9f07-4f83-a598-150e298f2297" /></body>
      <title>Microsoft's Hereos Happen Here Product Release Conference</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,51c7421d-9f07-4f83-a598-150e298f2297.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/04/04/MicrosoftsHereosHappenHereProductReleaseConference.aspx</link>
      <pubDate>Fri, 04 Apr 2008 04:00:38 GMT</pubDate>
      <description>I had the opportunity to escape from work today and attend Microsoft's &lt;a href="http://www.microsoft.com/heroeshappenhere/default.mspx"&gt;Heroes
Happen Here&lt;/a&gt; conference in Las Vegas.&amp;nbsp; For those unaware, it is essentially
a produce release conference that Microsoft is doing all over the country through
the end of June.&amp;nbsp; They are giving away free copies of Windows Server 2008, SQL
Server 2008, and Visual Studio 2008, well worth the attendance even without the speaking
sessions.&amp;nbsp; However, I did attend both the Data Platform (database-oriented) and
Developer sessions.&lt;br&gt;
&lt;br&gt;
My thoughts:&lt;br&gt;
&lt;br&gt;
Data Platform session:&amp;nbsp; There was really nothing that wowed me here.&amp;nbsp; Granted,
I'm a coder, but I have enough background in database management that it's not all
just noise to me.&amp;nbsp; However, I thought the presentation was poorly arranged and
delivered.&amp;nbsp; There seemed to be a couple of neat things (Resource Management,
for one), but I didn't see many demos.&amp;nbsp; Our speaker's delivery was fairly awful;
he was rather weak-voiced, wasn't very exciting to listen to, and would basically
stop talking when something didn't go right, which happened often.&amp;nbsp; He appeared
to be trying to run too much on his machine at once, which meant that all his demo
time was sucked up trying to get the various application windows to switch back and
forth.&amp;nbsp; The first two hours had a &lt;i&gt;lot&lt;/i&gt; of dead air time that was making
me think I should like to go eat a real breakfast rather than listen to him saying
things like "it worked last night".&amp;nbsp; Skip this one if you have a chance.&lt;br&gt;
&lt;br&gt;
Developer session:&amp;nbsp; Blew me away.&amp;nbsp; The speaker, Rob Bagby, was an incredible
speaker, keeping the audience riveted, cracking jokes, and flying through code samples
so fast it was almost difficult to follow him (almost).&amp;nbsp; He pretty much skipped
over the boring marketing-type presentation slides and would go straight to the meat.&amp;nbsp;
Plus, he demonstrated &lt;i&gt;many&lt;/i&gt; different cool elements of .NET 3.5, including WPF,
LINQ, extending Office applications, and web service-driven solutions.&amp;nbsp; He actually
tied all of his demos into one continuous demonstration, building upon the system
throughout the entire four-hour talk.&amp;nbsp; It was amazing and I learned a lot of
new things, plus good reference material for replicating his process (he mentioned
a screencast of the talk would be on his &lt;a href="http://www.robbagby.com"&gt;blog&lt;/a&gt;).&amp;nbsp;
Despite his fast talk and fast coding, he did run out of time, provoking a mystery
organizer to grab a mic and announce "This is not God, but it is 4:30".&amp;nbsp; Rob
wrapped up nicely and left me excited to get home and play with my new software.&lt;br&gt;
&lt;br&gt;
I highly encourage everyone to attend the Heroes event nearest to them, for the software,
and for the Developer talk if possible.&lt;br&gt;
&lt;br&gt;
Cheers!&lt;br&gt;
&lt;br&gt;
Devan&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=51c7421d-9f07-4f83-a598-150e298f2297" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,51c7421d-9f07-4f83-a598-150e298f2297.aspx</comments>
      <category>.NET</category>
    </item>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=c8caa6a9-5ea2-4ba6-b111-7b5ffbec8457</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,c8caa6a9-5ea2-4ba6-b111-7b5ffbec8457.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,c8caa6a9-5ea2-4ba6-b111-7b5ffbec8457.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=c8caa6a9-5ea2-4ba6-b111-7b5ffbec8457</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">(I need to get in the habit of posting
when I don't have code to share.)<br /><br />
Something I've wanted to do for a while is develop a really flexible and highly configurable
particle system for XNA.  I've seen some solutions (samples, really) that are
rather hacked or not very extensible.  <a href="http://www.amazon.com/dp/0672329646?tag=wwwziggywarco-20&amp;camp=15041&amp;creative=373501&amp;link_code=as3">Microsoft
XNA Unleashed</a> had a solution that I thought was decently constructed and easy
to use with small projects, but was still fairly constrictive for what I'd like to
see.  Maybe I've just been pampered....<br /><br />
Several years ago, I ran across the <a href="http://en.wikipedia.org/wiki/3D_Studio_Max">Particle
Flow</a> system in <a href="http://usa.autodesk.com/adsk/servlet/index?siteID=123112&amp;id=5659302">3ds
MAX</a>.  It is an incredibly powerful system.  Using a state machine driven
system, it provides a drag-and-drop view for designing systems.  Modifiers such
as rotation and scale can be added at different states, if/else conditionals can be
added for branching, new spawning/death events can be added at will, and even collision
checks against objects in the 3ds scene.<br /><br />
So, I'm going to start designing a particle system similar to Particle Flow that can
be used with XNA and I'll be detailing my progress right here in my blog.  I
think to start with, I'll break the system down into these parts:<br /><ul><li>
The system:<br /></li><ul><li>
States<br /></li></ul><ul><li>
Rules</li><li>
Particles</li></ul></ul>
The state machine system will be broken into states (duh).  Each state will hold
a list of rules, which will consist of different attributes (rotation, scale, position),
actions (spawn, die), and hooks (attachments to [update: point] sprites) to begin
with.  Tentatively, conditionals will be added eventually, as will such things
as AI behaviors, attaching 3D objects, and bounding volume collision checks. 
The particles will be the physical objects in the system.  Each time a particle
is created, it will start at the top of the state machine specified during its creation. 
Some particles may spawned by other particles and may traverse the same state machine
or a different one.<br /><br />
That's what I'll start with and we'll see where this takes me!  Leave me a comment
if you have a suggestion or questions.<br /><br />
[Update:] I think I'll have a top-level particle system that will hold all of the
particles, as well as handle their updating and rendering through the use of dynamic
vertex buffers, as done in the <a href="http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Particle-3D-Sample.aspx">Creators
Club sample</a>.<br /><br />
Cheers!<br /><br />
Devan<br /><p></p><img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=c8caa6a9-5ea2-4ba6-b111-7b5ffbec8457" /></body>
      <title>XNA and 3ds MAX's Particle Flow</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,c8caa6a9-5ea2-4ba6-b111-7b5ffbec8457.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/04/03/XNAAnd3dsMAXsParticleFlow.aspx</link>
      <pubDate>Thu, 03 Apr 2008 02:20:30 GMT</pubDate>
      <description>(I need to get in the habit of posting when I don't have code to share.)&lt;br&gt;
&lt;br&gt;
Something I've wanted to do for a while is develop a really flexible and highly configurable
particle system for XNA.&amp;nbsp; I've seen some solutions (samples, really) that are
rather hacked or not very extensible.&amp;nbsp; &lt;a href="http://www.amazon.com/dp/0672329646?tag=wwwziggywarco-20&amp;amp;camp=15041&amp;amp;creative=373501&amp;amp;link_code=as3"&gt;Microsoft
XNA Unleashed&lt;/a&gt; had a solution that I thought was decently constructed and easy
to use with small projects, but was still fairly constrictive for what I'd like to
see.&amp;nbsp; Maybe I've just been pampered....&lt;br&gt;
&lt;br&gt;
Several years ago, I ran across the &lt;a href="http://en.wikipedia.org/wiki/3D_Studio_Max"&gt;Particle
Flow&lt;/a&gt; system in &lt;a href="http://usa.autodesk.com/adsk/servlet/index?siteID=123112&amp;amp;id=5659302"&gt;3ds
MAX&lt;/a&gt;.&amp;nbsp; It is an incredibly powerful system.&amp;nbsp; Using a state machine driven
system, it provides a drag-and-drop view for designing systems.&amp;nbsp; Modifiers such
as rotation and scale can be added at different states, if/else conditionals can be
added for branching, new spawning/death events can be added at will, and even collision
checks against objects in the 3ds scene.&lt;br&gt;
&lt;br&gt;
So, I'm going to start designing a particle system similar to Particle Flow that can
be used with XNA and I'll be detailing my progress right here in my blog.&amp;nbsp; I
think to start with, I'll break the system down into these parts:&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
The system:&lt;br&gt;
&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;
States&lt;br&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li&gt;
Rules&lt;/li&gt;
&lt;li&gt;
Particles&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
The state machine system will be broken into states (duh).&amp;nbsp; Each state will hold
a list of rules, which will consist of different attributes (rotation, scale, position),
actions (spawn, die), and hooks (attachments to [update: point] sprites) to begin
with.&amp;nbsp; Tentatively, conditionals will be added eventually, as will such things
as AI behaviors, attaching 3D objects, and bounding volume collision checks.&amp;nbsp;
The particles will be the physical objects in the system.&amp;nbsp; Each time a particle
is created, it will start at the top of the state machine specified during its creation.&amp;nbsp;
Some particles may spawned by other particles and may traverse the same state machine
or a different one.&lt;br&gt;
&lt;br&gt;
That's what I'll start with and we'll see where this takes me!&amp;nbsp; Leave me a comment
if you have a suggestion or questions.&lt;br&gt;
&lt;br&gt;
[Update:] I think I'll have a top-level particle system that will hold all of the
particles, as well as handle their updating and rendering through the use of dynamic
vertex buffers, as done in the &lt;a href="http://creators.xna.com/Headlines/developmentaspx/archive/2007/01/01/Particle-3D-Sample.aspx"&gt;Creators
Club sample&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;
Cheers!&lt;br&gt;
&lt;br&gt;
Devan&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=c8caa6a9-5ea2-4ba6-b111-7b5ffbec8457" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,c8caa6a9-5ea2-4ba6-b111-7b5ffbec8457.aspx</comments>
      <category>XNA</category>
    </item>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=bf9f68e8-b4e3-4d70-bc72-e6fd05938d8c</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,bf9f68e8-b4e3-4d70-bc72-e6fd05938d8c.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,bf9f68e8-b4e3-4d70-bc72-e6fd05938d8c.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=bf9f68e8-b4e3-4d70-bc72-e6fd05938d8c</wfw:commentRss>
      <title>Extended XNA Console Component with Lua Virtual Machine</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,bf9f68e8-b4e3-4d70-bc72-e6fd05938d8c.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/03/10/ExtendedXNAConsoleComponentWithLuaVirtualMachine.aspx</link>
      <pubDate>Mon, 10 Mar 2008 00:52:01 GMT</pubDate>
      <description>&lt;p class="MsoNormal"&gt;
I’ve made an extension to the &lt;a href="http://www.ziggyware.com/readarticle.php?article_id=163"&gt;Console
component sample&lt;/a&gt; posted on &lt;a href="http://www.ziggyware.com/"&gt;Ziggyware&lt;/a&gt;.&lt;span style=""&gt;&amp;nbsp;
It provides access to a Lua virtual machine through the console.&amp;nbsp; &lt;/span&gt;I believe
many of you budding (or experienced) XNA developers out there may find of use.&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
I’d like to thank Kevin Jurkowski for his Console sample, it gave me a fine starting
point from which to expand upon.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Also, I’d like to note
that I have updated his sample to run on XNA 2.0.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Second,
I’d like to thank Martin Echenique’s great example of adding Lua functions to a .NET
program using reflection, as detailed &lt;a href="http://www.gamedev.net/reference/articles/article2275.asp"&gt;here&lt;/a&gt;.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;I
wrote about this project in a &lt;a href="http://www.voyagegames.com/blog/2008/03/09/LuaNETInterface.aspx"&gt;previous
post&lt;/a&gt; and expanded upon it somewhat; this is the base Lua project that I utilize
for this sample.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;In this post, I will simply explain how
I integrated it into the Console component.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Download my sample project here: 
&lt;/p&gt;
&lt;a href="http://www.voyagegames.com/blog/code/ConsoleWithLua.zip"&gt;ConsoleWithLua.zip
(801.74 KB)&lt;/a&gt; 
&lt;p class="MsoNormal"&gt;
&lt;br&gt;
First, I added a Lua function, GetFPS, to the Game1 class.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;This
returns the FPS component added to our Game class.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Make
sure to include the LuaNetInterface assembly.&lt;o:p&gt;
&lt;br&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;font size="4"&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; LuaNetInterface;&lt;br&gt;
&lt;br&gt;
&lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
Gets the FPS component of the game.&lt;/span&gt;
&lt;br&gt;
&lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;br&gt;
[LuaFunctionAttribute(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"GetFPS"&lt;/span&gt;, &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Gets
the FPS component."&lt;/span&gt;)]&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; DrawableGameComponent
GetFPSComponent()&lt;br&gt;
{&lt;br&gt;
&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; FPS;&lt;br&gt;
}&lt;/span&gt;&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Then, I added a Lua virtual machine to the Game1 class.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;After
initializing it, I registered the functions in this class (the only function that
gets registered is our GetFPS() method).&amp;nbsp; When we create the ConsoleComponent
object, we pass our Lua virtual machine as an argument.
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
The Lua virtual machine for our game.&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt; LuaVirtualMachine
lua; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; Game1()
{ ... &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
Create our Lua virtual machine&lt;/span&gt; lua &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; LuaVirtualMachine();
lua.RegisterLuaFunctions(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;);
Components.Add(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; ConsoleComponent(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt;,
lua)); ... }&lt;/span&gt;&lt;/pre&gt;
These are all of our changes to the main Game1 class.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;I
also added a basic InputManager class, but it’s nothing out of the usual for usage
of keyboard input.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Just take a quick look at the class
if you need to; it’s fairly basic and self-explanatory.&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
On to the modified ConsoleComponent class.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;I added the
LuaInterface and LuaNetInterface assemblies to the class to access the needed Lua
objects.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; LuaInterface; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;using&lt;/span&gt; LuaNetInterface;&lt;/span&gt;&lt;/pre&gt;
We added a LuaVirtualMachine (Lua VM) object to the console class.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;It
stores the Lua VM object sent in through the object’s constructor.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;In
the Initialize() method, the Lua VM registers the functions in our class (note: we’ll
add these later).&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;I also created an instance of our input
manager class in the console class.&lt;p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt; LuaVirtualMachine
_lua; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;private&lt;/span&gt; InputManager
_inputManager; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; ConsoleComponent(Game
game, LuaVirtualMachine lua) : &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;base&lt;/span&gt;(game)
{ &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
If no Lua scripting virtual machine was passed in, create one&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (lua
== &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;)
lua &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; LuaVirtualMachine();
_lua &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; lua;
} &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;override&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; Initialize()
{ ... _inputManager &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; InputManager(Game);
.... }&lt;/span&gt;&lt;/pre&gt;
I added a ValidCharacter struct to the console class.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;It
specifies valid characters that can be entered (both normal characters and alternate
characters that are displayed when a Shift key is pressed).&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;I
defined the list of valid characters in the RegisterValidKeys() function, called from
within Initialize().&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;These are held within a hash table
for quick access.&lt;p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;internal&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;struct&lt;/span&gt; ValidCharacter
{ &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
The standard character to display.&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt; Character; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
The character to display when the Shift key is pressed.&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt; ShiftedCharacter; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
Creates a valid text characters structure.&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;param name="ch"&amp;gt;The standard character to display.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;param name="shiftCh"&amp;gt;The character to display when the Shift key is pressed.&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; ValidCharacter(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt; ch, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;char&lt;/span&gt; shiftCh)
{ Character &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; ch;
ShiftedCharacter &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; shiftCh;
} }&lt;/span&gt;&lt;/pre&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
I radically re-vamped the Update() method.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;First, I go
through all of the pressed keys from the input manager and update our command string
based upon the valid keys pressed that we have registered.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;bool&lt;/span&gt; shiftDown &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; _inputManager.CurrentKeyboardState.IsKeyDown(Keys.LeftShift)
|| _inputManager.PreviousKeyboardState.IsKeyDown(Keys.RightShift); Keys[] keysPressed &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; _inputManager.CurrentKeyboardState.GetPressedKeys(); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
No need to do further processing if no keys were pressed&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (keysPressed.Length
&amp;gt; 0) { &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
Process valid keys just pressed&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;foreach&lt;/span&gt; (Keys
key &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;in&lt;/span&gt; keysPressed)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (_validChars.ContainsKey(key)
&amp;amp;&amp;amp; _inputManager.PreviousKeyboardState.IsKeyUp(key)) { ValidCharacter ch &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; (ValidCharacter)_validChars[key]; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (shiftDown)
_command += ch.ShiftedCharacter; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; _command
+= ch.Character; } } }&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
I also added some functionality for scrolling up and down through our console log.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;This
is not critical to our changes, so I won’t discuss it in-depth, but you may find it
useful to look over.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;These update changes modify our Draw()
function a bit, but nothing serious.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The meat of the final
changes to Update() are where we enter a valid command and process it using the Lua
VM.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;From there on, Lua handles the rest!&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (_inputManager.JustPressed(Keys.Enter)
&amp;amp;&amp;amp; _command !&lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;""&lt;/span&gt;)
{ _logOffset &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0;
_log.Add(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;""&lt;/span&gt;);
_log.Add(_prefix &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; _command); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;try&lt;/span&gt; { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (_lua
!&lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;null&lt;/span&gt;)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (_lua.IsRunning)
_lua.Lua.DoString(_command); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; _log.Add(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"ERROR:
Lua Virtual Machine is no longer running."&lt;/span&gt;); } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;else&lt;/span&gt; _log.Add(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"ERROR:
Lua Virtual Machine has not been set."&lt;/span&gt;); } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;catch&lt;/span&gt; (LuaException
e) { _log.Add(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Lua
Error: "&lt;/span&gt; &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; e.Message);
} _command &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;""&lt;/span&gt;;
}&lt;/span&gt;&lt;/pre&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
I also updated the Draw() method a bit.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;I’ll reproduce
it here, but there should be nothing to surprise you there, outside of the inconsequential
display changes I mentioned earlier.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;override&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; Draw(GameTime
gameTime) { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (_active
== &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;true&lt;/span&gt;)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;float&lt;/span&gt; prefixHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; _font.MeasureString(_prefix).Y; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;float&lt;/span&gt; drawHeight; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
Saves a copy of the current screen into the texture. This allows the menus to be transparent&lt;/span&gt; Game.GraphicsDevice.ResolveBackBuffer(_texture); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
Without restoring the states properly, the alpha blending will cause some problems&lt;/span&gt; _spriteBatch.Begin(SpriteBlendMode.AlphaBlend,
SpriteSortMode.Immediate, SaveStateMode.SaveState); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
Draw the full background texture&lt;/span&gt; _spriteBatch.Draw(_texture, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; Rectangle(0,
0, Game.GraphicsDevice.Viewport.Width, Game.GraphicsDevice.Viewport.Height), Color.White); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
Draw transparent menu&lt;/span&gt; _spriteBatch.Draw(_texture, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; Rectangle(0,
0, _width, _height), &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; Rectangle(0,
0, _width, _height), Color.Gray); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
Draw command string&lt;/span&gt; _spriteBatch.DrawString(_font, _line &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; _prefix &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; _command, &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; Vector2(10f,
_height &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; (prefixHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;*&lt;/span&gt; 2f) &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; 4f),
Color.White); &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;//
Draw log&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;for&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; i &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0;
i &amp;lt; _log.Count; i++) { drawHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; _height &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; 34 &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; (prefixHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;*&lt;/span&gt; i) &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;-&lt;/span&gt; (prefixHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;*&lt;/span&gt; _log.Count) &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; (_logOffset &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;*&lt;/span&gt; prefixHeight); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (drawHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; prefixHeight
&amp;gt; 0 &amp;amp;&amp;amp; drawHeight &amp;lt; _validDisplayHeight &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;*&lt;/span&gt; prefixHeight)
{ _spriteBatch.DrawString(_font, _log[i], &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; Vector2(10f,
drawHeight), Color.Silver); } } _spriteBatch.End(); } &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;base&lt;/span&gt;.Draw(gameTime);
}&lt;/span&gt;&lt;/pre&gt;
Lastly, we add our Lua methods to the console class.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Most
of these are basic helper functions (help() displays a list of available functions,
helpcmd() gets you an in-depth description of an individual function, and print()
simply reprints the line you entered).&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;The most notable
function here is the ToggleComponent() method.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;This enables
or disables whatever component you pass to the function.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Within
the Lua commands, this is accessed as “Toggle”.&lt;o:p&gt;&lt;/o:p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;[LuaFunctionAttribute(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Toggle"&lt;/span&gt;, &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"Turns
a component on or off."&lt;/span&gt;, &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"The
component to toggle on or off."&lt;/span&gt;)] &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;void&lt;/span&gt; ToggleComponent(DrawableGameComponent
component) { component.Enabled &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; !component.Enabled;
component.Visible &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; !component.Visible;
}&lt;/span&gt;&lt;/pre&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
This constitutes all of the major changes to the sample.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Now
on to the fun part!&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Let’s use our magic!
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Run the program.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;You should see the FPS component displayed
in the bottom left hand corner.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Press the tilde (~) key
to open up the console.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Type “help()” to get a list of
available commands if you wish.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;Enter the following commands
into the console:&lt;o:p&gt;&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;/p&gt;
&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;fps &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; GetFPS()
Toggle(fps)&lt;/span&gt;&lt;/pre&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
At this point, you should see the FPS component disappear.&lt;span style=""&gt;&amp;nbsp; &lt;/span&gt;If
you want to re-enable it, re-enter the “Toggle(fps)” command.
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
I hope this gives you a start in easily adding Lua into your XNA programs and gives
you an easy interface into accessing the Lua VM!&lt;o:p&gt;
&lt;br&gt;
&lt;/o:p&gt;
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
&lt;br&gt;
Cheers!
&lt;/p&gt;
&lt;p class="MsoNormal"&gt;
Devan Stormont
&lt;/p&gt;
&lt;a href="http://www.voyagegames.com/blog/content/binary/ConsoleWithLua.zip"&gt;&lt;/a&gt;&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=bf9f68e8-b4e3-4d70-bc72-e6fd05938d8c" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,bf9f68e8-b4e3-4d70-bc72-e6fd05938d8c.aspx</comments>
      <category>.NET</category>
      <category>XNA</category>
    </item>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=e8ed76fe-29f7-4cd9-88fb-bd0093ad2a4d</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,e8ed76fe-29f7-4cd9-88fb-bd0093ad2a4d.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,e8ed76fe-29f7-4cd9-88fb-bd0093ad2a4d.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=e8ed76fe-29f7-4cd9-88fb-bd0093ad2a4d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
        </p>
A few years ago, I came across <a href="http://www.gamedev.net/reference/articles/article2275.asp">this
excellent article</a>, written by Martin Echenique and hosted on <a href="http://www.gamedev.net/">GameDev.net</a>. 
It discusses integrating <a href="http://www.lua.org/">Lua</a> scripting into .NET
projects by assigning custom attributes.  Using reflection, these custom attributes
can be examined at run-time, allowing Lua functions to be loaded into the virtual
machine dynamically.<br /><br />
I have taken Matin's project and modified it somewhat.  First, I added the capability
to sub-class Lua packages, allowing packages to contain other packages.<br /><br />
Second, I have made the Lua virtual machine (VM) non-static.  This was done for
two reasons.<br /><br />
First, I was having issues with exceptions being thrown due to reloading objects multiple
times into the VM.  This is caused by trying to register any functions/packages
with a name that has already been registered.  This is still an outstanding issue
to be corrected in a future version, but is avoidable if you only load the functions/packages
when you create the VM, then destroy the VM when you are finished with it, so it gets
re-built the next time you run it.  Not the most elegant solution, but it has
served my needs so far and I haven't gotten around to fixing this yet.<br /><br />
The second reason is that by creating separate virtual machines, you can restrict
different security access in your Lua functions.  For instance, you can have
a public Lua VM that is available to end users of your game/application to modify
interfaces or generate batch scripts.  In addition, you could have a separate
administrator VM that allows an admin to make network-wide changes to everyone's application,
or to provide game masters with the ability to change change events, spawn new creatures,
and fix bugged characters at run-time in your MMORPG.<br /><br />
These libraries are required to build the revised LuaNetInterface (LNI) project and
must be locally available to any projects that use LNI.  They do not need to
be referenced by any libraries other than LNI itself, but they do need to be copied
into your executable's local directory.<br /><br /><a href="http://www.voyagegames.com/blog/code/LuaLibraries_1.0.0.zip">LuaLibraries_1.0.0.zip
(652.09 KB)</a><br /><br />
These libraries come from the official Lua and LuaNet releases at <a href="http://luabinaries.luaforge.net/">http://luabinaries.luaforge.net/</a> and <a href="http://luaforge.net/projects/luainterface">http://luaforge.net/projects/luainterface</a>,
respectively.<br /><br />
Here is the code for the revised LuaNetInterface project.  Reference luaXX.dll
and LuaInterface.dll from the previous .zip into your build.<br /><br /><a href="http://www.voyagegames.com/blog/code/LuaNetInterface_0.1.0.zip">LuaNetInterface_0.1.0.zip
(11.64 KB)</a><br /><br /><br />
Cheers!<br /><br />
Devan Stormont<br /><br />
--<br /><br /><b>[UPDATE]</b>  The files for this project have been added to <a href="http://www.codeplex.com">Codeplex</a>. 
They can be accessed here:  <a href="http://www.codeplex.com/luanetinterface/">http://www.codeplex.com/luanetinterface/</a>. 
Future revisions to the project can be found there.<br /><img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=e8ed76fe-29f7-4cd9-88fb-bd0093ad2a4d" /></body>
      <title>Lua .NET Interface</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,e8ed76fe-29f7-4cd9-88fb-bd0093ad2a4d.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/03/09/LuaNETInterface.aspx</link>
      <pubDate>Sun, 09 Mar 2008 02:37:17 GMT</pubDate>
      <description>&lt;p&gt;
&lt;/p&gt;
A few years ago, I came across &lt;a href="http://www.gamedev.net/reference/articles/article2275.asp"&gt;this
excellent article&lt;/a&gt;, written by Martin Echenique and hosted on &lt;a href="http://www.gamedev.net/"&gt;GameDev.net&lt;/a&gt;.&amp;nbsp;
It discusses integrating &lt;a href="http://www.lua.org/"&gt;Lua&lt;/a&gt; scripting into .NET
projects by assigning custom attributes.&amp;nbsp; Using reflection, these custom attributes
can be examined at run-time, allowing Lua functions to be loaded into the virtual
machine dynamically.&lt;br&gt;
&lt;br&gt;
I have taken Matin's project and modified it somewhat.&amp;nbsp; First, I added the capability
to sub-class Lua packages, allowing packages to contain other packages.&lt;br&gt;
&lt;br&gt;
Second, I have made the Lua virtual machine (VM) non-static.&amp;nbsp; This was done for
two reasons.&lt;br&gt;
&lt;br&gt;
First, I was having issues with exceptions being thrown due to reloading objects multiple
times into the VM.&amp;nbsp; This is caused by trying to register any functions/packages
with a name that has already been registered.&amp;nbsp; This is still an outstanding issue
to be corrected in a future version, but is avoidable if you only load the functions/packages
when you create the VM, then destroy the VM when you are finished with it, so it gets
re-built the next time you run it.&amp;nbsp; Not the most elegant solution, but it has
served my needs so far and I haven't gotten around to fixing this yet.&lt;br&gt;
&lt;br&gt;
The second reason is that by creating separate virtual machines, you can restrict
different security access in your Lua functions.&amp;nbsp; For instance, you can have
a public Lua VM that is available to end users of your game/application to modify
interfaces or generate batch scripts.&amp;nbsp; In addition, you could have a separate
administrator VM that allows an admin to make network-wide changes to everyone's application,
or to provide game masters with the ability to change change events, spawn new creatures,
and fix bugged characters at run-time in your MMORPG.&lt;br&gt;
&lt;br&gt;
These libraries are required to build the revised LuaNetInterface (LNI) project and
must be locally available to any projects that use LNI.&amp;nbsp; They do not need to
be referenced by any libraries other than LNI itself, but they do need to be copied
into your executable's local directory.&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.voyagegames.com/blog/code/LuaLibraries_1.0.0.zip"&gt;LuaLibraries_1.0.0.zip
(652.09 KB)&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
These libraries come from the official Lua and LuaNet releases at &lt;a href="http://luabinaries.luaforge.net/"&gt;http://luabinaries.luaforge.net/&lt;/a&gt; and &lt;a href="http://luaforge.net/projects/luainterface"&gt;http://luaforge.net/projects/luainterface&lt;/a&gt;,
respectively.&lt;br&gt;
&lt;br&gt;
Here is the code for the revised LuaNetInterface project.&amp;nbsp; Reference luaXX.dll
and LuaInterface.dll from the previous .zip into your build.&lt;br&gt;
&lt;br&gt;
&lt;a href="http://www.voyagegames.com/blog/code/LuaNetInterface_0.1.0.zip"&gt;LuaNetInterface_0.1.0.zip
(11.64 KB)&lt;/a&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Cheers!&lt;br&gt;
&lt;br&gt;
Devan Stormont&lt;br&gt;
&lt;br&gt;
--&lt;br&gt;
&lt;br&gt;
&lt;b&gt;[UPDATE]&lt;/b&gt;&amp;nbsp; The files for this project have been added to &lt;a href="http://www.codeplex.com"&gt;Codeplex&lt;/a&gt;.&amp;nbsp;
They can be accessed here:&amp;nbsp; &lt;a href="http://www.codeplex.com/luanetinterface/"&gt;http://www.codeplex.com/luanetinterface/&lt;/a&gt;.&amp;nbsp;
Future revisions to the project can be found there.&lt;br&gt;
&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=e8ed76fe-29f7-4cd9-88fb-bd0093ad2a4d" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,e8ed76fe-29f7-4cd9-88fb-bd0093ad2a4d.aspx</comments>
      <category>.NET</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.voyagegames.com/blog/Trackback.aspx?guid=491c6a7e-36e0-4f6c-af88-bf3dcf12cde2</trackback:ping>
      <pingback:server>http://www.voyagegames.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.voyagegames.com/blog/PermaLink,guid,491c6a7e-36e0-4f6c-af88-bf3dcf12cde2.aspx</pingback:target>
      <dc:creator>Your DisplayName here!</dc:creator>
      <wfw:comment>http://www.voyagegames.com/blog/CommentView,guid,491c6a7e-36e0-4f6c-af88-bf3dcf12cde2.aspx</wfw:comment>
      <wfw:commentRss>http://www.voyagegames.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=491c6a7e-36e0-4f6c-af88-bf3dcf12cde2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
Well, here we go again.<br /><br />
I suppose I ought to introduce myself.  My name is Devan Stormont and I am a
firmware engineer and a game developer/hobbyist.  This blog is intended to be
primarily a source for me to discuss new developments in Microsoft's <a href="http://creators.xna.com/">XNA
game development framework</a> for Windows and the XBOX 360, as well as to post tutorials
as time permits.<br /><br />
Hopefully, I won't forget my pasword again!<br /><br />
Cheers!<br /><br />
Devan Stormont<br /><p></p><img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=491c6a7e-36e0-4f6c-af88-bf3dcf12cde2" /></body>
      <title>Blog Launch, Take Three</title>
      <guid isPermaLink="false">http://www.voyagegames.com/blog/PermaLink,guid,491c6a7e-36e0-4f6c-af88-bf3dcf12cde2.aspx</guid>
      <link>http://www.voyagegames.com/blog/2008/03/08/BlogLaunchTakeThree.aspx</link>
      <pubDate>Sat, 08 Mar 2008 22:20:44 GMT</pubDate>
      <description>
		Well, here we go again.&lt;br&gt;
&lt;br&gt;
I suppose I ought to introduce myself.&amp;nbsp; My name is Devan Stormont and I am a
firmware engineer and a game developer/hobbyist.&amp;nbsp; This blog is intended to be
primarily a source for me to discuss new developments in Microsoft's &lt;a href="http://creators.xna.com/"&gt;XNA
game development framework&lt;/a&gt; for Windows and the XBOX 360, as well as to post tutorials
as time permits.&lt;br&gt;
&lt;br&gt;
Hopefully, I won't forget my pasword again!&lt;br&gt;
&lt;br&gt;
Cheers!&lt;br&gt;
&lt;br&gt;
Devan Stormont&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.voyagegames.com/blog/aggbug.ashx?id=491c6a7e-36e0-4f6c-af88-bf3dcf12cde2" /&gt;</description>
      <comments>http://www.voyagegames.com/blog/CommentView,guid,491c6a7e-36e0-4f6c-af88-bf3dcf12cde2.aspx</comments>
      <category>General</category>
      <category>XNA</category>
    </item>
  </channel>
</rss>