static orxSTATUS orxFASTCALL EventHandler(const orxEVENT *_pstEvent) { orxSTATUS eResult = orxSTATUS_SUCCESS; /* 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"); /* Adds bip sound on one of them */ orxObject_AddSound(orxOBJECT(_pstEvent->hSender), "Bip"); } /* Done! */ return eResult; }
/** 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; }
/** 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; }
/** 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; }
/** Sets camera parent * @param[in] _pstCamera Concerned camera * @param[in] _pParent Parent structure to set (object, camera or frame) / orxNULL * @return orsSTATUS_SUCCESS / orxSTATUS_FAILURE */ orxSTATUS orxFASTCALL orxCamera_SetParent(orxCAMERA *_pstCamera, void *_pParent) { orxFRAME *pstFrame; orxSTATUS eResult = orxSTATUS_SUCCESS; /* Checks */ orxASSERT(sstCamera.u32Flags & orxCAMERA_KU32_STATIC_FLAG_READY); orxSTRUCTURE_ASSERT(_pstCamera); orxASSERT((_pParent == orxNULL) || (((orxSTRUCTURE *)(_pParent))->eID ^ orxSTRUCTURE_MAGIC_TAG_ACTIVE) < orxSTRUCTURE_ID_NUMBER); /* Gets frame */ pstFrame = _pstCamera->pstFrame; /* No parent? */ if(_pParent == orxNULL) { /* Removes parent */ orxFrame_SetParent(pstFrame, orxNULL); } else { /* Depending on parent ID */ switch(orxStructure_GetID(_pParent)) { case orxSTRUCTURE_ID_CAMERA: { /* Updates its parent */ orxFrame_SetParent(pstFrame, orxCAMERA(_pParent)->pstFrame); break; } case orxSTRUCTURE_ID_FRAME: { /* Updates its parent */ orxFrame_SetParent(pstFrame, orxFRAME(_pParent)); break; } case orxSTRUCTURE_ID_OBJECT: { /* Updates its parent */ orxFrame_SetParent(pstFrame, orxOBJECT_GET_STRUCTURE(orxOBJECT(_pParent), FRAME)); break; } case orxSTRUCTURE_ID_SPAWNER: { /* Updates its parent */ orxFrame_SetParent(pstFrame, orxSpawner_GetFrame(orxSPAWNER(_pParent))); break; } default: { /* Logs message */ orxDEBUG_PRINT(orxDEBUG_LEVEL_RENDER, "Invalid ID for structure."); /* Updates result */ eResult = orxSTATUS_FAILURE; break; } } } /* Done! */ return eResult; }
/** 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; }