Browse Source

Generic support for Vector, ScriptVector push

Josh Engebretson 9 years ago
parent
commit
485d3db21e

+ 23 - 0
Script/AtomicNET/AtomicNET/Core/Vector.cs

@@ -18,12 +18,35 @@ namespace AtomicEngine
 			}
 		}
 
+		public void Push(T refCounted)
+		{
+			scriptVector.Push(refCounted);
+		}
+
 		public T At(uint index)
 		{
 			return (T) scriptVector.At(index);	
 		}
 
 
+		public T this[int key]
+		{
+			get
+			{
+				return At((uint)key);
+			}
+		}
+
+		public T this[uint key]
+		{
+			get
+			{
+				return At(key);
+			}
+		}
+
+
+
 		public static implicit operator IntPtr(Vector<T> vector)
 		{
 			if (vector == null)

+ 36 - 0
Script/AtomicNET/AtomicNET/Scene/Node.cs

@@ -23,6 +23,42 @@ namespace AtomicEngine
             return (T) CreateComponent(type.Name, mode, id);
         }
 
+		public void GetChildrenWithComponent<T>(Vector<Node> dest, bool recursive = false)
+		{
+			var type = typeof(T);
+
+			// If we're a CSComponent, get "CSComponents" native side and filter here
+			if (type.IsSubclassOf(typeof(CSComponent)))
+			{
+				Vector<Node> temp = new Vector<Node>();
+
+				GetChildrenWithComponent(temp, "CSComponent", recursive);
+
+				// filter based on actual type
+
+				for (uint i = 0; i < temp.Size; i++)
+				{
+					var node = temp[i];
+
+					Vector<Component> components = new Vector<Component>();
+
+					node.GetComponents(components, "Component", false);
+
+					for (uint j = 0; j < components.Size; j++)
+					{
+						if (components[j].GetType() == type)
+						{
+							dest.Push(node);
+							break;
+						}						
+					}
+				}
+
+				return;
+			}
+
+			GetChildrenWithComponent(dest, type.Name, recursive);
+		}
 
     }
 

+ 7 - 0
Source/Atomic/Script/ScriptVector.h

@@ -30,6 +30,13 @@ public:
         return refVector_[index];
     }
 
+    void Push(RefCounted* refCounted)
+    {
+        // TODO: check null?
+
+        refVector_.Push(SharedPtr<RefCounted>(refCounted));
+    }
+
     unsigned GetSize() const
     {
         return refVector_.Size();