Example #1
0
void Bundle::loadFromDisk() {
	std::ifstream file;
	GetBundleFileHandleForReading(this->bundleName, file);

	if (file.good()) {
		XmlParser* parser = new XmlParser();
		parser->ParseXmlFile(file);

		XmlTree* tree = parser->GetXmlTree();
		VERIFY(tree != nullptr, "Got xml tree for bundle data in bundle %s", this->bundleName.c_str());

		XmlNode* rootNode = tree->GetRootNode();
		VERIFY(rootNode != nullptr, "Got root node for bundle data in bundle %s", this->bundleName.c_str());
		VERIFY(rootNode->GetName() == BUNDLE_TAG, "Got bundle node for bundle data in bundle %s", this->bundleName.c_str());

		XmlNode* dataNode = rootNode->GetFirstChildByNodeName(DATA_TAG);
		while(dataNode != nullptr) {
			std::string key   = dataNode->GetAttributeValueS(KEY_ATTRIBUTE);
			std::string value = dataNode->GetAttributeValueS(VALUE_ATTRIBUTE);
			this->PutString(key, value);
			//
			dataNode = dataNode->GetNextSiblingByNodeName(DATA_TAG);
		}

		delete parser;
	}
}
Example #2
0
void LevelLoader::loadOtherDataFromXml(XmlNode* otherDataNode) {
	XmlNode* dynamicObjNode = otherDataNode->GetFirstChildByNodeName(DYNAMIC_OBJECT_TAG);
	while (dynamicObjNode != nullptr) {
		int objXmlId       = dynamicObjNode->GetAttributeValueI(ID_ATTRIBUTE);
		std::string prefab = dynamicObjNode->GetAttributeValueS(PREFAB_ATTRIBUTE);
		int xGridPosition  = dynamicObjNode->GetAttributeValueI(X_ATTRIBUTE);
		float yPosition    = dynamicObjNode->GetAttributeValueF(Y_ATTRIBUTE);
		int zGridPosition  = dynamicObjNode->GetAttributeValueI(Z_ATTRIBUTE);
		float rotation     = dynamicObjNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians;

		GameObject* dynamicObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + prefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D());
		idsFromXml[objXmlId] = dynamicObj->GetId();

		// Position and orient the object
		dynamicObj->GetTransform()->SetPosition(xGridPosition, yPosition, -zGridPosition);
		dynamicObj->GetTransform()->SetOrientation(rotation, YAXIS);

		// Check for overloaded components
		XmlNode* compNode = dynamicObjNode->GetFirstChildByNodeName(COMPONENT_TAG);
		while (compNode != nullptr) {
			PrefabLoader::LoadComponentFromComponentNodeInPrefab(dynamicObj, compNode);
			compNode = compNode->GetNextSiblingByNodeName(COMPONENT_TAG);
		}

		GridZone* zone = dynamicObj->GetComponent<GridZone>();
		if (zone != nullptr) {
			SINGLETONS->GetGridManager()->placeZoneOnGrid(dynamicObj->GetId());//GetGrid()->AddGridZone(dynamicObj->GetId());
		}

		dynamicObjNode = dynamicObjNode->GetNextSiblingByNodeName(DYNAMIC_OBJECT_TAG);
	}

	// TODO [Implement] Other things such as triggerables
}
Example #3
0
void LevelLoader::loadUnitDataFromXml(XmlNode* unitBaseNode) {
	// Start with player units
	XmlNode* unitNode = unitBaseNode->GetFirstChildByNodeName("");
	while (unitNode != nullptr) {
		int unitXmlId          = unitNode->GetAttributeValueI(ID_ATTRIBUTE);
		std::string unitPrefab = unitNode->GetAttributeValueS(PREFAB_ATTRIBUTE);
		GameObject* unitObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + unitPrefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D());
		idsFromXml[unitXmlId] = unitObj->GetId();

		// Units require a GridNavigator component
		GridNavigator* gNav = unitObj->GetComponent<GridNavigator>();
		ASSERT(gNav != nullptr, "Unit with id %d has GridNavigator component", unitObj->GetId());

		// Read the initial position of the unit
		int gX = unitNode->GetAttributeValueI(X_ATTRIBUTE);
		int gZ = unitNode->GetAttributeValueI(Z_ATTRIBUTE);
		float rotation = unitNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians;

		// Add the unit to the grid
		SINGLETONS->GetGridManager()->placeUnitOnGrid(unitObj->GetId(), gX, gZ);

		// Orient the unit.
		unitObj->GetTransform()->SetOrientation(rotation, YAXIS);

		// Check unit type
		if (unitNode->GetName() == ENEMY_UNIT_TAG) {
			EnemyUnit* enemyUnit = unitObj->GetComponent<EnemyUnit>();
			ASSERT(enemyUnit != nullptr, "Enemy unit with id %d has EnemyUnit component", unitObj->GetId());
			enemyUnit->Activate();

			AiPerception* aiPerception = unitObj->GetComponent<AiPerception>();
			ASSERT(aiPerception != nullptr, "Enemy unit with id %d has AiPerception component", unitObj->GetId());
			aiPerception->Activate();

			AiRoutine* aiRoutine = unitObj->GetComponent<AiRoutine>();
			ASSERT(aiRoutine != nullptr, "Enemy unit with id %d has AiRoutine component", unitObj->GetId());

			// Load the AI routine.
			XmlNode* aiCommandNode = unitNode->GetFirstChildByNodeName(AI_COMMAND_TAG);
			std::vector<std::string> commands;
			while (aiCommandNode != nullptr) {
				std::string command = aiCommandNode->GetValue();
				commands.push_back(command);
				aiCommandNode = aiCommandNode->GetNextSiblingByNodeName(AI_COMMAND_TAG);
			}
			aiRoutine->SetBehavior(commands);
		}

		GridZone* zone = unitObj->GetComponent<GridZone>();
		if (zone != nullptr) {
			SINGLETONS->GetGridManager()->placeZoneOnGrid(unitObj->GetId());//GetGrid()->AddGridZone(dynamicObj->GetId());
		}

		unitNode = unitNode->GetNextSiblingByNodeName("");
	}
}
Example #4
0
void LevelLoader::loadStaticDataFromXml(XmlNode* staticNode) {
	XmlNode* staticObjNode = staticNode->GetFirstChildByNodeName(STATIC_OBJECT_TAG);
	while (staticObjNode != nullptr) {
		int objXmlId       = staticObjNode->GetAttributeValueI(ID_ATTRIBUTE);
		std::string prefab = staticObjNode->GetAttributeValueS(PREFAB_ATTRIBUTE);
		int westBound      = staticObjNode->GetAttributeValueI(X_ATTRIBUTE);
		float yPosition    = staticObjNode->GetAttributeValueF(Y_ATTRIBUTE);
		int southBound     = staticObjNode->GetAttributeValueI(Z_ATTRIBUTE);
		int objWidth       = staticObjNode->GetAttributeValueI(WIDTH_ATTRIBUTE);
		int objHeight      = staticObjNode->GetAttributeValueI(HEIGHT_ATTRIBUTE);
		float rotation     = staticObjNode->GetAttributeValueF(ROTATION_ATTRIBUTE) inRadians;

		GameObject* staticObj = PrefabLoader::InstantiateGameObjectFromPrefab(FRAMEWORK->GetFileSystemUtils()->GetDevicePrefabsResourcesPath() + prefab + PREFAB_EXTENSION, ENGINE->GetSceneGraph3D());
		idsFromXml[objXmlId] = staticObj->GetId();

		// Add the object to the grid
		SINGLETONS->GetGridManager()->placeStaticObjectOnGrid(staticObj->GetId(), westBound, southBound, objWidth, objHeight);

		staticObj->GetTransform()->Translate(yPosition, YAXIS);
		staticObj->GetTransform()->SetOrientation(rotation, YAXIS);

		staticObjNode = staticObjNode->GetNextSiblingByNodeName(STATIC_OBJECT_TAG);
	}
}
Example #5
0
void LevelLoader::LoadLevelFromFile(std::string levelFilename) {
	FRAMEWORK->GetLogger()->dbglog("\nLoading level from level file: %s", levelFilename.c_str());

	XmlParser* parser = new XmlParser();
	parser->ParseXmlFile(FRAMEWORK->GetFileSystemUtils()->GetDeviceBaseResourcesPath() + "levels/" + levelFilename);

#ifdef DEBUG
	parser->Print();
#endif // DEBUG

	XmlTree* xmlTree = parser->GetXmlTree();
	ASSERT(xmlTree != nullptr, "Got valid xmlTree from parser for level file %s", levelFilename.c_str());
	XmlNode* levelNode = xmlTree->GetRootNode();
	ASSERT(levelNode != nullptr && levelNode->GetName() == LEVEL_TAG, "Got valid level node from xml tree for level file %s", levelFilename.c_str());
	
	std::string bgm = levelNode->GetAttributeValueS(BGM_ATTRIBUTE);
	if (bgm != "") {
		AudioSource* bgmSource = SINGLETONS->GetMenuManager()->GetBGMSource();
		bgmSource->LoadAudioClip(LEVEL_BGM, "audio/" + bgm);
	}

	XmlNode* gridNode = levelNode->GetFirstChildByNodeName(GRID_TAG);
	VERIFY(gridNode != nullptr, "Level definition contains <%s> node", GRID_TAG);
	SINGLETONS->GetGridManager()->loadGridDataFromXml(gridNode);

	// Create the shady camera before we load any objects because their AudioSource components will need it
	createCamera();

	XmlNode* staticNode = levelNode->GetFirstChildByNodeName(STATIC_TAG);
	// The level doesn't need to have a STATIC_TAG node
	if (staticNode != nullptr) {
		loadStaticDataFromXml(staticNode);
	}

	XmlNode* otherDataNode = levelNode->GetFirstChildByNodeName(OTHER_TAG);
	// The level doesn't need to have an OTHER_TAG node
	if (otherDataNode != nullptr) {
		loadOtherDataFromXml(otherDataNode);
	}

	XmlNode* unitBaseNode = levelNode->GetFirstChildByNodeName(UNITS_TAG);
	VERIFY(unitBaseNode != nullptr, "Level definition contains <%s> node", UNITS_TAG);
	loadUnitDataFromXml(unitBaseNode);

	XmlNode* linkBaseNode = levelNode->GetFirstChildByNodeName(LINKS_TAG);
	VERIFY(linkBaseNode != nullptr, "Level definition contains <%s> node", LINKS_TAG);
	if (linkBaseNode != nullptr) {
		loadLinkDataFromXml(linkBaseNode);
		loadParentConnectionsFromXml(linkBaseNode);
		loadEndConditionsFromXml(linkBaseNode);
	}

	XmlNode* cameraNode = levelNode->GetFirstChildByNodeName(CAMERA_TAG);
	VERIFY(cameraNode != nullptr, "Level definition contains <%s> node", CAMERA_TAG);
	loadCameraDataFromXml(cameraNode);

	delete parser;

	SINGLETONS->GetMenuManager()->PlayBGM(LEVEL_BGM);

	idsFromXml.clear();
	
	LevelLoader::adjustLighting();

	LevelLoader::postLoadLevel();
}