Пример #1
0
        void HandleComponentAssemblyReference(uint eventType, ScriptVariantMap eventData)
        {
            string assemblyPath = eventData["AssemblyPath"];
            string assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);

            Log.Info($"Component Assembly referenced {assemblyName} ");
        }
Пример #2
0
        void HandleComponentAssemblyReference(uint eventType, ScriptVariantMap eventData)
        {
            string assemblyPath = eventData["AssemblyPath"];

            Dictionary <string, CSComponentInfo> assemblyTypes = null;

            if (!componentCache.TryGetValue(assemblyPath, out assemblyTypes))
            {
                componentCache[assemblyPath] = assemblyTypes = new Dictionary <string, CSComponentInfo>();
            }

            // HACK!
            if (PlayerApp.DeployedApp)
            {
                assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/AtomicProject.dll";
            }

            Assembly assembly = Assembly.LoadFrom(assemblyPath);

            Type[] types = assembly.GetTypes();

            foreach (var type in types)
            {
                if (type.IsSubclassOf(typeof(CSComponent)))
                {
                    var csinfo = new CSComponentInfo(type);
                    csinfoLookup[csinfo.Type] = csinfo;
                    assemblyTypes[type.Name]  = csinfo;
                }
            }
        }
Пример #3
0
        void HandleComponentLoad(uint eventType, ScriptVariantMap eventData)
        {
            var assemblyPath = eventData["AssemblyPath"];
            var className = eventData["ClassName"];
            IntPtr csnative = eventData.GetVoidPtr("NativeInstance");
            IntPtr fieldValues = IntPtr.Zero;

            if (eventData.Contains("FieldValues"))
                fieldValues = eventData.GetVoidPtr("FieldValues");

            Dictionary<string, CSComponentInfo> assemblyTypes = null;

            if (!componentCache.TryGetValue(assemblyPath, out assemblyTypes))
            {
                return;
            }

            CSComponentInfo csinfo;

            if (!assemblyTypes.TryGetValue(className, out csinfo))
            {
                return;
            }

            NativeCore.NativeContructorOverride = csnative;
            var component = (CSComponent)Activator.CreateInstance(csinfo.Type);
            NativeCore.VerifyNativeContructorOverrideConsumed();

            if (fieldValues != IntPtr.Zero)
                csinfo.ApplyFieldValues(component, fieldValues);

            csinfo.RegisterInstance(component);
        }
Пример #4
0
        void HandleComponentAssemblyReference(uint eventType, ScriptVariantMap eventData)
        {
            string assemblyPath = eventData["AssemblyPath"];

            Dictionary<string, CSComponentInfo> assemblyTypes = null;

            if (!componentCache.TryGetValue(assemblyPath, out assemblyTypes))
            {
                componentCache[assemblyPath] = assemblyTypes = new Dictionary<string, CSComponentInfo>();
            }

            // HACK!
            if (PlayerApp.DeployedApp)
            {
                assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "/AtomicProject.dll";
            }

            Assembly assembly = Assembly.LoadFrom(assemblyPath);

            Type[] types = assembly.GetTypes();

            foreach (var type in types)
            {
                if (type.IsSubclassOf(typeof(CSComponent)))
                {
                    var csinfo = new CSComponentInfo(type);
                    csinfoLookup[csinfo.Type] = csinfo;
                    assemblyTypes[type.Name] = csinfo;
                }
            }
        }
Пример #5
0
 internal static void Initialize()
 {
     // preallocate script variant maps
     svm = new ScriptVariantMap[svmMax];
     for (int i = 0; i < svmMax; i++)
     {
         svm[i] = new ScriptVariantMap();
     }
 }
Пример #6
0
        public static void EventDispatch(IntPtr sender, uint eventType, IntPtr eventData)
        {
            List <EventSubscription> eventReceivers;

            if (!eventReceiverLookup.TryGetValue(eventType, out eventReceivers))
            {
                // This should not happen, as event NET objects are subscribed to are filtered
                throw new InvalidOperationException("NativeCore.EventDispatch - received unregistered event type");
            }

            // iterate over copy of list so we can modify it while running
            ScriptVariantMap scriptMap       = null;
            NativeEventData  nativeEventData = null;

            AObject receiver;

            foreach (EventSubscription er in eventReceivers.ToList())
            {
                // GC'd?
                if (!er.Receiver.TryGetTarget(out receiver))
                {
                    continue;
                }

                if (er.Sender != IntPtr.Zero && er.Sender != sender)
                {
                    continue;
                }

                if (scriptMap == null)
                {
                    if (svmDepth == svmMax)
                    {
                        throw new InvalidOperationException("NativeCore.EventDispatch - exceeded max svm");
                    }

                    scriptMap = svm[svmDepth++];
                    scriptMap.CopyVariantMap(eventData);
                    nativeEventData = NativeEvents.GetNativeEventData(eventType, scriptMap);
                    nativeEventData.sourceEventData = eventData;
                }

                receiver.HandleEvent(eventType, scriptMap, nativeEventData);
            }

            if (scriptMap != null)
            {
                svmDepth--;

                if (nativeEventData != null)
                {
                    NativeEvents.ReleaseNativeEventData(nativeEventData);
                }
            }
        }
Пример #7
0
        void HandlePostUpdate(uint eventType, ScriptVariantMap eventData)
        {
            Object[] args = new Object[1] {
                eventData.GetFloat("timestep")
            };

            foreach (var csinfo in csinfoLookup.Values)
            {
                csinfo.PostUpdate(args);
            }
        }
Пример #8
0
        public static void Main(string[] args)
        {
            // create the service
            var app = NETServiceApplication.Create();

            // Subscribe to IPC NET commands
            app.SubscribeToEvent("IPCCmd", (eventType, eventData) =>
            {
                // get the command
                string command = eventData["command"];

                switch (command)
                {
                    // parse assembly for component information
                    case "parse":

                        // Get the assembly to parse
                        string assemblyPath = eventData["assemblyPath"];

                        // Inspect the assembly for components
                        var assemblyJSON = AtomicTools.InspectAssembly(assemblyPath);

                        // Return result
                        var vmap = new ScriptVariantMap();

                        // FIXME: update index operator to a generic
                        vmap.SetUInt("id", eventData.GetUInt("id"));

                        vmap["command"] = command;
                        vmap["result"] = assemblyJSON;

                        AtomicNET.GetSubsystem<IPC>().SendEventToBroker("IPCCmdResult", vmap);

                        break;

                    // exit service
                    case "exit":

                        app.SendEvent("ExitRequested");
                        break;

                }

            });

            // Managed code in charge of main loop
            while (app.RunFrame())
            {

            }

            // Shut 'er down
            app.Shutdown();
        }
Пример #9
0
        void HandlePhysicsPreStep(uint eventType, ScriptVariantMap eventData)
        {
            // TODO: eventData also has a PhysicsWorld pointer, which could be factored in for multiworld support

            Object[] args = new Object[1] {
                eventData.GetFloat("timestep")
            };

            foreach (var csinfo in csinfoLookup.Values)
            {
                csinfo.FixedUpdate(args);
            }
        }
Пример #10
0
        void HandleComponentAssemblyReference(uint eventType, ScriptVariantMap eventData)
        {
#if ATOMIC_DESKTOP || ATOMIC_ANDROID
            string assemblyPath = eventData["AssemblyPath"];

            string assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);
            if (componentCache.ContainsKey(assemblyName))
            {
                return;
            }

            Assembly assembly = Assembly.LoadFrom(assemblyPath);

            ParseAssembly(assembly);
#endif
        }
Пример #11
0
        public static NativeEventData GetNativeEventData(uint eventID, ScriptVariantMap eventMap)
        {
            NativeEventDataCache cache;

            if (eventCacheByEventID.TryGetValue(eventID, out cache))
            {
                if (cache.eventDataDepth == NativeEventDataCache.eventDataMax)
                {
                    throw new InvalidOperationException("GetNativeEventData - max recursive event");
                }

                var eventData = cache.eventData[cache.eventDataDepth++];
                eventData.scriptMap = eventMap;
                return(eventData);
            }

            return(null);
        }
Пример #12
0
        internal void HandleEvent(uint eventType, ScriptVariantMap eventData, NativeEventData nativeEventData)
        {
            NativeEventDelegate nativeDelegate;

            if (NativeEventHandlers.TryGetValue(eventType, out nativeDelegate))
            {
                nativeDelegate(nativeEventData);
                return;
            }

            EventDelegate eventDelegate;

            if (EventHandlers.TryGetValue(eventType, out eventDelegate))
            {
                eventDelegate(eventType, eventData);
                return;
            }

            // Reaching here should be a warning, possibly an error
        }
Пример #13
0
        public static void EventDispatch(uint eventType, IntPtr eventData)
        {
            List <WeakReference <AObject> > eventReceivers;

            if (!eventReceiverLookup.TryGetValue(eventType, out eventReceivers))
            {
                // This should not happen, as event NET objects are subscribed to are filtered
                throw new System.InvalidOperationException("NativeCore.EventDispatch - received unregistered event type");
            }

            ScriptVariantMap scriptMap = null;
            AObject          receiver;

            // iterate over copy of list so we can modify it while running
            foreach (var w in eventReceivers.ToList())
            {
                // GC'd?
                if (!w.TryGetTarget(out receiver))
                {
                    continue;
                }

                if (scriptMap == null)
                {
                    if (svmDepth == svmMax)
                    {
                        throw new System.InvalidOperationException("NativeCore.EventDispatch - exceeded max svm");
                    }

                    scriptMap = svm[svmDepth++];
                    scriptMap.CopyVariantMap(eventData);
                }

                receiver.HandleEvent(eventType, scriptMap);
            }

            if (scriptMap != null)
            {
                svmDepth--;
            }
        }
Пример #14
0
        void HandleComponentLoad(uint eventType, ScriptVariantMap eventData)
        {
            var assemblyPath = eventData["AssemblyPath"];

            var    className   = eventData["ClassName"];
            IntPtr csnative    = eventData.GetVoidPtr("NativeInstance");
            IntPtr fieldValues = IntPtr.Zero;

            if (eventData.Contains("FieldValues"))
            {
                fieldValues = eventData.GetVoidPtr("FieldValues");
            }

            Dictionary <string, CSComponentInfo> assemblyTypes = null;

            if (!componentCache.TryGetValue(assemblyPath, out assemblyTypes))
            {
                return;
            }

            CSComponentInfo csinfo;

            if (!assemblyTypes.TryGetValue(className, out csinfo))
            {
                return;
            }

            NativeCore.NativeContructorOverride = csnative;
            var component = (CSComponent)Activator.CreateInstance(csinfo.Type);

            NativeCore.VerifyNativeContructorOverrideConsumed();

            if (fieldValues != IntPtr.Zero)
            {
                csinfo.ApplyFieldValues(component, fieldValues);
            }

            csinfo.RegisterInstance(component);
        }
Пример #15
0
        void HandleUpdate(uint eventType, ScriptVariantMap eventData)
        {
            Object[] args = new Object[1] { eventData.GetFloat("timestep") };

            foreach (var csinfo in csinfoLookup.Values)
            {
                csinfo.Update(args);
            }
        }
Пример #16
0
 void HandleComponentAssemblyReference(uint eventType, ScriptVariantMap eventData)
 {
     string assemblyPath = eventData["AssemblyPath"];
     string assemblyName = Path.GetFileNameWithoutExtension(assemblyPath);
     Log.Info($"Component Assembly referenced {assemblyName} ");
 }
Пример #17
0
        void HandleRenderPathEvent(uint eventType, ScriptVariantMap eventData)
        {
            if (eventData.GetString("name") != "customrender")
                return;

            CustomRenderer.Begin();

            Draw();

            CustomRenderer.End();
        }
Пример #18
0
        void HandleUpdate(uint eventType, ScriptVariantMap eventData)
        {
            float time = eventData.GetFloat("timestep");

            ElapsedTime += time;

            #if !ATOMIC_IOS
            deltaTime += time;

            if (deltaTime < 1.0f / 60.0f)
                return;

            deltaTime = 0.0f;

            #endif

            ShipInput.Update();

            if (!paused)
            {
                PlayerStatus.Update();
                EntityManager.Update();
                EnemySpawner.Update();
                ParticleManager.Update();
                Grid.Update();
            }
        }
Пример #19
0
 internal void HandleEvent(uint eventType, ScriptVariantMap eventData)
 {
     eventHandlers[eventType](eventType, eventData);
 }
Пример #20
0
        internal void HandleEvent(AObject sender, uint eventType, ScriptVariantMap eventData)
        {
            var key = new SenderEventKey(eventType, sender.nativeInstance);

            senderEventHandlers[key](sender, eventType, eventData);
        }
Пример #21
0
        public static void EventDispatch(IntPtr sender, uint eventType, IntPtr eventData)
        {
            List <EventSubscription> eventReceivers;

            if (!eventReceiverLookup.TryGetValue(eventType, out eventReceivers))
            {
                // This should not happen, as event NET objects are subscribed to are filtered
                throw new InvalidOperationException("NativeCore.EventDispatch - received unregistered event type");
            }

            AObject managedSender = null;
            WeakReference <RefCounted> wr;

            if (sender != IntPtr.Zero &&
                nativeLookup.TryGetValue(sender, out wr))
            {
                RefCounted refCounted;
                if (wr.TryGetTarget(out refCounted))
                {
                    managedSender = refCounted as AObject;
                }
            }

            // iterate over copy of list so we can modify it while running
            ScriptVariantMap scriptMap = null;
            AObject          receiver;

            foreach (EventSubscription er in eventReceivers.ToList())
            {
                // GC'd?
                if (!er.Receiver.TryGetTarget(out receiver))
                {
                    continue;
                }

                if (scriptMap == null)
                {
                    if (svmDepth == svmMax)
                    {
                        throw new InvalidOperationException("NativeCore.EventDispatch - exceeded max svm");
                    }

                    scriptMap = svm[svmDepth++];
                    scriptMap.CopyVariantMap(eventData);
                }

                if (managedSender != null && er.Sender == sender)
                {
                    receiver.HandleEvent(managedSender, eventType, scriptMap);
                }
                else if (er.Sender == IntPtr.Zero)
                {
                    receiver.HandleEvent(eventType, scriptMap);
                }
            }

            if (scriptMap != null)
            {
                svmDepth--;
            }
        }
Пример #22
0
 public void SendEventToBroker(string eventType, ScriptVariantMap eventData)
 {
     csi_Atomic_IPC_SendEventToBrokerWithEventData(nativeInstance, eventType, eventData == null ? IntPtr.Zero : eventData.nativeInstance);
 }
Пример #23
0
 public void SendEventToBroker(string eventType, ScriptVariantMap eventData)
 {
     csb_Atomic_IPC_SendEventToBrokerWithEventData(nativeInstance, eventType, eventData == null ? IntPtr.Zero : eventData.nativeInstance);
 }
Пример #24
0
 public void SendEvent(string eventType, ScriptVariantMap eventData = null)
 {
     csi_Atomic_AObject_SendEvent(this.nativeInstance, eventType, eventData == null ? IntPtr.Zero : eventData.nativeInstance);
 }