public void BeginProcess(PathMask mask, Vector2f position, Vector2f moveTo, float elapsed, bool reverse) { Clear(); this.mask = mask; openList = new List <Node>(); closedList = new List <Node>(); goal = moveTo; nearest = position; this.position = position; gridGoal = ToGridPoint(goal); this.reverse = reverse; if (!reverse && !mask[gridGoal]) { reversePath = new Path(); reversePath.BeginProcess(mask, moveTo, position, elapsed, true); } Node node = new Node(ToGridPoint(position), gridGoal); nearestNode = node; openList.Add(node); Process(elapsed, position); }
public MaskHandler() { _shapePicker = new ShapePicker(); FillModes = Enum.GetValues(typeof(FillMode)).Cast <FillMode>().ToArray(); ClipModes = Enum.GetValues(typeof(ClipMode)).Cast <ClipMode>().ToArray(); FontAttributes = Enum.GetValues(typeof(FontAttributes)).Cast <FontAttributes>().ToArray(); EllipseMask = new EllipseMask { IsActive = false }; TextMask = new TextMask { FontSize = 100, Text = "Magic Gradients", IsActive = false }; PathMask = new PathMask { Data = _shapePicker.GetData("Xamagon"), IsActive = false }; Collection = new MaskCollection { Masks = new GradientElements <GradientMask> { EllipseMask, TextMask, PathMask } }; ShowPickerCommand = new Command(() => ShowPicker()); }
public override Vector2 Process(PathMask mask, Vector2 position, float elapsed) { this.position = position; Vector2f dif = move - this.position; float elapsedSpeed = speed * elapsed; // goal reached if (dif.Length < 0.1f) { path.Clear(); return(position); } // moveto position differs from active path goal, recalculate path if (adjustedMove != path.Goal) { path.BeginProcess(mask, this.position, adjustedMove, elapsed, false); } // in case path finding is not finished yet do further processing else if (!path.FinishedCalculation) { path.Process(elapsed, this.position); } // in case the goal was adjusted copy to move adjustedMove = path.Goal; //// wait until path is calculated //if (!path.FinishedCalculation) // return this.position; // process way points while (elapsedSpeed > 0 && !path.IsEmpty) { Vector2f wayPoint = path.NextWayPoint; dif = wayPoint - this.position; // we will not reach the next waypoint, calculate position if (dif.Length > elapsedSpeed) { dif.Normalize(); this.position += dif * elapsedSpeed; elapsedSpeed = 0; } // otherwise walk path and remove waypoint from path queue else { elapsedSpeed -= dif.Length; path.Next(); } } return(this.position); }
public void Clear() { reversePath = null; wayPoints.Clear(); wayPointsWalked.Clear(); finishedCalculation = false; closedList = null; openList = null; mask = null; }
public override Vector2 Process(PathMask mask, Vector2 position, float elapsed) { this.position = position; Vector2f dif = moveTo - this.position; float speedElapsed = elapsed * speed; // quit if goal is reached if (dif.Length < 0.1f) { return(position); } // calculate distance if (dif.Length > speedElapsed) { dif.Normalize(); dif *= speedElapsed; } // calculate new position Vector2f newpos = this.position + dif; Rectf boundaries = new Rectf(0, 0, mask.Width * mask.Resolution, mask.Height * mask.Resolution); if (boundaries.PointInside(newpos)) { // transform to map mask position Vector2 maskpos = mask.ConvertMapToMask(newpos); // set new position if there is no obstacle if (mask[maskpos]) { this.position = newpos; } else // otherwise just cancel walking { moveTo = this.position; } } else // otherwise just cancel walking { moveTo = this.position; } return(this.position); }
public MaskHandler() { _shapePicker = new ShapePicker(); EllipseMask = new EllipseMask { IsActive = false }; RectangleMask = new RectangleMask { IsActive = false, Corners = new Corners(Dimensions.Abs(50, 50)) }; TextMask = new TextMask { FontSize = 100, Text = "Magic Gradients", IsActive = false }; PathMask = new PathMask { Data = _shapePicker.GetData("Xamagon"), IsActive = false }; Collection = new MaskCollection { Masks = new GradientElements <GradientMask> { RectangleMask, EllipseMask, TextMask, PathMask } }; ShowPickerCommand = new Command(() => ShowPicker()); }
public override CPPOutput CompileCPPFiles(CppCompileEnvironment CompileEnvironment, List <FileItem> InputFiles, DirectoryReference OutputDir, string ModuleName, IActionGraphBuilder Graph) { // Use a subdirectory for PVS output, to avoid clobbering regular build artifacts OutputDir = DirectoryReference.Combine(OutputDir, "PVS"); // Preprocess the source files with the regular toolchain CppCompileEnvironment PreprocessCompileEnvironment = new CppCompileEnvironment(CompileEnvironment); PreprocessCompileEnvironment.bPreprocessOnly = true; PreprocessCompileEnvironment.bEnableUndefinedIdentifierWarnings = false; // Not sure why THIRD_PARTY_INCLUDES_START doesn't pick this up; the _Pragma appears in the preprocessed output. Perhaps in preprocess-only mode the compiler doesn't respect these? PreprocessCompileEnvironment.Definitions.Add("PVS_STUDIO"); List <Action> PreprocessActions = new List <Action>(); CPPOutput Result = InnerToolChain.CompileCPPFiles(PreprocessCompileEnvironment, InputFiles, OutputDir, ModuleName, new ActionGraphCapture(Graph, PreprocessActions)); // Run the source files through PVS-Studio foreach (Action PreprocessAction in PreprocessActions) { if (PreprocessAction.ActionType != ActionType.Compile) { continue; } FileItem SourceFileItem = PreprocessAction.PrerequisiteItems.FirstOrDefault(x => x.HasExtension(".c") || x.HasExtension(".cc") || x.HasExtension(".cpp")); if (SourceFileItem == null) { Log.TraceWarning("Unable to find source file from command: {0} {1}", PreprocessAction.CommandArguments); continue; } FileItem PreprocessedFileItem = PreprocessAction.ProducedItems.FirstOrDefault(x => x.HasExtension(".i")); if (PreprocessedFileItem == null) { Log.TraceWarning("Unable to find preprocessed output file from command: {0} {1}", PreprocessAction.CommandArguments); continue; } // Disable a few warnings that seem to come from the preprocessor not respecting _Pragma PreprocessAction.CommandArguments += " /wd4005"; // macro redefinition PreprocessAction.CommandArguments += " /wd4828"; // file contains a character starting at offset xxxx that is illegal in the current source character set // Write the PVS studio config file StringBuilder ConfigFileContents = new StringBuilder(); foreach (DirectoryReference IncludePath in Target.WindowsPlatform.Environment.IncludePaths) { ConfigFileContents.AppendFormat("exclude-path={0}\n", IncludePath.FullName); } if (ApplicationSettings != null && ApplicationSettings.PathMasks != null) { foreach (string PathMask in ApplicationSettings.PathMasks) { if (PathMask.Contains(":") || PathMask.Contains("\\") || PathMask.Contains("/")) { if (Path.IsPathRooted(PathMask) && !PathMask.Contains(":")) { ConfigFileContents.AppendFormat("exclude-path=*{0}*\n", PathMask); } else { ConfigFileContents.AppendFormat("exclude-path={0}\n", PathMask); } } } } if (Platform == UnrealTargetPlatform.Win64) { ConfigFileContents.Append("platform=x64\n"); } else if (Platform == UnrealTargetPlatform.Win32) { ConfigFileContents.Append("platform=Win32\n"); } else { throw new BuildException("PVS-Studio does not support this platform"); } ConfigFileContents.Append("preprocessor=visualcpp\n"); ConfigFileContents.Append("language=C++\n"); ConfigFileContents.Append("skip-cl-exe=yes\n"); ConfigFileContents.AppendFormat("i-file={0}\n", PreprocessedFileItem.Location.FullName); string BaseFileName = PreprocessedFileItem.Location.GetFileNameWithoutExtension(); FileReference ConfigFileLocation = FileReference.Combine(OutputDir, BaseFileName + ".cfg"); FileItem ConfigFileItem = Graph.CreateIntermediateTextFile(ConfigFileLocation, ConfigFileContents.ToString()); // Run the analzyer on the preprocessed source file FileReference OutputFileLocation = FileReference.Combine(OutputDir, BaseFileName + ".pvslog"); FileItem OutputFileItem = FileItem.GetItemByFileReference(OutputFileLocation); Action AnalyzeAction = Graph.CreateAction(ActionType.Compile); AnalyzeAction.CommandDescription = "Analyzing"; AnalyzeAction.StatusDescription = BaseFileName; AnalyzeAction.WorkingDirectory = UnrealBuildTool.EngineSourceDirectory; AnalyzeAction.CommandPath = AnalyzerFile; AnalyzeAction.CommandArguments = String.Format("--cl-params \"{0}\" --source-file \"{1}\" --output-file \"{2}\" --cfg \"{3}\" --analysis-mode {4}", PreprocessAction.CommandArguments, SourceFileItem.AbsolutePath, OutputFileLocation, ConfigFileItem.AbsolutePath, (uint)Settings.ModeFlags); if (LicenseFile != null) { AnalyzeAction.CommandArguments += String.Format(" --lic-file \"{0}\"", LicenseFile); AnalyzeAction.PrerequisiteItems.Add(FileItem.GetItemByFileReference(LicenseFile)); } AnalyzeAction.PrerequisiteItems.Add(ConfigFileItem); AnalyzeAction.PrerequisiteItems.Add(PreprocessedFileItem); AnalyzeAction.PrerequisiteItems.AddRange(InputFiles); // Add the InputFiles as PrerequisiteItems so that in SingleFileCompile mode the PVSAnalyze step is not filtered out AnalyzeAction.ProducedItems.Add(OutputFileItem); AnalyzeAction.DeleteItems.Add(OutputFileItem); // PVS Studio will append by default, so need to delete produced items Result.ObjectFiles.AddRange(AnalyzeAction.ProducedItems); } return(Result); }
public override CPPOutput CompileCPPFiles(CppCompileEnvironment CompileEnvironment, List <FileItem> InputFiles, DirectoryReference OutputDir, string ModuleName, ActionGraph ActionGraph) { // Get the MSVC arguments required to compile all files in this batch List <string> SharedArguments = new List <string>(); SharedArguments.Add("/nologo"); SharedArguments.Add("/P"); // Preprocess SharedArguments.Add("/C"); // Preserve comments when preprocessing SharedArguments.Add("/D PVS_STUDIO"); SharedArguments.Add("/wd4005"); if (EnvVars.Compiler >= WindowsCompiler.VisualStudio2015) { SharedArguments.Add("/D _SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS=1"); } foreach (DirectoryReference IncludePath in CompileEnvironment.IncludePaths.UserIncludePaths) { SharedArguments.Add(String.Format("/I \"{0}\"", IncludePath)); } foreach (DirectoryReference IncludePath in CompileEnvironment.IncludePaths.SystemIncludePaths) { SharedArguments.Add(String.Format("/I \"{0}\"", IncludePath)); } foreach (DirectoryReference IncludePath in EnvVars.IncludePaths) { SharedArguments.Add(String.Format("/I \"{0}\"", IncludePath)); } foreach (string Definition in CompileEnvironment.Definitions) { SharedArguments.Add(String.Format("/D \"{0}\"", Definition)); } foreach (FileItem ForceIncludeFile in CompileEnvironment.ForceIncludeFiles) { SharedArguments.Add(String.Format("/FI\"{0}\"", ForceIncludeFile.Location)); } CPPOutput Result = new CPPOutput(); foreach (FileItem SourceFile in InputFiles) { // Get the file names for everything we need string BaseFileName = SourceFile.Location.GetFileName(); // Write the response file FileReference PreprocessedFileLocation = FileReference.Combine(OutputDir, BaseFileName + ".i"); List <string> Arguments = new List <string>(SharedArguments); Arguments.Add(String.Format("/Fi\"{0}\"", PreprocessedFileLocation)); // Preprocess to a file Arguments.Add(String.Format("\"{0}\"", SourceFile.AbsolutePath)); FileReference ResponseFileLocation = FileReference.Combine(OutputDir, BaseFileName + ".i.response"); FileItem ResponseFileItem = FileItem.CreateIntermediateTextFile(ResponseFileLocation, String.Join("\n", Arguments)); // Preprocess the source file FileItem PreprocessedFileItem = FileItem.GetItemByFileReference(PreprocessedFileLocation); Action PreprocessAction = ActionGraph.Add(ActionType.Compile); PreprocessAction.CommandPath = EnvVars.CompilerPath.FullName; PreprocessAction.WorkingDirectory = UnrealBuildTool.EngineSourceDirectory.FullName; PreprocessAction.CommandArguments = " @\"" + ResponseFileItem.AbsolutePath + "\""; PreprocessAction.PrerequisiteItems.AddRange(CompileEnvironment.ForceIncludeFiles); PreprocessAction.PrerequisiteItems.Add(SourceFile); PreprocessAction.PrerequisiteItems.Add(ResponseFileItem); PreprocessAction.ProducedItems.Add(PreprocessedFileItem); PreprocessAction.bShouldOutputStatusDescription = false; // Write the PVS studio config file StringBuilder ConfigFileContents = new StringBuilder(); foreach (DirectoryReference IncludePath in EnvVars.IncludePaths) { ConfigFileContents.AppendFormat("exclude-path={0}\n", IncludePath.FullName); } foreach (string PathMask in ApplicationSettings.PathMasks) { if (PathMask.Contains(":") || PathMask.Contains("\\") || PathMask.Contains("/")) { if (Path.IsPathRooted(PathMask) && !PathMask.Contains(":")) { ConfigFileContents.AppendFormat("exclude-path=*{0}*\n", PathMask); } else { ConfigFileContents.AppendFormat("exclude-path={0}\n", PathMask); } } } if (CppPlatform == CppPlatform.Win64) { ConfigFileContents.Append("platform=x64\n"); } else if (CppPlatform == CppPlatform.Win32) { ConfigFileContents.Append("platform=Win32\n"); } else { throw new BuildException("PVS-Studio does not support this platform"); } ConfigFileContents.Append("preprocessor=visualcpp\n"); ConfigFileContents.Append("language=C++\n"); ConfigFileContents.Append("skip-cl-exe=yes\n"); ConfigFileContents.AppendFormat("i-file={0}\n", PreprocessedFileItem.Location.FullName); FileReference ConfigFileLocation = FileReference.Combine(OutputDir, BaseFileName + ".cfg"); FileItem ConfigFileItem = FileItem.CreateIntermediateTextFile(ConfigFileLocation, ConfigFileContents.ToString()); // Run the analzyer on the preprocessed source file FileReference OutputFileLocation = FileReference.Combine(OutputDir, BaseFileName + ".pvslog"); FileItem OutputFileItem = FileItem.GetItemByFileReference(OutputFileLocation); Action AnalyzeAction = ActionGraph.Add(ActionType.Compile); AnalyzeAction.CommandDescription = "Analyzing"; AnalyzeAction.StatusDescription = BaseFileName; AnalyzeAction.WorkingDirectory = UnrealBuildTool.EngineSourceDirectory.FullName; AnalyzeAction.CommandPath = AnalyzerFile.FullName; AnalyzeAction.CommandArguments = String.Format("--cl-params \"{0}\" --source-file \"{1}\" --output-file \"{2}\" --cfg \"{3}\" --analysis-mode 4", PreprocessAction.CommandArguments, SourceFile.AbsolutePath, OutputFileLocation, ConfigFileItem.AbsolutePath); if (LicenseFile != null) { AnalyzeAction.CommandArguments += String.Format(" --lic-file \"{0}\"", LicenseFile); AnalyzeAction.PrerequisiteItems.Add(FileItem.GetItemByFileReference(LicenseFile)); } AnalyzeAction.PrerequisiteItems.Add(ConfigFileItem); AnalyzeAction.PrerequisiteItems.Add(PreprocessedFileItem); AnalyzeAction.ProducedItems.Add(OutputFileItem); AnalyzeAction.bShouldDeleteProducedItems = true; // PVS Studio will append by default, so need to delete produced items Result.ObjectFiles.AddRange(AnalyzeAction.ProducedItems); } return(Result); }
public abstract Vector2 Process(PathMask mask, Vector2 position, float elapsed);