void loadSettings() { Ogre::ConfigFile cfg; if (Util::pathExists(SETTINGS_FILE)) cfg.loadDirect(SETTINGS_FILE); else cfg.loadDirect(DEFAULT_SETTINGS_FILE); //--- Ogre ------------------------------------------------------------------------- GlbVar.settings.ogre.pluginDirectory = cfg.getSetting("pluginDirectory", "ogre", "."); GlbVar.settings.ogre.plugins = Ogre::StringConverter::parseStringVector( cfg.getSetting("plugins", "ogre", "Plugin_CgProgramManager Plugin_ParticleFX Plugin_OctreeSceneManager") ); GlbVar.settings.ogre.renderer = cfg.getSetting("renderer", "ogre", "OpenGL") == "Direct3D" ? Globals::Settings::OgreSettings::DIRECT3D : Globals::Settings::OgreSettings::OPENGL; GlbVar.settings.ogre.winWidth = Ogre::StringConverter::parseReal(cfg.getSetting("width", "ogre", "1024")); GlbVar.settings.ogre.winHeight = Ogre::StringConverter::parseReal(cfg.getSetting("height", "ogre", "768")); GlbVar.settings.ogre.winFullscreen = Ogre::StringConverter::parseBool(cfg.getSetting("fullscreen", "ogre", "no")); GlbVar.settings.ogre.FSAA = cfg.getSetting("FSAA", "ogre", "0"); GlbVar.settings.ogre.vsync = cfg.getSetting("vsync", "ogre", "no"); //--- Graphics --------------------------------------------------------------------- GlbVar.settings.graphics.lighting = Ogre::StringConverter::parseBool(cfg.getSetting("lighting", "graphics", "yes")); GlbVar.settings.graphics.shadows = Ogre::StringConverter::parseBool(cfg.getSetting("shadows", "graphics", "yes")); GlbVar.settings.graphics.normalMapping = Ogre::StringConverter::parseBool(cfg.getSetting("normalMapping", "graphics", "yes")); GlbVar.settings.graphics.parallaxMapping = Ogre::StringConverter::parseBool(cfg.getSetting("parallaxMapping", "graphics", "yes")); //--- Controls --------------------------------------------------------------------- GlbVar.settings.controls.turningSensitivity = Ogre::StringConverter::parseReal(cfg.getSetting("turningSensitivity", "controls", "0.2")); GlbVar.settings.controls.upDownSensitivity = Ogre::StringConverter::parseReal(cfg.getSetting("upDownSensitivity", "controls", "1")); GlbVar.settings.controls.invertMouse = Ogre::StringConverter::parseBool(cfg.getSetting("invertMouse", "controls", "1")); GlbVar.settings.controls.keys["forward"] = GlbVar.keyMap->stringToKey(cfg.getSetting("forward", "controls", "W"), OIS::KC_W); GlbVar.settings.controls.keys["backward"] = GlbVar.keyMap->stringToKey(cfg.getSetting("backward", "controls", "S"), OIS::KC_W); GlbVar.settings.controls.keys["left"] = GlbVar.keyMap->stringToKey(cfg.getSetting("left", "controls", "A"), OIS::KC_W); GlbVar.settings.controls.keys["right"] = GlbVar.keyMap->stringToKey(cfg.getSetting("right", "controls", "D"), OIS::KC_W); GlbVar.settings.controls.keys["dimensionSwitch"] = GlbVar.keyMap->stringToKey(cfg.getSetting("dimensionSwitch", "controls", "SPACE"), OIS::KC_W); GlbVar.settings.controls.keys["gravitySwitch"] = GlbVar.keyMap->stringToKey(cfg.getSetting("gravitySwitch", "controls", "G"), OIS::KC_W); GlbVar.settings.controls.keys["selfDestruct"] = GlbVar.keyMap->stringToKey(cfg.getSetting("selfDestruct", "controls", "Z"), OIS::KC_W); GlbVar.settings.controls.keys["peepLeft"] = GlbVar.keyMap->stringToKey(cfg.getSetting("peepLeft", "controls", "Q"), OIS::KC_W); GlbVar.settings.controls.keys["peepRight"] = GlbVar.keyMap->stringToKey(cfg.getSetting("peepRight", "controls", "E"), OIS::KC_W); //--- Misc. ------------------------------------------------------------------------ GlbVar.settings.misc.fixCameraObstruction = Ogre::StringConverter::parseBool(cfg.getSetting("fixCameraObstruction", "misc", "yes")); //---------------------------------------------------------------------------------- }
void createRenderWindow() { mRoot->initialise(false); { Ogre::String lWindowTitle = "Ballz"; Ogre::ConfigFile cfgFile; cfgFile.loadDirect("config.ini"); std::string wString = cfgFile.getSetting("width", "renderer"); std::string hString = cfgFile.getSetting("height", "renderer"); std::string fsString = cfgFile.getSetting("fullscreen", "renderer"); int lSizeX = Ogre::StringConverter::parseInt(wString); int lSizeY = Ogre::StringConverter::parseInt(hString); int lFullscreen = Ogre::StringConverter::parseBool(fsString); Ogre::NameValuePairList lParams; // we use our own FXAA lParams["FSAA"] = "0"; lParams["vsync"] = "false"; lParams["useNVPerfHUD"] = "true"; mWindow = mRoot->createRenderWindow(lWindowTitle, lSizeX, lSizeY, lFullscreen, &lParams); } }
void loadRecord() { Ogre::ConfigFile cfg; try { cfg.loadDirect(RECORD_FILE); } catch (Ogre::FileNotFoundException &) { std::ofstream out(RECORD_FILE); out << std::endl; out.close(); cfg.loadDirect(RECORD_FILE); } GlbVar.records.firstTime = Ogre::StringConverter::parseBool(cfg.getSetting("firstTime", Ogre::StringUtil::BLANK, "yes")); Ogre::String highestLevelStr = cfg.getSetting("highestLevelIndex", Ogre::StringUtil::BLANK, "n"); if (highestLevelStr != "n") { GlbVar.records.highestLevelIndex = Ogre::StringConverter::parseInt(highestLevelStr); if (GlbVar.records.highestLevelIndex >= GlbVar.woMgr->getNumWorlds()) GlbVar.records.highestLevelIndex = GlbVar.firstLevel; } else GlbVar.records.highestLevelIndex = GlbVar.firstLevel; //Deserialise recordMap from string. Ogre::String recordMapStr = cfg.getSetting("records", Ogre::StringUtil::BLANK, "n"); if (recordMapStr != "n") { std::stringstream recordMapStream(std::stringstream::in | std::stringstream::out); recordMapStream << recordMapStr; boost::archive::text_iarchive ia(recordMapStream); ia >> GlbVar.records.recordMap; }
SettingsFileParser::SettingsFileParser(Ogre::String filePath) : mFilePath(filePath) { // Set default settings mRestoreConfig = false; mLockMouse = true; mDebugDraw = true; mHumanChars = true; mObstacles = true; mSingleNavmesh = false; mRaycastScene = false; mTempObstacleSteering = true; mComplexObstacles = true; mTerrain = false; mPaged = false; mTerrainTilesX = 1; mTerrainTilesZ = 1; mTerrainTileSize = 12000.0f; mTerrainTileResolution = 513; mTerrainHeightScale = 1.0f; // Load settings from config file Ogre::ConfigFile settingsFile = Ogre::ConfigFile(); settingsFile.loadDirect(filePath); Ogre::ConfigFile::SectionIterator sectIt = settingsFile.getSectionIterator(); Ogre::String sectionName, optionName, optionValue; while(sectIt.hasMoreElements()) { sectionName = sectIt.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *sectSettings = sectIt.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator it; for(it = sectSettings->begin(); it != sectSettings->end(); it++) { optionName = it->first; optionValue = it->second; addOption(sectionName, optionName, optionValue); } } }
int Landusemap::loadConfig(Ogre::String filename) { Vector3 mapsize = gEnv->terrainManager->getMaxTerrainSize(); std::map<unsigned int, String> usemap; String textureFilename = ""; LOG("Parsing landuse config: '"+filename+"'"); String group = ""; try { group = ResourceGroupManager::getSingleton().findGroupContainingResource(filename); }catch(...) { // we wont catch anything, since the path could be absolute as well, then the group is not found } Ogre::ConfigFile cfg; try { // try to load directly otherwise via resource group if (group == "") cfg.loadDirect(filename); else cfg.loadFromResourceSystem(filename, group, "\x09:=", true); } catch(Ogre::Exception& e) { ErrorUtils::ShowError(_L("Error while loading landuse config"), e.getFullDescription()); return 1; } Ogre::ConfigFile::SectionIterator seci = cfg.getSectionIterator(); Ogre::String secName, kname, kvalue; while (seci.hasMoreElements()) { secName = seci.peekNextKey(); Ogre::ConfigFile::SettingsMultiMap *settings = seci.getNext(); Ogre::ConfigFile::SettingsMultiMap::iterator i; for (i = settings->begin(); i != settings->end(); ++i) { kname = i->first; kvalue = i->second; // we got all the data available now, processing now if (secName == "general" || secName == "config") { // set some class properties accoring to the information in this section if (kname == "texture") textureFilename = kvalue; else if (kname == "frictionconfig" || kname == "loadGroundModelsConfig") gEnv->collisions->loadGroundModelsConfigFile(kvalue); else if (kname == "defaultuse") default_ground_model = gEnv->collisions->getGroundModelByString(kvalue); } else if (secName == "use-map") { if (kname.size() != 10) { LOG("invalid color in landuse line in " + filename); continue; } char *ptr; //not used unsigned int color = strtoul(kname.c_str(), &ptr, 16); usemap[color] = kvalue; } } } #ifdef USE_PAGED // process the config data and load the buffers finally try { Forests::ColorMap *colourMap = Forests::ColorMap::load(textureFilename, Forests::CHANNEL_COLOR); colourMap->setFilter(Forests::MAPFILTER_NONE); /* // debug things below printf("found ground use definitions:\n"); for (std::map < uint32, String >::iterator it=usemap.begin(); it!=usemap.end(); it++) { printf(" 0x%Lx : %s\n", it->first, it->second.c_str()); } */ bool bgr = colourMap->getPixelBox().format == PF_A8B8G8R8; Ogre::TRect<Ogre::Real> bounds = Forests::TBounds(0, 0, mapsize.x, mapsize.z); // now allocate the data buffer to hold pointers to ground models data = new ground_model_t*[(int)(mapsize.x * mapsize.z)]; ground_model_t **ptr = data; //std::map < String, int > counters; for (int z=0; z<mapsize.z; z++) { for (int x=0; x<mapsize.x; x++) { unsigned int col = colourMap->getColorAt(x, z, bounds); if (bgr) { // Swap red and blue values unsigned int cols = col & 0xFF00FF00; cols |= (col & 0xFF) << 16; cols |= (col & 0xFF0000) >> 16; col = cols; } String use = usemap[col]; //if (use!="") // counters[use]++; // store the pointer to the ground model in the data slot *ptr = gEnv->collisions->getGroundModelByString(use); ptr++; } } } catch (...) { Log("Landuse: Failed to load texture: " + textureFilename); } #endif // USE_PAGED return 0; }
int _tmain(int argc, _TCHAR* argv[]) { // ------------------------- Check for command line argument ------------------------------------------- if (! argv[1]) { printf("\n"); printf("Missing argument.\nExample: \"Converter.exe job1.cfg\""); return 0; } // ------------------------- Basic Ogre Engine initialization ------------------------------------------- Ogre::Root* root = new Ogre::Root; Ogre::RenderSystem* rendersys = root->getRenderSystemByName("Direct3D9 Rendering Subsystem"); rendersys->setConfigOption("Full Screen", "No"); rendersys->setConfigOption("Video Mode", "800 x 600 @ 32-bit colour"); root->setRenderSystem(rendersys); Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resource", "FileSystem", "General"); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); root->initialise(false); Ogre::RenderWindow* window = root->createRenderWindow("RAW2OGT", 800, 600, false); Ogre::SceneManager* scenemgr = root->createSceneManager(Ogre::SceneType::ST_GENERIC); Ogre::Camera* camera = scenemgr->createCamera("camera"); Ogre::Viewport* viewport = window->addViewport(camera); /*Ogre::Vector3 lightdir(0, -0.3, 0.75); lightdir.normalise(); Ogre::Light* l = scenemgr->createLight("tstLight"); l->setType(Ogre::Light::LT_DIRECTIONAL); l->setDirection(lightdir); l->setDiffuseColour(Ogre::ColourValue(1.0, 1.0, 1.0)); l->setSpecularColour(Ogre::ColourValue(0.4, 0.4, 0.4));*/ scenemgr->setAmbientLight(Ogre::ColourValue(0.7, 0.7, 0.7)); // --------------------------------- Start convert ---------------------------------------------------- // Load job config Ogre::ConfigFile* terrainconfig = OGRE_NEW Ogre::ConfigFile(); terrainconfig->loadDirect(argv[1]); // Load info from [general] block Ogre::String heightmapfile = terrainconfig->getSetting("heightmap", "general"); Ogre::Real heightmapscale = Ogre::StringConverter::parseReal(terrainconfig->getSetting("heightmapscale", "general")); Ogre::Real heightmapoffset = Ogre::StringConverter::parseReal(terrainconfig->getSetting("heightmapoffset", "general")); Ogre::uint16 terrainsize = Ogre::StringConverter::parseUnsignedInt(terrainconfig->getSetting("terrainsize", "general")); Ogre::Real worldsize = Ogre::StringConverter::parseReal(terrainconfig->getSetting("worldsize", "general")); Ogre::uint16 layercount = Ogre::StringConverter::parseUnsignedInt(terrainconfig->getSetting("layercount", "general")); // initialise stream to heightmapfile Ogre::DataStreamPtr stream = Ogre::ResourceGroupManager::getSingleton().openResource(heightmapfile, "General"); size_t size = stream.get()->size(); // verify size if(size != terrainsize * terrainsize * 4) OGRE_EXCEPT( Ogre::Exception::ERR_INTERNAL_ERROR, "Size of stream does not match terrainsize!", "TerrainPage" ); // load to buffer float* buffer = OGRE_ALLOC_T(float, size, Ogre::MEMCATEGORY_GENERAL); stream->read(buffer, size); // apply scale and offset for(int i=0;i<terrainsize*terrainsize;i++) { buffer[i] = (buffer[i] + heightmapoffset) * heightmapscale; } // Terrain initialization Ogre::TerrainGlobalOptions* terrainglobals = OGRE_NEW Ogre::TerrainGlobalOptions(); terrainglobals->setMaxPixelError(1); //terrainglobals->setCompositeMapDistance(30000); //terrainglobals->setLightMapDirection(lightdir); //terrainglobals->setCompositeMapAmbient(scenemgr->getAmbientLight()); //terrainglobals->setCompositeMapDiffuse(l->getDiffuseColour()); Ogre::TerrainMaterialGeneratorA::SM2Profile* pMatProfile = static_cast<Ogre::TerrainMaterialGeneratorA::SM2Profile*>(terrainglobals->getDefaultMaterialGenerator()->getActiveProfile()); pMatProfile->setLightmapEnabled(false); pMatProfile->setCompositeMapEnabled(false); Ogre::TerrainGroup* terraingroup = OGRE_NEW Ogre::TerrainGroup(scenemgr, Ogre::Terrain::ALIGN_X_Z, terrainsize, worldsize); terraingroup->setFilenameConvention(Ogre::String("terrain"), Ogre::String("ogt")); terraingroup->setOrigin(Ogre::Vector3::ZERO); Ogre::Terrain* terrain = OGRE_NEW Ogre::Terrain(scenemgr); // terrainsettings Ogre::Terrain::ImportData& imp = terraingroup->getDefaultImportSettings(); imp.terrainSize = terrainsize; imp.worldSize = worldsize; imp.minBatchSize = 33; imp.maxBatchSize = 65; // use float RAW heightmap as input imp.inputFloat = buffer; // process texture layers imp.layerList.resize(layercount); Ogre::StringVector blendmaps(layercount); for(int i=0;i<layercount;i++) { // load layer info Ogre::String sectionStr = Ogre::StringConverter::toString(i); Ogre::Real layerworldsize = Ogre::StringConverter::parseReal(terrainconfig->getSetting("worldsize", sectionStr)); if (i==0) { // no blendmap at layer 0 (baselayer) Ogre::String specular = terrainconfig->getSetting("specular", sectionStr); Ogre::String normal = terrainconfig->getSetting("normal", sectionStr); // add layer imp.layerList[i].textureNames.push_back(specular); imp.layerList[i].textureNames.push_back(normal); imp.layerList[i].worldSize = layerworldsize; } else { Ogre::String specular = terrainconfig->getSetting("specular", sectionStr); Ogre::String normal = terrainconfig->getSetting("normal", sectionStr); Ogre::String blend = terrainconfig->getSetting("blend", sectionStr); // add layer imp.layerList[i].textureNames.push_back(specular); imp.layerList[i].textureNames.push_back(normal); imp.layerList[i].worldSize = layerworldsize; blendmaps[i] = blend; } } // load the terrain terrain->prepare(imp); terrain->load(); // load those blendmaps into the layers for(int j = 1;j < terrain->getLayerCount();j++) { Ogre::TerrainLayerBlendMap *blendmap = terrain->getLayerBlendMap(j); Ogre::Image img; img.load(blendmaps[j],"General"); int blendmapsize = terrain->getLayerBlendMapSize(); if(img.getWidth() != blendmapsize) img.resize(blendmapsize, blendmapsize); float *ptr = blendmap->getBlendPointer(); Ogre::uint8 *data = static_cast<Ogre::uint8*>(img.getPixelBox().data); for(int bp = 0;bp < blendmapsize * blendmapsize;bp++) ptr[bp] = static_cast<float>(data[bp]) / 255.0f; blendmap->dirty(); blendmap->update(); } // create filename for writing int pos = heightmapfile.find_last_of('.'); if (pos < 0) heightmapfile = heightmapfile + ".ogt"; else heightmapfile = heightmapfile.substr(0, pos) + ".ogt"; // save as Ogre .OGT terrain->save(heightmapfile); Ogre::LogManager::getSingletonPtr()->logMessage(Ogre::LogMessageLevel::LML_NORMAL, heightmapfile + " successfully written."); // debug viewing (exit with CTRL+C) camera->setPosition(-terrainsize, 7000, -terrainsize); camera->lookAt(terrainsize/2,0,terrainsize/2); root->startRendering(); return 0; }