示例#1
0
void Game::saveGame()
{
	std::ofstream ofs("saved_game");
	GameState gs;
	std::cout << "DONE 1" << std::endl;
	// Populate the game state
	// Add local players' states
	for (std::vector<RenderableChar*>::iterator ite = local_players.begin(); ite != local_players.end(); ++ite) {
		Ogre::Vector3 p = (*ite)->getWorldPosition();
		gs.addPlayerState(p.x, p.y, p.z, (*ite)->GetName());
		// Add score
		gs.addScore(ScoreManager::getSingletonPtr()->getScore((*ite)->GetName()));
	}
	// Add level blocks
	if (myLevel != NULL) {
		std::vector<LevelBlock*> myobjs = myLevel->getLevelObjects(); 
		for (std::vector<LevelBlock*>::iterator ite = myobjs.begin(); ite != myobjs.end(); ++ite) {
			Ogre::Vector3 p = (*ite)->getWorldPosition();
			gs.addLevelBlockState(p.x, p.y, p.z, (*ite)->getExtension());
		}
	}

	// save data to archive
    {
        boost::archive::text_oarchive oa(ofs);
        // write class instance to archive
        oa << gs;
    	// archive and stream closed when destructors are called
    }
	std::cout << "Game Saved!" << std::endl;
}