Ejemplo n.º 1
0
/** Find an item in a hash table.
 * @param[in] _pstHashTable  The hash table where search.
 * @param[in] _u64Key      Key to find.
 * @return The Element associated to the key or orxNULL if not found.
 */
void *orxFASTCALL orxHashTable_Get(const orxHASHTABLE *_pstHashTable, orxU64 _u64Key)
{
  orxU32              u32Index;
  orxHASHTABLE_CELL  *pstCell = orxNULL;

  /* Profiles */
  orxPROFILER_PUSH_MARKER("orxHashTable_Get");

  /* Checks */
  orxASSERT(_pstHashTable != orxNULL);

  /* Gets the index from the key */
  u32Index = orxHashTable_FindIndex(_pstHashTable, _u64Key);

  /* Finds the corresponding cell */
  for(pstCell = _pstHashTable->apstCell[u32Index];
      (pstCell != orxNULL) && (pstCell->u64Key != _u64Key);
      pstCell = pstCell->pstNext);

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return (pstCell != orxNULL) ? pstCell->pData : orxNULL;
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
/** Add an item value.
 * @param[in] _pstHashTable The hash table where set.
 * @param[in] _u64Key      Key to assign.
 * @param[in] _pData       Data to assign.
 * @return Returns the status of the operation. (fails if key already used)
 */
orxSTATUS orxFASTCALL orxHashTable_Add(orxHASHTABLE *_pstHashTable, orxU64 _u64Key, void *_pData)
{
  orxU32              u32Index;
  orxHASHTABLE_CELL  *pstCell;
  orxSTATUS           eStatus = orxSTATUS_FAILURE;

  /* Profiles */
  orxPROFILER_PUSH_MARKER("orxHashTable_Add");

  /* Checks */
  orxASSERT(_pstHashTable != orxNULL);
  orxASSERT(_pData != orxNULL);

  /* Gets the index from the key */
  u32Index = orxHashTable_FindIndex(_pstHashTable, _u64Key);

  /* Finds the corresponding cell */
  for(pstCell = _pstHashTable->apstCell[u32Index];
      (pstCell != orxNULL) && (pstCell->u64Key != _u64Key);
      pstCell = pstCell->pstNext);

  /* Not found? */
  if(pstCell == orxNULL)
  {
    /* Creates a new cell */
    pstCell = (orxHASHTABLE_CELL *)orxBank_Allocate(_pstHashTable->pstBank);

    /* Success? */
    if(pstCell != orxNULL)
    {
      /* Inits cell */
      pstCell->u64Key   = _u64Key;
      pstCell->pData    = _pData;
      pstCell->pstNext  = _pstHashTable->apstCell[u32Index];

      /* Inserts it */
      _pstHashTable->apstCell[u32Index] = pstCell;

      /* Updates counter */
      _pstHashTable->u32Counter++;

      /* Updates result */
      eStatus = orxSTATUS_SUCCESS;
    }
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return eStatus;
}
Ejemplo n.º 4
0
/** Create a new segment of memory and returns a pointer on it
 * @param[in] _pstBank    Concerned bank
 * @return  returns a pointer on the memory segment (orxNULL if an error occurred)
 */
static orxINLINE orxBANK_SEGMENT *orxBank_CreateSegment(const orxBANK *_pstBank)
{
  orxBANK_SEGMENT *pstSegment;  /* Pointer on the segment of memory */
  orxU32 u32BaseSegmentSize;    /* Base size of segment allocation */

  /* Profiles */
  orxPROFILER_PUSH_MARKER("orxBank_CreateSegment");

  /* Module initialized ? */
  orxASSERT((sstBank.u32Flags & orxBANK_KU32_STATIC_FLAG_READY) == orxBANK_KU32_STATIC_FLAG_READY);

  /* Correct parameters ? */
  orxASSERT(_pstBank != orxNULL);

  /* Compute the base segment size */
  u32BaseSegmentSize = sizeof(orxBANK_SEGMENT) + _pstBank->u16SizeSegmentBitField * sizeof(orxU32);

  /* Allocates a new segment of memory */
  pstSegment = (orxBANK_SEGMENT *)orxMemory_Allocate(u32BaseSegmentSize + sstBank.u32CacheLineSize - 1 + (_pstBank->u16NbCellPerSegments * _pstBank->u32ElemSize), _pstBank->eMemType);
  if(pstSegment != orxNULL)
  {
    orxU8 *pAlignedSegmentData;

    /* Set initial segment values */
    orxMemory_Zero(pstSegment, u32BaseSegmentSize + (_pstBank->u16NbCellPerSegments * _pstBank->u32ElemSize));
    pstSegment->pstNext               = orxNULL;
    pstSegment->u32NbFree             = _pstBank->u16NbCellPerSegments;
    pAlignedSegmentData               = ((orxU8 *)pstSegment) + u32BaseSegmentSize;
    pstSegment->pSegmentData          = (void *)orxALIGN(pAlignedSegmentData, sstBank.u32CacheLineSize);
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return pstSegment;
}
Ejemplo n.º 5
0
/** Updates the FXPointer (Callback for generic structure update calling)
 * @param[in]   _pstStructure                 Generic Structure or the concerned Body
 * @param[in]   _pstCaller                    Structure of the caller
 * @param[in]   _pstClockInfo                 Clock info used for time updates
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
static orxSTATUS orxFASTCALL orxFXPointer_Update(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo)
{
  orxFXPOINTER *pstFXPointer;
  orxOBJECT    *pstObject;
  orxSTATUS     eResult = orxSTATUS_SUCCESS;

  /* Profiles */
  orxPROFILER_PUSH_MARKER("orxFXPointer_Update");

  /* Checks */
  orxASSERT(sstFXPointer.u32Flags & orxFXPOINTER_KU32_STATIC_FLAG_READY);
  orxSTRUCTURE_ASSERT(_pstStructure);
  orxSTRUCTURE_ASSERT(_pstCaller);

  /* Gets FXPointer */
  pstFXPointer = orxFXPOINTER(_pstStructure);

  /* Gets calling object */
  pstObject = orxOBJECT(_pstCaller);

  /* Is enabled? */
  if(orxFXPointer_IsEnabled(pstFXPointer) != orxFALSE)
  {
    orxFLOAT      fLastTime;
    orxU32        i;
    orxSTRUCTURE *pstOwner;

    /* Gets owner */
    pstOwner = orxStructure_GetOwner(pstFXPointer);

    /* Backups last time */
    fLastTime = pstFXPointer->fTime;

    /* Computes its new time cursor */
    pstFXPointer->fTime += _pstClockInfo->fDT;

    /* For all FXs */
    for(i = 0; i < orxFXPOINTER_KU32_FX_NUMBER; i++)
    {
      orxFX *pstFX;

      /* Gets FX */
      pstFX = pstFXPointer->astFXList[i].pstFX;

      /* Valid? */
      if(pstFX != orxNULL)
      {
        orxFLOAT fFXLocalStartTime, fFXLocalEndTime;

        /* Gets FX local times */
        fFXLocalStartTime = fLastTime - pstFXPointer->astFXList[i].fStartTime;
        fFXLocalEndTime   = pstFXPointer->fTime - pstFXPointer->astFXList[i].fStartTime;

        /* Is the FX reached? */
        if(fFXLocalEndTime >= orxFLOAT_0)
        {
          /* Is the first time? */
          if(!orxFLAG_TEST(pstFXPointer->astFXList[i].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_PLAYED))
          {
            orxFX_EVENT_PAYLOAD stPayload;

            /* Inits event payload */
            orxMemory_Zero(&stPayload, sizeof(orxFX_EVENT_PAYLOAD));
            stPayload.pstFX   = pstFX;
            stPayload.zFXName = orxFX_GetName(pstFX);

            /* Sends event */
            orxEVENT_SEND(orxEVENT_TYPE_FX, orxFX_EVENT_START, pstOwner, pstOwner, &stPayload);
          }

          /* Updates its status */
          orxFLAG_SET(pstFXPointer->astFXList[i].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_PLAYED, orxFXPOINTER_HOLDER_KU32_FLAG_NONE);

          /* Applies FX from last time to now */
          if(orxFX_Apply(pstFX, pstObject, fFXLocalStartTime, fFXLocalEndTime) == orxSTATUS_FAILURE)
          {
            orxFX_EVENT_PAYLOAD stPayload;

            /* Inits event payload */
            orxMemory_Zero(&stPayload, sizeof(orxFX_EVENT_PAYLOAD));
            stPayload.pstFX   = pstFX;
            stPayload.zFXName = orxFX_GetName(pstFX);

            /* Is a looping FX? */
            if(orxFX_IsLooping(pstFX) != orxFALSE)
            {
              /* Sends event */
              orxEVENT_SEND(orxEVENT_TYPE_FX, orxFX_EVENT_LOOP, pstOwner, pstOwner, &stPayload);

              /* Updates its start time */
              pstFXPointer->astFXList[i].fStartTime = pstFXPointer->fTime;
            }
            else
            {
              /* Decreases its reference counter */
              orxStructure_DecreaseCounter(pstFX);

              /* Removes its reference */
              pstFXPointer->astFXList[i].pstFX = orxNULL;

              /* Sends event */
              orxEVENT_SEND(orxEVENT_TYPE_FX, orxFX_EVENT_STOP, pstOwner, pstOwner, &stPayload);

              /* Sends event */
              orxEVENT_SEND(orxEVENT_TYPE_FX, orxFX_EVENT_REMOVE, pstOwner, pstOwner, &stPayload);

              /* Is internal? */
              if(orxFLAG_TEST(pstFXPointer->astFXList[i].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_INTERNAL))
              {
                /* Removes its owner */
                orxStructure_SetOwner(pstFX, orxNULL);

                /* Deletes it */
                orxFX_Delete(pstFX);
              }
            }
          }
        }
      }
    }
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return eResult;
}
Ejemplo n.º 6
0
/** Updates the SoundPointer (Callback for generic structure update calling)
 * @param[in]   _pstStructure                 Generic Structure or the concerned Body
 * @param[in]   _pstCaller                    Structure of the caller
 * @param[in]   _pstClockInfo                 Clock info used for time updates
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
static orxSTATUS orxFASTCALL orxSoundPointer_Update(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo)
{
  orxSOUNDPOINTER  *pstSoundPointer;
  orxSTATUS         eResult = orxSTATUS_SUCCESS;

  /* Profiles */
  orxPROFILER_PUSH_MARKER("orxSoundPointer_Update");

  /* Checks */
  orxASSERT(sstSoundPointer.u32Flags & orxSOUNDPOINTER_KU32_STATIC_FLAG_READY);
  orxSTRUCTURE_ASSERT(_pstStructure);
  orxSTRUCTURE_ASSERT(_pstCaller);

  /* Gets sound pointer */
  pstSoundPointer = orxSOUNDPOINTER(_pstStructure);

  /* Is enabled? */
  if(orxSoundPointer_IsEnabled(pstSoundPointer) != orxFALSE)
  {
    orxU32 i;

    /* For all Sounds */
    for(i = 0; i < orxSOUNDPOINTER_KU32_SOUND_NUMBER; i++)
    {
      orxSOUND *pstSound;

      /* Gets sound */
      pstSound = pstSoundPointer->astSoundList[i].pstSound;

      /* Valid? */
      if(pstSound != orxNULL)
      {
        /* Should auto play? */
        if(orxFLAG_TEST(pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PLAY))
        {
          /* Plays it */
          orxSound_Play(pstSound);

          /* Updates its flags */
          orxFLAG_SET(pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_NONE, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PLAY);
        }

        /* Delegates update to the sound */
        orxStructure_Update(pstSound, _pstCaller, _pstClockInfo);

        /* Is sound stopped? */
        if(orxSound_GetStatus(pstSound) == orxSOUND_STATUS_STOP)
        {
          /* Removes it */
          orxSoundPointer_RemoveSound(pstSoundPointer, pstSound);
        }
      }
    }
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return eResult;
}
Ejemplo n.º 7
0
/** Updates the TimeLine (Callback for generic structure update calling)
 * @param[in]   _pstStructure                 Generic Structure or the concerned Body
 * @param[in]   _pstCaller                    Structure of the caller
 * @param[in]   _pstClockInfo                 Clock info used for time updates
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
static orxSTATUS orxFASTCALL orxTimeLine_Update(orxSTRUCTURE *_pstStructure, const orxSTRUCTURE *_pstCaller, const orxCLOCK_INFO *_pstClockInfo)
{
  orxTIMELINE  *pstTimeLine;
  orxSTATUS     eResult = orxSTATUS_SUCCESS;

  /* Profiles */
  orxPROFILER_PUSH_MARKER("orxTimeLine_Update");

  /* Checks */
  orxASSERT(sstTimeLine.u32Flags & orxTIMELINE_KU32_STATIC_FLAG_READY);
  orxSTRUCTURE_ASSERT(_pstStructure);
  orxSTRUCTURE_ASSERT(_pstCaller);

  /* Gets TimeLine */
  pstTimeLine = orxTIMELINE(_pstStructure);

  /* Is enabled? */
  if(orxTimeLine_IsEnabled(pstTimeLine) != orxFALSE)
  {
    orxU32 i;

    /* Cleans its flags */
    orxStructure_SetFlags(pstTimeLine, orxTIMELINE_KU32_FLAG_NONE, orxTIMELINE_KU32_FLAG_DIRTY);

    /* Has clock info? */
    if(_pstClockInfo != orxNULL)
    {
      /* Computes its new time cursor */
      pstTimeLine->fTime += _pstClockInfo->fDT;
    }

    /* For all tracks */
    for(i = 0; i < orxTIMELINE_KU32_TRACK_NUMBER; i++)
    {
      orxTIMELINE_TRACK *pstTrack;

      /* Is timeline dirty? */
      if(orxStructure_TestFlags(pstTimeLine, orxTIMELINE_KU32_FLAG_DIRTY))
      {
        orxU32 j;

        /* For all previous tracks */
        for(j = 0; j < i; j++)
        {
          /* Is defined? */
          if(pstTimeLine->astTrackList[j].pstTrack != orxNULL)
          {
            /* Hasn't been updated? */
            if(!orxFLAG_TEST(pstTimeLine->astTrackList[j].u32Flags, orxTIMELINE_HOLDER_KU32_FLAG_UPDATED))
            {
              /* Selects it */
              i = j;

              break;
            }
          }
        }
      }

      /* Gets track */
      pstTrack = pstTimeLine->astTrackList[i].pstTrack;

      /* Valid and not already updated? */
      if((pstTrack != orxNULL) && (!orxFLAG_TEST(pstTimeLine->astTrackList[i].u32Flags, orxTIMELINE_HOLDER_KU32_FLAG_UPDATED)))
      {
        orxFLOAT fTrackLocalTime;

        /* Gets track local time */
        fTrackLocalTime = pstTimeLine->fTime - pstTimeLine->astTrackList[i].fStartTime;

        /* Has time come? */
        if(fTrackLocalTime >= orxFLOAT_0)
        {
          orxTIMELINE_EVENT_PAYLOAD stPayload;
          orxU32                    u32EventIndex;

          /* Is the first time? */
          if(!orxFLAG_TEST(pstTimeLine->astTrackList[i].u32Flags, orxTIMELINE_HOLDER_KU32_FLAG_PLAYED))
          {
            /* Inits event payload */
            orxMemory_Zero(&stPayload, sizeof(orxTIMELINE_EVENT_PAYLOAD));
            stPayload.pstTimeLine = pstTimeLine;
            stPayload.zTrackName  = pstTrack->zReference;

            /* Sends event */
            orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_TRACK_START, _pstCaller, _pstCaller, &stPayload);
          }

          /* Updates its status */
          orxFLAG_SET(pstTimeLine->astTrackList[i].u32Flags, orxTIMELINE_HOLDER_KU32_FLAG_PLAYED | orxTIMELINE_HOLDER_KU32_FLAG_UPDATED, orxTIMELINE_HOLDER_KU32_FLAG_NONE);

          /* Inits event payload */
          orxMemory_Zero(&stPayload, sizeof(orxTIMELINE_EVENT_PAYLOAD));
          stPayload.pstTimeLine = pstTimeLine;
          stPayload.zTrackName  = pstTrack->zReference;

          /* For all recently past events */
          for(u32EventIndex = pstTimeLine->astTrackList[i].u32NextEventIndex;
              (u32EventIndex < pstTrack->u32EventCounter) && (fTrackLocalTime >= pstTrack->astEventList[u32EventIndex].fTimeStamp);
              u32EventIndex++)
          {
            /* Updates payload */
            stPayload.zEvent      = pstTrack->astEventList[u32EventIndex].zEventText;
            stPayload.fTimeStamp  = pstTrack->astEventList[u32EventIndex].fTimeStamp;

            /* Sends event */
            orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_TRIGGER, _pstCaller, _pstCaller, &stPayload);
          }

          /* Is over? */
          if(u32EventIndex >= pstTrack->u32EventCounter)
          {
            orxTIMELINE_TRACK *pstTrack;

            /* Gets track */
            pstTrack = pstTimeLine->astTrackList[i].pstTrack;

            /* Inits event payload */
            orxMemory_Zero(&stPayload, sizeof(orxTIMELINE_EVENT_PAYLOAD));
            stPayload.pstTimeLine = pstTimeLine;
            stPayload.zTrackName  = pstTrack->zReference;

            /* Is a looping track? */
            if(orxFLAG_TEST(pstTrack->u32Flags, orxTIMELINE_TRACK_KU32_FLAG_LOOP))
            {
              /* Sends event */
              orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_LOOP, _pstCaller, _pstCaller, &stPayload);

              /* Resets track */
              pstTimeLine->astTrackList[i].u32NextEventIndex  = 0;
              pstTimeLine->astTrackList[i].fStartTime         = pstTimeLine->fTime;
            }
            else
            {
              /* Sends event */
              orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_TRACK_STOP, _pstCaller, _pstCaller, &stPayload);

              /* Removes its reference */
              pstTimeLine->astTrackList[i].pstTrack = orxNULL;

              /* Sends event */
              orxEVENT_SEND(orxEVENT_TYPE_TIMELINE, orxTIMELINE_EVENT_TRACK_REMOVE, _pstCaller, _pstCaller, &stPayload);

              /* Deletes it */
              orxTimeLine_DeleteTrack(pstTrack);
            }
          }
          else
          {
            /* Updates next event index */
            pstTimeLine->astTrackList[i].u32NextEventIndex = u32EventIndex;
          }
        }
      }
    }

    /* For all tracks */
    for(i = 0; i < orxTIMELINE_KU32_TRACK_NUMBER; i++)
    {
      /* Clears its update flag */
      orxFLAG_SET(pstTimeLine->astTrackList[i].u32Flags, orxTIMELINE_HOLDER_KU32_FLAG_NONE, orxTIMELINE_HOLDER_KU32_FLAG_UPDATED);
    }
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return eResult;
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
/** Update callback
 */
static void orxFASTCALL orxBounce_Update(const orxCLOCK_INFO *_pstClockInfo, void *_pstContext)
{
  orxVECTOR vMousePos;

  /* Profiles */
  orxPROFILER_PUSH_MARKER("Bounce_Update");

  if((sbRecord == orxFALSE) && (orxInput_IsActive("Record") != orxFALSE))
  {
    /* Starts recording with default settings */
    orxSound_StartRecording("orxSoundRecording.wav", orxFALSE, 0, 0);

    /* Updates status */
    sbRecord = orxTRUE;
  }

  if(orxInput_IsActive("ToggleTrail") && (orxInput_HasNewStatus("ToggleTrail")))
  {
    /* Toggles trail rendering */
    orxConfig_PushSection("Bounce");
    orxConfig_SetBool("DisplayTrail", !orxConfig_GetBool("DisplayTrail"));
    orxConfig_PopSection();
  }

  if(orxInput_IsActive("ToggleProfiler") && orxInput_HasNewStatus("ToggleProfiler"))
  {
    /* Toggles profiler rendering */
    orxConfig_PushSection(orxRENDER_KZ_CONFIG_SECTION);
    orxConfig_SetBool(orxRENDER_KZ_CONFIG_SHOW_PROFILER, !orxConfig_GetBool(orxRENDER_KZ_CONFIG_SHOW_PROFILER));
    orxConfig_PopSection();
  }

  if(orxInput_IsActive("PreviousResolution") && orxInput_HasNewStatus("PreviousResolution"))
  {
    /* Updates video mode index */
    su32VideoModeIndex = (su32VideoModeIndex == 0) ? orxDisplay_GetVideoModeCounter() - 1 : su32VideoModeIndex - 1;

    /* Applies it */
    orxBounce_ApplyCurrentVideoMode();
  }
  else if(orxInput_IsActive("NextResolution") && orxInput_HasNewStatus("NextResolution"))
  {
    /* Updates video mode index */
    su32VideoModeIndex = (su32VideoModeIndex >= orxDisplay_GetVideoModeCounter() - 1) ? 0 : su32VideoModeIndex + 1;

    /* Applies it */
    orxBounce_ApplyCurrentVideoMode();
  }
  if(orxInput_IsActive("ToggleFullScreen") && orxInput_HasNewStatus("ToggleFullScreen"))
  {
    /* Toggles full screen display */
    orxDisplay_SetFullScreen(!orxDisplay_IsFullScreen());
  }

  /* Pushes config section */
  orxConfig_PushSection("Bounce");

  /* Updates shader values */
  sfShaderPhase    += orxConfig_GetFloat("ShaderPhaseSpeed") * _pstClockInfo->fDT;
  sfShaderFrequency = orxConfig_GetFloat("ShaderMaxFrequency") * orxMath_Sin(orxConfig_GetFloat("ShaderFrequencySpeed") * _pstClockInfo->fTime);
  sfShaderAmplitude = orxConfig_GetFloat("ShaderMaxAmplitude") * orxMath_Sin(orxConfig_GetFloat("ShaderAmplitudeSpeed") * _pstClockInfo->fTime);

  /* Updates color time */
  sfColorTime -= _pstClockInfo->fDT;

  /* Should update color */
  if(sfColorTime <= orxFLOAT_0)
  {
    orxConfig_PushSection("BounceShader");
    orxConfig_GetVector("color", &svColor);
    orxConfig_PopSection();

    sfColorTime += orx2F(3.0f);
  }

  /* Gets mouse world position */
  orxRender_GetWorldPosition(&vMousePos, orxNULL, orxMouse_GetPosition(&vMousePos));

  /* Updates position */
  vMousePos.fZ += orx2F(0.5f);

  /* Has ball spawner? */
  if(spoBallSpawner != orxNULL)
  {
    /* Updates its position */
    orxSpawner_SetPosition(spoBallSpawner, &vMousePos);
  }

  /* Spawning */
  if(orxInput_IsActive("Spawn"))
  {
    /* Spawns one ball */
    orxSpawner_Spawn(spoBallSpawner, 1);
  }
  /* Picking? */
  else if(orxInput_IsActive("Pick"))
  {
    orxOBJECT *pstObject;

    /* Updates mouse position */
    vMousePos.fZ -= orx2F(0.1f);

    /* Picks object under mouse */
    pstObject = orxObject_Pick(&vMousePos, orxU32_UNDEFINED);

    /* Found? */
    if(pstObject)
    {
      /* Adds FX */
      orxObject_AddUniqueFX(pstObject, "Pick");
    }
  }

  /* Pops config section */
  orxConfig_PopSection();

  /* Toggle shader? */
  if(orxInput_IsActive("ToggleShader") && (orxInput_HasNewStatus("ToggleShader")))
  {
    /* Toggles shader status */
    sbShaderEnabled = !sbShaderEnabled;
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();
}
Ejemplo n.º 10
0
/** Bounce event handler
 * @param[in]   _pstEvent                     Sent event
 * @return      orxSTATUS_SUCCESS if handled / orxSTATUS_FAILURE otherwise
 */
static orxSTATUS orxFASTCALL orxBounce_EventHandler(const orxEVENT *_pstEvent)
{
  orxSTATUS eResult = orxSTATUS_SUCCESS;

  /* Profiles */
  orxPROFILER_PUSH_MARKER("Bounce_EventHandler");

  /* Checks */
  orxASSERT((_pstEvent->eType == orxEVENT_TYPE_PHYSICS)
         || (_pstEvent->eType == orxEVENT_TYPE_INPUT)
         || (_pstEvent->eType == orxEVENT_TYPE_SHADER)
         || (_pstEvent->eType == orxEVENT_TYPE_SOUND)
         || (_pstEvent->eType == orxEVENT_TYPE_DISPLAY)
         || (_pstEvent->eType == orxEVENT_TYPE_TIMELINE)
         || (_pstEvent->eType == orxEVENT_TYPE_RENDER));

  /* Depending on event type */
  switch(_pstEvent->eType)
  {
    /* Input */
    case orxEVENT_TYPE_INPUT:
    {
      /* Not a set selection and console not enabled? */
      if((_pstEvent->eID != orxINPUT_EVENT_SELECT_SET) && (orxConsole_IsEnabled() == orxFALSE))
      {
        orxINPUT_EVENT_PAYLOAD *pstPayload;

        /* Gets event payload */
        pstPayload = (orxINPUT_EVENT_PAYLOAD *)_pstEvent->pstPayload;

        /* Has a multi-input info? */
        if(pstPayload->aeType[1] != orxINPUT_TYPE_NONE)
        {
          /* Logs info */
          orxLOG("[%s::%s] is %s (%s/v=%g + %s/v=%g)", pstPayload->zSetName, pstPayload->zInputName, (_pstEvent->eID == orxINPUT_EVENT_ON) ? "ON " : "OFF", orxInput_GetBindingName(pstPayload->aeType[0], pstPayload->aeID[0], pstPayload->aeMode[0]), pstPayload->afValue[0], orxInput_GetBindingName(pstPayload->aeType[1], pstPayload->aeID[1], pstPayload->aeMode[1]), pstPayload->afValue[1]);
        }
        else
        {
          /* Logs info */
          orxLOG("[%s::%s] is %s (%s/v=%g)", pstPayload->zSetName, pstPayload->zInputName, (_pstEvent->eID == orxINPUT_EVENT_ON) ? "ON " : "OFF", orxInput_GetBindingName(pstPayload->aeType[0], pstPayload->aeID[0], pstPayload->aeMode[0]), pstPayload->afValue[0]);
        }
      }

      break;
    }

    /* Physics */
    case orxEVENT_TYPE_PHYSICS:
    {
      /* Colliding? */
      if(_pstEvent->eID == orxPHYSICS_EVENT_CONTACT_ADD)
      {
        /* Adds bump FX on both objects */
        orxObject_AddUniqueFX(orxOBJECT(_pstEvent->hSender), "Bump");
        orxObject_AddUniqueFX(orxOBJECT(_pstEvent->hRecipient), "Bump");
      }

      break;
    }

    /* Shader */
    case orxEVENT_TYPE_SHADER:
    {
      orxSHADER_EVENT_PAYLOAD *pstPayload;

      /* Profiles */
      orxPROFILER_PUSH_MARKER("Bounce_EventHandler_Shader");

      /* Checks */
      orxASSERT(_pstEvent->eID == orxSHADER_EVENT_SET_PARAM);

      /* Gets its payload */
      pstPayload = (orxSHADER_EVENT_PAYLOAD *)_pstEvent->pstPayload;

      /* Enabled? */
      if(!orxString_Compare(pstPayload->zParamName, "enabled"))
      {
        /* Updates its value */
        pstPayload->fValue = (sbShaderEnabled != orxFALSE) ? orxFLOAT_1 : orxFLOAT_0;
      }
      /* Phase? */
      else if(!orxString_Compare(pstPayload->zParamName, "phase"))
      {
        /* Updates its value */
        pstPayload->fValue = sfShaderPhase;
      }
      else if(!orxString_Compare(pstPayload->zParamName, "color"))
      {
        orxVector_Copy(&pstPayload->vValue, &svColor);
      }
      /* Frequency? */
      else if(!orxString_Compare(pstPayload->zParamName, "frequency"))
      {
        /* Updates its value */
        pstPayload->fValue = sfShaderFrequency;
      }
      /* Amplitude? */
      else if(!orxString_Compare(pstPayload->zParamName, "amplitude"))
      {
        /* Updates its value */
        pstPayload->fValue = sfShaderAmplitude;
      }

      /* Profiles */
      orxPROFILER_POP_MARKER();

      break;
    }

    /* Sound */
    case orxEVENT_TYPE_SOUND:
    {
      /* Recording packet? */
      if(_pstEvent->eID == orxSOUND_EVENT_RECORDING_PACKET)
      {
        orxSOUND_EVENT_PAYLOAD *pstPayload;

        /* Gets event payload */
        pstPayload = (orxSOUND_EVENT_PAYLOAD *)_pstEvent->pstPayload;

        /* Is recording input active? */
        if(orxInput_IsActive("Record") != orxFALSE)
        {
          orxU32 i;

          /* For all samples */
          for(i = 0; i < pstPayload->stStream.stPacket.u32SampleNumber / 2; i++)
          {
            /* Shorten the packets by half */
            pstPayload->stStream.stPacket.as16SampleList[i] = pstPayload->stStream.stPacket.as16SampleList[i * 2];
          }

          /* Updates sample number */
          pstPayload->stStream.stPacket.u32SampleNumber = pstPayload->stStream.stPacket.u32SampleNumber / 2;

          /* Asks for writing it */
          pstPayload->stStream.stPacket.bDiscard = orxFALSE;
        }
        else
        {
          /* Asks for not writing it */
          pstPayload->stStream.stPacket.bDiscard = orxTRUE;
        }
      }

      break;
    }

    /* Display */
    case orxEVENT_TYPE_DISPLAY:
    {
      /* New video mode? */
      if(_pstEvent->eID == orxDISPLAY_EVENT_SET_VIDEO_MODE)
      {
        orxDISPLAY_EVENT_PAYLOAD *pstPayload;
        orxCHAR                   acBuffer[1024];

        /* Gets payload */
        pstPayload = (orxDISPLAY_EVENT_PAYLOAD *)_pstEvent->pstPayload;

        /* Updates title string */
        orxConfig_PushSection("Bounce");
        orxString_NPrint(acBuffer, sizeof(acBuffer) - 1, "%s (%dx%d)", orxConfig_GetString("Title"), pstPayload->stVideoMode.u32Width, pstPayload->stVideoMode.u32Height);
        acBuffer[sizeof(acBuffer) - 1] = orxCHAR_NULL;
        orxConfig_PopSection();

        /* Updates display module config content */
        orxConfig_PushSection(orxDISPLAY_KZ_CONFIG_SECTION);
        orxConfig_SetString(orxDISPLAY_KZ_CONFIG_TITLE, acBuffer);
        orxConfig_PopSection();

        /* Updates window */
        orxDisplay_SetVideoMode(orxNULL);
      }

      break;
    }

    /* TimeLine */
    case orxEVENT_TYPE_TIMELINE:
    {
      /* New event triggered? */
      if(_pstEvent->eID == orxTIMELINE_EVENT_TRIGGER)
      {
        orxTIMELINE_EVENT_PAYLOAD *pstPayload;

        /* Gets event payload */
        pstPayload = (orxTIMELINE_EVENT_PAYLOAD *)_pstEvent->pstPayload;

        /* Logs info */
        orxLOG("[%s::%s::%s] has been triggered", orxObject_GetName(orxOBJECT(_pstEvent->hSender)), pstPayload->zTrackName, pstPayload->zEvent);
      }

      break;
    }

    /* Render */
    case orxEVENT_TYPE_RENDER:
    {
      /* Object start? */
      if(_pstEvent->eID == orxRENDER_EVENT_OBJECT_START)
      {
        /* Is walls? */
        if(orxOBJECT(_pstEvent->hSender) == spstWalls)
        {
          /* Pushes config section */
          orxConfig_PushSection("Bounce");

          /* Should display trail */
          if(orxConfig_GetBool("DisplayTrail"))
          {
            /* Draws trail */
            orxBounce_DisplayTrail(orxTexture_GetBitmap(orxTEXTURE(orxGraphic_GetData(orxOBJECT_GET_STRUCTURE(orxOBJECT(_pstEvent->hSender), GRAPHIC)))));
          }

          /* Pops config section */
          orxConfig_PopSection();

          /* Updates result */
          eResult = orxSTATUS_FAILURE;
        }
      }

      break;
    }

    default:
    {
      break;
    }
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return eResult;
}
Ejemplo n.º 11
0
/** Remove an item.
 * @param[in] _pstHashTable  The hash table where remove.
 * @param[in] _u64Key      Key to remove.
 * @return Returns the status of the operation.
 */
orxSTATUS orxFASTCALL orxHashTable_Remove(orxHASHTABLE *_pstHashTable, orxU64 _u64Key)
{
  orxU32 u32Index;                        /* Hash table index */
  orxHASHTABLE_CELL *pstCell;             /* Cell used to traverse */
  orxSTATUS eStatus = orxSTATUS_FAILURE;  /* Status to return */

  /* Profiles */
  orxPROFILER_PUSH_MARKER("orxHashTable_Remove");

  /* Checks */
  orxASSERT(_pstHashTable != orxNULL);

  /* Get the index from the key */
  u32Index = orxHashTable_FindIndex(_pstHashTable, _u64Key);

  pstCell = _pstHashTable->apstCell[u32Index];

  /* Is the first key is the key to remove ? */
  if(pstCell != orxNULL)
  {
    if(pstCell->u64Key == _u64Key)
    {
      /* The first cell has to be removed */
      _pstHashTable->apstCell[u32Index] = pstCell->pstNext;
      orxBank_Free(_pstHashTable->pstBank, pstCell);

      /* Operation succeed */
      eStatus = orxSTATUS_SUCCESS;
    }
    else
    {
      /* Traverse to find the key */
      while(pstCell->pstNext != orxNULL && pstCell->pstNext->u64Key != _u64Key)
      {
        /* Try with next cell */
        pstCell = pstCell->pstNext;
      }

      /* Cell found ? (key should be on the next cell) */
      if(pstCell->pstNext != orxNULL)
      {
        orxHASHTABLE_CELL *pstRemoveCell;

        /* We found it, remove this cell */
        pstRemoveCell = pstCell->pstNext;
        pstCell->pstNext = pstRemoveCell->pstNext;

        /* Free cell from bank */
        orxBank_Free(_pstHashTable->pstBank, pstRemoveCell);

        /* Operation succeed */
        eStatus = orxSTATUS_SUCCESS;
      }
    }
  }

  /* Successful? */
  if(eStatus != orxSTATUS_FAILURE)
  {
    /* Updates counter */
    _pstHashTable->u32Counter--;
  }

  /* Profiles */
  orxPROFILER_POP_MARKER();

  /* Done! */
  return eStatus;
}