void CCoral::DestroyAllModules() { for (unsigned int i = 0; i < modules.size(); i++) { DestroyModule(modules[i]); } }
XnStatus XnSensor::CreateDeviceModule(XnDeviceModuleHolder** ppModuleHolder) { XnStatus nRetVal = XN_STATUS_OK; nRetVal = XnDeviceBase::CreateDeviceModule(ppModuleHolder); XN_IS_STATUS_OK(nRetVal); // add sensor properties XnDeviceModule* pModule = (*ppModuleHolder)->GetModule(); XnProperty* pProps[] = { &m_ErrorState, &m_ResetSensorOnStartup, &m_Interface, &m_ReadFromEP1, &m_ReadFromEP2, &m_ReadFromEP3, &m_ReadData, &m_NumberOfBuffers, &m_FirmwareParam, &m_CmosBlankingUnits, &m_CmosBlankingTime, &m_Reset, &m_FirmwareMode, &m_Version, &m_FixedParam, &m_FrameSync, &m_CloseStreamsOnShutdown, &m_InstancePointer, &m_ID, &m_USBPath, &m_DeviceName, &m_VendorSpecificData, }; nRetVal = pModule->AddProperties(pProps, sizeof(pProps)/sizeof(XnProperty*)); if (nRetVal != XN_STATUS_OK) { DestroyModule(*ppModuleHolder); *ppModuleHolder = NULL; return (nRetVal); } // configure it from global file if (m_strGlobalConfigFile[0] != '\0') { nRetVal = pModule->LoadConfigFromFile(m_strGlobalConfigFile); XN_IS_STATUS_OK(nRetVal); } return (XN_STATUS_OK); }
XnStatus XnDeviceBase::Destroy() { XnStatus nRetVal = XN_STATUS_OK; // free all modules while (m_Modules.Size() != 0) { XnDeviceModuleHolder* pModuleHolder = m_Modules.Begin()->Value(); if (IsStream(pModuleHolder->GetModule())) { XnChar strName[XN_DEVICE_MAX_STRING_LENGTH]; strcpy(strName, pModuleHolder->GetModule()->GetName()); nRetVal = DestroyStream(strName); XN_IS_STATUS_OK(nRetVal); } else { // free memory of registered properties to this module FreeModuleRegisteredProperties(m_Modules.Begin()->Key()); pModuleHolder->GetModule()->Free(); DestroyModule(pModuleHolder); m_Modules.Remove(m_Modules.Begin()); } } m_pDevicePropertiesHolder = NULL; m_Modules.Clear(); // close dump xnDumpFileClose(m_StreamsDataDump); if (m_hLock != NULL) { xnOSCloseCriticalSection(&m_hLock); m_hLock = NULL; } return XN_STATUS_OK; }
XnStatus XnSensorClient::CreateDeviceModule(XnDeviceModuleHolder** ppModuleHolder) { XnStatus nRetVal = XN_STATUS_OK; nRetVal = XnDeviceBase::CreateDeviceModule(ppModuleHolder); XN_IS_STATUS_OK(nRetVal); // add sensor properties XnDeviceModule* pModule = (*ppModuleHolder)->GetModule(); XnProperty* pProps[] = { &m_InstancePointer, &m_ErrorState }; nRetVal = pModule->AddProperties(pProps, sizeof(pProps)/sizeof(XnProperty*)); if (nRetVal != XN_STATUS_OK) { DestroyModule(*ppModuleHolder); *ppModuleHolder = NULL; return (nRetVal); } return (XN_STATUS_OK); }
XnStatus XnDeviceFileReader::CreateDeviceModule(XnDeviceModuleHolder** ppModuleHolder) { XnStatus nRetVal = XN_STATUS_OK; nRetVal = XnStreamReaderDevice::CreateDeviceModule(ppModuleHolder); XN_IS_STATUS_OK(nRetVal); XnDeviceModule* pModule = (*ppModuleHolder)->GetModule(); // add sensor properties XnProperty* pProps[] = { &m_FrameDelay, &m_InstancePointer }; nRetVal = pModule->AddProperties(pProps, sizeof(pProps)/sizeof(XnProperty*)); if (nRetVal != XN_STATUS_OK) { DestroyModule(*ppModuleHolder); *ppModuleHolder = NULL; return (nRetVal); } return (XN_STATUS_OK); }
XnStatus XnDeviceBase::CreateDeviceModule(XnDeviceModuleHolder** ppModuleHolder) { XnStatus nRetVal = XN_STATUS_OK; // create module nRetVal = CreateModule(XN_MODULE_NAME_DEVICE, ppModuleHolder); XN_IS_STATUS_OK(nRetVal); XnDeviceModule* pModule = (*ppModuleHolder)->GetModule(); // add device properties XnProperty* pProps[] = { &m_DeviceMirror }; nRetVal = pModule->AddProperties(pProps, sizeof(pProps)/sizeof(XnProperty*)); if (nRetVal != XN_STATUS_OK) { DestroyModule(*ppModuleHolder); *ppModuleHolder = NULL; return (nRetVal); } return XN_STATUS_OK; }
XnStatus XnDeviceBase::CreateDeviceModule(XnDeviceModuleHolder** ppModuleHolder) { XnStatus nRetVal = XN_STATUS_OK; // create module nRetVal = CreateModule(XN_MODULE_NAME_DEVICE, ppModuleHolder); XN_IS_STATUS_OK(nRetVal); XnDeviceModule* pModule = (*ppModuleHolder)->GetModule(); // add device properties XnProperty* pProps[] = { &m_ReadWriteMode, &m_SharingMode, &m_PrimaryStream, &m_DeviceMirror, &m_SDKVersionProp, &m_HighResTimestamps, &m_DeviceName }; nRetVal = pModule->AddProperties(pProps, sizeof(pProps)/sizeof(XnProperty*)); if (nRetVal != XN_STATUS_OK) { DestroyModule(*ppModuleHolder); *ppModuleHolder = NULL; return (nRetVal); } return XN_STATUS_OK; }
//==================================================================================== // THE MAIN INTERNAL FUNCTIONS //------------------------------------------------------------------------------------ DWORD WINAPI WorkerThread(LPVOID lpParameter) { MSG ThNewMsg; PVOICEINFO VoiceInf; LogMsg("Entering worker thread..."); if((VoiceInf=&ModInfo->VoiceInf[VoiceMale])->VoiceEnabled) { LogMsg("Trying to initialize 'VoiceMale'."); VoiceInf->Voice.Initialize(SPKTOMEMB, FALSE); VoiceInf->Voice.SetOutputFormat(SOAF44kHz16BitM); VoiceInf->Voice.SetVoiceConfig((LPSTR)&VoiceInf->VoiceConfig); if(VoiceInf->Voice.SetVoice((LPSTR)&VoiceInf->VoiceName))LogMsg("'VoiceMale' is failed to initialize."); else LogMsg("'VoiceMale' is initialized."); } if((VoiceInf=&ModInfo->VoiceInf[VoiceFemale])->VoiceEnabled) { LogMsg("Trying to initialize 'VoiceFemale'."); VoiceInf->Voice.Initialize(SPKTOMEMB, FALSE); VoiceInf->Voice.SetOutputFormat(SOAF44kHz16BitM); VoiceInf->Voice.SetVoiceConfig((LPSTR)&VoiceInf->VoiceConfig); if(VoiceInf->Voice.SetVoice((LPSTR)&VoiceInf->VoiceName))LogMsg("'VoiceFemale' is failed to initialize."); else LogMsg("'VoiceFemale' is initialized."); } if((VoiceInf=&ModInfo->VoiceInf[VoiceCreature])->VoiceEnabled) { LogMsg("Trying to initialize 'VoiceCreature'."); VoiceInf->Voice.Initialize(SPKTOMEMB, FALSE); VoiceInf->Voice.SetOutputFormat(SOAF44kHz16BitM); VoiceInf->Voice.SetVoiceConfig((LPSTR)&VoiceInf->VoiceConfig); if(VoiceInf->Voice.SetVoice((LPSTR)&VoiceInf->VoiceName))LogMsg("'VoiceCreature' is failed to initialize."); else LogMsg("'VoiceCreature' is initialized."); } if((VoiceInf=&ModInfo->VoiceInf[VoiceDocument])->VoiceEnabled && !ModInfo->Config.DocVoiceAsDlg) { LogMsg("Trying to initialize 'VoiceDocument'."); VoiceInf->Voice.Initialize(SPKTOMEMB, FALSE); VoiceInf->Voice.SetOutputFormat(SOAF44kHz16BitM); VoiceInf->Voice.SetVoiceConfig((LPSTR)&VoiceInf->VoiceConfig); if(VoiceInf->Voice.SetVoice((LPSTR)&VoiceInf->VoiceName))LogMsg("'VoiceDocument' is failed to initialize."); else LogMsg("'VoiceDocument' is initialized."); } LogMsg("Entering a message loop."); PeekMessage(&ThNewMsg, NULL, 0, MAXDWORD, PM_REMOVE); while(1) { if(ModInfo->GameInMenuMode || ModInfo->CurrentTalker->IsPlaying())PeekMessage(&ThNewMsg, NULL, MSG_START_SPEAK, MSG_THREADEXIT, PM_REMOVE); else GetMessage(&ThNewMsg, NULL, MSG_START_SPEAK, MSG_THREADEXIT); // LogMsg("Message received: %08X.",ThNewMsg.message); if(ThNewMsg.message == MSG_START_SPEAK){(reinterpret_cast<PCTalker>(ThNewMsg.wParam))->SpeakToBuffer();} if(ThNewMsg.message == MSG_THREADEXIT)break; ThNewMsg.message = NULL; ThNewMsg.lParam = NULL; ThNewMsg.wParam = NULL; Sleep(KEYWAITDEL); if(ModInfo->GameInMenuMode && IsKeyCombinationPressed(ModInfo->Config.SpeakKeyCode) && !ModInfo->CurrentTalker->IsPlaying()){ModInfo->CurrentTalker->SendWavDataToObject();continue;} if(ModInfo->GameInMenuMode && IsKeyCombinationPressed(ModInfo->Config.SilenceKeyCode)){ModInfo->CurrentTalker->Silence();continue;} if(!ModInfo->GameInMenuMode && IsKeyCombinationPressed(ModInfo->Config.SilenceKeyCode)){ModInfo->CurrentTalker->SilenceAllTalkers();continue;} } // When exiting from a game menu, this code will never be reached! LogMsg("Exiting TalkyMorrowind..."); DestroyModule(); FreeLibraryAndExitThread(ModInfo->ThisLibBase,1); return 0; }
//==================================================================================== DWORD _stdcall ModEventOnHostExit(void) { LogMsg("Unloading..."); DestroyModule(); return 0; }
void CCoral::SetModuleData(std::vector<EntityData> mods) { modules.resize(mods.size()); for (unsigned int i = 0; i < mods.size(); i++) { //If this module is alive in object, but types don't match up if (modules[i] && (EntityType)modules[i]->GetType() != mods[i].type) { //Kill it, but kill it safely DestroyModule(modules[i], true); } //If this module is dead in object and alive in data if (mods[i].type != EntityType::BaseClass && !modules[i]) { switch (mods[i].type) { case EntityType::BaseModule: modules[i] = new CModule; break; case EntityType::ShieldModule: modules[i] = new CShieldModule; break; case EntityType::EngineModule: modules[i] = new CEngine; break; case EntityType::LaserModule: modules[i] = new CLaserModule; break; case EntityType::MissileModule: modules[i] = new CMissileModule; break; case EntityType::WellModule: modules[i] = new CWellModule; break; case EntityType::PushModule: modules[i] = new CPushModule; break; case EntityType::WarpModule: modules[i] = new CWarpModule; break; } modules[i]->SetOffset(modulePositions[i]); modules[i]->SetOwner(this); } //If this module is dead in data if (mods[i].type == EntityType::BaseClass) { //We already killed it. Types wouldn't match up in this case. //Kill it in object //DestroyModule(modules[i], true); //We're done with this one continue; } //We should only hit this with a live module of a type that matches the one in data modules[i]->SetHull(mods[i].hull); if ((EntityType)modules[i]->GetType() == EntityType::Shield) { dynamic_cast<CShieldModule*>(modules[i])->SetShield(mods[i].shield); } } }
CSnowboard::~CSnowboard() { DestroyModule(); }
XnStatus XnStreamReaderDevice::SetInitialState(const XnDeviceConfig* pDeviceConfig, XnPropertySet* pSet) { XnStatus nRetVal = XN_STATUS_OK; // Fix state (remove some properties that we don't wish to reflect in reader device) XnActualPropertiesHash* pDeviceModule = NULL; if (XN_STATUS_OK == pSet->pData->Get(XN_MODULE_NAME_DEVICE, pDeviceModule)) { pDeviceModule->Remove(XN_MODULE_PROPERTY_READ_WRITE_MODE); pDeviceModule->Remove(XN_MODULE_PROPERTY_PRIMARY_STREAM); } // now init base using this state (this will also create module DEVICE) XnDeviceConfig initConfig; initConfig.cpConnectionString = pDeviceConfig->cpConnectionString; initConfig.DeviceMode = pDeviceConfig->DeviceMode; initConfig.pInitialValues = pSet; initConfig.SharingMode = pDeviceConfig->SharingMode; nRetVal = XnStreamDevice::InitImpl(&initConfig); XN_IS_STATUS_OK(nRetVal); // now create the rest of the modules and streams (DEVICE was already created) XnPropertySetData* pPropSetData = pSet->pData; for (XnPropertySetData::ConstIterator it = pPropSetData->begin(); it != pPropSetData->end(); ++it) { // ignore module DEVICE if (strcmp(XN_MODULE_NAME_DEVICE, it.Key()) == 0) { continue; } // check if this is a stream XnActualPropertiesHash::ConstIterator itProp = it.Value()->end(); if (XN_STATUS_OK == it.Value()->Find(XN_STREAM_PROPERTY_TYPE, itProp)) { XnActualStringProperty* pTypeProp = (XnActualStringProperty*)itProp.Value(); nRetVal = HandleNewStream(pTypeProp->GetValue(), it.Key(), it.Value()); XN_IS_STATUS_OK(nRetVal); } else { // this is module. create it XnDeviceModuleHolder* pHolder = NULL; nRetVal = CreateModule(it.Key(), &pHolder); XN_IS_STATUS_OK(nRetVal); // set its props nRetVal = pHolder->Init(it.Value()); if (nRetVal != XN_STATUS_OK) { DestroyModule(pHolder); return (nRetVal); } // and add it nRetVal = AddModule(pHolder); if (nRetVal != XN_STATUS_OK) { DestroyModule(pHolder); return (nRetVal); } } } // modules loop return (XN_STATUS_OK); }