Browse Source

Fixed an issue where complex objects display in an array or a list would try to insert their GUI elements at wrong layout indices
Fixed an issue where list inspector wasn't properly cleaning up its GUI elements on refresh
Fixed race condition in script object finalizer

Marko Pintera 10 years ago
parent
commit
774f974053

+ 36 - 24
MBansheeEditor/Inspector/InspectableArray.cs

@@ -11,41 +11,35 @@ namespace BansheeEditor
     {
     {
         private class EntryRow
         private class EntryRow
         {
         {
-            public GUILayoutX rowLayout;
             public GUILayoutY contentLayout;
             public GUILayoutY contentLayout;
-            public GUIButton cloneBtn;
-            public GUIButton deleteBtn;
-            public GUIButton moveUpBtn;
-            public GUIButton moveDownBtn;
+            private GUILayoutX rowLayout;
 
 
             public EntryRow(GUILayout parentLayout, int seqIndex, InspectableArray parent)
             public EntryRow(GUILayout parentLayout, int seqIndex, InspectableArray parent)
             {
             {
                 rowLayout = parentLayout.AddLayoutX();
                 rowLayout = parentLayout.AddLayoutX();
                 contentLayout = rowLayout.AddLayoutY();
                 contentLayout = rowLayout.AddLayoutY();
-                cloneBtn = new GUIButton("C");
-                deleteBtn = new GUIButton("X");
-                moveUpBtn = new GUIButton("Up");
-                moveDownBtn = new GUIButton("Down");
+                GUILayoutY buttonLayout = rowLayout.AddLayoutY();
+
+                GUIButton cloneBtn = new GUIButton("C");
+                GUIButton deleteBtn = new GUIButton("X");
+                GUIButton moveUpBtn = new GUIButton("Up");
+                GUIButton moveDownBtn = new GUIButton("Down");
 
 
                 cloneBtn.OnClick += () => parent.OnCloneButtonClicked(seqIndex);
                 cloneBtn.OnClick += () => parent.OnCloneButtonClicked(seqIndex);
                 deleteBtn.OnClick += () => parent.OnDeleteButtonClicked(seqIndex);
                 deleteBtn.OnClick += () => parent.OnDeleteButtonClicked(seqIndex);
                 moveUpBtn.OnClick += () => parent.OnMoveUpButtonClicked(seqIndex);
                 moveUpBtn.OnClick += () => parent.OnMoveUpButtonClicked(seqIndex);
                 moveDownBtn.OnClick += () => parent.OnMoveDownButtonClicked(seqIndex);
                 moveDownBtn.OnClick += () => parent.OnMoveDownButtonClicked(seqIndex);
 
 
-                rowLayout.AddElement(cloneBtn);
-                rowLayout.AddElement(deleteBtn);
-                rowLayout.AddElement(moveUpBtn);
-                rowLayout.AddElement(moveDownBtn);
+                buttonLayout.AddElement(cloneBtn);
+                buttonLayout.AddElement(deleteBtn);
+                buttonLayout.AddElement(moveUpBtn);
+                buttonLayout.AddElement(moveDownBtn);
+                buttonLayout.AddFlexibleSpace();
             }
             }
 
 
             public void Destroy()
             public void Destroy()
             {
             {
                 rowLayout.Destroy();
                 rowLayout.Destroy();
-                contentLayout.Destroy();
-                cloneBtn.Destroy();
-                deleteBtn.Destroy();
-                moveUpBtn.Destroy();
-                moveDownBtn.Destroy();
             }
             }
         }
         }
 
 
@@ -73,17 +67,36 @@ namespace BansheeEditor
                 return true;
                 return true;
 
 
             object newPropertyValue = property.GetValue<object>();
             object newPropertyValue = property.GetValue<object>();
+            if (propertyValue == null)
+                return newPropertyValue != null;
+
+            if (newPropertyValue == null)
+                return propertyValue != null;
+
             if (!propertyValue.Equals(newPropertyValue))
             if (!propertyValue.Equals(newPropertyValue))
                 return true;
                 return true;
 
 
-            if (newPropertyValue != null)
+            SerializableArray array = property.GetArray();
+            if (array.GetLength() != numArrayElements)
+                return true;
+
+            return base.IsModified();
+        }
+
+        public override bool Refresh(int layoutIndex)
+        {
+            bool anythingModified = false;
+
+            if (IsModified())
             {
             {
-                SerializableArray array = property.GetArray();
-                if (array.GetLength() != numArrayElements)
-                    return true;
+                Update(layoutIndex);
+                anythingModified = true;
             }
             }
 
 
-            return base.IsModified();
+            for (int i = 0; i < GetChildCount(); i++)
+                anythingModified |= GetChild(i).Refresh(0);
+
+            return anythingModified;
         }
         }
 
 
         protected override void Update(int layoutIndex)
         protected override void Update(int layoutIndex)
@@ -98,7 +111,6 @@ namespace BansheeEditor
                 row.Destroy();
                 row.Destroy();
 
 
             rows.Clear();
             rows.Clear();
-
             layout.DestroyElements();
             layout.DestroyElements();
 
 
             propertyValue = property.GetValue<object>();
             propertyValue = property.GetValue<object>();

+ 25 - 5
MBansheeEditor/Inspector/InspectableList.cs

@@ -73,17 +73,36 @@ namespace BansheeEditor
                 return true;
                 return true;
 
 
             object newPropertyValue = property.GetValue<object>();
             object newPropertyValue = property.GetValue<object>();
+            if (propertyValue == null)
+                return newPropertyValue != null;
+
+            if (newPropertyValue == null)
+                return propertyValue != null;
+
             if (!propertyValue.Equals(newPropertyValue))
             if (!propertyValue.Equals(newPropertyValue))
                 return true;
                 return true;
 
 
-            if (newPropertyValue != null)
+            SerializableList list = property.GetList();
+            if (list.GetLength() != numArrayElements)
+                return true;
+
+            return base.IsModified();
+        }
+
+        public override bool Refresh(int layoutIndex)
+        {
+            bool anythingModified = false;
+
+            if (IsModified())
             {
             {
-                SerializableList list = property.GetList();
-                if (list.GetLength() != numArrayElements)
-                    return true;
+                Update(layoutIndex);
+                anythingModified = true;
             }
             }
 
 
-            return base.IsModified();
+            for (int i = 0; i < GetChildCount(); i++)
+                anythingModified |= GetChild(i).Refresh(0);
+
+            return anythingModified;
         }
         }
 
 
         protected override void Update(int layoutIndex)
         protected override void Update(int layoutIndex)
@@ -98,6 +117,7 @@ namespace BansheeEditor
                 row.Destroy();
                 row.Destroy();
 
 
             rows.Clear();
             rows.Clear();
+            layout.DestroyElements();
 
 
             propertyValue = property.GetValue<object>();
             propertyValue = property.GetValue<object>();
             if (propertyValue == null)
             if (propertyValue == null)

+ 10 - 0
MBansheeEditor/Inspector/InspectableObjectBase.cs

@@ -83,6 +83,16 @@ namespace BansheeEditor
             children.Clear();
             children.Clear();
         }
         }
 
 
+        protected InspectableObjectBase GetChild(int index)
+        {
+            return children[index];
+        }
+
+        protected int GetChildCount()
+        {
+            return children.Count;
+        }
+
         public virtual void Destroy()
         public virtual void Destroy()
         {
         {
             layout.DestroyElements();
             layout.DestroyElements();

+ 0 - 2
MBansheeEditor/Inspector/InspectorWindow.cs

@@ -90,8 +90,6 @@ namespace BansheeEditor
             if (so == null)
             if (so == null)
                 return;
                 return;
 
 
-            Debug.Log("INSPECTOR REBUILD");
-
             currentType = InspectorType.SceneObject;
             currentType = InspectorType.SceneObject;
             activeSO = so;
             activeSO = so;
 
 

+ 2 - 1
SBansheeEngine/Include/BsScriptObjectManager.h

@@ -47,6 +47,7 @@ namespace BansheeEngine
 		Set<ScriptObjectBase*> mScriptObjects;
 		Set<ScriptObjectBase*> mScriptObjects;
 
 
 		Vector<ScriptObjectBase*> mFinalizedObjects[2];
 		Vector<ScriptObjectBase*> mFinalizedObjects[2];
-		std::atomic<UINT32> mFinalizedQueueIdx;
+		UINT32 mFinalizedQueueIdx;
+		BS_MUTEX(mMutex);
 	};
 	};
 }
 }

+ 9 - 4
SBansheeEngine/Source/BsScriptObjectManager.cpp

@@ -62,8 +62,8 @@ namespace BansheeEngine
 
 
 	void ScriptObjectManager::notifyObjectFinalized(ScriptObjectBase* instance)
 	void ScriptObjectManager::notifyObjectFinalized(ScriptObjectBase* instance)
 	{
 	{
-		UINT32 idx = mFinalizedQueueIdx.load(std::memory_order_relaxed);
-		mFinalizedObjects[idx].push_back(instance);
+		BS_LOCK_MUTEX(mMutex);
+		mFinalizedObjects[mFinalizedQueueIdx].push_back(instance);
 	}
 	}
 
 
 	void ScriptObjectManager::update()
 	void ScriptObjectManager::update()
@@ -73,8 +73,13 @@ namespace BansheeEngine
 
 
 	void ScriptObjectManager::processFinalizedObjects()
 	void ScriptObjectManager::processFinalizedObjects()
 	{
 	{
-		UINT32 readQueueIdx = mFinalizedQueueIdx.fetch_xor(0x1, std::memory_order_relaxed);
-
+		UINT32 readQueueIdx = 0;
+		{
+			BS_LOCK_MUTEX(mMutex);
+			readQueueIdx = mFinalizedQueueIdx;
+			mFinalizedQueueIdx = (mFinalizedQueueIdx + 1) % 2;
+		}
+		
 		for (auto& finalizedObj : mFinalizedObjects[readQueueIdx])
 		for (auto& finalizedObj : mFinalizedObjects[readQueueIdx])
 			finalizedObj->_onManagedInstanceDeleted();
 			finalizedObj->_onManagedInstanceDeleted();
 
 

+ 5 - 1
TODO.txt

@@ -60,7 +60,6 @@ Polish stage 1
 Fix inspector crashes:
 Fix inspector crashes:
  - Try expanding/collapsing foldouts
  - Try expanding/collapsing foldouts
  - Had one with invalid index in Layout.InsertElement called from InspectableObject.Update
  - Had one with invalid index in Layout.InsertElement called from InspectableObject.Update
- - And another 
 
 
 Test inspector selection, selecting a resource and adding/removing component updates
 Test inspector selection, selecting a resource and adding/removing component updates
 Handle seems to lag behind the selected mesh
 Handle seems to lag behind the selected mesh
@@ -97,14 +96,19 @@ Need a way to add scene objects and components (and remove them)
  - Adding scene objects should be doable from context menu in Hierarchy, by dropping a Prefab or by main Menu (undoable)
  - Adding scene objects should be doable from context menu in Hierarchy, by dropping a Prefab or by main Menu (undoable)
  - Deleting them should be doable by context menu in Hierarchy and Del keystroke (undoable)
  - Deleting them should be doable by context menu in Hierarchy and Del keystroke (undoable)
 
 
+Hook up color picker to guicolor field
 Add shortcut keys for view/move/rotate/scale
 Add shortcut keys for view/move/rotate/scale
 Add "focus on object" key (F) - animate it: rotate camera towards then speed towards while zooming in
 Add "focus on object" key (F) - animate it: rotate camera towards then speed towards while zooming in
 Ortographic camera views (+ gizmo in scene view corner that shows camera orientation)
 Ortographic camera views (+ gizmo in scene view corner that shows camera orientation)
 Drag to select in scene view
 Drag to select in scene view
+Update GUISlider so it works with the new style (and to have min/max limits, plus step size)
 
 
 Replace "minimize" button in tabbed title bar with maximize and make sure it works
 Replace "minimize" button in tabbed title bar with maximize and make sure it works
+When I expand inspector elements and them come back to that object it should remember the previous state
+ - Add a chaching mechanism to inspector (likely based on instance ID & property names)
 
 
 Make sure to persist EditorSettings
 Make sure to persist EditorSettings
+Add copyright notices in all files & change license to GPL
 
 
 Later:
 Later:
  - I could record undo/redo per-property using the new diff system
  - I could record undo/redo per-property using the new diff system