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