virtual Ogre::GpuProgramPtr generateFragmentShader(Perm permutation)
	{
		/// Create shader
		if (mMasterSource.empty())
		{
			Ogre::DataStreamPtr ptrMasterSource = Ogre::ResourceGroupManager::getSingleton().openResource(
				 "DeferredShading/post/LightMaterial_ps.cg"
				, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
			assert(ptrMasterSource.isNull()==false);
			mMasterSource = ptrMasterSource->getAsString();
		}

		assert(mMasterSource.empty()==false);

		// Create name
		Ogre::String name = mBaseName+Ogre::StringConverter::toString(permutation)+"_ps";		

		// Create shader object
		Ogre::HighLevelGpuProgramPtr ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(
			name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			"cg", Ogre::GPT_FRAGMENT_PROGRAM);
		ptrProgram->setSource(mMasterSource);
		ptrProgram->setParameter("entry_point","main");
	    ptrProgram->setParameter("profiles","ps_2_x arbfp1");
		// set up the preprocessor defines
		// Important to do this before any call to get parameters, i.e. before the program gets loaded
		ptrProgram->setParameter("compile_arguments", getPPDefines(permutation));

		setUpBaseParameters(ptrProgram->getDefaultParameters());

		return Ogre::GpuProgramPtr(ptrProgram);
	}
Esempio n. 2
0
void DataLibrary::appendXmlDate( rapidxml::xml_document<>* currentDoc,std::string fileName, std::string resGroup )
{
	try
	{
		rapidxml::xml_document<> doc;
		Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(fileName, resGroup.c_str(), true);
		std::string ss=stream->getAsString();
		int i=ss.size();
		char* s=new char[i+1];
		ss.copy(s,i);
		s[i]='\0';
		doc.parse<0>(s);

		rapidxml::xml_node<>* srcElement=doc.first_node();
		rapidxml::xml_node<>* destElement=currentDoc->last_node();

		copyElement(srcElement,destElement);

		delete []s;
	}
	catch (rapidxml::parse_error& e)
	{
		Ogre::LogManager::getSingletonPtr()->logMessage(e.what(),Ogre::LML_CRITICAL);
	}
}
Esempio n. 3
0
void DotSceneLoader::parseDotScene(const Ogre::String &SceneName, const Ogre::String &groupName, Ogre::SceneManager *yourSceneMgr, Ogre::SceneNode *pAttachNode, const Ogre::String &sPrependNode)
{
    // set up shared object values
    m_sGroupName = groupName;
    mSceneMgr = yourSceneMgr;
    m_sPrependNode = sPrependNode;
    staticObjects.clear();
    dynamicObjects.clear();

    rapidxml::xml_document<> XMLDoc;    // character type defaults to char

    rapidxml::xml_node<>* XMLRoot;

    Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(SceneName, groupName );
    char* scene = strdup(stream->getAsString().c_str());
    XMLDoc.parse<0>(scene);

    // Grab the scene node
    XMLRoot = XMLDoc.first_node("scene");

    // Validate the File
    if( getAttrib(XMLRoot, "formatVersion", "") == "")
    {
        Ogre::LogManager::getSingleton().logMessage( "[DotSceneLoader] Error: Invalid .scene File. Missing <scene>" );
        return;
    }

    // figure out where to attach any nodes we create
    mAttachNode = pAttachNode;
    if(!mAttachNode)
        mAttachNode = mSceneMgr->getRootSceneNode();

    // Process the scene
    processScene(XMLRoot);
}
Esempio n. 4
0
bool XMLHelper::Load(TiXmlDocument& xmlDoc, Ogre::DataStreamPtr stream)
{
	size_t length(stream->size());

	if ( length )
	{
		// If we have a file, assume it is all one big XML file, and read it in.
		// The document parser may decide the document ends sooner than the entire file, however.
		std::string data(stream->getAsString());

		xmlDoc.Parse( data.c_str());

		if (xmlDoc.Error() ) {
			std::string errorDesc = xmlDoc.ErrorDesc();
			int errorLine =  xmlDoc.ErrorRow();
			int errorColumn =  xmlDoc.ErrorCol();
			std::stringstream ss;
			ss << "Failed to load xml file '" << stream->getName() << "'! Error at column: " << errorColumn << " line: " << errorLine << ". Error message: " << errorDesc;
			S_LOG_FAILURE(ss.str());
			return false;
		} else {
            return true;
		}
	}
	return false;
}
//----------------------------------------------------------------------------//
void OgreResourceProvider::loadRawDataContainer(const String& filename,
                                                RawDataContainer& output,
                                                const String& resourceGroup)
{
    String orpGroup;
    if (resourceGroup.empty())
        orpGroup = d_defaultResourceGroup.empty() ?
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME.c_str() :
            d_defaultResourceGroup;
    else
        orpGroup = resourceGroup;

    Ogre::DataStreamPtr input = Ogre::ResourceGroupManager::getSingleton().
        openResource(filename.c_str(), orpGroup.c_str());

    if (input.isNull())
        CEGUI_THROW(InvalidRequestException(
            "Unable to open resource file '" + filename +
            "' in resource group '" + orpGroup + "'."));

    Ogre::String buf = input->getAsString();
    const size_t memBuffSize = buf.length();

    unsigned char* mem = new unsigned char[memBuffSize];
    memcpy(mem, buf.c_str(), memBuffSize);

    output.setData(mem);
    output.setSize(memBuffSize);
}
Esempio n. 6
0
//Loads and checks the scenefile. then calls parseScene to parse the data.
bool SceneLoader::parseLevel(const Ogre::String &filename,const Ogre::String &group, Ogre::SceneManager *sceneMgr, Ogre::SceneNode *attachNode, PhysicsManager *physicsMgr, Ogre::Terrain* terrain)
{
	//Initialize
	mvpXMLDoc = 0;
	mvpSceneMgr = sceneMgr;
	mvpAttachNode = attachNode;
	mvpPhysicsMgr = physicsMgr;
	TiXmlElement *XMLRoot;
	mvpTerrain = terrain;
	
	try
	{
		//Strip the filename
		Ogre::String basename, path;
		//stripStr(filename, basename, path);
		
		//Fetch the resource to open

		Ogre::DataStreamPtr pStream = Ogre::ResourceGroupManager::getSingleton().openResource(filename);
		//Get the string
		Ogre::String data = pStream->getAsString();

		//Open xmldoc
		mvpXMLDoc = new TiXmlDocument();
		mvpXMLDoc->Parse(data.c_str());

		if( mvpXMLDoc->Error() )
			return false;
		else
			std::cout << filename << " open..." << std::endl;
	}
	catch (...)
	{
		delete mvpXMLDoc;
		return false;		
	}

	// Validate the File as a "Scene" file
	XMLRoot = mvpXMLDoc->RootElement();
	if( Ogre::String( XMLRoot->Value()) != "scene"  ) 
	{
		delete mvpXMLDoc;      
		return false;
	}

	// Check for passed node to attach scene
	if(attachNode == NULL)
	{
		mvpAttachNode = mvpSceneMgr->getRootSceneNode();
	}
	
	//If all is good to here we can begin processing the scene file
	parseScene(XMLRoot);

	return true;
}
	virtual Ogre::GpuProgramPtr generateFragmentShader(Perm permutation)
	{
		/// Create shader
		if (mMasterSource.empty())
		{
			Ogre::DataStreamPtr ptrMasterSource;
            if(Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("glsles"))
                ptrMasterSource = Ogre::ResourceGroupManager::getSingleton().openResource("DeferredShading/post/LightMaterial_ps.glsles",
                                                                                    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
            else
                ptrMasterSource = Ogre::ResourceGroupManager::getSingleton().openResource("DeferredShading/post/LightMaterial_ps.glsl",
                                                                                    Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

			assert(ptrMasterSource.isNull()==false);
			mMasterSource = ptrMasterSource->getAsString();
		}

		assert(mMasterSource.empty()==false);

		// Create name
		Ogre::String name = mBaseName+Ogre::StringConverter::toString(permutation)+"_ps";

		// Create shader object
		Ogre::HighLevelGpuProgramPtr ptrProgram;
        if(Ogre::GpuProgramManager::getSingleton().isSyntaxSupported("glsles"))
        {
            ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                                                  "glsles", Ogre::GPT_FRAGMENT_PROGRAM);
            ptrProgram->setParameter("profiles", "glsles");
        }
        else
        {
            ptrProgram = Ogre::HighLevelGpuProgramManager::getSingleton().createProgram(name, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                                                                  "glsl", Ogre::GPT_FRAGMENT_PROGRAM);
            ptrProgram->setParameter("profiles", "glsl150");
        }
        ptrProgram->setSource(mMasterSource);
		// set up the preprocessor defines
		// Important to do this before any call to get parameters, i.e. before the program gets loaded
		ptrProgram->setParameter("preprocessor_defines", getPPDefines(permutation));

		setUpBaseParameters(ptrProgram->getDefaultParameters());

        // Bind samplers
		Ogre::GpuProgramParametersSharedPtr params = ptrProgram->getDefaultParameters();
        int numSamplers = 0;
        params->setNamedConstant("Tex0", (int)numSamplers++);
        params->setNamedConstant("Tex1", (int)numSamplers++);

        if(permutation & LightMaterialGenerator::MI_SHADOW_CASTER)
            params->setNamedConstant("ShadowTex", (int)numSamplers++);

		return Ogre::GpuProgramPtr(ptrProgram);
	}
Esempio n. 8
0
void AnimationSystem::loadAnimationInfo( const std::string& animationInfoOgreResourceName, const std::string& ogreResourceResourceGroupName )
{
	using namespace tecnofreak::property;

	Ogre::DataStreamPtr dataStream = Ogre::ResourceGroupManager::getSingleton().openResource( animationInfoOgreResourceName, ogreResourceResourceGroupName );
	
	std::string animationInfoData( dataStream->getAsString() );

	Property animationInfo;
	xml::PropertyBuilder::initialiseFromData( &animationInfo, animationInfoData );

	loadAnimationInfo( &animationInfo );
}
void aiBehaviorTreeTemplateManager::LoadAll()
{
	Ogre::StringVectorPtr loc = Ogre::ResourceGroupManager::getSingleton().findResourceLocation("BehaviorTemplate", "*Behaviors");
	const STRING filename = loc->at(0) + "\\Script\\";

	//加载全局黑板xml
	Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource("RaceGlobal.xml", "BehaviorTemplate");
	char* szData = strdup(stream->getAsString().c_str());

	rapidxml::xml_document<> XMLDoc;
	XMLDoc.parse<0>(szData);
	rapidxml::xml_node<>* pNode = XMLDoc.first_node("Root")->first_node("BlackBoard");

	while(pNode)
	{
		const STRING raceName = pNode->first_attribute("race")->value();
		rapidxml::xml_node<>* pVarNode = pNode->first_node("Variable");

		eGameRace race;
		if(raceName == "Terran") race = eGameRace_Terran;
		else if(raceName == "Zerg") race = eGameRace_Zerg;
		else assert(0);

		aiBlackBoard* bb = new aiBlackBoard;
		bb->LoadParams(pVarNode);
		m_globalBBs.insert(std::make_pair(race, bb));

		//脚本
		const char* szFilename = XMLDoc.first_node("Root")->first_node("Script")->first_attribute("filename")->value();
		const STRING filepath = filename + szFilename;
		SCRIPTNAMAGER.DoFile(filepath);

		pNode = pNode->next_sibling("BlackBoard");
	}

	free(szData);
	XMLDoc.clear();

	//加载各单位行为树xml
	Ogre::StringVectorPtr files = Ogre::ResourceGroupManager::getSingleton().findResourceNames("BehaviorTemplate", "*.xml");
	auto iter = std::find(files->begin(), files->end(), "RaceGlobal.xml");
	files->erase(iter);
	for (auto iter=files->begin(); iter!=files->end(); ++iter)
	{
		aiBehaviorTreeTemplate* pTmpl = new aiBehaviorTreeTemplate;
		const STRING name = pTmpl->Load(*iter);
		m_bts.insert(std::make_pair(name, pTmpl));
	}
}
Esempio n. 10
0
bool VehicleRenderable::load(Ogre::String fileName, Ogre::String groupName)
{
	//open resource from exist group if specify group or file does not exist
	Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(fileName, groupName);
	
	//create a tinyXml object by stream
	TinyXml::TiXmlDocument* doc = new TinyXml::TiXmlDocument;
	try
	{
		doc->Parse(stream->getAsString().c_str());
	}
	catch (...)
	{
		Ogre::LogManager::getSingleton().
			logMessage("VehicleRenderable Error : Parse <" + fileName + "> fail!");
		delete doc;
		return false;
	}

	//check if scene file can parse
	Ogre::String str = Ogre::String(doc->RootElement()->Value());
	if (str != "scene")
	{
		Ogre::LogManager::getSingleton().
			logMessage("VehicleRenderable Error : <" + fileName + "> is not a scene file!");
		delete doc;
		return false;
	}

	TinyXml::TiXmlElement* ele;

	// process scene node
	ele = doc->RootElement()->FirstChildElement("nodes");
	if (!loadSceneNodes(ele))
	{
		Ogre::LogManager::getSingleton().
			logMessage("VehicleRenderable Error : errors occurred in parsing nodes!");
		delete doc;
		return false;
	}

	Ogre::LogManager::getSingleton().
		logMessage("VehicleRenderable succeed!");

	delete doc;
	return true;
}
Esempio n. 11
0
/* Loads an XmlDocument from a filename.
 * Requires:
 * 	@filename		The xml filename
 * Returns:
 * 	@doc			The xmlDocument or 0 if error
 */
TiXmlDocument *Util::loadXmlDocument(const char *fname)
{
	ASSERT(fname);
	TiXmlDocument   *XMLDoc = 0;

	try
	{
		// Strip the path
		Ogre::String basename, path;
		Ogre::StringUtil::splitFilename(fname, basename, path);

		// we will hardcode the groupName
		Ogre::DataStreamPtr pStream = Ogre::ResourceGroupManager::getSingleton().
			openResource( basename, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);

		//DataStreamPtr pStream = ResourceGroupManager::getSingleton().
		//    openResource( SceneName, groupName );

		Ogre::String data = pStream->getAsString();

		// Open the .scene File
		XMLDoc = new TiXmlDocument();
		XMLDoc->Parse( data.c_str() );

		pStream->close();
		pStream.setNull();

		if( XMLDoc->Error() )
		{
			//We'll just log, and continue on gracefully
			debug("Couldn't load the %s xml\n", fname);
			delete XMLDoc;
			return 0;
		}
	}
	catch(...)
	{
		//We'll just log, and continue on gracefully
		debug("Error creating TiXmlDocument for %s\n", fname);
		delete XMLDoc;
		return 0;
	}

	// Close the XML File
	return XMLDoc;
}
Esempio n. 12
0
//----------------------------------------------------------------------------------
bool  UILayout::loadLayoutFile(const Ogre::String& fileName)
{
	Ogre::DataStreamPtr stream ;
	try
	{

		stream = Ogre::ResourceGroupManager::getSingleton().openResource(fileName, "UI");
	}
	catch(...)
	{

		Ogre::LogManager::getSingleton().logMessage("UIBase::loadLayoutFile error,file name is "+fileName);
		return false;
	}


	rapidxml::xml_document<> XMLDoc;    // character type defaults to char
	rapidxml::xml_node<>* XMLRoot=NULL;

	char* scene = strdup(stream->getAsString().c_str());
	XMLDoc.parse<0>(scene);


	XMLRoot=XMLDoc.first_node("GUILayout");
	if(XMLRoot==NULL)
	{
		Ogre::LogManager::getSingleton().logMessage( "UIBase::loadLayoutFile error,is not layout format" );
		return false;

	}




	XMLRoot = XMLRoot->first_node("Window");
	if( XMLRoot==NULL)
	{
		Ogre::LogManager::getSingleton().logMessage( "UIBase::loadLayoutFile error,can't find Window node" );
		return false;
	}

	return 	processRootWindow(XMLRoot);

}
Esempio n. 13
0
void Level::parseLevelFile(const Ogre::String &FileName, const Ogre::String &groupName, Ogre::SceneManager *sceneMgr, Ogre::SceneNode *AttachNode, const Ogre::String &prependNode)
{
	mGroupName = groupName;
	mSceneMgr = sceneMgr;
	mPrependNode = prependNode;

	TiXmlDocument *mXMLDoc = 0;
	TiXmlElement *mXMLRoot = 0;

	try
	{
		Ogre::String basename, path;
		Ogre::StringUtil::splitFilename(FileName, basename, path);

		Ogre::DataStreamPtr spStream = Ogre::ResourceGroupManager::getSingleton().openResource(basename,groupName);

		Ogre::String data = spStream->getAsString();

		mXMLDoc = new TiXmlDocument();
		mXMLDoc->Parse(data.c_str());

		spStream->close();
		spStream.setNull();

		mXMLRoot = mXMLDoc->RootElement();

		mAttachNode = AttachNode;


		if(!mAttachNode)
			mAttachNode = mSceneMgr->getRootSceneNode();

		parseScene(mXMLRoot);

		delete mXMLDoc;
	}
	catch(Ogre::Exception e)
	{
		Ogre::LogManager::getSingleton().logMessage("Level failed to load");
		delete mXMLDoc;
	}
}
Esempio n. 14
0
void GameScriptParser::parseScript(const Ogre::String &sFileName, const Ogre::String &sResourceGroupName) {
    m_sFileName = sFileName;
    m_sResourceGroupName = sResourceGroupName;
    clearIdMap();
    setWaitFor(PauseData::WAIT_DISABLED, Ogre::StringUtil::BLANK);

    // Strip the path
    Ogre::String basename, path;
    Ogre::StringUtil::splitFilename(sFileName, basename, path);

    Ogre::DataStreamPtr pStream = Ogre::ResourceGroupManager::getSingleton().openResource(basename, sResourceGroupName, false);
    Ogre::String data = pStream->getAsString();

    int status = luaL_loadstring(lua_state, data.c_str());
    int result = 0;
    if(status == LUA_OK) {
        result = lua_pcall(lua_state, 0, LUA_MULTRET, 0);
    }
    else {
        throw Ogre::Exception(__LINE__, "Could not load the lua script", __FILE__);
    }
}
Esempio n. 15
0
int createLuaScript(lua_State *l) {
    Ogre::String sLuaScript = lua_tostring(l, 1);
    Ogre::String sResourceGroup = GameScriptParser::getSingleton().getResourceGroupName();
    Ogre::LogManager::getSingleton().logMessage("Parsing lua script: " + sLuaScript + " in " + sResourceGroup);

    lua_State *pNewLuaState = luaL_newstate();

    // load Lua libraries
    static const luaL_Reg lualibs[] =
    {
        {"base", luaopen_base},
        {"io", luaopen_io},
        {NULL, NULL}
    };
    const luaL_Reg *lib = lualibs;
    for(; lib->func != NULL; lib++)
    {
        luaL_requiref(pNewLuaState, lib->name, lib->func, 1);
        lua_settop(pNewLuaState, 0);
    }
    // Strip the path
    Ogre::String basename, path;
    Ogre::StringUtil::splitFilename(sLuaScript, basename, path);

    Ogre::DataStreamPtr pStream = Ogre::ResourceGroupManager::getSingleton().openResource(basename, sResourceGroup, false);
    Ogre::String data = pStream->getAsString();

    int status = luaL_loadstring(pNewLuaState, data.c_str());
    int result = 0;
    if(status == LUA_OK) {
        result = lua_pcall(pNewLuaState, 0, LUA_MULTRET, 0);
    }
    else {
        throw Ogre::Exception(__LINE__, "Could not load the lua script", __FILE__);
    }

    lua_pushinteger(l, GameScriptParser::getSingleton().addPointerToMap(pNewLuaState, GameScriptParser::UserPointerData::LUA_STATE));
    return 1;
}
Esempio n. 16
0
bool openXMLDocument(const gkString& fileName, TiXmlDocument &XMLDoc, const gkString& resGroupName)
{
	try
	{
		//open from file
		if (!Ogre::ResourceGroupManager::getSingletonPtr())
			return openXMLDocumentOnFile(fileName, XMLDoc);

		//open from resource

		// Strip the path
		gkString basename, path;
		Ogre::StringUtil::splitFilename(fileName, basename, path);

		Ogre::DataStreamPtr pStream = Ogre::ResourceGroupManager::getSingleton().
			openResource( basename, resGroupName );

		gkString data = pStream->getAsString();
		// Open the .scene File
		
		XMLDoc.Parse( data.c_str() );
		pStream->close();
		pStream.setNull();

		if (XMLDoc.Error())
		{			
			gkPrintf("[XML] Error - The TiXmlDocument reported an error: %s", XMLDoc.ErrorDesc());
			return false;
		}
	} 
	catch(Ogre::Exception &e) 
	{		
		gkPrintf("[XML] Error - creating TiXmlDocument %s %s", fileName.c_str(), e.getDescription().c_str());
		return false;
	}

	return true;
}
Esempio n. 17
0
DotSceneLoader::DotSceneLoader()
:
#ifdef USE_OGRE_TERRAIN
	mSceneMgr(0), mTerrainGroup(0) {
	mTerrainGlobalOptions = OGRE_NEW Ogre::TerrainGlobalOptions();
#else
	mSceneMgr(0) {
#endif
}

DotSceneLoader::~DotSceneLoader() {
#ifdef USE_OGRE_TERRAIN
	if (mTerrainGroup) {
		OGRE_DELETE mTerrainGroup;
	}

	OGRE_DELETE mTerrainGlobalOptions;
#endif
}

	/*
void ParseStringVector(
		const Ogre::String &str,
		const Ogre::StringVector &list
	) {
	list.clear();
	Ogre::StringUtil::trim(str, true, true);
	if (str == "")
		return;

	int pos = str.find(";");
	while (pos != -1) {
		list.push_back(str.substr(0, pos));
		str.erase(0, pos + 1);
		pos = str.find(";");
	}

	if (str != "")
		list.push_back(str);
}
		*/

void DotSceneLoader::parseDotScene(const Ogre::String &SceneName,
		const Ogre::String &groupName, Ogre::SceneManager *yourSceneMgr,
		Ogre::SceneNode *pAttachNode, const Ogre::String &sPrependNode) {
	// set up shared object values
	m_sGroupName = groupName;
	mSceneMgr = yourSceneMgr;
	m_sPrependNode = sPrependNode;
	staticObjects.clear();
	dynamicObjects.clear();

	// character type defaults to char
	rapidxml::xml_document<> XMLDoc;

	rapidxml::xml_node<>* XMLRoot;

	Ogre::DataStreamPtr stream =
			Ogre::ResourceGroupManager::getSingleton().openResource(SceneName,
					groupName);
	char* scene = strdup(stream->getAsString().c_str());
	XMLDoc.parse<0> (scene);

	// Grab the scene node
	XMLRoot = XMLDoc.first_node("scene");

	// figure out where to attach any nodes we create
	mAttachNode = pAttachNode;
	if (!mAttachNode)
		mAttachNode = mSceneMgr->getRootSceneNode();

	// Process the scene
	processScene(XMLRoot);

	delete scene;
}
Esempio n. 18
0
void LogFileSerializer::importTextFile(Ogre::DataStreamPtr &stream, LogFile *pDest)
{
    pDest->setTextPages(pageWrap(wordWrap(stream->getAsString(),94),22));
}