DI-Guy SDK Documentation  13.7.1
diguySignal.h
Go to the documentation of this file.
1 
2 /*********************************************************************
3  ** Copyright (c) 1992-2022 MAK Technologies, Inc.
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 
44 class BDI_DECLSPEC_diguy diguySignal
45 {
46 
47 public:
48  /*****************************************************************************/
58  /*l
59  *b Description:
60  **
61  ** Returns the name of the object. This pointer will
62  ** never be NULL.
63  **
64  *b Returns:
65  **
66  ** name of the signal
67  */
68  const char* get_name();
69 
70  /*l
71  *b Description:
72  **
73  ** This function sets the name of this object.
74  **
75  *b Returns:
76  **
77  ** 0 on success, -1 on failure
78  */
79  int set_name(const char* name);
80 
81  /*l
82  *b Description:
83  **
84  ** Returns the type name of the object. This pointer will
85  ** never be NULL.
86  **
87  *b Returns:
88  **
89  ** type name of the object
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  int signal_palette_show();
171 
172  /*l
173  *b Description:
174  **
175  ** This function causes the button for this signal to become hidden
176  ** in the DI-Guy Scenario Signal Palette.
177  **
178  ** This function is for DI-Guy Scenario only.
179  **
180  *b Returns:
181  **
182  ** 0 on success, -1 on failure
183  */
184  int signal_palette_hide();
185 
186  /*l
187  *b Description:
188  **
189  ** This function returns a flag specifying whether the signal's
190  ** button is visible in the DI-Guy Scenario Signal Palette.
191  **
192  ** This function is for DI-Guy Scenario only.
193  **
194  *b Returns:
195  **
196  ** 1 if the signal's button is visible, 0 if not
197  */
198  int get_is_visible_in_signal_palette();
199 
200  /*l
201  *b Description:
202  **
203  ** This function returns an optional signal description buffer.
204  **
205  *b Returns:
206  **
207  ** pointer to info text
208  */
209  const char* get_info_text();
210 
211  /*l
212  *b Description:
213  **
214  ** This function sets an optional signal description buffer.
215  **
216  *b Arguments:
217  **
218  *a info_text - text of info
219  */
220  void set_info_text(const char* info_text);
221 
222 
223 /*****************************************************************************/
228  /*l
229  *b Description:
230  **
231  ** This is an enumeration of the different callbacks
232  ** that can be registered with add_callback() and
233  ** add_callback_script().
234  **
235  *b Usable From:
236  **
237  *- - C++
238  *- - Script
239  */
240  enum {
241  CALLBACK_ID_PRE_TRIGGER = 1,
242  CALLBACK_ID_POST_TRIGGER
243  };
244 
245 #ifdef CPLUSPLUS_ONLY
246 
247  /*l
248  *b Description:
249  **
250  ** This function adds a user callback.
251  **
252  *b Arguments:
253  **
254  *a callback - pointer to function with prototype
255  *a diguySignalCallback (typedefed above)
256  *a callback_id - integer id of when this callback is to be called
257  *a callback_params - not currently used; pass NULL
258  *a callback_user_data - pointer for user's own use; DI-Guy will
259  *a do nothing to the contents of this pointer
260  *a beyond passing it back when the callback is
261  *a invoked
262  **
263  ** callback_id should be one of the following values:
264  **
265  *i CALLBACK_ID_PRE_TRIGGER
266  **
267  ** This callback will be called whenever the trigger() function
268  ** is called, whether internally by DI-Guy of explicitly by
269  ** the user in C++ or in a script. It will be called before
270  ** the default handler of the function.
271  **
272  ** There are no parameters for this callback.
273  **
274  *i CALLBACK_ID_POST_TRIGGER
275  **
276  ** This callback will be called whenever the trigger() function
277  ** is called, whether internally by DI-Guy of explicitly by
278  ** the user in C++ or in a script. It will be called after
279  ** the default handler of the function.
280  **
281  ** There are no parameters for this callback.
282  **
283  *i Callback Return Values:
284  **
285  ** Callbacks return a value of type diguyCallbackReturn,
286  ** which will be DIGUY_CALLBACK_STOP or DIGUY_CALLBACK_CONTINUE.
287  ** If the callback returns DIGUY_CALLBACK_STOP, the default handler
288  ** of the function will not be called; the callback is asserting
289  ** that it has done everything necessary for the function call.
290  ** If the callback returns DIGUY_CALLBACK_CONTINUE, the default
291  ** handler for the function will be called after the callback.
292  **
293  *b Returns:
294  **
295  ** 0 on success, -1 on failure
296  **
297  *b Callable From:
298  **
299  *- - C++
300  */
301  int add_callback(int callback_id,
302  diguySignalCallback* callback,
303  void* callback_params = 0,
304  void* callback_user_data = 0);
305 
306  /*l
307  *b Description:
308  **
309  ** This function removes a user callback. All callbacks matching
310  ** the specified callback_id and callback function will be removed.
311  **
312  *b Arguments:
313  **
314  *a callback_id - integer id of when this callback is to be called
315  *a callback - pointer to function with prototype
316  *a diguySignalCallback (typedefed above)
317  **
318  *b Returns:
319  **
320  ** 0 on success, -1 on failure
321  **
322  *b Callable From:
323  **
324  *- - C++
325  */
326  int remove_callback(int callback_id,
327  diguySignalCallback* callback);
328 
329  /*l
330  *b Description:
331  **
332  ** This function removes a user callback. All callbacks matching
333  ** the specified callback_id and callback_user_data pointer will
334  ** be removed.
335  **
336  *b Arguments:
337  **
338  *a callback_id - integer id of when this callback is to be called
339  *a callback_user_data - pointer for user's own use
340  **
341  *b Returns:
342  **
343  ** 0 on success, -1 on failure
344  **
345  *b Callable From:
346  **
347  *- - C++
348  */
349  int remove_callback_with_user_data(int callback_id,
350  void* callback_user_data);
351 
352 #endif /* CPLUSPLUS_ONLY */
353 
354  /*l
355  *b Description:
356  **
357  ** This function adds a user callback script. Callback scripts can
358  ** be removed with remove_callback_script().
359  **
360  ** See diguyCharacter::add_callback_script() for an example
361  ** of use.
362  **
363  *b Arguments:
364  **
365  *a callback_id - integer id of the callback
366  *a callback_script - script text of callback to be added
367  *a callback_script_type - the type of script contained in
368  *a callback_script
369  **
370  ** If NULL is passed for callback_script_type, a default script type
371  ** will be derived based on the default script interpreter of the
372  ** scenario.
373  **
374  *i Lua specific:
375  **
376  ** When the script is called, the object for which it is being called
377  ** will be in the callback_object global.
378  **
379  ** To pass NULL when calling from a lua script, use nil.
380  **
381  *b Returns:
382  **
383  ** 0 on success, -1 on failure
384  **
385  *b Callable From:
386  **
387  *- - C++
388  *- - Script
389  */
390  int add_callback_script(int callback_id,
391  const char* callback_script,
392  const char* callback_script_type = NULL);
393 
394  /*l
395  *b Description:
396  **
397  ** This function removes a user callback script previously added with
398  ** add_callback_script().
399  **
400  ** See diguyCharacter::remove_callback_script() for an example
401  ** of use.
402  **
403  *b Arguments:
404  **
405  *a callback_id - integer id of the callback
406  *a callback_script - script text of callback previously added
407  *a callback_script_type - the type of script contained in
408  *a callback_script
409  **
410  ** If NULL is passed for callback_script, all callback
411  ** scripts whose ids match callback_id and whose types match
412  ** callback_script_type will be removed.
413  **
414  ** If NULL is passed for callback_script_type, a default script type
415  ** will be derived based on the default script interpreter of the
416  ** scenario.
417  **
418  *i Lua specific:
419  **
420  ** To pass NULL when calling from a lua script, use nil.
421  **
422  *b Returns:
423  **
424  ** 0 on success, -1 on failure
425  **
426  *b Callable From:
427  **
428  *- - C++
429  *- - Script
430  */
431  int remove_callback_script(int callback_id,
432  const char* callback_script,
433  const char* callback_script_type = NULL);
434 
435 
436 /*****************************************************************************/
446  /*l
447  *b Description:
448  **
449  ** This function maps the event handler with the given name
450  ** to a callback id. This mapping will be saved in the .dss
451  ** file and restored when the .dss file is loaded.
452  **
453  ** Mappings can also be made via the DI-Guy Scenario UI.
454  **
455  ** The event handler is one of the following:
456  **
457  *- - a signal callback function registered by
458  *- diguyScenario::register_signal_event_handler() or
459  *- diguyScenario::register_signal_event_handler_from_library()
460  *- - a script registered by
461  *- diguyScenario::register_signal_event_handler_script()
462  *- - a Script, Decision, or Library Function in the scenario
463  *- whose "Event Type" is "Signal"
464  **
465  *b Arguments:
466  **
467  *a callback_id - integer id of callback
468  *a handler_name - name of the event handler to map
469  **
470  *b Returns:
471  **
472  ** 0 on success, -1 on failure
473  */
474  int map_event_handler_to_callback_id(int callback_id,
475  const char* handler_name);
476 
477  /*l
478  *b Description:
479  **
480  ** This function unmaps the event handler with the given name
481  ** from a callback id.
482  **
483  *b Arguments:
484  **
485  *a callback_id - integer id of callback
486  *a handler_name - name of the event handler to map
487  *a unmap_all_matches - pass 0 to unmap only the first match,
488  *a pass 1 to unmap all matches
489  **
490  *b Returns:
491  **
492  ** 0 on success, -1 on failure
493  */
494  int unmap_event_handler_from_callback_id(int callback_id,
495  const char* handler_name,
496  int unmap_all_matches = 0);
497 
498 
503 #ifdef CPLUSPLUS_ONLY
504 
505  bdiScenarioSignal* get_scripted_object() {return m_signal;}
506 
507 private:
508 
509  /*l
510  ** A private constructor.
511  */
512  diguySignal(bdiScenarioSignal* signal);
513 
514  /*l
515  ** A pointer to internal data.
516  */
517  bdiScenarioSignal* m_signal;
518 
519  friend class bdiScenarioSignal;
520 
521 #endif /* CPLUSPLUS_ONLY */
522 
523 };
524 
525 #endif /* __diguySignal_H */
Definition: diguySignal.h:42
diguyCallbackReturn diguySignalCallback(diguySignal *signal, int callback_id, void *callback_params, void *callback_user_data)
Definition: diguy_typedefs.h:193