//-------------------------------------------------------------- // global initialization called in main.m void initFramework( const char* resourceDir) { chdir(resourceDir); mgOSLaunchSendLog(); // initialize random numbers time_t seed; time(&seed); srand(12123123); // srand(seed & 0xFFFF); mgDebugReset(); // reset trace file mgDebug(":Program: %s", mgProgramName != NULL ? mgProgramName : "unknown"); mgDebug(":Program Version: %s", mgProgramVersion != NULL ? mgProgramVersion : "unknown"); char machineID[256]; getPlatformUUID(machineID, sizeof(machineID)-1); machineID[sizeof(machineID)-1] = '\0'; mgDebug(":Machine Id: %s", machineID); struct utsname name; if (uname(&name) != -1) { mgDebug(":OS: %s", name.sysname); mgDebug(":Machine 64-bit: %s", strstr(name.machine, "_64") != NULL ? "true" : "false"); } else mgDebug(":OS: OSX"); const int MAX_DISPLAYS = 20; uint32_t displayCount; CGGetActiveDisplayList(MAX_DISPLAYS, NULL, &displayCount); mgDebug(":Machine Monitor count: %d", displayCount); CGDirectDisplayID mainDisplay = CGMainDisplayID(); mgDebug(":Machine Monitor res: %d by %d", CGDisplayPixelsWide(mainDisplay), CGDisplayPixelsHigh(mainDisplay)); mgOSInitTimer(); // performance timer atexit(termFramework); }
//-------------------------------------------------------------- // main entry int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { #ifdef DEBUG_MEMORY mgDebugMemoryInit(); #endif mgDebugReset(); // reset trace file mgOSInitTimer(); // performance timer // initialize random numbers time_t seed; time(&seed); srand(12123123); // srand(seed & 0xFFFF); mgOSFindWD("docs"); // handle utility error messages m_errorTable = new mgUtilErrorTable(); try { initWindow(); createWindow(); createBitmap(); createUI(); // create the terrain m_flatWorld = new FlatWorld(); m_flatWorld->resize(m_windowWidth, m_windowHeight); m_ui->setValue(m_flatWorld->m_playerX, m_flatWorld->m_playerY); // check for screen update every 25 ms SetTimer(m_window, 123, 25, NULL); while (true) { MSG msg; // if there is no input pending if (!PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { // update any movement keys still down updateMovement(); // if the ui needs an update if (m_surface != NULL && m_surface->isDamaged()) { // redraw ui at damaged area mgRectangle bounds; m_surface->getDamage(bounds); m_ui->m_top->surfacePaint(bounds); // copy bits from surface into bitmap m_surface->repair(bounds); // tell windows to redraw the updated area RECT rect; rect.left = bounds.m_x; rect.right = rect.left + bounds.m_width; rect.top = bounds.m_y; rect.bottom = rect.top + bounds.m_height; InvalidateRect(m_window, &rect, false); } } GetMessage(&msg, NULL, 0, 0); // end on quit if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } // shutdown destroyUI(); destroyBitmap(); destroyWindow(); termWindow(); } catch (mgErrorMsg* e) { mgString msg; m_errorTable->msgText(msg, e); mgDebug("%s", (const char*) msg); MessageBox(m_window, msg, "Error", MB_OK | MB_ICONINFORMATION); return 0; } catch (mgException* e) { mgDebug("%s", (const char*) e->m_message); MessageBox(m_window, e->m_message, "Error", MB_OK | MB_ICONINFORMATION); return 0; } delete m_errorTable; m_errorTable = NULL; #ifdef DEBUG_MEMORY // display all memory leaks mgDebugMemory(); #endif return 0; }
//-------------------------------------------------------------- // main entry int main( int argc, char** argv) { // mgOSLaunchSendLog(); // setlocale(LC_ALL, ""); mgDebugReset(true); // reset trace file if (SDL_Init (SDL_INIT_EVERYTHING) != 0) { mgDebug("SDL_Init failed"); return 0; } mgOSInitTimer(); // performance timer double startTime = mgOSGetTime(); // initialize random numbers time_t seed; time(&seed); srand(12123123); // srand(seed & 0xFFFF); systemReport(); mgScriptPlatform* platform = NULL; try { // initialize platform services platform = new mgScriptPlatform(); platform->m_startTime = startTime; // create the application platform->m_theApp = mgCreateApplication(); // tell application to set up display platform->m_theApp->appRequestDisplay(); // initialize the display platform->initDisplay(); // initialize the application platform->m_theApp->appInit(); // create buffers platform->m_theApp->appCreateBuffers(); platform->initView(); platform->m_theApp->appViewResized(platform->m_windowWidth, platform->m_windowHeight); platform->m_active = true; platform->m_initialized = true; } catch (mgErrorMsg* e) { double endTime = mgOSGetTime(); mgDebug(":Session time: %.2f seconds", (endTime - startTime)/1000.0); mgString msg; platform->m_errorTable->msgText(msg, e); mgDebug(":Session exit: %s", (const char*) msg); fprintf(stderr, "error: %s\n", (const char*) msg); return 0; } catch (mgException* e) { double endTime = mgOSGetTime(); mgDebug(":Session time: %.2f seconds", (endTime - startTime)/1000.0); mgDebug(":Session exit: %s", (const char*) e->m_message); fprintf(stderr, "error: %s\n", (const char*) e->m_message); return 0; } catch (...) { double endTime = mgOSGetTime(); mgDebug(":Session time: %.2f seconds", (endTime - startTime)/1000.0); mgDebug(":Session exit: \"...\" exception"); return -4; } return 0; }
//-------------------------------------------------------------- // main entry int WINAPI WinMain( HINSTANCE hInstance, // Instance HINSTANCE hPrevInstance, // Previous Instance LPSTR lpCmdLine, // Command Line Parameters int nCmdShow) // Window Show State { #ifdef DEBUG_MEMORY mgDebugMemoryInit(); #endif mgDebugReset(); // reset trace file OSVERSIONINFOEX osVersion; memset(&osVersion, 0, sizeof(osVersion)); osVersion.dwOSVersionInfoSize = sizeof(osVersion); GetVersionEx((OSVERSIONINFO*) &osVersion); mgDebug("Windows version %d.%d %s", osVersion.dwMajorVersion, osVersion.dwMinorVersion, osVersion.szCSDVersion); mgOSInitTimer(); // performance timer // initialize random numbers time_t seed; time(&seed); srand(12123123); // srand(seed & 0xFFFF); mgWinServices* platform = NULL; // defined for internal use try { // initialize platform services platform = new mgWinServices(); // create the application platform->m_theApp = mgCreateApplication(); // tell application to set up display platform->m_theApp->appRequestDisplay(); // initialize the display platform->initDisplay(); // initialize the application platform->m_theApp->appInit(); platform->m_theApp->appViewResized(platform->m_windowWidth, platform->m_windowHeight); // create buffers platform->m_theApp->appCreateBuffers(); platform->initView(); platform->m_active = true; platform->m_initialized = true; // process Windows messages until done while (true) { MSG msg; if (platform->m_active) { while (!PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { platform->m_theApp->appIdle(); } } GetMessage(&msg, NULL, 0, 0); // end on quit if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } mgDebug("------ shutdown"); platform->logTiming(true); // shutdown platform->termView(); // delete buffers platform->m_theApp->appDeleteBuffers(); platform->m_theApp->appTerm(); delete platform->m_theApp; platform->m_theApp = NULL; platform->termDisplay(); platform->destroyWindow(); platform->termWindowClass(); platform->restoreDisplayMode(); delete platform; platform = NULL; } catch (mgErrorMsg* e) { mgString msg; platform->m_errorTable->msgText(msg, e); mgDebug("%s", (const char*) msg); WCHAR* outText; int outLen; msg.toWCHAR(outText, outLen); MessageBox(platform->m_window, outText, L"Error", MB_OK | MB_ICONINFORMATION); delete outText; return 0; } catch (mgException* e) { mgDebug("%s", (const char*) e->m_message); WCHAR* outText; int outLen; e->m_message.toWCHAR(outText, outLen); MessageBox(platform->m_window, outText, TEXT("Error"), MB_OK | MB_ICONINFORMATION); delete outText; return 0; } #ifdef DEBUG_MEMORY // display all memory leaks mgDebugMemory(); #endif return 0; }