Esempio n. 1
0
/** Stops all related sounds
 * @param[in] _pstSoundPointer      Concerned SoundPointer
 * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxSoundPointer_Stop(orxSOUNDPOINTER *_pstSoundPointer)
{
  orxU32    i;
  orxSTATUS eResult = orxSTATUS_SUCCESS;

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

  /* 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)
    {
      /* Updates its flags */
      orxFLAG_SET(_pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_NONE, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PLAY);

      /* Stops it */
      orxSound_Stop(pstSound);

      /* Delegates update to the sound */
      orxStructure_Update(pstSound, orxStructure_GetOwner(_pstSoundPointer), orxNULL);
    }
  }

  /* Done! */
  return eResult;
}
Esempio n. 2
0
/** Adds a delayed FX
 * @param[in]   _pstFXPointer Concerned FXPointer
 * @param[in]   _pstFX        FX to add
 * @param[in]   _fDelay       Delay time
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxFXPointer_AddDelayedFX(orxFXPOINTER *_pstFXPointer, orxFX *_pstFX, orxFLOAT _fDelay)
{
  orxU32    u32Index;
  orxSTATUS eResult;

  /* Checks */
  orxASSERT(sstFXPointer.u32Flags & orxFXPOINTER_KU32_STATIC_FLAG_READY);
  orxSTRUCTURE_ASSERT(_pstFXPointer);
  orxSTRUCTURE_ASSERT(_pstFX);
  orxASSERT(_fDelay >= orxFLOAT_0);

  /* Finds an empty slot */
  for(u32Index = 0; (u32Index < orxFXPOINTER_KU32_FX_NUMBER) && (_pstFXPointer->astFXList[u32Index].pstFX != orxNULL); u32Index++);

  /* Found? */
  if(u32Index < orxFXPOINTER_KU32_FX_NUMBER)
  {
    orxSTRUCTURE       *pstOwner;
    orxFX_EVENT_PAYLOAD stPayload;

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

    /* Increases its reference counter */
    orxStructure_IncreaseCounter(_pstFX);

    /* Adds it to holder */
    _pstFXPointer->astFXList[u32Index].pstFX = _pstFX;

    /* Inits its start time */
    _pstFXPointer->astFXList[u32Index].fStartTime = _pstFXPointer->fTime + _fDelay;

    /* Updates its flags */
    orxFLAG_SET(_pstFXPointer->astFXList[u32Index].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_NONE, orxFXPOINTER_HOLDER_KU32_MASK_ALL);

    /* 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_ADD, pstOwner, pstOwner, &stPayload);

    /* Updates result */
    eResult = orxSTATUS_SUCCESS;
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "No available slots for FX.");

    /* Updates result */
    eResult = orxSTATUS_FAILURE;
  }

  /* Done! */
  return eResult;
}
Esempio n. 3
0
/** Removes a track using its config ID
 * @param[in]   _pstTimeLine          Concerned TimeLine
 * @param[in]   _zTrackID             Config ID of the track to remove
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxTimeLine_RemoveTrackFromConfig(orxTIMELINE *_pstTimeLine, const orxSTRING _zTrackID)
{
  orxU32        u32Index, u32TrackID;
  orxSTRUCTURE *pstOwner;
  orxSTATUS   eResult = orxSTATUS_FAILURE;

  /* Checks */
  orxASSERT(sstTimeLine.u32Flags & orxTIMELINE_KU32_STATIC_FLAG_READY);
  orxASSERT((_zTrackID != orxNULL) && (_zTrackID != orxSTRING_EMPTY));

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

  /* Gets track ID */
  u32TrackID = orxString_ToCRC(_zTrackID);

  /* For all tracks */
  for(u32Index = 0; u32Index < orxTIMELINE_KU32_TRACK_NUMBER; u32Index++)
  {
    /* Is defined? */
    if(_pstTimeLine->astTrackList[u32Index].pstTrack != orxNULL)
    {
      /* Do IDs match? */
      if(_pstTimeLine->astTrackList[u32Index].pstTrack->u32ID == u32TrackID)
      {
        orxTIMELINE_EVENT_PAYLOAD stPayload;
        orxTIMELINE_TRACK        *pstTrack;

        /* Gets track */
        pstTrack = _pstTimeLine->astTrackList[u32Index].pstTrack;

        /* Removes its reference */
        _pstTimeLine->astTrackList[u32Index].pstTrack = orxNULL;

        /* 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_REMOVE, pstOwner, pstOwner, &stPayload);

        /* Deletes it */
        orxTimeLine_DeleteTrack(pstTrack);

        break;
      }
    }
  }

  /* Done! */
  return eResult;
}
Esempio n. 4
0
/** Removes an FX using its config ID
 * @param[in]   _pstFXPointer Concerned FXPointer
 * @param[in]   _zFXConfigID  Config ID of the FX to remove
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxFXPointer_RemoveFXFromConfig(orxFXPOINTER *_pstFXPointer, const orxSTRING _zFXConfigID)
{
  orxU32        i, u32ID;
  orxSTRUCTURE *pstOwner;
  orxSTATUS     eResult = orxSTATUS_FAILURE;

  /* Checks */
  orxASSERT(sstFXPointer.u32Flags & orxFXPOINTER_KU32_STATIC_FLAG_READY);
  orxSTRUCTURE_ASSERT(_pstFXPointer);
  orxASSERT((_zFXConfigID != orxNULL) && (_zFXConfigID != orxSTRING_EMPTY));

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

  /* Gets ID */
  u32ID = orxString_ToCRC(_zFXConfigID);

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

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

    /* Valid? */
    if(pstFX != orxNULL)
    {
      /* Found? */
      if(orxString_ToCRC(orxFX_GetName(pstFX)) == u32ID)
      {
        orxFX_EVENT_PAYLOAD stPayload;

        /* Decreases its reference counter */
        orxStructure_DecreaseCounter(pstFX);

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

        /* 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_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);
        }

        /* Updates result */
        eResult = orxSTATUS_SUCCESS;
        break;
      }
    }
  }

  /* Done! */
  return eResult;
}
Esempio n. 5
0
/** Adds a delayed FX using its config ID
 * @param[in]   _pstFXPointer Concerned FXPointer
 * @param[in]   _zFXConfigID  Config ID of the FX to add
 * @param[in]   _fDelay       Delay time
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxFXPointer_AddDelayedFXFromConfig(orxFXPOINTER *_pstFXPointer, const orxSTRING _zFXConfigID, orxFLOAT _fDelay)
{
  orxU32    u32Index;
  orxSTATUS eResult;

  /* Checks */
  orxASSERT(sstFXPointer.u32Flags & orxFXPOINTER_KU32_STATIC_FLAG_READY);
  orxSTRUCTURE_ASSERT(_pstFXPointer);
  orxASSERT((_zFXConfigID != orxNULL) && (_zFXConfigID != orxSTRING_EMPTY));
  orxASSERT(_fDelay >= orxFLOAT_0);

  /* Finds an empty slot */
  for(u32Index = 0; (u32Index < orxFXPOINTER_KU32_FX_NUMBER) && (_pstFXPointer->astFXList[u32Index].pstFX != orxNULL); u32Index++);

  /* Found? */
  if(u32Index < orxFXPOINTER_KU32_FX_NUMBER)
  {
    orxFX *pstFX;

    /* Creates FX */
    pstFX = orxFX_CreateFromConfig(_zFXConfigID);

    /* Valid? */
    if(pstFX != orxNULL)
    {
      orxSTRUCTURE       *pstOwner;
      orxFX_EVENT_PAYLOAD stPayload;

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

      /* Increases its reference counter */
      orxStructure_IncreaseCounter(pstFX);

      /* Adds it to holder */
      _pstFXPointer->astFXList[u32Index].pstFX = pstFX;

      /* Inits its start time */
      _pstFXPointer->astFXList[u32Index].fStartTime = _pstFXPointer->fTime + _fDelay;

      /* Updates its owner */
      orxStructure_SetOwner(pstFX, _pstFXPointer);

      /* Updates its flags */
      orxFLAG_SET(_pstFXPointer->astFXList[u32Index].u32Flags, orxFXPOINTER_HOLDER_KU32_FLAG_INTERNAL, orxFXPOINTER_HOLDER_KU32_MASK_ALL);

      /* 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_ADD, pstOwner, pstOwner, &stPayload);

      /* Updates result */
      eResult = orxSTATUS_SUCCESS;
    }
    else
    {
      /* Logs message */
      orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "Loading FX <%s> from config failed.", _zFXConfigID);

      /* Updates result */
      eResult = orxSTATUS_FAILURE;
    }
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_SOUND, "Failed to find an empty slot to put FX <%s> into.", _zFXConfigID);

    /* Updates result */
    eResult = orxSTATUS_FAILURE;
  }

  /* Done! */
  return eResult;
}
Esempio n. 6
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;
}
Esempio n. 7
0
/** Adds a sound using its config ID
 * @param[in]   _pstSoundPointer    Concerned SoundPointer
 * @param[in]   _zSoundConfigID     Config ID of the sound to add
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxSoundPointer_AddSoundFromConfig(orxSOUNDPOINTER *_pstSoundPointer, const orxSTRING _zSoundConfigID)
{
  orxU32    u32Index;
  orxSTATUS eResult;

  /* Checks */
  orxASSERT(sstSoundPointer.u32Flags & orxSOUNDPOINTER_KU32_STATIC_FLAG_READY);
  orxSTRUCTURE_ASSERT(_pstSoundPointer);
  orxASSERT((_zSoundConfigID != orxNULL) && (_zSoundConfigID != orxSTRING_EMPTY));

  /* Finds an empty slot */
  for(u32Index = 0; (u32Index < orxSOUNDPOINTER_KU32_SOUND_NUMBER) && (_pstSoundPointer->astSoundList[u32Index].pstSound != orxNULL); u32Index++);

  /* Not found? */
  if(u32Index == orxSOUNDPOINTER_KU32_SOUND_NUMBER)
  {
    orxFLOAT  fShortestDuration;
    orxU32    u32ShortestIndex;

    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_SOUND, "No free slot to play sound <%s>, replacing shortest one.", _zSoundConfigID);

    /* Gets first index */
    u32ShortestIndex = (_pstSoundPointer->u32LastAddedIndex == 0) ? 1 : 0;

    /* Gets its duration */
    fShortestDuration = orxSound_GetDuration(_pstSoundPointer->astSoundList[u32ShortestIndex].pstSound);

    /* For all other sounds */
    for(u32Index = u32ShortestIndex + 1; (u32Index < orxSOUNDPOINTER_KU32_SOUND_NUMBER); u32Index++)
    {
      /* Not the latest added one? */
      if(u32Index != _pstSoundPointer->u32LastAddedIndex)
      {
        orxFLOAT fDuration;

        /* Gets its duration */
        fDuration = orxSound_GetDuration(_pstSoundPointer->astSoundList[u32Index].pstSound);

        /* Shorter? */
        if(fDuration < fShortestDuration)
        {
          /* Selects it */
          u32ShortestIndex = u32Index;
        }
      }
    }

    /* Removes it */
    orxSoundPointer_RemoveSound(_pstSoundPointer, _pstSoundPointer->astSoundList[u32ShortestIndex].pstSound);

    /* Updates index */
    u32Index = u32ShortestIndex;
  }

  /* Found? */
  if(u32Index < orxSOUNDPOINTER_KU32_SOUND_NUMBER)
  {
    orxSOUND *pstSound;

    /* Creates sound */
    pstSound = orxSound_CreateFromConfig(_zSoundConfigID);

    /* Valid? */
    if(pstSound != orxNULL)
    {
      orxSOUND_EVENT_PAYLOAD  stPayload;
      orxOBJECT              *pstOwner;

      /* Increases its reference counter */
      orxStructure_IncreaseCounter(pstSound);

      /* Adds it to holder */
      _pstSoundPointer->astSoundList[u32Index].pstSound = pstSound;

      /* Updates its owner */
      orxStructure_SetOwner(pstSound, _pstSoundPointer);

      /* Updates its flags */
      orxFLAG_SET(_pstSoundPointer->astSoundList[u32Index].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_INTERNAL | orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PLAY, orxSOUNDPOINTER_HOLDER_KU32_MASK_ALL);

      /* Stores it as last added sound */
      _pstSoundPointer->u32LastAddedIndex = u32Index;

      /* Gets its owner object */
      pstOwner = orxOBJECT(orxStructure_GetOwner(_pstSoundPointer));

      /* Valid? */
      if(pstOwner != orxNULL)
      {
         orxVECTOR vPosition;

         /* Updates its position */
         orxSound_SetPosition(pstSound, orxObject_GetWorldPosition(pstOwner, &vPosition));
      }

      /* Inits event payload */
      orxMemory_Zero(&stPayload, sizeof(orxSOUND_EVENT_PAYLOAD));
      stPayload.pstSound = pstSound;

      /* Sends event */
      orxEVENT_SEND(orxEVENT_TYPE_SOUND, orxSOUND_EVENT_ADD, pstOwner, pstOwner, &stPayload);

      /* Updates result */
      eResult = orxSTATUS_SUCCESS;
    }
    else
    {
      /* Logs message */
      orxDEBUG_PRINT(orxDEBUG_LEVEL_SOUND, "Could not find object named '%s' in config.", _zSoundConfigID);

      /* Clears last added sound index */
      _pstSoundPointer->u32LastAddedIndex = orxU32_UNDEFINED;

      /* Updates result */
      eResult = orxSTATUS_FAILURE;
    }
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_SOUND, "Failed to find an empty slot to put sound <%s> into.", _zSoundConfigID);

    /* Updates result */
    eResult = orxSTATUS_FAILURE;
  }

  /* Done! */
  return eResult;
}
Esempio n. 8
0
/** Removes all sounds
 * @param[in]   _pstSoundPointer    Concerned SoundPointer
 * @return      orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxSoundPointer_RemoveAllSounds(orxSOUNDPOINTER *_pstSoundPointer)
{
  orxU32    i;
  orxSTATUS eResult = orxSTATUS_FAILURE;

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

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

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

    /* Valid? */
    if(pstSound != orxNULL)
    {
      orxSOUND_EVENT_PAYLOAD  stPayload;
      orxSTRUCTURE           *pstOwner;

      /* Inits event payload */
      orxMemory_Zero(&stPayload, sizeof(orxSOUND_EVENT_PAYLOAD));
      stPayload.pstSound = pstSound;

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

      /* Wasn't stopped? */
      if(orxSound_GetStatus(pstSound) != orxSOUND_STATUS_STOP)
      {
        /* Sends stop event */
        orxEVENT_SEND(orxEVENT_TYPE_SOUND, orxSOUND_EVENT_STOP, pstOwner, pstOwner, &stPayload);
      }

      /* Sends event */
      orxEVENT_SEND(orxEVENT_TYPE_SOUND, orxSOUND_EVENT_REMOVE, pstOwner, pstOwner, &stPayload);

      /* Decreases its reference counter */
      orxStructure_DecreaseCounter(pstSound);

      /* Was last added sound? */
      if(_pstSoundPointer->u32LastAddedIndex == i)
      {
        /* Clears last added sound index */
        _pstSoundPointer->u32LastAddedIndex = orxU32_UNDEFINED;
      }

      /* Removes its reference */
      _pstSoundPointer->astSoundList[i].pstSound = orxNULL;

      /* Is internal? */
      if(orxFLAG_TEST(_pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_INTERNAL))
      {
        /* Removes its owner */
        orxStructure_SetOwner(pstSound, orxNULL);

        /* Deletes it */
        orxSound_Delete(pstSound);
      }

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

  /* Done! */
  return eResult;
}
Esempio n. 9
0
/** Event handler
 */
static orxSTATUS orxFASTCALL orxSoundPointer_EventHandler(const orxEVENT *_pstEvent)
{
  orxSTATUS eResult = orxSTATUS_SUCCESS;

  /* Depending on event ID */
  switch(_pstEvent->eID)
  {
    /* Pause / disable */
    case orxOBJECT_EVENT_PAUSE:
    case orxOBJECT_EVENT_DISABLE:
    {
      orxSOUNDPOINTER *pstSoundPointer;

      /* Gets sound pointer */
      pstSoundPointer = orxOBJECT_GET_STRUCTURE(orxOBJECT(_pstEvent->hSender), SOUNDPOINTER);

      /* Valid? */
      if(pstSoundPointer != orxNULL)
      {
        orxU32 i;

        /* For all Sounds */
        for(i = 0; i < orxSOUNDPOINTER_KU32_SOUND_NUMBER; i++)
        {
          /* Valid? */
          if(pstSoundPointer->astSoundList[i].pstSound != orxNULL)
          {
            /* Is playing? */
            if(orxSound_GetStatus(pstSoundPointer->astSoundList[i].pstSound) == orxSOUND_STATUS_PLAY)
            {
              /* Pauses it */
              orxSound_Pause(pstSoundPointer->astSoundList[i].pstSound);

              /* Updates its status */
              orxFLAG_SET(pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PAUSE, orxSOUNDPOINTER_HOLDER_KU32_FLAG_NONE);

              /* Delegates update to the sound */
              orxStructure_Update(pstSoundPointer->astSoundList[i].pstSound, orxStructure_GetOwner(pstSoundPointer), orxNULL);
            }
          }
        }
      }

      break;
    }

    /* Unpause / enable */
    case orxOBJECT_EVENT_UNPAUSE:
    case orxOBJECT_EVENT_ENABLE:
    {
      orxSOUNDPOINTER *pstSoundPointer;

      /* Gets sound pointer */
      pstSoundPointer = orxOBJECT_GET_STRUCTURE(orxOBJECT(_pstEvent->hSender), SOUNDPOINTER);

      /* Valid? */
      if(pstSoundPointer != orxNULL)
      {
        orxU32 i;

        /* For all Sounds */
        for(i = 0; i < orxSOUNDPOINTER_KU32_SOUND_NUMBER; i++)
        {
          /* Valid? */
          if(pstSoundPointer->astSoundList[i].pstSound != orxNULL)
          {
            /* Is auto-paused? */
            if(orxFLAG_TEST(pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PAUSE))
            {
              /* Resumes it */
              orxSound_Play(pstSoundPointer->astSoundList[i].pstSound);

              /* Updates its status */
              orxFLAG_SET(pstSoundPointer->astSoundList[i].u32Flags, orxSOUNDPOINTER_HOLDER_KU32_FLAG_NONE, orxSOUNDPOINTER_HOLDER_KU32_FLAG_AUTO_PAUSE);

              /* Delegates update to the sound */
              orxStructure_Update(pstSoundPointer->astSoundList[i].pstSound, orxStructure_GetOwner(pstSoundPointer), orxNULL);
            }
          }
        }
      }

      break;
    }

    default:
    {
      break;
    }
  }

  /* Done! */
  return eResult;
}
Esempio n. 10
0
/** Adds a track to a TimeLine from config
 * @param[in]   _pstTimeLine          Concerned TimeLine
 * @param[in]   _zTrackID             Config ID
 * return       orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxTimeLine_AddTrackFromConfig(orxTIMELINE *_pstTimeLine, const orxSTRING _zTrackID)
{
  orxU32    u32Index;
  orxSTATUS eResult = orxSTATUS_FAILURE;

  /* Checks */
  orxSTRUCTURE_ASSERT(_pstTimeLine);
  orxASSERT((_zTrackID != orxNULL) && (_zTrackID != orxSTRING_EMPTY));

  /* Checks */
  orxSTRUCTURE_ASSERT(_pstTimeLine);

  /* Finds an empty track */
  for(u32Index = 0; (u32Index < orxTIMELINE_KU32_TRACK_NUMBER) && (_pstTimeLine->astTrackList[u32Index].pstTrack != orxNULL); u32Index++);

  /* Found? */
  if(u32Index < orxTIMELINE_KU32_TRACK_NUMBER)
  {
    orxTIMELINE_TRACK  *pstTrack;
    orxU32              u32ID;

    /* Gets track ID */
    u32ID = orxString_ToCRC(_zTrackID);

    /* Search for reference */
    pstTrack = (orxTIMELINE_TRACK *)orxHashTable_Get(sstTimeLine.pstTrackTable, u32ID);

    /* Found? */
    if(pstTrack != orxNULL)
    {
      /* Increases counter */
      pstTrack->u32RefCounter++;
    }
    else
    {
      /* Creates track */
      pstTrack = orxTimeLine_CreateTrack(_zTrackID);
    }

    /* Valid? */
    if(pstTrack != orxNULL)
    {
      orxTIMELINE_EVENT_PAYLOAD stPayload;
      orxSTRUCTURE             *pstOwner;

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

      /* Updates track holder */
      _pstTimeLine->astTrackList[u32Index].pstTrack           = pstTrack;
      _pstTimeLine->astTrackList[u32Index].fStartTime         = _pstTimeLine->fTime;
      _pstTimeLine->astTrackList[u32Index].u32NextEventIndex  = 0;
      _pstTimeLine->astTrackList[u32Index].u32Flags           = orxTIMELINE_HOLDER_KU32_FLAG_NONE;

      /* 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_ADD, pstOwner, pstOwner, &stPayload);

      /* Updates timeline flags */
      orxStructure_SetFlags(_pstTimeLine, orxTIMELINE_KU32_FLAG_DIRTY, orxTIMELINE_KU32_FLAG_NONE);

      /* Is immediate? */
      if(orxFLAG_TEST(pstTrack->u32Flags, orxTIMELINE_TRACK_KU32_FLAG_IMMEDIATE))
      {
        /* Updates it */
        orxTimeLine_Update(orxSTRUCTURE(_pstTimeLine), pstOwner, orxNULL);
      }

      /* Updates result */
      eResult = orxSTATUS_SUCCESS;
    }
  }
  else
  {
    /* Logs message */
    orxDEBUG_PRINT(orxDEBUG_LEVEL_OBJECT, "No room for a new track in TimeLine, can't add track <%s>.", _zTrackID);
  }

  /* Done! */
  return eResult;
}
Esempio n. 11
0
/** Deletes a TimeLine
 * @param[in] _pstTimeLine            Concerned TimeLine
 * @return orxSTATUS_SUCCESS / orxSTATUS_FAILURE
 */
orxSTATUS orxFASTCALL orxTimeLine_Delete(orxTIMELINE *_pstTimeLine)
{
  orxSTATUS eResult = orxSTATUS_SUCCESS;

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

  /* Decreases counter */
  orxStructure_DecreaseCounter(_pstTimeLine);

  /* Not referenced? */
  if(orxStructure_GetRefCounter(_pstTimeLine) == 0)
  {
    orxTIMELINE_EVENT_PAYLOAD stPayload;
    orxSTRUCTURE             *pstOwner;
    orxU32                    i;

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

    /* Inits event payload */
    orxMemory_Zero(&stPayload, sizeof(orxTIMELINE_EVENT_PAYLOAD));
    stPayload.pstTimeLine = _pstTimeLine;

    /* For all tracks */
    for(i = 0; i < orxTIMELINE_KU32_TRACK_NUMBER; i++)
    {
      /* Valid? */
      if(_pstTimeLine->astTrackList[i].pstTrack != orxNULL)
      {
        orxTIMELINE_TRACK *pstTrack;

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

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

        /* Updates payload */
        stPayload.zTrackName = pstTrack->zReference;

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

        /* Deletes it */
        orxTimeLine_DeleteTrack(pstTrack);
      }
    }

    /* Deletes structure */
    orxStructure_Delete(_pstTimeLine);
  }
  else
  {
    /* Referenced by others */
    eResult = orxSTATUS_FAILURE;
  }

  /* Done! */
  return eResult;
}