当前位置: 首页>>代码示例>>C++>>正文


C++ Level::SerializeToOstream方法代码示例

本文整理汇总了C++中Level::SerializeToOstream方法的典型用法代码示例。如果您正苦于以下问题:C++ Level::SerializeToOstream方法的具体用法?C++ Level::SerializeToOstream怎么用?C++ Level::SerializeToOstream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Level的用法示例。


在下文中一共展示了Level::SerializeToOstream方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SaveLevel

void GameState_BasePlayable::SaveLevel (std::string levelPath, std::string levlistFilePath) {
	GOOGLE_PROTOBUF_VERIFY_VERSION;

	Level level;

	// SAVE DATA ===
	level.set_levelname(levelName);

	Level_Vector2D* plLevelSize = level.mutable_levelsize();
	plLevelSize->set_x(levelSize.x);
	plLevelSize->set_y(levelSize.y);

	if (objectives[0] != 0) {
		Level_WorldObj* plMission1st = level.mutable_mission1st();

		plMission1st->set_type(ConvertType(objectives[0]->entityType));

		// redundant save - not using it..this is just a reference
		Level_Vector2D* plMission1stPos = plMission1st->mutable_pos();
		plMission1stPos->set_x(objectives[0]->GetPosition().x);
		plMission1stPos->set_y(objectives[0]->GetPosition().y);
	}
	if (objectives[1] != 0) {
		Level_WorldObj* plMission2nd = level.mutable_mission2nd();

		plMission2nd->set_type(ConvertType(objectives[1]->entityType));

		Level_Vector2D* plMission2ndPos = plMission2nd->mutable_pos();
		plMission2ndPos->set_x(objectives[1]->GetPosition().x);
		plMission2ndPos->set_y(objectives[1]->GetPosition().y);
	}

	const EntityMap& guards = (*GameObjects)[ID_GUARD];
	for (EntityMap::const_iterator itG = guards.begin(); itG != guards.end(); itG++) {
		Level_Guard* plGuard = level.add_guards();

		Level_Vector2D* plGuardPos = plGuard->mutable_pos();
		plGuardPos->set_x(itG->second->GetPosition().x);
		plGuardPos->set_y(itG->second->GetPosition().y);

		std::deque<sf::Vector2i*>& wayPoints = dynamic_cast<Guard*>(itG->second)->GetWayPoints();
		for (std::deque<sf::Vector2i*>::iterator itWP = wayPoints.begin(); itWP != wayPoints.end(); itWP++) {
			Level_Vector2D* plWayPoint = plGuard->add_waypoints();
			plWayPoint->set_x((*itWP)->x);
			plWayPoint->set_y((*itWP)->y);
		}
	}

	SaveStuff(ID_ROCKWALL, level);
	SaveStuff(ID_ROCK01, level);
	SaveStuff(ID_ROCK02, level);
	SaveStuff(ID_BUSH, level);
	SaveStuff(ID_PINE, level);
	SaveStuff(ID_ROOF, level);
	SaveStuff(ID_ROAD, level);
	SaveStuff(ID_COIN, level);

	if (player) SaveStuff(player, level);

	// there are might be more "illegaly" as the screensprites have the same 'entityType'
	if (princess) SaveStuff(princess, level);
	if (chest) SaveStuff(chest, level);

//	if (goal) SaveStuff(goal, level);
	const EntityMap& entities = GameObjects->GetEntityMap(ID_GOAL);
	for (EntityMap::const_iterator itE = entities.begin(); itE != entities.end(); ++itE) {
		if (dynamic_cast<Goal*>(itE->second)) SaveStuff(itE->second, level);
	}

	NavMap* navMap = Nav->GetNavMap();
	if (navMap) {
		for (NavMap::iterator itN = navMap->begin(); itN != navMap->end(); itN++) {
			Level_NavMapNode* plNavMapNode = level.add_navmapnodes();

			Level_Vector2D* plNavMapNodePosition = plNavMapNode->mutable_position();
			plNavMapNodePosition->set_x(itN->first.x);
			plNavMapNodePosition->set_y(itN->first.y);

			for (std::deque<sf::Vector2i>::iterator itA = itN->second.begin();
					itA != itN->second.end(); ++itA) {
				Level_Vector2D* plAdjPos = plNavMapNode->add_adjacentpositions();

				plAdjPos->set_x((*itA).x);
				plAdjPos->set_y((*itA).y);
			}
		}
	}
	else level.clear_navmapnodes();
	// === SAVE DATA

//	if (!level.IsInitialized()) {
////std::cout << "not all required fields were set" << std::endl;
//		google::protobuf::ShutdownProtobufLibrary();
//		return;
//	}

	bool failed = false;
	std::fstream levelFile(levelPath.c_str(), std::ios::out | std::ios::trunc | std::ios::binary);
	if (levelFile.is_open()) {
		if (!level.SerializeToOstream(&levelFile)) {
//.........这里部分代码省略.........
开发者ID:matyicsapo,项目名称:Infiltrator,代码行数:101,代码来源:GameState_BasePlayable.cpp


注:本文中的Level::SerializeToOstream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。