//////////////////////////////////////////////////////////////////////
// Application INIT
//////////////////////////////////////////////////////////////////////
int Application::Init()
{
WNDCLASS WndCls;
extern LRESULT CALLBACK WindowProc (HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam);
WndCls.style = CS_HREDRAW | CS_VREDRAW;
WndCls.lpfnWndProc = WindowProc;
WndCls.cbClsExtra = 0;
WndCls.cbWndExtra = 0;
WndCls.hInstance = Instance;
WndCls.hIcon = LoadIcon( Instance, MAKEINTRESOURCE( IDI_ICON1 ) );
WndCls.hCursor = LoadCursor( NULL, IDC_ARROW );
WndCls.hbrBackground = ( HBRUSH ) GetStockObject( BLACK_BRUSH );
WndCls.lpszMenuName = NULL;
WndCls.lpszClassName = "My Game";
RegisterClass( &WndCls );
hwnd = CreateWindowEx( WS_EX_TOPMOST, "My Game", "My Game", WS_POPUP, 0, 0,
GetSystemMetrics( SM_CXSCREEN ), GetSystemMetrics( SM_CYSCREEN ), NULL,
NULL, Instance, NULL );
ShowWindow (hwnd, nCmdShow );
//
// DDraw
//
DDMan.SetDisplayMode( 800, 600, 16 );
DDMan.Initialize();
PrimarySurface.SetSurfaceType( ( enum DirectDrawSurface::SurfaceType ) 0 );
DDMan.CreateSurface( PrimarySurface );
MessageBox(hwnd,"done w/ DD", "done", NULL );
//
// Input
//
InputMan.Initialize();
DIMouse Mouse;
InputMan.CreateMouse( Mouse );
MessageBox(hwnd,"done w/ DI", "done", NULL );
return MAINMENU;
}
Commenting out the MessageBox there at the end will make this function take about 10 seconds as opposed to 1/10 of a second or so.
~Vendayan
VERY weird problem
For some reason I have a function that takes about 10 seconds to finish running through, although if a add a messagebox at the VERY end, right before it returns the function will successfully finish seemingly in an instant.
Here''s the function if it helps. I just want to know how I can get this function to work fast w/o the message box.
well, it should take the same amount of time with each. you are passing the correct hwnd to dx right? cause from what i see, you are not and thats what is screwing your stuff up. then again you could be doing other things wrong, but i am no mind reader.
No, everything in that function works perfect, hwnd is a member of my application class with makes it nearly global for things such as initialization and such. Anyway the app does run from what I can tell just how I want it but if I comment out that LAST MessageBox the whole thing takes 10 seconds longer.
Commenting out the other messageboxes is fine and will run normal.
Commenting out the other messageboxes is fine and will run normal.
Try creating dinput devices with emulation on. To do this, check ''emulation'' in dinput in dx control panel.
try to replace the last MessageBox() with
that should help. if it doesnt i dont know.
bye,
--- foobar
We push more polygons before breakfast than most people do in a day
Edited by - foobar on February 22, 2002 8:59:27 PM
{ MSG msg; while( GetMessage( &msg, 0, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); }}
that should help. if it doesnt i dont know.
bye,
--- foobar
We push more polygons before breakfast than most people do in a day
Edited by - foobar on February 22, 2002 8:59:27 PM
No you guys are paying too much attention to what you don''t see in that bit. Everything in that function happens vetry smoothly and instantaneously when the MB is there but if it is removed it takes 10 seconds to make it to the message loop which is started immediately after this function.
~Vendayan
~Vendayan
Perhaps its because without the msgbox there are no messages sent to the message pump for around 10 seconds.
Maybe you could try replacing the msgbox with a SendMessage(hwnd) to see if this is the cause?
Perhaps its because you need to run the game code every frame, but where the gamerun() is means its only getting called when there is a message.
Something like the following should run the game every frame regardless of number of messages:-
Note you should put something in you GameRun() that limits it to say 60fps, using Sleeps or whatever. Otherwise windows tends to get upset.
Hope this helps.
Maybe you could try replacing the msgbox with a SendMessage(hwnd) to see if this is the cause?
Perhaps its because you need to run the game code every frame, but where the gamerun() is means its only getting called when there is a message.
Something like the following should run the game every frame regardless of number of messages:-
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ MSG msg; msg.wParam = 0; // Initialize global strings MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) return(FALSE); while (TRUE) { if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE)) { // Message pending. If it''s QUIT then exit the message loop if (WM_QUIT == msg.message) { DestroyWindow(hWnd); PostQuitMessage(0); break; } else { TranslateMessage(&msg); DispatchMessage(&msg); } } //run game code GameRun(); }//end while return(msg.wParam);}
Note you should put something in you GameRun() that limits it to say 60fps, using Sleeps or whatever. Otherwise windows tends to get upset.
Hope this helps.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement