예제 #1
0
        public Script LoadScript(string path)
        {
            var asset = AssetManager.GetAsset(path);

            if (asset == null)
            {
                Logger.Log(LogType.Error, "Cannot load script. No such asset at path: " + path);
                return(null);
            }

            Profiler.Start("ScriptManager_LoadScript");

            // if hierarchy contains empty untitled script, remove it
            if (m_LoadedScripts.Count == 1 && m_LoadedScripts[0].Name == Script.DefaultScriptName && m_LoadedScripts[0].Commands.Count() == 0)
            {
                RemoveScript(0);
            }

            Script newScript = asset.Importer.ReloadAsset <Script>();

            if (newScript != null)
            {
                newScript.Path = asset.Path;
                AddScript(newScript, true);
            }
            else
            {
                Logger.Log(LogType.Error, "Failed to load script: " + asset.Path);
            }

            Profiler.Stop("ScriptManager_LoadScript");
            return(newScript);
        }
예제 #2
0
        public void CollectAllImporters()
        {
            Profiler.Start("RuntimeAssetManager.CollectAllImporters");

            m_GuidImporterMap.Clear();

            m_PreloadedAssetsUpToDate = false;

            var paths = Paths.GetAllFilePaths();

            foreach (var path in paths)
            {
                var importer = AssetImporter.FromPath(path);
                if (Logger.AssertIf(importer == null, "Cannot create importer on path: " + path))
                {
                    continue;
                }

                var guid = AssetGuidManager.GetGuid(path);
                if (Logger.AssertIf(guid.IsDefault(), "AssetGuidManager did not have guid for asset: " + path + ". Did you forget to load metadata?"))
                {
                    continue;
                }

                m_GuidImporterMap.Add(guid, importer);
            }

            Profiler.Stop("RuntimeAssetManager.CollectAllImporters");
        }
예제 #3
0
        protected override void ThreadAction()
        {
            Profiler.Start(Name);
            Profiler.Start(Name + "_TakeScreenshot");
            BitmapUtility.TakeScreenshot(m_TempBitmap);
            Profiler.Stop(Name + "_TakeScreenshot");

            Profiler.Start(Name + "_CloneBitmap");
            lock (ScreenBmpLock)
            {
                BitmapUtility.Clone32BPPBitmap(m_TempBitmap, ScreenBmp);
            }
            Profiler.Stop(Name + "_CloneBitmap");
            Profiler.Stop(Name);
        }
예제 #4
0
        protected override void ThreadAction()
        {
            if (ObservedImage == null)
            {
                return;
            }

            if (m_SampleImage == null)
            {
                return;
            }

            Profiler.Start(Name);

            Profiler.Start(Name + "_CloneScreen");
            lock (ScreenStateThread.ScreenBmpLock)
            {
                BitmapUtility.Clone32BPPBitmap(ScreenStateThread.ScreenBmp, ObservedImage);
            }
            Profiler.Stop(Name + "_CloneScreen");

            Profiler.Start(Name + "_FindMatch");
            var points  = FindImagePositions();
            var success = ValidatePointsCorrectness(points);

            Profiler.Stop(Name + "_FindMatch");

            if (success)
            {
                PositionFound?.Invoke(points);
                LastKnownPositions  = points;
                WasImageFound       = true;
                WasLastCheckSuccess = true;
                TimeSinceLastFind   = 0;
                m_Watch.Restart();
            }
            else
            {
                WasLastCheckSuccess = false;
                TimeSinceLastFind   = (int)m_Watch.ElapsedMilliseconds;
            }

            Profiler.Stop(Name);
        }
예제 #5
0
        private bool CompileCodeSync(string[] sources)
        {
            StatusManager.Add("PluginCompiler", 2, new Status("", "Compiling...", StandardColors.Orange));

            Profiler.Start("PluginCompiler_CompileCode");

            CompilerParams.ReferencedAssemblies.Clear();
            CompilerParams.ReferencedAssemblies.AddRange(m_DefaultReferencedAssemblies.ToArray());

            var settings = SettingsManager.GetSettings <CompilerSettings>();

            if (settings != null && settings.CompilerReferences != null && settings.CompilerReferences.Length > 0)
            {
                CompilerParams.ReferencedAssemblies.AddRange(settings.CompilerReferences);
            }

            var results = CodeProvider.CompileAssemblyFromSource(CompilerParams, sources);

            Profiler.Stop("PluginCompiler_CompileCode");

            m_IsCompiling = false;

            // This might happen if scripts are modified before compilation is finished
            if (m_ShouldRecompile)
            {
                m_ShouldRecompile = false;
                CompileCode(m_TempSources);
                return(false);
            }

            if (results.Errors.HasErrors)
            {
                foreach (CompilerError error in results.Errors)
                {
                    Logger.Log(LogType.Error,
                               string.Format("({0}): {1}", error.ErrorNumber, error.ErrorText),
                               string.Format("at {0} {1} : {2}", error.FileName, error.Line, error.Column));
                }

                ScriptsRecompiled?.Invoke();
                Logger.Log(LogType.Error, "Scripts have compilation errors.");
                StatusManager.Add("PluginCompiler", 8, new Status("", "Compilation Failed", StandardColors.Red));
                return(false);
            }
            else
            {
                ScriptsRecompiled?.Invoke();
                Logger.Log(LogType.Log, "Scripts successfully compiled.");
                StatusManager.Add("PluginCompiler", 10, new Status("", "Compilation Complete", default(Color)));
                return(true);
            }
        }
예제 #6
0
        public void AssetRefreshTime_100_ScriptAssets() // 22 ms - 50 (guid)
        {
            int count = 100;
            var name  = "Refresh_Test_1";

            for (int i = 0; i < count; ++i)
            {
                CreateDummyScriptWithImporter("Scripts\\A" + i + ".mrb");
            }

            Profiler.Start(name);
            AssetManager.Refresh();
            Profiler.Stop(name);

            Assert.AreEqual(count, AssetManager.Assets.Count(), "Asset count missmatch");

            var timeTaken = Profiler.CopyNodes()[name][0].Time;

            System.Diagnostics.Debug.WriteLine("Asset Refresh on 100 entries took: " + timeTaken + " ms.");

            Assert.IsTrue(timeTaken < 80, "This test took 40% longer than usual");
        }
예제 #7
0
        private Asset FindImage(Point cursorPos)
        {
            Profiler.Start("RecordingManager_FindImage");
            Profiler.Start("RecordingManager_CropFromScreen");

            var size = k_ImageForReferenceSearchUnderCursorSize;
            var crop = BitmapUtility.TakeScreenshotOfSpecificRect(
                WinAPI.GetCursorPosition().Sub(new Point(size.Width / 2, size.Width / 2)), size);

            Profiler.Stop("RecordingManager_CropFromScreen");
            Profiler.Start("RecordingManager_FindAssetReference");

            // TODO: FeatureDetector.Get will fail to find proper match if another thread already used/is using it
            var   detector = FeatureDetectorFactory.Create(DetectorNamesHardcoded.PixelPerfect);
            Asset retAsset = null;

            foreach (var asset in AssetManager.Assets)
            {
                if (asset.HoldsTypeOf(typeof(Bitmap)))
                {
                    if (detector.FindImagePos(crop, asset.Importer.Load <Bitmap>()) != null)
                    {
                        ImageFoundInAssets?.Invoke(asset, cursorPos);
                        retAsset = asset;
                        break;
                    }
                }
            }

            Profiler.Stop("RecordingManager_FindAssetReference");
            Profiler.Stop("RecordingManager_FindImage");

            if (retAsset == null)
            {
                ImageNotFoundInAssets?.Invoke(cursorPos);
            }

            return(retAsset);
        }
예제 #8
0
        public void SaveTestFixture(TestFixture fixture, string path)
        {
            Profiler.Start("TestFixtureManager_SaveFixture");

            fixture.Name = Paths.GetName(path);
            fixture.Path = Paths.GetProjectRelativePath(path);
            AssetManager.CreateAsset(fixture.ToLightTestFixture(), path);
            fixture.IsDirty = false; // This will fire callback which will update UI dirty flag if needed.

            FixtureSaved?.Invoke(fixture, path);

            Profiler.Stop("TestFixtureManager_SaveFixture");
        }
예제 #9
0
        public void CreateUserAppDomain()
        {
            Profiler.Start("PluginLoader.ReloadAppDomain");

            if (Assemblies != null)
            {
                DestroyUserAppDomain();
            }

            LoadUserAssemblies();
            UserDomainReloaded?.Invoke();
            // AsyncOperationOnUI?.Post(() => UserDomainReloaded?.Invoke());

            Profiler.Stop("PluginLoader.ReloadAppDomain");
        }
예제 #10
0
        public override IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
        {
            Guard.ArgumentIsNotNull(input, "input");
            Guard.ArgumentIsNotNull(getNext, "getNext");

            _profiler.Start();

            var nextMethod = getNext().Invoke(input, getNext);

            var elapsedTime = _profiler.Stop();
            var duration    = string.Format("{0:00}:{1:00}:{2:00}.{3:00}", elapsedTime.Hours, elapsedTime.Minutes, elapsedTime.Seconds, elapsedTime.Milliseconds / 10);

            _logger.Write(string.Format("{0} {1} duration: {2}", input.Target, input.MethodBase, duration), TraceEventType.Verbose);

            return(nextMethod);
        }
예제 #11
0
        private void ReplaceCommandsInScriptsWithNewRecompiledOnes()
        {
            Profiler.Start("BaseScriptManager_ReplaceOldCommandInstances");

            foreach (var script in LoadedScripts)
            {
                foreach (var node in script.Commands.GetAllNodes().ToArray())
                {
                    var command = node.value;
                    if (command == null || CommandFactory.IsNative(command))
                    {
                        continue;
                    }

                    script.ReplaceCommand(node.value, CommandFactory.Create(node.value.Name, node.value));
                }
            }

            Profiler.Stop("BaseScriptManager_ReplaceOldCommandInstances");
        }
예제 #12
0
        public void Refresh()
        {
            Profiler.Start("AssetManager_Refresh");
            BeginAssetEditing();

            var paths        = Paths.GetAllFilePaths();
            var assetsOnDisk = paths.Select(path => new Asset(path));

            // Detect renamed assets if application was closed, and assets were renamed via file system
            foreach (var pair in AssetGuidManager.Paths.ToList())
            {
                var path = pair.Value;
                if (!File.Exists(path))
                {
                    var guid = pair.Key;
                    var hash = AssetGuidManager.GetHash(guid);

                    var assetOnDiskWithSameHashButNotKnownPath = assetsOnDisk.FirstOrDefault(
                        a => a.Hash == hash && !AssetGuidManager.ContainsValue(a.Path));

                    // If this asset on disk is found, update old guid to new path, since best prediction is that it was renamed
                    if (assetOnDiskWithSameHashButNotKnownPath != null)
                    {
                        AssetGuidManager.AddNewGuid(guid, assetOnDiskWithSameHashButNotKnownPath.Path, hash);
                        Logger.Log(LogType.Log, "Asset '" + assetOnDiskWithSameHashButNotKnownPath.Name + "' was recognized as renamed asset");
                    }
                }
            }

            // Detect Rename for assets in memory (while keeping existing asset references)
            foreach (var assetInMemory in Assets.ToList())
            {
                if (!File.Exists(assetInMemory.Path))
                {
                    // if known path does not exist on disk anymore but some other asset with same hash exists on disk, it must have been renamed
                    var assetWithSameHashAndNotInDbYet = assetsOnDisk.FirstOrDefault(asset =>
                                                                                     asset.Hash == assetInMemory.Hash && !GuidPathTable.ContainsValue(asset.Path));

                    if (assetWithSameHashAndNotInDbYet != null)
                    {
                        RenameAssetInternal(assetInMemory.Path, assetWithSameHashAndNotInDbYet.Path);
                        Logger.Log(LogType.Log, "Asset '" + assetInMemory.Name + "' was renamed to '" + assetWithSameHashAndNotInDbYet.Name + "'");
                    }
                    else
                    {
                        DeleteAssetInternal(assetInMemory);
                        Logger.Log(LogType.Log, "Asset was deleted: '" + assetInMemory.Name + "'");
                    }
                }
            }

            // Add new assets and detect modifications
            foreach (var assetOnDisk in assetsOnDisk)
            {
                var isHashKnown = GuidHashTable.ContainsValue(assetOnDisk.Hash);
                var isPathKnown = GuidPathTable.ContainsValue(assetOnDisk.Path);

                // We know the path, but hash has changed, must have been modified
                if (!isHashKnown && isPathKnown)
                {
                    UpdateAssetInternal(GetAsset(assetOnDisk.Path));
                    Logger.Log(LogType.Log, "Asset was modified: '" + assetOnDisk.Name + "'");
                }
                // New file added
                else if (!isPathKnown)
                {
                    AddAssetInternal(assetOnDisk);
                }
            }

            EndAssetEditing();
            Profiler.Stop("AssetManager_Refresh");

            StatusManager.Add("AssetManager", 10, new Status(null, "Asset Refresh Finished", StandardColors.Default));
            // Logger.Log(LogType.Log, "Asset refresh finished");

            RefreshFinished?.Invoke();
        }
예제 #13
0
 public void Dispose()
 {
     _profiler.Stop();
     _profileAction(_profiler.Elapsed);
 }
예제 #14
0
 public void Dispose()
 {
     _profiler.Stop();
     _profileAction(_profiler.ElapsedMilliseconds);
 }
예제 #15
0
        private void ReloadTestFixtures(bool firstReload = false)
        {
            Profiler.Start("TestRunnerManager.ReloadTestFixtures");

            var fixtureAssets = AssetManager.Assets.Where(asset => asset.Importer.HoldsType() == typeof(LightTestFixture));

            // Update test fixtures with modified values
            foreach (var asset in fixtureAssets)
            {
                // Ignore non-modified assets
                if (!firstReload && !m_ModifiedFilesSinceLastUpdate.Contains(asset.Path))
                {
                    continue;
                }

                var lightFixture = asset.Importer.Load <LightTestFixture>();
                if (lightFixture == null)
                {
                    continue;
                }

                lightFixture.Name = asset.Name;

                // Making a deep clone so modifying fixtures in other windows will not affect the status on TestRunner
                lightFixture = (LightTestFixture)lightFixture.Clone();

                var fixture = m_TestFixtures.FirstOrDefault(f => f.Name == asset.Name);

                // Create new fixture if one does not exist
                if (fixture == null)
                {
                    fixture = Container.Resolve <TestFixture>();
                    fixture.ApplyLightFixtureValues(lightFixture);
                    fixture.Path = asset.Path;

                    m_TestFixtures.Add(fixture);
                    TestFixtureAdded?.Invoke(fixture, m_TestFixtures.Count - 1);
                }
                // Modify an existing one with new data from disk
                else
                {
                    ResetTestStatusForModifiedTests(fixture, lightFixture);
                    fixture.ApplyLightFixtureValues(lightFixture);
                    fixture.Path = asset.Path;
                    TestFixtureModified?.Invoke(fixture, m_TestFixtures.IndexOf(fixture));
                }
            }

            var assetNames = fixtureAssets.Select(asset => asset.Name);

            // Remove deleted test fixtures
            for (int i = m_TestFixtures.Count - 1; i >= 0; --i)
            {
                if (!assetNames.Contains(m_TestFixtures[i].Name))
                {
                    var fixture = m_TestFixtures[i];
                    m_TestFixtures.RemoveAt(i);
                    TestFixtureRemoved?.Invoke(fixture, i);
                }
            }

            m_ModifiedFilesSinceLastUpdate.Clear();

            Profiler.Stop("TestRunnerManager.ReloadTestFixtures");
        }