示例#1
0
        public bool FreeMemory(IntPtr address)
        {
            if (MemoryAllocations.ContainsKey(address))
            {
                MemoryAllocations.Remove(address);
                return(VirtualFreeEx(ProcessHandle, address, 0, AllocationType.Release));
            }

            return(false);
        }
示例#2
0
        public bool AllocateMemory(uint size, out IntPtr address)
        {
            address = VirtualAllocEx(ProcessHandle, IntPtr.Zero, size, AllocationType.Commit, MemoryProtection.ExecuteReadWrite);
            if (address != IntPtr.Zero)
            {
                MemoryAllocations.Add(address, size);
                return(true);
            }

            address = IntPtr.Zero;
            return(false);
        }
示例#3
0
        private void PreStepForward()
        {
            bool savePreFirstTimeStep = Application.isEditor &&
                                        SavePreFirstStep &&
                                        SavePreFirstStepPath != string.Empty &&
                                        m_simulation.getTimeStamp() == 0.0;

            if (savePreFirstTimeStep)
            {
                var saveSuccess = SaveToNativeFile(SavePreFirstStepPath);
                if (saveSuccess)
                {
                    Debug.Log(Utils.GUI.AddColorTag("Successfully wrote initial state to: ", Color.green) +
                              new FileInfo(SavePreFirstStepPath).FullName);
                }
            }

            agx.Timer timer = null;
            if (DisplayStatistics)
            {
                timer = new agx.Timer(true);
            }

            if (TrackMemoryAllocations)
            {
                MemoryAllocations.Snap(MemoryAllocations.Section.Begin);
            }

            if (StepCallbacks.PreStepForward != null)
            {
                StepCallbacks.PreStepForward.Invoke();
            }

            if (TrackMemoryAllocations)
            {
                MemoryAllocations.Snap(MemoryAllocations.Section.PreStepForward);
            }

            if (StepCallbacks.PreSynchronizeTransforms != null)
            {
                StepCallbacks.PreSynchronizeTransforms.Invoke();
            }

            if (TrackMemoryAllocations)
            {
                MemoryAllocations.Snap(MemoryAllocations.Section.PreSynchronizeTransforms);
            }

            if (timer != null)
            {
                timer.stop();
            }
        }
示例#4
0
        public bool Attach(Process wowProcess)
        {
            Process = wowProcess;
            if (Process == null || Process.HasExited)
            {
                return(false);
            }

            ProcessHandle = OpenProcess(ProcessAccessFlags.All, false, wowProcess.Id);
            if (ProcessHandle == IntPtr.Zero)
            {
                return(false);
            }

            Fasm = new ManagedFasm(ProcessHandle);
            MemoryAllocations.Clear();
            return(true);
        }
示例#5
0
        private void PostStepForward()
        {
            agx.Timer timer = null;
            if (DisplayStatistics)
            {
                timer = new agx.Timer(true);
            }

            if (TrackMemoryAllocations)
            {
                MemoryAllocations.Snap(MemoryAllocations.Section.StepForward);
            }

            if (StepCallbacks.PostSynchronizeTransforms != null)
            {
                StepCallbacks.PostSynchronizeTransforms.Invoke();
            }

            if (TrackMemoryAllocations)
            {
                MemoryAllocations.Snap(MemoryAllocations.Section.PostSynchronizeTransforms);
            }

            if (StepCallbacks.PostStepForward != null)
            {
                StepCallbacks.PostStepForward.Invoke();
            }

            if (TrackMemoryAllocations)
            {
                MemoryAllocations.Snap(MemoryAllocations.Section.PostStepForward);
            }

            Rendering.DebugRenderManager.OnActiveSimulationPostStep(m_simulation);

            if (timer != null)
            {
                timer.stop();
                m_statisticsWindowData.ManagedStepForward = Convert.ToSingle(timer.getTime());
            }
        }
示例#6
0
        protected void OnGUI()
        {
            if (m_simulation == null)
            {
                return;
            }

            if (!NativeHandler.Instance.HasValidLicense)
            {
                GUILayout.Window(GUIUtility.GetControlID(FocusType.Passive),
                                 new Rect(new Vector2(16,
                                                      0.5f * Screen.height),
                                          new Vector2(Screen.width - 32, 32)),
                                 id =>
                {
                    // Invalid license if initialized.
                    if (NativeHandler.Instance.Initialized && agx.Runtime.instance().getStatus().Length > 0)
                    {
                        GUILayout.Label(Utils.GUI.MakeLabel("AGX Dynamics: " + agx.Runtime.instance().getStatus(),
                                                            Color.red,
                                                            18,
                                                            true),
                                        Utils.GUI.Skin.label);
                    }
                    else
                    {
                        GUILayout.Label(Utils.GUI.MakeLabel("AGX Dynamics: Errors occurred during initialization of AGX Dynamics.",
                                                            Color.red,
                                                            18,
                                                            true),
                                        Utils.GUI.Skin.label);
                    }
                },
                                 "AGX Dynamics not properly initialized",
                                 Utils.GUI.Skin.window);

                return;
            }

            if (m_statisticsWindowData == null)
            {
                return;
            }

            var simColor      = Color.Lerp(Color.white, Color.blue, 0.2f);
            var spaceColor    = Color.Lerp(Color.white, Color.green, 0.2f);
            var dynamicsColor = Color.Lerp(Color.white, Color.yellow, 0.2f);
            var eventColor    = Color.Lerp(Color.white, Color.cyan, 0.2f);
            var dataColor     = Color.Lerp(Color.white, Color.magenta, 0.2f);
            var memoryColor   = Color.Lerp(Color.white, Color.red, 0.2f);

            var labelStyle         = m_statisticsWindowData.LabelStyle;
            var stats              = agx.Statistics.instance();
            var simTime            = stats.getTimingInfo("Simulation", "Step forward time");
            var spaceTime          = stats.getTimingInfo("Simulation", "Collision-detection time");
            var dynamicsSystemTime = stats.getTimingInfo("Simulation", "Dynamics-system time");
            var preCollideTime     = stats.getTimingInfo("Simulation", "Pre-collide event time");
            var preTime            = stats.getTimingInfo("Simulation", "Pre-step event time");
            var postTime           = stats.getTimingInfo("Simulation", "Post-step event time");
            var lastTime           = stats.getTimingInfo("Simulation", "Last-step event time");

            var numBodies      = m_system.getRigidBodies().Count;
            var numShapes      = m_space.getGeometries().Count;
            var numConstraints = m_system.getConstraints().Count +
                                 m_space.getGeometryContacts().Count;

            GUILayout.Window(m_statisticsWindowData.Id,
                             DisplayMemoryAllocations ? m_statisticsWindowData.RectMemoryEnabled : m_statisticsWindowData.Rect,
                             id =>
            {
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Total time:            ", simColor) + simTime.current.ToString("0.00").PadLeft(5, ' ') + " ms", 14, true), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Pre-collide step:      ", eventColor) + preCollideTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Collision detection:   ", spaceColor) + spaceTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Pre step:              ", eventColor) + preTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Dynamics solvers:      ", dynamicsColor) + dynamicsSystemTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Post step:             ", eventColor) + postTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Last step:             ", eventColor) + lastTime.current.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Data:                  ", dataColor), 14, true), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Update frequency:      ", dataColor) + (int)(1.0f / TimeStep + 0.5f) + " Hz"), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Number of bodies:      ", dataColor) + numBodies), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Number of shapes:      ", dataColor) + numShapes), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Number of constraints: ", dataColor) + numConstraints), labelStyle);
                GUILayout.Label("");
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("StepForward (managed):", memoryColor), 14, true), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Step forward:          ", memoryColor) + m_statisticsWindowData.ManagedStepForward.ToString("0.00").PadLeft(5, ' ') + " ms"), labelStyle);
                if (!DisplayMemoryAllocations)
                {
                    return;
                }
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("Allocations (managed):", memoryColor), 14, true), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Pre step callbacks:    ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PreStepForward).PadLeft(6, ' ')), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Pre synchronize:       ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PreSynchronizeTransforms).PadLeft(6, ' ')), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Step forward:          ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.StepForward).PadLeft(6, ' ')), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Post synchronize:      ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PostSynchronizeTransforms).PadLeft(6, ' ')), labelStyle);
                GUILayout.Label(Utils.GUI.MakeLabel(Utils.GUI.AddColorTag("  - Post step callbacks:   ", memoryColor) + MemoryAllocations.GetDeltaString(MemoryAllocations.Section.PostStepForward).PadLeft(6, ' ')), labelStyle);
            },
                             "AGX Dynamics statistics",
                             Utils.GUI.Skin.window);
        }
示例#7
0
        protected void FixedUpdate()
        {
            if (!NativeHandler.Instance.HasValidLicense)
            {
                return;
            }

            if (m_simulation != null)
            {
                bool savePreFirstTimeStep = Application.isEditor &&
                                            SavePreFirstStep &&
                                            SavePreFirstStepPath != string.Empty &&
                                            m_simulation.getTimeStamp() == 0.0;
                if (savePreFirstTimeStep)
                {
                    var saveSuccess = SaveToNativeFile(SavePreFirstStepPath);
                    if (saveSuccess)
                    {
                        Debug.Log("Successfully wrote initial state to: " + SavePreFirstStepPath);
                    }
                }

                agx.Timer timer = null;
                if (DisplayStatistics)
                {
                    timer = new agx.Timer(true);
                }

                MemoryAllocations.Snap(MemoryAllocations.Section.Begin);

                StepCallbacks.PreStepForward?.Invoke();

                MemoryAllocations.Snap(MemoryAllocations.Section.PreStepForward);

                StepCallbacks.PreSynchronizeTransforms?.Invoke();

                MemoryAllocations.Snap(MemoryAllocations.Section.PreSynchronizeTransforms);

                if (timer != null)
                {
                    timer.stop();
                }

                m_simulation.stepForward();

                if (timer != null)
                {
                    timer.start();
                }

                MemoryAllocations.Snap(MemoryAllocations.Section.StepForward);

                StepCallbacks.PostSynchronizeTransforms?.Invoke();

                MemoryAllocations.Snap(MemoryAllocations.Section.PostSynchronizeTransforms);

                StepCallbacks.PostStepForward?.Invoke();

                MemoryAllocations.Snap(MemoryAllocations.Section.PostStepForward);

                Rendering.DebugRenderManager.OnActiveSimulationPostStep(m_simulation);

                if (timer != null)
                {
                    timer.stop();
                    m_statisticsWindowData.ManagedStepForward = Convert.ToSingle(timer.getTime());
                }
            }
        }