int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { Psx *psx = Psx::GetInstance(); CoInitialize(0); if (!CreateMainWindows(psx)) { return 1; } CreateThreads(psx); DWORD start = timeGetTime(); static char title[256]; while (!psx->quit) { if (psx->cpu->state == PSX_CPU_RUNNING) { if (timeGetTime()-start > 1000) { float speed = ((float)psx->cpu->mTotalCycles / Psx::CPU_CLOCK) * 100.0; sprintf_s(title, 256, "%.2f fps (%.2f%%)", (speed / 100.0) * 60.0, speed); SetWindowText(psx->mDispWnd->GetHwnd(), title); start = timeGetTime(); psx->cpu->mTotalCycles = 0; } } else { SetWindowText(psx->mDispWnd->GetHwnd(), "Paused"); } Window::ProcessMessages(); Sleep(10); } return psx->mMainWnd->GetMsg().wParam; }
//----------------------------------------------------------------------------- // Entry point into the program. //----------------------------------------------------------------------------- int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, INT nCmdShow) { Instance = hInstance; InitCommonControls(); // A monospaced font FixedFont = CreateFont(SS.TW.CHAR_HEIGHT, SS.TW.CHAR_WIDTH, 0, 0, FW_REGULAR, false, false, false, ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, FF_DONTCARE, "Lucida Console"); if(!FixedFont) FixedFont = (HFONT)GetStockObject(SYSTEM_FONT); // Create the root windows: one for control, with text, and one for // the graphics CreateMainWindows(); ThawWindowPos(TextWnd); ThawWindowPos(GraphicsWnd); ShowWindow(TextWnd, SW_SHOWNOACTIVATE); ShowWindow(GraphicsWnd, SW_SHOW); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(GetDC(GraphicsWnd)); glClearColor(0, 0, 0, 1); glClear(GL_COLOR_BUFFER_BIT); SwapBuffers(GetDC(GraphicsWnd)); // Create the heaps for all dynamic memory (AllocTemporary, MemAlloc) InitHeaps(); // A filename may have been specified on the command line; if so, then // strip any quotation marks, and make it absolute. char file[MAX_PATH] = ""; if(strlen(lpCmdLine)+1 < MAX_PATH) { char *s = lpCmdLine; while(*s == ' ' || *s == '"') s++; strcpy(file, s); s = strrchr(file, '"'); if(s) *s = '\0'; } if(*file != '\0') { GetAbsoluteFilename(file); } #ifdef HAVE_SPACEWARE // Initialize the SpaceBall, if present. Test if the driver is running // first, to avoid a long timeout if it's not. HWND swdc = FindWindow("SpaceWare Driver Class", NULL); if(swdc != NULL) { SiOpenData sod; SiInitialize(); SiOpenWinInit(&sod, GraphicsWnd); SpaceNavigator = SiOpen("GraphicsWnd", SI_ANY_DEVICE, SI_NO_MASK, SI_EVENT, &sod); SiSetUiMode(SpaceNavigator, SI_UI_NO_CONTROLS); } #endif // Call in to the platform-independent code, and let them do their init SS.Init(); if(strcmp(file, "")) SS.OpenFile(file); // And now it's the message loop. All calls in to the rest of the code // will be from the wndprocs. MSG msg; DWORD ret; while((ret = GetMessage(&msg, NULL, 0, 0)) != 0) { #ifdef HAVE_SPACEWARE // Is it a message from the six degree of freedom input device? if(ProcessSpaceNavigatorMsg(&msg)) goto done; #endif // A message from the keyboard, which should be processed as a keyboard // accelerator? if(msg.message == WM_KEYDOWN) { if(ProcessKeyDown(msg.wParam)) goto done; } if(msg.message == WM_SYSKEYDOWN && msg.hwnd == TextWnd) { // If the user presses the Alt key when the text window has focus, // then that should probably go to the graphics window instead. SetForegroundWindow(GraphicsWnd); } // None of the above; so just a normal message to process. TranslateMessage(&msg); DispatchMessage(&msg); done: SS.DoLater(); } #ifdef HAVE_SPACEWARE if(swdc != NULL) { if(SpaceNavigator != SI_NO_HANDLE) SiClose(SpaceNavigator); SiTerminate(); } #endif // Write everything back to the registry FreezeWindowPos(TextWnd); FreezeWindowPos(GraphicsWnd); // Free the memory we've used; anything that remains is a leak. SK.Clear(); SS.Clear(); return 0; }