VActorData.cpp
Engine/source/Verve/VActor/VActorData.cpp
Public Functions
Detailed Description
Public Functions
IMPLEMENT_CO_DATABLOCK_V1(VActorData )
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 "VActorData.h" 25 26#include "console/consoleTypes.h" 27#include "core/stream/bitStream.h" 28 29//----------------------------------------------------------------------------- 30IMPLEMENT_CO_DATABLOCK_V1( VActorData ); 31//----------------------------------------------------------------------------- 32 33VActorData::VActorData( void ) : 34 mMaxStepHeight( 1.f ), 35 mRunSpeed( 6.f ), 36 mSubmergeCoverage( 0.25f ) 37{ 38 // Setup Shadowing. 39 shadowEnable = true; 40 shadowSize = 256; 41 shadowProjectionDistance = 14.0f; 42 43 VECTOR_SET_ASSOCIATION( mAnimationSequenceList ); 44 VECTOR_SET_ASSOCIATION( mPhysicsList ); 45} 46 47VActorData::~VActorData( void ) 48{ 49 // Void. 50} 51 52void VActorData::initPersistFields( void ) 53{ 54 Parent::initPersistFields(); 55 56 addField( "MaxStepHeight", TypeF32, Offset( mMaxStepHeight, VActorData ) ); 57 addField( "RunSpeed", TypeF32, Offset( mRunSpeed, VActorData ) ); 58 59 addField( "SubmergeCoverage", TypeF32, Offset( mSubmergeCoverage, VActorData ) ); 60} 61 62//----------------------------------------------------------------------------- 63 64bool VActorData::initAnimationSequenceList( const S32 &pSize, const sAnimationSequence *pTable ) 65{ 66 if ( !mShape ) 67 { 68 // Sanity! 69 return false; 70 } 71 72 // Clear the List. 73 mAnimationSequenceList.clear(); 74 75 // Initialise each Animation Sequence. 76 for ( U32 i = 0; i < pSize; i++ ) 77 { 78 // Fetch Sequence Definition. 79 const sAnimationSequence &animSequenceDef = pTable[i]; 80 81 // Update Animation Details. 82 sAnimationSequence animSequence = animSequenceDef; 83 // Find Sequence. 84 animSequence.Sequence = mShape->findSequence( animSequenceDef.Name ); 85 86 // Store. 87 mAnimationSequenceList.push_back( animSequence ); 88 } 89 90 return true; 91} 92 93bool VActorData::initAnimationTransitionList( const S32 &pSize, const sAnimationTransition *pTable ) 94{ 95 if ( !mShape ) 96 { 97 // Sanity! 98 return false; 99 } 100 101 // Clear the List. 102 mAnimationTransitionList.clear(); 103 104 // Store each Animation Transition. 105 for ( U32 i = 0; i < pSize; i++ ) 106 { 107 // Store. 108 mAnimationTransitionList.push_back( pTable[i] ); 109 } 110 111 return true; 112} 113 114bool VActorData::initPhysicsStateList( const S32 &pSize, const sPhysicsState *pTable ) 115{ 116 // Clear the List. 117 mPhysicsList.clear(); 118 119 // Initialise each Animation Sequence. 120 for ( U32 i = 0; i < pSize; i++ ) 121 { 122 // Store. 123 mPhysicsList.push_back( pTable[i] ); 124 } 125 126 return true; 127} 128 129//----------------------------------------------------------------------------- 130 131void VActorData::packData( BitStream *pStream ) 132{ 133 Parent::packData( pStream ); 134 135 pStream->write( mMaxStepHeight ); 136 pStream->write( mRunSpeed ); 137 138 pStream->write( mSubmergeCoverage ); 139} 140 141void VActorData::unpackData( BitStream *pStream ) 142{ 143 Parent::unpackData( pStream ); 144 145 pStream->read( &mMaxStepHeight ); 146 pStream->read( &mRunSpeed ); 147 148 pStream->read( &mSubmergeCoverage ); 149} 150 151//----------------------------------------------------------------------------- 152 153S32 VActorData::getAnimationSequence( const U32 &pIndex ) 154{ 155 // Iterate over the Registered Animations. 156 for ( tAnimationSequenceVector::iterator itr = mAnimationSequenceList.begin(); itr != mAnimationSequenceList.end(); itr++ ) 157 { 158 // Fetch Sequence Defintion. 159 const sAnimationSequence &animSequence = ( *itr ); 160 161 // Target Index? 162 if ( animSequence.Index == pIndex ) 163 { 164 // Return Sequence ID. 165 return animSequence.Sequence; 166 } 167 } 168 169 // Invalid Sequence. 170 return -1; 171}; 172