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