Explorar el Código

Fixed terrain live reload in the editor.

Lasse Öörni hace 13 años
padre
commit
40f91c7399
Se han modificado 3 ficheros con 30 adiciones y 21 borrados
  1. 27 20
      Engine/Graphics/Terrain.cpp
  2. 2 0
      Engine/Graphics/Terrain.h
  3. 1 1
      Engine/IO/FileWatcher.cpp

+ 27 - 20
Engine/Graphics/Terrain.cpp

@@ -150,23 +150,10 @@ void Terrain::SetPatchSize(unsigned size)
 
 bool Terrain::SetHeightMap(Image* image)
 {
-    if (image && image->IsCompressed())
-    {
-        LOGERROR("Can not use a compressed image as a terrain heightmap");
-        return false;
-    }
-    
-    // Unsubscribe from the reload event of previous image (if any), then subscribe to the new
-    if (heightMap_)
-        UnsubscribeFromEvent(heightMap_, E_RELOADFINISHED);
-    if (image)
-        SubscribeToEvent(image, E_RELOADFINISHED, HANDLER(Terrain, HandleHeightMapReloadFinished));
-    
-    heightMap_ = image;
+    bool success = SetHeightMapInternal(image, true);
     
-    CreateGeometry();
     MarkNetworkUpdate();
-    return true;
+    return success;
 }
 
 void Terrain::SetMaterial(Material* material)
@@ -456,11 +443,7 @@ void Terrain::SetHeightMapAttr(ResourceRef value)
 {
     ResourceCache* cache = GetSubsystem<ResourceCache>();
     Image* image = cache->GetResource<Image>(value.id_);
-    if (image != heightMap_ && (!image || !image->IsCompressed()))
-    {
-        heightMap_ = image;
-        recreateTerrain_ = true;
-    }
+    SetHeightMapInternal(image, false);
 }
 
 void Terrain::SetPatchSizeAttr(unsigned value)
@@ -669,6 +652,30 @@ Vector3 Terrain::GetNormal(unsigned x, unsigned z) const
         Vector3(nwSlope, 1.0f, nwSlope)).Normalized();
 }
 
+bool Terrain::SetHeightMapInternal(Image* image, bool recreateNow)
+{
+    if (image && image->IsCompressed())
+    {
+        LOGERROR("Can not use a compressed image as a terrain heightmap");
+        return false;
+    }
+    
+    // Unsubscribe from the reload event of previous image (if any), then subscribe to the new
+    if (heightMap_)
+        UnsubscribeFromEvent(heightMap_, E_RELOADFINISHED);
+    if (image)
+        SubscribeToEvent(image, E_RELOADFINISHED, HANDLER(Terrain, HandleHeightMapReloadFinished));
+    
+    heightMap_ = image;
+    
+    if (recreateNow)
+        CreateGeometry();
+    else
+        recreateTerrain_ = true;
+    
+    return true;
+}
+
 void Terrain::HandleHeightMapReloadFinished(StringHash eventType, VariantMap& eventData)
 {
     CreateGeometry();

+ 2 - 0
Engine/Graphics/Terrain.h

@@ -145,6 +145,8 @@ private:
     float GetRawHeight(unsigned x, unsigned z) const;
     /// Get terrain normal at position.
     Vector3 GetNormal(unsigned x, unsigned z) const;
+    /// Set heightmap image and optionally recreate the geometry immediately. Return true if successful.
+    bool SetHeightMapInternal(Image* image, bool recreateNow);
     /// Handle heightmap image reload finished.
     void HandleHeightMapReloadFinished(StringHash eventType, VariantMap& eventData);
     

+ 1 - 1
Engine/IO/FileWatcher.cpp

@@ -139,7 +139,7 @@ void FileWatcher::ThreadFunction()
             {
                 FILE_NOTIFY_INFORMATION* record = (FILE_NOTIFY_INFORMATION*)&buffer[offset];
                 
-                if (record->Action == FILE_ACTION_MODIFIED) // Modify
+                if (record->Action == FILE_ACTION_MODIFIED || record->Action == FILE_ACTION_RENAMED_NEW_NAME)
                 {
                     String fileName;
                     const wchar_t* src = record->FileName;