void UpdateController::moveSnake(Snake &snake) { switch (input) { case KEY_LEFT: snake.movex(-1); break; case KEY_RIGHT: snake.movex(1); break; case KEY_UP: snake.movey(-1); break; case KEY_DOWN: snake.movey(1); break; default: snake.movex(1); } for ( auto iter = coins.begin(), endPtr = coins.end() ; iter != endPtr ; ++iter ) { if (snake.headLiesOn(iter->getxy())) { snake.grow(iter->getvalue()); coinMutex.lock(); *iter = Coin(getFreeCoord()); coinMutex.unlock(); break; } } auto head = snake.getHead(); if (snake.bitItself() || !map.contains(head) || snakeWallCollision()) { stop(); } }
void CCoinsViewCache::AddCoin(const COutPoint &outpoint, Coin&& coin, bool possible_overwrite) { if (pChainedWitView) { if ( IsPow2WitnessOutput(coin.out) ) { pChainedWitView->AddCoin(outpoint, Coin(coin.out, coin.nHeight, coin.fCoinBase, coin.fSegSig), possible_overwrite); } } assert(!coin.IsSpent()); if (coin.out.IsUnspendable()) return; CTxOut out = coin.out; CCoinsMap::iterator it; bool inserted; std::tie(it, inserted) = cacheCoins.emplace(std::piecewise_construct, std::forward_as_tuple(outpoint), std::tuple<>()); bool fresh = false; if (!inserted) { cachedCoinsUsage -= it->second.coin.DynamicMemoryUsage(); } if (!possible_overwrite) { if (!it->second.coin.IsSpent()) { throw std::logic_error("Adding new coin that replaces non-pruned entry"); } fresh = !(it->second.flags & CCoinsCacheEntry::DIRTY); } it->second.coin = std::move(coin); it->second.flags |= CCoinsCacheEntry::DIRTY | (fresh ? CCoinsCacheEntry::FRESH : 0); cachedCoinsUsage += it->second.coin.DynamicMemoryUsage(); }
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight) { bool fCoinbase = tx.IsCoinBase(); const uint256& txid = tx.GetHash(); for (size_t i = 0; i < tx.vout.size(); ++i) { // Pass fCoinbase as the possible_overwrite flag to AddCoin, in order to correctly // deal with the pre-BIP30 occurrances of duplicate coinbase transactions. cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), fCoinbase); } }
void AddCoins(CCoinsViewCache& cache, const CTransaction &tx, int nHeight, bool check) { bool fCoinbase = tx.IsCoinBase(); const uint256& txid = tx.GetHash(); for (size_t i = 0; i < tx.vout.size(); ++i) { bool overwrite = check ? cache.HaveCoin(COutPoint(txid, i)) : fCoinbase; // Always set the possible_overwrite flag to AddCoin for coinbase txn, in order to correctly // deal with the pre-BIP30 occurrences of duplicate coinbase transactions. cache.AddCoin(COutPoint(txid, i), Coin(tx.vout[i], nHeight, fCoinbase), overwrite); } }
bool CCoinsViewMemPool::GetCoin(const COutPoint &outpoint, Coin &coin) const { // If an entry in the mempool exists, always return that one, as it's guaranteed to never // conflict with the underlying cache, and it cannot have pruned entries (as it contains full) // transactions. First checking the underlying cache risks returning a pruned entry instead. CTransactionRef ptx = mempool.get(outpoint.hash); if (ptx) { if (outpoint.n < ptx->vout.size()) { coin = Coin(ptx->vout[outpoint.n], MEMPOOL_HEIGHT, false); return true; } else { return false; } } return base->GetCoin(outpoint, coin); }
static void CheckAddCoinBase(CAmount base_value, CAmount cache_value, CAmount modify_value, CAmount expected_value, char cache_flags, char expected_flags, bool coinbase) { SingleEntryCacheTest test(base_value, cache_value, cache_flags); CAmount result_value; char result_flags; try { CTxOut output; output.nValue = modify_value; test.cache.AddCoin(OUTPOINT, Coin(std::move(output), 1, coinbase), coinbase); test.cache.SelfTest(); GetCoinsMapEntry(test.cache.map(), result_value, result_flags); } catch (std::logic_error& e) { result_value = FAIL; result_flags = NO_ENTRY; } BOOST_CHECK_EQUAL(result_value, expected_value); BOOST_CHECK_EQUAL(result_flags, expected_flags); }
void Wallet::newCoin(Coin& coin, const ZZ &rValue, int coinIndex) { coin = Coin(params, walletSize, coinIndex, sk_u, s, t, signature, stat, lx, rValue, coinDenom, hashAlg); }
void UpdateController::addCoin() { coinMutex.lock(); coins.push_back(Coin (getFreeCoord())); coinMutex.unlock(); }
void Walkway::draw() { // static GLuint texture = BMPTextureLoader::loadTexture("box.bmp"); static GLuint texture = PNGTextureLoader::loadTexture("space.png"); if(walkwayList == 0) { walkwayList = glGenLists(1); cerr << "New list!" << endl; glNewList(walkwayList, GL_COMPILE); glPushMatrix(); glEnable(GL_TEXTURE_2D); glDisable(GL_LIGHTING); glColor3f(1.0f, 1.0f, 1.0f); glColor3ub(50, 50, 100); glBindTexture(GL_TEXTURE_2D, texture); glBegin(GL_QUADS); glNormal3f(0.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(LEFT_LIMIT-5, -10, HIGH_LIMIT+10); glTexCoord2f(0.0f, 0.0f); glVertex3f(LEFT_LIMIT-5, -10, LOW_LIMIT-10); glTexCoord2f(1.0f, 0.0f); glVertex3f(RIGHT_LIMIT+5, -10, LOW_LIMIT-10); glTexCoord2f(1.0f, 1.0f); glVertex3f(RIGHT_LIMIT+5, -10, HIGH_LIMIT+10); glEnd(); glEnable(GL_LIGHTING); glDisable(GL_TEXTURE_2D); glPopMatrix(); glEndList(); } if(EnergyBall::texture == 0) { EnergyBall::texture = PNGTextureLoader::loadTexture("whitespace.png"); } if(Coin::texture == 0) { Coin::texture = PNGTextureLoader::loadTexture("goldspace.png"); } if(energyBalls.size() == 0) { for(int z = Walkway::LOW_LIMIT; z < Walkway::HIGH_LIMIT; z++) for(int x = Walkway::LEFT_LIMIT; x < Walkway::RIGHT_LIMIT; x++) { if(rand()%500 == 0) energyBalls.push_back(Position(x, -9, z)), energyBallsObj.push_back(EnergyBall(x, -9, z, 0.5)); } if(coinDisks.size() == 0) for(int z = Walkway::LOW_LIMIT; z < Walkway::HIGH_LIMIT; z++) for(int x = Walkway::LEFT_LIMIT; x < Walkway::RIGHT_LIMIT; x++) { if(rand()%200 == 0) coinDisks.push_back(Position(x, -9, z)), coinDisksObj.push_back(Coin(x, -9, z, 0.7)); } } glCallList(walkwayList); glColor3ub(254, 254, 254); for(int i = 0; i < energyBalls.size(); i++) energyBallsObj[i].draw(); glColor3f(1.0f, 1.0f, 1.0f); for(int i = 0; i < coinDisks.size(); i++) coinDisksObj[i].draw(); return; }