VPostEffect.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. //-----------------------------------------------------------------------------
  2. // Verve
  3. // Copyright (C) 2014 - Violent Tulip
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. #include "Verve/VerveConfig.h"
  24. #include "Verve/Torque3D/VPostEffect.h"
  25. #include "T3D/gameBase/gameConnection.h"
  26. #include "core/stream/bitStream.h"
  27. //-----------------------------------------------------------------------------
  28. //
  29. // Post Effect Methods.
  30. //
  31. //-----------------------------------------------------------------------------
  32. bool VTorque::isPostEffectEnabled( PostEffectType *pPostEffect )
  33. {
  34. if ( !pPostEffect )
  35. {
  36. // Sanity!
  37. return false;
  38. }
  39. return pPostEffect->isEnabled();
  40. }
  41. void VTorque::setPostEffectOn( PostEffectType *pPostEffect, const bool &pStatus )
  42. {
  43. if ( !pPostEffect )
  44. {
  45. // Sanity!
  46. return;
  47. }
  48. #ifdef VT_EDITOR
  49. if ( pStatus )
  50. {
  51. // Enable Effect.
  52. pPostEffect->enable();
  53. }
  54. else
  55. {
  56. // Disable Effect.
  57. pPostEffect->disable();
  58. }
  59. #else
  60. // Fetch Name.
  61. StringTableEntry name = pPostEffect->getName();
  62. if ( !name || name == StringTable->insert( "" ) )
  63. {
  64. Con::warnf( "VTorque::setPostEffectOn() - Invalid Object Name." );
  65. return;
  66. }
  67. // Fetch Client Group.
  68. SimGroup* clientGroup = Sim::getClientGroup();
  69. for ( SimGroup::iterator itr = clientGroup->begin(); itr != clientGroup->end(); itr++ )
  70. {
  71. NetConnection *connection = static_cast<NetConnection*>( *itr );
  72. if ( connection )
  73. {
  74. // Create Event.
  75. VPostEffectNetEvent *event = new VPostEffectNetEvent();
  76. // Setup Event.
  77. event->mPostEffect = name;
  78. event->mEnabled = pStatus;
  79. // Post Event.
  80. connection->postNetEvent( event );
  81. }
  82. }
  83. #endif
  84. }
  85. //-----------------------------------------------------------------------------
  86. IMPLEMENT_CO_CLIENTEVENT_V1( VPostEffectNetEvent );
  87. //-----------------------------------------------------------------------------
  88. VPostEffectNetEvent::VPostEffectNetEvent( void ) : mPostEffect( StringTable->insert( "" ) ),
  89. mEnabled( false )
  90. {
  91. // Void.
  92. }
  93. void VPostEffectNetEvent::write( NetConnection *pConnection, BitStream *pStream )
  94. {
  95. // Void.
  96. }
  97. void VPostEffectNetEvent::pack( NetConnection *pConnection, BitStream *pStream )
  98. {
  99. // Object Name.
  100. pStream->writeString( mPostEffect );
  101. // Status.
  102. pStream->writeFlag( mEnabled );
  103. }
  104. void VPostEffectNetEvent::unpack( NetConnection *pConnection, BitStream *pStream )
  105. {
  106. // Object Name.
  107. mPostEffect = pStream->readSTString();
  108. // Status.
  109. mEnabled = pStream->readFlag();
  110. }
  111. void VPostEffectNetEvent::process( NetConnection *pConnection )
  112. {
  113. PostEffect *postEffect;
  114. if ( !Sim::findObject( mPostEffect, postEffect ) )
  115. {
  116. Con::warnf( "VPostEffectNetEvent::process() - Unable to find PostEffect Object '%s'", mPostEffect );
  117. return;
  118. }
  119. if ( mEnabled )
  120. {
  121. // Enable Effect.
  122. postEffect->enable();
  123. }
  124. else
  125. {
  126. // Disable Effect.
  127. postEffect->disable();
  128. }
  129. }