コード例 #1
0
ファイル: Zokusei.cpp プロジェクト: LakeIshikawa/splstage2
/*
	指定されたファイルから配置データを読み込みます。
	この場で配置のデータフォーマットを変換して、配置
	オブジェクトを作ります。

	配置リストの項目がXPxが低い順になるはず。

	エラーの場合、1を返します。
*/
int Zokusei::Load(string rFname)
{
	// データを読み込む
	if(Map::LoadFromFile(rFname)) return 1;

	// リストを作成
	Haichi* ch = GAMECONTROL->GetStageManager()->GetCurrentStage()->GetHaichi();
	int MOVASHIBA_NO = GI("MOVASHIBA_NO");
	int TENBIN_NO = GI("TENBIN_NO");

	int tenbin_idx = 0;

	for(int x=0; x<SP->CHIPNX*mNGamen; x++)
		for(int y=0; y<SP->CHIPNY; y++)
		{
			int data = (*(mData[y]))[x];

			// 動く足場
			if( ISASHIBAMOV(data) && data && ch->GetData(x, y) == 0 ){
				AshibaMovable* ashiba = ch->GetAshibaMov(data/0x10);
				int card = ((data/0x10)==0) ? (data%0x10) : ((data%0x10)+1);
				ashiba->AddRoutePoint( card, x*SP->CHSZX, y*SP->CHSZY );
				if( data%0x10 == 0xF ) ashiba->SetLooping(true);
			}

			// 天秤
			else if( ch->GetData(x, y) == TENBIN_NO ){
				Tenbin* tenbin = ch->GetTenbin(tenbin_idx++);
				tenbin->SetVrSpace((data/0x10 - 7) * 32);
				tenbin->SetHrSpace((data%0x10) * 32);
			}
		}
	return 0; //OK
}
コード例 #2
0
ファイル: Apple.cpp プロジェクト: LakeIshikawa/splstage2
Apple::Apple(int rXPx, int rYPx)
{

	APPLESZX = GI("APPLESZX");
	APPLESZY = GI("APPLESZY");

	APPLE_BRTM = GF("APPLE_BRTM");

	mSizeX = APPLESZX;
	mSizeY = APPLESZY;

	mX = rXPx;
	mY = rYPx;
	mZ = 1.0f;

	mNo = 0;
	mTimer = 0.0f;
	mBaseStatus = NORMAL;

	// あたり判定
	AddFrame(FR_NORMAL);
	AddCircle(FR_NORMAL, SP->GRID_BOGYO, 20, 20, 15);

	AddFrame(FR_DISABLE);

	SetCurFrame(FR_DISABLE);

}
コード例 #3
0
ファイル: KaeruKing.cpp プロジェクト: LakeIshikawa/splstage2
KaeruKing::KaeruKing(int rXPx, int rYPx)
{

	KAERUKSX = GI("KAERUKSX");
	KAERUKSY = GI("KAERUKSY");

	KTAIKI_TIME = GF("KTAIKI_TIME");
	KJUMPSTART_TIME = GF("KJUMPSTART_TIME");
	KJMPSPX = GF("KJMPSPX");
	KJMPTAKASA = GF("KJMPTAKASA");

	mX = rXPx;
	mY = rYPx - sMapAtHanteiY[0][0] + SP->CHSZY;

	mSizeX = KAERUKSX;
	mSizeY = KAERUKSY;

	mStatus		= JUMP;

	mTaikiTimer = 0.0f;

	mCurAshiba = NULL;

	// 当たり判定
	AddFrame(0);
	AddCircle(0, SP->GRID_BOGYO, 44, 44, 44);
	AddIndexedRect(0, SP->GRID_BOUND, TBOUND_IDX, 10, 12, 73, 85);
	SetCurFrame(0);
}
コード例 #4
0
void FastMarch2D::FindPhi(int index, int x, int y) {
	static Double phiX, phiY, phiZ, b, quotient, phi;
    static int a;
    static bool flagX, flagY;

    phiX = phiY = phiZ = 0.;
    a = 0;
    flagX = flagY = 0;

	//Find The phiS
	CheckFront (phiX, a, flagX, GI(x+1,  y));
	CheckBehind(phiX, a, flagX, GI(x-1,  y));
	CheckFront (phiY, a, flagY, GI(x  ,y+1));
	CheckBehind(phiY, a, flagY, GI(x  ,y-1));

	//Max Tests
	if(a == 2) {
		if(phiX >= phiY) CheckMax2(a, phiX, phiY);
		else			 CheckMax2(a, phiY, phiX);
	}

	b = phiX + phiY + phiZ;
	quotient = square(b) - 
		Double(a) * (square(phiX) + square(phiY) + square(phiZ) - square(h));
	if(quotient < 0.) cout << "0 ";
	else {
		phi = b + sqrt(quotient);
		phi /= Double(a);
		grid[index].value = phi;
		if(grid[index].HeapPosition == -1) AddToHeap(index);
	    else                               UpdateHeap(index); 
	}
}
コード例 #5
0
/**
* ユーザーが矢印にクリックしたら、ステージの画像が別の画像にスライドする。
* ユーザーがステージ画像をクリックしたら、ゲーム開始
*/
void StageSelect::ProcessUserControl()
{
	// ライトの位置
	int lx = GAMECONTROL->GetUserLightControl()->GetControlLight()->GetX();
	int ly = GAMECONTROL->GetUserLightControl()->GetControlLight()->GetY();
	
	// 矢印
	// -- 左
	int lyx = GI("STGSELECT_LARX") + GI("STGSELECT_ARSX")/2;
	int lyy = GI("STGSELECT_ARY") + GI("STGSELECT_ARSY")/2;
	if( (sqrt( pow((float)(lyx-lx), 2) + pow((float)(lyy-ly), 2)) <= LIGHT_AT  && 
		(GAMECONTROL->GetDXController()->IsMouseClicked() ))
		|| GAMECONTROL->GetDXController()->KeyPush(DIK_LEFT))
	{
		//SE
		if( selectedIdx > 0 )
			GAMECONTROL->GetSoundController()->PlaySE("audio\\se\\se_cansel.wav");
		GoToLeft();
		return;
	}

	// -- 右
	int ryx = GI("STGSELECT_RARX") + GI("STGSELECT_ARSX")/2;
	if( (sqrt( pow((float)(ryx-lx), 2) + pow((float)(lyy-ly), 2) ) <= LIGHT_AT && 
		(GAMECONTROL->GetDXController()->IsMouseClicked() ))
		|| GAMECONTROL->GetDXController()->KeyPush(DIK_RIGHT))
	{
		//SE
		if(  selectedIdx < GAMECONTROL->GetStageManager()->GetLastStageIdx() - 
			GAMECONTROL->GetStageManager()->GetFirstStageIdx()  )
		{
			GAMECONTROL->GetSoundController()->PlaySE("audio\\se\\se_cansel.wav");
		}

		GoToRight();
		return;
	}

	// ステージ開始
	int top = GI("STGSELECT_IMGY");
	int left = SP->SCRSZX/2 - GI("STGSELECT_IMGSX")/2;
	int bottom = top + GI("STGSELECT_IMGSY");
	int right = left + GI("STGSELECT_IMGSX");

	// ステージ開始が選択されたか
	if( ((lx >= left && lx <= right && ly>=top && ly <= bottom && selectedIdx <= saveStageTdx && scroll == 0) &&
		(GAMECONTROL->GetDXController()->IsMouseClicked() || GAMECONTROL->GetDXController()->KeyPush(DIK_Z))))
	{
		GAMECONTROL->GetMaku()->Close();
		GAMECONTROL->GetUserLightControl()->GetControlLight()->TurnOff();
		stage = 4;
		//SE
		GAMECONTROL->GetSoundController()->PlaySE("audio\\se\\se_kettei.wav");
	}
}
コード例 #6
0
ファイル: MESIProtocol.cpp プロジェクト: jockey10/sesc
void MESIProtocol::changeState(Line *l, unsigned newstate)
{
  // should use invalidate interface 
  I(newstate != MESI_INVALID);
  #ifndef TLS
  ID(unsigned currentstate);
  IS(currentstate = l->getState());
  GI(currentstate == MESI_INVALID,      newstate == MESI_TRANS_RSV);
  GI(currentstate == MESI_TRANS_RSV,    newstate == MESI_TRANS_RD ||
                                        newstate == MESI_TRANS_WR);
  GI(currentstate == MESI_TRANS_RD,     newstate == MESI_SHARED ||
                                        newstate == MESI_TRANS_RD_MEM);
  GI(currentstate == MESI_TRANS_RD_MEM, newstate == MESI_EXCLUSIVE);
  GI(currentstate == MESI_TRANS_WR,     newstate == MESI_MODIFIED ||
                                        newstate == MESI_TRANS_WR_MEM);
  GI(currentstate == MESI_TRANS_WR_MEM, newstate == MESI_MODIFIED);
  GI(currentstate == MESI_EXCLUSIVE,    newstate == MESI_SHARED ||
                                        newstate == MESI_MODIFIED ||
                                        newstate == MESI_TRANS_INV);
  GI(currentstate == MESI_SHARED,       newstate == MESI_SHARED ||
                                        newstate == MESI_MODIFIED ||
                                        newstate == MESI_TRANS_INV ||
                                        newstate == MESI_TRANS_WR);
  GI(currentstate == MESI_MODIFIED,     newstate == MESI_SHARED ||
                                      newstate == MESI_TRANS_INV_D); 
  #endif
  l->changeStateTo(newstate);
}
コード例 #7
0
void FastMarch2D::PrintFlags()
{
    cout << endl;
    for(int j=0; j < Ny+2; j++) {
        for(int i=0; i < Nx+2; i++) {
            if(grid[GI(i,j)].DoneFlag >= 0) cout << " ";
            cout << grid[GI(i,j)].DoneFlag;
        }
        cout << endl;
    }
}
コード例 #8
0
void FastMarch2D::Initialize() {
    static int ci, pi, flag;
	for(int i = 1; i <= Nx; i++)
	{
        //if(Done == 0)  f= 0: change --> -1^f = -1;           NO -->  0^f = 0; 1^f = 1;
        //if(Done == -1) f=-1: change -->  0^f = -1; 1^f = -2; NO --> -1^f = 0;
        //if(Done == 1)  f= 1: change --> -1^f = -2;           NO -->  0^f = 1; 1^f = 0;
        flag = grid[GI(i,1)].DoneFlag;
		for(int j = 2; j <= Ny; j++)
		{
            ci = GI(i,j);
            if((flag ^ grid[ci].DoneFlag) < 0)
            {
                pi = GI(i,j-1);
                flag = grid[ci].DoneFlag;
                if(flag >= 0) {
                    grid[ci].DoneFlag = 1;
                    AddClose(GI(i,j+1));
                    grid[ci].value = min(grid[ci].value, abs(h + grid[pi].value));
                }
                else {
                    grid[pi].DoneFlag = 1;
                    AddClose(GI(i,j-2));
                    grid[pi].value = min(grid[pi].value, abs(h + grid[ci].value));
                }
            }
        }
    }
    
	for(int j = 1; j <= Ny; j++)
	{
        flag = grid[GI(1,j)].DoneFlag;
		for(int i = 2; i <= Nx; i++)
		{
            ci = GI(i,j);
            if((flag ^ grid[ci].DoneFlag) < 0)
            {
                pi = GI(i-1,j);
                flag = grid[ci].DoneFlag;
                if(flag >= 0) {
                    grid[ci].DoneFlag = 1;
                    AddClose(GI(i+1,j));
                    grid[ci].value = min(grid[ci].value, abs(h + grid[pi].value));
                }
                else {
                    grid[pi].DoneFlag = 1;
                    AddClose(GI(i-2,j));
                    grid[pi].value = min(grid[pi].value, abs(h + grid[ci].value));
                }
            }
		}
	}
}
コード例 #9
0
/**
* 左のステージに選択を移す
*/
void StageSelect::GoToLeft()
{
	if( selectedIdx > 0 /*&& scrollNLRdir == 0*/){
		selectedIdx--;
		// スクロール
		scroll = -GI("STGSELECT_SLDDIST");
		scrollNLRdir = 1;
		// アルファフェード
		alpha = 0.0f;
		// カーソル
		curScroll = GI("STGSELECT_ALL1SX");
	}
}
コード例 #10
0
void FastMarch2D::SetBoundary()
{
	for(int i=1 ; i<=Ny; i++ ) grid[GI(0   ,i)].DoneFlag = grid[GI(Nx+1,i)].DoneFlag = -1;
	for(int i=1 ; i<=Nx; i++ ) grid[GI(i,0   )].DoneFlag = grid[GI(i,Ny+1)].DoneFlag = -1;
	grid[GI(0   ,0   )].DoneFlag = grid[GI(0   ,Ny+1)].DoneFlag = -1;
	grid[GI(Nx+1,0   )].DoneFlag = grid[GI(Nx+1,Ny+1)].DoneFlag = -1;
}
コード例 #11
0
/**
* 右のステージに選択を移す
*/
void StageSelect::GoToRight()
{
	if( selectedIdx < GAMECONTROL->GetStageManager()->GetLastStageIdx() - 
		GAMECONTROL->GetStageManager()->GetFirstStageIdx() )
	{
		selectedIdx++;
		scroll = GI("STGSELECT_SLDDIST");
		scrollNLRdir = 2;
		// アルファフェード
		alpha = 0.0f;
		// カーソル
		curScroll = -GI("STGSELECT_ALL1SX");
	}
}
コード例 #12
0
ファイル: TaskHandler.cpp プロジェクト: volyrique/esesc
void TaskHandler::report(const char *str) {
  /* dump statistics to report file {{{1 */

  Report::field("OSSim:nCPUs=%d",cpus.size());
  size_t cpuid     = 0;
  size_t cpuid_sub = 0;
  FlowID samplercount = 0;

  for(size_t i = 0;i<emulas.size();i++) {
    Report::field("OSSim:P(%d)_Sampler=%d",cpuid,(emulas[i]->getSampler())->getsFid());
    if ((emulas[i]->getSampler())->getsFid() > samplercount){
      samplercount = (emulas[i]->getSampler())->getsFid();
    }
    Report::field("OSSim:P(%d)_Type=%d",cpuid,emulas[i]->cputype);

    cpuid_sub++;
    if (cpuid_sub>=cpus[cpuid]->getMaxFlows()) {
      cpuid_sub = 0;
      GI((cpus.size() > 1), (cpuid < cpus.size()));
      cpuid     = cpuid+1;
    }
  }
  Report::field("OSSim:nSampler=%d",samplercount+1);
  Report::field("OSSim:globalClock=%lld",globalClock);



  /*
   *
     for(size_t i=0;i<cpus.size();i++) {
     cpus[i]->report(str);
     }*/

}
コード例 #13
0
void AddressPrefetcher::tryPrefetch(MemRequest *mreq)
{
  // NOTE: This prefetcher works because PAddr and VAddr are the
  // same. If they were different, there should be a translation layer
  // in the middle
  GI(mreq->isDataReq() && mreq->getVaddr(), mreq->getPAddr() == mreq->getVaddr());

  I(!mreq->isPrefetch()); // No recursion

  PAddr vaddr = mreq->getPAddr();

  if (!ThreadContext::isValidVAddr(vaddr))
    return; // Junk read or icache read (just ignore it)

  // Look at the words (word boundary) in the cache line displaced or
  // brough to the cache. Keep it in the small cache
  RAddr start = ThreadContext::getMainThreadContext()->virt2real(vaddr);

  I(ThreadContext::isPrivateVAddr(start));

  RAddr end   = start + bsize;

  for(RAddr addr = start ; addr < end ; addr+=4) {
    long *pos = (long *)addr;
    VAddr val = SWAP_WORD(*pos);
    if (ThreadContext::isPrivateVAddr(val)) {
      cache->fillLine(val); // FIXME
      MSG("prefetch [0x%x]",(uint) val);
    }
  }
}
コード例 #14
0
ファイル: MESIProtocol.cpp プロジェクト: jockey10/sesc
void MESIProtocol::read(MemRequest *mreq)
{
  PAddr addr = mreq->getPAddr();

  // time for this has already been accounted in SMPCache::read
  Line *l = pCache->getLine(addr);

  // if line is in transient state, read should not have been called
  GI(l, !l->isLocked()); 

  if(l)
  {
  	#ifdef TLS
	  	//Read hit is to be propagated
	  	doSendReadPropagate(mreq);
	  	return;
  	#endif
  }
  else
  {

  	#ifdef TLS
	    l = pCache->allocateLine(addr, mreq,doReadCB::create(this, mreq));
		if (l && mreq->isDataReq())
		{
			I (mreq->getEpoch());
			if (mreq->getEpoch()->getClock() !=0)
			{
				//printf("LINE:%p-EPOCH %p:%d:%d\n",l,mreq->getEpoch(),mreq->getEpoch()->getClock(),mreq->getEpoch()->getTid());
				l->setEpoch(mreq->getEpoch()); 
				(l->getCacheFlags())->setEpoch(mreq->getEpoch());
			}
			else
			{
				printf("Got a epoch with clk 0\n");
				l->setEpoch(0);
			}
			(l->getCacheFlags())->clearFlags();
				
		}
		else if (l)
		{
			l->setEpoch(0);
		}
		
	#else
	    l = pCache->allocateLine(addr, doReadCB::create(this, mreq));
	#endif
  }

  if(!l) {
    // not possible to allocate a line, will be called back later
    return;
  }
  
  changeState(l, MESI_TRANS_RSV);
  doRead(mreq);
}
コード例 #15
0
void FastMarch2D::PrintValues()
{
    cout << endl;
    for(int j=0; j < Ny+2; j++){
        for(int i=0; i < Nx+2; i++) 
            cout << grid[GI(i,j)].value << " ";
        cout << endl;
    }
}
コード例 #16
0
ファイル: KariudoKen.cpp プロジェクト: LakeIshikawa/splstage2
KariudoKen::KariudoKen(int rXPx, int rYPx)
{

	KARIKENSX = GI("KARIKENSX");
	KARIKENSY = GI("KARIKENSY");

	KARIKENSPX = GF("KARIKENSPX");
	KARIKENKGHANI = GF("KARIKENKGHANI");
	KARIKENWTM1 = GF("KARIKENWTM1");
	KARIKENWTM2 = GF("KARIKENWTM2");

	mX = rXPx;
	mY = rYPx - sMapAtHanteiY[0][0] + SP->CHSZY;

	mSizeX = KARIKENSX;
	mSizeY = KARIKENSY;

	mStatus = ARUKI;

	mKgTimer = 0.0f;

	mSeFl = false;

	// 当たり判定	
	AddFrame(FR_KAMAE);
	AddFrame(FR_ZANZOU);
	AddFrame(FR_DOWN);

	AddRect(FR_KAMAE, SP->GRID_BOGYO, 43, 33, 81, 119);
	AddIndexedRect( FR_KAMAE, SP->GRID_BOUND, TBOUND_IDX, 38, 22, 83, 120);
	
	AddRect(FR_ZANZOU, SP->GRID_BOGYO, 43, 33, 81, 119);
	AddCircle(FR_ZANZOU, SP->GRID_KOUGEKI, 38, 43, 35);
	AddCircle(FR_ZANZOU, SP->GRID_KOUGEKI, 33, 69, 35);
	AddIndexedRect( FR_ZANZOU, SP->GRID_BOUND, TBOUND_IDX, 38, 22, 83, 120);

	AddRect(FR_DOWN, SP->GRID_BOGYO, 43, 33, 81, 119);
	AddCircle(FR_DOWN, SP->GRID_BOGYO, 20, 62, 11);
	AddIndexedRect( FR_DOWN, SP->GRID_BOUND, TBOUND_IDX, 38, 22, 83, 120);

	//AddCircle(0, GRID_BOGYO, 60, 60, 30);

	SetAnim(0);
}
コード例 #17
0
void FastMarch2D::FastMarch() {
	static int x, y; 
	for(int index = PopHeap(); index != -1; index = PopHeap()) {
		if(grid[index].value > FASTMARCH_LIMIT) return;
		GIJ(index, x, y);
        if(grid[GI(x-1,y)].DoneFlag == 0) FindPhi(GI(x-1,y),x-1,y);
        if(grid[GI(x+1,y)].DoneFlag == 0) FindPhi(GI(x+1,y),x+1,y);
        if(grid[GI(x,y-1)].DoneFlag == 0) FindPhi(GI(x,y-1),x,y-1);
        if(grid[GI(x,y+1)].DoneFlag == 0) FindPhi(GI(x,y+1),x,y+1);
	}
}
コード例 #18
0
FlowID QEMUEmulInterface::getFid(FlowID last_fid)
/* Get a new fid, tries to use the same last_fid if possible/applicable */
{
  //pthread_mutex_lock(&mutex);
  I(fidFreePool.size() == nEmuls); 

  FlowID fid2 = FID_NULL;
  for(size_t i=0; i<nEmuls ; i++){ // Search for fids that are used and freed recently
    if (fidFreePool[i] == FID_FREED) {
      if (fid2 == FID_NULL) fid2 = i;
      if (last_fid != i) continue;
      fidFreePool[i] = FID_TAKEN;
      //pthread_mutex_unlock (&mutex);
      return i;
    }
  }
  FlowID fid1 = FID_NULL;
  for(size_t i=0; i<nEmuls ; i++){ 
    if (fidFreePool[i] == FID_FREE) {
      if (fid1 == FID_NULL) fid1 = i;
      if (last_fid != i) continue;
      fidFreePool[i] = FID_TAKEN;
      //pthread_mutex_unlock (&mutex);
      return i;
    }
  }
  
  if (fid2 != FID_NULL) {
    GI(last_fid != FID_NULL, 0); /* we should get the same FID except for the first call */
    fidFreePool[fid2] = FID_TAKEN;
    //pthread_mutex_unlock (&mutex);
    return fid2;
  }else if (fid1 != FID_NULL) {
    GI(last_fid != FID_NULL, 0); /* we should get the same FID except for the first call */
    fidFreePool[fid1] = FID_TAKEN;
    //pthread_mutex_unlock (&mutex);
    return fid1;
  }else {
    MSG("Error! demanding more flowID than what's available");
    exit(-11);
  }
  
}
コード例 #19
0
ファイル: MESIProtocol.cpp プロジェクト: jockey10/sesc
void MESIProtocol::doWrite(MemRequest *mreq)
{
  Line *l = pCache->getLine(mreq->getPAddr());

  GI(l->isLocked(), l->getState() == MESI_TRANS_RSV);

  changeState(l, MESI_TRANS_WR);

  sendWriteMiss(mreq);
}
コード例 #20
0
ファイル: EmuSampler.cpp プロジェクト: volyrique/esesc
bool EmuSampler::execute(FlowID fid, uint64_t icount)
  /* called for every instruction that qemu/gpu executes  */
{

  GI(mode==EmuTiming, icount==1);

  local_icount+=icount; // There can be several samplers, but each has its own thread
  //if ( likely(local_icount < 100))
  //  return !done[fid];

  AtomicAdd(&phasenInst, local_icount);
  AtomicAdd(&totalnInst, local_icount);
  local_icount = 0;

  if( likely(totalnInst <= next) )  // This is an likely taken branch, pass the info to gcc
    return !done[fid];

  next += 4*1024*1024; // Note, this is racy code. We can miss a rwdt from time to time, but who cares?

  if ( done[fid] ) {
    fprintf(stderr,"X" ); 
    fflush(stderr);
    {
      // We can not really, hold the thread, because it can hold locks inside qemu
      usleep(10000);
      fprintf(stderr,"X[%d]",fid); 
    }
  }else{
    if (mode==EmuRabbit)
      fprintf(stderr,"r%d",fid );
    else if (mode==EmuWarmup)
      fprintf(stderr,"w%d",fid );
    else if (mode==EmuDetail)
      fprintf(stderr,"d%d",fid );
    else if (mode==EmuTiming) 
      fprintf(stderr,"t%d",fid );
    else if (mode==EmuInit) 
      fprintf(stderr,">%d",fid );
    else
      fprintf(stderr,"?%d",fid );
  }

  // An adjustment when adding more than one instruction. Keeps the sample prints valid 
  // Repeat: Note, this is racy code. We can miss a rwdt from time to time, but who cares?
  if (icount > 1) {
    while (next < totalnInst) {
        if (mode==EmuRabbit)
            fprintf(stderr,"r%d",fid );
        next += 4*1024*1024; 
    }
    next = totalnInst;
  }

  return !done[fid];
}
コード例 #21
0
ファイル: MESIProtocol.cpp プロジェクト: jockey10/sesc
void MESIProtocol::doRead(MemRequest *mreq)
{
  Line *l = pCache->getLine(mreq->getPAddr());
  I(l);

  GI(l->isLocked(), l->getState() == MESI_TRANS_RSV);
  // go into transient state and send request out
  changeState(l, MESI_TRANS_RD);

  sendReadMiss(mreq);
}
コード例 #22
0
ファイル: P1583.cpp プロジェクト: LasseD/uva
int main() {
  int generators[MX];
  memset(generators, 0, sizeof(generators));
  for(int i = 1; i < MX; ++i) {
    int s = sum(i);
    if(s < MX && generators[s] == 0)
      generators[s] = i;
  }
  FORCAS {
    GI(x); 
    cout << generators[x] << endl;
  }
  return 0;
}
コード例 #23
0
ファイル: P10895.cpp プロジェクト: LasseD/uva
int main() {
  set<PI> rows[10001];
  int pos[10001];

  int width, height;
  while(cin >> height >> width) {
    FORI(width)
      rows[i].clear();
    FORI(height) {
      GI(N);
      FORJ(N) {
	cin >> pos[j];
	--pos[j];
      }
      FORJ(N) {
	GI(x);
	rows[pos[j]].insert(PI(i, x));
      }
    }
    cout << width << " " << height << endl;
    FORI(width) {
      cout << rows[i].size();
      FORIT(set<PI>, rows[i]) {
	cout << " " << it->first+1;
      }
      cout << endl;
      bool first = true;
      FORIT(set<PI>, rows[i]) {
	if(!first)
	  cout << " ";
	first = false;
	cout << it->second;
      }
      cout << endl;	
    } // FORI
  } // while(cin)
コード例 #24
0
ファイル: Stage.cpp プロジェクト: LakeIshikawa/splstage2
/*
	開始演�?
	終わったら1を返す
*/
void Stage::Init()
{
	if( !bgm_played){
		bgm_played = true;
		GAMECONTROL->GetSoundController()->SetBGM(mBgm);
	}

	// ?�ェ?�??��イ??
	if( GAMECONTROL->GetFader()->FadeIn() ){
		
		// タイトル表示
		if( title_stage == 0 ){
			title_stage = 1;
			GAMECONTROL->GetTxtGraphicController()->
				ShowWithEnterFromRight( GI("STGTITLE_Y"), GI("STGTITLE_SX"), GI("STGTITLE_SY"), mTitleGraphic, GF("STGTITLE_SPX") );
		}
		// act start
		if( GAMECONTROL->GetTxtGraphicController()->IsFinished() ){
			if( title_stage == 1 ){
				title_stage = 2;
				GAMECONTROL->GetTxtGraphicController()->
				ShowWithEnterFromRight( GI("STGACTSTART_Y"), GI("STGACTSTART_SX"), GI("STGACTSTART_SY"), "graphics\\txtgraphic\\actstart.png", GF("STGTITLE_SPX") );
			}
		}

		// �?
		if( GAMECONTROL->GetTxtGraphicController()->IsFinished() ){

			if( GAMECONTROL->GetMaku()->IsClosed() ) GAMECONTROL->GetMaku()->Open();
			// 幕をあげ�?
			if( GAMECONTROL->GetMaku()->IsOpen() ){
				inited = true;
				//BGM
				//GAMECONTROL->GetSoundController()->SetBGM(SoundController::STGSTART);
				GAMECONTROL->GetUserLightControl()->GetControlLight()->TurnOn();
				GAMECONTROL->GetJiki()->SetSuperControl();
				GAMECONTROL->GetJiki()->GetInterface()->Show();
				GAMECONTROL->GetStageManager()->GetCurrentStage()->GetSeigenJikan()->SeigenJikanOn();	
			}
		}


		// ?�ウ?�?�?�ッ?�演�?スキ�??
		if( GAMECONTROL->GetDXController()->IsMouseClicked() ){
			// 幕を強制�?��持ち上げ�?
			GAMECONTROL->GetMaku()->SetOpened();
			// �?��を消す
			GAMECONTROL->GetTxtGraphicController()->Reset();
			title_stage = 2;
		}
	}
}
コード例 #25
0
ファイル: VCR.cpp プロジェクト: jockey10/sesc
void VCR::addCheck(const VMemWriteReq *oreq, const VMemWriteReq *vreq)
{
  I(oreq->getType() == VWriteCheck);
  I(vreq->getType() == VWriteCheckAck);

  if(vreq->getVersionRef()==0)
    return;
  if (vreq->getVersionRef()->isKilled())
    return;

  // FIXME: add VCR energy
  //
  // VCR should be a small SRAM (direct map) structure with as many
  // entries as caches on the system multiplied by the associativity
  // (note that LMVCache may have different associativity)
  //
  // Additionaly, it also has version comparators (one per word).
  //
  // Caches send request in order, so that they can be locally combine
  // as soon as they arrive

  VCRMap::iterator it = vcrMap.find(oreq);
  VCRType *versionList;
  if(it == vcrMap.end()) {
    versionList = vcrPool.out();
    vcrMap[oreq] = versionList;
  }else{
    versionList = it->second;
  }

#ifdef DEBUG
  // Check that the same versions is not ack twice
  VCRType::iterator sit = versionList->begin();
  for(; sit != versionList->end(); sit++) {
    GI(!(*sit)->getVersionRef()->isKilled()
       ,(*sit)->getVersionRef() != vreq->getVersionRef());
  }
#endif

  VCREntry *entry = VCREntry::create(vreq->getStateRef()
				     ,vreq->getVersionDuplicate());
  versionList->insert(entry);
}
コード例 #26
0
ファイル: CCache.cpp プロジェクト: khaleghzadeh/esesc
void CCache::doReqAck(MemRequest *mreq)
/* CCache reqAck {{{1 */
{
  trackAddress(mreq);

  mreq->recoverReqAction();

  AddrType addr = mreq->getAddr();
  Line *l = cacheBank->readLine(addr);
  // It could be l!=0 if we requested a check in the lower levels to change state.
  if (l == 0) {
    l = allocateLine(addr, mreq);
  }else{
    if (notifyHigherLevels(l,mreq)) {
      // FIXME I(0);
      I(mreq->hasPendingSetStateAck());
      return;
    }
  }

  s_reqSetState[mreq->getAction()]->inc(mreq->getStatsFlag());

  int16_t portid = router->getCreatorPort(mreq);
  GI(portid<0,mreq->isHomeNode());
	l->adjustState(mreq, portid);

  Time_t when = port->reqDone(mreq)+dyn_hitDelay;
  mshr->retire(addr);

  avgMissLat.sample(mreq->getTimeDelay(when), mreq->getStatsFlag());
  avgMemLat.sample(mreq->getTimeDelay(when));

  if(mreq->isHomeNode()) {
		mreq->ackAbs(when);
  }else {
    router->scheduleReqAckAbs(mreq,when); 
  }
}
コード例 #27
0
ファイル: CCache.cpp プロジェクト: khaleghzadeh/esesc
bool CCache::CState::adjustState(MemRequest *mreq, int16_t portid) 
  // {{{1
{
  StateType ostate = state;
  state = calcAdjustState(mreq);

  //I(ostate != state); // only if we have full MSHR
  if (state == I) {
    invalidate();
    return true;
  }

  I(state != I);

  if (mreq->isDisp()) {
    removeSharing(portid);
  }else{
    addSharing(portid);
  }

  GI(nSharers>1,state!=E && state!=M); // ME states require single share

  return (ostate != state); // changed state?
}
コード例 #28
0
ファイル: P10365.cpp プロジェクト: LasseD/uva
int main() {
  int ret[1001];
  ret[0] = 0;
  for(int i = 1; i <= 1000; ++i)
    ret[i] = 2+4*i;

  for(int W = 1; W <= 1000; ++W) {
    for(int L = W; L*W <= 1000; ++L) {
      int area = W*L;
      for(int H = L; H*area <= 1000; ++H) {
	int volume = area*H;
	int surface = 2*(area + L*H + W*H);
	if(ret[volume] > surface)
	  ret[volume] = surface;
      }
    }
  }
  
  FORCAS {
    GI(N);
    cout << ret[N] << endl;
  }
  return 0;
}
コード例 #29
0
ファイル: CCache.cpp プロジェクト: khaleghzadeh/esesc
void CCache::doReq(MemRequest *mreq)
/* processor/upper level issued read/write/busread {{{1 */
{
  trackAddress(mreq);

  AddrType addr = mreq->getAddr();
  bool retrying = mreq->isRetrying();

  if (retrying) { // reissued operation
		mreq->clearRetrying();
  }else{
    //curRequests++;
    if(!mshr->canIssue(addr)) {
      s_reqHalfMiss[mreq->getAction()]->inc(mreq->getStatsFlag());

      mshr->addEntry(addr, &mreq->redoReqCB);
      mreq->setRetrying();
      return;
    }
    mshr->addEntry(addr);
  }

  Line *l = cacheBank->readLine(addr);
  if (l == 0) {
		mustForwardReqDown(mreq);
    return;
  }

  if (notifyLowerLevels(l,mreq)) {
    mustForwardReqDown(mreq);
    return; // Done (no retrying), and wait for the ReqAck
  }

  I(!mreq->hasPendingSetStateAck());
  if (notifyHigherLevels(l,mreq)) {
    I(mreq->hasPendingSetStateAck());
    mreq->setRetrying();
    return;
  }

	I(l);
	I(l->isValid());

  int16_t portid = router->getCreatorPort(mreq);
  GI(portid<0,mreq->isHomeNode());
	l->adjustState(mreq, portid);

  if (retrying)
    s_reqHalfMiss[mreq->getAction()]->inc(mreq->getStatsFlag());
  else
    s_reqHit[mreq->getAction()]->inc(mreq->getStatsFlag());

  avgMemLat.sample(mreq->getTimeDelay()+dyn_hitDelay);

  Time_t when = port->reqDone(mreq)+dyn_hitDelay;
	I(when>=globalClock);
  if(mreq->isHomeNode()) {
		mreq->ackAbs(when);
	}else{
    int16_t portid = router->getCreatorPort(mreq);
    l->adjustState(mreq, portid);
		mreq->convert2ReqAck(l->reqAckNeeds());
		router->scheduleReqAckAbs(mreq, when);
	}

  mshr->retire(addr);
}
コード例 #30
0
ファイル: P1.cpp プロジェクト: LasseD/uva
int main() {
  // Read images:
  GI(N);

  srand ( unsigned ( time(0) ) );

  vector<Image> vertical, horizontal;
  map<string,int> words;

  FORI(N) {
    if(i % 1000 == 0)
      cerr << ",";
    GS(type);

    Image image; image.i1 = i; image.i2 = -1;

    GI(M);
    FORJ(M) {
      GS(tag);
      if(words.find(tag) == words.end()) {
        words[tag] = (int)words.size()+1;
      }
      image.tags.push_back(words[tag]);
    }
    sort(image.tags.begin(), image.tags.end());

    if(type[0] == 'V') {
      vertical.push_back(image);
    }
    else {
      horizontal.push_back(image);
    }
  }
  cerr << "Data read" << endl;

  cout << (horizontal.size() + (vertical.size()/2)) << endl;

  // Pair the verticals:
  //sort(vertical.begin(), vertical.end(), cmpSize);
  random_shuffle(vertical.begin(), vertical.end(), myrandom);

  cerr << "Verticals sorted" << endl;

  for(int i = 0, j = (int)vertical.size()-1; i < j; i++, j--) {
    Image &a = vertical[i];
    Image &b = vertical[j];
    Image mix;
    mix.i1 = a.i1;
    mix.i2 = b.i1;
    // Merge tags:
    unsigned int idxA = 0, idxB = 0;
    while(idxA < a.tags.size() && idxB < b.tags.size()) {
      int ta = a.tags[idxA], tb = b.tags[idxB];
      if(ta < tb) {
        mix.tags.push_back(ta);
        idxA++;
      }
      else if(ta > tb) {
        mix.tags.push_back(tb);
        idxB++;
      }
      else {
        mix.tags.push_back(ta);
        idxA++;
        idxB++;
      }
    }
    while(idxA < a.tags.size()) {
      int t = a.tags[idxA++];
      mix.tags.push_back(t);
    }
    while(idxB < b.tags.size()) {
      int t = b.tags[idxB++];
      mix.tags.push_back(t);
    }
    horizontal.push_back(mix);
  }
  
  
  cerr << "MIXING" << endl;
  random_shuffle(horizontal.begin(), horizontal.end(), myrandom);
  cerr << "MIXING DONE" << endl;

  /*
  cout << "DEBUG" << endl;
  for(int i = 0; i < (int)horizontal.size(); i++) {
    Image &a = horizontal[i];
    output(a);
  }
  cout << "DEBUG END" << endl;*/

  int w = 30000;
  int total = 0;
  for(int i = 0; i < (int)horizontal.size(); i++) {
    if(i % 1000 == 0)
      cerr << ".";
    Image &a = horizontal[i];
    output(a); // Improve ahead:
    if(i+2 >= (int)horizontal.size()) {
      continue; // Don't improve if nothingg ahead.
    }
    int bestScore = -1;
    int bestJ = -1;
    for(int j = i+1; j <= w+i && j < (int)horizontal.size(); j++) {
      Image &b = horizontal[j];
      int v = score(a, b);
      if(v > bestScore) {
        bestScore = v;
        bestJ = j;
      }
    }
    total += bestScore;
    swap(horizontal[i+1], horizontal[bestJ]);
  }
  cerr << "TOTAL: " << total << endl;
}