Exemplo n.º 1
0
/** Update callback
 */
static void orxFASTCALL orxJoystick_GLFW_Update(const orxCLOCK_INFO *_pstClockInfo, void *_pContext)
{
  /* Profiles */
  orxPROFILER_PUSH_MARKER("orxJoystick_Update");

  /* Was first joystick present since the beginning? */
  if(sstJoystick.astJoyInfoList[0].bIsConnected != orxFALSE)
  {
     /* Updates it */
     orxJoystick_GLFW_UpdateInfo(0);

     /* Still connected? */
     if(sstJoystick.astJoyInfoList[0].bIsConnected != orxFALSE)
     {
       orxSYSTEM_EVENT_PAYLOAD stPayload;

       /* Inits event payload */
       orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
       stPayload.stAccelerometer.dTime = orxSystem_GetTime();
       stPayload.stAccelerometer.vAcceleration.fX = sstJoystick.astJoyInfoList[0].afAxisInfoList[orxJOYSTICK_AXIS_X_1];
       stPayload.stAccelerometer.vAcceleration.fY = sstJoystick.astJoyInfoList[0].afAxisInfoList[orxJOYSTICK_AXIS_Y_1];
       stPayload.stAccelerometer.vAcceleration.fZ = sstJoystick.astJoyInfoList[0].afAxisInfoList[orxJOYSTICK_AXIS_Z_1];

       /* Sends accelerometer event */
       orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_ACCELERATE, orxNULL, orxNULL, &stPayload);
     }
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return;
}
Exemplo n.º 2
0
/** Update callback
 */
static void orxFASTCALL orxMouse_GLFW_Update(const orxCLOCK_INFO *_pstClockInfo, void *_pContext)
{
  /* Profiles */
  orxPROFILER_PUSH_MARKER("orxMouse_Update");

  /* Should update cursor? */
  if(sstMouse.bUpdateCursor != orxFALSE)
  {
    /* Restores cursor status */
    if(sstMouse.bShowCursor != orxFALSE)
    {
      glfwEnable(GLFW_MOUSE_CURSOR);
    }
    else
    {
      glfwDisable(GLFW_MOUSE_CURSOR);
    }

    /* Updates status */
    sstMouse.bUpdateCursor = orxFALSE;
  }

  /* Is left button pressed? */
  if(glfwGetMouseButton(GLFW_MOUSE_BUTTON_LEFT) != GL_FALSE)
  {
    orxSYSTEM_EVENT_PAYLOAD stPayload;

    /* Inits event payload */
    orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
    stPayload.stTouch.dTime     = orxSystem_GetTime();
    stPayload.stTouch.u32ID     = 0;
    stPayload.stTouch.fX        = sstMouse.vMouseBackup.fX;
    stPayload.stTouch.fY        = sstMouse.vMouseBackup.fY;
    stPayload.stTouch.fPressure = orxFLOAT_1;

    /* Wasn't pressed before? */
    if(sstMouse.bButtonPressed == orxFALSE)
    {
      /* Sends touch event */
      orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_TOUCH_BEGIN, orxNULL, orxNULL, &stPayload);

      /* Updates button pressed status */
      sstMouse.bButtonPressed = orxTRUE;

      /* Stores touch position */
      orxVector_Copy(&(sstMouse.vMouseTouch), &(sstMouse.vMouseBackup));
    }
    else
    {
      /* Has moved? */
      if(orxVector_AreEqual(&(sstMouse.vMouseBackup), &(sstMouse.vMouseTouch)) == orxFALSE)
      {
        /* Sends touch event */
        orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_TOUCH_MOVE, orxNULL, orxNULL, &stPayload);

        /* Stores touch position */
        orxVector_Copy(&(sstMouse.vMouseTouch), &(sstMouse.vMouseBackup));
      }
    }
  }
  else
  {
    /* Was previously pressed? */
    if(sstMouse.bButtonPressed != orxFALSE)
    {
      orxSYSTEM_EVENT_PAYLOAD stPayload;

      /* Inits event payload */
      orxMemory_Zero(&stPayload, sizeof(orxSYSTEM_EVENT_PAYLOAD));
      stPayload.stTouch.dTime     = orxSystem_GetTime();
      stPayload.stTouch.u32ID     = 0;
      stPayload.stTouch.fX        = sstMouse.vMouseBackup.fX;
      stPayload.stTouch.fY        = sstMouse.vMouseBackup.fY;
      stPayload.stTouch.fPressure = orxFLOAT_0;

      /* Sends touch event */
      orxEVENT_SEND(orxEVENT_TYPE_SYSTEM, orxSYSTEM_EVENT_TOUCH_END, orxNULL, orxNULL, &stPayload);

      /* Updates button pressed status */
      sstMouse.bButtonPressed = orxFALSE;

      /* Clears touch position */
      orxVector_Copy(&(sstMouse.vMouseTouch), &orxVECTOR_0);
    }
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return;
}
Exemplo n.º 3
0
/** Updates the clock system
 * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxClock_Update()
{
  orxDOUBLE dNewTime;
  orxFLOAT  fDT, fDelay;
  orxCLOCK *pstClock;
  orxSTATUS eResult = orxSTATUS_SUCCESS;

  /* Checks */
  orxASSERT(sstClock.u32Flags & orxCLOCK_KU32_STATIC_FLAG_READY);

  /* Not already locked? */
  if(!(sstClock.u32Flags & orxCLOCK_KU32_STATIC_FLAG_UPDATE_LOCK))
  {
    /* Lock clocks */
    sstClock.u32Flags |= orxCLOCK_KU32_STATIC_FLAG_UPDATE_LOCK;

    /* Gets new time */
    dNewTime  = orxSystem_GetTime();

    /* Computes natural DT */
    fDT       = (orxFLOAT)(dNewTime - sstClock.dTime);

    /* Gets modified DT */
    fDT       = orxClock_ComputeDT(fDT, orxNULL);

    /* Updates time */
    sstClock.dTime = dNewTime;

    /* Inits delay */
    fDelay = sstClock.fMainClockTickSize;

    /* For all clocks */
    for(pstClock = orxCLOCK(orxStructure_GetFirst(orxSTRUCTURE_ID_CLOCK));
        pstClock != orxNULL;
        pstClock = orxCLOCK(orxStructure_GetNext(pstClock)))
    {
      /* Locks it */
      orxStructure_SetFlags(pstClock, orxCLOCK_KU32_FLAG_UPDATE_LOCK, orxCLOCK_KU32_FLAG_NONE);

      /* Is clock not paused? */
      if(orxClock_IsPaused(pstClock) == orxFALSE)
      {
        orxFLOAT fClockDelay;

        /* Updates clock real time & partial DT */
        pstClock->fPartialDT += fDT;

        /* New tick happens? */
        if(pstClock->fPartialDT >= pstClock->stClockInfo.fTickSize)
        {
          orxFLOAT                    fClockDT;
          orxCLOCK_TIMER_STORAGE     *pstTimerStorage;
          orxCLOCK_FUNCTION_STORAGE  *pstFunctionStorage;

          /* Gets clock modified DT */
          fClockDT = orxClock_ComputeDT(pstClock->fPartialDT, &(pstClock->stClockInfo));

          /* Updates clock DT */
          pstClock->stClockInfo.fDT = fClockDT;

          /* Updates clock time */
          pstClock->stClockInfo.fTime += fClockDT;

          /* For all timers */
          for(pstTimerStorage = (orxCLOCK_TIMER_STORAGE *)orxLinkList_GetFirst(&(pstClock->stTimerList)); pstTimerStorage != orxNULL;)
          {
            /* Should call it? */
            if((pstTimerStorage->fTimeStamp <= pstClock->stClockInfo.fTime) && (pstTimerStorage->s32Repetition != 0))
            {
              /* Calls it */
              pstTimerStorage->pfnCallback(&(pstClock->stClockInfo), pstTimerStorage->pContext);

              /* Updates its time stamp */
              pstTimerStorage->fTimeStamp = pstClock->stClockInfo.fTime + pstTimerStorage->fDelay;

              /* Should update counter */
              if(pstTimerStorage->s32Repetition > 0)
              {
                /* Updates it */
                pstTimerStorage->s32Repetition--;
              }
            }

            /* Should delete it */
            if(pstTimerStorage->s32Repetition == 0)
            {
              orxCLOCK_TIMER_STORAGE *pstDelete;

              /* Gets timer to delete */
              pstDelete = pstTimerStorage;

              /* Gets the next timer */
              pstTimerStorage = (orxCLOCK_TIMER_STORAGE *)orxLinkList_GetNext(&(pstTimerStorage->stNode));

              /* Removes current timer */
              orxLinkList_Remove(&(pstDelete->stNode));

              /* Deletes it */
              orxBank_Free(sstClock.pstTimerBank, pstDelete);
            }
            else
            {
              /* Gets the next timer */
              pstTimerStorage = (orxCLOCK_TIMER_STORAGE *)orxLinkList_GetNext(&(pstTimerStorage->stNode));
            }
          }

          /* For all registered callbacks */
          for(pstFunctionStorage = (orxCLOCK_FUNCTION_STORAGE *)orxLinkList_GetFirst(&(pstClock->stFunctionList));
              pstFunctionStorage != orxNULL;
              pstFunctionStorage = (orxCLOCK_FUNCTION_STORAGE *)orxLinkList_GetNext(&(pstFunctionStorage->stNode)))
          {
            /* Calls it */
            pstFunctionStorage->pfnCallback(&(pstClock->stClockInfo), pstFunctionStorage->pContext);
          }

          /* Updates partial DT */
          pstClock->fPartialDT = orxFLOAT_0;
        }

        /* Gets clock's delay */
        fClockDelay = pstClock->stClockInfo.fTickSize - pstClock->fPartialDT;

        /* Smaller than previous clocks' delay? */
        if(fClockDelay < fDelay)
        {
          /* Stores it */
          fDelay = fClockDelay;
        }
      }

      /* Unlocks it */
      orxStructure_SetFlags(pstClock, orxCLOCK_KU32_FLAG_NONE, orxCLOCK_KU32_FLAG_UPDATE_LOCK);
    }

    /* Unlocks clocks */
    sstClock.u32Flags &= ~orxCLOCK_KU32_STATIC_FLAG_UPDATE_LOCK;

    /* Gets real remaining delay */
    fDelay = fDelay + orxCLOCK_KF_DELAY_ADJUSTMENT - orx2F(orxSystem_GetTime() - sstClock.dTime);

    /* Should delay? */
    if(fDelay > orxFLOAT_0)
    {
      /* Waits for next time slice */
      orxSystem_Delay(fDelay);
    }
  }

  /* Done! */
  return eResult;
}
Exemplo n.º 4
0
/** Inits clock module
 * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxClock_Init()
{
  orxSTATUS eResult = orxSTATUS_FAILURE;

  /* Not already Initialized? */
  if(!(sstClock.u32Flags & orxCLOCK_KU32_STATIC_FLAG_READY))
  {
    /* Registers structure type */
    eResult = orxSTRUCTURE_REGISTER(CLOCK, orxSTRUCTURE_STORAGE_TYPE_LINKLIST, orxMEMORY_TYPE_MAIN, orxCLOCK_KU32_BANK_SIZE, orxNULL);

    /* Successful? */
    if(eResult != orxSTATUS_FAILURE)
    {
      /* Cleans control structure */
      orxMemory_Zero(&sstClock, sizeof(orxCLOCK_STATIC));

      /* Creates timer bank */
      sstClock.pstTimerBank = orxBank_Create(orxCLOCK_KU32_TIMER_BANK_SIZE, sizeof(orxCLOCK_TIMER_STORAGE), orxBANK_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN);

      /* Valid? */
      if(sstClock.pstTimerBank != orxNULL)
      {
        /* Creates reference table */
        sstClock.pstReferenceTable = orxHashTable_Create(orxCLOCK_KU32_REFERENCE_TABLE_SIZE, orxHASHTABLE_KU32_FLAG_NONE, orxMEMORY_TYPE_MAIN);

        /* Valid? */
        if(sstClock.pstReferenceTable != orxNULL)
        {
          orxCLOCK *pstClock;

          /* No mod type by default */
          sstClock.eModType = orxCLOCK_MOD_TYPE_NONE;

          /* Gets init time */
          sstClock.dTime  = orxSystem_GetTime();

          /* Inits Flags */
          sstClock.u32Flags = orxCLOCK_KU32_STATIC_FLAG_READY;

          /* Gets main clock tick size */
          orxConfig_PushSection(orxCLOCK_KZ_CONFIG_SECTION);
          sstClock.fMainClockTickSize = (orxConfig_HasValue(orxCLOCK_KZ_CONFIG_MAIN_CLOCK_FREQUENCY) && orxConfig_GetFloat(orxCLOCK_KZ_CONFIG_MAIN_CLOCK_FREQUENCY) > orxFLOAT_0) ? (orxFLOAT_1 / orxConfig_GetFloat(orxCLOCK_KZ_CONFIG_MAIN_CLOCK_FREQUENCY)) : orxFLOAT_0;
          orxConfig_PopSection();

          /* Creates default full speed core clock */
          pstClock = orxClock_Create(sstClock.fMainClockTickSize, orxCLOCK_TYPE_CORE);

          /* Success? */
          if(pstClock != orxNULL)
          {
            /* Sets it as its own owner */
            orxStructure_SetOwner(pstClock, pstClock);

            /* Updates result */
            eResult = orxSTATUS_SUCCESS;
          }
          else
          {
            /* Updates result */
            eResult = orxSTATUS_FAILURE;
          }
        }
        else
        {
          /* Deletes timer bank */
          orxBank_Delete(sstClock.pstTimerBank);
          sstClock.pstTimerBank = orxNULL;

          /* Updates result */
          eResult = orxSTATUS_FAILURE;
        }
      }
      else
      {
        /* Logs message */
        orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Failed creating clock bank.");

        /* Clock bank not created */
        eResult = orxSTATUS_FAILURE;
      }
    }
    else
    {
      /* Logs message */
      orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Failed to register link list structure.");
    }
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_CLOCK, "Tried to initialize clock module when it was already initialized.");

    /* Already initialized */
    eResult = orxSTATUS_SUCCESS;
  }

  /* Done! */
  return eResult;
}