1 /++ 2 A module for describing some local events by means of function attributes. 3 4 Macros: 5 LREF = <a href="#$1">$1</a> 6 HREF = <a href="$1">$2</a> 7 PHOBREF = <a href="https://dlang.org/phobos/$1.html#$2">$2</a> 8 9 Authors: $(HREF https://github.com/TodNaz,TodNaz) 10 Copyright: Copyright (c) 2020 - 2021, TodNaz. 11 License: $(HREF https://github.com/TodNaz/Tida/blob/master/LICENSE,MIT) 12 +/ 13 module tida.localevent; 14 15 enum 16 { 17 /++ 18 Object initialization flag. Will be called when the very first scene 19 initialization occurs. When control is transferred to the scene again, 20 such functions will no longer be called. 21 +/ 22 Init, 23 24 /++ 25 A function with such a flag will be called only when the scene has already 26 been initialized and control is transferred to it again, and so on every time. 27 +/ 28 Restart, 29 30 /++ 31 A function with such a flag will be called when control is transferred to 32 the scene, regardless of whether it was initialized or not. 33 +/ 34 Entry, 35 36 /++ 37 A function with such a flag will be called only when the scene control is lost. 38 +/ 39 Leave, 40 41 /++ 42 This flag is called every unit of the game loop pass in the current scene. 43 +/ 44 Step, 45 46 /++ 47 This function with a flag will be called when the user has entered something. 48 Like a mouse, keyboard, joystick, etc. 49 +/ 50 Input, 51 52 /++ 53 This function will be called to draw an object to form a frame. 54 +/ 55 Draw, 56 57 /++ 58 A function with this flag will respond to all triggers that were 59 called in the current scene. 60 +/ 61 AnyTrigger, 62 63 /++ 64 A function with this flag will react to all collisions of two objects 65 (only applicable to an instance). 66 +/ 67 AnyCollision, 68 69 /++ 70 A function with this flag will react when the scene destroys the 71 owner of the function. 72 +/ 73 Destroy, 74 75 /++ 76 A function with such a flag will be called at the very beginning of the game 77 (if such an object was previously added to the constructor). 78 +/ 79 GameStart, 80 81 /++ 82 A function with this flag will be called when the game is restarted. 83 +/ 84 GameRestart, 85 86 /++ 87 A function with this flag will be called when the game ends. 88 It is not necessary to implement garbage cleaning here, it is enough to 89 implement it in destructors, here they usually implement the storage 90 of some data. 91 +/ 92 GameExit, 93 94 /++ 95 A function with this flag will be called when an unhandled error occurs. 96 +/ 97 GameError 98 } 99 100 struct FunEvent(int ev) {} 101 alias Event = FunEvent; 102 103 /++ 104 Trigger flag. It is hung on a function where triggers with the selected 105 name will be listened to. 106 107 Example: 108 --- 109 @Trigger("Attack") 110 void onAttack() { ... } 111 --- 112 +/ 113 struct Trigger 114 { 115 public: 116 string name; 117 } 118 119 /++ 120 Event flag. Functions with this attribute will listen for collision events 121 only for the instance selected in the arguments (by name and / or tag). 122 123 Example: 124 --- 125 @Collision("Wolf") 126 void onWolfCollision(Instance wolf) { ... } 127 --- 128 +/ 129 struct Collision 130 { 131 public: 132 string name; /// Component name 133 string tag; /// Component tag. 134 } 135 136 struct StepThread 137 { 138 public: 139 size_t id; 140 }