Esempio n. 1
0
File: list.cpp Progetto: EBone/Faust
Tree tmap (Tree key, tfun f, Tree t)
{	
	//printf("start tmap\n");
	Tree p; 
	
	if (getProperty(t, key, p)) {
		
		return (isNil(p)) ? t : p;	// truc pour eviter les boucles
		
	} else {

        tvec br;
        int n = t->arity();
        for (int i = 0; i < n; i++) {
            br.push_back( tmap(key, f, t->branch(i)) );
        }

        Tree r1 = tree(t->node(), br);

		Tree r2 = f(r1);
		if (r2 == t) {
			setProperty(t, key, gGlobal->nil);
		} else {
			setProperty(t, key, r2);
		}
		return r2;
	}
}
//--------------------------------------------------------------------------
//
// creates a structure datatype
//
// basse_addr: base address added to relative OFST displacements
// num_map_blocks: number of map blocks
// map: typemap with num_blocks blocks
// type: new (output) datatype
//
// returns: error code
//
int DIY_Create_struct_datatype(DIY_Aint base_addr, int num_map_blocks, 
			struct map_block_t *map, DIY_Datatype *type) {

  vector<map_block_t>tmap(map, map + num_map_blocks);
  CreateDtype(base_addr, &tmap, type);
  MPI_Type_commit(type);
  dtype_absolute_address = true;

  return 0;

}
Esempio n. 3
0
Tree tmap (Tree key, tfun f, Tree t)
{	
	//printf("start tmap\n");
	Tree p; 
	
	if (getProperty(t, key, p)) {
		
		return (isNil(p)) ? t : p;	// truc pour eviter les boucles
		
	} else {
		
		Tree r1=nil;
		switch (t->arity()) {
			
			case 0 : 
				r1 = t; 
				break;
			case 1 : 
				r1 = tree(t->node(), tmap(key,f,t->branch(0))); 
				break;
			case 2 : 
				r1 = tree(t->node(), tmap(key,f,t->branch(0)), tmap(key,f,t->branch(1))); 
				break;
			case 3 : 
				r1 = tree(t->node(), tmap(key,f,t->branch(0)), tmap(key,f,t->branch(1)),
										   tmap(key,f,t->branch(2))); 
				break;
			case 4 : 
				r1 = tree(t->node(), tmap(key,f,t->branch(0)), tmap(key,f,t->branch(1)),
										   tmap(key,f,t->branch(2)), tmap(key,f,t->branch(3))); 
				break;
		}
		Tree r2 = f(r1);
		if (r2 == t) {
			setProperty(t, key, nil);
		} else {
			setProperty(t, key, r2);
		}
		return r2;
	}
}
TileMapBufferHolder*
TileMapCreator::createOceanTileMap( const MC2SimpleString& str,
                                    const ServerTileMapFormatDesc& desc ) {
   TileMapParams param( str );

   // If the layer ID is invalid then we need to create an empty tile map
   // instead of the ocean tile map.
   // For example some b0rk client might send: TQ2sAPOST
   if ( ! desc.isValidLayerID( param.getLayer() ) ||
        ! desc.isValidImportance( param ) ) {
      
      mc2dbg << "[TMC] Param: " << str 
             << " layer is invalid! Will create empty tmap instead of ocean."  << endl;

      EmptyTileMap m( param );
      auto_ptr<BitBuffer> buf( new BitBuffer( str.length() + 100 ) );
      uint32 crc;
      m.save( *buf, &crc );
      // addBuffer must have same getBufferSize as getCurrentOffset
      buf->setSizeToOffset();
      buf->reset();

      return new TileMapBufferHolder( str.c_str(),
                                      buf.release(), crc,
                                      false );
   }

   MC2BoundingBox box;
   desc.getBBoxFromTileIndex( param.getLayer(),
                              box,
                              param.getDetailLevel(),
                              param.getTileIndexLat(), param.getTileIndexLon() );

   WritableTileMap tmap( param, desc,
                         desc.getImportanceNbr( param )->getType(),
                         1 );

   createOceanFeature( tmap, &desc, box );

   tmap.complete();

   // force crc 
   BitBuffer* buf = new BitBuffer( 1024*1024*10 ); // 10Mbytes
   uint32 crc = MAX_UINT32;
   tmap.save( *buf, &crc );
   buf->setSizeToOffset();
   buf->reset();
   // holder now owns buf
   return new TileMapBufferHolder( str.c_str(), buf, crc, false );
}
Esempio n. 5
0
File: main.cpp Progetto: CCJY/coliru
int main() {
  std::tuple<float, int> t(3, 2);
  print(tmap(t, some_functor()));
  print(tmap(t, some_other_functor()));
}
Esempio n. 6
0
void iMinimapView::PrepareMap(iMapHandler* pMap, iDib& odib, bool bShowCnsts)
{	
	if (pMap) {
		iSize nsiz(pMap->GetWidth()*2, pMap->GetHeight()*2);
		if (nsiz != odib.GetSize()) odib.Resize(nsiz);
		else odib.Fill(cColorTransparent);
		sint32 xx,yy;

		// Prepare map
		iMapT<iColor> tmap(pMap->GetWidth(), pMap->GetHeight());
		for (yy=0; yy<tmap.GetHeight(); ++yy){
			for (xx=0; xx<tmap.GetWidth(); ++xx){
				iMapHandler::iSurfCell cell;
				pMap->GetCellSurf(iPoint(xx,yy),cell);
				tmap.At(xx,yy) = Cvt16to32(SURF_COLOR[cell.lowestLayer]);
				if (const iAvatar* pAvatar = pMap->GetCell(xx,yy).pDecor) {
					for (uint32 pmid = 0; pmid<pAvatar->PassModsCount(); ++pmid) {
						sint32 nx = xx+pAvatar->PassModEntry(pmid).offset.x;
						sint32 ny = yy+pAvatar->PassModEntry(pmid).offset.y;
						if (tmap.IsValidPos(nx,ny)) {
							tmap.At(nx,ny).AlphaBlend(iColor(0,0,0,96));
						} 
					}
				} else if (const iPathElNode* pPathEl = pMap->GetCell(xx,yy).pPathEl) {
					if (pPathEl->PassModVal() == -1) {
						tmap.At(xx,yy).AlphaBlend(iColor(0,0,0,96));
					}
				}
			}
		}

		if (bShowCnsts) {
			// Visitables
			for (uint32 vcid = 0; vcid<pMap->m_VisCnstList.GetSize(); ++vcid) {
				for (uint32 aid=0; aid<pMap->m_VisCnstList[vcid]->Proto()->AvatarsCount(); ++aid) {
					const iAvatar& avt = gItemMgr.m_AvatarMgr[pMap->m_VisCnstList[vcid]->Proto()->Avatar(aid).id];
					for (uint32 pm=0; pm<avt.PassModsCount(); ++pm){
						sint32 nx = pMap->m_VisCnstList[vcid]->Pos().x+pMap->m_VisCnstList[vcid]->Proto()->Avatar(aid).offset.x+avt.PassModEntry(pm).offset.x;
						sint32 ny = pMap->m_VisCnstList[vcid]->Pos().y+pMap->m_VisCnstList[vcid]->Proto()->Avatar(aid).offset.y+avt.PassModEntry(pm).offset.y;
						if (tmap.IsValidPos(nx, ny)) tmap.At(nx,ny).AlphaBlend(iColor(0,0,0,96));//tmap.At(nx, ny) = iColor(192,192,192,255);
					}
				}
			}

			// Ownerables
			for (uint32 ocid = 0; ocid<pMap->m_OwnCnstList.GetSize(); ++ocid) {
				for (uint32 aid=0; aid<pMap->m_OwnCnstList[ocid]->Proto()->AvatarsCount(); ++aid) {
					const iAvatar& avt = gItemMgr.m_AvatarMgr[pMap->m_OwnCnstList[ocid]->Proto()->Avatar(aid).id];
					for (uint32 pm=0; pm<avt.PassModsCount(); ++pm){
						sint32 nx = pMap->m_OwnCnstList[ocid]->Pos().x+pMap->m_OwnCnstList[ocid]->Proto()->Avatar(aid).offset.x+avt.PassModEntry(pm).offset.x;
						sint32 ny = pMap->m_OwnCnstList[ocid]->Pos().y+pMap->m_OwnCnstList[ocid]->Proto()->Avatar(aid).offset.y+avt.PassModEntry(pm).offset.y;
						if (tmap.IsValidPos(nx, ny)) {
							if (pMap->m_OwnCnstList[ocid]->Owner() == PID_NEUTRAL) tmap.At(nx, ny) = iColor(192,192,192,255);
							else tmap.At(nx, ny) = Cvt16to32(PLAYER_COLORS[pMap->m_OwnCnstList[ocid]->Owner()]);
						}
					}
				}
			}

			// Castles
			for (uint32 ctlid = 0; ctlid<pMap->m_CastleList.GetSize(); ++ctlid) {
				for (uint32 aid=0; aid<pMap->m_CastleList[ctlid]->Proto()->AvatarsCount(); ++aid) {
					const iAvatar& avt = gItemMgr.m_AvatarMgr[pMap->m_CastleList[ctlid]->Proto()->Avatar(aid).id];
					for (uint32 pm=0; pm<avt.PassModsCount(); ++pm){
						sint32 nx = pMap->m_CastleList[ctlid]->Pos().x+pMap->m_CastleList[ctlid]->Proto()->Avatar(aid).offset.x+avt.PassModEntry(pm).offset.x;
						sint32 ny = pMap->m_CastleList[ctlid]->Pos().y+pMap->m_CastleList[ctlid]->Proto()->Avatar(aid).offset.y+avt.PassModEntry(pm).offset.y;
						if (tmap.IsValidPos(nx, ny)) {
							if (pMap->m_CastleList[ctlid]->Owner() == PID_NEUTRAL) tmap.At(nx, ny) = iColor(192,192,192,255);
							else tmap.At(nx, ny) = Cvt16to32(PLAYER_COLORS[pMap->m_CastleList[ctlid]->Owner()]);
						}
					}
				}
			}

			// Heroes
			for (uint32 hid = 0; hid<pMap->m_HeroList.GetSize(); ++hid) {
				tmap.At(pMap->m_HeroList[hid]->Pos().x, pMap->m_HeroList[hid]->Pos().y) = Cvt16to32(PLAYER_COLORS[pMap->m_HeroList[hid]->Owner()]);
			}
		}

		// Compose
		const sint32 const_x = (sint32)(nsiz.w/2);
		const sint32 const_y = 0;
		sint32 base_x = const_x;
		sint32 base_y = const_y;
		sint32 pos_x=base_x;
		sint32 pos_y=base_y;

		for (yy=0; yy<tmap.GetHeight(); ++yy){
			for (xx=0; xx<tmap.GetWidth(); ++xx){
				iRect orc(pos_x,pos_y,2,1);
				odib.FillRect(orc, tmap.At(xx,yy));
				pos_x+=1;
				pos_y+=1;
			}
			base_x-=1;
			base_y+=1;
			pos_x = base_x;
			pos_y = base_y;
		}
		tmap.Cleanup();
	}
}
Esempio n. 7
0
void StoreMapsSDD(Int_t firstRun=0,Int_t lastRun=AliCDBRunRange::Infinity(), Bool_t optSmear=kFALSE){
  ///////////////////////////////////////////////////////////////////////
  // Macro to generate and store the correction maps for SDD           //
  // Generates:                                                        //
  //  1 file with 520 AliITSCorrMapSDD drift maps (MapsTimeSDD)        //
  ///////////////////////////////////////////////////////////////////////
  
  if(!AliCDBManager::Instance()->IsDefaultStorageSet()) {
    AliCDBManager::Instance()->SetDefaultStorage("local://OCDB");
  }
  

  AliCDBMetaData *md = new AliCDBMetaData();
  md->SetObjectClassName("TObjArray");
  md->SetResponsible("Francesco Prino");
  md->SetBeamPeriod(0);
  md->SetComment("Simulated data");



  AliCDBId mapT("ITS/Calib/MapsTimeSDD",firstRun,lastRun);
  TObjArray tmap(520);
  tmap.SetOwner(kFALSE);

  TRandom3 *gran = new TRandom3();
  
  AliITSCorrMapSDD* mapTime0;
  AliITSCorrMapSDD* mapTime1;
  for(Int_t mod=0;mod<260;mod++){
    // maps
    Char_t name[20];
    sprintf(name,"DriftTimeMap_%d_%d\n",mod,0);
    Int_t nbinsan=1;
    if(optSmear && (mod==10 || mod==240)){
      nbinsan=256;
      sprintf(name,"DriftTimeMap_%d_%d\n",mod,0);
      mapTime0 = new AliITSCorrMap2DSDD(name,nbinsan,72);
      sprintf(name,"DriftTimeMap_%d_%d\n",mod,1);
      mapTime1 = new AliITSCorrMap2DSDD(name,nbinsan,72);
    }else{
      sprintf(name,"DriftTimeMap_%d_%d\n",mod,0);
      mapTime0 = new AliITSCorrMap1DSDD(name,72);
      sprintf(name,"DriftTimeMap_%d_%d\n",mod,1);
      mapTime1 = new AliITSCorrMap1DSDD(name,72);
    }
    for(Int_t nan = 0;nan< nbinsan;nan++){
      for(Int_t nt = 0;nt<36*2;nt++){
	Double_t cnt0=0.;
	Double_t cnt1=0.;
	if(optSmear){
	  cnt0=gran->Gaus(0,20);
	  cnt1=gran->Gaus(0,20);
	}
	mapTime0->SetCellContent(nan,nt,cnt0);
	mapTime1->SetCellContent(nan,nt,cnt1);   
      }
    }
    tmap.Add(mapTime0);
    tmap.Add(mapTime1); 
    printf("Added module %d\n",mod);
  }
    
  AliCDBManager::Instance()->GetDefaultStorage()->Put(&tmap, mapT, md);

}