DI-Guy SDK Documentation  13.2
diguySignal.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2019 VT MAK
4  ** All rights reserved.
5  *********************************************************************/
6 
7 /*********************************************************************
8  **
9  *t diguySignal
10  **
11  *b Link against: libdiguy
12  */
13 
14 #ifndef __diguySignal_H
15 #define __diguySignal_H
16 
17 #ifdef SWIG
18 %module diguySignal
19 #else
20 #define CPLUSPLUS_ONLY
21 #endif
22 
23 #ifdef CPLUSPLUS_ONLY
24 
25 class bdiScenarioSignal;
26 class diguySignal;
27 
28 #include <stdio.h> // for NULL
29 #include <diguy_constants.h>
30 #include <diguy_typedefs.h>
31 
32 #endif /* CPLUSPLUS_ONLY */
33 
34 
35 #include <declspec_diguy.h>
36 
37 /****************************************************************************/
38 class BDI_DECLSPEC_diguy diguySignal
39 {
40 
41 public:
42 
43  /*l
44  *b Description:
45  **
46  ** Returns the name of the object. This pointer will
47  ** never be NULL.
48  **
49  *b Returns:
50  **
51  ** name of the signal
52  **
53  *b Callable From:
54  **
55  *- - C++
56  *- - Script
57  */
58  const char* get_name();
59 
60  /*l
61  *b Description:
62  **
63  ** This function sets the name of this object.
64  **
65  *b Returns:
66  **
67  ** 0 on success, -1 on failure
68  **
69  *b Callable From:
70  **
71  *- - C++
72  *- - Script
73  */
74  int set_name(const char* name);
75 
76  /*l
77  *b Description:
78  **
79  ** Returns the type name of the object. This pointer will
80  ** never be NULL.
81  **
82  *b Returns:
83  **
84  ** type name of the object
85  **
86  *b Callable From:
87  **
88  *- - C++
89  *- - Script
90  */
91  const char* get_type_name();
92 
93  /*l
94  *b Description:
95  **
96  ** This function resets the signal. The number of times the signal
97  ** has been triggered will be set to 0.
98  **
99  *b Returns:
100  **
101  ** 0 on success, -1 on failure
102  **
103  *b Callable From:
104  **
105  *- - C++
106  *- - Script
107  *- - Decision Bead
108  */
109  int reset();
110 
111  /*l
112  *b Description:
113  **
114  ** This function triggers the signal. If a sound is associated with
115  ** the signal, it will be played. The number of times the signal
116  ** has been triggered will be incremented by one.
117  **
118  *b Returns:
119  **
120  ** 0 on success, -1 on failure
121  **
122  *b Callable From:
123  **
124  *- - C++
125  *- - Script
126  *- - Decision Bead
127  */
128  int trigger();
129 
130  /*l
131  *b Returns:
132  **
133  ** Returns the number of times this signal has been triggered since
134  ** the scenario started or since the last call to reset().
135  **
136  *b Callable From:
137  **
138  *- - C++
139  *- - Script
140  *- - Decision Bead
141  */
142  int triggered();
143 
144  /*l
145  *b Returns:
146  **
147  ** Returns 1 if the signal has been triggered at least n
148  ** times, else returns 0.
149  **
150  *b Callable From:
151  **
152  *- - C++
153  *- - Script
154  *- - Decision Bead
155  */
156  int triggered_at_least_n_times(int n);
157 
158  /*l
159  *b Description:
160  **
161  ** This function causes the button for this signal to become visible
162  ** in the DI-Guy Scenario Signal Palette.
163  **
164  ** This function is for DI-Guy Scenario only.
165  **
166  *b Returns:
167  **
168  ** 0 on success, -1 on failure
169  **
170  *b Callable From:
171  **
172  *- - C++
173  *- - Script
174  */
175  int signal_palette_show();
176 
177  /*l
178  *b Description:
179  **
180  ** This function causes the button for this signal to become hidden
181  ** in the DI-Guy Scenario Signal Palette.
182  **
183  ** This function is for DI-Guy Scenario only.
184  **
185  *b Returns:
186  **
187  ** 0 on success, -1 on failure
188  **
189  *b Callable From:
190  **
191  *- - C++
192  *- - Script
193  */
194  int signal_palette_hide();
195 
196  /*l
197  *b Description:
198  **
199  ** This function returns a flag specifying whether the signal's
200  ** button is visible in the DI-Guy Scenario Signal Palette.
201  **
202  ** This function is for DI-Guy Scenario only.
203  **
204  *b Returns:
205  **
206  ** 1 if the signal's button is visible, 0 if not
207  **
208  *b Callable From:
209  **
210  *- - C++
211  *- - Script
212  */
213  int get_is_visible_in_signal_palette();
214 
215  /*l
216  *b Description:
217  **
218  ** This function returns an optional signal description buffer.
219  **
220  *b Returns:
221  **
222  ** pointer to info text
223  **
224  *b Callable From:
225  **
226  *- - C++
227  *- - Script
228  */
229  const char* get_info_text();
230 
231  /*l
232  *b Description:
233  **
234  ** This function sets an optional signal description buffer.
235  **
236  *b Arguments:
237  **
238  *a info_text - text of info
239  **
240  *b Callable From:
241  **
242  *- - C++
243  *- - Script
244  */
245  void set_info_text(const char* info_text);
246 
247 
248 /*****************************************************************************/
253  /*l
254  *b Description:
255  **
256  ** This is an enumeration of the different callbacks
257  ** that can be registered with add_callback() and
258  ** add_callback_script().
259  **
260  *b Usable From:
261  **
262  *- - C++
263  *- - Script
264  */
265  enum {
266  CALLBACK_ID_PRE_TRIGGER = 1,
267  CALLBACK_ID_POST_TRIGGER
268  };
269 
270 #ifdef CPLUSPLUS_ONLY
271 
272  /*l
273  *b Description:
274  **
275  ** This function adds a user callback.
276  **
277  *b Arguments:
278  **
279  *a callback - pointer to function with prototype
280  *a diguySignalCallback (typedefed above)
281  *a callback_id - integer id of when this callback is to be called
282  *a callback_params - not currently used; pass NULL
283  *a callback_user_data - pointer for user's own use; DI-Guy will
284  *a do nothing to the contents of this pointer
285  *a beyond passing it back when the callback is
286  *a invoked
287  **
288  ** callback_id should be one of the following values:
289  **
290  *i CALLBACK_ID_PRE_TRIGGER
291  **
292  ** This callback will be called whenever the trigger() function
293  ** is called, whether internally by DI-Guy of explicitly by
294  ** the user in C++ or in a script. It will be called before
295  ** the default handler of the function.
296  **
297  ** There are no parameters for this callback.
298  **
299  *i CALLBACK_ID_POST_TRIGGER
300  **
301  ** This callback will be called whenever the trigger() function
302  ** is called, whether internally by DI-Guy of explicitly by
303  ** the user in C++ or in a script. It will be called after
304  ** the default handler of the function.
305  **
306  ** There are no parameters for this callback.
307  **
308  *i Callback Return Values:
309  **
310  ** Callbacks return a value of type diguyCallbackReturn,
311  ** which will be DIGUY_CALLBACK_STOP or DIGUY_CALLBACK_CONTINUE.
312  ** If the callback returns DIGUY_CALLBACK_STOP, the default handler
313  ** of the function will not be called; the callback is asserting
314  ** that it has done everything necessary for the function call.
315  ** If the callback returns DIGUY_CALLBACK_CONTINUE, the default
316  ** handler for the function will be called after the callback.
317  **
318  *b Returns:
319  **
320  ** 0 on success, -1 on failure
321  **
322  *b Callable From:
323  **
324  *- - C++
325  */
326  int add_callback(int callback_id,
327  diguySignalCallback* callback,
328  void* callback_params = 0,
329  void* callback_user_data = 0);
330 
331  /*l
332  *b Description:
333  **
334  ** This function removes a user callback. All callbacks matching
335  ** the specified callback_id and callback function will be removed.
336  **
337  *b Arguments:
338  **
339  *a callback_id - integer id of when this callback is to be called
340  *a callback - pointer to function with prototype
341  *a diguySignalCallback (typedefed above)
342  **
343  *b Returns:
344  **
345  ** 0 on success, -1 on failure
346  **
347  *b Callable From:
348  **
349  *- - C++
350  */
351  int remove_callback(int callback_id,
352  diguySignalCallback* callback);
353 
354  /*l
355  *b Description:
356  **
357  ** This function removes a user callback. All callbacks matching
358  ** the specified callback_id and callback_user_data pointer will
359  ** be removed.
360  **
361  *b Arguments:
362  **
363  *a callback_id - integer id of when this callback is to be called
364  *a callback_user_data - pointer for user's own use
365  **
366  *b Returns:
367  **
368  ** 0 on success, -1 on failure
369  **
370  *b Callable From:
371  **
372  *- - C++
373  */
374  int remove_callback_with_user_data(int callback_id,
375  void* callback_user_data);
376 
377 #endif /* CPLUSPLUS_ONLY */
378 
379  /*l
380  *b Description:
381  **
382  ** This function adds a user callback script. Callback scripts can
383  ** be removed with remove_callback_script().
384  **
385  ** See diguyCharacter::add_callback_script() for an example
386  ** of use.
387  **
388  *b Arguments:
389  **
390  *a callback_id - integer id of the callback
391  *a callback_script - script text of callback to be added
392  *a callback_script_type - the type of script contained in
393  *a callback_script
394  **
395  ** If NULL is passed for callback_script_type, a default script type
396  ** will be derived based on the default script interpreter of the
397  ** scenario.
398  **
399  *i Lua specific:
400  **
401  ** When the script is called, the object for which it is being called
402  ** will be in the callback_object global.
403  **
404  ** To pass NULL when calling from a lua script, use nil.
405  **
406  *b Returns:
407  **
408  ** 0 on success, -1 on failure
409  **
410  *b Callable From:
411  **
412  *- - C++
413  *- - Script
414  */
415  int add_callback_script(int callback_id,
416  const char* callback_script,
417  const char* callback_script_type = NULL);
418 
419  /*l
420  *b Description:
421  **
422  ** This function removes a user callback script previously added with
423  ** add_callback_script().
424  **
425  ** See diguyCharacter::remove_callback_script() for an example
426  ** of use.
427  **
428  *b Arguments:
429  **
430  *a callback_id - integer id of the callback
431  *a callback_script - script text of callback previously added
432  *a callback_script_type - the type of script contained in
433  *a callback_script
434  **
435  ** If NULL is passed for callback_script, all callback
436  ** scripts whose ids match callback_id and whose types match
437  ** callback_script_type will be removed.
438  **
439  ** If NULL is passed for callback_script_type, a default script type
440  ** will be derived based on the default script interpreter of the
441  ** scenario.
442  **
443  *i Lua specific:
444  **
445  ** To pass NULL when calling from a lua script, use nil.
446  **
447  *b Returns:
448  **
449  ** 0 on success, -1 on failure
450  **
451  *b Callable From:
452  **
453  *- - C++
454  *- - Script
455  */
456  int remove_callback_script(int callback_id,
457  const char* callback_script,
458  const char* callback_script_type = NULL);
459 
460 
461 /*****************************************************************************/
467  /*l
468  *b Description:
469  **
470  ** This function maps the event handler with the given name
471  ** to a callback id. This mapping will be saved in the .dss
472  ** file and restored when the .dss file is loaded.
473  **
474  ** Mappings can also be made via the DI-Guy Scenario UI.
475  **
476  ** The event handler is one of the following:
477  **
478  *- - a signal callback function registered by
479  *- diguyScenario::register_signal_event_handler() or
480  *- diguyScenario::register_signal_event_handler_from_library()
481  *- - a script registered by
482  *- diguyScenario::register_signal_event_handler_script()
483  *- - a Script, Decision, or Library Function in the scenario
484  *- whose "Event Type" is "Signal"
485  **
486  *b Arguments:
487  **
488  *a callback_id - integer id of callback
489  *a handler_name - name of the event handler to map
490  **
491  *b Returns:
492  **
493  ** 0 on success, -1 on failure
494  **
495  *b Callable From:
496  **
497  *- - C++
498  *- - Script
499  */
500  int map_event_handler_to_callback_id(int callback_id,
501  const char* handler_name);
502 
503  /*l
504  *b Description:
505  **
506  ** This function unmaps the event handler with the given name
507  ** from a callback id.
508  **
509  *b Arguments:
510  **
511  *a callback_id - integer id of callback
512  *a handler_name - name of the event handler to map
513  *a unmap_all_matches - pass 0 to unmap only the first match,
514  *a pass 1 to unmap all matches
515  **
516  *b Returns:
517  **
518  ** 0 on success, -1 on failure
519  **
520  *b Callable From:
521  **
522  *- - C++
523  *- - Script
524  */
525  int unmap_event_handler_from_callback_id(int callback_id,
526  const char* handler_name,
527  int unmap_all_matches = 0);
528 
529 
534 #ifdef CPLUSPLUS_ONLY
535 
536  bdiScenarioSignal* get_scripted_object() {return m_signal;}
537 
538 private:
539 
540  /*l
541  ** A private constructor.
542  */
543  diguySignal(bdiScenarioSignal* signal);
544 
545  /*l
546  ** A pointer to internal data.
547  */
548  bdiScenarioSignal* m_signal;
549 
550  friend class bdiScenarioSignal;
551 
552 #endif /* CPLUSPLUS_ONLY */
553 
554 };
555 
556 #endif /* __diguySignal_H */
Definition: diguySignal.h:36
diguyCallbackReturn diguySignalCallback(diguySignal *signal, int callback_id, void *callback_params, void *callback_user_data)
Definition: diguy_typedefs.h:184