# App's speed should be better but isn't !

## Recommended Posts

G_Axer    122
Hi, i have a little problem with speed of my game (I'm trying to make something like CD-Man/PacMan). I've read all tutorials and followed them, but the game still demands tooo much memory and isn't fast enough... Her it goes: I use these standard methods to run my app. This one is the main cycle-
public static void Run()
{
targetForm = new Form1();
targetForm.Show();

Init(targetForm);//Init method prepares graphic device
while (running)
{
m_StopWatch.Reset();
m_StopWatch.Start();

Application.DoEvents();
Update();//Goes through Update() method of every drawable object in the game.
Render();//Renders every drawable object

m_StopWatch.Stop();
m_CurrentFrameTime = (double)m_StopWatch.ElapsedTicks;

double delta = m_FrameTime - m_CurrentFrameTime;

if (delta > 0)
{
m_StopWatch.Reset();
m_StopWatch.Start();
while ((double)m_StopWatch.ElapsedTicks < delta) ;
m_StopWatch.Stop();
m_CurrentFrameTime += m_StopWatch.ElapsedTicks;
}

InfoTxt.Text = "FPS: " + CurrentFrameRate.ToString();
}
Application.Exit();
}


Here is Init() method-
private static void Init(Form targetForm)
{
FrameRate = 60;

PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = true;
presentParams.PresentationInterval = PresentInterval.Immediate;

dGDevice = new DGDevice(0, Microsoft.DirectX.Direct3D.DeviceType.Hardware, targetForm, CreateFlags.SoftwareVertexProcessing, presentParams);

dGDevice.RenderState.ReferenceAlpha = 0;
dGDevice.RenderState.AlphaFunction = Compare.NotEqual;

dXSprite = new D3DSprite(dGDevice);
}


Pictures in my game are represented as Microsoft.DirectX.Direct3D.Texture and are drawn with Sprite.Draw2D() method Now: + My (and the tutorial's game)FPS is hardly 60. + Application needs approximately 25MB of memory (which is terrible, because the window of the game is exactly same big as window of microsoft's Pinball3D game (the one you get automatically with WinXP), but Pinball3D is happy with 3MB) Do you have some tips, please?? I want to make my first game that is not just a pathetic parody of a game :-) and i have these obstacles. Thx very much for any suggestions. G'Axer

##### Share on other sites
ToohrVyk    1595
For performance:

1- Find a profiler
2- Profile
3- Rework the slowest parts

Honestly, there's generally not much a human can do, except guesswork. Profilers are your best friend.

For memory:

What sizes are the textures you use? These are generally the most heavy consumers of memory.

##### Share on other sites
imbusy    106
How do you calculate memory usage? Are you sure the 60fps limit is not because of the vertical sync?

##### Share on other sites
G_Axer    122
To ToohrVyk:
+ Profiler is a good idea, but unfortunately i'm relatively new to programming, so i don't know about any recommended... Would you please write here name of some profiler (or link)? Thx

+Textures shouldn't be a biggie. I use only about 10 pictures 32x32p in the game at the moment.

##### Share on other sites
G_Axer    122
To imbusy:
+I've calculate memory usage with the thing you get when you press CTRL+ALT+DEL (I'm sorry I have windows in czech language and therefore I don't know how is it called in english :-) )
+V-sync is not "the problem", i have LCD monitor :-). It must be something else, for example, when mouse cursor goes over game window FPS falls to 10 (ugh :-X).

##### Share on other sites
Evil Steve    2017
Quote:
 Original post by G_Axer+V-sync is not "the problem", i have LCD monitor :-). It must be something else, for example, when mouse cursor goes over game window FPS falls to 10 (ugh :-X).
LCD monitors still have V-sync from an applications point of view.

I seem to recall a thread around here recently where tooltips caused the FPS of DirectX apps to plummet, but I can't remember any more details than that...

##### Share on other sites
Wolfdog    268
What is happening inside of Application.DoEvents(); I have a feeling something is happening with the WM_MOUSEMOVE windows message perhaps that could kill your framerate when the mouse is over the window. I am guessing this is C# and i have no experience with it but i figure you must be processing messages.

##### Share on other sites
Enselic    829
Quote:
 Original post by G_Axer+ Application needs approximately 25MB of memory (which is terrible, because the window of the game is exactly same big as window of microsoft's Pinball3D game (the one you get automatically with WinXP), but Pinball3D is happy with 3MB)

There's a rumor that says that the big memory print is due to the .NET framework is loaded in that process aswell. I havevn't bothered to verify it but it seems reasonable to me.

Quote:
 Do you have some tips, please??

I see you are not .Dispose()-ing your Form, which you should do. If you don't then there's a risk that the window will stay visible for very long (since it is not garbage collected immediately) while being unresponsive. It is actually very encouraged to call .Dispose() on any object that uses unmanaged resources.

What tutorial are you basing this on? I am curious to poke with some of that code and see if I also get a crappy framerate.

##### Share on other sites
sirob    1181
What's this?
                if (delta > 0)                {                    m_StopWatch.Reset();                    m_StopWatch.Start();                    while ((double)m_StopWatch.ElapsedTicks < delta) ;                    m_StopWatch.Stop();                    m_CurrentFrameTime += m_StopWatch.ElapsedTicks;                }

You shouldn't have a while loop that does nothing but wait for a certain amount of time to pass, that's just silly.

I'm not sure what this does, but I can't see any code that actually calculates the FPS. Are you sure it isn't just showing the 60 you set it to originally and never getting updated?

EDIT: I also see you're showing the FPS every frame using infoTxt.Text. I'm assuming this is some kind of control, which would also be slow.

Hope this helps.

##### Share on other sites
G_Axer    122
To sirob:
+The cycle that do nothing is there intentionally - it protects app to have FPS higher than intended 60. So it is no error for sure. In ideal case the app will have precisely wanted 60.
+I don't think that randering one line of text needs more memory than rendering normal texture.

But anyway, thanks for tips ;-)