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

<channel>
	<title>Forty-Two</title>
	<atom:link href="http://jameskilton.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://jameskilton.com</link>
	<description>On gaming, programming, everything!</description>
	<lastBuildDate>Tue, 23 Feb 2010 14:13:25 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How Rice Works</title>
		<link>http://jameskilton.com/2010/02/23/how-rice-works/</link>
		<comments>http://jameskilton.com/2010/02/23/how-rice-works/#comments</comments>
		<pubDate>Tue, 23 Feb 2010 14:13:25 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[everything!]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[rice]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://jameskilton.com/?p=227</guid>
		<description><![CDATA[Rice is one impressive piece of software. I highly doubt I could have written this from scratch (and for that I give Paul Brannan huge accolades for his work) but after working with and on this library for at least a year I probably could. Now that lead maintainership has been passed on to me, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://rice.rubyforge.org">Rice</a> is one impressive piece of software. I highly doubt I could have written this from scratch (and for that I give Paul Brannan huge accolades for his work) but after working with and on this library for at least a year I probably could. Now that lead maintainership has been passed on to me, I&#8217;d like to take some time to explain exactly how Rice works, how one can dive in and help develop this library, and what my plans are for the near future as I work to make Rice and the <a href="http://rbplusplus.rubyforge.org">rb++ suite</a>; a full and proper replacement for <a href="http://www.swig.org">SWIG</a> when wrapping C++ libraries into Ruby (if you&#8217;re wrapping a pure C library, I highly recommend <a href="http://github.com/ffi/ffi">Ruby-FFI</a>, though Rice will work).</p>
<p>So with that, I&#8217;m putting together this post to help clarify exactly how the various parts of Rice work together, how the entire process flows and more importantly helping anyone who&#8217;s wanting to learn and work on Rice with a solid starting point (or at least officially crooked). After reading this, anyone should be able to understand the various classes in Rice, and have an idea on where certain functionality lives when looking to add features, or address any bugs. So with that, we&#8217;ll start at the top.</p>
<p><span id="more-227"></span></p>
<h3>What is Rice?</h3>
<p>Rice is a wholly remarkable piece of software that takes complicated C++ classes, methods, types, etc and exposes them into Ruby using as simple an API as can be made. In short, you can take a C++ class such as:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Generator <span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
    Generator<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> seed<span style="color: #008000;">&#41;</span> <span style="color: #008080;">:</span> mSeed<span style="color: #008000;">&#40;</span>seed<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
    ~Generator<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
    <span style="color: #0000ff;">int</span> getRandomInt<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">4</span><span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span> <span style="color: #666666;">// chosen by dice roll, guaranteed to be random</span>
&nbsp;
    <span style="color: #0000ff;">void</span> setSeed<span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> seed<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span> mSeed <span style="color: #000080;">=</span> seed<span style="color: #008080;">;</span> <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
    <span style="color: #0000ff;">int</span> mSeed<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>and use in in Ruby seemlessly:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">g = <span style="color:#CC00FF; font-weight:bold;">Generator</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>
g.<span style="color:#9900CC;">random_int</span>          <span style="color:#008000; font-style:italic;"># =&gt; 4</span>
g.<span style="color:#9900CC;">seed</span> = <span style="color:#006666;">10</span></pre></div></div>

<p>through a very simple Rice wrapper Ruby extension:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">void</span> Init_generator<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   define_class<span style="color: #339933;">&lt;</span>Generator<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;Generator&quot;</span><span style="color: #009900;">&#41;</span>.
      <span style="color: #202020;">define_constructor</span><span style="color: #009900;">&#40;</span>Constructor<span style="color: #339933;">&lt;</span>Generator<span style="color: #339933;">,</span> int<span style="color: #339933;">&gt;</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>.
      <span style="color: #202020;">define_method</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;random_int&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>Generator<span style="color: #339933;">::</span><span style="color: #202020;">getRandomInt</span><span style="color: #009900;">&#41;</span>.
      <span style="color: #202020;">define_method</span><span style="color: #009900;">&#40;</span><span style="color: #ff0000;">&quot;seed=&quot;</span><span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>Generator<span style="color: #339933;">::</span><span style="color: #202020;">setSeed</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Were this class to be wrapped using Ruby&#8217;s C-API, every method on Generator, and even the constructor would have to be wrapped in a C method with calls into Ruby&#8217;s API (particularly Data_Make_Struct and Data_Get_Struct), very tedious and time consuming work, and at times quite error prone. So how does Rice make this tedious process as simple as four lines of code? C++ templates, and lots of them. We&#8217;ll go through each line here and dive into Rice itself to see what&#8217;s happening, but first, a quick word on Rice&#8217;s file naming convention.</p>
<h4>ipp, hpp, cpp, _defn &#8230; what??</h4>
<p>Because Rice is so template driven, most of the code cannot be pre compiled. That which can gets put into cpp files and ends up in librice.a, otherwise the core of Rice is template code generation which means only the code needed for the given extension is generated and compiled when building the extension itself. Given this, Rice still tries to strongly adhere to the separation of definition and implementation code. The definitions of classes are normally placed in [class_name]_defn.hpp, with the implementation placed in [class_name].ipp (to keep it separate from compilable code which gets placed in .cpp files). These two files are then combined in [class_name].hpp which is meant to be used in Rice extensions when including various pieces of functionality. When working inside of Rice and you need class definitions, you&#8217;ll want to use #include &#8220;[class_name]_defn.hpp&#8221; in most cases or risk running into circular dependencies and &#8220;already defined&#8221; compiler errors. Otherwise, when writing an extension using Rice, you&#8217;ll #include &#8220;[class_name].hpp&#8221; to ensure that all functionality is available for the extension.</p>
<p>As for the .mustache files, a lot of Rice&#8217;s template code is very repetitive and so instead of using complicated macros like Boost.Python does, Rice simply uses Ruby to generate the C++ code. Rice currently uses the <a href="http://defunkt.github.com/mustache/">Mustache</a> library for this and the code for this process can be seen in rice/code_gen.</p>
<h4>Defining a class: define_class</h4>
<p>To expose a C++ class into Ruby you first need to define the class, give it a name, and tell Rice which C++ type this class is (as a side note, you can create a Ruby class not hooked to a C++ type, just don&#8217;t give define_class a type). The prototypes of define_class are found in Data_Type_defn.hpp. The one we are particularly interested in is:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//! Define a new data class in the default namespace.</span>
<span style="color: #ff0000; font-style: italic;">/*! The class will have a base class of Object.
 *  \param T the C++ type of the wrapped class.
 *  \return the new class.
 */</span>
<span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span>
Rice<span style="color: #008080;">::</span><span style="color: #007788;">Data_Type</span><span style="color: #000080;">&lt;</span>T<span style="color: #000080;">&gt;</span> define_class<span style="color: #008000;">&#40;</span>
    <span style="color: #0000ff;">char</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">*</span> name<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Following the code into Data_Type.ipp, we can see the implementation of this method:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span>
<span style="color: #0000ff;">inline</span> Rice<span style="color: #008080;">::</span><span style="color: #007788;">Data_Type</span><span style="color: #000080;">&lt;</span>T<span style="color: #000080;">&gt;</span> Rice<span style="color: #008080;">::</span>
<span style="color: #007788;">define_class</span><span style="color: #008000;">&#40;</span>
    <span style="color: #0000ff;">char</span> <span style="color: #0000ff;">const</span> <span style="color: #000040;">*</span> name<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  Class c<span style="color: #008000;">&#40;</span>define_class<span style="color: #008000;">&#40;</span>name, rb_cObject<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  c.<span style="color: #007788;">undef_creation_funcs</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">return</span> Data_Type<span style="color: #000080;">&lt;</span>T<span style="color: #000080;">&gt;</span><span style="color: #008080;">::</span><span style="color: #0000ff;">template</span> bind<span style="color: #000080;">&lt;</span><span style="color: #0000ff;">void</span><span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>c<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>This method starts out creating a new Rice::Class with the given name, making it a subclass of Object (aka a top-level Class, emulating what Ruby itself does). A quick jump into Class.cpp shows us that define_class(char*, VALUE) simply forwards off to the Ruby API call rb_define_class, then takes the resulting VALUE and wraps it into a Rice::Class. </p>
<p>Rice then undefines #alloc and #initialize to prepare the class for Rice&#8217;s own type management (to be discussed later). The third line of this method is what actually binds this new class to the C++ type, binding it as a top-level class (Data_Type::bind is templated to the superclass type, so void in this case).</p>
<h4>Data_Type binding</h4>
<p>Probably the most confusing, and at the same time most important, aspect of Rice is how it manages C++ types and their link into the Ruby world. Every C++ class that&#8217;s to be wrapped into Ruby must be bound to a Ruby class which is done in the static method Data_Type::bind (implemented in Data_Type.ipp). This logic forms the core of how Rice does automatic conversions from C++ types to Ruby types and vis-versa. </p>
<p>To start, every Data_Type&lt;T&gt; has a static pointer to a Ruby class (Data_Type&lt;T&gt;::klass_). After checking that this C++ class isn&#8217;t already bound to another Ruby class, bind() registers the Ruby class with the Ruby GC and sets up a Caster between this C++ type and the Ruby class (to be discussed later). </p>
<p>We&#8217;ve now got our C++ class Generator properly bound to the Ruby class Generator and can continue.</p>
<h4>Adding methods to a class: define_method</h4>
<p>We&#8217;re now at the point where we can start wrapping the methods on our Generator class. We&#8217;ll follow the code execution of wrapping the method Generator::getRandomInt(), starting with Module::define_method found in Module_impl.hpp.</p>
<p><b>Quick side note:</b> Rice&#8217;s C++ API attempts to mimic Ruby&#8217;s top level Object structure, so the interplay between Data_Type, Module and Class can get confusing. Suffice it to say, class-based objects in Rice are all Rice::Module-s at the top, which then itself is a Rice::Object.</p>
<p>The specific define_method we&#8217;re interested in here is as follows:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">  <span style="color: #666666;">//! Define an instance method.</span>
  <span style="color: #ff0000; font-style: italic;">/*! The method's implementation can be any function or member
   *  function.  A wrapper will be generated which will use from_ruby&lt;&gt;
   *  to convert the arguments from ruby types to C++ types before
   *  calling the function.  The return value will be converted back to
   *  ruby by using to_ruby().
   *  \param name the name of the method
   *  \param func the implementation of the function, either a function
   *  pointer or a member function pointer.
   *  \param arguments the list of arguments of this function, used for
   *  defining default parameters (optional)
   *  \return *this
   */</span>
  <span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> Func_T<span style="color: #000080;">&gt;</span>
  Derived_T <span style="color: #000040;">&amp;</span> define_method<span style="color: #008000;">&#40;</span>
      Identifier name,
      Func_T func,
      Arguments<span style="color: #000040;">*</span> arguments <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The Rice::Arguments object has to do with the implementation of default argument definitions and I&#8217;ll get to that later.</p>
<p>This method is the beginning of where the true template craziness (genius? probably) happens. As a warning, if you are not comfortable with templates, the following is either going to confuse you, or it will open your eyes to a whole new level of possibilities in C++.</p>
<p>Rice works directly with Function Pointers and template definitions tailored to react to specific function pointer definitions to generate the appropriate code for properly wrapping C++ methods into Ruby. As a refresher, a C++ function pointer looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">ReturnType <span style="color: #008000;">&#40;</span>ClassName<span style="color: #008080;">::</span><span style="color: #000040;">*</span>methodName<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span>ArgT1, ArgT2, ...<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>so if we were to print out the function pointer of Generator::getRandomInt we would see:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> <span style="color: #008000;">&#40;</span>Generator<span style="color: #008080;">::</span><span style="color: #000040;">*</span>getRandomInt<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>This is what Func_T ends up being, a function pointer type. It can be a method with any return type, and any number and type of arguments, all handled by this one method. Looking at the implementation of this in Module_impl.ipp, we can see that execution is simply forwarded off to detail::define_method_and_auto_wrap given the Module/Class/Data_Type (*this), the name, the function pointer, any defined exception handler (this->handler) and the arguments object.</p>
<p>From this point, Rice needs to make a very important distinction on the method being wrapped: is it a class method, or a static method? The method Rice::detail::define_method_and_auto_wrap, defined in detail/define_method_and_auto_wrap.{hpp,ipp} uses Wrapped_Function classes, via wrap_function (detail/wrap_function.{hpp,ipp}) to make this distinction and to set up the final method object before finally jumping into Ruby&#8217;s C-API for finally exposing this method.</p>
<h4>Auto_{,Member}_Function_Wrapper</h4>
<p>Opening up detail/wrap_function.ipp you&#8217;ll see a very long file full of very repetitive method definitions. The key here is this method uses templates to match the passed in function pointer to one of Auto_Function_Wrapper (static functions) or Auto_Member_Function_Wrapper (a class instance method). Due to how Auto_{,Member}_Function_Wrapper works, wrap_function also has to have template specifications for functions with a return type and functions with void, as well as specifications to handle const and non-const function pointers.</p>
<p>To continue from here we need to understand how Rice actually hooks into Ruby. Glancing in detail/Auto_Function_Wrapper.hpp  we&#8217;ll find template-overload classes similar to what&#8217;s in wrap_function. These classes are the core that handle argument and return type management as well as taking execution from Ruby and passing it into the related C++ function or method. What we&#8217;re going to focus on here is the ::call static method, though we&#8217;ll get to the details of this method&#8217;s implementations later. </p>
<p>Ruby&#8217;s API will only take C-style functions with the signature VALUE(*)(&#8230;). The Auto_&#8230;_Wrapper classes are the glue that gives us a function with this signature:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">static</span> VALUE Auto_Function_Wrapper<span style="color: #008080;">::</span><span style="color: #007788;">call</span><span style="color: #008000;">&#40;</span><span style="color: #0000ff;">int</span> argc, VALUE <span style="color: #000040;">*</span>argv, VALUE self<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>If you&#8217;re familiar with Ruby&#8217;s C-API, then this signature should look familiar, it&#8217;s the -1 arity signature used when you want to support a variable number of arguments (in Rice&#8217;s case, default arguments). So how does a static function on a templated class work with an instance of this class to call the correct C++ method or function? It&#8217;s time to dive into detail/method_data.cpp, which defines define_method_with_data() as seen in the second part of define_method_and_auto_wrap() (Rice::protect is a wrapper around rb_protect to catch any exceptions and handle them gracefully).</p>
<h4>detail/method_data.cpp</h4>
<p>I&#8217;ll start this section with the comment block describing define_method_with_data():</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// Define a method and attach data to it.</span>
<span style="color: #666666;">// The method looks to ruby like a normal aliased CFUNC, with a modified</span>
<span style="color: #666666;">// origin class.</span>
<span style="color: #666666;">//</span>
<span style="color: #666666;">// How this works:</span>
<span style="color: #666666;">//</span>
<span style="color: #666666;">// To store method data and have it registered with the GC, we need a</span>
<span style="color: #666666;">// &quot;slot&quot; to put it in.  This &quot;slot&quot; must be recognized and marked by</span>
<span style="color: #666666;">// the garbage collector.  There happens to be such a place we can put</span>
<span style="color: #666666;">// data, and it has to do with aliased methods.  When Ruby creates an</span>
<span style="color: #666666;">// alias for a method, it stores a reference to the original class in</span>
<span style="color: #666666;">// the method entry.  The form of the method entry differs from ruby</span>
<span style="color: #666666;">// version to ruby version, but the concept is the same across all of</span>
<span style="color: #666666;">// them.</span>
<span style="color: #666666;">// </span>
<span style="color: #666666;">// In Rice, we make use of this by defining a method on a dummy class,</span>
<span style="color: #666666;">// then attaching that method to our real class.  The method is a real</span>
<span style="color: #666666;">// method in our class, but its origin class is our dummy class.</span>
<span style="color: #666666;">// </span>
<span style="color: #666666;">// When Ruby makes a method call, it stores the origin class in the</span>
<span style="color: #666666;">// current stack frame.  When Ruby calls into Rice, we grab the origin</span>
<span style="color: #666666;">// class from the stack frame, then pull the data out of the origin</span>
<span style="color: #666666;">// class.  The data item is then used to determine how to convert</span>
<span style="color: #666666;">// arguments and return type, how to handle exceptions, etc.</span></pre></div></div>

<p>Bear with me here as I still have a hard time keeping this straight in my mind. To help understand what exactly is going on here, I&#8217;ve made a graph showing all the relevant links between Rice, C++ and Ruby as made by this method.</p>
<p><img src="http://jameskilton.com/blog/wp-content/uploads/2010/02/method_data.png" alt="Graph showing how Rice hooks into Ruby" /></p>
<p>The steps define_method_with_data takes:</p>
<p>   1. Create a new class inside of the class we&#8217;re exposing (called the origin class).<br />
   2. Build a new two-element array that has [ 0xDA7A, VALUE pointer to Auto_..._Wrapper class]<br />
   3. Give the origin class an easily recognized name (which is also an invalid Ruby constant name, preventing it from every being accidentally used in Ruby code, but it prints out in object dumps on occasion).<br />
   4. Set this origin class to be FT_SINGLETON which hides it from the user<sup>1</sup>.<br />
   5. Set a hidden ivar on the class that&#8217;s the array built in step 2<br />
   6. Define a method on the origin class that links to Auto_&#8230;_Wrapper::call with the requested name</p>
<p>At this point we&#8217;ve got everything ready except for actually being able to call the method from Ruby. These next steps were hard to show right on the graph because Rice actually modifies the symbol table of the base class in question.</p>
<p>  7. Create an alias on the origin class that aliases the method to &#8220;dummy&#8221;<br />
  8. Find this new alias entry in the origin class&#8217; symbol table<br />
  9. Modify the symbol table of the base class to call &#8220;dummy&#8221; on the origin class on any call to the method being wrapped.</p>
<p>We&#8217;ve now got everything hooked up: we have the c-style function hooked into Ruby and we have a way to access the actual Auto_&#8230;_Wrapper class once call() gets called. Now, you may be asking why this is such a complicated process when it could be done with a simple rb_define_method on Auto_&#8230;_Wrapper::call(). The answer to this question is show in the image above, there&#8217;s data and information saved in this Auto_&#8230;_Wrapper object that Rice needs to be able to properly convert argument and return types, and handle any exceptions that may get thrown.</p>
<p>With that, we&#8217;re done with the wrapping and exposing path through Rice. Now it&#8217;s time to head back up the chain and see how Rice handles calls from Ruby and passing execution back up into C++.</p>
<h4>Auto_&#8230;_Wrapper::call()</h4>
<p>It&#8217;s time to take a detailed look at this method. In short, once execution enters this method, it&#8217;s now Rice&#8217;s job to convert VALUE arguments into the appropriate C++ types, execute the wrapped method / function, then do any required conversion of return values back to VALUEs for Ruby, while also making sure that any exceptions that throw along the way are properly caught and handled (an uncaught exception in C++ will give you a SegmentationFault or a BusError. Always fun to debug).</p>
<p>So, first things first, we need to get back the Auto_&#8230;_Wrapper object we saved when we wrapped this function. This is done with the detail::method_data() function, details of which are easily seen and understood in detail/method_data.cpp. With this we run our arguments list through rb_scan_args then run through each argument and check if there&#8217;s was a default set in the wrapper and if we should use it (Side note: the sanitize<> template is a no-op right now and can be ignored. It&#8217;s there to attempt to clean out any references or const arguments that may come in to get the base type, but this was causing crashes on other wrappers. For now I assume there&#8217;s a possibility of a small memory leak here related to reference types). Once all the types are converted it&#8217;s time to actually call the C++ method or function, and handle the return type. </p>
<p>The noticeable difference between Auto_Member_Function_Wrapper and Auto_Function_Wrapper is that Auto_Function_Wrapper has some special handling for the &#8220;self&#8221; parameter. This functionality is here to support the ability to wrap C functions that are written in an OO way, such as:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">Jukebox<span style="color: #339933;">*</span> newJukebox<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> play<span style="color: #009900;">&#40;</span>Jukebox<span style="color: #339933;">*</span> jukebox<span style="color: #339933;">,</span> Song<span style="color: #339933;">*</span> song<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> stop<span style="color: #009900;">&#40;</span>Jukebox<span style="color: #339933;">*</span> jukebox<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #993333;">void</span> addSong<span style="color: #009900;">&#40;</span>Jukebox<span style="color: #339933;">*</span> jukebox<span style="color: #339933;">,</span> Song<span style="color: #339933;">*</span> song<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// etc.</span></pre></div></div>

<p>Because of the special self handling of Auto_Function_Wrapper, these methods can be wrapped into a Jukebox class very simply:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">define_class<span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Jukebox&quot;</span><span style="color: #008000;">&#41;</span>.
  <span style="color: #007788;">define_method</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;initialize&quot;</span>, <span style="color: #000040;">&amp;</span>newJukebox<span style="color: #008000;">&#41;</span>.
  <span style="color: #007788;">define_method</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;play&quot;</span>, <span style="color: #000040;">&amp;</span>play<span style="color: #008000;">&#41;</span>.
  <span style="color: #007788;">define_method</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;stop&quot;</span>, <span style="color: #000040;">&amp;</span>stop<span style="color: #008000;">&#41;</span>.
  <span style="color: #007788;">define_method</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;add_song&quot;</span>, <span style="color: #000040;">&amp;</span>addSong<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Other than this, the two classes are identical in functionality.</p>
<h4>Constructor</h4>
<p>Because constructors aren&#8217;t accessible via normal function pointers, Rice has to implement special handling of wrapping class constructors for proper instantiation. This is done through the Rice::Constructor class and the define_constructor method. The path here is mostly equivalent to define_method. Opening up Constructor.{hpp,ipp} you can see the same ::call() static method, with a much simpler body. Every Ruby object has a free slot accessible through DATA_PTR. It&#8217;s in this slot that C++ class instances are saved and used for type conversions as described next. Constructor::call creates this object and saves it in DATA_PTR for later use.</p>
<h4>Default Arguments</h4>
<p>The code for handling and managing Default Arguments is pretty easy to read, but how the syntax work is definitely cause for confusion. Pulled from Boost.Python&#8217;s implementation of this exact feature, this functionality uses the comma operator to string together Rice::Arg objects into a single Arguments object that&#8217;s then passed into the Wrapped_Function object for that method. Due to the fact the comma operator doesn&#8217;t even come into play if there&#8217;s a single argument to a method, I was forced to copy some functionality around to make this feature work in all situations. So where you see two methods, one which takes a Rice::Arguments* and one which takes a Rice::Arg*, that&#8217;s what&#8217;s going on. I hope to clean this up drastically in the near future.</p>
<h4>to_ruby / from_ruby</h4>
<p>The last piece of Rice&#8217;s functionality is the type conversion system, exposed to the user through two methods: to_ruby(), which takes a C/C++ type and converts it to a VALUE, and from_ruby() which does the opposite. The signatures of these methods are simple:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span>
T from_ruby<span style="color: #008000;">&#40;</span>Rice<span style="color: #008080;">::</span><span style="color: #007788;">Object</span> x<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">template</span><span style="color: #000080;">&lt;</span><span style="color: #0000ff;">typename</span> T<span style="color: #000080;">&gt;</span>
Rice<span style="color: #008080;">::</span><span style="color: #007788;">Object</span> to_ruby<span style="color: #008000;">&#40;</span>T <span style="color: #0000ff;">const</span> <span style="color: #000040;">&amp;</span> x<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>For most basic and fundamental types, the to_/from_ruby implementations are very simple and can be seen in to_from_ruby.ipp, but this is only half of the story.</p>
<p>Rice&#8217;s real strength comes in handling custom-defined C++ types and seamlessly converting them from Ruby to C++ and back again, making sure to handle inheritance (both C++ &lt;=&gt; C++ and C++ &lt;=&gt; Ruby) appropriately. The core of this functionality is found in Data_Type::from_ruby in Data_Type.ipp, and in the Rice::Caster class found in detail/Caster.hpp, but it begins at the end of Data_Type::bind, which creates a new Caster for the newly bound type:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">  detail<span style="color: #008080;">::</span><span style="color: #007788;">Abstract_Caster</span> <span style="color: #000040;">*</span> base_caster <span style="color: #000080;">=</span> Data_Type<span style="color: #000080;">&lt;</span>Base_T<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">caster</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  caster_.<span style="color: #007788;">reset</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">new</span> detail<span style="color: #008080;">::</span><span style="color: #007788;">Caster</span><span style="color: #000080;">&lt;</span>T, Base_T<span style="color: #000080;">&gt;</span><span style="color: #008000;">&#40;</span>base_caster, klass<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  Data_Type_Base<span style="color: #008080;">::</span><span style="color: #007788;">casters</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>.<span style="color: #007788;">insert</span><span style="color: #008000;">&#40;</span>std<span style="color: #008080;">::</span><span style="color: #007788;">make_pair</span><span style="color: #008000;">&#40;</span>klass, caster_.<span style="color: #007788;">get</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span></pre></div></div>

<p>Caster is at the core very simple. It&#8217;s a class that enables Rice to build a tree of Casters that define how to cast from a Ruby type into a custom C++ type. The code above is simply building a new Caster linking the new type to the Ruby class, specifying any superclass type as needed, then registering this Caster with Rice&#8217;s Caster tree. From here it&#8217;s time to look at how Rice uses this Caster list in Data_Type::from_ruby() (which btw is called through ::convert() in detail/from_ruby.{hpp,ipp}).</p>
<p>In the case that the C++ type we want is exactly the Ruby type we&#8217;ve been given, casting is easy, make a new Data_Object for that type and get the pointer. If this doesn&#8217;t match, then we need to start heading up the inheritance heirarchy (rb_mod_ancestors) looking for the <strong>lowest</strong> class in the hierarchy bound in Rice, get it&#8217;s Caster and attempt to cast into C++. This functionality allows any depth of inheritance to work seamlessly in Rice.</p>
<h3>The Future of Rice</h3>
<p>Rice is currently a very capable library, and is being used successfully by a couple of projects, but it does have a long way to go to be the SWIG replacement (along with my rb++ suite) I want it to be. For the next release of Rice I&#8217;m current planning on the following work:</p>
<ul>
<li>Refactoring Auto_{,Member}_Function_Wrapper, Constructor, wrap_function, et.al. to be much simpler. Going to try to abstract out the actual method dispatch into a class like Auto_Functor_Wrapper which will handle all the to_/from_ruby and argument management magic.</li>
<li>Default arguments on Constructor. To do this Constructor needs to act more like an Auto_Function_Wrapper, and thus would be much easier to implement once the refactoring above is done.</li>
<li>Beginning into a def_helper (from Boost.Python) feature. Right now the implementation of default arguments is pretty messy. As I need to handle multiple arguments as well as a single argument, I&#8217;ve resorted to two define_method implementations to take these two cases. With some template magic, I can make it work with a single argument, as well as opening up a single place for call and return policy functionality, instead of multiple places that would be required today.</li>
</ul>
<p>As always, I&#8217;m available over Github messages / Issues, Email, comments here, or on Rice&#8217;s mailing list (rice AT librelist DOT com). I&#8217;ve also got a public tracker up on Pivotal: <a href="http://www.pivotaltracker.com/projects/48783">http://www.pivotaltracker.com/projects/48783</a>, but not sure how well that&#8217;s going to work for a free-time project such as this, though keeping a some-what strict time line is probably good for me, but I digress.</p>
<ol class="footnotes"><li id="footnote_0_227" class="footnote"><a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/336728">http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/336728</a></li></ol>]]></content:encoded>
			<wfw:commentRss>http://jameskilton.com/2010/02/23/how-rice-works/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Modern Christianity and Evolution</title>
		<link>http://jameskilton.com/2009/10/04/modern-christianity-and-evolution/</link>
		<comments>http://jameskilton.com/2009/10/04/modern-christianity-and-evolution/#comments</comments>
		<pubDate>Sun, 04 Oct 2009 22:12:14 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[everything!]]></category>
		<category><![CDATA[religion]]></category>
		<category><![CDATA[science]]></category>

		<guid isPermaLink="false">http://jameskilton.com/?p=144</guid>
		<description><![CDATA[I read a very disturbing statistic recently: 39% of Americans believe in Evolution. I found this surprisingly low number in a recent article about a new movie on Charles Darwin&#8217;s struggle with his life, his faith, and his Origin of Species here: 
http://www.telegraph.co.uk/news/worldnews/northamerica/usa/6173399/Charles-Darwin-film-too-controversial-for-religious-America.html
The article does make some very good points. In America, religion rules. This [...]]]></description>
			<content:encoded><![CDATA[<p>I read a very disturbing statistic recently: <strong>39% of Americans believe in Evolution</strong>. I found this surprisingly low number in a recent article about a new movie on Charles Darwin&#8217;s struggle with his life, his faith, and his <em>Origin of Species</em> here: </p>
<p><a href="http://www.telegraph.co.uk/news/worldnews/northamerica/usa/6173399/Charles-Darwin-film-too-controversial-for-religious-America.html">http://www.telegraph.co.uk/news/worldnews/northamerica/usa/6173399/Charles-Darwin-film-too-controversial-for-religious-America.html</a></p>
<p>The article does make some very good points. In America, religion rules. This can be seen especially today with the massive political upheaval of the recent elections, where we&#8217;ve got the &#8220;religious right&#8221; (mainly Christian, which I&#8217;m most familiar with) against the &#8220;secular left&#8221; fighting it out to the bitter end. What I have been trying to understand is why do less than half of all Americans believe in Evolution and how can we solve this? Is there a glaring and unrecoverable conflict between Evolution and Christianity? Is there any scientific evidence supporting either side? Is this an irrational, fearful reaction in the face of the unexpected and the new? And more importantly, why is it most Americans are so against Evolution while almost everyone else in the world has happily accepted the theory?</p>
<p><span id="more-144"></span></p>
<h3>What is Evolution?</h3>
<p>To make sure we&#8217;re on the same page, I want to specify the definition of &#8216;believe&#8217; here. I&#8217;m going with Webster&#8217;s second definition:</p>
<blockquote><p>
<strong>b</strong> : to accept as true, genuine, or real <ideals we believe in> <believes in ghosts>.&#8221;<sup>1</sup>,
</p></blockquote>
<p>When I talk about belief in Evolution, I&#8217;m simply talking about the acceptance of the scientific evidence in favor of Evolution, nothing religious.</p>
<p>Also, this post will be mostly on Biological Evolution, but will touch on the general idea of Young Earth and the Big Bang Theory.</p>
<p>Lets start with a quick primer on what Evolution actually is. First laid out in Charles Darwin&#8217;s <em>Origin of Species</em> in 1859, it&#8217;s the theory that states (paraphrased):</p>
<blockquote><p>
Biological evolution &#8230; is change in the properties of populations of organisms that transcend the lifetime of a single individual. The ontogeny of an individual is not considered evolution; individual organisms do not evolve. The changes in populations that are considered evolutionary are those that are inheritable via the genetic material from one generation to the next.<sup>2</sup>
</p></blockquote>
<p>The Theory of Evolution is the theory that species change over time. This change manifests itself in random mutations of the DNA defining an organism, which is passed down to offspring. If these mutations are harmful, the offspring don&#8217;t survive. If these mutations are neutral, or even beneficial to the organism, it survives to pass down these changes to it&#8217;s offspring, a process known as Survival of the Fittest. Following this process over thousands and even millions of years results in the diversity of life we see today. </p>
<p>Evolution today is used to explain a myriad of observations we&#8217;ve made in the biological world, from why there are hundreds of different species of pigeons, some slightly different, others completely different, yet definitely all pigeon, to why virii are impossible to vaccinate against and why cancer is such a brutal and difficult disease to fight.</p>
<p>So if Evolution is so successful in describing the biological we live in, why isn&#8217;t it more accepted here in the States, and in some cases attacked as a tool of Evil? Lets look at the Christian counter-argument known as Creationism.</p>
<h3>Creationism</h3>
<p>I used to be a Creationist. I was brought up in a rather conservative Christian home, and as the prevailing view of the Beginning of the Universe was Creationism, I naturally accepted and followed these beliefs. What follows is what I used to believe, and what I know about the movement.</p>
<p>Creationism has very simple roots: Genesis 1:1 (NIV).</p>
<blockquote><p>
In the beginning, God created the Heavens and the Earth.
</p></blockquote>
<p>What follows in verses two to the end of the chapter is a day-by-day account of what God created on each day, creating the entire Earth and everything on it, in six days. Creationists take this account literally, in that it took six days, as we define &#8220;day,&#8221; for God to create the Earth and all living things. They also believe that, as each day starts with &#8220;and God said&#8230;,&#8221; we all appeared here one day by the whim and will of God. Picture it as a blank sheet of paper, and start drawing animals, plants, and people. There was nothing, then there was everything.</p>
<p>Creationism&#8217;s biggest beef with Evolution is that Evolution seems to take God completely out of the picture. They commonly argue that Evolution says we&#8217;re &#8220;all here by accident&#8221; or &#8220;we&#8217;re a product of random chance.&#8221; They claim that because of this, Evolution goes directly against the Bible and thus (in the most extreme of cases) claim that Satan introduced Evolution into the scientists&#8217; minds to drive people away from Christ. Past this, the next most popular argument Creationists have against Evolution is the idea of a biological part being <em>unevolvable</em>, such as the eyeball, saying Evolution cannot be true because the eyeball is so complex that it has to either exist, or not exist, there is no half-way-point because, according to Evolution, the part would have been deemed bad and been phased out many generations ago.</p>
<h3>Where do I stand in this?</h3>
<p>I&#8217;m still a Christian, but I can no longer accept the Creationist claims. I owe this change-of-mind to two books: <em>Language of God</em> by Francis S. Collins and <em>Only a Theory</em> by Kenneth R. Miller. These books showed me that one can believe in Evolution, and still be a Christian. For anyone on the fence, these are great books to start with, and what follows is a quick run down of the major arguments <strong>for</strong> Evolution, and how they fit into the Christian world-view.</p>
<h3>Problems with Literal Bible Interpretations</h3>
<p>Christianity has a very poor track record when it comes to literal translations of the Bible. The most poignant, and relevant, example would be the stories of Copernicus and Galileo. They had the audacity to suggest that the Earth actually revolves around the Sun, contradicting a long standing teaching of the Church that the Earth is obviously the center of the Universe, because the Bible says so. We all know how that one turned out.</p>
<p>So following this, are Creationists making another mistake in taking the Bible literally? It would appear so, as the first two chapters of Genesis give two (arguably three) different creation accounts.</p>
<p>Genesis 1:1 &#8211; </p>
<blockquote><p>
In the beginning, God created the Heavens and the Earth.
</p></blockquote>
<p>Gensis 1:2-31 &#8211; </p>
<ul>
<li>Day 1 &#8211; Light and Dark</li>
<li>Day 2 &#8211; Land and Air</li>
<li>Day 3 &#8211; Sea and Land, Vegitation</li>
<li>Day 4 &#8211; Sun Moon and Stars</li>
<li>Day 5 &#8211; Water Animals and Birds</li>
<li>Day 6 &#8211; Land Animals and Man</li>
<li>Day 7 &#8211; Rest</li>
</ul>
<p>Genesis 2 &#8211; </p>
<ul>
<li>Earth and Water</li>
<li>Man</li>
<li>Vegitation</li>
<li>Animals</li>
<li>Woman</li>
</ul>
<p>While the comparison isn&#8217;t one-to-one, it&#8217;s easy to see that the order of events do not match up. If one is to attempt to take the Bible completely literally, this is a difficult contradiction to overcome. </p>
<p>Other arguments against literal interpretations of the Bible include discussions of the Hebrew writing style, mainly that they wrote more in poems and stories, and that the writers were less concerned about factual accounts, but as I am not knowledgeable in this I&#8217;ll leave it at that.</p>
<h3>Evolution&#8217;s &#8220;Random Chance&#8221;</h3>
<p>A major misconception that is proving very difficult to dispel is this idea that Evolution is a completely random process. This idea couldn&#8217;t be farther from the truth. Most Evolution nay-sayers completely forget about, or do not completely understand, the concept of Survival of the Fittest. All mutations are put through the most strenuous of tests: surviving and reproducing. When mutations pass this test, they get fully integrated into that gene pool and thrive. When the mutations fail the test, the organism(s) die off and the mutation is lost. The key point here is that <b>most mutations fail the test</b> due to the random nature of the process mixed with the very complex nature of DNA. </p>
<p>Due to this, were our evolutionary process to be done over, we most assuredly wouldn&#8217;t be exactly the same, but fish would still be shaped like they are (for efficient movement through water) and birds would have wings and probably hollow bones (for light-weight and moving through the air). The limits imposed on organisms by the world they live in are what drive evolution failures and successes, we are <strong>not</strong> the direct result of a few thousand random mutations, we are the result of a select subset of mutations that survived among the millions that allowed us to survive and thrive in our environment.</p>
<h3>Unevolvability</h3>
<p>Another common argument against Evolution is this idea of &#8220;unevolvability.&#8221; Creationists say that there are biological components (the eye and bacteria flagellum, to name two) that simply cannot have evolved because if a single part is missing, the component is useless. Useless parts, of course, are not favored in Evolution and thus, these parts should not exist. </p>
<p>This is actually a very true statement, which lends towards it&#8217;s strength in the Creationism world. However, there is a very pivotal assumption being made in this argument that Evolutionists have found to be a false one. This is the assumption that the parts of these components are <strong>only</strong> useful in the component they&#8217;re found in today. I&#8217;ll paraphrase the argument made in <em>Language of God</em> on how a bacteria&#8217;s flagellum actually did evolve to show this point.</p>
<p>Flagellum<sup>3</sup> is a collection of proteins used to propel bacteria through it&#8217;s environment in a rotating and/or whip-like manner. This is obviously a very complicated system, and if any of the many parts were to be missing, this locomotion would not be possible. This does not disprove Evolution though, because scientists have actually found parts of the flagellum being put to completely different uses<sup>4</sup>. For example, scientists have found a similar sub-construct being used as a secretion system.</p>
<p>I&#8217;ll admit this can be hard to understand for those of us who aren&#8217;t medically versed, but the point is this: the process of Evolution periodically takes a working and capable part, and mutates it to be something completely different. There is a lot we do not know about this process, but there is very strong evidence that biological constructs previously thought to be unevolvable are in fact a direct product of the evolution of various <strong>other</strong> constructs. For further information, here&#8217;s <a href="http://en.wikipedia.org/wiki/Evolution_of_the_eye">Wikipedia&#8217;s page on the evolution of the eye</a>.</p>
<h3>What Evolution Does Not Cover</h3>
<p>Given all this, there are still a few points that Evolution and Science in general does not yet have answers for. Among these are: </p>
<ol>
<li>How did life itself get started from a lifeless ball of rock orbiting a burning ball of gas?</li>
<li>The Big Bang. Something exploded, but where did <strong>that</strong> something come from?</li>
</ol>
<p>If we can figure out how to answer question #1, that would be the biggest breakthrough in all of Science: the ability to create life. This of course has some very far reaching moral, religions, and philosophical issues to work through, for if Man can create life from lifelessness, does that new life have rights like the rest of us? And what does that mean for Man itself, the ownership of a life form, etc?</p>
<p>As for question #2, I&#8217;m not sure if that question can be answered scientifically. As our viewing technology gets more sophisticated, we can see closer and closer to Time Zero, but how do you see anything before the Big Bang and is there anything to really see?</p>
<h3>What I Believe</h3>
<p>So given all this, how exactly does my Christianity work with current scientific knowledge? I believe that God used and continues to use Evolution in our Universe (even outside of the Earth? we may never know, but there&#8217;s nothing stopping God from such a thing). I believe that there had to be <strong>something</strong> that God created out of the nothing that was the Void, and that this thing eventually exploded in the Big Bang. </p>
<p>I believe that at a certain point in our Evolutionary history, God had on his hands beings that were advanced enough intellectually to understand Him and to worship Him. He embodied these beings with souls and named them Adam and Eve, starting what we know call the Human Race.</p>
<p>I believe that God gave us Science and infinitely inquisitive minds and as such it&#8217;s impossible for Science to in any way disprove the existence of God. We are simply learning about the world that He put us in. Any scientific finding that seems to go against my personal beliefs should be a cause of reflection on the discovery and on the beliefs I hold, not of immediate rejection of the science in question.</p>
<h3>Going Forward</h3>
<p>So what can I do to help fix the state of affairs in this country? I can educate people. Talk with friends, discuss with family, and encourage people to branch out. I&#8217;ve found that the best way for me to strengthen my faith is to doubt what I believe. With doubt comes uncertainty, and the mind hates uncertainty, and will crave resolution, which requires more information. When I can take this one further and can get other people to doubt their fundamental ideals, the discussions and debates that follow can only help to strengthen my beliefs. If I can get a few people to change their thinking, they&#8217;ll do the same with others.</p>
<p>I realize that fanatics and extremist will always exist, but the key to defeating them is to ignore them, to defuse their movements. If they&#8217;re yelling at people, and no-ones listening, they&#8217;ll eventually go away. This won&#8217;t be easy, but it&#8217;s necessary if this country is going to stay the leader in scientific advancements.</p>
<p>Evolution is the process God put in place to bring about life on this Earth.</p>
<ol class="footnotes"><li id="footnote_0_144" class="footnote"><a href="http://www.merriam-webster.com/dictionary/believe">http://www.merriam-webster.com/dictionary/believe</a></li><li id="footnote_1_144" class="footnote"><a href="http://www.talkorigins.org/faqs/evolution-definition.html">http://www.talkorigins.org/faqs/evolution-definition.html</a></li><li id="footnote_2_144" class="footnote"><a href="http://en.wikipedia.org/wiki/Flagellum">http://en.wikipedia.org/wiki/Flagellum</a></li><li id="footnote_3_144" class="footnote"><a href="http://en.wikipedia.org/wiki/Evolution_of_flagella">http://en.wikipedia.org/wiki/Evolution_of_flagella</a></li></ol>]]></content:encoded>
			<wfw:commentRss>http://jameskilton.com/2009/10/04/modern-christianity-and-evolution/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Game design lessons learned from World of Warcraft &#8211; Part 3: PvP and PvE</title>
		<link>http://jameskilton.com/2009/06/22/game-design-lessons-learned-from-world-of-warcraft-part-3-pvp-and-pve/</link>
		<comments>http://jameskilton.com/2009/06/22/game-design-lessons-learned-from-world-of-warcraft-part-3-pvp-and-pve/#comments</comments>
		<pubDate>Mon, 22 Jun 2009 20:58:58 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[game design]]></category>
		<category><![CDATA[gaming]]></category>

		<guid isPermaLink="false">http://jameskilton.com/?p=132</guid>
		<description><![CDATA[So I&#8217;ll be honest. I&#8217;ve had a huge rant building up for some time now on how Blizzard has royally screwed up WoW, and continues to do so, because they have a flawed look at how to balance PvP and PvE gameplay together.
I&#8217;m not going to write it because frankly, I&#8217;d never want to read [...]]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ll be honest. I&#8217;ve had a huge rant building up for some time now on how Blizzard has royally screwed up WoW, and continues to do so, because they have a flawed look at how to balance PvP and PvE gameplay together.</p>
<p>I&#8217;m not going to write it because frankly, I&#8217;d never want to read it. So I&#8217;ve condensed my point into three simple words:</p>
<h3><em>BALANCE</em></h3>
<h3><em>PVP</em></h3>
<h3><em>FIRST</em></h3>
<p>You simply cannot have a PvE game and add PvP on top of it. PvP is player skill, PvE is just numbers. One could go to the extreme and say that they can&#8217;t co-exist, but I&#8217;m not quite convinced this is true. Close, but not quite.</p>
]]></content:encoded>
			<wfw:commentRss>http://jameskilton.com/2009/06/22/game-design-lessons-learned-from-world-of-warcraft-part-3-pvp-and-pve/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe Flash 9 &amp; 10 Security Requirements</title>
		<link>http://jameskilton.com/2009/06/03/adobe-flash-9-10-security-requirements/</link>
		<comments>http://jameskilton.com/2009/06/03/adobe-flash-9-10-security-requirements/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 17:43:35 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[flash]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://jameskilton.com/?p=123</guid>
		<description><![CDATA[For those of us messing and working in Flash, the transition from Flash 8 through to Flash 10 have been rife with some major changes in the security model that allows a local Flash application to communicate with the outside world. Adobe, knowing that these are big changes, had its developers write pages, pages, and [...]]]></description>
			<content:encoded><![CDATA[<p>For those of us messing and working in Flash, the transition from Flash 8 through to Flash 10 have been rife with some major changes in the security model that allows a local Flash application to communicate with the outside world. Adobe, knowing that these are big changes, had its developers write <a href="http://www.adobe.com/devnet/flashplayer/articles/fplayer9_security.html">pages</a>, <a href="http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes.html">pages</a>, and <a href="http://www.adobe.com/devnet/flashplayer/articles/fplayer10_security_changes_02.html">pages</a> of documentation describing the where what how and why of these updates. </p>
<p>Problem is, it&#8217;s very hard to find the simple How-Tos for common situations in all this text. I spent many days scouring and tinkering to figure out the security solution to my application: a flash-based video viewer that would connect into a server and display Motion-JPEG frames that get streamed in. </p>
<p>Hopefully I&#8217;ll help save someone else the same hours of research and playing with this problem. My solution is such:</p>
<p>You first need up a simple service on the server you want to connect into that serves the crossdomain.xml content that defines your security policies.</p>
<p>I use a modified version of the service found here: <a href="http://www.lightsphere.com/dev/articles/flash_socket_policy.html">http://www.lightsphere.com/dev/articles/flash_socket_policy.html</a>. It&#8217;s updated to be a full Daemon process, so you need Proc::Daemon and Proc::PID::File installed. </p>
<p><script src="http://gist.github.com/123110.js"></script></p>
<p>Please note:</p>
<blockquote><p>
  &lt;site-control permitted-cross-domain-policies=&#8221;all&#8221;/&gt;
</p></blockquote>
<p>is the required addition to make this script work with Flash 10. Also, if you are worried about corporate firewalls blocking ports < 1000, simply change $port to something bigger, and add the following to your Flash client:</p>
<p><script src="http://gist.github.com/123117.js"></script></p>
<p>And you're good to go!</p>
]]></content:encoded>
			<wfw:commentRss>http://jameskilton.com/2009/06/03/adobe-flash-9-10-security-requirements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The GOP is precisely that&#8230;</title>
		<link>http://jameskilton.com/2009/05/27/the-gop-is-precisely-that/</link>
		<comments>http://jameskilton.com/2009/05/27/the-gop-is-precisely-that/#comments</comments>
		<pubDate>Wed, 27 May 2009 17:05:07 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[everything!]]></category>
		<category><![CDATA[politics]]></category>

		<guid isPermaLink="false">http://jameskilton.com/?p=107</guid>
		<description><![CDATA[&#8230; Grandiose and Old.
I have to say, I&#8217;m impressed. I was appalled at the atrocities perpetrated by the Bush administration, especially now as more information gets leaked out, but what&#8217;s going on now is mind-boggling at best, and at worst will decimate our country to where we&#8217;ll never recover. 
I refer, of course, to the [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; <b>Grandiose</b> and <b>Old</b>.</p>
<p>I have to say, I&#8217;m impressed. I was appalled at the atrocities perpetrated by the Bush administration, especially now as more information gets leaked out, but what&#8217;s going on now is mind-boggling at best, and at worst will decimate our country to where we&#8217;ll never recover. </p>
<p>I refer, of course, to the constant Republican QQ-ing and stonewalling about the choices the Obama administration is making. </p>
<p>Ever time I hear a prominent Republican talk on TV, on the radio, or read something on the Internet, I hear nothing but &#8220;waaah waaah I&#8217;m not getting my way anymore so I&#8217;m going to make life difficult for everyone who doesn&#8217;t see things my way, waaah waaah!&#8221; Ironic, this, as it&#8217;s the old-folks that are acting like 8 year olds who aren&#8217;t getting their way. </p>
<p>Aparently, some of these people need a refresher for what THEY had a hand in for the past EIGHT YEARS:</p>
<ul>
<li>DOUBLING our National Debt from ~$5 trillion to > $10 trillion</li>
<li>TWO wars, one justified one not</li>
<ul>
<li>The justified war in Afghanistan has been under-manned and assumed to be a &#8220;quick romp&#8221; to clear out the Taliban. Guess who&#8217;s back in power and even stronger?</li>
<li>The unjustified war in Iraq has destroyed the friendships we had with many countries around the world and has made even MORE people angry at America, leading to MORE terrorists. Iraq will fall into civil war between Sunni and Shiite as soon as we leave, just you watch.</li>
</ul>
<li>Decimation of personal liberties through acts like the Patriot Act and the Digital Millennium Copyright Act (What did Benjamin Franklin say about safety and liberty?)</li>
<li>Secret prison camps. Torture guidelines, Guantanamo Bay, Detention without Trial</li>
<li>&#8230; and who knows what else we&#8217;ll find out about in the coming years</li>
</ul>
<p>You guys have done a TERRIBLE job at running the country. Why should we trust, or even listen to, anything you guys have to say? You complain about lack of bi-partisanship, but then you don&#8217;t ever budge on your stances on bills. You guys are going to fight the new Supreme Court nominee (well, you&#8217;re probably still pissed that the exiting justice, <a href="http://en.wikipedia.org/wiki/David_Souter">David Souter</a>, made you guys look like idiots, but I digress), only because it&#8217;s Obama&#8217;s choice, not one from your party. </p>
<p>You guys might mostly disagree with Limbaugh, but come on, you are all working towards Limbaugh&#8217;s ultimate hope, the &#8220;failure&#8221; of Barack Obama. </p>
<p>Do you care about this country? Or do you only care about your personal &#8220;values&#8221; that get thrown out of the window anyway once you&#8217;re in power?</p>
<p>Congratulations on losing most of the young vote (like myself), that&#8217;s really going to help you get back into power in the future. Oh and grats on alienating the Hispanic vote, and most of the Black vote too. In fact, the women vote is going to the Democrats as well (thank you Limbaugh!)! If anything, the self-inflicted implosion of the GOP has been very entertaining to watch, but the delusion that the party is still as relevant now as it was 20 years ago is causing far more damage than good.</p>
<p>That said, there is a simple solution to this problem:</p>
<p>Grow Up.</p>
]]></content:encoded>
			<wfw:commentRss>http://jameskilton.com/2009/05/27/the-gop-is-precisely-that/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Game design lessons learned from World of Warcraft &#8211; Part 2</title>
		<link>http://jameskilton.com/2009/05/01/game-design-lessons-learned-from-world-of-warcraft-part-2/</link>
		<comments>http://jameskilton.com/2009/05/01/game-design-lessons-learned-from-world-of-warcraft-part-2/#comments</comments>
		<pubDate>Sat, 02 May 2009 00:20:43 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[game design]]></category>
		<category><![CDATA[gaming]]></category>

		<guid isPermaLink="false">http://jameskilton.com/?p=81</guid>
		<description><![CDATA[While Part 1 touched on abstract decisions affecting game design (and admittedly turned into a rant by the end, I&#8217;m kind of bad at that), part 2 here will focus on a few of Blizzard&#8217;s design decisions for WoW that we can learn from, and in Part 3 I&#8217;m going to touch on my ideas [...]]]></description>
			<content:encoded><![CDATA[<p>While <a href="http://jameskilton.com/2009/03/28/game-design-lessons-learned-from-world-of-warcraft-part-1/">Part 1</a> touched on abstract decisions affecting game design (and admittedly turned into a rant by the end, I&#8217;m kind of bad at that), part 2 here will focus on a few of Blizzard&#8217;s design decisions for WoW that we can learn from, and in Part 3 I&#8217;m going to touch on my ideas and observations on the game&#8217;s PvP and PvE.</p>
<p>Now of course I can&#8217;t list, or even think about, most of the design decisions that have helped towards making WoW the massive success that it is, but there are a few decisions, both good and bad, that have hit close to home for me, decisions that I have to work with or around every time I play. Were I to be on the WoW dev team, these are some of the things I&#8217;d be recommending.</p>
<p><span id="more-81"></span></p>
<h3>Stat Equality</h3>
<p>Wow is all about gear because character power advancement is built completely around the stats. The stats in WoW are Strength (STR), Agility (AGI), Intellect (INT), Spirit (SPI), and Stamina (STA), and they are directly related to how powerful your character is, or at least they should be. </p>
<p>In WoW, stat allocations over the various classes has always felt arbitrary, and frankly it&#8217;s a very complicated system that doesn&#8217;t need to be, which has lead to serious balancing issues between Melee and Caster classes that have yet to and probably will never be fixed. </p>
<p>For example, a Warrior gets two Attack Power (AP) (stat on which all abilities scale, thus directly related to damage output) per point of strength. Rogues and Hunters get their Attack Power from AGI (Hunter is considered a &#8220;Ranged Melee&#8221; class by the game). However, Mages get a 1% increase chance to crit every 60 INT along with 100 mana per one point of INT, while Spell Power comes purely from items themselves. SPI gives a DPS boost to Warlocks because of a skill that class has, but anyone else just gets mana regen (as of 3.1, SPI does give very small amounts of crit now too), making it a very important stat for some healing classes, but not all. </p>
<p>Confused yet?</p>
<p>When WoW first came out, progression for DPS caster classes, especially Mages, stopped hard at level 60. The game did not have the stat Spell Power, so the only benefits Mages got from gear was higher health in STA and more mana / crit with INT. The game <b>did</b> have Attack Power, so melee were outscaling Mages exponentially, who were simply able to cast spells longer. Since then, caster DPS scaling has been an issue. </p>
<p>A much, much simpler system of making INT behave like STR would have gone a long way towards simplifying scaling from the beginning. If your game is going to have stats, make them consistent. Arbitrary decisions will lead to big problems, and sooner than you&#8217;d expect.</p>
<h3>All stats need to scale to appropriate levels and then some</h3>
<p>Following the above, make sure those stat decisions actually do scale into the foreseeable future. It is surprising to see a Blizzard lead designer explicitly say that they check the scaling of all classes only through to the next patch or expansion (which ever is nearer) and fix problems as they crop up. I can&#8217;t begin to imagine the amount of work that would have been saved had more care been taking at the beginning to make stats less complicated and properly scale for longer than just the next tier of gear.</p>
<h3>Character resource decisions can make or break balancing from the beginning</h3>
<p>The Death Knight uses a Runes and Runic Power resource system. The DK expends Runes on certain attacks, those attacks build Runic Power, from which the DK then uses other abilities that deplete the Runic Power. Any rotation a DK choses can be kept going forever. </p>
<p>Rogue energy is always refilling and simply serves to put a &#8220;cast time&#8221; on rogue abilities. Rogues can fight forever. </p>
<p>Warriors have Rage. Warriors gain Rage when they hit with white attacks or get hit. They then use this Rage to use special attacks. This system, while dependent on Rage income, can be kept going forever.</p>
<p>Casters use Mana, and can run out. They cannot fight forever. This is a very poor decision that has caused numerous problems with fight balancing, character balancing, and makes PvPing with these classes especially difficult.</p>
<p>Healers are not included in this. Healers running out of mana is a very valid &#8217;soft enrage&#8217; system to put on a raid. If a healer could go forever, then any fight is easily trivialized.</p>
<p>Warhammer got it right: every class uses a refilling energy system like the WoW Rogue. </p>
<h3>Incentives drive player inclusion</h3>
<p>Converse to that, disinsentives do drive players to not participate. When you&#8217;re dealing with a group of people, it really is quite easy to predict what that group will do. For example, by adding Battlegrounds and gear rewards for doing those battlegrounds, Blizzard completely destroyed World PvP. Why spend hours ganking people in the world when at least you get rewards for doing it in a Battleground?</p>
<h3>Achievements!</h3>
<p>Nothing has refreshed WoW like Achievements. Giving people the ability to show off their exploits, to be rewarded for taking on hard content, or for committing acts of crazy mindlessness (see: <a href="http://www.wowhead.com/?achievement=1682">The Loremaster</a>) helps keep players busy with tasks they otherwise have not done, along with just straight keeping them in-game and paying. Nothing helps a game&#8217;s population than more ways for people to show off what they&#8217;ve done.</p>
<h3>World Events</h3>
<p>Special time-specific events are always a big hit for players, but they usually are very time consuming to implement and it&#8217;s rare that every player gets to participate in said events. WoW&#8217;s system of having set events that happen throughout the year, every year, help to make sure that as many players as possible can experience this specially crafted content. Hooking achievements to world events was of course a brilliant idea, and has made players actually look forward to the next event, preparing and planning.</p>
<p>Mistakes have been made, but it cannot be denied that Blizzard hit on the recipe for hugely successful MMO. It&#8217;s easy to get into, easy to play, difficult to master, and full of content for everyone, from the PvPer to the PvEer to the players that just hang out with friends. There&#8217;s a lot to be learned from this game, and I&#8217;m sure designers will be using WoW as a template for many years to come. </p>
<p>Part 3 will be my (hopefully not to angry) rant on the decision Blizzard made to try to turn a PvE game into a PvP game, and the constant balancing work that has and is going into both sides of this game.</p>
]]></content:encoded>
			<wfw:commentRss>http://jameskilton.com/2009/05/01/game-design-lessons-learned-from-world-of-warcraft-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Embedding IRB into your Ruby application</title>
		<link>http://jameskilton.com/2009/04/02/embedding-irb-into-your-ruby-application/</link>
		<comments>http://jameskilton.com/2009/04/02/embedding-irb-into-your-ruby-application/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 11:55:54 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://jameskilton.com/?p=71</guid>
		<description><![CDATA[A feature I realized would be very helpful to have in rb++ is a debugging console. Basically, I wanted the ability to drop into an irb session and have available to me the internals of rb++ and rbgccxml, all set up for the sources I&#8217;ve specified for the given extension. 
Turns out, this is a [...]]]></description>
			<content:encoded><![CDATA[<p>A feature I realized would be very helpful to have in <a href="http://github.com/jameskilton/rbpluslpus">rb++</a> is a debugging console. Basically, I wanted the ability to drop into an irb session and have available to me the internals of rb++ and rbgccxml, all set up for the sources I&#8217;ve specified for the given extension. </p>
<p>Turns out, this is a lot harder to figure out than it would initially seem. The irb code is quite complex and nothing there is documented in any way shape or form. Also, searches around the Internet came back with results that were some six years old, and while helpful, did not pertain to my particular case. </p>
<p>Then I remembered that <a href="http://rubyforge.org/projects/ruby-debug/">ruby-debug</a> does exactly what I&#8217;m looking for. A quick glance in that code got me the code snippet I needed.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'irb'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">module</span> IRB <span style="color:#008000; font-style:italic;"># :nodoc:</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">start_session</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">binding</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">unless</span> <span style="color:#0066ff; font-weight:bold;">@__initialized</span>
      args = ARGV
      ARGV.<span style="color:#9900CC;">replace</span><span style="color:#006600; font-weight:bold;">&#40;</span>ARGV.<span style="color:#9900CC;">dup</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      IRB.<span style="color:#9900CC;">setup</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">nil</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      ARGV.<span style="color:#9900CC;">replace</span><span style="color:#006600; font-weight:bold;">&#40;</span>args<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#0066ff; font-weight:bold;">@__initialized</span> = <span style="color:#0000FF; font-weight:bold;">true</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    workspace = WorkSpace.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">binding</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    irb = Irb.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>workspace<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
    <span style="color:#0066ff; font-weight:bold;">@CONF</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:IRB_RC</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">call</span><span style="color:#006600; font-weight:bold;">&#40;</span>irb.<span style="color:#9900CC;">context</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0066ff; font-weight:bold;">@CONF</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:IRB_RC</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#0066ff; font-weight:bold;">@CONF</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:MAIN_CONTEXT</span><span style="color:#006600; font-weight:bold;">&#93;</span> = irb.<span style="color:#9900CC;">context</span>
&nbsp;
    <span style="color:#CC0066; font-weight:bold;">catch</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:IRB_EXIT</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      irb.<span style="color:#9900CC;">eval_input</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And it&#8217;s use is quite simple. When you want to drop into an irb session, you simply do</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">IRB.<span style="color:#9900CC;">start_session</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">binding</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>and you will have a code prompt with all data available at your finger-tips. </p>
<p><a href="http://github.com/jameskilton/rbplusplus/commit/ebb28d290ef6c0e2b7a71032f14a20c9e5150e26">See the related rb++ commit</a></p>
<p>You use this feature in rb++ as follows:</p>
<p><code><br />
ruby your_extension_file.rb console<br />
</code></p>
<p>From there, start playing around with the parsed source tree using either @parser or self.namespace to get started.</p>
]]></content:encoded>
			<wfw:commentRss>http://jameskilton.com/2009/04/02/embedding-irb-into-your-ruby-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Game design lessons learned from World of Warcraft &#8211; Part 1</title>
		<link>http://jameskilton.com/2009/03/28/game-design-lessons-learned-from-world-of-warcraft-part-1/</link>
		<comments>http://jameskilton.com/2009/03/28/game-design-lessons-learned-from-world-of-warcraft-part-1/#comments</comments>
		<pubDate>Sat, 28 Mar 2009 14:44:53 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[game design]]></category>
		<category><![CDATA[gaming]]></category>

		<guid isPermaLink="false">http://jameskilton.com/blog/?p=4</guid>
		<description><![CDATA[Given that I love gaming, and I love programming, it&#8217;s only natural that I put the two together. Now while I haven&#8217;t yet gotten deeply into game development and design, I have become acutely aware of design decisions made in the games that I play, and I like to take mental notes of what works, [...]]]></description>
			<content:encoded><![CDATA[<p>Given that I love gaming, and I love programming, it&#8217;s only natural that I put the two together. Now while I haven&#8217;t yet gotten deeply into game development and design, I have become acutely aware of design decisions made in the games that I play, and I like to take mental notes of what works, and what doesn&#8217;t. I also spend a lot of time watching game-related news and lurk the <a href="http://gamedev.net">GameDev</a> forums to keep up-to-date on the latest game development trends and advances. </p>
<p>I figured, now that I&#8217;ve got a blog, it&#8217;s time to start taking more permanent notes on the design decisions, both good and bad, of the various games I play. To start, I&#8217;m going to pick on the 800lb Gorilla in the room, <a href="http://www.worldofwarcraft.com">World of Warcraft</a> (known here on out as WoW). This is the first of what will be a multi-part series of articles, as I tend to delve in to rants and ramblings at time. However, I will try to keep it all coherent. So, without further ado&#8230;</p>
<p><span id="more-4"></span></p>
<p>I&#8217;ve been playing this game on and off for nigh three years now. I&#8217;ve seen plenty of ups and plenty of downs, been a part of quite a few guild breakups, and have developed an almost unhealthy love of criticizing and critiquing every little change Blizzard make to the game. I&#8217;ll admit, it&#8217;s not the best state of mind to be in, and many-a-time it has eaten away at me and caused me to loose all enjoyment of the game as I end up only able to focus on what&#8217;s wrong and not what&#8217;s fun. </p>
<p>What follows are the results of my brooding over the what and the why of the decisions made at Blizzard. Why does Blizzard make the decisions they do, what are the ramifications, and what can other game designers and developers learn from one of the best companies in the business. To start off, the most important rule about game design in general is quite simple:</p>
<h3>You are building <em>your</em> game. Make the decisions <em>you</em> think are right.</h3>
<p>I give Blizzard HUGE applause for what they have accomplished with WoW. It is by far the most complicated game ever created, and the fact that they have kept it running, continually added more, and still kept the same general WoW atmosphere and Blizzard Polish since release is a testament to the courage the development team has in shaping this massive game over time. Given all the flak they receive on a daily basis on their official forums and forums across the world, Blizzard rolls right along with the punches.</p>
<p>If you want your game to be successful, trust your instincts. It&#8217;s your game, not theirs. Make the game <b>you</b> want to play. That said&#8230;</p>
<h3>Some players will know the game better than you</h3>
<p>An interesting phenomenon I&#8217;ve been following with WoW is the statements of theorycrafters (those players that constantly calculate and run all the numbers they can get a hold of, to find the best, the worst, and everything in between) contrasted to the official statements of Blizzard, and what I&#8217;ve noticed is this: the theorycrafter community is almost always right. </p>
<p>As an example (and this will be difficult to really show without forum posts, but those are gone so please bear with me), with the most recent expansion to the game, The Wrath of the Lich King, we&#8217;ll look at how WoW&#8217;s PvP game became, quite frankly, a failure. </p>
<p>Wrath of the Lich King came with three changes that worked together to completely dismantle the game&#8217;s PvP.</p>
<ul>
<ol>Up the level cap to 80</ol>
<ol>Restart everyone on even footing as of level 71</ol>
<ol>Introduction of the Death Knight</ol>
</ul>
<p><b>Upping the level cap</b> is a normal move for any MMO expansion, and follows with the previous 10 level jump we saw in The Burning Crusade (TBC), the first expansion. There needs to be significant increases in the status of player characters, so it stands to reason that a level 80 character would easily tromp a level 70 character.</p>
<p><b>Restarting on equal footing</b> is almost a necessity given WoW&#8217;s PvE end-game. Now, first and foremost, WoW is a gear driven game. Everything you do to make your character more powerful involves gear. To help be better in PvP, you get better gear. To do better, and progress farther in PvE, you acquire better and better gear. The side effect of this is, a level capped character with full end-game PvE gear is far more powerful than a character who just hit the level cap. With a new expansion, and 10 more levels to grind through, Blizzard could not require high end PvE gear to continue through the new content or they would have very quickly lost a large portion of the player base (as only about 10% of the population really experience much of the end-game content). </p>
<p>So, the new area, Northrend, had to offer quest reward items and random world drop items that were almost equal in power to the previous end-game PvE gear, putting all characters back on an even footing. This means that everyone suddenly does more damage, has more health, and is overall significantly stronger (example: my best raiding DPS in TBC was around 1500. When I started raiding again in Lich King, I was already doing 2500 and quickly improving). In general, the calculations showed that a level 80 character started out about 2.5 to 3 times more powerful than at level 70. </p>
<p><b>The introduction of the Death Knight</b> was long in coming, and heavily anticipated. A new class for WoW was just what the game needed to bring a fresh breath of air to the game some people had been playing for 3 straight years by then. It is a class with a novel new resource system (Runes and Runic Power), tons of new spells and abilities to master, and an entire new starting area built just for the class and its lore leading up to Lich King. Blizzard put everything into this class, they wanted it to be a huge success, and quite a success it has been, and a major sore spot as well.</p>
<p>With the triage of these three major changes, WoW&#8217;s PvP was doomed from the start. It didn&#8217;t take the theorycrafters long to crunch the numbers, to play with classes on the Test Realm, and to come to the conclusion that at level 80, characters were either going to do way too much damage, or they weren&#8217;t going to have high enough health pools to soak up the huge damage increase. Posts on the official forums and post on respected theorycrafting forums like Elitist Jerks showed, argued, and asked constantly for Blizzard to re-think their stance on character power at level 80, but Blizzard would have none of it. If there&#8217;s one statement seen the most, it was &#8220;We will just wait and see what happens&#8221; often followed by &#8220;We think it will be ok, characters will have enough health.&#8221;</p>
<p>Well the &#8220;wait and see&#8221; has happened, and the game&#8217;s PvP devolved to the worst it&#8217;s ever been. Healers gave up trying to heal, because you can&#8217;t heal someone who gets killed in 3 seconds or less. Entire classes stopped playing because they either couldn&#8217;t do the damage others could, or they couldn&#8217;t get out of the way of the incoming damage. It was, and in most cases still is, absolute mayhem. Skill has been shoved into a trailer and gear and choice of class is the king of PvP now. To see what I mean, here&#8217;s the top 10 ranked PvP Arena 3v3 teams as of the March 24th:</p>
<pre>
The top 10 teams of the 2009 Arena Tournament’s online qualifier as of March 24, 2009 are listed below:

Rank. Team Name	                Classes
1. well then                        Death Knight, Paladin, Warlock
2. BARKSDALE CREW             Death Knight, Paladin, Warlock
3. monkey attack squad        Hunter, Mage, Shaman
4. GET MONEY GET PAYCE     Death Knight, Hunter, Paladin
5. Walrus Attack Squad	        Hunter, Mage, Priest
6. Paradorn’s Team	        Hunter, Paladin, Warlock
7. NO LIGHTNING GEN BRAH	Death Knight, Paladin, Warlock
7. Nekos’ Team	                Death Knight, Death Knight, Paladin
9. faceroll tunnel vision         Paladin, Priest, Shaman
10. Wd’s Team	                Death Knight, Paladin, Warlock
</pre>
<p>Pretty obvious to see just how inbalanced the PvP game has become. The top teams, while good at PvPing anyway, are so much better simply because of the class composition of the team. Entire classes are absent of this list: Druid, Warrior, and Rogue, which ironically enough were always present in Arena teams during TBC. </p>
<p>Anyway, it&#8217;s a lot of talk to make a point, but the severity of the failure <b>because</b> Blizzard didn&#8217;t listen to the theorycrafters at all needs to be shown. There have been many steps since taken to &#8220;tone down burst damage&#8221; since Lich King&#8217;s release, but Blizzard has a long way to go. More time up front, and a willingness to admit that they were wrong, and Blizzard could have made huge strides towards preventing this catastrophe. Blizzard has been working hard since the release of TBC to make WoW&#8217;s Arena a viable &#8220;e-sport&#8221;, but with current state of Lich King&#8217;s PvP, they have taking a very severe blow to that work, making it that much harder to convince people that Arena is worth standing on the pedestal with games like Counter Strike and Quake.</p>
<p><a href="http://jameskilton.com/2009/05/01/game-design-lessons-learned-from-world-of-warcraft-part-2/">Continue with Part 2</a></p>
]]></content:encoded>
			<wfw:commentRss>http://jameskilton.com/2009/03/28/game-design-lessons-learned-from-world-of-warcraft-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Blog Named!</title>
		<link>http://jameskilton.com/2009/03/26/blog-named/</link>
		<comments>http://jameskilton.com/2009/03/26/blog-named/#comments</comments>
		<pubDate>Thu, 26 Mar 2009 22:42:18 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[everything!]]></category>

		<guid isPermaLink="false">http://jameskilton.com/?p=45</guid>
		<description><![CDATA[That&#8217;s right, I decided on a name. Being a huge fan of Douglas Adams, and especially the Hitchhiker&#8217;s Guide to the Galaxy, it seemed only right to pay homage to such a great author and fantastically weird story. 
So the choice of theme made, the name came down to two: Forty-Two, otherwise known as The [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s right, I decided on a name. Being a huge fan of Douglas Adams, and especially the <em>Hitchhiker&#8217;s Guide to the Galaxy</em>, it seemed only right to pay homage to such a great author and fantastically weird story. </p>
<p>So the choice of theme made, the name came down to two: Forty-Two, otherwise known as The Answer, or Slartibartfast, because the name really doesn&#8217;t matter. I was leaning towards Forty-Two, and with an extra vote from a good friend of mine, it became the name.</p>
<p>I&#8217;ll probably update other parts of the site to fit the theme, like the subtitle and the categories. All in all, feels good to have a solidly named site.</p>
<p>Now, what <b>do</b> you get when you multiply six by nine?</p>
]]></content:encoded>
			<wfw:commentRss>http://jameskilton.com/2009/03/26/blog-named/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>There are two hard problems in Computer Science&#8230;</title>
		<link>http://jameskilton.com/2009/03/21/there-are-two-hard-problems-in-computer-science/</link>
		<comments>http://jameskilton.com/2009/03/21/there-are-two-hard-problems-in-computer-science/#comments</comments>
		<pubDate>Sat, 21 Mar 2009 19:27:17 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[everything!]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://jameskilton.com/?p=13</guid>
		<description><![CDATA[Cache invalidation and naming things, and the latter is most definitely not a Computer Science-only problem. I have no idea what to name this blog, so for now, it&#8217;s going to remain un-named until either a good suggestion comes along, or inspiration hits me. 
]]></description>
			<content:encoded><![CDATA[<p>Cache invalidation and naming things, and the latter is most definitely not a Computer Science-only problem. I have no idea what to name this blog, so for now, it&#8217;s going to remain un-named until either a good suggestion comes along, or inspiration hits me. </p>
]]></content:encoded>
			<wfw:commentRss>http://jameskilton.com/2009/03/21/there-are-two-hard-problems-in-computer-science/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
