From 596628d339472e19864d7433675e1d4e146a04d2 Mon Sep 17 00:00:00 2001
From: scrawl <scrawl@baseoftrash.de>
Date: Mon, 4 Feb 2013 23:13:01 +0100
Subject: [PATCH 1/4] Fix terrain derived data update (bug 534, bug 544)

---
 apps/openmw/mwrender/terrain.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/apps/openmw/mwrender/terrain.cpp b/apps/openmw/mwrender/terrain.cpp
index e5a1362d7..5b24bbd45 100644
--- a/apps/openmw/mwrender/terrain.cpp
+++ b/apps/openmw/mwrender/terrain.cpp
@@ -3,6 +3,7 @@
 #include <OgreTerrain.h>
 #include <OgreTerrainGroup.h>
 #include <OgreHardwarePixelBuffer.h>
+#include <OgreRoot.h>
 
 #include "../mwworld/esmstore.hpp"
 
@@ -151,6 +152,16 @@ namespace MWRender
 
                     mTerrainGroup.loadTerrain(terrainX, terrainY, true);
 
+                    // when loading from a heightmap, Ogre::Terrain does not update the derived data (normal map, LOD)
+                    // synchronously, even if we supply synchronous = true parameter to loadTerrain.
+                    // the following to be the only way to make sure derived data is ready when rendering the next frame.
+                    while (mTerrainGroup.isDerivedDataUpdateInProgress())
+                    {
+                       // we need to wait for this to finish
+                       OGRE_THREAD_SLEEP(5);
+                       Root::getSingleton().getWorkQueue()->processResponses();
+                    }
+
                     Terrain* terrain = mTerrainGroup.getTerrain(terrainX, terrainY);
                     initTerrainBlendMaps(terrain,
                                          cellX, cellY,

From 58cf182db2df6e47e8e98e35c2c49d157857c88b Mon Sep 17 00:00:00 2001
From: scrawl <scrawl@baseoftrash.de>
Date: Tue, 5 Feb 2013 00:21:29 +0100
Subject: [PATCH 2/4] better place for syncing

---
 apps/openmw/mwrender/terrain.cpp | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/apps/openmw/mwrender/terrain.cpp b/apps/openmw/mwrender/terrain.cpp
index 5b24bbd45..f4ad261c5 100644
--- a/apps/openmw/mwrender/terrain.cpp
+++ b/apps/openmw/mwrender/terrain.cpp
@@ -152,16 +152,6 @@ namespace MWRender
 
                     mTerrainGroup.loadTerrain(terrainX, terrainY, true);
 
-                    // when loading from a heightmap, Ogre::Terrain does not update the derived data (normal map, LOD)
-                    // synchronously, even if we supply synchronous = true parameter to loadTerrain.
-                    // the following to be the only way to make sure derived data is ready when rendering the next frame.
-                    while (mTerrainGroup.isDerivedDataUpdateInProgress())
-                    {
-                       // we need to wait for this to finish
-                       OGRE_THREAD_SLEEP(5);
-                       Root::getSingleton().getWorkQueue()->processResponses();
-                    }
-
                     Terrain* terrain = mTerrainGroup.getTerrain(terrainX, terrainY);
                     initTerrainBlendMaps(terrain,
                                          cellX, cellY,
@@ -189,6 +179,16 @@ namespace MWRender
             }
         }
 
+        // when loading from a heightmap, Ogre::Terrain does not update the derived data (normal map, LOD)
+        // synchronously, even if we supply synchronous = true parameter to loadTerrain.
+        // the following to be the only way to make sure derived data is ready when rendering the next frame.
+        while (mTerrainGroup.isDerivedDataUpdateInProgress())
+        {
+           // we need to wait for this to finish
+           OGRE_THREAD_SLEEP(5);
+           Root::getSingleton().getWorkQueue()->processResponses();
+        }
+
         mTerrainGroup.freeTemporaryResources();
     }
 

From 3fe5757770b9abecd02cbb288f371c8208f92892 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Tue, 5 Feb 2013 10:28:49 +0100
Subject: [PATCH 3/4] updated changelog for 0.21.0 again

---
 readme.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/readme.txt b/readme.txt
index 91690ff57..3124744c3 100644
--- a/readme.txt
+++ b/readme.txt
@@ -114,8 +114,10 @@ Bug #521: MWGui::InventoryWindow creates a duplicate player actor at the origin
 Bug #524: Beast races are able to wear shoes
 Bug #527: Background music fails to play
 Bug #533: The arch at Gnisis entrance is not displayed
+Bug #534: Terrain gets its correct shape only some time after the cell is loaded
 Bug #536: The same entry can be added multiple times to the journal
 Bug #539: Race selection is broken
+Bug #544: Terrain normal map corrupt when the map is rendered
 Feature #39: Video Playback
 Feature #151: ^-escape sequences in text output
 Feature #392: Add AI related script functions

From cfceb450095db1ea1a8d91c21f86ecc81a85c6b1 Mon Sep 17 00:00:00 2001
From: Marc Zinnschlag <marc@zpages.de>
Date: Tue, 5 Feb 2013 11:53:48 +0100
Subject: [PATCH 4/4] adjusted gcc settings again to avoid problems with older
 compiler versions

---
 CMakeLists.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 165db6b79..577b6f6b2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -306,7 +306,7 @@ endif()
 
 # Compiler settings
 if (CMAKE_COMPILER_IS_GNUCC)
-    add_definitions (-Wall -Wextra -Wno-unused-parameter -Wno-reorder -std=c++03 -pedantic -Wno-long-long)
+    add_definitions (-Wall -Wextra -Wno-unused-parameter -Wno-reorder -std=c++98 -pedantic -Wno-long-long)
 
     # Silence warnings in OGRE headers. Remove once OGRE got fixed!
     add_definitions (-Wno-ignored-qualifiers)