coverPoint.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /// Amount of cover provided at this point.
  51. enum Size {
  52. Prone,
  53. Crouch,
  54. Stand,
  55. NumSizes
  56. };
  57. void setSize(Size size) { mSize = size; setMaskBits(TransformMask); }
  58. Size getSize() const { return mSize; }
  59. /// Is this point occupied?
  60. bool isOccupied() const { return mOccupied; }
  61. void setOccupied(bool occ) { mOccupied = occ; setMaskBits(TransformMask); }
  62. /// Get the normal of this point (i.e., the direction from which it provides cover).
  63. Point3F getNormal() const;
  64. F32 getQuality() const { return mQuality; }
  65. bool peekLeft() const { return mPeekLeft; }
  66. bool peekRight() const { return mPeekRight; }
  67. bool peekOver() const { return mPeekOver; }
  68. void setPeek(bool left, bool right, bool over) { mPeekLeft = left, mPeekRight = right, mPeekOver = over; }
  69. /// Init static buffers for rendering.
  70. static void initGFXResources();
  71. /// @name SceneObject
  72. /// @{
  73. static void initPersistFields();
  74. bool onAdd();
  75. void onRemove();
  76. void onEditorEnable();
  77. void onEditorDisable();
  78. void inspectPostApply();
  79. void setTransform(const MatrixF &mat);
  80. void prepRenderImage(SceneRenderState *state);
  81. void render(ObjectRenderInst *ri, SceneRenderState *state, BaseMatInstance *overrideMat);
  82. /// @}
  83. /// @name NetObject
  84. /// @{
  85. U32 packUpdate(NetConnection *conn, U32 mask, BitStream *stream);
  86. void unpackUpdate(NetConnection *conn, BitStream *stream);
  87. /// @}
  88. protected:
  89. private:
  90. typedef GFXVertexPCN VertexType;
  91. static GFXStateBlockRef smNormalSB;
  92. static GFXVertexBufferHandle<VertexType> smVertexBuffer[NumSizes];
  93. /// Size of this point.
  94. Size mSize;
  95. /// Quality of this point as cover.
  96. F32 mQuality;
  97. /// Can we look left around this cover?
  98. bool mPeekLeft;
  99. /// Can we look right around this cover?
  100. bool mPeekRight;
  101. /// Can we look up over this cover?
  102. bool mPeekOver;
  103. /// Is this point currently occupied?
  104. bool mOccupied;
  105. };
  106. typedef CoverPoint::Size CoverPointSize;
  107. DefineEnumType(CoverPointSize);
  108. #endif