sfx3DWorld.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. SFX3DObject();
  43. ///
  44. SFX3DObject( SFX3DWorld* world, SceneObject* object );
  45. /// Return the transform for the ears on this object.
  46. void getEarTransform( MatrixF& transform ) const;
  47. // SFXObject.
  48. void getReferenceCenter( F32 position[ 3 ] ) const;
  49. void getBounds( F32 minBounds[ 3 ], F32 maxBounds[ 3 ] ) const;
  50. void getRealBounds( F32 minBounds[ 3 ], F32 maxBounds[ 3 ] ) const;
  51. SFXAmbience* getAmbience() const;
  52. bool containsPoint( const F32 point[ 3 ] ) const;
  53. String describeSelf() const;
  54. };
  55. /// Manager for the 3D sound world.
  56. ///
  57. /// Any SceneObject in the world can be made the current listener. It's ear position (if it's a ShapeBase)
  58. /// will then be used as the reference center for attenuating 3D sounds, traversing ambient spaces, etc.
  59. ///
  60. class SFX3DWorld : public SceneTracker
  61. {
  62. public:
  63. typedef SceneTracker Parent;
  64. typedef SFXWorld< 3, SFX3DObject* > SFXWorldType;
  65. enum
  66. {
  67. /// The scene object type mask used to filter out the
  68. /// type of objects we are interested in.
  69. TYPEMASK = WaterObjectType // Sound ambience.
  70. | StaticShapeObjectType // Occlusion and sound ambience.
  71. | StaticObjectType // Portals and zones.
  72. };
  73. protected:
  74. /// The SFX world tracking system.
  75. SFXWorldType mSFXWorld;
  76. /// Allocator for the SFX3DObject SceneObjectLinks we attach to SceneObjects.
  77. FreeListChunker< SFX3DObject > mChunker;
  78. // SceneTracker.
  79. bool _isTrackableObject( SceneObject* object ) const override;
  80. public:
  81. ///
  82. SFX3DWorld();
  83. ///
  84. void update();
  85. /// Return the current listener object.
  86. SceneObject* getListener() const;
  87. /// Make the given object the current listener object.
  88. void setListener( SceneObject* object );
  89. /// Notify the SFX world that the given object had a (potential) change in its
  90. /// sound-related properties.
  91. void notifyChanged( SceneObject* object );
  92. ///
  93. void debugDump();
  94. // SceneTracker.
  95. void registerObject( SceneObject* object ) override;
  96. void unregisterObject( SceneObject* object ) override;
  97. void updateObject( SceneObjectLink* object ) override;
  98. };
  99. /// The singleton instance of SFX3DWorld, if there is one.
  100. extern SFX3DWorld* gSFX3DWorld;
  101. #endif // !_SFX3DWORLD_H_