HRESULT CPigEngine::CreatePig(BSTR bstrType, BSTR bstrCommandLine, IPig** ppPig) { // Initialize the [out] parameter CLEAROUT(ppPig, (IPig*)NULL); // Lock the object for the following validation checks { XLock lock(this); // Ensure that the scripts have been loaded RETURN_FAILED(EnsureScriptsAreLoaded()); // Ensure that the MissionServer property is not empty if (!m_bstrMissionServer.Length()) return AtlReportError(CLSID_PigSession, IDS_E_NO_MISSIONSRV, IID_IPigSession, 0, _Module.GetResourceInstance()); // Get the number of pigs that exist long cPigs = 0; if (m_pPigs) _SVERIFYE(m_pPigs->get_Count(&cPigs)); // Get the maximum number of pigs allowed long nMaxPigs = 0; _SVERIFYE(get_MaxPigs(&nMaxPigs)); // Check for maximum pigs if (nMaxPigs >= 0 && cPigs >= nMaxPigs) return AtlReportError(CLSID_PigSession, IDS_E_TOOMANYPIGS, IID_IPigSession, 0, _Module.GetResourceInstance()); } // bstrType is optional, so assign a default value if not specified CComBSTR bstrTheType(bstrType); if (!bstrTheType.Length()) bstrTheType = L"Default"; // Find the specified behavior type CPigBehaviorScriptType* pBehaviorType = GetBehaviorType(bstrTheType); if (!pBehaviorType) return AtlReportError(CLSID_PigSession, IDS_E_CREATE_BEHAVIOR_TYPE, IID_IPigSession, 0, _Module.GetResourceInstance()); // Create a new pig thread object and it's associated pig player object DWORD dwGITCookie; RETURN_FAILED(CPig::Create(pBehaviorType, bstrCommandLine, &dwGITCookie)); // Get an apartment-safe pointer to the pig object RETURN_FAILED(GetInterfaceFromGlobal(dwGITCookie, IID_IPig, (void**)ppPig)); assert(*ppPig); // Indicate success return S_OK; }
ezParticleBehavior* ezParticleBehaviorFactory::CreateBehavior(ezParticleSystemInstance* pOwner) const { const ezRTTI* pRtti = GetBehaviorType(); ezParticleBehavior* pBehavior = pRtti->GetAllocator()->Allocate<ezParticleBehavior>(); pBehavior->Reset(pOwner); CopyBehaviorProperties(pBehavior, true); pBehavior->CreateRequiredStreams(); return pBehavior; }