Revision: 2749 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2749&view=rev Author: rorthomas Date: 2012-05-29 01:05:54 +0000 (Tue, 29 May 2012) Log Message: ----------- continued working on terrain code, wip
Modified Paths: -------------- trunk/source/main/GlobalEnvironment.h trunk/source/main/gameplay/CacheSystem.cpp trunk/source/main/terrain/TerrainManager.cpp trunk/source/main/terrain/TerrainManager.h Modified: trunk/source/main/GlobalEnvironment.h =================================================================== --- trunk/source/main/GlobalEnvironment.h 2012-05-28 20:47:34 UTC (rev 2748) +++ trunk/source/main/GlobalEnvironment.h 2012-05-29 01:05:54 UTC (rev 2749) @@ -47,7 +47,7 @@ , sky(0) , surveyMap(0) , terrainManager(0) - , ogreRoot(0) + , ogreRoot(0) { } Modified: trunk/source/main/gameplay/CacheSystem.cpp =================================================================== --- trunk/source/main/gameplay/CacheSystem.cpp 2012-05-28 20:47:34 UTC (rev 2748) +++ trunk/source/main/gameplay/CacheSystem.cpp 2012-05-29 01:05:54 UTC (rev 2749) @@ -31,6 +31,7 @@ #include "SHA1.h" #include "SoundScriptManager.h" #include "Utils.h" +#include "TerrainManager.h" #ifdef USE_MYGUI #include "LoadingWindow.h" @@ -1177,12 +1178,15 @@ { //LOG("Read to add "+String(entry.dname)+" filename "+String(filename)); DataStreamPtr ds = ResourceGroupManager::getSingleton().openResource(filename, group); - entry.dname = ds->getLine(); if (ext == "terrn2") + { fillTerrainDetailInfo(entry, ds, filename); - else + } else + { + entry.dname = ds->getLine(); fillTruckDetailInfo(entry, ds, filename); + } // ds closes automatically, so do _not_ close it explicitly below entry.fname = filename; @@ -1660,83 +1664,15 @@ void CacheSystem::fillTerrainDetailInfo(CacheEntry &entry, Ogre::DataStreamPtr ds, Ogre::String fname) { - char authorformat[256] = "//author %s %i %s %s"; - char authortag[256] = "//author"; + TerrainManager tm; + tm.loadTerrainConfigBasics(ds); - char categoryformat[256] = "//fileinfo %s %i, %i"; - char categorytag[256] = "//fileinfo"; - //parsing the current file entry.authors.clear(); - LOG("Parsing terrain for detail information: '"+String(fname)+"'"); - //LOG("Parsing for authors: '"+String(d.fname)+"'"); - char line[1024]; - int linecounter = 0; - int categoryid=-1, version=-1; - - // try to get unique ID from the filename! - String uniqueid = "no-uid"; - String fileuid = getUIDfromString(fname); - if (fileuid != "") uniqueid = fileuid; - - while (!ds->eof()) - { - size_t ll=ds->readLine(line, 1023); - if (ll <= 1) - // ignore empty lines - continue; - linecounter++; - if (!strncmp(authortag, line, strnlen(authortag, 254))) { - int authorid; - char authorname[256], authoremail[256], authortype[256]; - memset(authorname, 0, 255); - memset(authoremail, 0, 255); - memset(authortype, 0, 255); - int result = sscanf(line, authorformat, &authortype, &authorid, &authorname, &authoremail); - if (result < 1 || result == EOF) - { - LOG("Error parsing File (author) " + String(fname) +" line " + TOSTRING(linecounter) + ". trying to continue ..."); - continue; - } - //replace '_' with ' ' - authorinfo_t author; - //char *tmp = authorname; - //while (*tmp!=0) {if (*tmp=='_') *tmp=' ';tmp++;}; - - //fill the struct now - author.id = authorid; - author.type = String(authortype); - author.name = String(authorname); - author.email = String(authoremail); - entry.authors.push_back(author); - - } else if (!strncmp(categorytag, line, strnlen(categorytag, 254))) - { - char uidtmp[256] = ""; - int result = sscanf(line, categoryformat, uidtmp, &categoryid, &version); - if (result < 3 || result == EOF) - { - LOG("Error parsing File (fileinfo) " + String(fname) +" line " + TOSTRING(linecounter) + ". trying to continue ..."); - continue; - } - - if (uniqueid != "") - { - // remove trailing comma - size_t slen = strnlen(uidtmp, 250); - if (slen > 0 && uidtmp[slen-1] == ',') - uidtmp[slen-1] = 0; - - // fix the -1 from the old format - if (strnlen(uidtmp, 5) > 0 && strncmp(uidtmp, "-1", 2)) - uniqueid = String(uidtmp); - } - - } - } - entry.categoryid = categoryid; - entry.uniqueid = uniqueid; - entry.version = version; + entry.dname = tm.terrain_name; + entry.categoryid = tm.categoryID; + entry.uniqueid = tm.guid; + entry.version = tm.version; } int CacheSystem::getCategoryUsage(int category) Modified: trunk/source/main/terrain/TerrainManager.cpp =================================================================== --- trunk/source/main/terrain/TerrainManager.cpp 2012-05-28 20:47:34 UTC (rev 2748) +++ trunk/source/main/terrain/TerrainManager.cpp 2012-05-29 01:05:54 UTC (rev 2749) @@ -54,6 +54,38 @@ } +void TerrainManager::loadTerrainConfigBasics(Ogre::DataStreamPtr &ds) +{ + // now generate the hash of it + generateHashFromDataStream(ds, fileHash); + + mTerrainConfig.load(ds, "\t:=", true); + + // read in the settings + terrain_name = mTerrainConfig.getSetting("Name", "General"); + if (terrain_name.empty()) + { + showError(_L("Terrain loading error"), _L("the terrain name cannot be empty")); + exit(125); + } + + ogre_terrain_config_filename = mTerrainConfig.getSetting("GeometryConfig", "General"); + // otc = ogre terrain config + if (ogre_terrain_config_filename.find(".otc") == String::npos) + { + showError(_L("Terrain loading error"), _L("the new terrain mode only supports .otc configurations")); + exit(125); + } + + ambient_color = StringConverter::parseColourValue(mTerrainConfig.getSetting("AmbientColor", "General")); + start_position = StringConverter::parseVector3(mTerrainConfig.getSetting("StartPosition", "General")); + + guid = mTerrainConfig.getSetting("GUID", "General"); + categoryID = StringConverter::parseInt(mTerrainConfig.getSetting("CategoryID", "General")); + version = StringConverter::parseInt(mTerrainConfig.getSetting("Version", "General")); + +} + void TerrainManager::loadTerrain(String filename) { DataStreamPtr ds; @@ -69,25 +101,9 @@ exit(125); } - // now generate the hash of it - generateHashFromDataStream(ds, fileHash); + loadTerrainConfigBasics(ds); - mTerrainConfig.load(ds, "\t:=", false); - // read in the settings - terrain_name = mTerrainConfig.getSetting("Name"); - - ogre_terrain_config_filename = mTerrainConfig.getSetting("GeometryConfig"); - // otc = ogre terrain config - if (ogre_terrain_config_filename.find(".otc") == String::npos) - { - showError(_L("Terrain loading error"), _L("the new terrain mode only supports .otc configurations")); - exit(125); - } - - ambient_color = StringConverter::parseColourValue(mTerrainConfig.getSetting("AmbientColor")); - start_position = StringConverter::parseVector3(mTerrainConfig.getSetting("StartPosition")); - // then, init the subsystems, order is important :) initSubSystems(); @@ -118,6 +134,9 @@ // geometry - ogre terrain things geometry_manager = new TerrainGeometryManager(this); + // collisions + initCollisions(); + // shadows initShadows(); @@ -184,7 +203,7 @@ gEnv->sky = sky_manager; // try to load caelum config - String caelumConfig = mTerrainConfig.getSetting("CaelumConfigFile"); + String caelumConfig = mTerrainConfig.getSetting("CaelumConfigFile", "General"); if (!caelumConfig.empty() && ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(caelumConfig)) { @@ -199,7 +218,7 @@ } else #endif //USE_CAELUM { - String sandStormConfig = mTerrainConfig.getSetting("SandStormCubeMap"); + String sandStormConfig = mTerrainConfig.getSetting("SandStormCubeMap", "General"); if (!sandStormConfig.empty()) { Modified: trunk/source/main/terrain/TerrainManager.h =================================================================== --- trunk/source/main/terrain/TerrainManager.h 2012-05-28 20:47:34 UTC (rev 2748) +++ trunk/source/main/terrain/TerrainManager.h 2012-05-29 01:05:54 UTC (rev 2749) @@ -22,16 +22,20 @@ #include "RoRPrerequisites.h" +#include "CacheSystem.h" + #include <OgreConfigFile.h> class TerrainManager : public ZeroedMemoryAllocator { + friend class CacheSystem; public: TerrainManager(); ~TerrainManager(); void loadTerrain(Ogre::String filename); + void loadTerrainConfigBasics(Ogre::DataStreamPtr &ds); void update(float dt) {}; @@ -70,7 +74,10 @@ Ogre::String fileHash; Ogre::String ogre_terrain_config_filename; Ogre::String terrain_name; + Ogre::String guid; Ogre::Vector3 start_position; + int categoryID; + int version; bool use_caelum; float gravity; float water_line; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Rigsofrods-devel mailing list Rigsofrods-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel