Example #1
0
int main(){

	int i;

	std::cout << ">>>>>>>>>>refence test<<<<<<<<<<<" << std::endl;

	refenceValue ref1( 1, 1);
	refenceValue ref2( 2, 2);
	refenceValue ref3 = ref2;
	refenceValue ref4(ref2);
	refenceValue *ref5 = new refenceValue(123, 321);
	refenceValue &ref6 = *ref5; 
	*ref5=(ref4);
//	refenceValue& ref4;

	std::cout << "ref1: " << ref1.a << " and " << ref1.b << std::endl;
	std::cout << "ref2: " << ref2.a << " and " << ref2.b << std::endl;
	std::cout << "ref3: " << ref3.a << " and " << ref3.b << std::endl;
	std::cout << "ref4: " << ref4.a << " and " << ref4.b << std::endl;
	std::cout << "ref5: " << ref5->a << " and " << ref5->b << std::endl;

	///dangerous statement.
	delete ref5;

	int *p = new int[10000];
	//memset(p, 0, sizeof(p));
	for(i = 0; i < 10000; i++)
	{
		p[i] = 1;
	}

	std::cout << "i = " << i << ";" << std::endl;

	std::cout << "ref6: " << ref6.a << " and " << ref6.b << std::endl;
	std::cout << std::endl;
	
	setRefenceValue mySetRefe;
	mySetRefe( ref2 );
	std::cout << "ref2: " << ref2.a << " and " << ref2.b << std::endl;
	std::cout << std::endl;

	setValue mySetValue;
	mySetValue( ref1 );
	std::cout << "ref1: " << ref1.a << " and " << ref1.b << std::endl;
	delete p;
}
Example #2
0
void GuiPanel::setSelection(const QModelIndexList &newsel, int k){
  int sel=-1;
  int nsel = (int)newsel.size();
  if (newsel.size()!=0) sel = newsel[0].row();

  //bool vertexani=false;
  //bool skinned=false;
  //bool vertexcolor=false;
  /*bool manyMaterials=false;
  int flags=-1;
  char materialSt[255]="";
  bool differentAni = false;

  int nv=0, nf=0, nfr=0, np=0;
  int last = -1;

  for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
    sel = i->row();
    if (k==MESH && sel<(int)data->mesh.size() ) {
      BrfMesh *m = &(data->mesh[sel]);
      skinned |= m->IsSkinned();
      vertexani |= m->frame.size()>1;
      vertexcolor |= m->hasVertexColor;
      np += m->frame[0].pos.size();
      nv += m->vert.size();
      int k = m->frame.size();
      if (nfr>k || !nfr) nfr=k;

      if (!differentAni) {

        if (last!=-1) {
          if (data->mesh[sel].frame.size()!=data->mesh[last].frame.size()) differentAni=true;
          else for (unsigned int fi=0; fi < data->mesh[sel].frame.size(); fi++)
            if (data->mesh[sel].frame[fi].time!=data->mesh[last].frame[fi].time) differentAni=true;
        } else {
          for (unsigned int fi=0; fi < data->mesh[sel].frame.size(); fi++)
            _frameTime[fi]=data->mesh[sel].frame[fi].time;
        }
        last = sel;
      }

      nf += m->face.size();
      if (!materialSt[0]) sprintf(materialSt,"%s",m->material);
      else if (strcmp(materialSt,m->material)) {
        sprintf(materialSt,"%s","<various>");
        manyMaterials=true;
      }
      if (flags==-1) flags=m->flags; else {
        if (flags!=(int)m->flags) flags=-2;
      }
    }


  }
  if (k==-1) k=NONE;

  BrfMesh *m = NULL;
  BrfTexture *tex = NULL;
  BrfAnimation *ani = NULL;
*/
_selectedIndex = sel;
//_nsel =
switch (TokenEnum(k)){
  case MATERIAL:{
    myClear(ui->leMatBump);
    myClear(ui->leMatDifA);
    myClear(ui->leMatDifB);
    myClear(ui->leMatEnv);
    myClear(ui->leMatShader);
    myClear(ui->leMatSpec);

    myClear(ui->leMatFlags);
    //myClear(ui->leMatRendOrd);
    myClear(ui->leMatCoeff);
    myClear(ui->leMatR);
    myClear(ui->leMatG);
    myClear(ui->leMatB);

    for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
      int sel = i->row();
      if (sel<0 || sel>=(int)data->material.size())  break;
      BrfMaterial &m(data->material[sel]);

      mySetText(ui->leMatBump,  m.bump );
      mySetText(ui->leMatDifA,  m.diffuseA );
      mySetText(ui->leMatDifB,  m.diffuseB );
      mySetText(ui->leMatEnv,   m.enviro);
      mySetText(ui->leMatShader,m.shader );
      mySetText(ui->leMatSpec,  m.spec );

      mySetText(ui->leMatFlags, StringH(m.flags) );
      //mySetText(ui->leMatRendOrd, m.RenderOrder() );
      mySetText(ui->leMatCoeff, StringF(m.specular,3) );
      mySetText(ui->leMatR, StringF( m.r ,3));
      mySetText(ui->leMatG, StringF( m.g ,3));
      mySetText(ui->leMatB, StringF( m.b ,3));
    }
    break;
    }

  case MESH: {
    myClear(ui->boxFlags);
    myClear(ui->boxMaterial);
    myClear(ui->boxTexture);
    myClear(ui->boxNVerts);
    myClear(ui->boxNFaces);
    myClear(ui->boxNPos);
    myClear(ui->boxNVerts);
    myClear(ui->boxNFrames);
    ui->meshDataAni->setVisible(false);
    ui->rbRiggingcolor->setEnabled(false);
    ui->rbVertexcolor->setEnabled(false);
    ui->viewRefAni->setVisible( false );

    int hasAni=-1,hasCol=-1,hasTan=-1,hasRig=-1;
    bool hasBump=false, hasSpec=false, hasTran = false;

    for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
      int sel = i->row();
      if (sel<0 || sel>=(int)data->mesh.size()) continue;
      BrfMesh *m=&(data->mesh[sel]);

      mySetText(ui->boxFlags, StringH(m->flags & ~(3<<16) ));
      mySetText( ui->boxMaterial ,  m->material );

      mySetValueAdd( ui->boxNVerts , (int)m->vert.size());
      mySetValueAdd( ui->boxNFaces , (int)m->face.size());
      mySetValueAdd( ui->boxNPos   , (int)m->frame[0].pos.size());
      mySetValueMax( ui->boxNFrames, (int)m->frame.size());

      mySetCompositeVal(hasAni, m->HasVertexAni());
      mySetCompositeVal(hasCol, m->hasVertexColor);
      mySetCompositeVal(hasTan, m->StoresTangentField());
      mySetCompositeVal(hasRig, m->IsSkinned());

      bool ta,tb,tc;
      QString s = inidata.mat2tex(m->material,&ta,&tb,&tc);
      if (s.isEmpty()) s = tr("<not found>");
      hasBump |= ta;
      hasSpec |= tb;
      hasTran |= tc;

      mySetText( ui->boxTexture, s );

      for (unsigned int fi=0; fi < m->frame.size(); fi++)
         frameTime[fi]=m->frame[fi].time;
    }

    if (hasRig>0)  {
      ui->rbRiggingcolor->setEnabled( true );
      ui->viewRefAni->setVisible( true );
    }
    if (hasCol>0) ui->rbVertexcolor->setEnabled(true);
    if (hasAni>0) ui->meshDataAni->setVisible(true);
    ui->cbMeshHasAni->setCheckState(myCheckState(hasAni));
    ui->cbMeshHasCol->setCheckState(myCheckState(hasCol));
    ui->cbMeshHasTan->setCheckState(myCheckState(hasTan));
    ui->cbMeshHasRig->setCheckState(myCheckState(hasRig));

    ui->cbTransp->setEnabled( hasTran );
    ui->cbNormalmap->setEnabled( hasBump );
    ui->cbSpecularmap->setEnabled( hasSpec );


    ui->timeOfFrame->setEnabled( newsel.size()==1 );

    int nfr = (int)ui->boxNFrames->value();
    if (nfr>0)
    ui->frameNumber->setMaximum(nfr -1 );
    ui->frameNumber->setMinimum( 0 );
    ui->frameNumber->setWrapping(true);

    break;
    }

  case TEXTURE:
    myClear(ui->boxTextureFlags);

    for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
      int j=i->row();
      if (j>=0 && j<(int)data->texture.size())
        mySetText(ui->boxTextureFlags,StringH(data->texture[j].flags));
      int nf = data->texture[j].NFrames();
      if (nf==0)
        ui->labNFrames->setHidden(true);
      else {
        ui->labNFrames->setHidden(false);
        ui->labNFrames->setText(QString("x %1").arg(nf));
      }

    }
    break;
  case SKELETON: {
    {
        int hasHb=-1;
        myClear(ui->boxSkelNBones);
        for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
          int sel = i->row();
          if (sel<0 || sel>=(int)data->skeleton.size()) continue;
          BrfSkeleton *s=&(data->skeleton[sel]);
          int bi=-1;
          if (hitBoxes) bi = hitBoxes->Find(s->name,BODY);
          mySetCompositeVal(hasHb,bi>=0);
          mySetValue(ui->boxSkelNBones,(int)s->bone.size());
        }
        ui->cbSkelHasHitbox->setCheckState(myCheckState(hasHb));

    }

    ui->cbTransp->setEnabled( true );
    ui->cbNormalmap->setEnabled( true );
    ui->cbSpecularmap->setEnabled( true );

    BodyPartModel* bmp = ((BodyPartModel*)(ui->lvBones->model()));
    if (sel>=0 && nsel==1 && sel<(int)data->skeleton.size()) {
      BrfSkeleton &s(data->skeleton[sel]);
      bmp->setSkel(s);      
    } else  bmp->clear();

    emit selectedSubPiece(-1); // unselect all
    ui->lvBones->selectionModel()->clearSelection();
    ui->hitboxEdit->setVisible(false); // until a piece is not selected

    break; }
  case ANIMATION:
    {

    myClear(ui->boxAniNBones);
    myClear(ui->boxAniNFrames);
    myClear(ui->boxAniMinFrame);
    myClear(ui->boxAniMaxFrame);

    for (QModelIndexList::ConstIterator i=newsel.constBegin(); i!=newsel.constEnd(); i++){
      int sel = i->row();
      if (sel<0 || sel>=(int)data->animation.size()) continue;
      BrfAnimation *a=&(data->animation[sel]);

      mySetValue(ui->boxAniNBones,a->nbones);
      mySetValue(ui->boxAniNFrames,a->frame.size());
      mySetValue(ui->boxAniMinFrame,a->FirstIndex());
      mySetValue(ui->boxAniMaxFrame,a->LastIndex() );
    }


    BrfAnimation *ani =NULL;
    if (sel>=0 && nsel==1 && sel<(int)data->animation.size()) ani=&(data->animation[sel]);
    if (ani) {
      for (unsigned int fi=0; fi < ani->frame.size(); fi++)
       frameTime[fi]=ani->frame[fi].index;
      ui->frameNumberAni->setMaximum(ani->frame.size());
      ui->frameNumberAni->setMinimum(1);
      updateFrameNumber( ui->frameNumberAni->value() );
    }

    ui->cbTransp->setEnabled( true );
    ui->cbNormalmap->setEnabled( true );
    ui->cbSpecularmap->setEnabled( true );

    ui->rbRiggingcolor->setEnabled( true ); // quick: use "true": just let user edit them
    ui->rbVertexcolor->setEnabled( true );
    ui->viewRefSkel->setVisible( true );
    if (ani) setAnimation(ani);
    }
    break;
  case SHADER:
      {
      if (!newsel.size()) break;
      int sel = newsel[0].row();
      if (sel<0 || sel>=(int)data->shader.size())  break;
      BrfShader &s(data->shader[sel]);
      ui->leShaderTechnique->setText( s.technique );
      ui->leShaderFallback->setText( s.fallback );
      ui->leShaderFlags->setText( StringH(s.flags) );
      ui->leShaderRequires->setText( StringH(s.requires) );
      updateShaderTextaccSize();
      }
      break;
    case BODY:

      bool collisionBodyHasMesh;
      if (nsel==1) {
          char* bodyname = data->body[sel].name;
          int si = data->Find(bodyname,SKELETON);

          collisionBodyHasSkel= (si>=0);
          if (si>=0) skel = &(data->skeleton[si]); else skel = NULL;
          collisionBodyHasMesh = false;
          for (int i=0; i<(int)data->mesh.size(); i++) {
              if (data->mesh[i].IsNamedAsBody(bodyname)) collisionBodyHasMesh = true;
          }
      } else {
          collisionBodyHasMesh = true;
          collisionBodyHasSkel = false;
      }
      ui->cbComparisonMesh->setEnabled( collisionBodyHasMesh || collisionBodyHasSkel );
      updateBodyPartData();
      break;
    default:

      break;
  }

  ui->animationData->setVisible(k == ANIMATION);
  ui->textureData->setVisible(k == TEXTURE);
  ui->meshData->setVisible(k == MESH);
  ui->materialData->setVisible( k==MATERIAL );
  ui->skeletonData->setVisible( k==SKELETON );
  ui->shaderData->setVisible( k==SHADER );
  ui->bodyData->setVisible( k==BODY );
  ui->generalView->setVisible( k!=SHADER && k!=NONE );

  QRect rect = ui->generalView->geometry();
  if (k==MATERIAL)
    rect.setTop( ui->materialData->geometry().bottom() + 40 );
  else
    rect.setTop( ui->meshData->geometry().bottom() + 40 );
  ui->generalView->setGeometry(rect);

  displaying=k;
  updateVisibility();
  updateFrameNumber( ui->frameNumber->value() );

}