|
@@ -9,40 +9,40 @@ namespace AtomicEngine
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
-public partial class CSComponent : ScriptComponent
|
|
|
|
|
-{
|
|
|
|
|
-
|
|
|
|
|
- public void StartInternal()
|
|
|
|
|
|
|
+ public partial class CSComponent : ScriptComponent
|
|
|
{
|
|
{
|
|
|
- ApplyFieldValues();
|
|
|
|
|
- Start();
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- public virtual void Start()
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public void StartInternal()
|
|
|
|
|
+ {
|
|
|
|
|
+ ApplyFieldValues();
|
|
|
|
|
+ Start();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public virtual void Start()
|
|
|
|
|
+ {
|
|
|
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- public virtual void Update(float timeStep)
|
|
|
|
|
- {
|
|
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public virtual void Update(float timeStep)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
-public static class ComponentCore
|
|
|
|
|
-{
|
|
|
|
|
|
|
+ public static class ComponentCore
|
|
|
|
|
+ {
|
|
|
|
|
|
|
|
- static List<CSComponent> startQueue = new List<CSComponent>();
|
|
|
|
|
|
|
+ static List<CSComponent> startQueue = new List<CSComponent>();
|
|
|
|
|
|
|
|
- // holds a reference
|
|
|
|
|
- static Dictionary<IntPtr, CSComponent> liveComponents = new Dictionary<IntPtr, CSComponent>();
|
|
|
|
|
|
|
+ // holds a reference
|
|
|
|
|
+ static Dictionary<IntPtr, CSComponent> liveComponents = new Dictionary<IntPtr, CSComponent>();
|
|
|
|
|
|
|
|
- public static void Update (float timeStep)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public static void Update (float timeStep)
|
|
|
|
|
+ {
|
|
|
|
|
|
|
|
List<CSComponent> _startQueue = new List<CSComponent>(startQueue);
|
|
List<CSComponent> _startQueue = new List<CSComponent>(startQueue);
|
|
|
startQueue.Clear();
|
|
startQueue.Clear();
|
|
@@ -54,23 +54,23 @@ public static class ComponentCore
|
|
|
|
|
|
|
|
foreach (var c in liveComponents.Values)
|
|
foreach (var c in liveComponents.Values)
|
|
|
{
|
|
{
|
|
|
- c.Update(timeStep);
|
|
|
|
|
|
|
+ c.Update(timeStep);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // This will need to be optimized
|
|
|
|
|
- public static void CSComponentApplyFields(IntPtr componentPtr, IntPtr fieldMapPtr)
|
|
|
|
|
- {
|
|
|
|
|
- NETVariantMap fieldMap = NativeCore.WrapNative<NETVariantMap>(fieldMapPtr);;
|
|
|
|
|
- CSComponent component = NativeCore.WrapNative<CSComponent>(componentPtr);;
|
|
|
|
|
|
|
+ // This will need to be optimized
|
|
|
|
|
+ public static void CSComponentApplyFields(IntPtr componentPtr, IntPtr fieldMapPtr)
|
|
|
|
|
+ {
|
|
|
|
|
+ NETVariantMap fieldMap = NativeCore.WrapNative<NETVariantMap>(fieldMapPtr);;
|
|
|
|
|
+ CSComponent component = NativeCore.WrapNative<CSComponent>(componentPtr);;
|
|
|
|
|
|
|
|
- if (fieldMap == null || component == null)
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ if (fieldMap == null || component == null)
|
|
|
|
|
+ return;
|
|
|
|
|
|
|
|
- FieldInfo[] fields = componentClassFields[component.GetType()];
|
|
|
|
|
|
|
+ FieldInfo[] fields = componentClassFields[component.GetType()];
|
|
|
|
|
|
|
|
- foreach (var field in fields)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ foreach (var field in fields)
|
|
|
|
|
+ {
|
|
|
if (fieldMap.Contains(field.Name))
|
|
if (fieldMap.Contains(field.Name))
|
|
|
{
|
|
{
|
|
|
//Console.WriteLine("Applying: {0} {1}", field.Name, field.FieldType.Name);
|
|
//Console.WriteLine("Applying: {0} {1}", field.Name, field.FieldType.Name);
|
|
@@ -79,83 +79,110 @@ public static class ComponentCore
|
|
|
|
|
|
|
|
if (fieldType.IsEnum)
|
|
if (fieldType.IsEnum)
|
|
|
{
|
|
{
|
|
|
- field.SetValue(component, fieldMap.GetInt(field.Name));
|
|
|
|
|
- continue;
|
|
|
|
|
|
|
+ field.SetValue(component, fieldMap.GetInt(field.Name));
|
|
|
|
|
+ continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
switch (Type.GetTypeCode(fieldType))
|
|
switch (Type.GetTypeCode(fieldType))
|
|
|
{
|
|
{
|
|
|
case TypeCode.Boolean:
|
|
case TypeCode.Boolean:
|
|
|
- field.SetValue(component, fieldMap.GetBool(field.Name));
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
- case TypeCode.Int32:
|
|
|
|
|
- field.SetValue(component, fieldMap.GetInt(field.Name));
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
- case TypeCode.Single:
|
|
|
|
|
- field.SetValue(component, fieldMap.GetFloat(field.Name));
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
- case TypeCode.String:
|
|
|
|
|
- field.SetValue(component, fieldMap.GetString(field.Name));
|
|
|
|
|
- break;
|
|
|
|
|
-
|
|
|
|
|
- default:
|
|
|
|
|
-
|
|
|
|
|
- if (fieldType == typeof(Vector3))
|
|
|
|
|
- {
|
|
|
|
|
- field.SetValue(component, fieldMap.GetVector3(field.Name));
|
|
|
|
|
- }
|
|
|
|
|
- else if (fieldType == typeof(Quaternion))
|
|
|
|
|
- {
|
|
|
|
|
- field.SetValue(component, fieldMap.GetQuaternion(field.Name));
|
|
|
|
|
- }
|
|
|
|
|
- else if (fieldType.IsSubclassOf(typeof(Resource)))
|
|
|
|
|
- {
|
|
|
|
|
- field.SetValue(component, fieldMap.GetResourceFromRef(field.Name));
|
|
|
|
|
- }
|
|
|
|
|
- else if (fieldType.IsSubclassOf(typeof(RefCounted)))
|
|
|
|
|
- {
|
|
|
|
|
- field.SetValue(component, fieldMap.GetPtr(field.Name));
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- break;
|
|
|
|
|
|
|
+ field.SetValue(component, fieldMap.GetBool(field.Name));
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case TypeCode.Int32:
|
|
|
|
|
+ field.SetValue(component, fieldMap.GetInt(field.Name));
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case TypeCode.Single:
|
|
|
|
|
+ field.SetValue(component, fieldMap.GetFloat(field.Name));
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ case TypeCode.String:
|
|
|
|
|
+ field.SetValue(component, fieldMap.GetString(field.Name));
|
|
|
|
|
+ break;
|
|
|
|
|
+
|
|
|
|
|
+ default:
|
|
|
|
|
+
|
|
|
|
|
+ if (fieldType == typeof(Vector3))
|
|
|
|
|
+ {
|
|
|
|
|
+ field.SetValue(component, fieldMap.GetVector3(field.Name));
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (fieldType == typeof(Quaternion))
|
|
|
|
|
+ {
|
|
|
|
|
+ field.SetValue(component, fieldMap.GetQuaternion(field.Name));
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (fieldType.IsSubclassOf(typeof(Resource)))
|
|
|
|
|
+ {
|
|
|
|
|
+ field.SetValue(component, fieldMap.GetResourceFromRef(field.Name));
|
|
|
|
|
+ }
|
|
|
|
|
+ else if (fieldType.IsSubclassOf(typeof(RefCounted)))
|
|
|
|
|
+ {
|
|
|
|
|
+ field.SetValue(component, fieldMap.GetPtr(field.Name));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ break;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- static Dictionary<Type, FieldInfo[] > componentClassFields = new Dictionary<Type, FieldInfo[]>();
|
|
|
|
|
|
|
+ static Dictionary<Type, FieldInfo[] > componentClassFields = new Dictionary<Type, FieldInfo[]>();
|
|
|
|
|
|
|
|
- public static IntPtr CSComponentCreate(string assemblyName, string classTypeName)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ static Dictionary<string, Dictionary<string, Type>> componentTypeLookup = new Dictionary<string, Dictionary<string, Type>>();
|
|
|
|
|
|
|
|
- Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(assemblyName));
|
|
|
|
|
|
|
+ public static IntPtr CSComponentCreate(string assemblyName, string classTypeName)
|
|
|
|
|
+ {
|
|
|
|
|
|
|
|
- Type type = assembly.GetType("AtomicNETTest." + classTypeName);
|
|
|
|
|
|
|
+ Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(assemblyName));
|
|
|
|
|
|
|
|
- // TODO: check type is derived from CSComponent
|
|
|
|
|
|
|
+ string classNamespace = "";
|
|
|
|
|
+ if (!componentTypeLookup.ContainsKey(assemblyName))
|
|
|
|
|
+ {
|
|
|
|
|
+ componentTypeLookup[assemblyName] = new Dictionary<string, Type>();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- var component = (CSComponent) Activator.CreateInstance(type);
|
|
|
|
|
|
|
+ var lookup = componentTypeLookup[assemblyName];
|
|
|
|
|
|
|
|
- if (!componentClassFields.ContainsKey(type))
|
|
|
|
|
- {
|
|
|
|
|
- var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
|
|
|
|
|
- .Where(field => field.IsDefined(typeof(InspectorAttribute), true));
|
|
|
|
|
|
|
+ Type type = null;
|
|
|
|
|
|
|
|
- componentClassFields[type] = fields.ToArray<FieldInfo>();
|
|
|
|
|
|
|
+ if (!lookup.TryGetValue(classTypeName, out type))
|
|
|
|
|
+ {
|
|
|
|
|
+ var types = assembly.GetTypes();
|
|
|
|
|
+ foreach (var atype in types)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (atype.Name == classTypeName)
|
|
|
|
|
+ {
|
|
|
|
|
+ lookup[classTypeName] = atype;
|
|
|
|
|
+ type = atype;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ if (type == null)
|
|
|
|
|
+ return IntPtr.Zero;
|
|
|
|
|
|
|
|
- startQueue.Add(component);
|
|
|
|
|
|
|
+ // TODO: check type is derived from CSComponent
|
|
|
|
|
|
|
|
- liveComponents[component.nativeInstance] = component;
|
|
|
|
|
|
|
+ var component = (CSComponent) Activator.CreateInstance(type);
|
|
|
|
|
|
|
|
- return component.nativeInstance;
|
|
|
|
|
|
|
+ if (!componentClassFields.ContainsKey(type))
|
|
|
|
|
+ {
|
|
|
|
|
+ var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
|
|
|
|
|
+ .Where(field => field.IsDefined(typeof(InspectorAttribute), true));
|
|
|
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ componentClassFields[type] = fields.ToArray<FieldInfo>();
|
|
|
|
|
|
|
|
-}
|
|
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ startQueue.Add(component);
|
|
|
|
|
+
|
|
|
|
|
+ liveComponents[component.nativeInstance] = component;
|
|
|
|
|
+
|
|
|
|
|
+ return component.nativeInstance;
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|