Exemplo n.º 1
0
        public static byte[] Unload()
        {
            DateTime beginUnloadTime = DateTime.Now;

            FMessage.Log("BeginUnload: " + beginUnloadTime.TimeOfDay);

            HotReload.OnUnload();

            HotReload.Data.BeginUnloadTime = beginUnloadTime;
            byte[] data = HotReload.Data.Save();
            HotReload.Data.Close();

            TimeSpan endUnloadTime = DateTime.Now.TimeOfDay;

            FMessage.Log("EndUnload: " + endUnloadTime + " (" + (endUnloadTime - beginUnloadTime.TimeOfDay) + ")");
            return(data);
        }
Exemplo n.º 2
0
 private static bool ValidateFunction(UObject obj, FName functionName)
 {
     // Same validation that is in UKismetSystemLibrary::K2_SetTimer
     if (obj != null && functionName != FName.None)
     {
         IntPtr functionAddress = Native_UObject.FindFunction(obj.Address, ref functionName);
         if (functionAddress != IntPtr.Zero && Native_UFunction.Get_ParmsSize(functionAddress) > 0)
         {
             // User passed in a valid function, but one that takes parameters
             // FTimerDynamicDelegate expects zero parameters and will choke on execution if it tries
             // to execute a mismatched function
             FMessage.Log(ELogVerbosity.Warning, "SetTimer passed a function (" +
                          NativeReflection.GetPathName(functionAddress) + ") that expects parameters.");
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 3
0
        public static void Unload()
        {
            DateTime beginUnloadTime = DateTime.Now;

            FMessage.Log("BeginUnload: " + beginUnloadTime.TimeOfDay);

            HotReload.OnUnload();

            HotReload.Data.BeginUnloadTime = beginUnloadTime;
            byte[] data = HotReload.Data.Save();
            HotReload.Data.Close();

            SharedRuntimeState.SetHotReloadData(data);

            TimeSpan endUnloadTime = DateTime.Now.TimeOfDay;

            FMessage.Log("EndUnload: " + endUnloadTime + " (" + (endUnloadTime - beginUnloadTime.TimeOfDay) + ")");
        }
        private void Definition_SolutionEnd(object sender, GH_SolutionEventArgs e)
        {
            FMessage.Log(ELogVerbosity.Warning, "Solution End");
            if (definition != e.Document)
            {
                return;
            }

            mesh = GetDocumentPreview(e.Document);

            if (mesh == null)
            {
                return;
            }

            mesh.Faces.ConvertQuadsToTriangles();
            mesh.Flip(true, true, true);
        }
Exemplo n.º 5
0
        public void CameraToGH(FVector vector)
        {
            FMessage.Log(ELogVerbosity.Warning, "x:" + vector.X + " y:" + vector.Y + " z:" + vector.Z);
            var pt = new Rhino.Geometry.Point3d(vector.X, vector.Y, vector.Z);

            /*
             * using (var args = new Rhino.Runtime.NamedParametersEventArgs())
             * {
             * args.Set("point", new Rhino.Geometry.Point(pt));
             * Rhino.Runtime.HostUtils.ExecuteNamedCallback("ToGrasshopper", args);
             * }
             */
            string Name = "receive";

            var comp = FindComponentByName(Name, definition);

            if (comp is Grasshopper.Kernel.Special.GH_Panel)
            {
                var panel = comp as Grasshopper.Kernel.Special.GH_Panel;
                panel.UserText = "{" + vector.X + "," + vector.Y + "," + vector.Z + "}";
            }

            comp.ExpireSolution(true);
        }
Exemplo n.º 6
0
        private static void OnNativeFunctionsRegistered()
        {
            bool reloading = HotReload.IsReloading;

            HotReload.MinimalReload = Native_SharpHotReloadUtils.Get_MinimalHotReload();

            FMessage.Log("Runtime: " + SharedRuntimeState.GetRuntimeInfo(false));

            // HACK: Removing EPackageFlags.EditorOnly on the USharp package so that C# classes aren't tagged as
            //       EObjectMark.EditorOnly. The correct thing to do would be to seperate USharp into seperate
            //       Editor/Runtime modules.
            IntPtr package = NativeReflection.FindPackage(IntPtr.Zero, "/Script/USharp");

            if (package != IntPtr.Zero)
            {
                Native_UPackage.ClearPackageFlags(package, EPackageFlags.EditorOnly);
            }

            using (var timing = HotReload.Timing.Create(HotReload.Timing.UnrealTypes_Load))
            {
                UnrealTypes.Load();
            }

            if (HotReload.IsReloading)
            {
                HotReload.OnPreReloadBegin();
            }

            using (var timing = HotReload.Timing.Create(HotReload.Timing.UnrealTypes_LoadNative))
            {
                // Load the underlying native type info for generated types (class address/properties/functions/offsets)
                UnrealTypes.LoadNative();
            }

            using (var timing = HotReload.Timing.Create(HotReload.Timing.UClass_Load))
            {
                // Load native classes
                UClass.Load();
            }

            using (var timing = HotReload.Timing.Create(HotReload.Timing.NativeFunctions_GenerateAndCompileMissingAssemblies))
            {
                // Update the C# game project props file
                ProjectProps.Update();

                // Prompt to compile the C# engine wrapper code / C# game code (if it isn't already compiled)
                GenerateAndCompileMissingAssemblies();
            }

            // If any assemblies are loaded make sure to load their unreal types
            if (!AssemblyContext.IsCoreCLR || CurrentAssemblyContext.Reference.IsInvalid)
            {
                // .NET Core should resolve with AssemblyLoadContext.Resolving (unless the contexts aren't set up)
                CurrentAssemblyContext.AssemblyResolve += CurrentDomain_AssemblyResolve;
            }
            CurrentAssemblyContext.AssemblyLoad += OnAssemblyLoad;
            CurrentAssemblyContext.Resolving    += CurrentAssemblyContext_Resolving;

            using (var timing = HotReload.Timing.Create(HotReload.Timing.NativeFunctions_LoadAssemblies))
            {
                // Load managed assemblies (game assembly, and any others which may need loading)
                LoadAssemblies();
            }

            if (HotReload.IsReloading)
            {
                HotReload.OnPreReloadEnd();
            }

            using (var timing = HotReload.Timing.Create(HotReload.Timing.ManagedUnrealModuleInfo_Load))
            {
                // Load managed module infos
                ManagedUnrealModuleInfo.Load();
            }

            using (var timing = HotReload.Timing.Create(HotReload.Timing.ManagedUnrealTypes_Load))
            {
                // Load / register managed unreal types
                ManagedUnrealTypes.Load();
            }

            using (var timing = HotReload.Timing.Create(HotReload.Timing.HotReload_OnReload))
            {
                // Let HotReload handle reloading if this is a reload
                if (HotReload.IsReloading)
                {
                    HotReload.OnReload();
                }
            }

            // Clear the hot-reload data store if it isn't cleared already
            if (HotReload.Data != null)
            {
                HotReload.Data.Close();
                HotReload.Data = null;
            }

            if (FBuild.WithEditor && reloading)
            {
                using (var timing = HotReload.Timing.Create(HotReload.Timing.UObject_CollectGarbage))
                {
                    // If we are hotreloading collect garbage to clean up trashed types / reinstanced objects
                    UObject.CollectGarbage(GCHelper.GarbageCollectionKeepFlags, true);
                }

                if (!ManagedUnrealTypes.SkipBroadcastHotReload)
                {
                    using (var timing = HotReload.Timing.Create(HotReload.Timing.SharpHotReloadUtils_BroadcastOnHotReload))
                    {
                        // Broadcast the native OnHotReload (if we don't do this we would need to reimplement various
                        // handlers to ensure correct reloading. One example is FBlueprintActionDatabase::ReloadAll
                        // which needs to be called otherwise the action database will hold onto our old class members
                        // and would produce erros when opening blueprints).

                        // true will show the C++ "Hot Reload Complete!" notification (are there any other differences?)
                        //Native_SharpHotReloadUtils.BroadcastOnHotReload(true);

                        // The notification rendering gets messed up the longer hotreload takes. Wait 1 frame to ensure
                        // that the notification gets fully rendered (though the audio still seems to mess up)
                        Coroutine.StartCoroutine(null, DeferBroadcastHotReload());
                    }
                }
            }

            using (var timing = HotReload.Timing.Create(HotReload.Timing.GC_Collect))
            {
                // We likely created a bunch of garbage, best to clean it up now.
                GC.Collect();
            }
        }
Exemplo n.º 7
0
        public static int DllMain(string arg)
        {
            try
            {
                Args args = new Args(arg);

                if (!SharedRuntimeState.Initialized)
                {
                    SharedRuntimeState.Initialize((IntPtr)args.GetInt64("RuntimeState"));

                    AssemblyContextRef currentContext;
                    AssemblyContextRef.TryParse(args.GetString("AssemblyContext"), out currentContext);
                    AssemblyContext.Initialize(currentContext);
                    CurrentAssemblyContext.Initialize(currentContext);
                }

                if (args.GetBool("Preloading"))
                {
                    Preloading = true;
                    IntPtr address = (IntPtr)args.GetInt64("RegisterFuncs");
                    if (address != IntPtr.Zero)
                    {
                        NativeFunctions.RegisterFunctions(address);
                        Preloaded = true;
                    }
                    Preloading = false;
                    return(0);
                }
                else
                {
                    unsafe
                    {
                        SharedRuntimeState.Instance->ActiveRuntime = SharedRuntimeState.CurrentRuntime;
                    }

                    DateTime beginUnload = default(DateTime);
                    TimeSpan beginReload = DateTime.Now.TimeOfDay;

                    bool isReloading = false;
                    using (var timing = HotReload.Timing.Create(HotReload.Timing.TotalLoadTime))
                    {
                        using (var subTiming = HotReload.Timing.Create(HotReload.Timing.DataStore_Load))
                        {
                            // If this is a hot-reload then set up the data store
                            HotReload.Data = HotReload.DataStore.Load(SharedRuntimeState.GetHotReloadData());
                            beginUnload    = HotReload.Data.BeginUnloadTime;
                        }

                        HotReload.IsReloading = args.GetBool("Reloading");
                        isReloading           = HotReload.IsReloading;

                        IntPtr address = (IntPtr)args.GetInt64("RegisterFuncs");
                        if (address != IntPtr.Zero)
                        {
                            NativeFunctions.RegisterFunctions(address);
                        }
                    }

                    SharedRuntimeState.SetHotReloadAssemblyPaths(HotReloadAssemblyPaths);

                    TimeSpan endTime = DateTime.Now.TimeOfDay;
                    FMessage.Log("BeginReload: " + beginReload + " (BeginUnload-BeginReload: " + (beginReload - beginUnload.TimeOfDay) + ")");
                    FMessage.Log("EndReload: " + endTime + " (BeginUnload-EndReload: " + (endTime - beginUnload.TimeOfDay) + ")");
                    HotReload.Timing.Print(isReloading);
                    HotReload.Timing.PrintAll();
                    return(0);
                }
            }
            catch (Exception e)
            {
                string exceptionStr = "Entry point exception (UnrealEngine.Runtime): " + e;
                if (SharedRuntimeState.Initialized)
                {
                    SharedRuntimeState.LogError(exceptionStr);
                    SharedRuntimeState.MessageBox(exceptionStr, "Error");
                }
                return(1005);// AssemblyLoaderError.Exception
            }
        }
Exemplo n.º 8
0
        protected override void BeginPlay()
        {
            base.BeginPlay();

            FMessage.Log(ELogVerbosity.Warning, "Hello from C# (" + this.GetType().ToString() + ":BeginPlay)");
        }
 public void GetLocation(FVector vector)
 {
     FMessage.Log(ELogVerbosity.Warning, "X:" + vector.X + " Y:" + vector.Y + " Z:" + vector.Z);
 }
Exemplo n.º 10
0
 private void LogFunctionNotFound(string bindType, string actionName, Delegate del)
 {
     FMessage.Log(ELogVerbosity.Warning, "Input " + bindType + " - the target function isn't marked as a [UFunction] for \"" + actionName + "\" " +
                  "(" + del.Method.DeclaringType.FullName + ":" + del.Method.Name + ")");
 }
Exemplo n.º 11
0
 public void CallMe(string arg1)
 {
     FMessage.Log("Hello from CallMe: " + arg1);
 }
Exemplo n.º 12
0
 private static void LogFromSimpleFileParser(string msg)
 {
     FMessage.Log(ELogVerbosity.Log, "SimpleFileParser: " + msg);
 }