ApplicationOptions.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. namespace Urho
  5. {
  6. /// <summary>
  7. /// Application options, see full description at:
  8. /// http://urho3d.github.io/documentation/1.5/_running.html
  9. /// </summary>
  10. public class ApplicationOptions
  11. {
  12. internal static ApplicationOptions LastUsedOptions { get; private set; }
  13. /// <param name="assetsFolder">usually it's "Data". Can be null if built-in assets are enough for you</param>
  14. public ApplicationOptions(string assetsFolder)
  15. {
  16. if (assetsFolder != null)
  17. {
  18. if (assetsFolder.Contains(";"))
  19. ResourcePaths = assetsFolder.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  20. else
  21. ResourcePaths = new[] { assetsFolder };
  22. }
  23. LastUsedOptions = this;
  24. }
  25. public ApplicationOptions() : this(null) {}
  26. /// <summary>
  27. /// Desktop only
  28. /// </summary>
  29. public int Width { get; set; } = 0;
  30. /// <summary>
  31. /// Desktop only
  32. /// </summary>
  33. public int Height { get; set; } = 0;
  34. /// <summary>
  35. /// Desktop only
  36. /// </summary>
  37. public bool WindowedMode { get; set; } = true;
  38. /// <summary>
  39. /// Desktop only
  40. /// </summary>
  41. public bool ResizableWindow { get; set; } = false;
  42. /// <summary>
  43. /// With limit enabled: 200 fps for Desktop (and always 60 fps for mobile despite of the flag)
  44. /// </summary>
  45. public bool LimitFps { get; set; } = true;
  46. /// <summary>
  47. /// Disable sound output
  48. /// </summary>
  49. public bool NoSound { get; set; } = false;
  50. /// <summary>
  51. /// iOS & Android only
  52. /// </summary>
  53. public OrientationType Orientation { get; set; }
  54. #if __IOS__ && !XFORMS
  55. = OrientationType.Landscape;
  56. #else
  57. = OrientationType.LandscapeAndPortrait;
  58. #endif
  59. /// <summary>
  60. /// Resource path(s) to use (default: Data, CoreData)
  61. /// </summary>
  62. public string[] ResourcePaths { get; set; } = null;
  63. /// <summary>
  64. /// Resource package files to use (default: empty)
  65. /// </summary>
  66. public string[] ResourcePackagesPaths { get; set; } = null;
  67. #if WINDOWS_UWP
  68. public bool TouchEmulation { get { return true; } set {} }
  69. #else
  70. /// <summary>
  71. /// Touch emulation on desktop platform
  72. /// </summary>
  73. public bool TouchEmulation { get; set; } = false;
  74. #endif
  75. /// <summary>
  76. /// Enable high DPI, only supported by Apple platforms (OSX, iOS, and tvOS)
  77. /// </summary>
  78. public bool HighDpi { get; set; } = true;
  79. /// <summary>
  80. /// Add any flag listed here: http://urho3d.github.io/documentation/1.7/_running.html
  81. /// </summary>
  82. public string AdditionalFlags { get; set; } = string.Empty;
  83. /// <summary>
  84. /// Windows: external window handle (WinForms Panel.Handle) to use in order to display Urho game
  85. /// You can use it in WPF via WindowsFormsHost (and a WF panel inside it)
  86. /// </summary>
  87. public IntPtr ExternalWindow { get; set; }
  88. public bool DelayedStart { get; set; } = false;
  89. public bool AutoloadCoreData { get; set; } = true;
  90. public string[] ResourcePrefixPaths { get; set; }
  91. public int Multisampling { get; set; }
  92. public bool UseDirectX11 { get; set; }
  93. public enum OrientationType
  94. {
  95. Landscape,
  96. Portrait,
  97. LandscapeAndPortrait
  98. }
  99. public override string ToString()
  100. {
  101. StringBuilder builder = new StringBuilder();
  102. builder.Append("args");//it will be skipped by Urho;
  103. #if !__IOS__ //always use -w on iOS
  104. if (WindowedMode)
  105. #endif
  106. builder.Append(" -w");
  107. if (!LimitFps)
  108. builder.Append(" -nolimit");
  109. if (DelayedStart)
  110. builder.Append(" -delayedstart");
  111. if (Width > 0)
  112. builder.AppendFormat(" -x {0}", Width);
  113. if (Height > 0)
  114. builder.AppendFormat(" -y {0}", Height);
  115. if (Multisampling > 0)
  116. builder.AppendFormat(" -m {0}", Multisampling);
  117. #if !__IOS__ //always use -s on iOS
  118. if (ResizableWindow)
  119. #endif
  120. builder.Append(" -s");
  121. string[] resourcePathes =
  122. #if __ANDROID__
  123. new[] { "Assets/CoreData" } // CoreData on Android is embedded into the lib now
  124. #else
  125. new[] { "CoreData" }
  126. #endif
  127. .Concat(ResourcePaths ?? new string[0]).ToArray();
  128. if (!AutoloadCoreData)
  129. resourcePathes = ResourcePaths ?? new string[0];
  130. builder.AppendFormat(" -p \"{0}\"", string.Join(";", resourcePathes.Distinct()));
  131. if (ResourcePackagesPaths?.Length > 0)
  132. builder.AppendFormat(" -pf \"{0}\"", string.Join(";", ResourcePackagesPaths));
  133. string[] resourcePrefixPaths = ResourcePrefixPaths;
  134. #if NET45
  135. var urhoDllFolder = System.IO.Path.GetDirectoryName(typeof(SimpleApplication).Assembly.Location);
  136. var possibleCoreDataDirectories = new[]
  137. {
  138. Environment.CurrentDirectory,
  139. System.IO.Path.Combine(urhoDllFolder, "../../native"), //in case if Urho.dll is loaded from the nuget directory directly (see UrhoSharp.targets)
  140. urhoDllFolder,
  141. };
  142. if (ResourcePrefixPaths?.Length > 0)
  143. possibleCoreDataDirectories = ResourcePrefixPaths.Concat(possibleCoreDataDirectories).Distinct().ToArray();
  144. resourcePrefixPaths = possibleCoreDataDirectories;
  145. if (System.Diagnostics.Debugger.IsAttached && Environment.OSVersion.Platform == PlatformID.Win32NT)
  146. {
  147. NoSound = true;
  148. System.Diagnostics.Debug.WriteLine("WARNING! Sound is disabled on Windows when debugger is attached (temporarily).");
  149. }
  150. #endif
  151. if (resourcePrefixPaths?.Length > 0)
  152. builder.AppendFormat(" -pp \"{0}\"", string.Join(";", resourcePrefixPaths));
  153. #if !WINDOWS_UWP
  154. if (TouchEmulation)
  155. #endif
  156. builder.Append(" -touch");
  157. if (HighDpi)
  158. builder.Append(" -hd");
  159. if (NoSound)
  160. builder.Append(" -nosound");
  161. switch (Orientation)
  162. {
  163. case OrientationType.Landscape:
  164. builder.Append(" -landscape");
  165. break;
  166. case OrientationType.Portrait:
  167. builder.Append(" -portrait");
  168. break;
  169. case OrientationType.LandscapeAndPortrait:
  170. builder.Append(" -landscape -portrait");
  171. break;
  172. }
  173. return builder + " " + AdditionalFlags;
  174. }
  175. }
  176. }