Click here to Skip to main content
16,021,293 members
Home / Discussions / Game Development
   

Game Development

 
Question'Self-aware' classes? Pin
Purge1t30-Oct-11 18:54
Purge1t30-Oct-11 18:54 
AnswerRe: 'Self-aware' classes? Pin
CDP180231-Oct-11 9:21
CDP180231-Oct-11 9:21 
GeneralRe: 'Self-aware' classes? Pin
Purge1t31-Oct-11 14:26
Purge1t31-Oct-11 14:26 
GeneralRe: 'Self-aware' classes? Pin
CDP180231-Oct-11 15:39
CDP180231-Oct-11 15:39 
AnswerRe: 'Self-aware' classes? Pin
_Maxxx_31-Oct-11 18:33
professional_Maxxx_31-Oct-11 18:33 
Questionmodel, shade, looksRealistic OpenGL Pin
appollosputnik25-Oct-11 3:34
appollosputnik25-Oct-11 3:34 
AnswerRe: model, shade, looksRealistic OpenGL Pin
CDP180225-Oct-11 5:10
CDP180225-Oct-11 5:10 
QuestionHow to set pixelz using XNA and C# Pin
CDP180213-Oct-11 21:57
CDP180213-Oct-11 21:57 
Send me all your codez. It's urgentz

Just joking Smile | :)

I do have a little problem, which is not at all unsolvable, but I just don't like to bend and tweak things just to make them fit. And, hopefully, I will not have to provide endless code listings. It's more a matter of making certain that some events happen in the right order.

For a while I have been writing a GUI for XNA and now I have started on the actual game client which is supposed to use it. As expected, there have been numerous smaller and larger bugs and missing features, so that I'm not getting ahead very quickly right now. But the GUI is really getting ahead and is more up to its job every day.

Last I added themes for the GUI. Among other things, the theme contains styles for controls. The styles come in two flavors: Control styles and named styles. Control styles are applied to all controls of a type. Named styles are additionally applied to all controls which explicitly request that style by name. The theme is loaded from XAML and the styles actually are simple data objects with all properties as nullable types. This allows you to incrementally apply a control style and then a named style by changing only those properties of the controls which are not null in the style. And here is where the problem begins.

This would be the best sequence:
1) An instance of a control is created. All its properties are set to defaults in the constructor.
2) Apply the control style according to the type of the control. Overwrite only those properties which are not null in the style.
3) Apply a named style, if any is set, again only overwriting the properties which are not null in the style
4) Controls and forms are also loaded from XAML. If there are any properties set in the markup, they should be set last to give them the highest priority and enable them to override defaults or styles.

This is how it really is:
1) An instance of a control is created. All its properties are set to defaults in the constructor.
2) Controls are instantiated when loading from XAML and the properties from the markup are set right after that. They now have the second lowest priority, not the highest as I would like.
3) Later, when the control is inserted into the GUI, further initialisation is done. At this point the control gets its reference to the loaded theme and now can find and apply its control style and its named style (if any).


As I see it, there is only one way to be faster than the XAML loader: The styles must be applied in the constructor already. The problem is that the theme will not be available to the control until it is inserted into the UI.

Now, I could simply pass the loaded theme as a parameter to the constructor, but that would also make dynamically instantiating controls more awkward. A class factory for the controls would help a little, but still this would be a departure from the way we are accustomed to. That's something I have tried to avoid. I also thought of making the theme a singleton, so that I can access it from the constructors with out having a reference, but this would not work and appears to me like a hack to make fit what does not fit.

So, how do I get a reference to the theme into the constructor without passing it as a parameter? Applying the styles in the constructor is the only way to make sure that things always happen in the right sequence, so there is no way around that. What is the cleanest and least 'hackish' way to accomplish this?

Edit: Constructor parameters are not an option for another reason as well: Any class to be used with XAML must be serializable. This includes having a standard constructor without parameters. Even if there were a second constructor, then XAML would not use it while loading the controls.

Edit^2: Almost a week now and no reply. The title must really have scared everybody Smile | :)
And from the clouds a mighty voice spoke:
"Smile and be happy, for it could come worse!"

And I smiled and was happy
And it came worse.



AnswerRe: How to set pixelz using XNA and C# Pin
rj4524-Oct-11 11:54
rj4524-Oct-11 11:54 
GeneralRe: How to set pixelz using XNA and C# Pin
CDP180225-Oct-11 2:02
CDP180225-Oct-11 2:02 
Questioni need your help Pin
gif202014-Sep-11 1:39
gif202014-Sep-11 1:39 
AnswerRe: i need your help Pin
Pete O'Hanlon14-Sep-11 2:13
mvePete O'Hanlon14-Sep-11 2:13 
GeneralRe: i need your help Pin
gif202014-Sep-11 6:10
gif202014-Sep-11 6:10 
GeneralRe: i need your help Pin
Pete O'Hanlon14-Sep-11 6:47
mvePete O'Hanlon14-Sep-11 6:47 
GeneralRe: i need your help Pin
gif202014-Sep-11 8:33
gif202014-Sep-11 8:33 
AnswerRe: i need your help Pin
Mahdi Nejadsahebi25-Sep-11 1:01
Mahdi Nejadsahebi25-Sep-11 1:01 
AnswerRe: i need your help Pin
Paul Conrad25-Oct-11 6:01
professionalPaul Conrad25-Oct-11 6:01 
AnswerRe: i need your help Pin
Peter Hawke28-Dec-11 13:03
Peter Hawke28-Dec-11 13:03 
QuestionMy first released game Pin
Thomas.D Williams21-Jul-11 5:18
Thomas.D Williams21-Jul-11 5:18 
AnswerRe: My first released game Pin
Richard MacCutchan28-Jul-11 3:41
mveRichard MacCutchan28-Jul-11 3:41 
GeneralRe: My first released game Pin
Thomas.D Williams28-Jul-11 6:06
Thomas.D Williams28-Jul-11 6:06 
GeneralRe: My first released game PinPopular
Richard MacCutchan28-Jul-11 6:10
mveRichard MacCutchan28-Jul-11 6:10 
GeneralRe: My first released game [modified] Pin
Rakesh Meel6-Sep-11 1:53
professionalRakesh Meel6-Sep-11 1:53 
GeneralRe: My first released game [modified] Pin
CDP180229-Aug-11 22:47
CDP180229-Aug-11 22:47 
GeneralRe: My first released game Pin
Richard MacCutchan8-Sep-11 7:18
mveRichard MacCutchan8-Sep-11 7:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.