Пример #1
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;
}
Пример #2
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;
}