// clear model instance
void CModelInstance::Clear(void)
{
  // for each child of this model instance
  INDEX ctcmi = mi_cmiChildren.Count();
  for(INDEX icmi=0; icmi<ctcmi; icmi++) {
    // delete child
    CModelInstance *pcmi = &mi_cmiChildren[0];
    mi_cmiChildren.Remove(pcmi);
    DeleteModelInstance(pcmi);
  }

  // release all meshes in stock used by mi
  INDEX ctmshi = mi_aMeshInst.Count();
  for(INDEX imshi=0; imshi<ctmshi; imshi++) {
    MeshInstance &mshi = mi_aMeshInst[imshi];
    CMesh *pmesh = mshi.mi_pMesh;
    if(pmesh != NULL) {
      _pMeshStock->Release(pmesh);
    }
    // release all textures in stock used by mesh
    INDEX ctti = mshi.mi_tiTextures.Count();
    for(INDEX iti=0;iti<ctti;iti++) {
      TextureInstance &ti = mshi.mi_tiTextures[iti];
      ti.ti_toTexture.SetData(NULL);
    }
  }
  mi_aMeshInst.Clear();
  // release skeleton in stock used by mi(if it exist)
  if(mi_psklSkeleton != NULL) {
    _pSkeletonStock->Release(mi_psklSkeleton);
    mi_psklSkeleton = NULL;
  }

  // release all animsets in stock used by mi
  INDEX ctas = mi_aAnimSet.Count();
  for(INDEX ias=0;ias<ctas;ias++) {
    _pAnimSetStock->Release(&mi_aAnimSet[ias]);  
  }
  mi_aAnimSet.Clear();

  // clear all colision boxes 
  mi_cbAABox.Clear();
  // clear anim list
  mi_aqAnims.aq_Lists.Clear();
}
Пример #2
0
/*
 * Copy entity from another entity of same class.
 * NOTES:
 *  - Doesn't copy placement, it must be done on creation.
 *  - Entity must be initialized afterwards.
 */
void CEntity::Copy(CEntity &enOther, ULONG ulFlags)
{
  BOOL bRemapPointers = ulFlags & COPY_REMAP;

  // copy base class data
  en_RenderType     = enOther.en_RenderType;
  en_ulPhysicsFlags = enOther.en_ulPhysicsFlags;
  en_ulCollisionFlags = enOther.en_ulCollisionFlags;
  en_ulFlags        = enOther.en_ulFlags &
    ~(ENF_SELECTED|ENF_FOUNDINGRIDSEARCH|ENF_VALIDSHADINGINFO|ENF_INRENDERING);
  en_ulSpawnFlags   = enOther.en_ulSpawnFlags;

  // if this is a brush
  if ( enOther.en_RenderType == RT_BRUSH || en_RenderType == RT_FIELDBRUSH) {
    // there must be no existing brush
    ASSERT(en_pbrBrush == NULL);
    // create a new empty brush in the brush archive of current world
    en_pbrBrush = en_pwoWorld->wo_baBrushes.ba_abrBrushes.New();
    en_pbrBrush->br_penEntity = this;
    // copy the brush
    if (_bMirrorAndStretch) {
      en_pbrBrush->Copy(*enOther.en_pbrBrush, _fStretch, _wmtMirror!=WMT_NONE);
    } else {
      en_pbrBrush->Copy(*enOther.en_pbrBrush, 1.0f, FALSE);
    }
  // if this is a terrain
  } else if( enOther.en_RenderType == RT_TERRAIN) {
    ASSERT(en_ptrTerrain == NULL);
    // create a new empty terrain in the brush archive of current world
    en_ptrTerrain = en_pwoWorld->wo_taTerrains.ta_atrTerrains.New();
    en_ptrTerrain->tr_penEntity = this;
    // Copy terrain
    TR_CopyTerrain(en_ptrTerrain,enOther.en_ptrTerrain);
    // Update terrain shadowmap
    Matrix12 mTerrain;
    TR_GetMatrixFromEntity(mTerrain,en_ptrTerrain);
    TR_UpdateShadowMap(en_ptrTerrain,mTerrain,FLOATaabbox3D());
  // if this is a model
  } if ( enOther.en_RenderType == RT_MODEL || en_RenderType == RT_EDITORMODEL) {
    // if will not initialize
    if (!(ulFlags&COPY_REINIT)) {
      ASSERT(en_pmoModelObject==NULL);
      ASSERT(en_psiShadingInfo==NULL);
      if(en_pmoModelObject!=NULL) {
        delete en_pmoModelObject;
      }
      if(en_psiShadingInfo!=NULL) {
        delete en_psiShadingInfo;
      }
      // create a new model object
      en_pmoModelObject = new CModelObject;
      en_psiShadingInfo = new CShadingInfo;
      en_ulFlags &= ~ENF_VALIDSHADINGINFO;
      // copy it
      en_pmoModelObject->Copy(*enOther.en_pmoModelObject);
    }
  // if this is ska model
  } else if ( enOther.en_RenderType == RT_SKAMODEL || en_RenderType == RT_SKAEDITORMODEL) {
      ASSERT(en_psiShadingInfo==NULL);
      if(en_psiShadingInfo!=NULL) {
        delete en_psiShadingInfo;
      }
      en_psiShadingInfo = new CShadingInfo;
      en_ulFlags &= ~ENF_VALIDSHADINGINFO;
      ASSERT(en_pmiModelInstance==NULL);
      if(en_pmiModelInstance!=NULL) {
        DeleteModelInstance(en_pmiModelInstance);
      }
      en_pmiModelInstance = CreateModelInstance("");
      // copy it
      GetModelInstance()->Copy(*enOther.GetModelInstance());
  }

  // copy the parent pointer
  if (bRemapPointers) {
    en_penParent = FindRemappedEntityPointer(enOther.en_penParent);
  } else {
    en_penParent = enOther.en_penParent;
  }
  // if the entity has a parent
  if (en_penParent!=NULL) {
    // create relative offset
    en_plRelativeToParent = en_plPlacement;
    en_plRelativeToParent.AbsoluteToRelativeSmooth(en_penParent->en_plPlacement);
    // link to parent
    en_penParent->en_lhChildren.AddTail(en_lnInParent);
  }

  // copy the derived class properties
  CopyEntityProperties(enOther, ulFlags);

}