From: <sv...@ww...> - 2004-07-11 02:22:02
|
Author: mkrose Date: 2004-07-10 19:21:55 -0700 (Sat, 10 Jul 2004) New Revision: 1155 Modified: trunk/CSP/CSPSim/CHANGES.current trunk/CSP/CSPSim/Source/DynamicObject.cpp Log: Small formatting cleanup. Browse at: https://www.zerobar.net/viewcvs/viewcvs.cgi?view=rev&rev=1155 Modified: trunk/CSP/CSPSim/CHANGES.current =================================================================== --- trunk/CSP/CSPSim/CHANGES.current 2004-07-10 05:19:49 UTC (rev 1154) +++ trunk/CSP/CSPSim/CHANGES.current 2004-07-11 02:21:55 UTC (rev 1155) @@ -1,6 +1,9 @@ Version 0.4.0 (in progress) =========================== +2004-07-10: onsight + * Small formatting cleanup in DynamicObject.cpp. + 2004-07-08: onsight * Slight tweak of the logging macros. See the SimData changelog for details. Modified: trunk/CSP/CSPSim/Source/DynamicObject.cpp =================================================================== --- trunk/CSP/CSPSim/Source/DynamicObject.cpp 2004-07-10 05:19:49 UTC (rev 1154) +++ trunk/CSP/CSPSim/Source/DynamicObject.cpp 2004-07-11 02:21:55 UTC (rev 1155) @@ -1,17 +1,17 @@ // Combat Simulator Project - FlightSim Demo // Copyright (C) 2002 The Combat Simulator Project // http://csp.sourceforge.net -// +// // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. -// +// // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. @@ -95,13 +95,11 @@ if (!m_SceneModel) createSceneModel(); return m_SceneModel->getRoot(); } - -osg::Node* DynamicObject::getModelNode() { +osg::Node* DynamicObject::getModelNode() { if (!m_SceneModel) return 0; return m_SceneModel->getRoot(); } - void DynamicObject::setGlobalPosition(simdata::Vector3 const & position) { setGlobalPosition(position.x(), position.y(), position.z()); @@ -111,11 +109,11 @@ { if (isGrounded()) { - // if the object is fixed to the ground, ignore the z component + // if the object is fixed to the ground, ignore the z component // and use the local elevation (not implemented) // FIXME FIXME FIXME XXX XXX float offset = 0.0; - z = offset; + z = offset; } b_GlobalPosition->value() = simdata::Vector3(x, y, z); } @@ -145,7 +143,7 @@ VirtualBattlefield const *battlefield = sim->getBattlefield(); assert(battlefield); simdata::Vector3 &pos = b_GlobalPosition->value(); - pos.z() = battlefield->getGroundElevation(pos.x(), pos.y(), m_GroundHint) + offset; + pos.z() = battlefield->getGroundElevation(pos.x(), pos.y(), m_GroundHint) + offset; } @@ -156,8 +154,6 @@ } } - -// update double DynamicObject::onUpdate(double dt) { // Save the objects old position @@ -171,7 +167,6 @@ return 0.0; } - void DynamicObject::doControl(double dt) { if (m_Controller.valid()) { m_Controller->doControl(dt); @@ -199,9 +194,9 @@ VirtualBattlefield const *battlefield = sim->getBattlefield(); assert(battlefield); b_GroundZ->value() = battlefield->getGroundElevation( - b_GlobalPosition->value().x(), - b_GlobalPosition->value().y(), - b_GroundN->value(), + b_GlobalPosition->value().x(), + b_GlobalPosition->value().y(), + b_GroundN->value(), m_GroundHint ); double height = (b_GlobalPosition->value().z() - b_GroundZ->value()) * b_GroundN->value().z(); @@ -283,7 +278,6 @@ return model; } - void DynamicObject::registerChannels(Bus::Ref bus) { if (!bus) return; bus->registerChannel(b_GlobalPosition.get()); @@ -299,7 +293,6 @@ bus->registerLocalDataChannel< simdata::Ref<ObjectModel> >("Internal.ObjectModel", m_Model); } - Bus::Ref DynamicObject::getBus() { return (m_SystemsModel.valid() ? m_SystemsModel->getBus(): 0); } @@ -366,7 +359,7 @@ if (InputInterface::onMapEvent(event)) { return true; } -if (m_SystemsModel.valid() && m_SystemsModel->onMapEvent(event)) { + if (m_SystemsModel.valid() && m_SystemsModel->onMapEvent(event)) { return true; } return false; @@ -385,77 +378,69 @@ } } +NetworkMessage * DynamicObject::getUpdateMessage() { + CSP_LOG(NETWORK, DEBUG, "DynamicObject::getUpdateMessage()"); + unsigned short messageType = 2; + unsigned short payloadLen = sizeof(int) + sizeof(double) + 3*sizeof(simdata::Vector3) + sizeof(simdata::Quat) /* + sizeof(simdata::Matrix3) + sizeof(double) */; -NetworkMessage * DynamicObject::getUpdateMessage() -{ - CSP_LOG(APP, DEBUG, "DynamicObject::getUpdateMessage()"); - unsigned short messageType = 2; - unsigned short payloadLen = sizeof(int) + sizeof(double) + 3*sizeof(simdata::Vector3) + - sizeof(simdata::Quat) /* + sizeof(simdata::Matrix3) + sizeof(double) */; + NetworkMessage * message = CSPSim::theSim->getNetworkMessenger()->allocMessageBuffer(messageType, payloadLen); - NetworkMessage * message = CSPSim::theSim->getNetworkMessenger()->allocMessageBuffer(messageType, payloadLen); + ObjectUpdateMessagePayload * ptrPayload = (ObjectUpdateMessagePayload*)message->getPayloadPtr(); + ptrPayload->id = m_ID; + ptrPayload->timeStamp = CSPSim::theSim->getElapsedTime(); + b_GlobalPosition->value().writeBinary((unsigned char *)&(ptrPayload->globalPosition),24); + b_LinearVelocity->value().writeBinary((unsigned char *)&(ptrPayload->linearVelocity),24); + b_AngularVelocity->value().writeBinary((unsigned char *)&(ptrPayload->angularVelocity),24); + b_Attitude->value().writeBinary((unsigned char *)&(ptrPayload->attitude),32); - ObjectUpdateMessagePayload * ptrPayload = (ObjectUpdateMessagePayload*)message->getPayloadPtr(); - ptrPayload->id = m_ID; - ptrPayload->timeStamp = CSPSim::theSim->getElapsedTime(); - b_GlobalPosition->value().writeBinary((unsigned char *)&(ptrPayload->globalPosition),24); - b_LinearVelocity->value().writeBinary((unsigned char *)&(ptrPayload->linearVelocity),24); - b_AngularVelocity->value().writeBinary((unsigned char *)&(ptrPayload->angularVelocity),24); - b_Attitude->value().writeBinary((unsigned char *)&(ptrPayload->attitude),32); - -// simdata::MemoryWriter writer((simdata::uint8*)ptrPayload); -// writer << m_ID; -// writer << m_Type; -// writer << CSPSim::theSim->getElapsedTime(); -// b_GlobalPosition->value().serialize(writer); -// b_LinearVelocity->value().serialize(writer); -// b_AngularVelocity->value().serialize(writer); -// b_Attitude->value().serialize(writer); - - CSP_LOG(APP, DEBUG, "DynamicObject::getUpdateMessage() - returning message"); + // simdata::MemoryWriter writer((simdata::uint8*)ptrPayload); + // writer << m_ID; + // writer << m_Type; + // writer << CSPSim::theSim->getElapsedTime(); + // b_GlobalPosition->value().serialize(writer); + // b_LinearVelocity->value().serialize(writer); + // b_AngularVelocity->value().serialize(writer); + // b_Attitude->value().serialize(writer); + CSP_LOG(NETWORK, DEBUG, "DynamicObject::getUpdateMessage() - returning message"); - return message; + return message; } -void DynamicObject::putUpdateMessage(NetworkMessage* message) -{ - // read message +void DynamicObject::putUpdateMessage(NetworkMessage* message) { + // read message - ObjectUpdateMessagePayload * ptrPayload = (ObjectUpdateMessagePayload*)message->getPayloadPtr(); - // verify we have the correct id in the packet for this object. - if (m_ID == ptrPayload->id) - { -// printf("Loading update message of object %d\n", m_ID); - } - else - { -// printf("Error loading update message, object id (%d) does not match\n", idValue); - } + ObjectUpdateMessagePayload * ptrPayload = (ObjectUpdateMessagePayload*)message->getPayloadPtr(); + // verify we have the correct id in the packet for this object. + if (m_ID == ptrPayload->id) { + //printf("Loading update message of object %d\n", m_ID); + } else { + //printf("Error loading update message, object id (%d) does not match\n", idValue); + } - // we can disregard this message if the timestamp is older then the most - // recent update. - - ptrPayload->timeStamp = CSPSim::theSim->getElapsedTime(); - // - //load the other values. - b_GlobalPosition->value().readBinary((unsigned char*)&(ptrPayload->globalPosition),24); - b_LinearVelocity->value().readBinary((unsigned char *)&(ptrPayload->linearVelocity),24); - b_AngularVelocity->value().readBinary((unsigned char *)&(ptrPayload->angularVelocity),24); - b_Attitude->value().readBinary((unsigned char *)&(ptrPayload->attitude),32); - -// unsigned int _id; -// unsigned _type; -// float _timestamp; -// -// simdata::MemoryReader reader((simdata::uint8*)ptrPayload); -// reader >> _id; -// reader >> _type; -// reader >> _timestamp; -// b_GlobalPosition->value().serialize(reader); -// b_LinearVelocity->value().serialize(reader); -// b_AngularVelocity->value().serialize(reader); -// b_Attitude->value().serialize(reader); + // we can disregard this message if the timestamp is older then the most + // recent update. + + ptrPayload->timeStamp = CSPSim::theSim->getElapsedTime(); + + // load the other values. + b_GlobalPosition->value().readBinary((unsigned char*)&(ptrPayload->globalPosition),24); + b_LinearVelocity->value().readBinary((unsigned char *)&(ptrPayload->linearVelocity),24); + b_AngularVelocity->value().readBinary((unsigned char *)&(ptrPayload->angularVelocity),24); + b_Attitude->value().readBinary((unsigned char *)&(ptrPayload->attitude),32); + + //unsigned int _id; + //unsigned _type; + //float _timestamp; + // + //simdata::MemoryReader reader((simdata::uint8*)ptrPayload); + //reader >> _id; + //reader >> _type; + //reader >> _timestamp; + //b_GlobalPosition->value().serialize(reader); + //b_LinearVelocity->value().serialize(reader); + //b_AngularVelocity->value().serialize(reader); + //b_Attitude->value().serialize(reader); } |