<?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>Mr. Phil Games &#187; Code</title> <atom:link href="http://www.mrphilgames.com/category/code/feed/" rel="self" type="application/rss+xml" /><link>http://www.mrphilgames.com</link> <description>Thinking Gamers Rule!</description> <lastBuildDate>Tue, 17 Jan 2012 05:38:08 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Unity3D #pragma strict Gotch</title><link>http://www.mrphilgames.com/unity3d-pragma-strict-gotch/</link> <comments>http://www.mrphilgames.com/unity3d-pragma-strict-gotch/#comments</comments> <pubDate>Fri, 30 Dec 2011 03:27:28 +0000</pubDate> <dc:creator>MrPhil</dc:creator> <category><![CDATA[Code]]></category> <category><![CDATA[Unity]]></category><guid
isPermaLink="false">http://www.mrphilgames.com/?p=1310</guid> <description><![CDATA[I was working with some code in a book today and could not figure out why a variable was giving me problems. Unknown idenifier: &#8216;mesh&#8217;. (BCE0005) I don&#8217;t usually program using JavaScript much less with MonoDevlop, so it took me a while.  Turns out, it&#8217;s a little thing: #pragma strict I was using it, and [...]]]></description> <content:encoded><![CDATA[<p></p><p>I was working with some code in a book today and could not figure out why a variable was giving me problems.</p><blockquote><p>Unknown idenifier: &#8216;mesh&#8217;. (BCE0005)</p></blockquote><p>I don&#8217;t usually program using JavaScript much less with MonoDevlop, so it took me a while.  Turns out, it&#8217;s a little thing:</p><blockquote><p>#pragma strict</p></blockquote><p>I was using it, and the book wasn&#8217;t.  They didn&#8217;t declare the variable in the example unlike ALL the other ones! That&#8217;s why it is unknown, it IS unknown.  The sample code that came with the book compiled because it doesn&#8217;t have the #pragma strict.</p> ]]></content:encoded> <wfw:commentRss>http://www.mrphilgames.com/unity3d-pragma-strict-gotch/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>XNA SpriteFonts</title><link>http://www.mrphilgames.com/xna-spritefonts/</link> <comments>http://www.mrphilgames.com/xna-spritefonts/#comments</comments> <pubDate>Tue, 30 Aug 2011 04:08:52 +0000</pubDate> <dc:creator>MrPhil</dc:creator> <category><![CDATA[Code]]></category> <category><![CDATA[GameDev]]></category> <category><![CDATA[Iron Roads]]></category> <category><![CDATA[XNA]]></category><guid
isPermaLink="false">http://www.mrphilgames.com/?p=1250</guid> <description><![CDATA[While working on Iron Roads today, I tried to use the custom font Radius (a free font from Urban Fonts.)   I like how the letters look like curving tracks you might see on a draftsman&#8217;s drawing or surveying map.  It has potential for the Iron Roads logo.  Anyway, I ran into a tricky problem that stumped me for a long [...]]]></description> <content:encoded><![CDATA[<p></p><p>While working on Iron Roads today, I tried to use the custom font <a
href="http://www.urbanfonts.com/fonts/Radius.htm">Radius</a> (a free font from Urban Fonts.)   I like how the letters look like curving tracks you might see on a draftsman&#8217;s drawing or surveying map.  It has potential for the Iron Roads logo.  Anyway, I ran into a tricky problem that stumped me for a long while.</p><p
style="text-align: center;"><a
href="http://mrphilgames.s3.amazonaws.com/wp-content/uploads/2011/08/Iron-Roads-with-Radius-Font.png"><img
class="size-full wp-image-1252 aligncenter" title="Iron Roads with Radius Font" src="http://mrphilgames.s3.amazonaws.com/wp-content/uploads/2011/08/Iron-Roads-with-Radius-Font.png" alt="Iron Roads with Radius Font" width="463" height="71" /></a></p><p>I followed the normal procedure as Microsoft describes in <a
href="http://msdn.microsoft.com/en-us/library/bb447673(v=XNAGameStudio.40).aspx">Drawing Text with a Sprite</a>:</p><blockquote><ol><li>Right-click your Content project in Solution Explorer, click <strong>Add</strong>, and then click <strong>New Item</strong>.</li><li>In the <strong>Add New Item</strong> dialog box, click <strong>Sprite Font</strong>. You may find it convenient at this point to change the name of the new file from &#8220;SpriteFont1&#8243; to the friendly name of the font you intend to load (keeping the .spritefont file extension).  The friendly name identifies the font once it is installed on your computer, for example, &#8220;Courier New&#8221; or &#8220;Times New Roman.&#8221; When you reference the font in your code, you must use the friendly name you have assigned it. XNA Game Studio creates a new .spritefont file for your font and opens it.</li></ol></blockquote><p>At this point I had what I needed, but alas, it wouldn&#8217;t compile, complaining:</p><blockquote><p>The font family &#8220;Radius&#8221; could not be found. Please ensure the requested font is installed, and is a TrueType or OpenType font.</p></blockquote><p>Took me a long while to figure it out, but it&#8217;s actually quite simple. <strong>Install new fonts before starting up Visual Studio!</strong> So, all I had to do was shut VS2010 down and start her up again, an Voila! New beautiful font displaying in my game!!!</p><p><a
href="http://mrphilgames.s3.amazonaws.com/wp-content/uploads/2011/08/Iron-Roads-Title-Screen-Draft-Peek.png"><img
class="aligncenter size-medium wp-image-1258" title="Iron Roads Title Screen Draft Peek" src="http://mrphilgames.s3.amazonaws.com/wp-content/uploads/2011/08/Iron-Roads-Title-Screen-Draft-Peek-300x62.png" alt="Iron Roads Title Screen Draft Peek" width="300" height="62" /></a></p><p
style="text-align: center;"><em>Please note, this is a concept piece, not art assets are my original and I don&#8217;t claim copyright to them.</em></p> ]]></content:encoded> <wfw:commentRss>http://www.mrphilgames.com/xna-spritefonts/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Tom Miller&#8217;s render loop, a revision</title><link>http://www.mrphilgames.com/tom_miller_mana/</link> <comments>http://www.mrphilgames.com/tom_miller_mana/#comments</comments> <pubDate>Mon, 09 Oct 2006 00:04:36 +0000</pubDate> <dc:creator>MrPhil</dc:creator> <category><![CDATA[Code]]></category><guid
isPermaLink="false">http://www.mrphilgames.com/?p=194</guid> <description><![CDATA[Tom Miller, Managed DirectX’s father figure, has made several posts on the game loop or render loop for the managed environment. His lastest post on the subject was back in May 2005. I’m writing the render loop for Alien Sovereign using GDI+, so I needed to tweak his code a little to make it work [...]]]></description> <content:encoded><![CDATA[<p></p><p>Tom Miller, Managed DirectX’s father figure, has made several posts on the game loop or render loop for the managed environment. His lastest post on the subject was back in May 2005. I’m writing the render loop for Alien Sovereign using GDI+, so I needed to tweak his code a little to make it work for a non-DirectX renderer. Here is my version source:</p><blockquote><p>#region Source<br
/> /* This code is an adaptation by Philip Ludington (of Mr.<br
/> * Phil Games) from the DirectX SDK file DXMUTMisc.cs, and<br
/> * Tom Miller&#8217;s blog post &#8220;My last post on render loops<br
/> * (hopefully)..&#8221; * http://blogs.msdn.com/tmiller/archive/2005/05/05/415008.aspx*/#endregionusing System;<br
/> using System.Collections.Generic;<br
/> using System.Windows.Forms;<br
/> using System.Runtime.InteropServices;</p><p>namespace Company.Program<br
/> {<br
/> #region Enum, deligates, struct etc.<br
/> public enum WindowMessage : uint    {        // Misc messages        Destroy = 0&#215;0002,        Close = 0&#215;0010,        Quit = 0&#215;0012,        Paint = 0x000F,        SetCursor = 0&#215;0020,        ActivateApplication = 0x001C,        EnterMenuLoop = 0&#215;0211,        ExitMenuLoop = 0&#215;0212,        NonClientHitTest = 0&#215;0084,        PowerBroadcast = 0&#215;0218,        SystemCommand = 0&#215;0112,        GetMinMax = 0&#215;0024,        // Keyboard messages        KeyDown = 0&#215;0100,        KeyUp = 0&#215;0101,        Character = 0&#215;0102,        SystemKeyDown = 0&#215;0104,        SystemKeyUp = 0&#215;0105,        SystemCharacter = 0&#215;0106,        // Mouse messages        MouseMove = 0&#215;0200,        LeftButtonDown = 0&#215;0201,        LeftButtonUp = 0&#215;0202,        LeftButtonDoubleClick = 0&#215;0203,        RightButtonDown = 0&#215;0204,        RightButtonUp = 0&#215;0205,        RightButtonDoubleClick = 0&#215;0206,        MiddleButtonDown = 0&#215;0207,        MiddleButtonUp = 0&#215;0208,        MiddleButtonDoubleClick = 0&#215;0209,        MouseWheel = 0x020a,        XButtonDown = 0x020B,        XButtonUp = 0x020c,        XButtonDoubleClick = 0x020d,        MouseFirst = LeftButtonDown, // Skip mouse move,<br
/> // it happens a lot and there is another<br
/> // message for that        MouseLast = XButtonDoubleClick,        // Sizing        EnterSizeMove = 0&#215;0231,        ExitSizeMove = 0&#215;0232,        Size = 0&#215;0005,    }    [StructLayout( LayoutKind.Sequential )]    public struct Message<br
/> {<br
/> public IntPtr hWnd;<br
/> public WindowMessage msg;<br
/> public IntPtr wParam;<br
/> public IntPtr lParam;<br
/> public uint time;<br
/> public System.Drawing.Point p;<br
/> }<br
/> #endregion    ///     /// Program    ///     static class Program<br
/> {<br
/> #region Member Variables<br
/> private static Form1 form1;<br
/> #endregion        #region Properties<br
/> #endregion        #region Constructors (including static)<br
/> #endregion        #region Public members<br
/> ///         /// The main entry point for the application.        ///         [STAThread]        static void Main()<br
/> {<br
/> Application.EnableVisualStyles();<br
/> Application.SetCompatibleTextRenderingDefault(<br
/> false );</p><p>form1 = new Form1();</p><p>// Hook the application&#8217;s idle event            Application.Idle += new EventHandler(<br
/> OnApplicationIdle );</p><p>Application.Run( form1 );<br
/> }</p><p>// We won&#8217;t use this maliciously<br
/> [System.Security.SuppressUnmanagedCodeSecurity]<br
/> [DllImport( "User32.dll", CharSet<br
/> = CharSet.Auto )]<br
/> public static extern bool PeekMessage(<br
/> out Message msg,<br
/> IntPtr hWnd, uint messageFilterMin,<br
/> uint messageFilterMax,<br
/> uint flags );<br
/> #endregion        #region Private (helper) methods<br
/> static private void OnApplicationIdle( object sender,<br
/> EventArgs e )<br
/> {<br
/> while( AppStillIdle )<br
/> {<br
/> // Render a frame during idle time<br
/> // (no messages are waiting)                Update();                Render();            }        }        private static void Render()<br
/> {<br
/> throw new Exception(<br
/> &#8220;The method or operation is not implemented.&#8221; );<br
/> }<br
/> private static void Update()<br
/> {<br
/> throw new Exception(<br
/> &#8220;The method or operation is not implemented.&#8221; );<br
/> }<br
/> static private bool AppStillIdle<br
/> {<br
/> get<br
/> {<br
/> Message msg;<br
/> return !PeekMessage( out msg,<br
/> IntPtr.Zero, 0, 0, 0 );<br
/> }<br
/> }<br
/> #endregion    }}</p></blockquote> ]]></content:encoded> <wfw:commentRss>http://www.mrphilgames.com/tom_miller_mana/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Visual Studio 2005 Keyboard Cheat Sheet</title><link>http://www.mrphilgames.com/visual_studio_2/</link> <comments>http://www.mrphilgames.com/visual_studio_2/#comments</comments> <pubDate>Wed, 23 Aug 2006 00:39:49 +0000</pubDate> <dc:creator>MrPhil</dc:creator> <category><![CDATA[Code]]></category><guid
isPermaLink="false">http://www.mrphilgames.com/?p=251</guid> <description><![CDATA[Lately I have been having pain in my arm and wrist from using the mouse so much.  So I went looking for a keyboard cheat sheet for Visual Studio 2005.  I am hoping this will allow me to use the mouse less and give my wrist a rest.  Sadly, the best thing I could find [...]]]></description> <content:encoded><![CDATA[<p></p><p>Lately I have been having pain in my arm and wrist from using the mouse so much.  So I went looking for a keyboard cheat sheet for Visual Studio 2005.  I am hoping this will allow me to use the mouse less and give my wrist a rest.  Sadly, the best thing I could find was this video at <a
href="http://msdn.microsoft.com/en-us/directx/default.aspx">Channel 9</a> (I can’t get a lot of these to work with C#).  So using tips from the video and my own sleuth like skills I created my own cheat sheet which I share here for you future Google travelers.</p><p><strong>Visual Studio 2005 Key Board Cheat Sheet</strong></p><p>Build = Shift+F6<br
/> Jump to Find Window = Ctrl + /<br
/> Toggle Region = Ctrl+M, M<br
/> Next Error = Ctrl+Shif+F12<br
/> Comment Line = Ctrl+C,C<br
/> UnComment Line = Ctrl+C,C<br
/> Open a file = Ctrl+O<br
/> Error W. = Ctrl+W, E<br
/> Class W. = Ctrl+W, C<br
/> Code = F7</p> ]]></content:encoded> <wfw:commentRss>http://www.mrphilgames.com/visual_studio_2/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>DOH!, Pause = Thread.Sleep(42)</title><link>http://www.mrphilgames.com/doh_pause_threa/</link> <comments>http://www.mrphilgames.com/doh_pause_threa/#comments</comments> <pubDate>Mon, 26 Jun 2006 00:43:56 +0000</pubDate> <dc:creator>MrPhil</dc:creator> <category><![CDATA[Code]]></category><guid
isPermaLink="false">http://www.mrphilgames.com/?p=259</guid> <description><![CDATA[So I&#8217;ve been working with .Net for years and today I put something together that made me feel foolish for not already realizing. Especially since I&#8217;ve used Threads before and even timed them out. I just never had the concept of needing to pause my code bump up next to the fact that my “normal” [...]]]></description> <content:encoded><![CDATA[<p></p><div><div><p>So I&#8217;ve been working with .Net for years and today I put something together that made me feel foolish for not already realizing. Especially since I&#8217;ve used Threads before and even timed them out. I just never had the concept of needing to pause my code bump up next to the fact that my “normal” code is in a thread too.  I’ve gotten so used to only dealing with threading stuff in special situations I guess I forget that my everyday code is threading too. So if you want to pause your code for a certain number of milliseconds do this</p><pre>     System.Threading.Thread.Sleep( milliseconds );</pre><p>Not:</p><pre>    DateTime stop = DateTime.Now.AddMilliseconds( milliseconds );
    while( DateTime.Now &lt; stop );</pre><p>Or some other machination with DateTimes and loops.</p><p>Oh well, it not really my fault it is simply a side affect of global warming.</p></div></div> ]]></content:encoded> <wfw:commentRss>http://www.mrphilgames.com/doh_pause_threa/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Strategy Pattern</title><link>http://www.mrphilgames.com/strategypattern/</link> <comments>http://www.mrphilgames.com/strategypattern/#comments</comments> <pubDate>Tue, 25 Jan 2005 23:40:20 +0000</pubDate> <dc:creator>MrPhil</dc:creator> <category><![CDATA[Code]]></category><guid
isPermaLink="false">http://www.mrphilgames.com/?p=188</guid> <description><![CDATA[Taking Alastair Patrick’s example of applying patterns to game making I present the strategy pattern. The strategy pattern encapsulates behavior allowing flexibility and object composition. This means a group of classes (as ships) can have some behavior in common, but also room for different flavors without having a lot of overrides and duplicate code. Here’s [...]]]></description> <content:encoded><![CDATA[<p></p><p>Taking <a
href="http://alpatrick.blogspot.com/">Alastair Patrick</a>’s example of applying patterns to game making I present the strategy pattern. The strategy pattern encapsulates behavior allowing flexibility and object composition. This means a group of classes (as ships) can have some behavior in common, but also room for different flavors without having a lot of overrides and duplicate code. Here’s an example in code. Note, I’ve even written it so the behavior can be changed at runtime!</p><blockquote><p> public interface AttackBehavior</p><p>{</p><p> void Attack();</p><p>}</p><p>public class AttackWithNoWeapon : AttackBehavior</p><p>{</p><p> public AttackWithNoWeapon()</p><p> {</p><p> //</p><p> // TODO: Add constructor logic here</p><p> //</p><p> }</p><p> public void Attack()</p><p> {</p><p> Console.Out.WriteLine( &#8220;No weapon to attack with.&#8221; );</p><p> }</p><p>}</p><p>public class AttackWithRedLaser : AttackBehavior</p><p>{</p><p> public AttackWithRedLaser()</p><p> {</p><p> //</p><p> // TODO: Add constructor logic here</p><p> //</p><p> }</p><p> public void Attack()</p><p> {</p><p> Console.Out.WriteLine( &#8220;Firing red lasers.&#8221; );</p><p> }</p><p>}</p><p>public class AttackWithReinforcedIceProjectile : AttackBehavior</p><p>{</p><p> public AttackWithReinforcedIceProjectile()</p><p> {</p><p> //</p><p> // TODO: Add constructor logic here</p><p> //</p><p> }</p><p> public void Attack()</p><p> {</p><p> Console.Out.WriteLine( &#8220;Firing Reinforced Ice Projectiles &#8221; );</p><p> }</p><p>}</p><p>public interface FlyBehavior</p><p>{</p><p> void Fly();</p><p>}</p><p>public class FlyWithIonEngines : FlyBehavior</p><p>{</p><p> public FlyWithIonEngines()</p><p> {</p><p> //</p><p> // TODO: Add constructor logic here</p><p> //</p><p> }</p><p> public void Fly()</p><p> {</p><p> Console.Out.WriteLine( &#8220;Moved 4 parsecs.&#8221; );</p><p> }</p><p>}</p><p>public class FlyWithNoEngines : FlyBehavior</p><p>{</p><p> public FlyWithNoEngines()</p><p> {</p><p> //</p><p> // TODO: Add constructor logic here</p><p> //</p><p> }</p><p> public void Fly()</p><p> {</p><p> Console.Out.WriteLine( &#8220;Movement determined by gravity and inertia.&#8221; );</p><p> }</p><p>}</p><p>public class FlyWithSolarSails : FlyBehavior</p><p>{</p><p> public FlyWithSolarSails()</p><p> {</p><p> //</p><p> // TODO: Add constructor logic here</p><p> //</p><p> }</p><p> public void Fly()</p><p> {</p><p> Console.Out.WriteLine( &#8220;Low Solar Wind, move .5 parsecs.&#8221; );</p><p> }</p><p>}</p><p>public abstract class Ship</p><p>{</p><p> protected FlyBehavior flyBehavior = null;</p><p> protected AttackBehavior attackBehavior = null;</p><p> public Ship()</p><p> {</p><p> }</p><p> public abstract void Display();</p><p> public void PerformFly()</p><p> {</p><p> flyBehavior.Fly();</p><p> }</p><p> public void PerformAttack()</p><p> {</p><p> attackBehavior.Attack();</p><p> }</p><p> public void Repair()</p><p> {</p><p> Console.Out.WriteLine( &#8220;Repair teams dispatched, 10% improvement.&#8221; );</p><p> }</p><p> public void SetFlyBehavior( FlyBehavior fb )</p><p> {</p><p> flyBehavior = fb;</p><p> }</p><p> public void SetAttackBehavior( AttackBehavior ab )</p><p> {</p><p> attackBehavior = ab;</p><p> }</p><p>}</p><p>public class TerranMarkI : Ship</p><p>{</p><p> public TerranMarkI()</p><p> {</p><p> flyBehavior = new FlyWithIonEngines();</p><p> attackBehavior = new AttackWithRedLaser();</p><p> }</p><p> public override void Display()</p><p> {</p><p> Console.Out.WriteLine( &#8220;This is a Terran Mark I ship.&#8221; );</p><p> }</p><p>}</p><p>public class NeiwckronMkI : Ship</p><p>{</p><p> public NeiwckronMkI()</p><p> {</p><p> SetAttackBehavior( new AttackWithNoWeapon() );</p><p> SetFlyBehavior( new FlyWithIonEngines() );</p><p> }</p><p> public override void Display()</p><p> {</p><p> Console.Out.WriteLine( &#8220;A Neiwckron Mark I ship.&#8221; );</p><p> }</p><p>}</p><p>public class TheMain</p><p>{</p><p> ///<br
/> <summary><p> /// The main entry point for the application.</p><p> /// </summary><p> [STAThread]</p><p> static void Main()</p><p> {</p><p> Ship s1 = new TerranMarkI();</p><p> s1.PerformAttack();</p><p> s1.PerformFly();</p><p> Ship s2 = new NeiwckronMkI();</p><p> s2.PerformFly();</p><p> s2.SetFlyBehavior( new FlyWithSolarSails() );</p><p> s2.PerformFly();</p><p> }</p><p>}</p></blockquote><p><em>When I am not writing about making games, procrastinating or watching movies I&#8217;m working on a science fiction strategy game (sometimes called 4X or empire builder.) Email me questions, ideas and jokes at mrphil (at) mrphilgames . com</em></p> ]]></content:encoded> <wfw:commentRss>http://www.mrphilgames.com/strategypattern/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Object Cloning Using Reflection</title><link>http://www.mrphilgames.com/object_cloning_/</link> <comments>http://www.mrphilgames.com/object_cloning_/#comments</comments> <pubDate>Mon, 10 Jan 2005 18:25:02 +0000</pubDate> <dc:creator>MrPhil</dc:creator> <category><![CDATA[Code]]></category><guid
isPermaLink="false">http://www.mrphilgames.com/?p=142</guid> <description><![CDATA[Today on Alastair Patrick’s blog he shared a way to use reflection to clone objects which I found really interesting. I took the liberty of expanding the example a little so I could better understand the effects deep and shallow cloning had. I also replaced his main() with a NUnit test. using System; using System.Reflection; [...]]]></description> <content:encoded><![CDATA[<p></p><p>Today on <a
href="http://alpatrick.blogspot.com/2005/01/prototype-pattern-using-reflection.html">Alastair Patrick’s blog he shared a way to use reflection to clone objects</a> which I found really interesting. I took the liberty of expanding the example a little so I could better understand the effects deep and shallow cloning had. I also replaced his main() with a NUnit test.</p><blockquote><p> using System;</p><p>using System.Reflection;</p><p>using NUnit.Framework;</p><p>public class DeepCopyAttribute : Attribute</p><p>{</p><p>}</p><p>public class PrototypeCloner</p><p>{</p><p> public object Clone( object prototype )</p><p> {</p><p> object clone = CreateNewInstance( prototype.GetType() );</p><p> CopyPropertyValuesFromPrototype( clone, prototype );</p><p> return clone;</p><p> }</p><p> private object CreateNewInstance(Type type)</p><p> {</p><p> ConstructorInfo defaultConstructor = type.GetConstructor( new Type[0] );</p><p> return defaultConstructor.Invoke(new object[0]);</p><p> }</p><p> private bool IsPropertyDeepCopied( PropertyInfo property )</p><p> {</p><p> if( property.GetCustomAttributes( typeof(DeepCopyAttribute), true).Length</p><p> != 0 )</p><p> {</p><p> return true;</p><p> }</p><p> else</p><p> {</p><p> return false;</p><p> }</p><p> }</p><p> private void CopyPropertyValuesFromPrototype(object clone, object prototype)</p><p> {</p><p> foreach (PropertyInfo property in prototype.GetType().GetProperties())</p><p> {</p><p> if (IsPropertyDeepCopied(property))</p><p> {</p><p> object prototypeProperty = property.GetValue(prototype, null);</p><p> object cloneProperty = Clone(prototypeProperty);</p><p> property.SetValue(clone, cloneProperty, null);</p><p> }</p><p> else</p><p> {</p><p> property.SetValue(clone, property.GetValue(prototype, null), null);</p><p> }</p><p> }</p><p> }</p><p>}</p><p>public abstract class Weapon</p><p>{</p><p>}</p><p>public class LaserDisruptor: Weapon</p><p>{</p><p> public float RateOfFire</p><p> {</p><p> get</p><p> {</p><p> return rateOfFire;</p><p> }</p><p> set</p><p> {</p><p> rateOfFire = value;</p><p> }</p><p> }</p><p> private float rateOfFire = 1000;</p><p>}</p><p>public abstract class Entity {}</p><p>public class SpaceMonkey: Entity</p><p>{</p><p> public float Speed</p><p> {</p><p> get</p><p> {</p><p> return speed;</p><p> }</p><p> set</p><p> {</p><p> speed = value;</p><p> }</p><p> }</p><p> private float speed = 5;</p><p> private Weapon deepCopyWeapon = new LaserDisruptor();</p><p> [DeepCopyAttribute()]</p><p> public Weapon DeepCopyWeapon</p><p> {</p><p> get</p><p> {</p><p> return deepCopyWeapon;</p><p> }</p><p> set</p><p> {</p><p> deepCopyWeapon = value;</p><p> }</p><p> }</p><p> private Weapon shallowCopyWeapon = new LaserDisruptor();</p><p> public Weapon ShallowCopyWeapon</p><p> {</p><p> get</p><p> {</p><p> return shallowCopyWeapon;</p><p> }</p><p> set</p><p> {</p><p> shallowCopyWeapon = value;</p><p> }</p><p> }</p><p>}</p><p>[TestFixture]</p><p>public class PrototypeClonerTests</p><p>{</p><p> [Test]</p><p> public void Clone()</p><p> {</p><p> SpaceMonkey prototypeObject = new SpaceMonkey();</p><p> PrototypeCloner cloner = new PrototypeCloner();</p><p> Entity clonedObject = null;</p><p> clonedObject = (Entity)cloner.Clone(prototypeObject);</p><p> SpaceMonkey clonedMonkey = (SpaceMonkey)clonedObject;</p><p> // Testing for Equality</p><p> Assert.AreEqual( prototypeObject.Speed, clonedMonkey.Speed, &#8220;Fail1&#8243; );</p><p> // &#8212; This is false because it is a Deep Copy property and this class</p><p> // doesn&#8217;t override the Equals or == operator so the Assert&#8217;s</p><p> // AreSame and AreEqual tests have the identical result</p><p> Assert.IsFalse(</p><p> prototypeObject.DeepCopyWeapon  == clonedMonkey.DeepCopyWeapon,</p><p> &#8220;Fail2&#8243; );</p><p> Assert.AreEqual(</p><p> ((LaserDisruptor)prototypeObject.DeepCopyWeapon).RateOfFire,</p><p> ((LaserDisruptor)clonedMonkey.DeepCopyWeapon).RateOfFire, &#8220;Fail3&#8243; );</p><p> // &#8212; Are equal, as in the same object because it is the Shallow Copy</p><p> Assert.AreEqual( prototypeObject.ShallowCopyWeapon,</p><p> clonedMonkey.ShallowCopyWeapon,</p><p> &#8220;Fail4&#8243; );</p><p> Assert.AreEqual(</p><p> ((LaserDisruptor)prototypeObject.ShallowCopyWeapon).RateOfFire,</p><p> ((LaserDisruptor)clonedMonkey.ShallowCopyWeapon).RateOfFire, &#8220;Fail5&#8243; );</p><p> // Testing for Same</p><p> // &#8212; Only the DeepCopyAttribute properties should be the same</p><p> // &#8212; Not same because it is not a referance object (float)</p><p> Assert.IsFalse(</p><p> object.ReferenceEquals( prototypeObject.Speed, clonedMonkey.Speed ),</p><p> &#8220;Fail6&#8243;  );</p><p> // &#8212; Not same because it is a DeepCopyAttribute</p><p> Assert.IsFalse(</p><p> object.ReferenceEquals( prototypeObject.DeepCopyWeapon,</p><p> clonedMonkey.DeepCopyWeapon),</p><p> &#8220;Fail7&#8243; );</p><p> // &#8212; Not same because it is not a referance object (float)</p><p> Assert.IsFalse( object.ReferenceEquals(</p><p> ((LaserDisruptor)prototypeObject.DeepCopyWeapon).RateOfFire,</p><p> ((LaserDisruptor)clonedMonkey.DeepCopyWeapon).RateOfFire), &#8220;Fail8&#8243;  );</p><p> // &#8212; The only referance object that isn&#8217;t a deep copy Are Same</p><p> Assert.AreSame( prototypeObject.ShallowCopyWeapon,</p><p> clonedMonkey.ShallowCopyWeapon,</p><p> &#8220;Fail9&#8243; );</p><p> // &#8212; Not same because it is not a referance object (float)</p><p> Assert.IsFalse( object.ReferenceEquals(</p><p> ((LaserDisruptor)prototypeObject.ShallowCopyWeapon).RateOfFire,</p><p> ((LaserDisruptor)clonedMonkey.ShallowCopyWeapon).RateOfFire),</p><p> &#8220;Fail10&#8243;  );</p><p> }</p><p>}</p></blockquote> ]]></content:encoded> <wfw:commentRss>http://www.mrphilgames.com/object_cloning_/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Your Own “Servlet” or HTML Spew Machine</title><link>http://www.mrphilgames.com/your_own_servle/</link> <comments>http://www.mrphilgames.com/your_own_servle/#comments</comments> <pubDate>Wed, 22 Sep 2004 18:23:25 +0000</pubDate> <dc:creator>MrPhil</dc:creator> <category><![CDATA[Code]]></category><guid
isPermaLink="false">http://www.mrphilgames.com/?p=136</guid> <description><![CDATA[So you want a quick way to spew your own html? Create an aspx page and remove all the html and then in the code behind replace the Page_Load procedure with: private void Page_Load(object sender, System.EventArgs e) { Response.Clear(); Response.ClearHeaders(); Response.ContentType = &#8220;Text/HTML&#8221;; Response.AppendHeader( &#8220;your header&#8221;, &#8220;your value&#8221; ); Response.Write( &#8220;Your spew&#8221; ); } Of [...]]]></description> <content:encoded><![CDATA[<p></p><p>So you want a quick way to spew your own html?</p><p>Create an aspx page and remove all the html and then in the code behind replace the Page_Load procedure with:</p><blockquote><p>private void Page_Load(object sender, System.EventArgs e)<br
/> {<br
/> Response.Clear();<br
/> Response.ClearHeaders();<br
/> Response.ContentType = &#8220;Text/HTML&#8221;;<br
/> Response.AppendHeader( &#8220;your header&#8221;, &#8220;your value&#8221; );<br
/> Response.Write( &#8220;<html><body>Your spew</body></html>&#8221; );<br
/> }</p></blockquote><p>Of course you don&#8217;t have to spew html.</p><p>-Mr.Phil</p><p>When I am not writing about making games, procrastinating or watching movies I&#8217;m working on a science fiction strategy game (sometimes called 4X or empire builder.) Email me questions, ideas and jokes at mrphil (at) mrphilgames . com</p> ]]></content:encoded> <wfw:commentRss>http://www.mrphilgames.com/your_own_servle/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>June 8th, 2004</title><link>http://www.mrphilgames.com/june-8th-2004/</link> <comments>http://www.mrphilgames.com/june-8th-2004/#comments</comments> <pubDate>Tue, 08 Jun 2004 23:18:32 +0000</pubDate> <dc:creator>MrPhil</dc:creator> <category><![CDATA[Code]]></category><guid
isPermaLink="false">http://www.mrphilgames.com/?p=171</guid> <description><![CDATA[Feeling pretty sick today, must have caught some bug, but I finished the code reorganizing I started yesterday. It may seem like just procrastination, but I wanted all the engine code in one assembly (was two). I also realized that I have another category of code I want to keep in it’s own namespace. I [...]]]></description> <content:encoded><![CDATA[<p></p><p>Feeling pretty sick today, must have caught some bug, but I finished the code reorganizing I started yesterday. It may seem like just procrastination, but I wanted all the engine code in one assembly (was two). I also realized that I have another category of code I want to keep in it’s own namespace. I am calling this new namespace Library. So my engine now has three parts Graphics, Framework, and Library. I also took all the NUnit tests out of the class’ they test and put them into their own project. It makes the engine more portable and I can access all the namespaces in the testing area without opening up a backdoor in the engine. Next I need to break the bindings between a couple classes that are in the Framework but access the directx device. The whole idea of a Graphics namespace was to keep display specific stuff out of the Framework!!! I also started a new solution I’m calling the Sandbox. Every time I run into trouble understanding how some class works I’m going to create a project in which to experiment with it. Hopefully this will increase my understanding and build a sort of “snippet” library.</p> ]]></content:encoded> <wfw:commentRss>http://www.mrphilgames.com/june-8th-2004/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Did you say, &#8220;Make a game with C#?&#8221;</title><link>http://www.mrphilgames.com/didyousaymakeagamewithc/</link> <comments>http://www.mrphilgames.com/didyousaymakeagamewithc/#comments</comments> <pubDate>Thu, 12 Feb 2004 23:09:45 +0000</pubDate> <dc:creator>MrPhil</dc:creator> <category><![CDATA[Business]]></category> <category><![CDATA[Code]]></category><guid
isPermaLink="false">http://www.mrphilgames.com/?p=152</guid> <description><![CDATA[Been doing a lot of research and work lately! Feeling great about my progress. I found some resources and technology I’m really excited about and it has helped me stave off the procrastination bug. I watched a .Net Show espisode called Managed DirectX with Tom Miller over at Microsoft and it made me seriously consider [...]]]></description> <content:encoded><![CDATA[<p></p><p>Been doing a lot of research and work lately! Feeling great about my progress. I found some resources and technology I’m really excited about and it has helped me stave off the procrastination bug.</p><p>I watched a .Net Show espisode called Managed DirectX with Tom Miller over at Microsoft and it made me seriously consider writing my game in C# using the new DirectX 9. Why you ask?</p><p>1. A performance hit of only 93% for using the .Net Framework<br
/> 2. A well organized class library<br
/> 3. C# is very similar to C++ which I already know<br
/> 4. Chance to develop in cutting edge technology<br
/> 5. Mono: Ximian’s project porting .Net to Linux</p><p>I feel like I’ve hit the jackpot!</p><p>I found a great tutorial using both technologies at kuhnstall and finished them on Monday. Now I’m writing my first basic 2D graphics engine. It has been a challenge, but a lot of fun and I’ve had no trouble sitting down and getting solid work done.</p><p><em>Philip Ludington aka Mr. Phil is a computer programmer who dreams of making computer games for a living, but is highly prone to procastination.</em></p> ]]></content:encoded> <wfw:commentRss>http://www.mrphilgames.com/didyousaymakeagamewithc/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced
Object Caching 608/658 objects using disk: basic
Content Delivery Network via Amazon Web Services: S3: mrphilgames.s3.amazonaws.com

Served from: www.mrphilgames.com @ 2012-02-06 20:00:56 -->
