コード例 #1
0
ファイル: mainWindow.c プロジェクト: Developer626/RockCrush
// Function to see if a proposed move results in matches
// Need to look two away on either side 0000CCSCC0000. 0=ignore, C=check, S=swap in both V and H
bool checkMove() {

  // we switch the colours temporarily
  switchColours(s_switch.first, s_switch.second);
  bool isValid = false;

  for (int p=0; p<2; ++p) {
    // Look in location A with location B's colour and visa versa
    if (p == 0) isValid = checkLocation(s_switch.first);
    if (p == 1) isValid = checkLocation(s_switch.second);
    if (isValid) break;
  }

  // switch back! we will animate the actual pieces into their new positions
  switchColours(s_switch.first, s_switch.second);

  // This routine also finds the computer a valid next move
  if (s_gameState == kFindNextMove) return isValid;

  // If it was user initiated we take action with the FSM
  if (isValid == true) {
    s_currentRun = 0;
    s_gameState = kSwapAnimate;
    s_hintOn = false;
    if (s_hintTimer) app_timer_cancel(s_hintTimer);
    s_hintTimer = NULL;
  } else {
    s_gameState = kNudgeAnimate;
  }
  return false; // This return to the FSM says no need to re-draw
}
コード例 #2
0
ファイル: Board.cpp プロジェクト: gcaven/oop-project
void generateLocation(Board *board, Human *human) {
	int xGen = randomInt(9,0);
	int yGen;
	if (human->enemy) {
		yGen = randomInt(1,0);
	} else {
		yGen = randomInt(9,8);
	}

	bool goodlocation = false;
	//make sure there are no other humans or boulders on the tile
	//if there is, choose another one
	while (!goodlocation) {
		goodlocation = checkLocation(board,xGen,yGen);
		if (!goodlocation) {
			xGen = randomInt(9,0);
			if (human->enemy) {
				yGen = randomInt(1,0);
			} else {
				yGen = randomInt(9,8);
			}
		}
	}
	human->x = xGen;
	human->y = yGen;
	board->tiles[xGen][yGen].setCharacter(human);
	return;
}
コード例 #3
0
ファイル: qgsgrassnewmapset.cpp プロジェクト: nbozon/QGIS
void QgsGrassNewMapset::locationRadioSwitched()
{
    if ( mSelectLocationRadioButton->isChecked() )
    {
        mLocationComboBox->setEnabled( true );
        mLocationLineEdit->setEnabled( false );
    }
    else
    {
        mLocationComboBox->setEnabled( false );
        mLocationLineEdit->setEnabled( true );
    }
    checkLocation();
}
コード例 #4
0
ファイル: dirac_staggered.cpp プロジェクト: lattice/quda
  void DiracStaggered::Dslash(ColorSpinorField &out, const ColorSpinorField &in, 
			      const QudaParity parity) const
  {
    checkParitySpinor(in, out);

    if (checkLocation(out, in) == QUDA_CUDA_FIELD_LOCATION) {
      staggeredDslashCuda(&static_cast<cudaColorSpinorField&>(out), 
			  *gauge, &static_cast<const cudaColorSpinorField&>(in), parity, 
			  dagger, 0, 0, commDim, profile);
    } else {
      errorQuda("Not supported");
    }

    flops += 570ll*in.Volume();
  }
コード例 #5
0
ファイル: MemoryManager.cpp プロジェクト: 8l/rose
void MemoryManager::checkRead(Location addr, size_t size) const
{
    const MemoryType* mt = checkLocation(addr, size, RuntimeViolation::INVALID_READ);
    assert(mt && ((mt->beginAddress() <= addr) || (!mt->blockSize())));

    if(! mt->isInitialized(addr, size) )
    {
      RuntimeSystem& rs = RuntimeSystem::instance();

      std::stringstream desc;
      desc << "Trying to read from uninitialized MemoryRegion "
           << "(Address " << addr
           << " of size " << std::dec << size << ")"
           << std::endl;

      rs.violationHandler(RuntimeViolation::INVALID_READ, desc.str());
    }
}
コード例 #6
0
ファイル: dirac_domain_wall.cpp プロジェクト: lattice/quda
  void DiracDomainWall::Dslash(ColorSpinorField &out, const ColorSpinorField &in, 
			       const QudaParity parity) const
  {
    if ( in.Ndim() != 5 || out.Ndim() != 5) errorQuda("Wrong number of dimensions\n");
    checkParitySpinor(in, out);
    checkSpinorAlias(in, out);
    if (checkLocation(out, in) == QUDA_CUDA_FIELD_LOCATION) {
      domainWallDslashCuda(&static_cast<cudaColorSpinorField&>(out), *gauge, 
			   &static_cast<const cudaColorSpinorField&>(in), 
			   parity, dagger, 0, mass, 0, commDim, profile);   
    } else {
      errorQuda("Not implemented");
    }

    long long Ls = in.X(4);
    long long bulk = (Ls-2)*(in.Volume()/Ls);
    long long wall = 2*in.Volume()/Ls;
    flops += 1320LL*(long long)in.Volume() + 96LL*bulk + 120LL*wall;
  }
コード例 #7
0
ファイル: newprojectwizard.cpp プロジェクト: fkfj/dosmall
bool ProjectInfoPage::checkLocation(const QString &text)
{
	projectLocation = text;
	projectLocation.remove(QRegExp("^\\s*"));
	projectLocation.remove(QRegExp("\\s*$"));
	projectLocation.remove(QRegExp("/$"));
	projectPathLineEdit->setText(projectLocation + "/" + projectName);
	
	if (!checkLocation())
		return false;
	if (!checkName())
		return false;
	if (!checkPath())
		return false;
	
	warningLabel->clear();
	warningLineEdit->setText(tr("t"));
	return true;
}
コード例 #8
0
ファイル: mainWindow.c プロジェクト: Developer626/RockCrush
void newGame(bool doLoadGame) {
  // Zero data store
  memset(&s_pieces, 0, BOARD_PIECES_X * BOARD_PIECES_Y * sizeof(Piece_t));
  memset(&s_score, 0, sizeof(Score_t));
  if (doLoadGame == true) {
    loadGame();
  } else { // new game
    // Init score
    s_score.level = 1;
    s_score.lives = 3;
    s_score.pointsToNextLevel = 200;
    s_score.nColoursActive = 5;
    #ifdef DEBUG_MODE
    s_score.nColoursActive = 3; // Allows to test long runs and interaction of special pieces with ease
    #endif
  }
  updateLevelColour();

  int offset = BOARD_SIZE_Y * SUB_PIXEL;
  for (int y = BOARD_PIECES_Y-1; y >= 0; --y) {
    for (int x = 0; x < BOARD_PIECES_X; ++x) {
      if (doLoadGame == false) {
        bool placing = true;
        while (placing) {
          s_pieces[ XY(x,y) ].colour = (rand() % s_score.nColoursActive) + 1;
          placing = checkLocation(GPoint(x,y)); // if match found then we're still placing as we need to try again
        }
      }
      s_pieces[ XY(x,y) ].loc.x = x * PIECE_SUB_PIXELS; // Set location
      s_pieces[ XY(x,y) ].loc.y = (y * PIECE_SUB_PIXELS) - offset; // Lets pieces fall in
    }
    offset += PIECE_SUB_PIXELS;
  }

  checkTiltMode();
  s_hintStatus = getHintStatus();  // Only want to read this once from store
  s_scoreState = kWait;
  s_gameState = kSettleBoard;
  s_gameOverMessage = false;
}
コード例 #9
0
ファイル: qgsgrassnewmapset.cpp プロジェクト: nbozon/QGIS
void QgsGrassNewMapset::newLocationChanged()
{
    QgsDebugMsg( "entered." );
    checkLocation();
}
コード例 #10
0
ファイル: qmlmanager.cpp プロジェクト: lehoon/subsurface
// update the dive and return the notes field, stripped of the HTML junk
void QMLManager::commitChanges(QString diveId, QString date, QString location, QString gps, QString duration, QString depth,
			       QString airtemp, QString watertemp, QString suit, QString buddy, QString diveMaster, QString weight, QString notes,
			       QString startpressure, QString endpressure, QString gasmix)
{
	struct dive *d = get_dive_by_uniq_id(diveId.toInt());
	DiveObjectHelper *myDive = new DiveObjectHelper(d);

	// notes comes back as rich text - let's convert this into plain text
	QTextDocument doc;
	doc.setHtml(notes);
	notes = doc.toPlainText();

	if (!d) {
		qDebug() << "don't touch this... no dive";
		return;
	}
	bool diveChanged = false;
	bool needResort = false;

	diveChanged = needResort = checkDate(myDive, d, date);

	diveChanged |= checkLocation(myDive, d, location, gps);

	diveChanged |= checkDuration(myDive, d, duration);

	diveChanged |= checkDepth(myDive, d, depth);

	if (myDive->airTemp() != airtemp) {
		diveChanged = true;
		d->airtemp.mkelvin = parseTemperatureToMkelvin(airtemp);
	}
	if (myDive->waterTemp() != watertemp) {
		diveChanged = true;
		d->watertemp.mkelvin = parseTemperatureToMkelvin(watertemp);
	}
	// not sure what we'd do if there was more than one weight system
	// defined - for now just ignore that case
	if (weightsystem_none((void *)&d->weightsystem[1])) {
		if (myDive->sumWeight() != weight) {
			diveChanged = true;
			d->weightsystem[0].weight.grams = parseWeightToGrams(weight);
		}
	}
	// start and end pressures for first cylinder only
	if (myDive->startPressure() != startpressure || myDive->endPressure() != endpressure) {
		diveChanged = true;
		d->cylinder[0].start.mbar = parsePressureToMbar(startpressure);
		d->cylinder[0].end.mbar = parsePressureToMbar(endpressure);
		if (d->cylinder[0].end.mbar > d->cylinder[0].start.mbar)
			d->cylinder[0].end.mbar = d->cylinder[0].start.mbar;
	}
	// gasmix for first cylinder
	if (myDive->firstGas() != gasmix) {
		int o2 = parseGasMixO2(gasmix);
		int he = parseGasMixHE(gasmix);
		// the QML code SHOULD only accept valid gas mixes, but just to make sure
		if (o2 >= 0 && o2 <= 1000 &&
		    he >= 0 && he <= 1000 &&
		    o2 + he <= 1000) {
			diveChanged = true;
			d->cylinder[0].gasmix.o2.permille = o2;
			d->cylinder[0].gasmix.he.permille = he;
		}
	}
	if (myDive->suit() != suit) {
		diveChanged = true;
		free(d->suit);
		d->suit = strdup(qPrintable(suit));
	}
	if (myDive->buddy() != buddy) {
		diveChanged = true;
		free(d->buddy);
		d->buddy = strdup(qPrintable(buddy));
	}
	if (myDive->divemaster() != diveMaster) {
		diveChanged = true;
		free(d->divemaster);
		d->divemaster = strdup(qPrintable(diveMaster));
	}
	if (myDive->notes() != notes) {
		diveChanged = true;
		free(d->notes);
		d->notes = strdup(qPrintable(notes));
	}
	// now that we have it all figured out, let's see what we need
	// to update
	DiveListModel *dm = DiveListModel::instance();
	int oldModelIdx = dm->getDiveIdx(d->id);
	int oldIdx = get_idx_by_uniq_id(d->id);
	if (needResort) {
		// we know that the only thing that might happen in a resort is that
		// this one dive moves to a different spot in the dive list
		sort_table(&dive_table);
		int newIdx = get_idx_by_uniq_id(d->id);
		if (newIdx != oldIdx) {
			DiveListModel::instance()->removeDive(oldModelIdx);
			DiveListModel::instance()->insertDive(oldModelIdx - (newIdx - oldIdx), myDive);
			diveChanged = false; // because we already modified things
		}
	}
	if (diveChanged) {
		if (d->maxdepth.mm == d->dc.maxdepth.mm &&
		    d->maxdepth.mm > 0 &&
		    same_string(d->dc.model, "manually added dive") &&
		    d->dc.samples == 0) {
			// so we have depth > 0, a manually added dive and no samples
			// let's create an actual profile so the desktop version can work it
			// first clear out the mean depth (or the fake_dc() function tries
			// to be too clever
			d->meandepth.mm = d->dc.meandepth.mm = 0;
			d->dc = *fake_dc(&d->dc, true);
		}
		DiveListModel::instance()->updateDive(oldModelIdx, d);
		invalidate_dive_cache(d);
		mark_divelist_changed(true);
	}
	if (diveChanged || needResort)
		changesNeedSaving();
}
コード例 #11
0
ファイル: MemoryManager.cpp プロジェクト: 8l/rose
bool
MemoryManager::checkIfSameChunk(Location addr1, Location addr2, size_t typeSize, RuntimeViolation::Type violation) const
{
  RuntimeViolation::Type access_violation = violation;

  if (access_violation != RuntimeViolation::NONE) access_violation = RuntimeViolation::INVALID_READ;

  const MemoryType*      mem1 = checkLocation(addr1, typeSize, access_violation);
  const bool             sameChunk = (mem1 && mem1->containsMemArea(addr2, typeSize));

  // check that addr1 and addr2 point to the same base location
  if (! sameChunk)
  {
    const MemoryType*    mem2 = checkLocation(addr2, typeSize, access_violation);
    // the error is skipped, if a chunk is not available b/c pointer errors
    // should be recorded only when the out-of-bounds memory is accessed, but
    // not when the pointer is moved out of bounds.
    const bool           skiperr = (violation == RuntimeViolation::NONE && !(mem1 && mem2));

    if (!skiperr)
    {
      assert(mem1 && mem2 && mem1 != mem2);
      RuntimeSystem&       rs = RuntimeSystem::instance();
      std::stringstream    ss;

      ss << "Pointer changed allocation block from " << addr1 << " to " << addr2 << std::endl;

      rs.violationHandler( violation, ss.str() );
    }

    return false;
  }

  // so far we know that addr1, addr2 have been allocated within the same chunk
  // now, test for same array chunks
  const size_t                totalblocksize = mem1->blockSize();
  const Location              memloc = mem1->beginAddress();
  const std::ptrdiff_t        ofs1 = byte_offset(memloc, addr1, totalblocksize, 0);
  const std::ptrdiff_t        ofs2 = byte_offset(memloc, addr2, totalblocksize, 0);

  //~ std::cerr << *mem1 << std::endl;
  //~ std::cerr << "a = " << addr1 << std::endl;
  //~ std::cerr << "b = " << addr2 << std::endl;
  //~ std::cerr << "ts = " << typeSize << std::endl;
  //~ std::cerr << "tbs = " << totalblocksize << std::endl;

  // \pp as far as I understand, getTypeAt returns the innermost type
  //     that overlaps a certain memory region [addr1, typeSize).
  //     The current implementation stops at the highest level of array...
  const RsType*               type1 = mem1 -> getTypeAt( ofs1, typeSize );
  const RsType*               type2 = mem1 -> getTypeAt( ofs2, typeSize );
  std::auto_ptr<const RsType> guard1(NULL);
  std::auto_ptr<const RsType> guard2(NULL);

  if( !type1 ) {
      //~ std::cerr << "type1! " << std::endl;
      type1 = mem1->computeCompoundTypeAt( ofs1, typeSize );
      guard1.reset(type1);
  }

  if( !type2 ) {
      //~ std::cerr << "type2! " << std::endl;
      type2 = mem1->computeCompoundTypeAt( ofs2, typeSize );
      guard2.reset(type2);
  }

  assert( type1 && type2 );

  //~ std::cerr << "-- T1 = " << typeid(*type1).name() << std::endl;
  //~ std::cerr << "-- T2 = " << typeid(*type2).name() << std::endl;

  bool               accessOK = type1->isConsistentWith( *type2 );
  const RsArrayType* array = (accessOK ? dynamic_cast< const RsArrayType* >( type1 ) : 0);

  //~ std::cerr << "accOK: " << accessOK << std::endl;

  if (array)
  {
    // \pp in order to calculate the last memory location of elem, we need to
    //     know whether its type is an array type, and whether this is an
    //     immediate (there is no user defined type or pointer in between)
    //     subarray of the containing array.
    const size_t          blockofs = 0; /* \todo calculate offset from addr1 */

    // \pp \todo
    //     not sure why bounds checking is based on a relative address (addr1)
    //     and not on absolute boundaries of the chunk where this address
    //     is located...
    //     e.g., addr2 < array(addr).lb || array(addr).ub < (addr2+typeSize)
    //     - a reason is that we want to bounds check within a multi-dimensional
    //       array; a sub-array might not start at the same address as the
    //       allocated chunk (which is always at [0][0]...)
    // \bug  this works fine for arrays, but it does not seem to be OK for
    //       pointers; in which case addr1 might point in the middle of a chunk.
    const Location       arrlb = addr1;
    const std::ptrdiff_t arrlen = array->getByteSize();
    const Location       elemlo = addr2;
          Location       elemhi = addr2;
    const RsType*        memtype = mem1->getTypeAt( 0, mem1->getSize() );
    const size_t         basesize = basetypeSize(memtype);

    if (typeSize > basesize)
    {
      // elem is another array
      // assert( rs->testing() || dynamic_cast< const RsArrayType* >(type2) );

      const long   elemblockofs = 0; // \todo calculate the ofs of elem's address (is this needed?)

      elemhi = ::add(elemhi, typeSize-1, totalblocksize, elemblockofs);
    }
    else
    {
      elemhi.local += (typeSize-1);
    }

    // \pp \note [arrlb, arrub] and [elemlo, elemhi]  (therefore typeSize - 1)
    //           arrub < elemhi this holds for UPC
    //           in contrast, using a range [elemlb, elemub) causes problems
    //           for UPC where the elemub can be larger than arrub
    //           for last elements on threads other than 0.
    //           e.g., shared int x[THREADS];
    //                   arrub == &x@thread(0) + sizeof(int)
    //                 writing to x[1] has the following upper bound
    //                   elemub == &x@thread(1) + sizeof(int)
    //                 consequently arrub < elemub :(

#if EXTENDEDDBG
    std::cerr << "  arrlb = " << arrlb << "( lb + " << arrlen << " [" << totalblocksize << "] )" << std::endl;
    std::cerr << "  elmlb = " << elemlo << std::endl;
    std::cerr << "  elmub = " << elemhi << " ( lb + " << typeSize << " )" << std::endl;

    std::cerr << "  ofs(elemlb) >= 0 : " << byte_offset(arrlb, elemlo, totalblocksize, blockofs) << std::endl;
    std::cerr << "  ofs(elemub) < sz(arr) : " << (byte_offset(arrlb, elemhi, totalblocksize, blockofs)) << std::endl;
#endif /* EXTENDEDDBG */

    // the offset of the element in respect to the array has to be positive
    //   and the offset of the elements last byte has to be less than the
    //   array length.
    accessOK  = (byte_offset(arrlb, elemlo, totalblocksize, blockofs) >= 0);
    accessOK &= (byte_offset(arrlb, elemhi, totalblocksize, blockofs) < arrlen);

    // the array element might be before it [ -1 ]
    // ... or after the array [ N ]...
    // was: accessOK = ! ( (elemlo < arrlb) || (arrub < elemhi) )
    /* was:
    if  !(  addr1 + array -> getByteSize() >= addr2 + typeSize  // the array element might be after the array [ N ]...
         && addr1 <= addr2 // ... or before it [ -1 ]
         *   (12)     (8)
         )
    {
      // out of bounds error (e.g. int[2][3], ref [0][3])
      consistent = false;
    }
    */
  }

  if (!accessOK)
    failNotSameChunk( *type1, *type2, addr1, addr2, *mem1, violation );

  return accessOK;
}
コード例 #12
0
ファイル: MemoryManager.cpp プロジェクト: 8l/rose
bool MemoryManager::isInitialized(Location addr, size_t size) const
{
    const MemoryType* mt = checkLocation(addr, size, RuntimeViolation::INVALID_READ);

    return mt->isInitialized(addr, size);
}
コード例 #13
0
ファイル: qgsgrassnewmapset.cpp プロジェクト: rskelly/QGIS
void QgsGrassNewMapset::newLocationChanged()
{
  checkLocation();
}