From: <ko...@us...> - 2009-07-19 19:26:50
|
Revision: 4079 http://planeshift.svn.sourceforge.net/planeshift/?rev=4079&view=rev Author: kougaro Date: 2009-07-19 19:26:42 +0000 (Sun, 19 Jul 2009) Log Message: ----------- Clean up the code for attaching and detaching the rider to his mount, client-side Modified Paths: -------------- trunk/src/client/charapp.cpp trunk/src/client/charapp.h Modified: trunk/src/client/charapp.cpp =================================================================== --- trunk/src/client/charapp.cpp 2009-07-19 19:15:08 UTC (rev 4078) +++ trunk/src/client/charapp.cpp 2009-07-19 19:26:42 UTC (rev 4079) @@ -275,41 +275,18 @@ return; } - csString keyName = "socket_back"; - - // Variables for transform to be specified - float trans_x = 0, trans_y = 0, trans_z = 0, rot_x = -PI/2, rot_y = 0, rot_z = 0; - - meshWrap->QuerySceneNode()->SetParent( baseMesh->QuerySceneNode ()); - socket->SetMeshWrapper( meshWrap ); - - socket->SetTransform( csTransform(csZRotMatrix3(rot_z)*csYRotMatrix3(rot_y)*csXRotMatrix3(rot_x), csVector3(trans_x,trans_y,trans_z)) ); - - usedSlots.PushSmart("back"); - + ProcessAttach(meshWrap, socket); } void psCharAppearance::RemoveRider(GEMClientActor* rider) { - csRef<iSpriteCal3DSocket> socket = state->FindSocket("back"); - if ( !socket ) - { - Error1("\"back\" socket not found."); - return; - } - - csRef<iMeshWrapper> meshWrap = rider->pcmesh; - csVector3 rpos = rider->GetPosition(); float rrot = rider->GetRotation(); + + Detach("back", false); - meshWrap->QuerySceneNode()->SetParent(0); - meshWrap->GetMovable()->SetSector(baseMesh->GetMovable()->GetSectors()->Get(0)); - + rider->pcmesh->GetMovable()->SetSector(baseMesh->GetMovable()->GetSectors()->Get(0)); rider->SetPosition(rpos, rrot, rider->GetSector()); - - socket->SetMeshWrapper(NULL); - usedSlots.Delete("back"); } void psCharAppearance::ApplyEquipment(csString& equipment) @@ -612,16 +589,24 @@ void psCharAppearance::ProcessAttach(csRef<iMeshFactoryWrapper> factory, const char* meshFactName, csRef<iSpriteCal3DSocket> socket) { csRef<iMeshWrapper> meshWrap = engine->CreateMeshWrapper( factory, meshFactName ); - meshWrap->GetFlags().Set(CS_ENTITY_NODECAL); - const char* socketName = socket->GetName(); + ProcessAttach(meshWrap, socket); + + psengine->GetCelClient()->HandleItemEffect(factory->QueryObject()->GetName(), socket->GetMeshWrapper(), false, socket->GetName(), &effectids, &lightids); +} + +void psCharAppearance::ProcessAttach(csRef<iMeshWrapper> meshWrap, csRef<iSpriteCal3DSocket> socket) +{ + meshWrap->GetFlags().Set(CS_ENTITY_NODECAL); + const char* socketName = socket->GetName(); + // Given a socket name of "righthand", we're looking for a key in the form of "socket_righthand" csString keyName = "socket_"; keyName += socketName; // Variables for transform to be specified float trans_x = 0, trans_y = 0.0, trans_z = 0, rot_x = -PI/2, rot_y = 0, rot_z = 0; - csRef<iObjectIterator> it = factory->QueryObject()->GetIterator(); + csRef<iObjectIterator> it = meshWrap->GetFactory()->QueryObject()->GetIterator(); while ( it->HasNext() ) { @@ -637,8 +622,6 @@ socket->SetTransform( csTransform(csZRotMatrix3(rot_z)*csYRotMatrix3(rot_y)*csXRotMatrix3(rot_x), csVector3(trans_x,trans_y,trans_z)) ); usedSlots.PushSmart(socketName); - - psengine->GetCelClient()->HandleItemEffect(factory->QueryObject()->GetName(), socket->GetMeshWrapper(), false, socketName, &effectids, &lightids); } void psCharAppearance::ProcessAttach(csRef<iMaterialWrapper> material, const char* materialName, const char* partName) @@ -875,7 +858,7 @@ } -bool psCharAppearance::Detach(const char* socketName ) +bool psCharAppearance::Detach(const char* socketName, bool removeItem ) { if (!socketName) { @@ -899,7 +882,8 @@ { meshWrap->QuerySceneNode()->SetParent (0); socket->SetMeshWrapper( NULL ); - engine->RemoveObject( meshWrap ); + if(removeItem) + engine->RemoveObject( meshWrap ); } usedSlots.Delete(socketName); Modified: trunk/src/client/charapp.h =================================================================== --- trunk/src/client/charapp.h 2009-07-19 19:15:08 UTC (rev 4078) +++ trunk/src/client/charapp.h 2009-07-19 19:26:42 UTC (rev 4079) @@ -194,7 +194,7 @@ * * @return True if the item was successfully removed from the socket. */ - bool Detach(const char* socketName); + bool Detach(const char* socketName, bool removeItem = true); /** Set the default material back onto a particular part of the model. * @param part The part we want to set the default material back on. @@ -209,6 +209,7 @@ void DefaultMesh(const char* part); void ProcessAttach(csRef<iMeshFactoryWrapper> factory, const char* meshFactName, csRef<iSpriteCal3DSocket> socket); + void ProcessAttach(csRef<iMeshWrapper> meshWrap, csRef<iSpriteCal3DSocket> socket); void ProcessAttach(csRef<iMaterialWrapper> material, const char* materialName, const char* partName); csRef<iMeshWrapper> baseMesh; // The mesh that is our base model. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |