sfx3DWorld.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. #ifndef _SFX3DWORLD_H_
  23. #define _SFX3DWORLD_H_
  24. #ifndef _SCENETRACKER_H_
  25. #include "scene/sceneTracker.h"
  26. #endif
  27. #ifndef _SFXWORLD_H_
  28. #include "sfx/sfxWorld.h"
  29. #endif
  30. #ifndef _DATACHUNKER_H_
  31. #include "core/dataChunker.h"
  32. #endif
  33. #ifndef _OBJECTTYPES_H_
  34. #include "T3D/objectTypes.h"
  35. #endif
  36. class SFX3DWorld;
  37. /// SFXObject implementation for the 3D system.
  38. class SFX3DObject : public SceneObjectLink, public SFXObject< 3 >
  39. {
  40. public:
  41. typedef SceneObjectLink Parent;
  42. ///
  43. SFX3DObject( SFX3DWorld* world, SceneObject* object );
  44. /// Return the transform for the ears on this object.
  45. void getEarTransform( MatrixF& transform ) const;
  46. // SFXObject.
  47. void getReferenceCenter( F32 position[ 3 ] ) const;
  48. void getBounds( F32 minBounds[ 3 ], F32 maxBounds[ 3 ] ) const;
  49. void getRealBounds( F32 minBounds[ 3 ], F32 maxBounds[ 3 ] ) const;
  50. SFXAmbience* getAmbience() const;
  51. bool containsPoint( const F32 point[ 3 ] ) const;
  52. String describeSelf() const;
  53. };
  54. /// Manager for the 3D sound world.
  55. ///
  56. /// Any SceneObject in the world can be made the current listener. It's ear position (if it's a ShapeBase)
  57. /// will then be used as the reference center for attenuating 3D sounds, traversing ambient spaces, etc.
  58. ///
  59. class SFX3DWorld : public SceneTracker
  60. {
  61. public:
  62. typedef SceneTracker Parent;
  63. typedef SFXWorld< 3, SFX3DObject* > SFXWorldType;
  64. enum
  65. {
  66. /// The scene object type mask used to filter out the
  67. /// type of objects we are interested in.
  68. TYPEMASK = WaterObjectType // Sound ambience.
  69. | StaticShapeObjectType // Occlusion and sound ambience.
  70. | StaticObjectType // Portals and zones.
  71. };
  72. protected:
  73. /// The SFX world tracking system.
  74. SFXWorldType mSFXWorld;
  75. /// Allocator for the SFX3DObject SceneObjectLinks we attach to SceneObjects.
  76. FreeListChunker< SFX3DObject > mChunker;
  77. // SceneTracker.
  78. virtual bool _isTrackableObject( SceneObject* object ) const;
  79. public:
  80. ///
  81. SFX3DWorld();
  82. ///
  83. void update();
  84. /// Return the current listener object.
  85. SceneObject* getListener() const;
  86. /// Make the given object the current listener object.
  87. void setListener( SceneObject* object );
  88. /// Notify the SFX world that the given object had a (potential) change in its
  89. /// sound-related properties.
  90. void notifyChanged( SceneObject* object );
  91. ///
  92. void debugDump();
  93. // SceneTracker.
  94. virtual void registerObject( SceneObject* object );
  95. virtual void unregisterObject( SceneObject* object );
  96. virtual void updateObject( SceneObjectLink* object );
  97. };
  98. /// The singleton instance of SFX3DWorld, if there is one.
  99. extern SFX3DWorld* gSFX3DWorld;
  100. #endif // !_SFX3DWORLD_H_