예제 #1
0
파일: KSO3World.cpp 프로젝트: 1suming/pap2
KDoodad* KSO3World::NewDoodad(DWORD dwDoodadID)
{
    KDoodad*        pResult         = NULL;
	BOOL            bRetCode        = false;
	KDoodad*        pDoodad         = NULL;
	BOOL            bDoodadRegFlag  = false;
    BOOL            bDoodadInitFlag = false;

    pDoodad = KMemory::New<KDoodad>();
    KGLOG_PROCESS_ERROR(pDoodad);

	bRetCode = g_pSO3World->m_DoodadSet.Register(pDoodad, dwDoodadID);
	KGLOG_PROCESS_ERROR(bRetCode);
	bDoodadRegFlag = true;

    bRetCode = pDoodad->Init();
    KGLOG_PROCESS_ERROR(bRetCode);
    bDoodadInitFlag = true;
	
	pResult = pDoodad;
Exit0:
    if (pResult == NULL)
    {
        if (bDoodadInitFlag)
        {
            pDoodad->UnInit();
            bDoodadInitFlag = false;
        }

		if (bDoodadRegFlag)
		{
			g_pSO3World->m_DoodadSet.Unregister(pDoodad);
			bDoodadRegFlag = false;
		}

        if (pDoodad)
        {
            KMemory::Delete(pDoodad);
            pDoodad = NULL;
        }
    }
	return pResult;
}
예제 #2
0
KDoodad* KDoodadMgr::CreateDoodad(DWORD dwTemplateId, DWORD dwId /*= KD_BAD_ID*/ )
{
	BOOL bResult = FALSE;
	INT nIndex = 0;
	KDoodad* pDoodad = NULL;

	pDoodad = m_cObjPool.GetById(dwId);
	if (pDoodad)
	{
		nIndex = pDoodad->m_nIndex;
		IKScene* pScene = pDoodad->GetScene();
		if (pScene)
			pScene->RemoveDoodad(pDoodad);
	}
	else
	{
		KDoodadTemplateMapIt stIt = m_mapDoodadTemplate.find(dwTemplateId);
		LOG_PROCESS_ERROR(stIt != m_mapDoodadTemplate.end());

		nIndex = m_cObjPool.Add(dwId);
		LOG_PROCESS_ERROR(pDoodad = m_cObjPool.GetByIndex(nIndex));
		LOG_PROCESS_ERROR(pDoodad->Init(nIndex, &stIt->second));
	}

	bResult = TRUE;
EXIT0:
	if (FALSE == bResult)
	{
		if (pDoodad)
		{
			DestroyDoodad(pDoodad->m_dwId);
			pDoodad = NULL;
		}
	}
	return pDoodad;
}