Exemplo n.º 1
0
//-----------------------------------------------------------------------------
// handle idle time
void GuiTestAll::appIdle()
{
  double now = mgOSGetTime();
  animate(now, now - m_lastAnimate);
  m_lastAnimate = now;

  mgDisplay->clearView();

  viewDraw();

  if (m_ui != NULL)
  {
    // if the ui needs an update
    if (m_surface->isDamaged())
    {
      mgRectangle bounds;
      m_surface->getDamage(bounds);
      m_ui->m_top->surfacePaint(bounds);
      m_surface->repair(bounds);
    }

    mgDisplay->setTransparent(true);
    mgDisplay->setZEnable(false);
    mgDisplay->drawOverlaySurface(m_surface, 0, 0);
  }

  mgDisplay->drawCursor();
  mgDisplay->swapBuffers();
}
Exemplo n.º 2
0
//--------------------------------------------------------------
// terminate framework
void termFramework(void)
{
  // shutdown
  mgOSXServices* platform = (mgOSXServices*) mgPlatform;

  mgDebug("------ shutdown");
  platform->logTiming(true);

  double sessionEnd = mgOSGetTime();
  mgDebug(":Session time: %.2f seconds", (sessionEnd - platform->m_sessionStart)/1000.0);
  mgDebug(":Session exit: clean");

/* 
  // too much of the window has already been destroyed by Cocoa.  skip this

  // shutdown
  platform->termView();

  // delete buffers
  platform->m_theApp->appDeleteBuffers();

  platform->m_theApp->appTerm();

  delete platform->m_theApp;
  platform->m_theApp = NULL;

  platform->termDisplay();
*/

  mgBlockPool::freeMemory();
}
Exemplo n.º 3
0
//--------------------------------------------------------------
// initialize application
void DontHitMe::appInit()
{
  // get the important directories
  mgString shaderDir;
  m_options.getFileName("shaderDir", m_options.m_sourceFileName, "docs/shaders", shaderDir);
  mgString uiDir;
  m_options.getFileName("uiDir", m_options.m_sourceFileName, "docs/ui", uiDir);
  mgString fontDir;
  m_options.getFileName("fontDir", m_options.m_sourceFileName, "docs/fonts", fontDir);

  mgInitDisplayServices(shaderDir, fontDir);

  mgDisplay->setFOV(m_options.getDouble("FOV", 60.0));
  mgDisplay->setDPI(m_options.getInteger("DPI", 0));

  // load cursor pattern
  loadCursor();
  setDeskMode(true);

  initMovement();

  // load the shaders we might use
  mgVertex::loadShader("litTexture");
  mgVertex::loadShader("unlitTexture");
  mgVertex::loadShader("litTextureCube");
  mgVertex::loadShader("unlitTextureCube");
  mgVertexTA::loadShader("litTextureArray");
  mgVertexTA::loadShader("unlitTextureArray");

  m_sky = new StarrySky(m_options);
  m_sky->enableSkyBox(true);
  m_sky->enableStars(true);
  m_sky->enableSun(true);

  mgPoint3 lightDir(0, 1, 1);
  lightDir.normalize();
  m_sky->setSunDir(lightDir);

  mgDisplay->setLightDir(lightDir);

  m_saucer = new Saucer(m_options);
  m_planet = new Planet(m_options);

  m_wreck = new Wreck(m_options);
  m_tower1 = new Tower(m_options, false);
  m_tower2 = new Tower(m_options, false);

  mgString fileName;
  m_options.getFileName("tube", m_options.m_sourceFileName, "tube.jpg", fileName);
  m_tubeTexture = mgDisplay->loadTexture(fileName);

  initTrack();
  initBall();
  updateBallPt();

  m_intro = new Intro(m_options, m_ballOrigin);
  m_showingIntro = false;

  m_lastAnimate = mgOSGetTime();  // now!
}
Exemplo n.º 4
0
//-----------------------------------------------------------------------------
// mouse button pressed
void GuiTestAll::appMouseDown(
  int pressed,
  int flags)
{
  if (m_deskMode)
  {
    // send the press to the UI if it wants it
    int x, y;
    mgDisplay->getCursorPosn(x, y);
    if (m_ui->useMousePoint(x, y))
    {
      m_ui->m_top->surfaceMouseDown(x, y, flags, pressed);
      return;
    }

    // if both buttons pressed
    if ((pressed == MG_EVENT_MOUSE1_DOWN || pressed == MG_EVENT_MOUSE2_DOWN) &&
        (flags & BOTH_BUTTONS) == BOTH_BUTTONS)
    {
      if (m_forwardSince == INVALID_TIME)
        m_forwardSince = mgOSGetTime();
//      avatarMoveTowardsCamera(true);
    }
  
    // any button pressed, turn off cursor
    mgDisplay->cursorEnable(false);
    mgDisplay->setMouseRelative(true);
  }
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
// mouse button pressed
void SeaOfMemes::appMouseDown(
  int pressed,
  int flags)
{
  if (m_deskMode)
  {
    // send the press to the UI if it wants it
    int x, y;
    mgDisplay->getCursorPosn(x, y);
    if (m_helpUI != NULL && m_helpUI->usesMousePoint(x, y))
    {
      m_helpUI->getTop()->surfaceMouseDown(x, y, flags, pressed);
      return;
    }

    // if both buttons pressed
    if ((pressed == MG_EVENT_MOUSE1_DOWN || pressed == MG_EVENT_MOUSE2_DOWN) &&
        (flags & BOTH_BUTTONS) == BOTH_BUTTONS)
    {
      if (m_forwardSince == INVALID_TIME)
        m_forwardSince = mgOSGetTime();
//      avatarMoveTowardsCamera(true);
    }
  
    // any button pressed, turn off cursor
    mgDisplay->cursorEnable(false);
    mgDisplay->setMouseRelative(true);
  }

  // if ui didn't take press, lose any key focus
  if (m_helpUI != NULL)
    m_helpUI->resetFocus();
}
Exemplo n.º 6
0
//--------------------------------------------------------------
// constructor
mgOSXServices::mgOSXServices()
{
  // set global pointer to framework
  mgPlatform = this;
  
  m_windowWidth = 800;
  m_windowHeight = 600;
  m_windowX = 100;
  m_windowY = 100;

  m_fullscreen = false;
  m_multiSample = false;
  m_swapImmediate = false;
  m_library = "";
  m_libraryFound = MG_LIBRARY_NONE;

  m_mouseRelative = false;
  m_active = false;
  m_lastCursorX = 0;
  m_lastCursorY = 0;
  m_mouseInside = false;
  
  m_errorTable = new mgPlatformErrorTable();

  m_eventFlags = 0;

  m_sessionStart = mgOSGetTime();

  resetTiming();
}
Exemplo n.º 7
0
//--------------------------------------------------------------
// initialize performance counter
void mgOSInitTimer()
{
  struct timespec ts;
  clock_gettime(CLOCK_MONOTONIC, &ts);
  m_baseTime = ts.tv_sec;

  for (int i = 0; i < 10; i++)
  {
    double now = mgOSGetTime();
    double when;
    while (true)
    {
      when = mgOSGetTime();
      if (when != now)
        break;
    }
    mgDebug("timer resolution is %g ms", when-now);
  }
}
Exemplo n.º 8
0
//--------------------------------------------------------------
// update movement 
void updateMovement()
{
  if (m_flatWorld == NULL)
    return;  // too early

  double now = mgOSGetTime();
  BOOL moved = false;
  BOOL turned = false;

  // turn left
  if (m_leftPress != -1)
  {
    m_flatWorld->playerLeft(now-m_leftPress);
    m_leftPress = now;
    turned = true;
  }

  // turn right
  if (m_rightPress != -1)
  {
    m_flatWorld->playerRight(now-m_rightPress);
    m_rightPress = now;
    turned = true;
  }

  // move forwards
  if (m_upPress != -1)
  {
    m_flatWorld->playerForward(now-m_upPress);
    m_upPress = now;
    moved = true;
  }

  // move backwards
  if (m_downPress != -1)
  {
    m_flatWorld->playerBackward(now-m_downPress);
    m_downPress = now;
    moved = true;
  }

  if (moved)
  {
    m_flatWorld->recenterTerrain();
    m_ui->setValue(m_flatWorld->m_playerX, m_flatWorld->m_playerY);
  }

  if (moved || turned)
    InvalidateRect(m_window, NULL, false);
}
Exemplo n.º 9
0
//--------------------------------------------------------------
// map movement key down
void movementKeyDown(
  WORD wParam)
{
  switch (wParam)
  {
    case VK_NEXT:
      m_flatWorld->zoomOut();
      InvalidateRect(m_window, NULL, false);
      break;

    case VK_PRIOR:
      m_flatWorld->zoomIn();
      InvalidateRect(m_window, NULL, false);
      break;

    case VK_LEFT:
      if (m_leftPress == -1)
        m_leftPress = mgOSGetTime();
      break;

    case VK_RIGHT:
      if (m_rightPress = -1)
        m_rightPress = mgOSGetTime();
      break;

    case VK_UP:
      if (m_upPress == -1)
        m_upPress = mgOSGetTime();
      break;

    case VK_DOWN:
      if (m_downPress == -1)
        m_downPress = mgOSGetTime();
      break;
  }
}
Exemplo n.º 10
0
//-----------------------------------------------------------------------------
// handle idle time
void DontHitMe::appIdle()
{
  double now = mgOSGetTime();
  appViewAnimate(now, now - m_lastAnimate);
  m_lastAnimate = now;

  mgDisplay->clearView();
  appViewDraw();
/*
  if (m_ui != NULL)
    m_ui->render();
*/
  mgDisplay->drawCursor();
  mgDisplay->swapBuffers();
}
Exemplo n.º 11
0
//--------------------------------------------------------------------
// initialize application
void GuiTestAll::appInit()
{
  // get the important directories
  mgString shaderDir;
  m_options.getFileName("shaderDir", m_options.m_sourceFileName, "docs/shaders", shaderDir);
  mgString uiDir;
  m_options.getFileName("uiDir", m_options.m_sourceFileName, "docs/ui", uiDir);
  mgString fontDir;
  m_options.getFileName("fontDir", m_options.m_sourceFileName, "docs/fonts", fontDir);

  mgInitDisplayServices(shaderDir, fontDir);

  mgDisplay->setDPI(m_options.getInteger("dpi", 0));
  mgDisplay->setFOV(m_options.getDouble("FOV", 60.0));

  mgString title;
  title.format("%s, %s", mgProgramName, mgProgramVersion);
  mgPlatform->setWindowTitle(title);

  // load the shaders we use
  mgVertex::loadShader("litTexture");
  mgVertexTA::loadShader("litTextureArray");

  // load cursor pattern
  loadCursor();
  setDeskMode(true);

  initMovement();
  m_lastAnimate = mgOSGetTime();  // now!

  // rotation angle for cube
  m_angle = 0.0;

  // load texture patterns
  loadTextures();

  // create vertex and index buffers
  m_cubeIndexes = NULL;
  m_cubeVertexes = NULL;
  m_floorVertexes = NULL;

  m_surface = mgDisplay->createOverlaySurface();

  mgString fileName;
  m_options.getFileName("helpFile", m_options.m_sourceFileName, "help.xml", fileName);
  m_ui = new SampleUI(m_surface, fileName);
}
Exemplo n.º 12
0
//-----------------------------------------------------------------------------
// handle idle time
void SeaOfMemes::appIdle()
{
  double now = mgOSGetTime();
  appViewAnimate(now, now - m_lastAnimate);
  m_lastAnimate = now;

  mgDisplay->clearView();
  appViewDraw();

  if (m_helpUI != NULL)
    m_helpUI->render();

  if (m_speedUI != NULL)
    m_speedUI->render();

  mgDisplay->drawCursor();
  mgDisplay->swapBuffers();
}
Exemplo n.º 13
0
//--------------------------------------------------------------
// write frames per second to log
void mgOSXServices::logTiming(
  BOOL forceReport)
{
  if (m_frameCount == 0)
    return;

  // get elapsed time since last report
  double interval = mgOSGetTime() - m_timingStart;

  // don't report more than once per minute
  if (!forceReport && interval < FPS_REPORT_INTERVAL)
    return;

  double frameTime = interval / m_frameCount;
  int fps = (int) (1000.0 / frameTime);
  
  mgDebug(":Session fps: %d fps, %.2f ms/frame, over %d frames, %.2f seconds", fps, frameTime, m_frameCount, interval/1000.0);
  resetTiming();  // don't count log time
}
Exemplo n.º 14
0
//-----------------------------------------------------------------------------
// mouse button pressed
void DontHitMe::appMouseDown(
  int pressed,
  int flags)
{
  if (m_deskMode)
  {
    // if both buttons pressed
    if ((pressed == MG_EVENT_MOUSE1_DOWN || pressed == MG_EVENT_MOUSE2_DOWN) &&
        (flags & BOTH_BUTTONS) == BOTH_BUTTONS)
    {
      if (m_forwardSince == INVALID_TIME)
        m_forwardSince = mgOSGetTime();
//      avatarMoveTowardsCamera(true);
    }
  
    // any button pressed, turn off cursor
    mgDisplay->cursorEnable(false);
    mgDisplay->setMouseRelative(true);
  }
}
Exemplo n.º 15
0
//--------------------------------------------------------------
// initialize application
void MovementApp::appInit()
{
  // get the important directories
  mgString shaderDir;
  m_options.getFileName("shaderDir", m_options.m_sourceFileName, "docs/shaders", shaderDir);
  mgString uiDir;
  m_options.getFileName("uiDir", m_options.m_sourceFileName, "docs/ui", uiDir);
  mgString fontDir;
  m_options.getFileName("fontDir", m_options.m_sourceFileName, "docs/fonts", fontDir);

  mgInitDisplayServices(shaderDir, fontDir);

  mgDisplay->setDPI(m_options.getInteger("dpi", 0));
  mgDisplay->setFOV(m_options.getDouble("FOV", 60.0));

  // load cursor pattern
  loadCursor();
  setDeskMode(true);

  initMovement();
  m_lastAnimate = mgOSGetTime();  // now!
}
Exemplo n.º 16
0
//-----------------------------------------------------------------------------
// key press
void SeaOfMemes::appKeyDown(
  int keyCode,
  int modifiers)
{
  switch (keyCode)
  {
    case MG_EVENT_KEY_F1:
      if (m_helpUI != NULL)
        m_helpUI->toggleHelp();
      break;

    case MG_EVENT_KEY_F2:
      if (m_helpUI != NULL)
        m_helpUI->toggleConsole();
      break;

    case MG_EVENT_KEY_F6:
    {
      mgDebug("debug");
      break;
    }
  }

  // if UI open, give it keys
  if (m_helpUI != NULL && m_helpUI->hasKeyFocus())
  {
    m_helpUI->getTop()->surfaceKeyDown(keyCode, modifiers);
    return;
  }

  switch (keyCode)
  {
    case MG_EVENT_KEY_ESCAPE: 
      setDeskMode(!m_deskMode);
      break;

    case 'W':
    case MG_EVENT_KEY_UP:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
        if (m_forwardSince == INVALID_TIME)
          m_forwardSince = mgOSGetTime();
      break;

    case 'S':
    case MG_EVENT_KEY_DOWN:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_backwardSince == INVALID_TIME)
        m_backwardSince = mgOSGetTime();
      break;

    case 'A':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_leftSince == INVALID_TIME)
        m_leftSince = mgOSGetTime();
      break;

    case 'D':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_rightSince == INVALID_TIME)
        m_rightSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEUP:
    case ' ':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_upSince == INVALID_TIME)
        m_upSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEDN:
    case 'X':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_downSince == INVALID_TIME)
        m_downSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_LEFT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnLeftSince == INVALID_TIME)
        m_turnLeftSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_RIGHT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnRightSince == INVALID_TIME)
        m_turnRightSince = mgOSGetTime();
      break;
  }
}
Exemplo n.º 17
0
//-----------------------------------------------------------------------------
// key press
void GuiTestAll::appKeyDown(
  int keyCode,
  int modifiers)
{
  if (m_ui != NULL && m_ui->hasKeyFocus())
  {
    m_ui->m_top->surfaceKeyDown(keyCode, modifiers);
    return;
  }

  switch (keyCode)
  {
    case MG_EVENT_KEY_F1:
      m_ui->toggleHelp();
      break;

    case MG_EVENT_KEY_F2:
      m_ui->toggleConsole();
      break;

    case MG_EVENT_KEY_ESCAPE: 
      setDeskMode(!m_deskMode);
      break;

    case 'W':
    case MG_EVENT_KEY_UP:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
        if (m_forwardSince == INVALID_TIME)
          m_forwardSince = mgOSGetTime();
      break;

    case 'S':
    case MG_EVENT_KEY_DOWN:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_backwardSince == INVALID_TIME)
        m_backwardSince = mgOSGetTime();
      break;

    case 'A':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_leftSince == INVALID_TIME)
        m_leftSince = mgOSGetTime();
      break;

    case 'D':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_rightSince == INVALID_TIME)
        m_rightSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEUP:
    case ' ':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_upSince == INVALID_TIME)
        m_upSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEDN:
    case 'X':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_downSince == INVALID_TIME)
        m_downSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_LEFT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnLeftSince == INVALID_TIME)
        m_turnLeftSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_RIGHT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnRightSince == INVALID_TIME)
        m_turnRightSince = mgOSGetTime();
      break;
  }
}
Exemplo n.º 18
0
//-----------------------------------------------------------------------------
// key press
void SeaOfMemes::appKeyDown(
  int keyCode,
  int modifiers)
{
  switch (keyCode)
  {
    case MG_EVENT_KEY_ESCAPE: 
      setDeskMode(!m_deskMode);
      break;

    case MG_EVENT_KEY_F1:
      if (m_helpUI != NULL)
        m_helpUI->toggleHelp();
      break;

    case MG_EVENT_KEY_F6:
    {
      mgDebug("debug");
      break;
    }

    case 'W':
    case MG_EVENT_KEY_UP:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
        if (m_forwardSince == INVALID_TIME)
          m_forwardSince = mgOSGetTime();
      break;

    case 'S':
    case MG_EVENT_KEY_DOWN:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_backwardSince == INVALID_TIME)
        m_backwardSince = mgOSGetTime();
      break;

    case 'A':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_leftSince == INVALID_TIME)
        m_leftSince = mgOSGetTime();
      break;

    case 'D':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_rightSince == INVALID_TIME)
        m_rightSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEUP:
    case ' ':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_upSince == INVALID_TIME)
        m_upSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEDN:
    case 'X':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_downSince == INVALID_TIME)
        m_downSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_LEFT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnLeftSince == INVALID_TIME)
        m_turnLeftSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_RIGHT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnRightSince == INVALID_TIME)
        m_turnRightSince = mgOSGetTime();
      break;

    case 'L':
      setLandingMode(!m_landingMode);
      break;

    case 'K':
      setUnits(!m_unitsMetric);
      break;

    case '=': 
    case '+':
    {
      m_avatarSpeed = m_avatarSpeed * 2.0;
      m_avatarSpeed = min(MAX_AVATAR_SPEED, m_avatarSpeed);
      if (m_speedUI != NULL)
        m_speedUI->setSpeed(m_avatarSpeed);
/*
      if (m_landingMode)
        m_avatarSpeed = min(MAX_LAND_SPEED, m_avatarSpeed);
      else m_avatarSpeed = min(MAX_SPACE_SPEED, m_avatarSpeed);
      showSpeed();
*/
      break;
    }
      
    case '-':
    {
      m_avatarSpeed = m_avatarSpeed / 2.0;
      m_avatarSpeed = max(MIN_AVATAR_SPEED, m_avatarSpeed);
      if (m_speedUI != NULL)
        m_speedUI->setSpeed(m_avatarSpeed);
/*
      if (m_landingMode)
        m_avatarSpeed = max(MIN_LAND_SPEED, m_avatarSpeed);
      else m_avatarSpeed = max(MIN_SPACE_SPEED, m_avatarSpeed);
      showSpeed();
*/
      break;
    }
  }
}
Exemplo n.º 19
0
//--------------------------------------------------------------
// reset frame rate timing
void mgScriptPlatform::resetTiming()
{
  m_frameCount = 0;
  m_timingStart = mgOSGetTime();
}
Exemplo n.º 20
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;
}
Exemplo n.º 21
0
//--------------------------------------------------------------
// mouse pressed
void mgUglyScrollbar::mouseDown(
  void* source,
  int x,
  int y,
  int modifiers,
  int button)
{
  int oldPress = m_pressPart;

  // find area of press
  if (m_horizontal)
  {
    if (x < m_lineUpCoord)
      m_pressPart = PART_LINEUP;
    else if (x < m_pageUpCoord)
    {
      m_dragStart = x;
      m_pressPart = PART_PAGEUP;
    }
    else if (x < m_sliderCoord)
    {
      m_pressPart = PART_SLIDER;
      m_dragOffset = x - m_pageUpCoord; // start of slider
    }
    else if (x < m_pageDownCoord)
    {    
      m_pressPart = PART_PAGEDOWN;
      m_dragStart = x;
    }
    else m_pressPart = PART_LINEDOWN;
  }
  else
  {
    if (y < m_lineUpCoord)
      m_pressPart = PART_LINEUP;
    else if (y < m_pageUpCoord)
    {
      m_pressPart = PART_PAGEUP;
      m_dragStart = y;
    }      
    else if (y < m_sliderCoord)
    {
      m_pressPart = PART_SLIDER;
      m_dragOffset = y - m_pageUpCoord; // start of slider
    }
    else if (y < m_pageDownCoord)
    {
      m_pressPart = PART_PAGEDOWN;
      m_dragStart = y;
    }     
    else m_pressPart = PART_LINEDOWN;
  }

  // do first scroll event
  switch (m_pressPart)
  {
    case PART_LINEUP:
    case PART_LINEDOWN:
    case PART_PAGEUP:
    case PART_PAGEDOWN:
      sendScrollEvent(m_pressPart, 0);
      break;
    case PART_SLIDER: ;
  }

  if (m_pressPart != PART_NONE && m_pressPart != PART_SLIDER)
  {
    // start timer
    addTimeListener((mgTimeListener*) this);  
    m_pressTime = mgOSGetTime();
    m_pressInterval = FIRST_INTERVAL;
  }

  if (m_pressPart != oldPress)
    damage();
}
Exemplo n.º 22
0
// shutdown messages
void mgShutdown()
{
  mgScriptPlatform* platform = (mgScriptPlatform*) mgPlatform;
  try
  {
    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();

    delete platform;
    platform = NULL;
  }
  catch (mgErrorMsg* e)
  {
    double endTime = mgOSGetTime();
    mgDebug(":Session time: %.2f seconds", (endTime - platform->m_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;
  }
  catch (mgException* e)
  {
    double endTime = mgOSGetTime();
    mgDebug(":Session time: %.2f seconds", (endTime - platform->m_startTime)/1000.0);

    mgDebug(":Session exit: %s", (const char*) e->m_message);
    fprintf(stderr, "error: %s\n", (const char*) e->m_message);
    return;
  }
  catch (...)
  {
    double endTime = mgOSGetTime();
    mgDebug(":Session time: %.2f seconds", (endTime - platform->m_startTime)/1000.0);

    mgDebug(":Session exit: \"...\" exception");
    return;
  }

  double endTime = mgOSGetTime();
  mgDebug(":Session time: %.2f seconds", (endTime - platform->m_startTime)/1000.0);

  mgDebug(":Session exit: clean");

//  mgBlockPool::freeMemory();

  // display all memory leaks
#ifdef DEBUG_MEMORY
  mgDebugMemory();
#endif
}
Exemplo n.º 23
0
//-----------------------------------------------------------------------------
// key press
void DontHitMe::appKeyDown(
  int keyCode,
  int modifiers)
{
  switch (keyCode)
  {
    case MG_EVENT_KEY_ESCAPE: 
      setDeskMode(!m_deskMode);
      break;

    case MG_EVENT_KEY_F1:
//      showHelp();
      break;

    case MG_EVENT_KEY_F5:
      mgDebug("break");
      break;

    case 'F':
      m_flying = !m_flying;
      m_eyeChanged = true;
      break;

    case 'W':
    case MG_EVENT_KEY_UP:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
        if (m_forwardSince == INVALID_TIME)
          m_forwardSince = mgOSGetTime();
      break;

    case 'S':
    case MG_EVENT_KEY_DOWN:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_backwardSince == INVALID_TIME)
        m_backwardSince = mgOSGetTime();
      break;

    case 'A':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_leftSince == INVALID_TIME)
        m_leftSince = mgOSGetTime();
      break;

    case 'D':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_rightSince == INVALID_TIME)
        m_rightSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEUP:
    case ' ':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_upSince == INVALID_TIME)
        m_upSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_PAGEDN:
    case 'X':
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_downSince == INVALID_TIME)
        m_downSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_LEFT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnLeftSince == INVALID_TIME)
        m_turnLeftSince = mgOSGetTime();
      break;

    case MG_EVENT_KEY_RIGHT:
      // ignore autorepeat keys
      if ((modifiers & MG_EVENT_KEYREPEAT) != 0)
        return;
          
      if (m_turnRightSince == INVALID_TIME)
        m_turnRightSince = mgOSGetTime();
      break;
  }
}
Exemplo n.º 24
0
//--------------------------------------------------------------
// reset frame rate timing
void mgOSXServices::resetTiming()
{
  m_frameCount = 0;
  m_timingStart = mgOSGetTime();
}