1 /** 2 Access to basic engine properties. 3 4 Copyright: 5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. 6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) 7 Copyright (c) 2017-2018 Godot-D contributors 8 9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License) 10 11 12 */ 13 module godot.engine; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.meta; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.object; 22 import godot.mainloop; 23 /** 24 Access to basic engine properties. 25 26 The `Engine` class allows you to query and modify the game's run-time parameters, such as frames per second, time scale, and others. 27 */ 28 @GodotBaseClass struct EngineSingleton 29 { 30 enum string _GODOT_internal_name = "_Engine"; 31 public: 32 @nogc nothrow: 33 union { godot_object _godot_object; GodotObject _GODOT_base; } 34 alias _GODOT_base this; 35 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 36 package(godot) __gshared bool _classBindingInitialized = false; 37 package(godot) static struct _classBinding 38 { 39 __gshared: 40 godot_object _singleton; 41 immutable char* _singletonName = "Engine"; 42 @GodotName("set_iterations_per_second") GodotMethod!(void, long) setIterationsPerSecond; 43 @GodotName("get_iterations_per_second") GodotMethod!(long) getIterationsPerSecond; 44 @GodotName("set_physics_jitter_fix") GodotMethod!(void, double) setPhysicsJitterFix; 45 @GodotName("get_physics_jitter_fix") GodotMethod!(double) getPhysicsJitterFix; 46 @GodotName("set_target_fps") GodotMethod!(void, long) setTargetFps; 47 @GodotName("get_target_fps") GodotMethod!(long) getTargetFps; 48 @GodotName("set_time_scale") GodotMethod!(void, double) setTimeScale; 49 @GodotName("get_time_scale") GodotMethod!(double) getTimeScale; 50 @GodotName("get_frames_drawn") GodotMethod!(long) getFramesDrawn; 51 @GodotName("get_frames_per_second") GodotMethod!(double) getFramesPerSecond; 52 @GodotName("get_main_loop") GodotMethod!(MainLoop) getMainLoop; 53 @GodotName("get_version_info") GodotMethod!(Dictionary) getVersionInfo; 54 @GodotName("get_author_info") GodotMethod!(Dictionary) getAuthorInfo; 55 @GodotName("get_copyright_info") GodotMethod!(Array) getCopyrightInfo; 56 @GodotName("get_donor_info") GodotMethod!(Dictionary) getDonorInfo; 57 @GodotName("get_license_info") GodotMethod!(Dictionary) getLicenseInfo; 58 @GodotName("get_license_text") GodotMethod!(String) getLicenseText; 59 @GodotName("is_in_physics_frame") GodotMethod!(bool) isInPhysicsFrame; 60 @GodotName("has_singleton") GodotMethod!(bool, String) hasSingleton; 61 @GodotName("get_singleton") GodotMethod!(GodotObject, String) getSingleton; 62 @GodotName("set_editor_hint") GodotMethod!(void, bool) setEditorHint; 63 @GodotName("is_editor_hint") GodotMethod!(bool) isEditorHint; 64 } 65 bool opEquals(in EngineSingleton other) const { return _godot_object.ptr is other._godot_object.ptr; } 66 EngineSingleton opAssign(T : typeof(null))(T n) { _godot_object.ptr = null; } 67 bool opEquals(typeof(null) n) const { return _godot_object.ptr is null; } 68 mixin baseCasts; 69 static EngineSingleton _new() 70 { 71 static godot_class_constructor constructor; 72 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("_Engine"); 73 if(constructor is null) return typeof(this).init; 74 return cast(EngineSingleton)(constructor()); 75 } 76 @disable new(size_t s); 77 /** 78 79 */ 80 void setIterationsPerSecond(in long iterations_per_second) 81 { 82 checkClassBinding!(typeof(this))(); 83 ptrcall!(void)(_classBinding.setIterationsPerSecond, _godot_object, iterations_per_second); 84 } 85 /** 86 87 */ 88 long getIterationsPerSecond() const 89 { 90 checkClassBinding!(typeof(this))(); 91 return ptrcall!(long)(_classBinding.getIterationsPerSecond, _godot_object); 92 } 93 /** 94 95 */ 96 void setPhysicsJitterFix(in double physics_jitter_fix) 97 { 98 checkClassBinding!(typeof(this))(); 99 ptrcall!(void)(_classBinding.setPhysicsJitterFix, _godot_object, physics_jitter_fix); 100 } 101 /** 102 103 */ 104 double getPhysicsJitterFix() const 105 { 106 checkClassBinding!(typeof(this))(); 107 return ptrcall!(double)(_classBinding.getPhysicsJitterFix, _godot_object); 108 } 109 /** 110 111 */ 112 void setTargetFps(in long target_fps) 113 { 114 checkClassBinding!(typeof(this))(); 115 ptrcall!(void)(_classBinding.setTargetFps, _godot_object, target_fps); 116 } 117 /** 118 119 */ 120 long getTargetFps() const 121 { 122 checkClassBinding!(typeof(this))(); 123 return ptrcall!(long)(_classBinding.getTargetFps, _godot_object); 124 } 125 /** 126 127 */ 128 void setTimeScale(in double time_scale) 129 { 130 checkClassBinding!(typeof(this))(); 131 ptrcall!(void)(_classBinding.setTimeScale, _godot_object, time_scale); 132 } 133 /** 134 135 */ 136 double getTimeScale() 137 { 138 checkClassBinding!(typeof(this))(); 139 return ptrcall!(double)(_classBinding.getTimeScale, _godot_object); 140 } 141 /** 142 Returns the total number of frames drawn. 143 */ 144 long getFramesDrawn() 145 { 146 checkClassBinding!(typeof(this))(); 147 return ptrcall!(long)(_classBinding.getFramesDrawn, _godot_object); 148 } 149 /** 150 Returns the frames per second of the running game. 151 */ 152 double getFramesPerSecond() const 153 { 154 checkClassBinding!(typeof(this))(); 155 return ptrcall!(double)(_classBinding.getFramesPerSecond, _godot_object); 156 } 157 /** 158 Returns the main loop object (see $(D MainLoop) and $(D SceneTree)). 159 */ 160 MainLoop getMainLoop() const 161 { 162 checkClassBinding!(typeof(this))(); 163 return ptrcall!(MainLoop)(_classBinding.getMainLoop, _godot_object); 164 } 165 /** 166 Returns the current engine version information in a Dictionary. 167 "major" - Holds the major version number as an int 168 "minor" - Holds the minor version number as an int 169 "patch" - Holds the patch version number as an int 170 "status" - Holds the status (e.g. "beta", "rc1", "rc2", ... "stable") as a String 171 "build" - Holds the build name (e.g. "custom-build") as a String 172 "string" - major + minor + patch + status + build in a single String 173 */ 174 Dictionary getVersionInfo() const 175 { 176 checkClassBinding!(typeof(this))(); 177 return ptrcall!(Dictionary)(_classBinding.getVersionInfo, _godot_object); 178 } 179 /** 180 Returns engine author information in a Dictionary. 181 "lead_developers" - Array of Strings, lead developer names 182 "founders" - Array of Strings, founder names 183 "project_managers" - Array of Strings, project manager names 184 "developers" - Array of Strings, developer names 185 */ 186 Dictionary getAuthorInfo() const 187 { 188 checkClassBinding!(typeof(this))(); 189 return ptrcall!(Dictionary)(_classBinding.getAuthorInfo, _godot_object); 190 } 191 /** 192 Returns an Array of copyright information Dictionaries. 193 "name" - String, component name 194 "parts" - Array of Dictionaries {"files", "copyright", "license"} describing subsections of the component 195 */ 196 Array getCopyrightInfo() const 197 { 198 checkClassBinding!(typeof(this))(); 199 return ptrcall!(Array)(_classBinding.getCopyrightInfo, _godot_object); 200 } 201 /** 202 Returns a Dictionary of Arrays of donor names. 203 {"platinum_sponsors", "gold_sponsors", "mini_sponsors", "gold_donors", "silver_donors", "bronze_donors"} 204 */ 205 Dictionary getDonorInfo() const 206 { 207 checkClassBinding!(typeof(this))(); 208 return ptrcall!(Dictionary)(_classBinding.getDonorInfo, _godot_object); 209 } 210 /** 211 Returns Dictionary of licenses used by Godot and included third party components. 212 */ 213 Dictionary getLicenseInfo() const 214 { 215 checkClassBinding!(typeof(this))(); 216 return ptrcall!(Dictionary)(_classBinding.getLicenseInfo, _godot_object); 217 } 218 /** 219 Returns Godot license text. 220 */ 221 String getLicenseText() const 222 { 223 checkClassBinding!(typeof(this))(); 224 return ptrcall!(String)(_classBinding.getLicenseText, _godot_object); 225 } 226 /** 227 Returns `true` if the game is inside the fixed process and physics phase of the game loop. 228 */ 229 bool isInPhysicsFrame() const 230 { 231 checkClassBinding!(typeof(this))(); 232 return ptrcall!(bool)(_classBinding.isInPhysicsFrame, _godot_object); 233 } 234 /** 235 236 */ 237 bool hasSingleton(StringArg0)(in StringArg0 name) const 238 { 239 checkClassBinding!(typeof(this))(); 240 return ptrcall!(bool)(_classBinding.hasSingleton, _godot_object, name); 241 } 242 /** 243 244 */ 245 GodotObject getSingleton(StringArg0)(in StringArg0 name) const 246 { 247 checkClassBinding!(typeof(this))(); 248 return ptrcall!(GodotObject)(_classBinding.getSingleton, _godot_object, name); 249 } 250 /** 251 252 */ 253 void setEditorHint(in bool enabled) 254 { 255 checkClassBinding!(typeof(this))(); 256 ptrcall!(void)(_classBinding.setEditorHint, _godot_object, enabled); 257 } 258 /** 259 260 */ 261 bool isEditorHint() const 262 { 263 checkClassBinding!(typeof(this))(); 264 return ptrcall!(bool)(_classBinding.isEditorHint, _godot_object); 265 } 266 /** 267 If `true`, it is running inside the editor. Useful for tool scripts. 268 */ 269 @property bool editorHint() 270 { 271 return isEditorHint(); 272 } 273 /// ditto 274 @property void editorHint(bool v) 275 { 276 setEditorHint(v); 277 } 278 /** 279 The number of fixed iterations per second (for fixed process and physics). 280 */ 281 @property long iterationsPerSecond() 282 { 283 return getIterationsPerSecond(); 284 } 285 /// ditto 286 @property void iterationsPerSecond(long v) 287 { 288 setIterationsPerSecond(v); 289 } 290 /** 291 The desired frames per second. If the hardware cannot keep up, this setting may not be respected. Defaults to 0, which indicates no limit. 292 */ 293 @property long targetFps() 294 { 295 return getTargetFps(); 296 } 297 /// ditto 298 @property void targetFps(long v) 299 { 300 setTargetFps(v); 301 } 302 /** 303 Controls how fast or slow the in-game clock ticks versus the real life one. It defaults to 1.0. A value of 2.0 means the game moves twice as fast as real life, whilst a value of 0.5 means the game moves at half the regular speed. 304 */ 305 @property double timeScale() 306 { 307 return getTimeScale(); 308 } 309 /// ditto 310 @property void timeScale(double v) 311 { 312 setTimeScale(v); 313 } 314 /** 315 316 */ 317 @property double physicsJitterFix() 318 { 319 return getPhysicsJitterFix(); 320 } 321 /// ditto 322 @property void physicsJitterFix(double v) 323 { 324 setPhysicsJitterFix(v); 325 } 326 } 327 /// Returns: the EngineSingleton 328 @property @nogc nothrow pragma(inline, true) 329 EngineSingleton Engine() 330 { 331 checkClassBinding!EngineSingleton(); 332 return EngineSingleton(EngineSingleton._classBinding._singleton); 333 }