本文整理汇总了C++中DataReader::position方法的典型用法代码示例。如果您正苦于以下问题:C++ DataReader::position方法的具体用法?C++ DataReader::position怎么用?C++ DataReader::position使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataReader
的用法示例。
在下文中一共展示了DataReader::position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: init
void Engine::init(DataReader& reader, const std::vector<Player*> players, const std::vector<GameObserver*>& observers)
{
// check that engine is not initialized yet
assert(!mPlayerIdCounter);
assert(mGeneratedIds.empty());
assert(mPlayers.empty());
assert(!mDeck);
assert(mGameObservers.empty());
// read players count
std::vector<const PlayerId*>::size_type playersCount;
reader.read(playersCount);
assert(players.size() == playersCount);
// add players
for (std::vector<Player*>::const_iterator it = players.begin(); it != players.end(); ++it) {
add(**it);
}
const Card defaultCard(SUIT_LAST, RANK_LAST);
// read each player cards
for (std::vector<const PlayerId*>::const_iterator it = mGeneratedIds.begin(); it != mGeneratedIds.end(); ++it) {
CardSet& playerCards = mPlayersCards[*it];
assert(playerCards.empty());
reader.read(playerCards, defaultCard);
mPlayers[*it]->cardsRestored(playerCards);
}
// read deck
Deck deck;
reader.read(deck, defaultCard);
Suit trumpSuit;
reader.read(trumpSuit);
deck.setTrumpSuit(trumpSuit);
setDeck(deck);
// read current player index
unsigned int currentPlayerindex;
reader.read(currentPlayerindex);
mCurrentPlayer = mGeneratedIds[currentPlayerindex];
// read current round index
reader.read(mRoundIndex);
bool roundRunning;
reader.read(roundRunning);
if (roundRunning) {
mCurrentRoundIndex = &mRoundIndex;
// read current round data
std::vector<const PlayerId*>::size_type attackersAmount;
reader.read(attackersAmount);
while (attackersAmount--) {
unsigned int attackerIndex;
reader.read(attackerIndex);
mAttackers.push_back(mGeneratedIds[attackerIndex]);
}
unsigned int defenderIndex;
reader.read(defenderIndex);
mDefender = mGeneratedIds[defenderIndex];
reader.read(mPassedCounter);
unsigned int currentRoundAttackerIndex;
reader.read(currentRoundAttackerIndex);
mCurrentRoundAttackerId = mGeneratedIds[currentRoundAttackerIndex];
std::vector<Card> attackCards;
reader.read(attackCards, defaultCard);
for (std::vector<Card>::iterator it = attackCards.begin(); it != attackCards.end(); ++it) {
mTableCards.addAttackCard(*it);
}
std::vector<Card> defendCards;
reader.read(defendCards, defaultCard);
for (std::vector<Card>::iterator it = defendCards.begin(); it != defendCards.end(); ++it) {
mTableCards.addDefendCard(*it);
}
reader.read(mMaxAttackCards);
reader.read(mDefendFailed);
mPickAttackCardFromTable = !mDefendFailed && attackCards.size() == defendCards.size() + 1;
}
// append observers
mGameObservers.insert(mGameObservers.end(), observers.begin(), observers.end());
std::map<const PlayerId*, unsigned int> playersCards;
for (PlayerIds::const_iterator it = mGeneratedIds.begin(); it != mGeneratedIds.end(); ++it) {
playersCards[*it] = mPlayersCards[*it].size();
}
std::for_each(mGameObservers.begin(), mGameObservers.end(), GameRestoredNotification(mGeneratedIds, playersCards, mDeck->size(), mDeck->trumpSuit(), mTableCards));
// initialize observers
unsigned int savedObservers;
reader.read(savedObservers);
assert(savedObservers == mGameObservers.size());
for (std::vector<GameObserver*>::iterator it = mGameObservers.begin(); it != mGameObservers.end(); ++it) {
unsigned int observerDataStart = reader.position();
(*it)->init(reader);
unsigned int actualObserverDataSize = reader.position() - observerDataStart;
unsigned int expectedObserverDataSize;
reader.read(expectedObserverDataSize);
assert(actualObserverDataSize == expectedObserverDataSize);
//.........这里部分代码省略.........