coverPoint.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2014 Daniel Buckmaster
  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 _COVERPOINT_H_
  23. #define _COVERPOINT_H_
  24. #ifndef _SCENEOBJECT_H_
  25. #include "scene/sceneObject.h"
  26. #endif
  27. #ifndef _GFXSTATEBLOCK_H_
  28. #include "gfx/gfxStateBlock.h"
  29. #endif
  30. #ifndef _GFXVERTEXBUFFER_H_
  31. #include "gfx/gfxVertexBuffer.h"
  32. #endif
  33. #ifndef _GFXPRIMITIVEBUFFER_H_
  34. #include "gfx/gfxPrimitiveBuffer.h"
  35. #endif
  36. class BaseMatInstance;
  37. class CoverPoint : public SceneObject
  38. {
  39. typedef SceneObject Parent;
  40. /// Network mask bits.
  41. enum MaskBits
  42. {
  43. TransformMask = Parent::NextFreeMask << 0,
  44. NextFreeMask = Parent::NextFreeMask << 1
  45. };
  46. public:
  47. CoverPoint();
  48. virtual ~CoverPoint();
  49. DECLARE_CONOBJECT(CoverPoint);
  50. DECLARE_CATEGORY("Navigation");
  51. /// Amount of cover provided at this point.
  52. enum Size {
  53. Prone,
  54. Crouch,
  55. Stand,
  56. NumSizes
  57. };
  58. void setSize(Size size) { mSize = size; setMaskBits(TransformMask); }
  59. Size getSize() const { return mSize; }
  60. /// Is this point occupied?
  61. bool isOccupied() const { return mOccupied; }
  62. void setOccupied(bool occ) { mOccupied = occ; setMaskBits(TransformMask); }
  63. /// Get the normal of this point (i.e., the direction from which it provides cover).
  64. Point3F getNormal() const;
  65. F32 getQuality() const { return mQuality; }
  66. bool peekLeft() const { return mPeekLeft; }
  67. bool peekRight() const { return mPeekRight; }
  68. bool peekOver() const { return mPeekOver; }
  69. void setPeek(bool left, bool right, bool over) { mPeekLeft = left, mPeekRight = right, mPeekOver = over; }
  70. /// Init static buffers for rendering.
  71. static void initGFXResources();
  72. /// @name SceneObject
  73. /// @{
  74. static void initPersistFields();
  75. bool onAdd() override;
  76. void onRemove() override;
  77. void onEditorEnable() override;
  78. void onEditorDisable() override;
  79. void inspectPostApply() override;
  80. void setTransform(const MatrixF &mat) override;
  81. void prepRenderImage(SceneRenderState *state) override;
  82. void render(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat);
  83. /// @}
  84. /// @name NetObject
  85. /// @{
  86. U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream) override;
  87. void unpackUpdate(NetConnection *conn, BitStream *stream) override;
  88. /// @}
  89. protected:
  90. private:
  91. typedef GFXVertexPCN VertexType;
  92. static GFXStateBlockRef smNormalSB;
  93. static GFXVertexBufferHandle<VertexType> smVertexBuffer[NumSizes];
  94. /// Size of this point.
  95. Size mSize;
  96. /// Quality of this point as cover.
  97. F32 mQuality;
  98. /// Can we look left around this cover?
  99. bool mPeekLeft;
  100. /// Can we look right around this cover?
  101. bool mPeekRight;
  102. /// Can we look up over this cover?
  103. bool mPeekOver;
  104. /// Is this point currently occupied?
  105. bool mOccupied;
  106. };
  107. typedef CoverPoint::Size CoverPointSize;
  108. DefineEnumType(CoverPointSize);
  109. #endif