예제 #1
0
void TerrainManager::loadTerrainConfigBasics(Ogre::DataStreamPtr &ds)
{
	// now generate the hash of it
	generateHashFromDataStream(ds, file_hash);

	m_terrain_config.load(ds, "\t:=", true);

	// read in the settings
	terrain_name = m_terrain_config.getSetting("Name", "General");
	if (terrain_name.empty())
	{
		ErrorUtils::ShowError(_L("Terrain loading error"), _L("the terrain name cannot be empty"));
		exit(125);
	}

	ogre_terrain_config_filename = m_terrain_config.getSetting("GeometryConfig", "General");
	// otc = ogre terrain config
	if (ogre_terrain_config_filename.find(".otc") == String::npos)
	{
		ErrorUtils::ShowError(_L("Terrain loading error"), _L("the new terrain mode only supports .otc configurations"));
		exit(125);
	}

	ambient_color = StringConverter::parseColourValue(m_terrain_config.getSetting("AmbientColor", "General"), ColourValue::White);
	category_id = StringConverter::parseInt(m_terrain_config.getSetting("CategoryID", "General"), 129);
	guid = m_terrain_config.getSetting("GUID", "General");
	start_position = StringConverter::parseVector3(m_terrain_config.getSetting("StartPosition", "General"), Vector3(512.0f, 0.0f, 512.0f));
	version = StringConverter::parseInt(m_terrain_config.getSetting("Version", "General"), 1);
	gravity = StringConverter::parseReal(m_terrain_config.getSetting("Gravity", "General"), -9.81);

	// parse author info
	ConfigFile::SettingsIterator it = m_terrain_config.getSettingsIterator("Authors");

	authors.clear();

	while (it.hasMoreElements())
	{
		String type = it.peekNextKey();   // e.g. terrain
		String name = it.peekNextValue(); // e.g. john doe

		if (!name.empty())
		{
			authorinfo_t author;

			author.type = type;
			author.name = name;

			authors.push_back(author);
		}

		it.moveNext();
	}
}
예제 #2
0
void TerrainManager::loadTerrainObjects()
{
	try
	{
		ConfigFile::SettingsIterator objectsIterator = m_terrain_config.getSettingsIterator("Objects");

		while (objectsIterator.hasMoreElements())
		{
			String sname = objectsIterator.peekNextKey();
			StringUtil::trim(sname);

			object_manager->loadObjectConfigFile(sname);
			objectsIterator.moveNext();
		}
	} catch(...)
	{
		// no objects found
	}

	// bakes the geometry and things
	object_manager->postLoad();
}
예제 #3
0
void TerrainManager::initScripting()
{
#ifdef USE_ANGELSCRIPT
	bool loaded = false;

	// only load terrain scripts while not in multiplayer
	if (!gEnv->network)
	{
		try
		{
			ConfigFile::SettingsIterator objectsIterator = m_terrain_config.getSettingsIterator("Scripts");
			while (objectsIterator.hasMoreElements())
			{
				String sname = objectsIterator.peekNextKey();
				StringUtil::trim(sname);
				String svalue = objectsIterator.getNext();
				StringUtil::trim(svalue);

				if(!ScriptEngine::getSingleton().loadScript(sname))
					loaded = true;
			}
		} catch(...)
		{
			// simply no script section
			//LOG("Exception while trying load script: " + e.getFullDescription());
		}
	}
	
	if (!loaded)
	{
		// load a default script that does the most basic things
		ScriptEngine::getSingleton().loadScript("default.as");
	}
	// finally activate AS logging, so we dont spam the users screen with initialization messages
	ScriptEngine::getSingleton().activateLogging();
#endif //USE_ANGELSCRIPT
}
예제 #4
0
void Settings::loadSettings(String configFile, bool overwrite)
{
	//printf("trying to load configfile: %s...\n", configFile.c_str());
	ConfigFile cfg;
	cfg.load(configFile, "=:\t", false);

	// load all settings into a map!
	ConfigFile::SettingsIterator i = cfg.getSettingsIterator();
	String svalue, sname;
	while (i.hasMoreElements())
	{
		sname = i.peekNextKey();
		svalue = i.getNext();
		if (!overwrite && settings[sname] != "") continue;
		settings[sname] = svalue;
		//logfile->AddLine(conv("### ") + conv(sname) + conv(" : ") + conv(svalue));logfile->Write();
	}
	// add a GUID if not there
	checkGUID();
	generateBinaryHash();

#ifndef NOOGRE
	// generate hash of the token
	String usertoken = SSETTING("User Token", "");
	char usertokensha1result[250];
	memset(usertokensha1result, 0, 250);
	if (usertoken.size()>0)
	{
		RoR::CSHA1 sha1;
		sha1.UpdateHash((uint8_t *)usertoken.c_str(), (uint32_t)usertoken.size());
		sha1.Final();
		sha1.ReportHash(usertokensha1result, RoR::CSHA1::REPORT_HEX_SHORT);
	}

	setSetting("User Token Hash", String(usertokensha1result));
#endif // NOOGRE
}
예제 #5
0
    //-----------------------------------------------------------------------
    RenderWindow* Root::initialise(bool autoCreateWindow, const String& windowTitle, const String& customCapabilitiesConfig)
    {
        if (!mActiveRenderer)
            OGRE_EXCEPT(Exception::ERR_INVALID_STATE,
            "Cannot initialise - no render "
            "system has been selected.", "Root::initialise");

        if (!mControllerManager)
			mControllerManager = OGRE_NEW ControllerManager();

        // .rendercaps manager
        RenderSystemCapabilitiesManager& rscManager = RenderSystemCapabilitiesManager::getSingleton();
        // caller wants to load custom RenderSystemCapabilities form a config file
        if(customCapabilitiesConfig != StringUtil::BLANK)
        {
            ConfigFile cfg;
            cfg.load(customCapabilitiesConfig, "\t:=", false);

            // Capabilities Database setting must be in the same format as
            // resources.cfg in Ogre examples.
            ConfigFile::SettingsIterator iter = cfg.getSettingsIterator("Capabilities Database");
            while(iter.hasMoreElements())
            {
                String archType = iter.peekNextKey();
                String filename = iter.getNext();

                rscManager.parseCapabilitiesFromArchive(filename, archType, true);
            }

            String capsName = cfg.getSetting("Custom Capabilities");
            // The custom capabilities have been parsed, let's retrieve them
            RenderSystemCapabilities* rsc = rscManager.loadParsedCapabilities(capsName);
			if(rsc == 0)
			{
				OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND,
					String("Cannot load a RenderSystemCapability named ") + capsName,
					"Root::initialise");
			}

            // Tell RenderSystem to use the comon rsc
            useCustomRenderSystemCapabilities(rsc);
        }


		PlatformInformation::log(LogManager::getSingleton().getDefaultLog());
		mAutoWindow =  mActiveRenderer->_initialise(autoCreateWindow, windowTitle);


        if (autoCreateWindow && !mFirstTimePostWindowInit)
        {
            oneTimePostWindowInit();
            mAutoWindow->_setPrimary();
        }

        // Initialise timer
        mTimer->reset();

		// Init pools
		ConvexBody::_initialisePool();

		mIsInitialised = true;

        return mAutoWindow;

    }
    //-------------------------------------------------------------------------
    void TerrainSceneManager::loadConfig(DataStreamPtr& stream)
    {
        /* Set up the options */
        ConfigFile config;
        String val;

        config.load( stream );

        val = config.getSetting( "DetailTile" );
        if ( !val.empty() )
            setDetailTextureRepeat(atoi(val.c_str()));

        val = config.getSetting( "MaxMipMapLevel" );
        if ( !val.empty() )
            setMaxGeoMipMapLevel(atoi( val.c_str() ));


        val = config.getSetting( "PageSize" );
        if ( !val.empty() )
            setPageSize(atoi( val.c_str() ));
        else
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'PageSize'",
            "TerrainSceneManager::loadConfig");


        val = config.getSetting( "TileSize" );
        if ( !val.empty() )
            setTileSize(atoi( val.c_str() ));
        else
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'TileSize'",
            "TerrainSceneManager::loadConfig");

        Vector3 v = Vector3::UNIT_SCALE;

        val = config.getSetting( "PageWorldX" );
        if ( !val.empty() )
            v.x = atof( val.c_str() );

        val = config.getSetting( "MaxHeight" );
        if ( !val.empty() )
            v.y = atof( val.c_str() );

        val = config.getSetting( "PageWorldZ" );
        if ( !val.empty() )
            v.z = atof( val.c_str() );

        // Scale x/z relative to pagesize
        v.x /= mOptions.pageSize - 1;
        v.z /= mOptions.pageSize - 1;
        setScale(v);

        val = config.getSetting( "MaxPixelError" );
        if ( !val.empty() )
            setMaxPixelError(atoi( val.c_str() ));

        mDetailTextureName = config.getSetting( "DetailTexture" );

        mWorldTextureName = config.getSetting( "WorldTexture" );

        if ( config.getSetting( "VertexColours" ) == "yes" )
            mOptions.coloured = true;

        if ( config.getSetting( "VertexNormals" ) == "yes" )
            mOptions.lit = true;

        if ( config.getSetting( "UseTriStrips" ) == "yes" )
            setUseTriStrips(true);

        if ( config.getSetting( "VertexProgramMorph" ) == "yes" )
            setUseLODMorph(true);

        val = config.getSetting( "LODMorphStart");
        if ( !val.empty() )
            setLODMorphStart(atof(val.c_str()));

        val = config.getSetting( "CustomMaterialName" );
        if ( !val.empty() )
            setCustomMaterial(val);

        val = config.getSetting( "MorphLODFactorParamName" );
        if ( !val.empty() )
            setCustomMaterialMorphFactorParam(val);

        val = config.getSetting( "MorphLODFactorParamIndex" );
        if ( !val.empty() )
            setCustomMaterialMorphFactorParam(atoi(val.c_str()));

        // Now scan through the remaining settings, looking for any PageSource
        // prefixed items
        String pageSourceName = config.getSetting("PageSource");
        if (pageSourceName == "")
        {
            OGRE_EXCEPT(Exception::ERR_ITEM_NOT_FOUND, "Missing option 'PageSource'",
            "TerrainSceneManager::loadConfig");
        }
        TerrainPageSourceOptionList optlist;
        ConfigFile::SettingsIterator setIt = config.getSettingsIterator();
        while (setIt.hasMoreElements())
        {
            String name = setIt.peekNextKey();
            String value = setIt.getNext();
            if (StringUtil::startsWith(name, pageSourceName, false))
            {
                optlist.push_back(TerrainPageSourceOption(name, value));
            }
        }
        // set the page source
        selectPageSource(pageSourceName, optlist);


    }