[GSoC 2012 - Accepted] Improve and Demo the Terrain System

Threads related to Google Summer of Code
Post Reply
User avatar
Xplodwild
Goblin
Posts: 231
Joined: Thu Feb 12, 2009 3:49 pm
Location: France
Contact:

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by Xplodwild » Tue Sep 25, 2012 8:07 am

I just updated to latest v1-9 branch and encountering a weird issue. In my editor (powered by Qt), I use this piece of code to load my terrain files:

Code: Select all

if (loadFromFile != "")
                mTerrainGroup->defineTerrain(x,y,loadFromFile);
        else
                mTerrainGroup->defineTerrain(node->getX(), node->getY(), &node->getImportData());

        Ogre::Terrain* t = 0;

        if (loadFromFile != "")
        {
                mTerrainGroup->loadTerrain(x, y, true);
                t = mTerrainGroup->getTerrain(x, y);
        }
loadTerrain is called with the synchronous parameter, and it's hanging there. The program freezes, and pausing it doesn't give any stack in my code (ntdll and such).
I tried to workaround this way:

Code: Select all

mTerrainGroup->loadTerrain(x, y, false);
while (!mTerrainGroup->getTerrain(x,y)->isLoaded()) {
    qApp->processEvents();
}
to allow the Ogre widget to update, thus render, and eventually fire some thread events. No luck there either, it freezes in the "getTerrain" call, nothing happens.

Was there changes done there? Do I need to use it in a different way?
0 x

xiaoxiangquan
Google Summer of Code Student
Google Summer of Code Student
Posts: 102
Joined: Tue Mar 20, 2012 3:20 am
Location: China

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by xiaoxiangquan » Tue Sep 25, 2012 2:09 pm

Xplodwild wrote:I just updated to latest v1-9 branch and encountering a weird issue. In my editor (powered by Qt), I use this piece of code to load my terrain files:
to allow the Ogre widget to update, thus render, and eventually fire some thread events. No luck there either, it freezes in the "getTerrain" call, nothing happens.
Was there changes done there? Do I need to use it in a different way?
I cannot reproduce it, but it seems like a bug I fixed recently.
Maybe you can try my fork: https://bitbucket.org/xiaoxq/ogre_soc_tpi
Or just take a look at this patch: https://bitbucket.org/xiaoxq/ogre_soc_t ... errain.cpp
0 x
Google Summer of Code 2012 Student
Topic: "Improve and Demo the Terrain System"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: masterfalcon

User avatar
Xplodwild
Goblin
Posts: 231
Joined: Thu Feb 12, 2009 3:49 pm
Location: France
Contact:

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by Xplodwild » Wed Sep 26, 2012 8:30 pm

No luck either. I built Ogre in RelWithDebInfo, and step-by-stepped inside the work done by loadTerrain when synchronous is enabled. It seems like there's some threading issues: The freeze occurs in OgreWorkQueue::processResponse (line 460) when work is added in OgreWorkQueue by Ogre::TerrainGroup::loadTerrainImpl.
I'm going to investigate to see what's blocking.

Seems like error is right in front of me since the beginning :P seeing some LogManager calls, here's what the log gives me:

Code: Select all

21:32:10: DefaultWorkQueueBase('Root') - QUEUED(thread:1684): ID=1 channel=1 requestType=1
21:32:16: DefaultWorkQueueBase('Root') - PROCESS_REQUEST_START(1684): ID=1 channel=1 requestType=1
21:32:16: OGRE EXCEPTION(1:InvalidStateException): Cannot determine endian mode because header is missing in StreamSerialiser::readHeader at ..\..\OgreMain\src\OgreStreamSerialiser.cpp (line 238)
21:32:16: DefaultWorkQueueBase('Root') - PROCESS_REQUEST_END(1684): ID=1 channel=1 requestType=1 processed=1
21:32:33: DefaultWorkQueueBase('Root') - PROCESS_RESPONSE_START(thread:1684): ID=1 success=0 messages=[OGRE EXCEPTION(1:InvalidStateException): Cannot determine endian mode because header is missing in StreamSerialiser::readHeader at ..\..\OgreMain\src\OgreStreamSerialiser.cpp (line 238)] channel=1 requestType=1
21:33:24: We failed to prepare the terrain at (0, 0) with the error 'OGRE EXCEPTION(1:InvalidStateException): Cannot determine endian mode because header is missing in StreamSerialiser::readHeader at ..\..\OgreMain\src\OgreStreamSerialiser.cpp (line 238)'
Edit: Ok - seems to work with newly created terrains. However, those terrain tiles I'm loading were always working, even restoring the stable files doesn't fix it. Also, it shouldn't be freezing the full program.
0 x

User avatar
duststorm
Minaton
Posts: 921
Joined: Sat Jul 31, 2010 6:29 pm
Location: Belgium
Contact:

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by duststorm » Thu Sep 27, 2012 4:12 pm

Xplodwild wrote:Edit: Ok - seems to work with newly created terrains. However, those terrain tiles I'm loading were always working, even restoring the stable files doesn't fix it. Also, it shouldn't be freezing the full program.
Maybe it has something to do with those old tiles being saved with non-compressed vertices. That makes them a lot more data, thus more IO time. Maybe that has something to do with it.
With Ogre 1.8 newly created terrain tiles will have vertex compression enabled automatically, only disabling it when you indicate to do so explicitly.
0 x
Developer @ MakeHuman.org

PacoRG
Kobold
Posts: 26
Joined: Fri May 23, 2008 10:46 pm
Location: Spain

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by PacoRG » Sun Sep 30, 2012 12:35 pm

Hi Xiao,

I just tested the last revision. The EndlessWorld Sample works fine, however, when a finite world is used I get a crash when the second terrain page is loaded from the disk. If the terrain is an only page all works fine. I have modified conveniently the sample in order to test this.

The crash occurs in TerrainQuadtreeNode::updateVertexData.

Thanks,
0 x
Paco, Spain

xiaoxiangquan
Google Summer of Code Student
Google Summer of Code Student
Posts: 102
Joined: Tue Mar 20, 2012 3:20 am
Location: China

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by xiaoxiangquan » Sun Sep 30, 2012 12:40 pm

PacoRG wrote:Hi Xiao,

I just tested the last revision. The EndlessWorld Sample works fine, however, when a finite world is used I get a crash when the the second terrain page is loaded from the disk. If the terrain is an only page all works fine. I have modified conveniently the sample in order to test this.

The crash occurs in TerrainQuadtreeNode::updateVertexData.
Thank you for feedback. I'll deal with it right now. I have just got a week free :D
0 x
Google Summer of Code 2012 Student
Topic: "Improve and Demo the Terrain System"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: masterfalcon

xiaoxiangquan
Google Summer of Code Student
Google Summer of Code Student
Posts: 102
Joined: Tue Mar 20, 2012 3:20 am
Location: China

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by xiaoxiangquan » Tue Oct 02, 2012 8:50 am

PacoRG wrote:Hi Xiao,

I just tested the last revision. The EndlessWorld Sample works fine, however, when a finite world is used I get a crash when the second terrain page is loaded from the disk. If the terrain is an only page all works fine. I have modified conveniently the sample in order to test this.

The crash occurs in TerrainQuadtreeNode::updateVertexData.

Thanks,
Could you send me your modified sample code?
I just cannot reach the crash.
0 x
Google Summer of Code 2012 Student
Topic: "Improve and Demo the Terrain System"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: masterfalcon

PacoRG
Kobold
Posts: 26
Joined: Fri May 23, 2008 10:46 pm
Location: Spain

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by PacoRG » Tue Oct 02, 2012 7:33 pm

Hi Xiao,

The sample code:

Code: Select all

/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/

Copyright (c) 2000-2012 Torus Knot Software Ltd
Also see acknowledgements in Readme.html

You may use this sample code for anything you like, it is not covered by the
same license as the rest of the engine.
-----------------------------------------------------------------------------
*/
#ifndef __EndlessWorld_H__
#define __EndlessWorld_H__

//#define PAGING
//#define ENDLESS

#ifdef ENDLESS 
	// max range for a int16
	#define TERRAIN_PAGE_MIN_X (-0x7FFF)
	#define TERRAIN_PAGE_MIN_Y (-0x7FFF)
	#define TERRAIN_PAGE_MAX_X 0x7FFF
	#define TERRAIN_PAGE_MAX_Y 0x7FFF
#else
	#define TERRAIN_PAGE_MIN_X -1
	#define TERRAIN_PAGE_MIN_Y -1
	#define TERRAIN_PAGE_MAX_X 1
	#define TERRAIN_PAGE_MAX_Y 1
#endif

#include "SdkSample.h"
#include "OgreTerrain.h"
#include "OgreTerrainGroup.h"
#include "OgreTerrainQuadTreeNode.h"
#include "OgreTerrainMaterialGeneratorA.h"
#include "OgreTerrainPagedWorldSection.h"
#include "OgreTerrainPaging.h"
#include "PerlinNoiseTerrainGenerator.h"

#define TERRAIN_FILE_PREFIX String("EndlessWorldTerrain")
#define TERRAIN_FILE_SUFFIX String("dat")
#define TERRAIN_WORLD_SIZE 12000.0f
#define TERRAIN_SIZE 513
#define HOLD_LOD_DISTANCE 3000.0

using namespace Ogre;
using namespace OgreBites;

class _OgreSampleClassExport Sample_EndlessWorld : public SdkSample
{
public:

	Sample_EndlessWorld()
		: mTerrainGroup(0)
		, mTerrainPaging(0)
		, mPageManager(0)
		, mPagedWorld(0)
		, mTerrainPagedWorldSection(0)
		, mPerlinNoiseTerrainGenerator(0)
        , mLodStatus(false)
		, mAutoLod(true)
		, mFly(true)
		, mFallVelocity(0)
        , mTerrainPos(0,0,0)

	{
		mInfo["Title"] = "Endless World";
		mInfo["Description"] = "Demonstrates use of the terrain plugin with paging option.";
		mInfo["Thumbnail"] = "thumb_terrain.png";
		mInfo["Category"] = "Environment";
		mInfo["Help"] = "Left click and drag anywhere in the scene to look around. Let go again to show "
			"cursor and access widgets. Use WASD keys to move. You can increase/decrease terrains' LOD level using Page Up/Page Down."
			"Use G to generate another random terrain";
	}

    void testCapabilities(const RenderSystemCapabilities* caps)
	{
        if (!caps->hasCapability(RSC_VERTEX_PROGRAM) || !caps->hasCapability(RSC_FRAGMENT_PROGRAM))
        {
			OGRE_EXCEPT(Exception::ERR_NOT_IMPLEMENTED, "Your graphics card does not support vertex or fragment shaders, "
                        "so you cannot run this sample. Sorry!", "Sample_EndlessWorld::testCapabilities");
        }
	}
    
	StringVector getRequiredPlugins()
	{
		StringVector names;
		return names;
	}

    bool frameRenderingQueued(const FrameEvent& evt)
    {
		if (!mFly)
		{
			// clamp to terrain
			Vector3 camPos = mCamera->getPosition();
			Ray ray;
			ray.setOrigin(Vector3(camPos.x, mTerrainPos.y + 10000, camPos.z));
			ray.setDirection(Vector3::NEGATIVE_UNIT_Y);

			TerrainGroup::RayResult rayResult = mTerrainGroup->rayIntersects(ray);
			const Real distanceAboveTerrain = 50;
			if (rayResult.hit)
				mCamera->setPosition(camPos.x, rayResult.position.y + distanceAboveTerrain, camPos.z);
		}

		if (mTerrainGroup->isDerivedDataUpdateInProgress())
		{
			mTrayMgr->moveWidgetToTray(mInfoLabel, TL_TOP, 0);
			mInfoLabel->show();
			mInfoLabel->setCaption("Building terrain...");
		}
		else
		{
			mTrayMgr->removeWidgetFromTray(mInfoLabel);
			mInfoLabel->hide();
		}

		if (mLodStatus)
		{
			for(LabelList::iterator li = mLodStatusLabelList.begin(); li != mLodStatusLabelList.end(); li++)
			{
				mLodInfoOverlayContainer->_removeChild(*li);
				OverlayManager::getSingleton().destroyOverlayElement(*li);
			}
			mLodStatusLabelList.clear();

			TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
			while(ti.hasMoreElements())
			{
				Terrain* t = ti.getNext()->instance;
				if (!t)
					continue;

				Vector3 pt = mCamera->getProjectionMatrix() * (mCamera->getViewMatrix() * t->getPosition());
				Real x = (pt.x / 2) + 0.5f;
				Real y = 1 - ((pt.y / 2) + 0.5f);

				String lName = StringConverter::toString((unsigned long)(t))+"/"+"LodInfoLabel";

				OverlayElement *l = OverlayManager::getSingleton().createOverlayElement("TextArea", lName);
				l->setCaption("Target="+StringConverter::toString(t->getTargetLodLevel())+"\nHighest="+
					  StringConverter::toString(t->getHighestLodLoaded())+"\nPrepared="+
					  StringConverter::toString(t->getHighestLodPrepared())
					  );
				l->setPosition(x, y);
				l->setDimensions(0.1, 0.1);  // center text in label and its position
				l->setParameter("font_name", "StarWars");
				l->setParameter("char_height", "0.02f");
				l->setColour(ColourValue(1.0,0.0,0.0));

				mLodInfoOverlayContainer->addChild(l);
				mLodStatusLabelList.push_back(l);
			}
		}

		mTerrainGroup->autoUpdateLodAll(false, Any( Real(HOLD_LOD_DISTANCE) ));
		return SdkSample::frameRenderingQueued(evt);  // don't forget the parent updates!
    }

	bool keyPressed (const OIS::KeyEvent &e)
	{
#if OGRE_PLATFORM != OGRE_PLATFORM_APPLE_IOS
		switch (e.key)
		{
		case OIS::KC_S:
			// CTRL-S to save
			if (mKeyboard->isKeyDown(OIS::KC_LCONTROL) || mKeyboard->isKeyDown(OIS::KC_RCONTROL))
			{
				mTerrainGroup->saveAllTerrains(true);
			}
			else
				return SdkSample::keyPressed(e);
			break;
		case OIS::KC_LSHIFT:
		case OIS::KC_RSHIFT:
			mCameraMan->setTopSpeed(1000);

			break;
		case OIS::KC_PGUP:
			{
				mAutoBox->setChecked(false);
				TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
				while(ti.hasMoreElements())
				{
					Terrain* t = ti.getNext()->instance;
					if (t)
						t->increaseLodLevel();
				}
			}
			break;
		case OIS::KC_PGDOWN:
			{
				mAutoBox->setChecked(false);
				TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
				while(ti.hasMoreElements())
				{
					Terrain* t = ti.getNext()->instance;
					if (t)
						t->decreaseLodLevel();
				}
			}
			break;
		// generate new random offset, to make terrains different
		case OIS::KC_G:
			if(mPerlinNoiseTerrainGenerator)
			{
				// random a new origin point
				mPerlinNoiseTerrainGenerator->randomize();

				// reload all terrains
				TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
				while(ti.hasMoreElements())
				{
					TerrainGroup::TerrainSlot* slot = ti.getNext();
					PageID pageID = mTerrainGroup->packIndex( slot->x, slot->y );
					mTerrainPagedWorldSection->unloadPage(pageID);
					mTerrainPagedWorldSection->loadPage(pageID);
				}
			}
			break;
		default:
			return SdkSample::keyPressed(e);
		}
#endif

		return true;
	}

	void checkBoxToggled(CheckBox* box)
	{
		if (box == mFlyBox)
		{
			mFly = mFlyBox->isChecked();
		}
		else if (box == mLodStatusBox)
		{
			mLodStatus = mLodStatusBox->isChecked();
			if (!mLodStatus)
			{
				for(LabelList::iterator li = mLodStatusLabelList.begin(); li != mLodStatusLabelList.end(); li++)
				{
					mLodInfoOverlayContainer->_removeChild(*li);
					OverlayManager::getSingleton().destroyOverlayElement(*li);
				}
				mLodStatusLabelList.clear();
			}
		}
		else if (box == mAutoBox)
		{
			if( mTerrainGroup )
			{
				if(!mAutoLod && mAutoBox->isChecked())
				{
					mTerrainGroup->setAutoUpdateLod( TerrainAutoUpdateLodFactory::getAutoUpdateLod(BY_DISTANCE) );
					mAutoLod = true;
				}
				else if(mAutoLod && !mAutoBox->isChecked())
				{
					mTerrainGroup->setAutoUpdateLod( TerrainAutoUpdateLodFactory::getAutoUpdateLod(NONE) );  // Why? Changed in last revision
					mAutoLod = false;
				}
			}
		}
	}

protected:

	TerrainGlobalOptions* mTerrainGlobals;
	TerrainGroup* mTerrainGroup;
	TerrainPaging* mTerrainPaging;
	PageManager* mPageManager;
	PagedWorld* mPagedWorld;
	TerrainPagedWorldSection* mTerrainPagedWorldSection;
	PerlinNoiseTerrainGenerator* mPerlinNoiseTerrainGenerator;
	bool mLodStatus;
	bool mAutoLod;

	/// This class just pretends to provide procedural page content to avoid page loading
	class DummyPageProvider : public PageProvider
	{
	public:
		bool prepareProceduralPage(Page* page, PagedWorldSection* section) { return true; }
		bool loadProceduralPage(Page* page, PagedWorldSection* section) { return true; }
		bool unloadProceduralPage(Page* page, PagedWorldSection* section) { return true; }
		bool unprepareProceduralPage(Page* page, PagedWorldSection* section) { return true; }
	};
	DummyPageProvider mDummyPageProvider;

	bool mFly;
	Real mFallVelocity;
	Vector3 mTerrainPos;
	CheckBox* mFlyBox;
	OgreBites::Label* mInfoLabel;

	typedef std::list<OverlayElement*> LabelList;
	LabelList mLodStatusLabelList;

	Overlay *mLodInfoOverlay;
	OverlayContainer *mLodInfoOverlayContainer;

	CheckBox *mLodStatusBox;
	CheckBox *mAutoBox;

	void configureTerrainDefaults(Light* l)
	{
		// Configure global
		mTerrainGlobals->setMaxPixelError(8);
		// testing composite map
		mTerrainGlobals->setCompositeMapDistance(3000);
		//mTerrainGlobals->setUseRayBoxDistanceCalculation(true);
		mTerrainGlobals->getDefaultMaterialGenerator()->setLightmapEnabled(false);

		mTerrainGlobals->setCompositeMapAmbient(mSceneMgr->getAmbientLight());
		//mTerrainGlobals->setCompositeMapAmbient(ColourValue::Red);
		mTerrainGlobals->setCompositeMapDiffuse(l->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;
		defaultimp.inputScale = 600;
		defaultimp.minBatchSize = 33;
		defaultimp.maxBatchSize = 65;
		// textures
		defaultimp.layerList.resize(3);
		defaultimp.layerList[0].worldSize = 100;
		defaultimp.layerList[0].textureNames.push_back("dirt_grayrocky_diffusespecular.dds");
		defaultimp.layerList[0].textureNames.push_back("dirt_grayrocky_normalheight.dds");
		defaultimp.layerList[1].worldSize = 30;
		defaultimp.layerList[1].textureNames.push_back("grass_green-01_diffusespecular.dds");
		defaultimp.layerList[1].textureNames.push_back("grass_green-01_normalheight.dds");
		defaultimp.layerList[2].worldSize = 200;
		defaultimp.layerList[2].textureNames.push_back("growth_weirdfungus-03_diffusespecular.dds");
		defaultimp.layerList[2].textureNames.push_back("growth_weirdfungus-03_normalheight.dds");
	}

	/*-----------------------------------------------------------------------------
	| Extends setupView to change some initial camera settings for this sample.
	-----------------------------------------------------------------------------*/
	void setupView()
	{
		SdkSample::setupView();
		// put camera at world center, so that it's difficult to reach the edge
		Vector3 worldCenter(
			(TERRAIN_PAGE_MAX_X+TERRAIN_PAGE_MIN_X) / 2 * TERRAIN_WORLD_SIZE,
			0,
			-(TERRAIN_PAGE_MAX_Y+TERRAIN_PAGE_MIN_Y) / 2 * TERRAIN_WORLD_SIZE
			);
		mCamera->setPosition( mTerrainPos+worldCenter );
		mCamera->lookAt(mTerrainPos);
		mCamera->setNearClipDistance(0.1);
		mCamera->setFarClipDistance(50000);

		if (mRoot->getRenderSystem()->getCapabilities()->hasCapability(RSC_INFINITE_FAR_PLANE))
        {
            mCamera->setFarClipDistance(0);   // enable infinite far clip distance if we can
        }
	}

	void setupControls()
	{
		mTrayMgr->showCursor();

		// make room for the controls
		mTrayMgr->showLogo(TL_TOPRIGHT);
		mTrayMgr->showFrameStats(TL_TOPRIGHT);
		mTrayMgr->toggleAdvancedFrameStats();

		mInfoLabel = mTrayMgr->createLabel(TL_TOP, "TInfo", "", 350);

		mFlyBox = mTrayMgr->createCheckBox(TL_BOTTOM, "Fly", "Fly");
		mFlyBox->setChecked(false, true);

		mLodStatusBox = mTrayMgr->createCheckBox(TL_BOTTOM, "LODStatus", "LOD Status");
		mLodStatusBox->setChecked(false, true);

		mAutoBox = mTrayMgr->createCheckBox(TL_BOTTOM, "LODAuto", "Auto LOD");
		mAutoBox->setChecked(true, true);

		// a friendly reminder
		StringVector names;
		names.push_back("Help");
		mTrayMgr->createParamsPanel(TL_TOPLEFT, "Help", 100, names)->setParamValue(0, "H/F1");
	}

	class SimpleTerrainDefiner : public TerrainPagedWorldSection::TerrainDefiner
	{
	public:
		virtual void define(TerrainGroup* terrainGroup, long x, long y)
		{
			Image img;
			img.load("terrain.png", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
			if (x % 2)
				img.flipAroundY();
			if (y % 2)
				img.flipAroundX();
			terrainGroup->defineTerrain(x, y, &img);
		}
	};

	void setupContent()
	{
		mTerrainGlobals = OGRE_NEW TerrainGlobalOptions();

		setupControls();
		mCameraMan->setTopSpeed(100);

		setDragLook(true);

		MaterialManager::getSingleton().setDefaultTextureFiltering(TFO_ANISOTROPIC);
		MaterialManager::getSingleton().setDefaultAnisotropy(7);

		mSceneMgr->setFog(FOG_LINEAR, ColourValue(0.7, 0.7, 0.8), 0, 4000, 10000);

		LogManager::getSingleton().setLogDetail(LL_BOREME);

		Vector3 lightdir(0.55, -0.3, 0.75);
		lightdir.normalise();


		Light* l = mSceneMgr->createLight("tstLight");
		l->setType(Light::LT_DIRECTIONAL);
		l->setDirection(lightdir);
		l->setDiffuseColour(ColourValue::White);
		l->setSpecularColour(ColourValue(0.4, 0.4, 0.4));

		mSceneMgr->setAmbientLight(ColourValue(0.2, 0.2, 0.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->setAutoUpdateLod( TerrainAutoUpdateLodFactory::getAutoUpdateLod(BY_DISTANCE) );

		configureTerrainDefaults(l);

		// 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);
		mPageManager->setDebugDisplayLevel(0);
		mTerrainPaging = OGRE_NEW TerrainPaging(mPageManager);
		mPagedWorld = mPageManager->createWorld();
		mTerrainPagedWorldSection = mTerrainPaging->createWorldSection(mPagedWorld, mTerrainGroup, 400, 500, 
			TERRAIN_PAGE_MIN_X, TERRAIN_PAGE_MIN_Y, 
			TERRAIN_PAGE_MAX_X, TERRAIN_PAGE_MAX_Y);

#ifdef ENDLESS
		mPerlinNoiseTerrainGenerator = OGRE_NEW PerlinNoiseTerrainGenerator;
		mTerrainPagedWorldSection->setDefiner( mPerlinNoiseTerrainGenerator );
#else
	#ifndef PAGING
			mTerrainPagedWorldSection->setDefiner( OGRE_NEW SimpleTerrainDefiner );
	#endif
#endif

		mTerrainGroup->freeTemporaryResources();

		mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");

		// setup LOD info overlay
		mLodInfoOverlay = OverlayManager::getSingleton().create("LODInfoOverlay");

		mLodInfoOverlay->setZOrder(10);
		mLodInfoOverlayContainer = (OverlayContainer*)OverlayManager::getSingleton().createOverlayElement("Panel", "LODInfoOverlayPanel");
		mLodInfoOverlayContainer->setDimensions(1.0, 1.0);
		mLodInfoOverlayContainer->setPosition(0.0, 0.0);

		mLodInfoOverlay->add2D(mLodInfoOverlayContainer);
		mLodInfoOverlay->show();
	}

	void _shutdown()
	{
		if(mTerrainPaging)
		{
			OGRE_DELETE mTerrainPaging;
			mPageManager->destroyWorld( mPagedWorld );
			OGRE_DELETE mPageManager;
		}
		OGRE_DELETE mTerrainGlobals;
		
		for(LabelList::iterator li = mLodStatusLabelList.begin(); li != mLodStatusLabelList.end(); li++)
		{
			mLodInfoOverlayContainer->_removeChild(*li);
			OverlayManager::getSingleton().destroyOverlayElement(*li);
		}
		mLodStatusLabelList.clear();

		OverlayManager::getSingleton().destroy(mLodInfoOverlay);
		OverlayManager::getSingleton().destroyOverlayElement(mLodInfoOverlayContainer);

		SdkSample::_shutdown();
	}
};

#endif
The sequence is the following:

1- With the commented statements:
//#define PAGING
//#define ENDLESS
compile and run.

2. When the 3x3 terrain pages are built save all terrains with CTRL+S.

3 When the terrain pages are saved exit.

4. Uncoment the statement
#define PAGING
compile an run.

When the second page is loading the crash occurs.

I hope this to be usefull.
0 x
Paco, Spain

xiaoxiangquan
Google Summer of Code Student
Google Summer of Code Student
Posts: 102
Joined: Tue Mar 20, 2012 3:20 am
Location: China

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by xiaoxiangquan » Thu Oct 04, 2012 4:11 pm

PacoRG wrote:Hi Xiao,
When the second page is loading the crash occurs.
I hope this to be usefull.
Fixed.
It's because that the LodManager will call Terrain::updateGeometry() when just streamed in new data, which will notify neighbours to update geometry.
Then if more than two linked terrains are updated at once, it'll becomes a circle, and the process is out of control, which always causes a null pointer exception.

Now when updating LOD, we'll just update the geometry without notifying neighbours. It's reasonable and all seems well so far.
0 x
Google Summer of Code 2012 Student
Topic: "Improve and Demo the Terrain System"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: masterfalcon

noorus
Halfling
Posts: 75
Joined: Wed Apr 20, 2011 9:55 pm
Location: Helsinki, Finland

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by noorus » Fri Jan 04, 2013 2:26 pm

Hi,
there's a problem in the current 1.9 terrain component, when loading terrain data from a custom stream, instead of its own file.
Please see here: https://ogre3d.atlassian.net/browse/OGRE-118
0 x
Creator of Nice Input Library, for your advanced input needs.
Image

xiaoxiangquan
Google Summer of Code Student
Google Summer of Code Student
Posts: 102
Joined: Tue Mar 20, 2012 3:20 am
Location: China

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by xiaoxiangquan » Fri Jan 04, 2013 2:37 pm

noorus wrote:Hi,
there's a problem in the current 1.9 terrain component, when loading terrain data from a custom stream, instead of its own file.
Please see here: https://ogre3d.atlassian.net/browse/OGRE-118
Yes, I indeed only considered reading from a *standard* terrain data file.
I'll have a look at the problem. Thank you for feedback!
0 x
Google Summer of Code 2012 Student
Topic: "Improve and Demo the Terrain System"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: masterfalcon

noorus
Halfling
Posts: 75
Joined: Wed Apr 20, 2011 9:55 pm
Location: Helsinki, Finland

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by noorus » Sat Jan 05, 2013 3:40 am

Hi xiaoxiangquan,
I also have this problem, even if I'm loading from a terrain-only file, where my terrain comes in as completely flat.
I'm not sure if the problem is in the saving or the loading, but in my editor I can create and modify a terrain just fine, and save it, but when I load the saved data, the terrain is flat. The textures work fine, but height is all zeroes.
Any idea what could be wrong? I'm basically only doing

Code: Select all

  new TerrainAutoUpdateLodByDistance
  new Terrain
  terrain->prepare( filename )
  terrain->load()
  terrain->freetemporaryresources()
  terrain->setposition()
  loop {
    lodstrategy->autoUpdateLod( terrain, false, Ogre::Any( 50.0f ) )
  }
This used to work fine in the pre-lod/pre-paging Terrain. I've only added the LoD strategy after that, but it didn't help.
0 x
Creator of Nice Input Library, for your advanced input needs.
Image

xiaoxiangquan
Google Summer of Code Student
Google Summer of Code Student
Posts: 102
Joined: Tue Mar 20, 2012 3:20 am
Location: China

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by xiaoxiangquan » Tue Mar 05, 2013 4:27 am

noorus wrote:Hi xiaoxiangquan,
I also have this problem, even if I'm loading from a terrain-only file, where my terrain comes in as completely flat.
I'm not sure if the problem is in the saving or the loading, but in my editor I can create and modify a terrain just fine, and save it, but when I load the saved data, the terrain is flat. The textures work fine, but height is all zeroes.
Any idea what could be wrong? I'm basically only doing
This used to work fine in the pre-lod/pre-paging Terrain. I've only added the LoD strategy after that, but it didn't help.
I'm terribly sorry that it has been so long and I still cannot make enough time to fix these bugs.
It's hard days. I have to revise my paper even on the very day of Chinese New Year.
About 4 months later, I should start looking for my first job, game-dev related, in US or Europe I think. So, time to practice oral English and review some algorithms.

I have ever participated in GSoC 2011 (@Blender) and 2012, but obviously don't have time for 2013. So I hope that with my experience I can work as a volunteer here to help the new comers :)

Regards!
0 x
Google Summer of Code 2012 Student
Topic: "Improve and Demo the Terrain System"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: masterfalcon

xiaoxiangquan
Google Summer of Code Student
Google Summer of Code Student
Posts: 102
Joined: Tue Mar 20, 2012 3:20 am
Location: China

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by xiaoxiangquan » Wed Apr 10, 2013 4:29 am

I have got some time free for the summer, finally. I'll keep on working my fork then. :D

And, congrats to Ogre for participating in another gsoc successfully!
0 x
Google Summer of Code 2012 Student
Topic: "Improve and Demo the Terrain System"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: masterfalcon

User avatar
Naman Gupta
Gnoblar
Posts: 14
Joined: Wed Feb 22, 2012 6:15 pm
Location: Meerut, India
Contact:

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by Naman Gupta » Fri Apr 12, 2013 3:23 am

Hey xiaoxiangquan, I'd like to know what were the implementations that you were looking forward to in this project, but couldn't due to time constrain.
0 x
-naman-

xiaoxiangquan
Google Summer of Code Student
Google Summer of Code Student
Posts: 102
Joined: Tue Mar 20, 2012 3:20 am
Location: China

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by xiaoxiangquan » Fri Apr 12, 2013 6:37 am

Naman Gupta wrote:Hey xiaoxiangquan, I'd like to know what were the implementations that you were looking forward to in this project, but couldn't due to time constrain.
Just some bugs. They are all reported in this page ->
by noorus » Fri Jan 04, 2013 9:26 pm ( https://ogre3d.atlassian.net/browse/OGRE-118 )
by noorus » Sat Jan 05, 2013 10:40 am

They seems to be imported by my work in gsoc 2012, so I'm always trying to fix.
0 x
Google Summer of Code 2012 Student
Topic: "Improve and Demo the Terrain System"
Project links: Project thread, WIKI page, Code fork for the project
Mentor: masterfalcon

User avatar
jacmoe
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 20570
Joined: Thu Jan 22, 2004 10:13 am
Location: Denmark
Contact:

Re: [GSoC 2012 - Accepted] Improve and Demo the Terrain Syst

Post by jacmoe » Mon Apr 15, 2013 9:58 pm

Xplodwild wrote:No luck either. I built Ogre in RelWithDebInfo, and step-by-stepped inside the work done by loadTerrain when synchronous is enabled. It seems like there's some threading issues: The freeze occurs in OgreWorkQueue::processResponse (line 460) when work is added in OgreWorkQueue by Ogre::TerrainGroup::loadTerrainImpl.
I'm going to investigate to see what's blocking.
...
Edit: Ok - seems to work with newly created terrains. However, those terrain tiles I'm loading were always working, even restoring the stable files doesn't fix it. Also, it shouldn't be freezing the full program.
The problem is that Ogre can't figure out how to upgrade to the new format.

However, Ismail 'stealth977' Tarim has written a converter from old to new binary terrain format:
https://bitbucket.org/jacmoe/ogitor/src ... at=default

We use it to auto-upgrade Ogitor scenes. :)
0 x
/* Less noise. More signal. */
Ogitor Scenebuilder - powered by Ogre, presented by Qt, fueled by Passion.
OgreAddons - the Ogre code suppository.

Post Reply