本文整理汇总了C++中DataWriter::position方法的典型用法代码示例。如果您正苦于以下问题:C++ DataWriter::position方法的具体用法?C++ DataWriter::position怎么用?C++ DataWriter::position使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DataWriter
的用法示例。
在下文中一共展示了DataWriter::position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: save
void Engine::save(DataWriter& writer) const
{
if (!mDeck || !mCurrentPlayer) {
// save called too early - nothing to save actually because the game has not been even started
return;
}
lock();
// save players count
writer.write(mGeneratedIds.size());
// save each player cards
for (std::vector<const PlayerId*>::const_iterator it = mGeneratedIds.begin(); it != mGeneratedIds.end(); ++it) {
const CardSet& playerCards = mPlayersCards.at(*it);
writer.write(playerCards.begin(), playerCards.end());
}
// save deck
writer.write(mDeck->begin(), mDeck->end());
// save trump suit
writer.write(mDeck->trumpSuit());
// save current player index
writer.write(mGeneratedIds.index(mCurrentPlayer));
// save current round index
writer.write(mRoundIndex);
// save bool if round is running
writer.write(static_cast<bool>(mCurrentRoundIndex));
// save current round related data
if (mCurrentRoundIndex) {
// save attackers
writer.write(mAttackers.size());
for (std::vector<const PlayerId*>::const_iterator it = mAttackers.begin(); it != mAttackers.end(); ++it) {
writer.write(mGeneratedIds.index(*it));
}
assert(mDefender);
writer.write(mGeneratedIds.index(mDefender));
writer.write(mPassedCounter);
assert(mCurrentRoundAttackerId);
writer.write(mGeneratedIds.index(mCurrentRoundAttackerId));
writer.write(mTableCards.attackCards().begin(), mTableCards.attackCards().end());
writer.write(mTableCards.defendCards().begin(), mTableCards.defendCards().end());
writer.write(mMaxAttackCards);
writer.write(mDefendFailed);
}
// save observers data
unsigned int observersCount = mGameObservers.size();
writer.write(observersCount);
for (std::vector<GameObserver*>::const_iterator it = mGameObservers.begin(); it != mGameObservers.end(); ++it) {
unsigned int observerDataStart = writer.position();
(*it)->save(writer);
writer.write(static_cast<unsigned int>(writer.position() - observerDataStart));
}
unlock();
}