Sign in to follow this  
marshdabeachy

Better performance with... Flash?

Recommended Posts

This seems absolutely bizarre to me, since it makes no sense, but it seems that my DirectX programs encounter hitching and stuttering unless I have the Macromedia Flash Player running in the background. As soon as I open an instance of the Flash Player, the hitching almost completely disappears. This isn't just my computer either, if I move the EXE to another system the same thing occurs. I have no idea what the link between these things are. Has anyone else experienced this?

Share this post


Link to post
Share on other sites
That is incredibly bizzare. It makes me think that it has something to do with your initialization code or your main program loop. How is your CPU usage for your program?

Share this post


Link to post
Share on other sites
I know sometimes on my comp (a Mac running OSX btw), I used to be able to get a great performance boost in my OpenGL apps simply by shuffling my mouse cursor through the menubar, which, technically, should decrease performance. I don't know why this happened or under what exact circumstances, and of course, this is a completely different OS...but it seems to be the same type of thing somewhat.

Share this post


Link to post
Share on other sites
Quote:
Original post by Moe
That is incredibly bizzare. It makes me think that it has something to do with your initialization code or your main program loop. How is your CPU usage for your program?


I won't have access to the program until tonight (at work right now), but I believe it hangs around 10%. I don't remember it spiking at all, but I'll double-check.

Share this post


Link to post
Share on other sites
Is that a managed program? Not that I'd be able to explain this either way, but strange performance changes happened to me with managed.

Share this post


Link to post
Share on other sites
I don't even know what a "managed program" is, so probably not (I'm new to DirectX). It's just a standard Windows program. I'm using code from my instructor (from DigiPen) for the window wrapper. I asked him about the problem and he had no idea either. It may be somewhere in his code though.

Share this post


Link to post
Share on other sites
This definatly sounds like a render loop issue to me. I'd guess Flash's drawings cause an invalidation of some sort in your app, triggering the rendering faster.

What language are you using? And can you possibly paste the code to it?

Hope this helps.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Flash is probelly changing windows internal timer resolution with timeBeginPeriod() as some mediaplayers do too. BTDT.

Share this post


Link to post
Share on other sites
I am using C++. I will post when I get home later tonight with the loop code.

As a side note, Flash doesn't have to be running in an open window for this to occur. It just has to be a process running in the background.

Share this post


Link to post
Share on other sites
Okay, here is the code for my main loop. I'm forcing the timeStep right now, but this problem happens either way.


int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) {
MSG msg = {0};
HACCEL hAccelTable;

// Initialize resources
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MODE7);

CMainWindow* pMainWindow = CMainWindow::CreateMainWindow( hInstance, szTitle );

if (pMainWindow)
{
// Main message loop:
while(msg.message != WM_QUIT) {
Sleep( 10 );
while( PeekMessage( &msg, NULL, 0, 0, TRUE ) ) {
TranslateMessage( &msg );
DispatchMessage( &msg );
}
// update game
pMainWindow->Update(
0.02f, // timestep
GetAsyncKeyState( VK_LEFT ) & 0x8000, // holding left
GetAsyncKeyState( VK_RIGHT ) & 0x8000, // holding right
GetAsyncKeyState( VK_UP ) & 0x8000, // holding up
GetAsyncKeyState( VK_DOWN ) & 0x8000 // holding down
);
}

delete pMainWindow;
}

return (int) msg.wParam;
}



I checked the CPU usage, and came up with some interesting results. When Flash is not running, my program is using roughly 0-2% of the CPU (and is choppy as hell). As soon as I open Flash, my program jumps to 35-45% CPU usage, and becomes noticably smoother.

And as a sidenote, what is the tag on these forums for code?

[Edited by - marshdabeachy on May 17, 2006 11:07:47 PM]

Share this post


Link to post
Share on other sites
Something you might want to think about is that maybe your pMainWindow->Update() function is being called too often. Perhaps running Flash increasing processor load enough that the hijinks aren't noticeable.

I had a problem with the app I'm currently working on that checked for mouse updates in the render loop, which was tied down to 60 fps. The problem was, my mouse updates would look for the change from the last mouse check, not absolute positions. I didn't notice any problems on my slow laptop, but when I tested it on my desktop, none of my camera rotations worked! What was going on was that my mouse update was actually just OUTSIDE of the part of the loop that was tied to 60 fps, so it was updating the mouse, skipping the render, then clearing the mouse change by the time it came time to render, causing my camera to have trouble rotating. The problem would only be cleared up when I was running on a slower processor or running lots of intensive apps. Once I moved the mouse update INSIDE the 60 fps-tied loop, everything worked fine.

Moral of the story is, perhaps it has nothing to do with Flash other than that Flash is typically processor-intensive. Maybe it's slowing your program execution down just far enough that it runs smoothly. I'd double-check your timing.

EDIT: Hitching and stuttering is JUST how I would describe my mouse issue.

Share this post


Link to post
Share on other sites
The thing is, even the Flash authoring environment (which uses a sum total of 0% CPU usage) makes it run faster. Additionally, I use a web browser called Avant, and THIS program fixes the problem too (perhaps Avant initializes Flash in some way, I don't know). Internet Explorer doesn't do anything unless an instance of the Flash player is running.

Quote:

is the program set to low priority?


No, it is set to normal.

Share this post


Link to post
Share on other sites
What happens if you change the Sleep(10) to Sleep(0)? I'm willing to bet that's why the CPU usage is at 2%, your app is inactive for most of the time. Although, that should give you a maximum of 100FPS...

Share this post


Link to post
Share on other sites
My best geuss - you've got Vertical Sync enabled, and Flash disables it. What's the frame-rate that you're getting with no Flash? If its consistently within 1 frame of your monitor's refresh rate, then chances are, this is the problem.

Also, check your graphics cards settings and check for Vertical Snyc(sometimes its vsync), try turning that off(if it isn't already) and see if you get the same boost as with Flash running in the background. Most computers have vsync enabled, which would explain why this happened on other computers, too).

However, I've never heard of one program enabling vsync for other programs, too, but then again, I rarely run two DirectX/OpenGL programs at the same time that both fiddle with the vsync settings.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
It's funny to see all the theory's when the solution and cause already are mentioned. Do some research on timeBeginPeriod()

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this