1 /** 2 Class that has everything pertaining to a 2D world. 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.world2d; 14 import std.meta : AliasSeq, staticIndexOf; 15 import std.traits : Unqual; 16 import godot.d.traits; 17 import godot.core; 18 import godot.c; 19 import godot.d.bind; 20 import godot.d.reference; 21 import godot.globalenums; 22 import godot.object; 23 import godot.classdb; 24 import godot.resource; 25 import godot.reference; 26 import godot.physics2ddirectspacestate; 27 /** 28 Class that has everything pertaining to a 2D world. 29 30 A physics space, a visual scenario and a sound space. 2D nodes register their resources into the current 2D world. 31 */ 32 @GodotBaseClass struct World2D 33 { 34 package(godot) enum string _GODOT_internal_name = "World2D"; 35 public: 36 @nogc nothrow: 37 union { /** */ godot_object _godot_object; /** */ Resource _GODOT_base; } 38 alias _GODOT_base this; 39 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 40 package(godot) __gshared bool _classBindingInitialized = false; 41 package(godot) static struct GDNativeClassBinding 42 { 43 __gshared: 44 @GodotName("get_canvas") GodotMethod!(RID) getCanvas; 45 @GodotName("get_direct_space_state") GodotMethod!(Physics2DDirectSpaceState) getDirectSpaceState; 46 @GodotName("get_space") GodotMethod!(RID) getSpace; 47 } 48 /// 49 pragma(inline, true) bool opEquals(in World2D other) const 50 { return _godot_object.ptr is other._godot_object.ptr; } 51 /// 52 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 53 { _godot_object.ptr = n; return null; } 54 /// 55 pragma(inline, true) bool opEquals(typeof(null) n) const 56 { return _godot_object.ptr is n; } 57 /// 58 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 59 mixin baseCasts; 60 /// Construct a new instance of World2D. 61 /// Note: use `memnew!World2D` instead. 62 static World2D _new() 63 { 64 static godot_class_constructor constructor; 65 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("World2D"); 66 if(constructor is null) return typeof(this).init; 67 return cast(World2D)(constructor()); 68 } 69 @disable new(size_t s); 70 /** 71 72 */ 73 RID getCanvas() 74 { 75 checkClassBinding!(typeof(this))(); 76 return ptrcall!(RID)(GDNativeClassBinding.getCanvas, _godot_object); 77 } 78 /** 79 80 */ 81 Physics2DDirectSpaceState getDirectSpaceState() 82 { 83 checkClassBinding!(typeof(this))(); 84 return ptrcall!(Physics2DDirectSpaceState)(GDNativeClassBinding.getDirectSpaceState, _godot_object); 85 } 86 /** 87 88 */ 89 RID getSpace() 90 { 91 checkClassBinding!(typeof(this))(); 92 return ptrcall!(RID)(GDNativeClassBinding.getSpace, _godot_object); 93 } 94 /** 95 The $(D RID) of this world's canvas resource. Used by the $(D VisualServer) for 2D drawing. 96 */ 97 @property RID canvas() 98 { 99 return getCanvas(); 100 } 101 /** 102 Direct access to the world's physics 2D space state. Used for querying current and potential collisions. When using multi-threaded physics, access is limited to `_physics_process(delta)` in the main thread. 103 */ 104 @property Physics2DDirectSpaceState directSpaceState() 105 { 106 return getDirectSpaceState(); 107 } 108 /** 109 The $(D RID) of this world's physics space resource. Used by the $(D Physics2DServer) for 2D physics, treating it as both a space and an area. 110 */ 111 @property RID space() 112 { 113 return getSpace(); 114 } 115 }