razerHydraFrameStore.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. //
  2. // Permission is hereby granted, free of charge, to any person obtaining a copy
  3. // of this software and associated documentation files (the "Software"), to
  4. // deal in the Software without restriction, including without limitation the
  5. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  6. // sell copies of the Software, and to permit persons to whom the Software is
  7. // furnished to do so, subject to the following conditions:
  8. //
  9. // The above copyright notice and this permission notice shall be included in
  10. // all copies or substantial portions of the Software.
  11. //
  12. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  17. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  18. // IN THE SOFTWARE.
  19. //-----------------------------------------------------------------------------
  20. #include "platform/input/razerHydra/razerHydraFrameStore.h"
  21. #include "platform/input/razerHydra/razerHydraFrame.h"
  22. #include "core/module.h"
  23. #include "console/simSet.h"
  24. #include "console/consoleTypes.h"
  25. MODULE_BEGIN( RazerHydraFrameStore )
  26. MODULE_INIT_AFTER( RazerHydraDevice )
  27. MODULE_INIT_AFTER( Sim )
  28. MODULE_SHUTDOWN_BEFORE( Sim )
  29. MODULE_SHUTDOWN_BEFORE( RazerHydraDevice )
  30. MODULE_INIT
  31. {
  32. RazerHydraFrameStore::staticInit();
  33. ManagedSingleton< RazerHydraFrameStore >::createSingleton();
  34. }
  35. MODULE_SHUTDOWN
  36. {
  37. ManagedSingleton< RazerHydraFrameStore >::deleteSingleton();
  38. }
  39. MODULE_END;
  40. S32 RazerHydraFrameStore::smMaximumFramesStored = 30;
  41. SimGroup* RazerHydraFrameStore::smFrameGroup = NULL;
  42. RazerHydraFrameStore::RazerHydraFrameStore()
  43. {
  44. // Set up the SimGroup to store our frames
  45. smFrameGroup = new SimGroup();
  46. smFrameGroup->registerObject("RazerHydraFrameGroup");
  47. smFrameGroup->setNameChangeAllowed(false);
  48. Sim::getRootGroup()->addObject(smFrameGroup);
  49. }
  50. RazerHydraFrameStore::~RazerHydraFrameStore()
  51. {
  52. if(smFrameGroup)
  53. {
  54. smFrameGroup->deleteObject();
  55. smFrameGroup = NULL;
  56. }
  57. }
  58. void RazerHydraFrameStore::staticInit()
  59. {
  60. Con::addVariable("RazerHydra::MaximumFramesStored", TypeS32, &smMaximumFramesStored,
  61. "@brief The maximum number of frames to keep when $RazerHydra::GenerateWholeFrameEvents is true.\n\n"
  62. "@ingroup Game");
  63. }
  64. S32 RazerHydraFrameStore::generateNewFrame(const sixenseAllControllerData& frame, const F32& maxAxisRadius)
  65. {
  66. // Make sure our group has been created
  67. if(!smFrameGroup)
  68. return 0;
  69. // Either create a new frame object or pull one off the end
  70. S32 frameID = 0;
  71. if(smFrameGroup->size() >= smMaximumFramesStored)
  72. {
  73. // Make the last frame the first and update
  74. RazerHydraFrame* frameObj = static_cast<RazerHydraFrame*>(smFrameGroup->last());
  75. smFrameGroup->bringObjectToFront(frameObj);
  76. frameObj->copyFromFrame(frame, maxAxisRadius);
  77. frameID = frameObj->getId();
  78. }
  79. else
  80. {
  81. // Create a new frame and add it to the front of the list
  82. RazerHydraFrame* frameObj = new RazerHydraFrame();
  83. frameObj->registerObject();
  84. smFrameGroup->addObject(frameObj);
  85. smFrameGroup->bringObjectToFront(frameObj);
  86. frameObj->copyFromFrame(frame, maxAxisRadius);
  87. frameID = frameObj->getId();
  88. }
  89. return frameID;
  90. }