Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Language: C# w/ XNA Framework

Relevant and Hopefully Helpful Background Info: I am making a library using the XNA framework for games I make with XNA. The Library has a folder(Namespace) dedication to the GUI. The GUI Controls inherit a base class hooked with the appropriate Interfaces. After a control is made, the programmer can hook the control with a "Frame" or "Module" that will tell the controls when to update and draw with an event. To make a "Frame" or "Module", you would inherit a class with the details coded in. (Kind of how win forms does it.) My reason for doing this is to simplify the process of creating menus with intractable controls. The only way I could think of for making the events for all the controls to function without being class specific would be to typecast a control to an object and typecast it back. (As I have read, this can be terribly inefficient.)

Problem: Unfortunately, after I have implemented interfaces into the base classes and changed

public delegate void ClickedHandler(BaseControl cntrl); 

to

public delegate void ClickedHandler(Object cntrl, EventArgs e);

my game has decreased in performance. This performance could be how I am firing the events, as what happens is the one menu will start fine, but then slowly but surely will freeze up. Every other frame works just fine, I just think it has something to do with the events and... that is why I am asking about them.

Question: Is there a better more industry way of dealing with GUI Libraries other then using and implementing Events?

Goal: To create a reusable feature rich XNA Control Library implementing performance enhancing standards and so on.

Thank-you very much for taking your time to read this. I also hope this will help others possibly facing what I am facing right now.

UPDATE: LAG SOLVED. The lag was caused do to an update method in my base text control. I had a mistake of running a loop a ton of times when it did not need to be ran.

I have also remove all instances of EventArgs from the library as I personally see no point in them.

share|improve this question
2  
Could you try profiling your code to see where the performance bottlenecks are? Also, you could take a look at Nuclex framework source to see how they do it, maybe you could pick up some good practices. –  Niko Drašković Nov 21 '12 at 21:54
    
Ahh, that's neat. I will surely look into it. Thanks! –  SchautDollar Nov 23 '12 at 4:13
1  
I also did some profiling and found the issue. Thanks! –  SchautDollar Nov 23 '12 at 4:20

2 Answers 2

up vote 1 down vote accepted

SOLUTION:

The lag was caused do to an update method in my base text control. I had a mistake of running a loop a ton of times when it did not need to be ran.

I have also remove all instances of EventArgs from the library as I personally see no point in them.

At this time, I have read quite a bit of posts saying events are appropriate for menus, but not necessarily for gameplay. The preferred way (That I have noticed.) is to use a state based form. So, really, you would check manually to see if something checks.

-Thanks for the help guys!

share|improve this answer

Wild stab in the dark:

You might have some events that fire very often (like every frame), for example OnMouseMove, and after your change of parameters you now create a new EventArgs at every call resulting in garbage piling up after a while. If I am correct then this should be more of an issue on x-box or windows phone than on PC.

A fix for this could be to not create EventArgs unless absolutely necessary for those calls that might happen very often but use value types instead. Or maybe use a circular buffer or something as an object pool for those eventargs.

I don't know how nuclex or the others do this, myself I have just avoided implementing calls that would occur too often.

share|improve this answer
    
I have removed all event args since, well.. I don't use them. Thanks for the idea. Also, I found where I had my lag come in. It was in my text box update solution. I have updated my question with what my problem was. –  SchautDollar Nov 23 '12 at 4:15
    
Ahh gotcha! You know you can post an answer yourself and mark it as accepted? –  Mikael Högström Nov 23 '12 at 18:13
    
Well,I do now. Thanks for the help. –  SchautDollar Nov 26 '12 at 18:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.