<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Changing constants at runtime</title>
	<atom:link href="http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/feed" rel="self" type="application/rss+xml" />
	<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime</link>
	<description>Programming and Game Development - Kevin Gadd's Personal Blog</description>
	<lastBuildDate>Tue, 31 Aug 2010 18:32:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Barnaby Smith</title>
		<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/comment-page-1#comment-904</link>
		<dc:creator>Barnaby Smith</dc:creator>
		<pubDate>Wed, 23 Jun 2010 10:35:16 +0000</pubDate>
		<guid isPermaLink="false">http://www.luminance.org/?p=315#comment-904</guid>
		<description>This is a very interesting post and series of comments. I&#039;ve implemented several tweakable systems in the past, but I&#039;m looking to write a better one. I&#039;ll be sure to link to this article when I post about it. :-)</description>
		<content:encoded><![CDATA[<p>This is a very interesting post and series of comments. I&#8217;ve implemented several tweakable systems in the past, but I&#8217;m looking to write a better one. I&#8217;ll be sure to link to this article when I post about it. <img src='http://www.luminance.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kael</title>
		<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/comment-page-1#comment-903</link>
		<dc:creator>Kael</dc:creator>
		<pubDate>Mon, 21 Jun 2010 18:17:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.luminance.org/?p=315#comment-903</guid>
		<description>&lt;blockquote&gt;
&lt;a href=&quot;#comment-902&quot; rel=&quot;nofollow&quot;&gt;
&lt;strong&gt;&lt;em&gt;Tom:&lt;/em&gt;&lt;/strong&gt;
&lt;/a&gt;
 &lt;p&gt;I’ll be sticking with attributes.  It’s a cleaner, faster solution, period.  Yours is very clever but not practical for commercial, high-performance, team-driven applications.&lt;/p&gt;
&lt;/blockquote&gt;I think you missed some buzzwords there like &#039;enterprise&#039;. ;)

Anyway, while I still don&#039;t see how attributes are any faster (I&#039;d like to see someone actually prove it with a benchmark), cleanliness is always a matter of personal taste, so more power to you. Maybe you should share the source code for a good attribute based alternative so people have an easy choice between both approaches? I&#039;ll gladly link to it in the post.</description>
		<content:encoded><![CDATA[<blockquote><p>
<a href="#comment-902" rel="nofollow"><br />
<strong><em>Tom:</em></strong><br />
</a></p>
<p>I’ll be sticking with attributes.  It’s a cleaner, faster solution, period.  Yours is very clever but not practical for commercial, high-performance, team-driven applications.</p>
</blockquote>
<p>I think you missed some buzzwords there like &#8216;enterprise&#8217;. <img src='http://www.luminance.org/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Anyway, while I still don&#8217;t see how attributes are any faster (I&#8217;d like to see someone actually prove it with a benchmark), cleanliness is always a matter of personal taste, so more power to you. Maybe you should share the source code for a good attribute based alternative so people have an easy choice between both approaches? I&#8217;ll gladly link to it in the post.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/comment-page-1#comment-902</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Mon, 21 Jun 2010 18:11:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.luminance.org/?p=315#comment-902</guid>
		<description>I&#039;ll be sticking with attributes.  It&#039;s a cleaner, faster solution, period.  Yours is very clever but not practical for commercial, high-performance, team-driven applications.</description>
		<content:encoded><![CDATA[<p>I&#8217;ll be sticking with attributes.  It&#8217;s a cleaner, faster solution, period.  Yours is very clever but not practical for commercial, high-performance, team-driven applications.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: The Week in Code &#171; Sgt. Conker</title>
		<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/comment-page-1#comment-446</link>
		<dc:creator>The Week in Code &#171; Sgt. Conker</dc:creator>
		<pubDate>Thu, 15 Oct 2009 14:15:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.luminance.org/?p=315#comment-446</guid>
		<description>[...] Changing constants at runtime Interesting way to get MotoGP: tweakables into your XNA FX based game [...]</description>
		<content:encoded><![CDATA[<p>[...] Changing constants at runtime Interesting way to get MotoGP: tweakables into your XNA FX based game [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kael</title>
		<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/comment-page-1#comment-423</link>
		<dc:creator>Kael</dc:creator>
		<pubDate>Fri, 02 Oct 2009 16:32:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.luminance.org/?p=315#comment-423</guid>
		<description>Again, I think I agree with you in principle but I can&#039;t agree with some of your conclusions here:

Constant&lt;float&gt; having implicit conversions to/from float is not inherently bad in any particular way. There are always ways in which implicit conversions can trip you up, but they&#039;re not guaranteed to cause issues. In this case, it is highly unlikely that an implicit conversion to/from Constant&lt;float&gt; is going to do anything bad: There will be no silent loss of data, and no silent execution of code. Furthermore, an accidental implicit conversion in this case is extremely unlikely.

I also don&#039;t understand your assertion that this use of implicit conversions violates the strong typing of the language. There&#039;s nothing soft or fuzzy going on here; the only remotely unclear thing is what happens when you assign a value like &#039;9.3&#039; to a field of type Constant&lt;float&gt;. I would hope that even a junior programmer could quickly understand the meaning of such a statement.

The decision basically comes down to this: Do you want to manually write out &#039;new Constant&lt;float&gt;(x)&#039; or just write &#039;x&#039;? If you choose the latter, you&#039;re paying a cost by introducing some &#039;magic&#039; (the implicit conversion) in order to reduce the amount of duplication within your codebase.

The suggestion that it could be a performance problem is a strange one. Of course everything has an implicit cost, but I find it highly unlikely that an implicit conversion from Constant&lt;float&gt; to float would ever show up on profiles. It&#039;s definitely never shown up on mine.

The only real significant performance impact I can think of is that it eliminates the opportunity for the compiler/JIT to perform constant folding, which could be a real problem in high performance math loops. Even then, though, I&#039;d have to see a significant overhead in profiles before I&#039;d believe it.

At worst, you&#039;re paying the cost of a method call and a read from memory to fetch the value - that&#039;s it. And theoretically, the .NET JIT can inline the implicit conversion (They don&#039;t ever guarantee that it *will*, but the documentation says it can.)

The attributes still don&#039;t seem any smaller than my approach to me. C# attribute syntax is too noisy for it to be a win on size. The fact that the attributes are decoupled from the rest of the declaration is potentially a win, I suppose, but I&#039;ve never needed that.

Being able to use #if to make a constant not a constant anymore doesn&#039;t seem particularly useful for me. I can&#039;t think of a possible use case for this where it wouldn&#039;t result in tremendous duplication. Of course, you can do this with my approach too - just #if/#else out the type part of the declaration - but I can&#039;t imagine a good reason to do that either.

Saying you don&#039;t need IConstant or ConstantManager suggests that you missed the purpose of those classes: Those are there specifically to enable simple, type-safe manipulation of your constants. There&#039;s no way to magically get that functionality for free; it has to come from somewhere.

I also find your assertion that attribute reflection is faster to be dubious. Do you have any data to support this? Finding fields by attribute isn&#039;t any faster than finding them by type as I understand it, since in both cases you have to enumerate defined types and then enumerate their fields in order to check each field for its attributes. Is there a helper &#039;search&#039; method somewhere in the Framework that performs this search for you more efficiently when aimed at custom attributes?

The suggestion that this approach &#039;spits in the face of OOP&#039; confuses me. I don&#039;t understand. I wanted to be able to modify constants, so I created an object to represent a modifiable constant. I don&#039;t see how this is inherently less pure OO than using an attribute.

I&#039;m also not sure what &#039;pro world&#039; you refer to in which techniques like this don&#039;t fly. I&#039;ve seen far worse techniques ship in commercial codebases. In the end, the determination is up to the people working on the app, and hopefully they make their choices based on what actually works, not based on fear or rhetoric. If this solution didn&#039;t solve my problems, I wouldn&#039;t be using it.</description>
		<content:encoded><![CDATA[<p>Again, I think I agree with you in principle but I can&#8217;t agree with some of your conclusions here:</p>
<p>Constant&lt;float&gt; having implicit conversions to/from float is not inherently bad in any particular way. There are always ways in which implicit conversions can trip you up, but they&#8217;re not guaranteed to cause issues. In this case, it is highly unlikely that an implicit conversion to/from Constant&lt;float&gt; is going to do anything bad: There will be no silent loss of data, and no silent execution of code. Furthermore, an accidental implicit conversion in this case is extremely unlikely.</p>
<p>I also don&#8217;t understand your assertion that this use of implicit conversions violates the strong typing of the language. There&#8217;s nothing soft or fuzzy going on here; the only remotely unclear thing is what happens when you assign a value like &#8216;9.3&#8242; to a field of type Constant&lt;float&gt;. I would hope that even a junior programmer could quickly understand the meaning of such a statement.</p>
<p>The decision basically comes down to this: Do you want to manually write out &#8216;new Constant&lt;float&gt;(x)&#8217; or just write &#8216;x&#8217;? If you choose the latter, you&#8217;re paying a cost by introducing some &#8216;magic&#8217; (the implicit conversion) in order to reduce the amount of duplication within your codebase.</p>
<p>The suggestion that it could be a performance problem is a strange one. Of course everything has an implicit cost, but I find it highly unlikely that an implicit conversion from Constant&lt;float&gt; to float would ever show up on profiles. It&#8217;s definitely never shown up on mine.</p>
<p>The only real significant performance impact I can think of is that it eliminates the opportunity for the compiler/JIT to perform constant folding, which could be a real problem in high performance math loops. Even then, though, I&#8217;d have to see a significant overhead in profiles before I&#8217;d believe it.</p>
<p>At worst, you&#8217;re paying the cost of a method call and a read from memory to fetch the value &#8211; that&#8217;s it. And theoretically, the .NET JIT can inline the implicit conversion (They don&#8217;t ever guarantee that it *will*, but the documentation says it can.)</p>
<p>The attributes still don&#8217;t seem any smaller than my approach to me. C# attribute syntax is too noisy for it to be a win on size. The fact that the attributes are decoupled from the rest of the declaration is potentially a win, I suppose, but I&#8217;ve never needed that.</p>
<p>Being able to use #if to make a constant not a constant anymore doesn&#8217;t seem particularly useful for me. I can&#8217;t think of a possible use case for this where it wouldn&#8217;t result in tremendous duplication. Of course, you can do this with my approach too &#8211; just #if/#else out the type part of the declaration &#8211; but I can&#8217;t imagine a good reason to do that either.</p>
<p>Saying you don&#8217;t need IConstant or ConstantManager suggests that you missed the purpose of those classes: Those are there specifically to enable simple, type-safe manipulation of your constants. There&#8217;s no way to magically get that functionality for free; it has to come from somewhere.</p>
<p>I also find your assertion that attribute reflection is faster to be dubious. Do you have any data to support this? Finding fields by attribute isn&#8217;t any faster than finding them by type as I understand it, since in both cases you have to enumerate defined types and then enumerate their fields in order to check each field for its attributes. Is there a helper &#8217;search&#8217; method somewhere in the Framework that performs this search for you more efficiently when aimed at custom attributes?</p>
<p>The suggestion that this approach &#8217;spits in the face of OOP&#8217; confuses me. I don&#8217;t understand. I wanted to be able to modify constants, so I created an object to represent a modifiable constant. I don&#8217;t see how this is inherently less pure OO than using an attribute.</p>
<p>I&#8217;m also not sure what &#8216;pro world&#8217; you refer to in which techniques like this don&#8217;t fly. I&#8217;ve seen far worse techniques ship in commercial codebases. In the end, the determination is up to the people working on the app, and hopefully they make their choices based on what actually works, not based on fear or rhetoric. If this solution didn&#8217;t solve my problems, I wouldn&#8217;t be using it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/comment-page-1#comment-414</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 29 Sep 2009 22:26:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.luminance.org/?p=315#comment-414</guid>
		<description>&quot;Considerably larger&quot; is completely untrue.  My approach is less code and i&#039;ll show you how......

You  initialize you classes just like I would initialize my attributes. You do them with an operator overload, which, most veteran programmers would say is very bad practice. Implicit conversion operators are sloppy at best and bad OOP practice as it blurs the lines of &#039;Strongly Typed Language&#039;. Non the less, we both are instantiating something with ONE line of code. So far, we are equal.


My attribute class is smaller than your constant class:


[AttributeUsage(AttributeTargets.Property)]
public class EditableUiProperty : Attribute
{
public EditableUiProperty (string name) { this.name = name; }
   string name;
}


Mine is 4 lines of code and has less members. So, now at this point, i&#039;m using less code than you&#039;re &quot;ICONSTANT&quot; or &quot;CONSTANT&quot; implementation. Also, if another developer looked at this, they wouldn&#039;t even need to ask me what&#039;s going on, it just makes sense and is clearly readable when it&#039;s used......


[EditableUiProperty(&quot;Boss&quot;)]
public float BossPunchDamage = 8;


Now, i have no need for &quot;IConstant&quot; or the &quot;ConstantManager &quot;. So i don&#039;t even code those.

So now, at this point, i&#039;m using  way less code. 

We both use reflection, but since mine is based on attributes, my reflection actually performs faster, instead of looking for instances of objects and finding them by type, like you do. 


In both approaches, we could choose to pull out this implementation so there is no sign of it in our production code.

Just like you said &quot;when you’re done tweaking, you can trivially pull them back out&quot;

You are not actually &#039;pulling anything out&#039;. You are changing the  TYPE of these members to a value type when it was previously a reference type. If you do performance tests before you pull out all YOUR implementation, the results will be different after you go back, and change all those &#039;constants&#039; to value types. 

In mine, i can do this.....

#if DEBUG
[assembly: AssemblyConfiguration(&quot;Debug&quot;)]
#endif
float BossPunchDamage

Wow! Now i don&#039;t need to touch my code. No going back and changing a ton of stuff. I just put my project into &#039;Release Build&#039; mode and those attributes no longer exist. It&#039;s impossible to do that with your approach. 

In mine, all the &#039;constants&#039; stay the same type. It&#039;s less obtrusive. My performance tests would be practically the same before and after. 

Remember, every time your code reads one of these values for the game logic, YOUR code does the implicit type conversion. This spits in the face of OOP and strongly typed programming and is a performance drop when you multiply it by 1000. 



On to XML parsing. If you don&#039;t know how to pull values from XML in  a few short lines, and wrap that into a reusable utility function, there are plenty of resources online. That&#039;s hardly as complicated as using StackFrame to actually change source code. 



Another benefit of my approach, is, you can write your &#039;variable editor application&#039; separate from your game, and actually perform these edits using only the assembly of your game, instead of all the source code. I know that defeats the purpose of this article, but i think it&#039;s a cleaner approach. 




In all, you say it&#039;s a taste thing, but i don&#039;t think it&#039;s that subjective. When you are coding in by yourself, then sure, nothing matters, but in pro world, this kind of stuff doesn&#039;t fly. 


I know you are sharing a cool thing you did, and i don&#039;t want to shoot you down for that. Any time a programmer takes the time to share thoughts online, it&#039;s a privilege for all of us. However, i think of the junior developers that might come across this and think this is totally great solution. So this is why i provide contrary evidence. And hey, who&#039;s to say anyone will read this far down anyway (ha!). 

That&#039;s my rant. I like some of the other articles on your site, and you&#039;re not a bad programmer. Keep up the good work.</description>
		<content:encoded><![CDATA[<p>&#8220;Considerably larger&#8221; is completely untrue.  My approach is less code and i&#8217;ll show you how&#8230;&#8230;</p>
<p>You  initialize you classes just like I would initialize my attributes. You do them with an operator overload, which, most veteran programmers would say is very bad practice. Implicit conversion operators are sloppy at best and bad OOP practice as it blurs the lines of &#8216;Strongly Typed Language&#8217;. Non the less, we both are instantiating something with ONE line of code. So far, we are equal.</p>
<p>My attribute class is smaller than your constant class:</p>
<p>[AttributeUsage(AttributeTargets.Property)]<br />
public class EditableUiProperty : Attribute<br />
{<br />
public EditableUiProperty (string name) { this.name = name; }<br />
   string name;<br />
}</p>
<p>Mine is 4 lines of code and has less members. So, now at this point, i&#8217;m using less code than you&#8217;re &#8220;ICONSTANT&#8221; or &#8220;CONSTANT&#8221; implementation. Also, if another developer looked at this, they wouldn&#8217;t even need to ask me what&#8217;s going on, it just makes sense and is clearly readable when it&#8217;s used&#8230;&#8230;</p>
<p>[EditableUiProperty("Boss")]<br />
public float BossPunchDamage = 8;</p>
<p>Now, i have no need for &#8220;IConstant&#8221; or the &#8220;ConstantManager &#8220;. So i don&#8217;t even code those.</p>
<p>So now, at this point, i&#8217;m using  way less code. </p>
<p>We both use reflection, but since mine is based on attributes, my reflection actually performs faster, instead of looking for instances of objects and finding them by type, like you do. </p>
<p>In both approaches, we could choose to pull out this implementation so there is no sign of it in our production code.</p>
<p>Just like you said &#8220;when you’re done tweaking, you can trivially pull them back out&#8221;</p>
<p>You are not actually &#8216;pulling anything out&#8217;. You are changing the  TYPE of these members to a value type when it was previously a reference type. If you do performance tests before you pull out all YOUR implementation, the results will be different after you go back, and change all those &#8216;constants&#8217; to value types. </p>
<p>In mine, i can do this&#8230;..</p>
<p>#if DEBUG<br />
[assembly: AssemblyConfiguration("Debug")]<br />
#endif<br />
float BossPunchDamage</p>
<p>Wow! Now i don&#8217;t need to touch my code. No going back and changing a ton of stuff. I just put my project into &#8216;Release Build&#8217; mode and those attributes no longer exist. It&#8217;s impossible to do that with your approach. </p>
<p>In mine, all the &#8216;constants&#8217; stay the same type. It&#8217;s less obtrusive. My performance tests would be practically the same before and after. </p>
<p>Remember, every time your code reads one of these values for the game logic, YOUR code does the implicit type conversion. This spits in the face of OOP and strongly typed programming and is a performance drop when you multiply it by 1000. </p>
<p>On to XML parsing. If you don&#8217;t know how to pull values from XML in  a few short lines, and wrap that into a reusable utility function, there are plenty of resources online. That&#8217;s hardly as complicated as using StackFrame to actually change source code. </p>
<p>Another benefit of my approach, is, you can write your &#8216;variable editor application&#8217; separate from your game, and actually perform these edits using only the assembly of your game, instead of all the source code. I know that defeats the purpose of this article, but i think it&#8217;s a cleaner approach. </p>
<p>In all, you say it&#8217;s a taste thing, but i don&#8217;t think it&#8217;s that subjective. When you are coding in by yourself, then sure, nothing matters, but in pro world, this kind of stuff doesn&#8217;t fly. </p>
<p>I know you are sharing a cool thing you did, and i don&#8217;t want to shoot you down for that. Any time a programmer takes the time to share thoughts online, it&#8217;s a privilege for all of us. However, i think of the junior developers that might come across this and think this is totally great solution. So this is why i provide contrary evidence. And hey, who&#8217;s to say anyone will read this far down anyway (ha!). </p>
<p>That&#8217;s my rant. I like some of the other articles on your site, and you&#8217;re not a bad programmer. Keep up the good work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kael</title>
		<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/comment-page-1#comment-412</link>
		<dc:creator>Kael</dc:creator>
		<pubDate>Tue, 29 Sep 2009 14:48:50 +0000</pubDate>
		<guid isPermaLink="false">http://www.luminance.org/?p=315#comment-412</guid>
		<description>Most of your points are accurate, but it&#039;s not remotely any less code. The custom attribute and need to initialize in specific places, along with the need for XML parsing, makes it considerably larger. The use of an attribute for categorizing constants is a cool idea, but I haven&#039;t needed to do that yet since constants are always members of a given class anyway.

There&#039;s no real performance benefit; I&#039;m not sure I ever suggested there was one. The point of this approach is to avoid having to repeat yourself and only need to make minimal changes to your code (essentially, you replace &#039;const x y&#039; with &#039;Constant y&#039;, which you can trivially do with a regex) in order to enable tweaking values. And when you&#039;re done tweaking, you can trivially pull them back out.

Ultimately it all comes down to taste, though. Using attributes to tag things and saving/loading from a file was an approach I considered initially; I ended up going with this approach after reading about a similar one implemented in C using macros, just to see how it worked out.</description>
		<content:encoded><![CDATA[<p>Most of your points are accurate, but it&#8217;s not remotely any less code. The custom attribute and need to initialize in specific places, along with the need for XML parsing, makes it considerably larger. The use of an attribute for categorizing constants is a cool idea, but I haven&#8217;t needed to do that yet since constants are always members of a given class anyway.</p>
<p>There&#8217;s no real performance benefit; I&#8217;m not sure I ever suggested there was one. The point of this approach is to avoid having to repeat yourself and only need to make minimal changes to your code (essentially, you replace &#8216;const x y&#8217; with &#8216;Constant y&#8217;, which you can trivially do with a regex) in order to enable tweaking values. And when you&#8217;re done tweaking, you can trivially pull them back out.</p>
<p>Ultimately it all comes down to taste, though. Using attributes to tag things and saving/loading from a file was an approach I considered initially; I ended up going with this approach after reading about a similar one implemented in C using macros, just to see how it worked out.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/comment-page-1#comment-409</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 29 Sep 2009 12:30:51 +0000</pubDate>
		<guid isPermaLink="false">http://www.luminance.org/?p=315#comment-409</guid>
		<description>Also, in response to #kreppa#  the UI question.... 
yeah, i personally like using WinForms (just like #kael# said) and loading the game inside a form.

Another option in the xWinForms library. It&#039;s almost ALL the controls from real WinForms, re-coded from scratch to work in XNA. 

Because it&#039;s re-coded from scratch, It&#039;s buggy as hell, but i have personally implemented it and works cool. Luckily, the source code is provided, as i needed to change several things in their code. Still an awesome effort that deserves a look.

http://www.gameprojects.com/project/?id=e68f3464c4</description>
		<content:encoded><![CDATA[<p>Also, in response to #kreppa#  the UI question&#8230;.<br />
yeah, i personally like using WinForms (just like #kael# said) and loading the game inside a form.</p>
<p>Another option in the xWinForms library. It&#8217;s almost ALL the controls from real WinForms, re-coded from scratch to work in XNA. </p>
<p>Because it&#8217;s re-coded from scratch, It&#8217;s buggy as hell, but i have personally implemented it and works cool. Luckily, the source code is provided, as i needed to change several things in their code. Still an awesome effort that deserves a look.</p>
<p><a href="http://www.gameprojects.com/project/?id=e68f3464c4" rel="nofollow">http://www.gameprojects.com/project/?id=e68f3464c4</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/comment-page-1#comment-408</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 29 Sep 2009 11:47:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.luminance.org/?p=315#comment-408</guid>
		<description>And to clarify, the UI would only work on Windows, the actual game would have no issues with XBOX.</description>
		<content:encoded><![CDATA[<p>And to clarify, the UI would only work on Windows, the actual game would have no issues with XBOX.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike</title>
		<link>http://www.luminance.org/gruedorf/2009/03/30/changing-constants-at-runtime/comment-page-1#comment-407</link>
		<dc:creator>Mike</dc:creator>
		<pubDate>Tue, 29 Sep 2009 11:42:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.luminance.org/?p=315#comment-407</guid>
		<description>Hi,

It&#039;s neat but i think you completely over complicated something, and in the process, mangled symantics. 

What you have there are certainly not constants. I don&#039;t mean to nitpick, but in C# constant is a real word that has a very specific meaning. 

What you have are regular read only properties. What is the performance benefit to using this approach? None. You aim to create a solution to globally find all &#039;constants&#039; so you can edit them in your UI.  In most cases, while you are tweaking things, you don&#039;t need access to ALL constants in the assembly at once, and if your game has quite a lot, then you end up with a bloated UI and have to scroll forever to find your one property (in alphebeical order i assume). 

Your solution has no way to group these constants.

.NET made something for you that is much better than your approach. They are called attributes. Decorate your VARIABLES with custom attributes, 


[CustomGameConstantAttribute(&quot;BigBadEnemyBoss&quot;)]
private READONLY float BossPunchDamageAmount { get; set; }


Now, using a little reflection, you find ALL properties that have the &#039;CustomGameConstantAttribute&#039;. Better yet, you group them by the argument value and your UI can only load the &#039;constants&#039; for the &#039;bigBadEnemyBoss&#039;. You&#039;re UI could have a cool drop down list at the top so you can choose what group of &#039;constants&#039; you want to edit.

So now, you have an easy way to get to your constants. 

Even better, when it&#039;s time to ship your game, you simply remove the code that does the actual reflection, and what you have left are properties with attributes that are ignored..... no performance cost what so ever. 

Your approach leaves artifacts of your &#039;development process&#039; in your game code. 

In the actual running game, is there any reason to have those properties be your &#039;Constant&#039; type? Of course not. It&#039;s only needed to make it easy to edit while developing. So why make it part of the running game&#039;s architecture?

Also, your approach to writing your values back to the actual source code is dangerous. Code generation is cool, but this is not a good case study of it. Since these are NOT constants, write to XML, and populate the values at runtime. Your approach already throws the benefit of constants out the window. You can populate a static variable at runtime, no big deal. They can still be READ ONLY if you populate them inside the constructor. 




Those are my two cents. Of course, i&#039;m a college drop out, and maybe i missed your point, but i just layed out how i would solve your problem in less time, with less code, and no impact on the production code i ship to my customers while using preexisting mechanisms of .net.



Of course, i will assume you would not be doing this on XBOX, so this solution would only work on windows.  



I don&#039;t mean this to sound like a scathing attack. If i didn&#039;t care, i wouldn&#039;t write anything. Any maybe you can tear me a new one and i&#039;ll learn something.


Happy Coding

:)</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>It&#8217;s neat but i think you completely over complicated something, and in the process, mangled symantics. </p>
<p>What you have there are certainly not constants. I don&#8217;t mean to nitpick, but in C# constant is a real word that has a very specific meaning. </p>
<p>What you have are regular read only properties. What is the performance benefit to using this approach? None. You aim to create a solution to globally find all &#8216;constants&#8217; so you can edit them in your UI.  In most cases, while you are tweaking things, you don&#8217;t need access to ALL constants in the assembly at once, and if your game has quite a lot, then you end up with a bloated UI and have to scroll forever to find your one property (in alphebeical order i assume). </p>
<p>Your solution has no way to group these constants.</p>
<p>.NET made something for you that is much better than your approach. They are called attributes. Decorate your VARIABLES with custom attributes, </p>
<p>[CustomGameConstantAttribute("BigBadEnemyBoss")]<br />
private READONLY float BossPunchDamageAmount { get; set; }</p>
<p>Now, using a little reflection, you find ALL properties that have the &#8216;CustomGameConstantAttribute&#8217;. Better yet, you group them by the argument value and your UI can only load the &#8216;constants&#8217; for the &#8216;bigBadEnemyBoss&#8217;. You&#8217;re UI could have a cool drop down list at the top so you can choose what group of &#8216;constants&#8217; you want to edit.</p>
<p>So now, you have an easy way to get to your constants. </p>
<p>Even better, when it&#8217;s time to ship your game, you simply remove the code that does the actual reflection, and what you have left are properties with attributes that are ignored&#8230;.. no performance cost what so ever. </p>
<p>Your approach leaves artifacts of your &#8216;development process&#8217; in your game code. </p>
<p>In the actual running game, is there any reason to have those properties be your &#8216;Constant&#8217; type? Of course not. It&#8217;s only needed to make it easy to edit while developing. So why make it part of the running game&#8217;s architecture?</p>
<p>Also, your approach to writing your values back to the actual source code is dangerous. Code generation is cool, but this is not a good case study of it. Since these are NOT constants, write to XML, and populate the values at runtime. Your approach already throws the benefit of constants out the window. You can populate a static variable at runtime, no big deal. They can still be READ ONLY if you populate them inside the constructor. </p>
<p>Those are my two cents. Of course, i&#8217;m a college drop out, and maybe i missed your point, but i just layed out how i would solve your problem in less time, with less code, and no impact on the production code i ship to my customers while using preexisting mechanisms of .net.</p>
<p>Of course, i will assume you would not be doing this on XBOX, so this solution would only work on windows.  </p>
<p>I don&#8217;t mean this to sound like a scathing attack. If i didn&#8217;t care, i wouldn&#8217;t write anything. Any maybe you can tear me a new one and i&#8217;ll learn something.</p>
<p>Happy Coding</p>
<p> <img src='http://www.luminance.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
