DI-Guy SDK Documentation  13.6
diguySensorRegion.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 diguySensorRegion
10  **
11  *b Link against: libdiguy
12  */
13 
14 #ifndef __diguySensorRegion_H
15 #define __diguySensorRegion_H
16 
17 #ifdef SWIG
18 %module diguySensorRegion
19 #else
20 #define CPLUSPLUS_ONLY
21 #endif
22 
23 #ifdef CPLUSPLUS_ONLY
24 
25 #include <stdio.h> // for NULL definition
26 #include <diguy_constants.h>
27 #include <diguy_typedefs.h>
28 
29 class bdiScenarioSensorRegion;
30 class diguySensorRegion;
31 class diguyCharacter;
33 
34 #endif
35 
36 
37 #include <declspec_diguy.h>
43 class BDI_DECLSPEC_diguy diguySensorRegion
44 {
45 
46 /*****************************************************************************/
56 public:
57 
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 object
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 is checks whether the passed x, y, z position
97  ** is in the sensor region.
98  **
99  *b Arguments:
100  **
101  *a tx, ty, tz - point to check
102  **
103  *b Returns:
104  **
105  ** 1 if the passed point is in the sensor region;
106  ** 0 otherwise.
107  */
108  int contains_point(float tx, float ty, float tz);
109 
110  /*l
111  *b Description:
112  **
113  ** This function checks to see whether the passed character is
114  ** within this sensor region. The actual point that is checked
115  ** is the point returned by diguyCharacter::get_position().
116  **
117  ** Note that this point is typically by the character's feet, so
118  ** it is possible for the upper half of a character to pass
119  ** through a sensor region without this function detecting this.
120  **
121  ** To check the upper portion of a character, use
122  ** contains_character_link() instead, and specify "cervical"
123  ** or "back" as the link.
124  **
125  *b Arguments:
126  **
127  *a character - character to check
128  **
129  *b Returns:
130  **
131  ** 1 if the passed character is in the sensor region;
132  ** 0 otherwise.
133  **
134  *b Callable From:
135  **
136  *- - C++
137  *- - Script
138  *- - Decision Bead
139  */
140  int contains_character(const char* character_name);
141 
142  /*l
143  *b Description:
144  **
145  ** This function checks to see whether a character with the specified
146  ** type is within this sensor region. The actual point that is
147  ** checked is the point returned by diguyCharacter::get_position().
148  **
149  ** Note that this point is typically by the character's feet, so it
150  ** is possible for the upper half of a character to pass through a
151  ** sensor region without this function detecting this.
152  **
153  *b Arguments:
154  **
155  *a character_type - character type to check
156  **
157  *b Returns:
158  **
159  ** 1 if a character with the passed type is in the sensor region;
160  ** 0 otherwise.
161  **
162  *b Callable From:
163  **
164  *- - C++
165  *- - Script
166  *- - Decision Bead
167  */
168  int contains_character_by_type(const char* character_type);
169 
170  /*l
171  *b Description:
172  **
173  ** This function checks to see whether a character with the specified
174  ** type and appearance is within this sensor region. The actual point
175  ** that is checked is the point returned by
176  ** diguyCharacter::get_position().
177  **
178  ** Note that this point is typically by the character's feet, so
179  ** it is possible for the upper half of a character to pass
180  ** through a sensor region without this function detecting this.
181  **
182  *b Arguments:
183  **
184  *a character_type - character type to check
185  *a appearance - appearance to check
186  **
187  *b Returns:
188  **
189  ** 1 if a character with the passed type is in the sensor region;
190  ** 0 otherwise.
191  **
192  *b Callable From:
193  **
194  *- - C++
195  *- - Script
196  *- - Decision Bead
197  */
198  int contains_character_by_type_and_appearance(const char* character_type,
199  const char* appearance);
200 
201  /*l
202  *b Description:
203  **
204  ** This function checks to see whether a character from the specified
205  ** group is within this sensor region. The actual point that is
206  ** checked is the point returned by diguyCharacter::get_position().
207  **
208  ** Note that this point is typically by the character's feet, so it
209  ** is possible for the upper half of a character to pass through a
210  ** sensor region without this function detecting this.
211  **
212  *b Arguments:
213  **
214  *a group_name - group of characters to check
215  **
216  *b Returns:
217  **
218  ** 1 if a character from the group is in the sensor region;
219  ** 0 otherwise.
220  **
221  *b Callable From:
222  **
223  *- - C++
224  *- - Script
225  *- - Decision Bead
226  */
227  int contains_character_from_group(const char* group_name);
228 
229  /*l
230  *b Description:
231  **
232  ** This function is similar to contains_character(), but
233  ** rather than checking whether the character's ideal position
234  ** is in the sensor region, this function checks whether the
235  ** specified link is in the sensor region.
236  **
237  *b Arguments:
238  **
239  *a character_name - name of the character
240  *a link_name - name of the link
241  *a offset_tx, offset_ty, offset_tz - offset in link
242  **
243  *b Returns:
244  **
245  ** 1 if the passed character link is in the sensor region;
246  ** 0 otherwise.
247  */
248  int contains_character_link(const char* character_name,
249  const char* link_name,
250  float offset_tx, float offset_ty, float offset_tz);
251 
252  /*l
253  *b Description:
254  **
255  ** This function checks all characters in the scenario for whether
256  ** they are in this sensor region. Each character that is in the
257  ** sensor region is put into the passed character group. Note that
258  ** the group is first cleared of all members.
259  **
260  ** A subset of characters can be checked by calling
261  ** add_candidate_characters_in_region_to_group().
262  **
263  *b Arguments:
264  **
265  *a group - group to which characters in sensor region should
266  *a be added
267  **
268  *b Returns:
269  **
270  ** 0 on success, -1 on failure
271  */
272  int add_characters_in_region_to_group(diguyCharacterGroup* group);
273 
274  /*l
275  *b Description:
276  **
277  ** This function checks all characters in the candidates_group
278  ** for whether they are in this sensor region. Each character that
279  ** is in the sensor region is put into the passed character group.
280  ** Note that the group is first cleared of all members.
281  **
282  *b Arguments:
283  **
284  *a candidates_group - group whose members should be checked
285  *a group - group to which characters in sensor region
286  *a should be added
287  **
288  *b Returns:
289  **
290  ** 0 on success, -1 on failure
291  */
292  int add_candidate_characters_in_region_to_group(diguyCharacterGroup* candidates_group,
293  diguyCharacterGroup* group);
294 
295 
296 /*****************************************************************************/
329  /*l
330  *b Description:
331  **
332  ** This function sets the group that will be used as
333  ** autosense candidates.
334  **
335  ** The passed group must be created by the DI-Guy Scenario UI
336  ** or via a call to diguyScenario::create_group().
337  **
338  ** The members of the candidates group should be set using
339  ** the DI-Guy Scenario UI or via calls to
340  ** diguyCharacterGroup::add_member().
341  **
342  *b Arguments:
343  **
344  *a autosense_candidates_group - group of characters to
345  *a use as candidates
346  **
347  *b Returns:
348  **
349  ** 0 on success, -1 on failure
350  */
351  int set_autosense_candidates_group(diguyCharacterGroup* autosense_candidates_group);
352 
353  /*l
354  *b Returns:
355  **
356  ** the most recent setting of set_autosense_candidates_group()
357  */
358  diguyCharacterGroup* get_autosense_candidates_group();
359 
360  /*l
361  *b Description:
362  **
363  ** This function sets the group that will be used to hold
364  ** autosense candidate characters that are in this sensor
365  ** region.
366  **
367  ** The passed group must be created by the DI-Guy Scenario UI
368  ** or via a call to diguyScenario::create_group().
369  **
370  ** The members group is always a subset of the candidates group.
371  ** Characters should not be manually added or removed from the
372  ** members group.
373  **
374  *b Arguments:
375  **
376  *a autosense_members_group - group that holds which candidate
377  *a characters are in this sensor region
378  **
379  *b Returns:
380  **
381  ** 0 on success, -1 on failure
382  */
383  int set_autosense_members_group(diguyCharacterGroup* autosense_members_group);
384 
385  /*l
386  *b Returns:
387  **
388  ** the most recent setting of set_autosense_members_group()
389  */
390  diguyCharacterGroup* get_autosense_members_group();
391 
392  /*l
393  *b Description:
394  **
395  ** This function returns the character of the autosense
396  ** candidates group that has entered the sensor
397  ** region, triggering a CALLBACK_ID_AUTOSENSE_CHARACTER_ENTERED
398  ** callback. This function will return NULL when not in the
399  ** above callback.
400  **
401  *b Returns:
402  **
403  ** autosense candidate that has entered this region; NULL if
404  ** not in a CALLBACK_ID_AUTOSENSE_CHARACTER_ENTERED callback
405  */
406  diguyCharacter* get_autosense_callback_candidate_entered();
407 
408  /*l
409  *b Description:
410  **
411  ** This function returns the character of the autosense
412  ** candidates group that has left the sensor
413  ** region, triggering a CALLBACK_ID_AUTOSENSE_CHARACTER_LEFT
414  ** callback. This function will return NULL when not in the
415  ** above callback.
416  **
417  *b Returns:
418  **
419  ** autosense candidate that has left this region; NULL if
420  ** not in a CALLBACK_ID_AUTOSENSE_CHARACTER_LEFT callback
421  */
422  diguyCharacter* get_autosense_callback_candidate_left();
423 
424  int get_min(float *x, float *y, float *z);
425  int set_min(float x, float y, float z, int validate = 1);
426 
427  int get_max(float *x, float *y, float *z);
428  int set_max(float x, float y, float z, int validate = 1);
429 
430 /*****************************************************************************/
435  /*l
436  *b Description:
437  **
438  ** This is an enumeration of the different callbacks
439  ** that can be registered with add_callback() and
440  ** add_callback_script().
441  **
442  *b Usable From:
443  **
444  *- - C++
445  *- - Script
446  */
447  enum {
448  CALLBACK_ID_CREATE = 1,
449  CALLBACK_ID_DESTROY,
450  CALLBACK_ID_DETONATION,
451  CALLBACK_ID_AUTOSENSE_CHARACTER_ENTERED,
452  CALLBACK_ID_AUTOSENSE_CHARACTER_LEFT
453  };
454 
455 
456 #ifdef CPLUSPLUS_ONLY
457 
458  /*l
459  *b Description:
460  **
461  ** This function adds a user callback. Callbacks can be removed
462  ** with remove_callback() or remove_callback_with_user_data().
463  **
464  *b Arguments:
465  **
466  *a callback - pointer to function with prototype
467  *a diguySensorRegionCallback (typedefed above)
468  *a callback_id - integer id of when this callback is to be called
469  *a callback_params - not currently used; pass NULL
470  *a callback_user_data - pointer for user's own use; DI-Guy will
471  *a do nothing to the contents of this pointer
472  *a beyond passing it back when the callback is
473  *a invoked
474  **
475  ** callback_id should be one of the following values:
476  **
477  *i CALLBACK_ID_CREATE
478  **
479  ** This callback will be called when a new sensor region is created.
480  **
481  ** Note that this callback can only be added by calling
482  ** diguyScenario::add_default_sensor_region_callback(); adding it
483  ** with diguySensorRegion::add_callback() will have no effect, as
484  ** by that time the sensor region has already been created.
485  **
486  *i CALLBACK_ID_DESTROY
487  **
488  ** This callback will be called when a sensor region is
489  ** destroyed.
490  **
491  *i CALLBACK_ID_DETONATION
492  **
493  ** This callback will be called when a detonation occurs within
494  ** the sensor region.
495  **
496  *i CALLBACK_ID_AUTOSENSE_CHARACTER_ENTERED
497  **
498  ** This callback will be called when an autosense candidate
499  ** character first enters the sensor region.
500  **
501  *i CALLBACK_ID_AUTOSENSE_CHARACTER_LEFT
502  **
503  ** This callback will be called when an autosense candidate
504  ** character first leaves the sensor region.
505  **
506  ** Callbacks return a value of type diguyCallbackReturn,
507  ** which will be DIGUY_CALLBACK_STOP or DIGUY_CALLBACK_CONTINUE.
508  ** If the callback returns DIGUY_CALLBACK_STOP, the default handler
509  ** of the function will not be called; the callback is asserting
510  ** that it has done everything necessary for the function call.
511  ** If the callback returns DIGUY_CALLBACK_CONTINUE, the default
512  ** handler for the function will be called after the callback.
513  **
514  *b Returns:
515  **
516  ** 0 on success, -1 on failure
517  **
518  *b Callable From:
519  **
520  *- - C++
521  */
522  int add_callback(int callback_id,
523  diguySensorRegionCallback* callback,
524  void* callback_params = 0,
525  void* callback_user_data = 0);
526 
527  /*l
528  *b Description:
529  **
530  ** This function removes a user callback. All callbacks matching
531  ** the specified callback_id and callback function will be removed.
532  **
533  *b Arguments:
534  **
535  *a callback_id - integer id of when this callback is to be called
536  *a callback - pointer to function with prototype
537  *a diguySensorRegionCallback (typedefed above)
538  **
539  *b Returns:
540  **
541  ** 0 on success, -1 on failure
542  **
543  *b Callable From:
544  **
545  *- - C++
546  */
547  int remove_callback(int callback_id,
548  diguySensorRegionCallback* callback);
549 
550  /*l
551  *b Description:
552  **
553  ** This function removes a user callback. All callbacks matching
554  ** the specified callback_id and callback_user_data pointer will
555  ** be removed.
556  **
557  *b Arguments:
558  **
559  *a callback_id - integer id of when this callback is to be called
560  *a callback_user_data - pointer for user's own use
561  **
562  *b Returns:
563  **
564  ** 0 on success, -1 on failure
565  */
566  int remove_callback_with_user_data(int callback_id,
567  void* callback_user_data);
568 
569 #endif
570 
571  /*l
572  *b Description:
573  **
574  ** This function adds a user callback script. Callback scripts can
575  ** be removed with remove_callback_script().
576  **
577  ** See diguyCharacter::add_callback_script() for an example
578  ** of use.
579  **
580  *b Arguments:
581  **
582  *a callback_id - integer id of the callback
583  *a callback_script - script text of callback to be added
584  *a callback_script_type - the type of script contained in
585  *a callback_script
586  **
587  ** If NULL is passed for callback_script_type, a default script type
588  ** will be derived based on the default script interpreter of the
589  ** scenario.
590  **
591  *i lua specific:
592  **
593  ** When the script is called, the object for which it is being called
594  ** will be in the callback_object global.
595  **
596  ** To pass NULL when calling from a lua script, use nil.
597  **
598  *b Returns:
599  **
600  ** 0 on success, -1 on failure
601  **
602  *b Callable From:
603  **
604  *- - C++
605  *- - Script
606  */
607  int add_callback_script(int callback_id,
608  const char* callback_script,
609  const char* callback_script_type = NULL);
610 
611  /*l
612  *b Description:
613  **
614  ** This function removes a user callback script previously added with
615  ** add_callback_script().
616  **
617  ** See diguyCharacter::remove_callback_script() for an example
618  ** of use.
619  **
620  *b Arguments:
621  **
622  *a callback_id - integer id of the callback
623  *a callback_script - script text of callback previously added
624  *a callback_script_type - the type of script contained in
625  *a callback_script
626  **
627  ** If NULL is passed for callback_script, all callback
628  ** scripts whose ids match callback_id and whose types match
629  ** callback_script_type will be removed.
630  **
631  ** If NULL is passed for callback_script_type, a default script type
632  ** will be derived based on the default script interpreter of the
633  ** scenario.
634  **
635  *i Lua specific:
636  **
637  ** To pass NULL when calling from a lua script, use nil.
638  **
639  *b Returns:
640  **
641  ** 0 on success, -1 on failure
642  **
643  *b Callable From:
644  **
645  *- - C++
646  *- - Script
647  */
648  int remove_callback_script(int callback_id,
649  const char* callback_script,
650  const char* callback_script_type = NULL);
651 
652 
653 /*****************************************************************************/
663  /*l
664  *b Description:
665  **
666  ** This function maps the event handler with the given name
667  ** to a callback id. This mapping will be saved in the .dss
668  ** file and restored when the .dss file is loaded.
669  **
670  ** Mappings can also be made via the DI-Guy Scenario UI.
671  **
672  ** The event handler is one of the following:
673  **
674  *- - a scene object callback function registered by
675  *- diguyScenario::register_sensor_region_event_handler() or
676  *- diguyScenario::register_sensor_region_event_handler_from_library()
677  *- - a script registered by
678  *- diguyScenario::register_sensor_region_event_handler_script()
679  *- - a Script, Decision, or Library Function in the scenario
680  *- whose "Event Type" is "Sensor Region"
681  **
682  *b Arguments:
683  **
684  *a callback_id - integer id of callback
685  *a handler_name - name of the event handler to map
686  **
687  *b Returns:
688  **
689  ** 0 on success, -1 on failure
690  */
691  int map_event_handler_to_callback_id(int callback_id,
692  const char* handler_name);
693 
694  /*l
695  *b Description:
696  **
697  ** This function unmaps the event handler with the given name
698  ** from a callback id.
699  **
700  *b Arguments:
701  **
702  *a callback_id - integer id of callback
703  *a handler_name - name of the event handler to map
704  *a unmap_all_matches - pass 0 to unmap only the first match,
705  *a pass 1 to unmap all matches
706  **
707  *b Returns:
708  **
709  ** 0 on success, -1 on failure
710  */
711  int unmap_event_handler_from_callback_id(int callback_id,
712  const char* handler_name,
713  int unmap_all_matches = 0);
714 
715 
720 #ifdef CPLUSPLUS_ONLY
721 
722 private:
723 
724  /*l
725  ** A private constructor.
726  */
727  diguySensorRegion(bdiScenarioSensorRegion* sensor_region);
728 
729  /*l
730  ** A pointer to internal data.
731  */
732  bdiScenarioSensorRegion* m_sensor_region;
733 
734  friend class bdiScenarioSensorRegion;
735 
736 #endif
737 
738 };
739 
740 #endif /* __diguySensorRegion_H */
diguyCallbackReturn diguySensorRegionCallback(diguySensorRegion *sensor_region, int callback_id, void *callback_params, void *callback_user_data)
Definition: diguy_typedefs.h:187
A group of DI-Guy characters, useful for organizing your scenarios.
Definition: diguyCharacterGroup.h:38
The class that represents a DI-Guy Entity in the world.
Definition: diguyCharacter.h:82
Definition: diguySensorRegion.h:41