1 /** 2 Enables certain nodes only when approximately visible. 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.visibilityenabler; 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.visibilitynotifier; 25 import godot.node; 26 /** 27 Enables certain nodes only when approximately visible. 28 29 The VisibilityEnabler will disable $(D RigidBody) and $(D AnimationPlayer) nodes when they are not visible. It will only affect other nodes within the same scene as the VisibilityEnabler itself. 30 If you just want to receive notifications, use $(D VisibilityNotifier) instead. 31 $(B Note:) VisibilityEnabler uses an approximate heuristic for performance reasons. It doesn't take walls and other occlusion into account. The heuristic is an implementation detail and may change in future versions. If you need precise visibility checking, use another method such as adding an $(D Area) node as a child of a $(D Camera) node and/or $(D Vector3.dot). 32 $(B Note:) VisibilityEnabler will not affect nodes added after scene initialization. 33 */ 34 @GodotBaseClass struct VisibilityEnabler 35 { 36 package(godot) enum string _GODOT_internal_name = "VisibilityEnabler"; 37 public: 38 @nogc nothrow: 39 union { /** */ godot_object _godot_object; /** */ VisibilityNotifier _GODOT_base; } 40 alias _GODOT_base this; 41 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 42 package(godot) __gshared bool _classBindingInitialized = false; 43 package(godot) static struct GDNativeClassBinding 44 { 45 __gshared: 46 @GodotName("_node_removed") GodotMethod!(void, Node) _nodeRemoved; 47 @GodotName("is_enabler_enabled") GodotMethod!(bool, long) isEnablerEnabled; 48 @GodotName("set_enabler") GodotMethod!(void, long, bool) setEnabler; 49 } 50 /// 51 pragma(inline, true) bool opEquals(in VisibilityEnabler other) const 52 { return _godot_object.ptr is other._godot_object.ptr; } 53 /// 54 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 55 { _godot_object.ptr = n; return null; } 56 /// 57 pragma(inline, true) bool opEquals(typeof(null) n) const 58 { return _godot_object.ptr is n; } 59 /// 60 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 61 mixin baseCasts; 62 /// Construct a new instance of VisibilityEnabler. 63 /// Note: use `memnew!VisibilityEnabler` instead. 64 static VisibilityEnabler _new() 65 { 66 static godot_class_constructor constructor; 67 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("VisibilityEnabler"); 68 if(constructor is null) return typeof(this).init; 69 return cast(VisibilityEnabler)(constructor()); 70 } 71 @disable new(size_t s); 72 /// 73 enum Enabler : int 74 { 75 /** 76 This enabler will pause $(D AnimationPlayer) nodes. 77 */ 78 enablerPauseAnimations = 0, 79 /** 80 This enabler will freeze $(D RigidBody) nodes. 81 */ 82 enablerFreezeBodies = 1, 83 /** 84 Represents the size of the $(D enabler) enum. 85 */ 86 enablerMax = 2, 87 } 88 /// 89 enum Constants : int 90 { 91 enablerPauseAnimations = 0, 92 enablerFreezeBodies = 1, 93 enablerMax = 2, 94 } 95 /** 96 97 */ 98 void _nodeRemoved(Node arg0) 99 { 100 Array _GODOT_args = Array.make(); 101 _GODOT_args.append(arg0); 102 String _GODOT_method_name = String("_node_removed"); 103 this.callv(_GODOT_method_name, _GODOT_args); 104 } 105 /** 106 Returns whether the enabler identified by given $(D enabler) constant is active. 107 */ 108 bool isEnablerEnabled(in long enabler) const 109 { 110 checkClassBinding!(typeof(this))(); 111 return ptrcall!(bool)(GDNativeClassBinding.isEnablerEnabled, _godot_object, enabler); 112 } 113 /** 114 Sets active state of the enabler identified by given $(D enabler) constant. 115 */ 116 void setEnabler(in long enabler, in bool enabled) 117 { 118 checkClassBinding!(typeof(this))(); 119 ptrcall!(void)(GDNativeClassBinding.setEnabler, _godot_object, enabler, enabled); 120 } 121 /** 122 If `true`, $(D RigidBody) nodes will be paused. 123 */ 124 @property bool freezeBodies() 125 { 126 return isEnablerEnabled(1); 127 } 128 /// ditto 129 @property void freezeBodies(bool v) 130 { 131 setEnabler(1, v); 132 } 133 /** 134 If `true`, $(D AnimationPlayer) nodes will be paused. 135 */ 136 @property bool pauseAnimations() 137 { 138 return isEnablerEnabled(0); 139 } 140 /// ditto 141 @property void pauseAnimations(bool v) 142 { 143 setEnabler(0, v); 144 } 145 }