From: <wol...@us...> - 2004-04-17 17:22:21
|
Update of /cvsroot/csp/APPLICATIONS/CSPSim/Source In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9139 Modified Files: CSPSim.cpp DynamicObject.cpp Log Message: changes for networking Index: CSPSim.cpp =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/CSPSim.cpp,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** CSPSim.cpp 3 Apr 2004 22:15:21 -0000 1.42 --- CSPSim.cpp 17 Apr 2004 17:22:11 -0000 1.43 *************** *** 49,52 **** --- 49,53 ---- #include "ConsoleCommands.h" #include "Profile.h" + #include "Networking.h" #include <SimData/Types.h> *************** *** 113,120 **** --- 114,128 ---- CSPSim::CSPSim() { + if (theSim == 0) { theSim = this; } + int level = g_Config.getInt("Debug", "LoggingLevel", 0, true); + csplog().setLogLevels(CSP_ALL, level); + csplog().setOutput("CSPSim.log"); + + CSP_LOG(APP, INFO, "Constructing CSPSim Object..."); + m_Clean = true; *************** *** 139,146 **** m_Shell = new PyShell(); - int level = g_Config.getInt("Debug", "LoggingLevel", 0, true); - csplog().setLogLevels(CSP_ALL, level); - csplog().setOutput("CSPSim.log"); } --- 147,153 ---- m_Shell = new PyShell(); + + m_NetworkBroadcaster = NULL; } *************** *** 156,164 **** void CSPSim::setActiveObject(simdata::Ref<DynamicObject> object) { ! /* CSP_LOG(APP, INFO, "CSPSim::setActiveObject - objectID: " << object->getObjectID() << ", ObjectType: " << object->getObjectType() << ", Position: " << object->getGlobalPosition()); ! */ if (m_ActiveObject.valid()) { --- 163,173 ---- void CSPSim::setActiveObject(simdata::Ref<DynamicObject> object) { ! /* CSP_LOG(APP, INFO, "CSPSim::setActiveObject - objectID: " << object->getObjectID() << ", ObjectType: " << object->getObjectType() << ", Position: " << object->getGlobalPosition()); ! */ ! ! CSP_LOG(APP, INFO, "CSPSim::setActiveObject()"); if (m_ActiveObject.valid()) { *************** *** 402,405 **** --- 411,417 ---- m_GameScreen = new GameScreen; m_GameScreen->onInit(); + + // create the networking layer + m_NetworkBroadcaster = new NetworkBroadcaster; #if 0 *************** *** 494,498 **** try { date.parseXML(date_string.c_str()); ! } catch (...) { std::cerr << "Invalid starting date in INI file (Testing:Date).\n" << std::endl; --- 506,510 ---- try { date.parseXML(date_string.c_str()); ! } catch (...) { std::cerr << "Invalid starting date in INI file (Testing:Date).\n" << std::endl; *************** *** 558,562 **** PROF1(_screen_render, 60); } ! // Swap OpenGL buffers #ifndef __CSPSIM_EXE__ --- 570,577 ---- PROF1(_screen_render, 60); } ! ! ! ! // Swap OpenGL buffers #ifndef __CSPSIM_EXE__ *************** *** 661,664 **** --- 676,680 ---- } if (!handled && m_Interface.valid()) { + CSP_LOG(APP, DEBUG, "CSPSim::doInput()-Calling m_Interface->onEvent()"); handled = m_Interface->onEvent(event); } *************** *** 680,684 **** CSP_LOG(APP, DEBUG, "CSPSim::updateObjects..."); ! if (m_Battlefield.valid()) { m_Battlefield->onUpdate(dt); } --- 696,700 ---- CSP_LOG(APP, DEBUG, "CSPSim::updateObjects..."); ! if (m_Battlefield.valid()) { m_Battlefield->onUpdate(dt); } *************** *** 686,689 **** --- 702,724 ---- m_Scene->onUpdate(dt); } + + // call networking layer. + // TODO the code below tests the networking section. Later it probably needs to + // be moved elsewhere. Currently commenting out so we can move to subversion. + // CSP_LOG(APP, DEBUG, "CSPSim::run... beginning network updates"); + + // simdata::Ref<DynamicObject> dynamicObject = (simdata::Ref<DynamicObject>)m_ActiveObject; + // NetworkMessage * message = dynamicObject->getUpdateMessage(); + + // m_NetworkBroadcaster->sendMessage(1, message ); + + // dynamicObject->putUpdateMessage( message ); + + // CSP_LOG(APP, DEBUG, "CSPSim::run... finished network updates"); + + // this may not be necessary. especially if a memory pool of messages objects is used. + // delete message; + + } Index: DynamicObject.cpp =================================================================== RCS file: /cvsroot/csp/APPLICATIONS/CSPSim/Source/DynamicObject.cpp,v retrieving revision 1.19 retrieving revision 1.20 diff -C2 -d -r1.19 -r1.20 *** DynamicObject.cpp 20 Oct 2003 00:23:23 -0000 1.19 --- DynamicObject.cpp 17 Apr 2004 17:22:12 -0000 1.20 *************** *** 384,392 **** } ! void DynamicObject::updateScene(simdata::Vector3 const &origin) { if (m_SceneModel.valid()) { ! m_SceneModel->setPositionAttitude(b_GlobalPosition->value() - origin, b_Attitude->value()); onRender(); } } --- 384,484 ---- } ! void DynamicObject::updateScene(simdata::Vector3 const &origin) { if (m_SceneModel.valid()) { ! m_SceneModel->setPositionAttitude(b_GlobalPosition->value() - origin, b_Attitude->value()); onRender(); } } + + NetworkMessage * 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 = new NetworkMessage(); + message->initialize( messageType, payloadLen); + + unsigned char * ptrBuf = (unsigned char*)message->getPayloadPtr(); + + printf("Generating network update message for object id: %d\n", m_ID); + memcpy((void*)ptrBuf, (void*)&m_ID, sizeof(unsigned int)); ptrBuf += sizeof(unsigned int); + + simdata::SimTime timeStamp = CSPSim::theSim->getElapsedTime(); + memcpy((void*)ptrBuf, (void*)&timeStamp, sizeof(simdata::SimTime)); ptrBuf += sizeof(simdata::SimTime); + + int bytescopied; + bytescopied = b_GlobalPosition->value().writeBinary(ptrBuf, sizeof(simdata::Vector3)); + ptrBuf += bytescopied; + + bytescopied = b_LinearVelocity->value().writeBinary(ptrBuf, sizeof(simdata::Vector3)); + ptrBuf += bytescopied; + + bytescopied = b_AngularVelocity->value().writeBinary(ptrBuf, sizeof(simdata::Vector3)); + ptrBuf += bytescopied; + + bytescopied = b_Attitude->value().writeBinary(ptrBuf, sizeof(simdata::Quat)); + ptrBuf += bytescopied; + + // bytescopied = b_Inertia->value().writeBinary(ptrBuf, sizeof(simdata::Quat)); + // ptrBuf += bytescopied; + + // memcpy((void*)ptrBuf, (void*)&b_Mass->value(), sizeof(double)); + // ptrBuf += bytescopied; + + + + return message; + } + + void DynamicObject::putUpdateMessage(NetworkMessage* message) + { + // read message + + unsigned char * ptrBuf = (unsigned char*)message->getPayloadPtr(); + + // skip object id + unsigned int idValue; + memcpy((void*)&idValue, (void*)ptrBuf, sizeof(unsigned int)); + ptrBuf += sizeof(unsigned int); + + // verify we have the correct id in the packet for this object. + if (m_ID == idValue) + { + printf("Loading update message of object %d\n", m_ID); + } + else + { + printf("Error loading update message, object id (%d) does not match\n", idValue); + } + + // get timestamp + simdata::SimTime timeStamp; + memcpy((void*)&timeStamp, (void*)ptrBuf, sizeof(simdata::SimTime)); ptrBuf += sizeof(simdata::SimTime); + + int bytescopied; + bytescopied = b_GlobalPosition->value().readBinary(ptrBuf, sizeof(simdata::Vector3)); + ptrBuf += bytescopied; + bytescopied = b_LinearVelocity->value().readBinary(ptrBuf, sizeof(simdata::Vector3)); + ptrBuf += bytescopied; + bytescopied = b_AngularVelocity->value().readBinary(ptrBuf, sizeof(simdata::Vector3)); + ptrBuf += bytescopied; + bytescopied = b_Attitude->value().readBinary(ptrBuf, sizeof(simdata::Quat)); + ptrBuf += bytescopied; + // bytescopied = b_Inertia->value().readBinary(ptrBuf, sizeof(simdata::Matrix3)); + // ptrBuf += bytescopied; + + // double *pValue = &b_Mass->value(); + // memcpy((void*)&pValue, (void*)ptrBuf, sizeof(double)); + + //ptrBuf += sizeof(double); + + // return message to shared pool. + // NetworkMessagePool.putMessageObject(message); + // delete message; + } + + + + |