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 event
101 {
102     int type;
103 }
104 
105 deprecated("Use instead `@event(type)`")
106 {
107     template FunEvent(int ev)
108     {
109         enum FunEvent = event(ev);
110     }
111     
112     alias Event = FunEvent;
113 }
114 
115 /++
116 Trigger flag. It is hung on a function where triggers with the selected
117 name will be listened to.
118 
119 Example:
120 ---
121 @Trigger("Attack")
122 void onAttack() { ... }
123 ---
124 +/
125 struct Trigger
126 {
127 public:
128     string name;
129 }
130 
131 /++
132 Event flag. Functions with this attribute will listen for collision events
133 only for the instance selected in the arguments (by name and / or tag).
134 
135 Example:
136 ---
137 @Collision("Wolf")
138 void onWolfCollision(Instance wolf) { ... }
139 ---
140 +/
141 struct Collision
142 {
143 public:
144     string name; /// Component name
145     string tag; /// Component tag.
146 }
147 
148 /++
149 Attribute indicating in which thread you need to make an object step.
150 
151 Example:
152 ---
153 @StepThread(2) void threadStep() @safe
154 {
155     ...
156 }
157 ---
158 +/
159 struct StepThread
160 {
161 public:
162     size_t id;
163 }
164 
165 /++
166 Attribute indicating that the flow function function
167 (guarantees the programmer himself) and can be transferred to another
168 stream to accelerate. Do not combine with the  @event(step).
169 +/
170 struct stepThreadSafe {}
171 
172 struct args(T...)
173 {
174     alias members = T;
175 }