Revision: 2646 http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2646&view=rev Author: rorthomas Date: 2012-05-24 13:46:55 +0000 (Thu, 24 May 2012) Log Message: ----------- new terrain WIP vehicle can change features on the fly now
Modified Paths: -------------- trunk/source/main/RoRPrerequisites.h trunk/source/main/gameplay/RoRFrameListener.cpp trunk/source/main/gameplay/RoRFrameListener.h trunk/source/main/physics/Beam.cpp trunk/source/main/physics/Beam.h Added Paths: ----------- trunk/source/main/gameplay/TerrainManager.cpp trunk/source/main/gameplay/TerrainManager.h Modified: trunk/source/main/RoRPrerequisites.h =================================================================== --- trunk/source/main/RoRPrerequisites.h 2012-05-24 01:01:10 UTC (rev 2645) +++ trunk/source/main/RoRPrerequisites.h 2012-05-24 13:46:55 UTC (rev 2646) @@ -163,6 +163,7 @@ class SoundManager; class SoundScriptInstance; class SoundScriptManager; +class TerrainManager; class TorqueCurve; class TruckEditor; class TruckHUD; Modified: trunk/source/main/gameplay/RoRFrameListener.cpp =================================================================== --- trunk/source/main/gameplay/RoRFrameListener.cpp 2012-05-24 01:01:10 UTC (rev 2645) +++ trunk/source/main/gameplay/RoRFrameListener.cpp 2012-05-24 13:46:55 UTC (rev 2646) @@ -57,6 +57,7 @@ #include "MeshObject.h" #include "MumbleIntegration.h" #include "network.h" +#include "TerrainManager.h" #include "OutProtocol.h" #include "OverlayWrapper.h" #include "PlayerColours.h" @@ -796,7 +797,8 @@ terrainName(""), terrainUID(""), truck_preload_num(0), - w(0) + w(0), + terrainManager(0) { RoRFrameListener::eflsingleton = this; @@ -2490,6 +2492,10 @@ { //Toggle Auto shift curr_truck->engine->toggleAutoMode(); + + // force gui update + curr_truck->triggerGUIFeaturesChanged(); + #ifdef USE_MYGUI switch(curr_truck->engine->getAutoMode()) { @@ -3828,264 +3834,8 @@ mSceneMgr->setWorldGeometry(geom); } else if (newTerrainMode && !disableTetrrain) { - // new terrain mode - // new terrain - int pageSize = StringConverter::parseInt(cfg.getSetting("PageSize")); - int worldSize = StringConverter::parseInt(cfg.getSetting("PageWorldX")); - int pageMaxHeight = StringConverter::parseInt(cfg.getSetting("MaxHeight")); - - String TERRAIN_FILE_PREFIX = String(geom); //"testTerrain"; - String TERRAIN_FILE_SUFFIX = "mapbin"; - float TERRAIN_WORLD_SIZE = worldSize; //1000.0f; // PageWorldX? - int TERRAIN_SIZE = pageSize; - int TERRAIN_PAGE_MIN_X=0, TERRAIN_PAGE_MAX_X=0; - int TERRAIN_PAGE_MIN_Y=0, TERRAIN_PAGE_MAX_Y=0; - - TERRAIN_PAGE_MAX_X = StringConverter::parseInt(cfg.getSetting("Pages_X")); - TERRAIN_PAGE_MAX_Y = StringConverter::parseInt(cfg.getSetting("Pages_Y")); - - bool mTerrainsImported=false; - TerrainPaging* mTerrainPaging=0; - PageManager* mPageManager=0; - - Vector3 mTerrainPos(worldSize/2,0,worldSize/2); - mTerrainGroup = OGRE_NEW TerrainGroup(mSceneMgr, Terrain::ALIGN_X_Z, TERRAIN_SIZE, TERRAIN_WORLD_SIZE); - mTerrainGroup->setFilenameConvention(TERRAIN_FILE_PREFIX, TERRAIN_FILE_SUFFIX); - mTerrainGroup->setOrigin(mTerrainPos); - mTerrainGroup->setResourceGroup("cache"); - - new TerrainGlobalOptions(); - // Configure global - TerrainGlobalOptions::getSingleton().setMaxPixelError(StringConverter::parseInt(cfg.getSetting("MaxPixelError"))); - - // testing composite map - if (mCamera->getFarClipDistance() == 0) - TerrainGlobalOptions::getSingleton().setCompositeMapDistance(1000.0f); - else - TerrainGlobalOptions::getSingleton().setCompositeMapDistance(std::min(1000.0f, mCamera->getFarClipDistance())); - //mTerrainGlobals->setUseRayBoxDistanceCalculation(true); - - // adds strange colours for debug purposes - //TerrainGlobalOptions::getSingleton().getDefaultMaterialGenerator()->setDebugLevel(1); - - // TBD: optimizations - TerrainMaterialGeneratorA::SM2Profile* matProfile = static_cast<TerrainMaterialGeneratorA::SM2Profile*>(TerrainGlobalOptions::getSingleton().getDefaultMaterialGenerator()->getActiveProfile()); - matProfile->setLightmapEnabled(true); - //matProfile->setLayerNormalMappingEnabled(false); - //matProfile->setLayerSpecularMappingEnabled(false); - //matProfile->setLayerParallaxMappingEnabled(false); - - matProfile->setGlobalColourMapEnabled(false); - matProfile->setReceiveDynamicShadowsDepth(true); - - - TerrainGlobalOptions::getSingleton().setCompositeMapSize(1024); - //TerrainGlobalOptions::getSingleton().setCompositeMapDistance(100); - TerrainGlobalOptions::getSingleton().setSkirtSize(1); - TerrainGlobalOptions::getSingleton().setLightMapSize(256); - TerrainGlobalOptions::getSingleton().setCastsDynamicShadows(true); - - // Important to set these so that the terrain knows what to use for derived (non-realtime) data - if (mainLight) TerrainGlobalOptions::getSingleton().setLightMapDirection(mainLight->getDerivedDirection()); - TerrainGlobalOptions::getSingleton().setCompositeMapAmbient(mSceneMgr->getAmbientLight()); - //mTerrainGlobals->setCompositeMapAmbient(ColourValue::Red); - if (mainLight) TerrainGlobalOptions::getSingleton().setCompositeMapDiffuse(mainLight->getDiffuseColour()); - - - - // Configure default import settings for if we use imported image - Terrain::ImportData& defaultimp = mTerrainGroup->getDefaultImportSettings(); - defaultimp.terrainSize = TERRAIN_SIZE; - defaultimp.worldSize = TERRAIN_WORLD_SIZE; - - //TerrainGlobalOptions::getSingleton().setDefaultGlobalColourMapSize(pageSize); - - defaultimp.inputScale = pageMaxHeight; - defaultimp.minBatchSize = 33; - if (!cfg.getSetting("minBatchSize").empty()) - defaultimp.minBatchSize = StringConverter::parseInt(cfg.getSetting("minBatchSize")); - - if (!cfg.getSetting("maxBatchSize").empty()) - defaultimp.maxBatchSize = StringConverter::parseInt(cfg.getSetting("maxBatchSize")); - - // TBD: properly load textures: http://www.ogre3d.org/forums/viewtopic.php?f=2&t=60302&start=0 - - // textures - StringVector blendMaps, blendMode; - int numLayers = StringConverter::parseInt(cfg.getSetting("Layers.count")); - if (numLayers > 0) - { - defaultimp.layerList.resize(numLayers+1); - blendMaps.resize(numLayers+1); - blendMode.resize(numLayers+1); - for(int i = 1; i<numLayers+1; i++) - { - defaultimp.layerList[i].worldSize = StringConverter::parseReal(cfg.getSetting("Layers."+TOSTRING(i)+".size")); - defaultimp.layerList[i].textureNames.push_back(cfg.getSetting("Layers."+TOSTRING(i)+".diffuse")); - defaultimp.layerList[i].textureNames.push_back(cfg.getSetting("Layers."+TOSTRING(i)+".normal")); - blendMaps[i] = cfg.getSetting("Layers."+TOSTRING(i)+".blendmap"); - blendMode[i] = cfg.getSetting("Layers."+TOSTRING(i)+".blendmapmode"); - } - } - - String filename = mTerrainGroup->generateFilename(0, 0); - bool is_cached = (ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(), filename)); - - bool disableCaching = false; - if (!cfg.getSetting("disableCaching").empty()) - disableCaching = StringConverter::parseBool(cfg.getSetting("disableCaching")); - - if (disableCaching || !is_cached) - { - for (long x = TERRAIN_PAGE_MIN_X; x <= TERRAIN_PAGE_MAX_X; ++x) - { - for (long y = TERRAIN_PAGE_MIN_Y; y <= TERRAIN_PAGE_MAX_Y; ++y) - { - String filename = mTerrainGroup->generateFilename(x, y); - if (!disableCaching && ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(), filename)) - { - mTerrainGroup->defineTerrain(x, y); - } - else - { - String heightmapString = "Heightmap.image." + TOSTRING(x) + "." + TOSTRING(y); - String heightmapFilename = cfg.getSetting(heightmapString); - if (heightmapFilename.empty()) - { - // try loading the old non-paged name - heightmapString = "Heightmap.image"; - heightmapFilename = cfg.getSetting(heightmapString); - } - Image img; - if (heightmapFilename.find(".raw") != String::npos) - { - int rawSize = StringConverter::parseInt(cfg.getSetting("Heightmap.raw.size")); - int bpp = StringConverter::parseInt(cfg.getSetting("Heightmap.raw.bpp")); - - // load raw data - DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource(heightmapFilename); - LOG(" loading RAW image: " + TOSTRING(stream->size()) + " / " + TOSTRING(rawSize*rawSize*bpp)); - PixelFormat pformat = PF_L8; - if (bpp == 2) - pformat = PF_L16; - img.loadRawData(stream, rawSize, rawSize, 1, pformat); - } else - { - img.load(heightmapFilename, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); - } - - if (!cfg.getSetting("Heightmap.flip").empty() && StringConverter::parseBool(cfg.getSetting("Heightmap.flip"))) - img.flipAroundX(); - - - //if (x % 2 != 0) - // img.flipAroundY(); - //if (y % 2 != 0) - // img.flipAroundX(); - - mTerrainGroup->defineTerrain(x, y, &img); - mTerrainsImported = true; - } - } - } - - // sync load since we want everything in place when we start - mTerrainGroup->loadAllTerrains(true); - - for (long x = TERRAIN_PAGE_MIN_X; x <= TERRAIN_PAGE_MAX_X; ++x) - { - for (long py = TERRAIN_PAGE_MIN_Y; py <= TERRAIN_PAGE_MAX_Y; ++py) - { - Terrain* terrain = mTerrainGroup->getTerrain(x,py); - if (!terrain) continue; - - ShadowManager::getSingleton().updatePSSM(terrain); - - // set up a colour map - /* - String textureString = "Texture.image." + TOSTRING(x) + "." + TOSTRING(y); - String textureFilename = cfg.getSetting(textureString); - if (textureFilename.empty()) - { - // try to load traditional world texture - textureString="WorldTexture"; - textureFilename = cfg.getSetting(textureString); - } - if (!textureFilename.empty() && !terrain->getGlobalColourMapEnabled()) - { - Image colourMap; - colourMap.load(textureFilename, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME); - - terrain->setGlobalColourMapEnabled(true, 1024); - - TexturePtr tp = terrain->getGlobalColourMap(); - if (!tp.isNull()) - tp->loadImage(colourMap); - } - */ - - for(int i=1; i<terrain->getLayerCount(); i++) - { - Ogre::Image img; - String group=""; - try - { - group = ResourceGroupManager::getSingleton().findGroupContainingResource(blendMaps[i]); - } catch(...) {} - if (group.empty()) - continue; - img.load(blendMaps[i], group); - - TerrainLayerBlendMap *bm = terrain->getLayerBlendMap(i); // starting with 1, very strange ... - - int bmSize = terrain->getLayerBlendMapSize(); - float* pBlend1 = bm->getBlendPointer(); - for (Ogre::uint16 y = 0; y != bmSize; y++) - { - for (Ogre::uint16 x = 0; x != bmSize; x++) - { - Ogre::Real tx=(float(x)/float(bmSize)); - Ogre::Real ty=(float(y)/float(bmSize)); - int ix = int(img.getWidth()*tx); - int iy = int(img.getHeight()*ty); - Ogre::ColourValue c = img.getColourAt(ix, iy, 0); - float alpha = 1;//(1/b); - if (blendMode[i] == "R") - *pBlend1++ = c.r * alpha; - else if (blendMode[i] == "G") - *pBlend1++ = c.g * alpha; - else if (blendMode[i] == "B") - *pBlend1++ = c.b * alpha; - else if (blendMode[i] == "A") - *pBlend1++ = c.a * alpha; - } - } - bm->dirty(); - bm->update(); - } - } - } - - if (disableCaching) - mTerrainGroup->saveAllTerrains(false); - } else - { - // paging, yeah! - // Paging setup - mPageManager = OGRE_NEW PageManager(); - // Since we're not loading any pages from .page files, we need a way just - // to say we've loaded them without them actually being loaded - mPageManager->setPageProvider(&mDummyPageProvider); - mPageManager->addCamera(mCamera); - mTerrainPaging = OGRE_NEW TerrainPaging(mPageManager); - PagedWorld* world = mPageManager->createWorld(); - mTerrainPaging->createWorldSection(world, mTerrainGroup, TERRAIN_SIZE, TERRAIN_SIZE*1.2f, - TERRAIN_PAGE_MIN_X, TERRAIN_PAGE_MIN_Y, - TERRAIN_PAGE_MAX_X, TERRAIN_PAGE_MAX_Y); - } - - mTerrainGroup->freeTemporaryResources(); - + terrainManager = new TerrainManager(mSceneMgr); + terrainManager->loadTerrain(geom); } } Modified: trunk/source/main/gameplay/RoRFrameListener.h =================================================================== --- trunk/source/main/gameplay/RoRFrameListener.h 2012-05-24 01:01:10 UTC (rev 2645) +++ trunk/source/main/gameplay/RoRFrameListener.h 2012-05-24 13:46:55 UTC (rev 2646) @@ -197,6 +197,8 @@ char screenshotformat[256]; char terrainmap[1024]; + + TerrainManager *terrainManager; collision_box_t *reload_box; double rtime; Added: trunk/source/main/gameplay/TerrainManager.cpp =================================================================== --- trunk/source/main/gameplay/TerrainManager.cpp (rev 0) +++ trunk/source/main/gameplay/TerrainManager.cpp 2012-05-24 13:46:55 UTC (rev 2646) @@ -0,0 +1,330 @@ +/* +This source file is part of Rigs of Rods +Copyright 2005-2012 Pierre-Michel Ricordel +Copyright 2007-2012 Thomas Fischer + +For more information, see http://www.rigsofrods.com/ + +Rigs of Rods is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License version 3, as +published by the Free Software Foundation. + +Rigs of Rods is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>. +*/ +#include "TerrainManager.h" + +#include "BeamFactory.h" +#include "CameraManager.h" +#include "RoRFrameListener.h" +#include "SkyManager.h" + +using namespace Ogre; + +TerrainManager::TerrainManager(Ogre::SceneManager *smgr) : + mSceneMgr(smgr) + , disableCaching(false) + , mTerrainsImported(false) +{ +} + +TerrainManager::~TerrainManager() +{ + +} + +void TerrainManager::loadTerrain(String filename) +{ + String ext; + Ogre::StringUtil::splitBaseFilename(filename, baseName, ext); + + loadTerrainConfig(filename); + + if (!terrainConfig.getSetting("disableCaching").empty()) + disableCaching = StringConverter::parseBool(terrainConfig.getSetting("disableCaching")); + + initTerrain(); +} + + +bool TerrainManager::loadTerrainConfig(String filename) +{ + try + { + DataStreamPtr ds_config = ResourceGroupManager::getSingleton().openResource(filename, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME); + terrainConfig.load(ds_config, "\t:=", false); + }catch(...) + { + terrainConfig.clear(); + } + return true; +} + + +void TerrainManager::initTerrain() +{ + // X, Y and Z scale + mapsizex = PARSEINT(terrainConfig.getSetting("PageWorldX")); + mapsizey = PARSEINT(terrainConfig.getSetting("MaxHeight")); + mapsizez = PARSEINT(terrainConfig.getSetting("PageWorldZ")); + pageSize = PARSEINT(terrainConfig.getSetting("PageSize")); + terrainSize = pageSize; + worldSize = std::max(mapsizex, mapsizez); + + String terrainFileSuffix = "mapbin"; + pageMinX = 0; + pageMaxX = 0; + pageMinY = 0; + pageMaxY = 0; + + pageMaxX = PARSEINT(terrainConfig.getSetting("Pages_X")); + pageMaxY = PARSEINT(terrainConfig.getSetting("Pages_Y")); + + + Vector3 mTerrainPos(mapsizex*0.5f, 0, mapsizez * 0.5f); + + mTerrainGroup = OGRE_NEW TerrainGroup(mSceneMgr, Terrain::ALIGN_X_Z, terrainSize, worldSize); + mTerrainGroup->setFilenameConvention(baseName, terrainFileSuffix); + mTerrainGroup->setOrigin(mTerrainPos); + mTerrainGroup->setResourceGroup("cache"); + + OGRE_NEW TerrainGlobalOptions(); + // Configure global + + configureTerrainDefaults(); + + String filename = mTerrainGroup->generateFilename(0, 0); + bool is_cached = ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(), filename); + if (disableCaching || !is_cached) + { + for (long x = pageMinX; x <= pageMaxX; ++x) + for (long y = pageMinY; y <= pageMaxY; ++y) + defineTerrain(x, y); + + // sync load since we want everything in place when we start + mTerrainGroup->loadAllTerrains(true); + + if (mTerrainsImported) + { + TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator(); + while(ti.hasMoreElements()) + { + Terrain *terrain = ti.getNext()->instance; + //ShadowManager::getSingleton().updatePSSM(terrain); + //initBlendMaps(terrain); + } + } + + // always save the results + //mTerrainGroup->saveAllTerrains(false); + } + + //mTerrainGroup->freeTemporaryResources(); +} + + +void TerrainManager::configureTerrainDefaults() +{ + Light *light = SkyManager::getSingleton().getMainLight(); + TerrainGlobalOptions *terrainOptions = TerrainGlobalOptions::getSingletonPtr(); + // Configure global + terrainOptions->setMaxPixelError(PARSEINT(terrainConfig.getSetting("MaxPixelError"))); + // testing composite map + terrainOptions->setCompositeMapDistance(PARSEINT(terrainConfig.getSetting("CompositeDistance"))); + + // Important to set these so that the terrain knows what to use for derived (non-realtime) data + if(light) + { + terrainOptions->setLightMapDirection(light->getDerivedDirection()); + terrainOptions->setCompositeMapDiffuse(light->getDiffuseColour()); + } + terrainOptions->setCompositeMapAmbient(mSceneMgr->getAmbientLight()); + + // Configure default import settings for if we use imported image + Ogre::Terrain::ImportData& defaultimp = mTerrainGroup->getDefaultImportSettings(); + defaultimp.terrainSize = terrainSize; // the heightmap size + defaultimp.worldSize = pageSize; // this is the scaled up size, like 12km + defaultimp.inputScale = mapsizey; + defaultimp.minBatchSize = 33; + defaultimp.maxBatchSize = 65; + + if (!terrainConfig.getSetting("minBatchSize").empty()) + defaultimp.minBatchSize = PARSEINT(terrainConfig.getSetting("minBatchSize")); + + if (!terrainConfig.getSetting("maxBatchSize").empty()) + defaultimp.maxBatchSize = PARSEINT(terrainConfig.getSetting("maxBatchSize")); + + /* + // testing composite map + + + + + // Configure default import settings for if we use imported image + Terrain::ImportData& defaultimp = mTerrainGroup->getDefaultImportSettings(); + defaultimp.terrainSize = pageSize; + defaultimp.worldSize = mapsizex; + + //TerrainGlobalOptions::getSingleton().setDefaultGlobalColourMapSize(pageSize); + + if (mCamera->getFarClipDistance() == 0) + TerrainGlobalOptions::getSingleton().setCompositeMapDistance(1000.0f); + else + TerrainGlobalOptions::getSingleton().setCompositeMapDistance(std::min(1000.0f, mCamera->getFarClipDistance())); + + //terrainOptions->setUseRayBoxDistanceCalculation(true); + + // adds strange colours for debug purposes + //TerrainGlobalOptions::getSingleton().getDefaultMaterialGenerator()->setDebugLevel(1); + + // TBD: optimizations + TerrainMaterialGeneratorA::SM2Profile* matProfile = static_cast<TerrainMaterialGeneratorA::SM2Profile*>(TerrainGlobalOptions::getSingleton().getDefaultMaterialGenerator()->getActiveProfile()); + matProfile->setLightmapEnabled(true); + //matProfile->setLayerNormalMappingEnabled(false); + //matProfile->setLayerSpecularMappingEnabled(false); + //matProfile->setLayerParallaxMappingEnabled(false); + + matProfile->setGlobalColourMapEnabled(false); + matProfile->setReceiveDynamicShadowsDepth(true); + + + TerrainGlobalOptions::getSingleton().setCompositeMapSize(1024); + //TerrainGlobalOptions::getSingleton().setCompositeMapDistance(100); + TerrainGlobalOptions::getSingleton().setSkirtSize(1); + TerrainGlobalOptions::getSingleton().setLightMapSize(256); + TerrainGlobalOptions::getSingleton().setCastsDynamicShadows(true); + + // Important to set these so that the terrain knows what to use for derived (non-realtime) data + Light *mainLight = SkyManager::getSingleton().getMainLight(); + if (mainLight) TerrainGlobalOptions::getSingleton().setLightMapDirection(mainLight->getDerivedDirection()); + TerrainGlobalOptions::getSingleton().setCompositeMapAmbient(mSceneMgr->getAmbientLight()); + //terrainOptions->setCompositeMapAmbient(ColourValue::Red); + if (mainLight) TerrainGlobalOptions::getSingleton().setCompositeMapDiffuse(mainLight->getDiffuseColour()); + */ + + + // load the textures and blendmaps into our data structures + blendMaps.clear(); + blendMode.clear(); + terrainLayers = StringConverter::parseInt(terrainConfig.getSetting("Layers.count")); + if (terrainLayers > 0) + { + defaultimp.layerList.resize(terrainLayers); + blendMaps.resize(terrainLayers); + blendMode.resize(terrainLayers); + for(int i = 0; i < terrainLayers; i++) + { + defaultimp.layerList[i].worldSize = PARSEINT(terrainConfig.getSetting("Layers."+TOSTRING(i)+".size")); + defaultimp.layerList[i].textureNames.push_back(terrainConfig.getSetting("Layers."+TOSTRING(i)+".diffusespecular")); + defaultimp.layerList[i].textureNames.push_back(terrainConfig.getSetting("Layers."+TOSTRING(i)+".normalheight")); + blendMaps[i] = terrainConfig.getSetting("Layers."+TOSTRING(i)+".blendmap"); + blendMode[i] = terrainConfig.getSetting("Layers."+TOSTRING(i)+".blendmapmode"); + } + } +} + +void TerrainManager::initBlendMaps( Ogre::Terrain* terrain ) +{ + for(int i = 1; i < terrain->getLayerCount(); i++) + { + Ogre::Image img; + try + { + img.load(blendMaps[i-1], ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME); + } catch(Exception &e) + { + LOG("Error loading blendmap: " + blendMaps[i] + " : " + e.getFullDescription()); + continue; + } + + TerrainLayerBlendMap *blendmap = terrain->getLayerBlendMap(i); // starting with 1, very strange ... + + // resize that blending map so it will fit + Ogre::uint32 blendmapSize = terrain->getLayerBlendMapSize(); + if(img.getWidth() != blendmapSize) + img.resize(blendmapSize, blendmapSize); + + // now to the ugly part + float* ptr = blendmap->getBlendPointer(); + for (Ogre::uint32 x = 0; x != blendmapSize; x++) + { + for (Ogre::uint32 y = 0; y != blendmapSize; y++) + { + Ogre::ColourValue c = img.getColourAt(x, y, 0); + float alpha = 1;//(1/b); + if (blendMode[i] == "R") + *ptr++ = c.r * alpha; + else if (blendMode[i] == "G") + *ptr++ = c.g * alpha; + else if (blendMode[i] == "B") + *ptr++ = c.b * alpha; + else if (blendMode[i] == "A") + *ptr++ = c.a * alpha; + } + } + blendmap->dirty(); + blendmap->update(); + } +} + +void TerrainManager::defineTerrain( int x, int y, bool flat ) +{ + if (flat) + { + // very simple, no height data to load at all + mTerrainGroup->defineTerrain(x, y, 0.0f); + return; + } + String filename = mTerrainGroup->generateFilename(x, y); + if (!disableCaching && ResourceGroupManager::getSingleton().resourceExists(mTerrainGroup->getResourceGroup(), filename)) + { + // load from cache + mTerrainGroup->defineTerrain(x, y); + } + else + { + // create new from image + String heightmapString = "Heightmap.image." + TOSTRING(x) + "." + TOSTRING(y); + String heightmapFilename = terrainConfig.getSetting(heightmapString); + if (heightmapFilename.empty()) + { + // try loading the old non-paged name + heightmapString = "Heightmap.image"; + heightmapFilename = terrainConfig.getSetting(heightmapString); + } + Image img; + if (heightmapFilename.find(".raw") != String::npos) + { + int rawSize = StringConverter::parseInt(terrainConfig.getSetting("Heightmap.raw.size")); + int bpp = StringConverter::parseInt(terrainConfig.getSetting("Heightmap.raw.bpp")); + + // load raw data + DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource(heightmapFilename); + LOG(" loading RAW image: " + TOSTRING(stream->size()) + " / " + TOSTRING(rawSize*rawSize*bpp)); + PixelFormat pformat = PF_L8; + if (bpp == 2) + pformat = PF_L16; + img.loadRawData(stream, rawSize, rawSize, 1, pformat); + } else + { + img.load(heightmapFilename, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); + } + + if (!terrainConfig.getSetting("Heightmap.flip").empty() && StringConverter::parseBool(terrainConfig.getSetting("Heightmap.flip"))) + img.flipAroundX(); + + + //if (x % 2 != 0) + // img.flipAroundY(); + //if (y % 2 != 0) + // img.flipAroundX(); + + mTerrainGroup->defineTerrain(x, y, &img); + mTerrainsImported = true; + } +} Property changes on: trunk/source/main/gameplay/TerrainManager.cpp ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/source/main/gameplay/TerrainManager.h =================================================================== --- trunk/source/main/gameplay/TerrainManager.h (rev 0) +++ trunk/source/main/gameplay/TerrainManager.h 2012-05-24 13:46:55 UTC (rev 2646) @@ -0,0 +1,65 @@ +/* +This source file is part of Rigs of Rods +Copyright 2005-2012 Pierre-Michel Ricordel +Copyright 2007-2012 Thomas Fischer + +For more information, see http://www.rigsofrods.com/ + +Rigs of Rods is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License version 3, as +published by the Free Software Foundation. + +Rigs of Rods is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>. +*/ +#ifndef TERRAINMANAGER_H__ +#define TERRAINMANAGER_H__ + +#include "RoRPrerequisites.h" + +#include <OgreTerrain.h> +#include <OgreTerrainMaterialGeneratorA.h> +#include <OgreTerrainPaging.h> +#include <OgreTerrainQuadTreeNode.h> +#include <OgreTerrainGroup.h> + +#include <OgreConfigFile.h> + +class TerrainManager +{ +public: + TerrainManager(Ogre::SceneManager *smgr); + ~TerrainManager(); + + void loadTerrain(Ogre::String filename); + +protected: + bool disableCaching; + bool mTerrainsImported; + Ogre::SceneManager *mSceneMgr; + int mapsizex, mapsizey, mapsizez, pageSize, terrainSize, worldSize; + Ogre::String baseName; + Ogre::ConfigFile terrainConfig; + int pageMinX, pageMaxX, pageMinY, pageMaxY; + int terrainLayers; + + // terrain engine specific + Ogre::TerrainGroup *mTerrainGroup; + Ogre::TerrainPaging* mTerrainPaging; + Ogre::PageManager* mPageManager; + Ogre::StringVector blendMaps, blendMode; + + void initTerrain(); + bool loadTerrainConfig(Ogre::String filename); + void configureTerrainDefaults(); + void defineTerrain(int x, int y, bool flat=false); + void initBlendMaps( Ogre::Terrain* t ); +}; +#endif // TERRAINMANAGER_H__ + + Property changes on: trunk/source/main/gameplay/TerrainManager.h ___________________________________________________________________ Added: svn:eol-style + native Modified: trunk/source/main/physics/Beam.cpp =================================================================== --- trunk/source/main/physics/Beam.cpp 2012-05-24 01:01:10 UTC (rev 2645) +++ trunk/source/main/physics/Beam.cpp 2012-05-24 13:46:55 UTC (rev 2646) @@ -183,7 +183,7 @@ , disableTruckTruckCollisions(false) , disableTruckTruckSelfCollisions(false) , pointCD(0) - , guiInitialized(false) + , GUIFeaturesChanged(false) { airbrakeval = 0; @@ -6022,12 +6022,19 @@ // set the features of this vehicle once - if(!guiInitialized) + if(!GUIFeaturesChanged) { bool hasEngine = (engine != 0); bool hasturbo = false; + bool autogearVisible = false; - dash->setEnabled(DD_ENGINE_TURBO, engine->hasturbo); + if(hasEngine) + { + hasturbo = engine->hasturbo; + autogearVisible = (engine->getAutoShift() == BeamEngine::MANUALMODE); + } + + dash->setEnabled(DD_ENGINE_TURBO, hasturbo); dash->setEnabled(DD_ENGINE_GEAR, hasEngine); dash->setEnabled(DD_ENGINE_NUM_GEAR, hasEngine); dash->setEnabled(DD_ENGINE_GEAR_STRING, hasEngine); @@ -6044,8 +6051,10 @@ dash->setEnabled(DD_TIES_MODE, !ties.empty()); dash->setEnabled(DD_LOCKED, !hooks.empty()); + dash->setEnabled(DD_ENGINE_AUTOGEAR_STRING, autogearVisible); + dash->updateFeatures(); - guiInitialized = true; + GUIFeaturesChanged = true; } // TODO: compass value @@ -6193,3 +6202,8 @@ return Vector3::ZERO; } + +void Beam::triggerGUIFeaturesChanged() +{ + GUIFeaturesChanged = true; +} Modified: trunk/source/main/physics/Beam.h =================================================================== --- trunk/source/main/physics/Beam.h 2012-05-24 01:01:10 UTC (rev 2645) +++ trunk/source/main/physics/Beam.h 2012-05-24 13:46:55 UTC (rev 2646) @@ -241,6 +241,7 @@ bool hasDriverSeat(); int calculateDriverPos(Ogre::Vector3 &pos, Ogre::Quaternion &rot); float getSteeringAngle(); + void triggerGUIFeaturesChanged(); float elevator; float rudder; @@ -472,7 +473,7 @@ // SLIDE NODES ///////////////////////////////////////////////////////////// //! true if SlideNodes are locked, false if not bool SlideNodesLocked; - bool guiInitialized; + bool GUIFeaturesChanged; /** @@ -494,7 +495,6 @@ * @return a pair containing the rail, and the distant to the SlideNode */ std::pair<RailGroup*, Ogre::Real> getClosestRailOnTruck( Beam* truck, const SlideNode& node); - }; 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