Changeset 542
- Timestamp:
- 03/02/10 22:45:36 (5 months ago)
- Location:
- branches/cpp-ode/src/libmmpong
- Files:
-
- 10 modified
-
netent.h (modified) (2 diffs)
-
netgame_ode.cc (modified) (1 diff)
-
netgame_ode.h (modified) (3 diffs)
-
netgame_ode_pong.cc (modified) (1 diff)
-
netgame_ode_pong.h (modified) (1 diff)
-
ode_box.cc (modified) (2 diffs)
-
ode_box.h (modified) (1 diff)
-
ode_obj.h (modified) (1 diff)
-
ode_sphere.cc (modified) (2 diffs)
-
ode_sphere.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/cpp-ode/src/libmmpong/netent.h
r526 r542 4 4 #include <ostream> 5 5 #include <boost/shared_ptr.hpp> 6 #include <boost/enable_shared_from_this.hpp> 6 7 #include <boost/function.hpp> 7 8 #include <stdexcept> … … 22 23 class NetGame; 23 24 24 class NetEnt {25 class NetEnt : public boost::enable_shared_from_this<NetEnt> { 25 26 private: 26 27 uint16_t entid; -
branches/cpp-ode/src/libmmpong/netgame_ode.cc
r541 r542 43 43 44 44 45 #define MAX_CONTACTS 4 //maximal number of contacts between two particular objects 46 47 void NetGameODE::collideCallback(void *data, dGeomID o1, dGeomID o2) { 48 dContact contact[MAX_CONTACTS]; 49 unsigned int n_collide = dCollide(o1, o2, MAX_CONTACTS, &contact[0].geom, sizeof(dContact)); 50 for (unsigned int i=0; i< n_collide; i++){ 51 contact[i].surface.mode = dContactBounce;// | dContactSoftCFM; 52 contact[i].surface.mu=dInfinity; 53 contact[i].surface.bounce=1.0; // \in [0,1] 54 contact[i].surface.bounce_vel=0.01; 55 //contact[i].surface.soft_cfm = 0.1; 56 dBodyID b1 = dGeomGetBody(o1), b2 = dGeomGetBody(o2); 57 dJointID c = dJointCreateContact(id(), 0, contact+i); 58 dJointAttach(c, b1, b2); 59 LOGDBG("Collision detected (BAM!)"); 60 } 61 } 62 63 #undef MAX_CONTACTS -
branches/cpp-ode/src/libmmpong/netgame_ode.h
r541 r542 7 7 namespace mmp { 8 8 9 #define MAX_CONTACTS 4 //maximal number of contacts between two particular objects10 9 11 10 //used only for initialization and cleanup of ODE … … 26 25 virtual NetEnt::pointer cln_ent_new(NetMsg::pointer msg); 27 26 27 std::map<dGeomID, NetEnt::pointer> geom2odeobj; 28 28 29 protected: 29 30 NetGameODE(NetCon::pointer cln_con) : NetGame(cln_con), space(NULL) { … … 43 44 pthis->collideCallback(NULL, o1, o2); 44 45 }; 45 46 46 47 virtual void collideCallback(void *data, dGeomID o1, dGeomID o2) { 48 dContact contact[MAX_CONTACTS]; 49 unsigned int n_collide = dCollide(o1, o2, MAX_CONTACTS, &contact[0].geom, sizeof(dContact)); 50 for (unsigned int i=0; i< n_collide; i++){ 51 contact[i].surface.mode = dContactBounce;// | dContactSoftCFM; 52 contact[i].surface.mu=dInfinity; 53 contact[i].surface.bounce=1.0; // \in [0,1] 54 contact[i].surface.bounce_vel=0.01; 55 //contact[i].surface.soft_cfm = 0.1; 56 dBodyID b1 = dGeomGetBody(o1), b2 = dGeomGetBody(o2); 57 dJointID c = dJointCreateContact(id(), 0, contact+i); 58 dJointAttach(c, b1, b2); 59 cout << "BAM!" << endl; // ;) 60 } 61 }; 62 47 virtual void collideCallback(void *data, dGeomID o1, dGeomID o2); 63 48 }; 64 65 #undef MAX_CONTACTS66 49 67 50 } -
branches/cpp-ode/src/libmmpong/netgame_ode_pong.cc
r541 r542 4 4 using namespace mmp; 5 5 6 void NetGameODEPong::srv_init() { 7 //create bars on top and bottom 8 //uint16_t entid; 9 boost::shared_ptr<ODEBox> 10 bartop=srv_ent_create<ODEBox>(), 11 barbot=srv_ent_create<ODEBox>(); 12 bartop->geom.setLengths(2.0,0.05,0.05); 13 bartop->setPosition(0.0, 1.05, 0.0); 14 bartop->set_immovable(); 15 16 barbot->geom.setLengths(2.0,0.05,0.05); 17 barbot->setPosition(0.0, -1.05, 0.0); 18 barbot->set_immovable(); 19 20 boost::shared_ptr<ODESphere> 21 ball=srv_ent_create<ODESphere>(); 22 ball->geom.setRadius(0.025); 23 ball->setLinearVel(0.0, 1.0, 0.0); 24 } 6 25 7 26 void NetGameODEPong::srv_con_start(NetCon::pointer con) { -
branches/cpp-ode/src/libmmpong/netgame_ode_pong.h
r541 r542 48 48 49 49 //server 50 virtual void srv_init() { 51 //create bars on top and bottom 52 //uint16_t entid; 53 boost::shared_ptr<ODEBox> 54 bartop=srv_ent_create<ODEBox>(), 55 barbot=srv_ent_create<ODEBox>(); 56 bartop->geom.setLengths(2.0,0.05,0.05); 57 bartop->setPosition(0.0, 1.05, 0.0); 58 bartop->set_immovable(); 59 60 barbot->geom.setLengths(2.0,0.05,0.05); 61 barbot->setPosition(0.0, -1.05, 0.0); 62 barbot->set_immovable(); 63 64 boost::shared_ptr<ODESphere> 65 ball=srv_ent_create<ODESphere>(); 66 ball->geom.setRadius(0.025); 67 ball->setLinearVel(0.0, 1.0, 0.0); 68 }; 50 virtual void srv_init(); 69 51 virtual void srv_con_start(NetCon::pointer con); 70 52 virtual void srv_con_end(NetCon::pointer con); -
branches/cpp-ode/src/libmmpong/ode_box.cc
r541 r542 3 3 using namespace mmp; 4 4 5 ODEBox::ODEBox(NetGame::pointer game, uint16_t entid, bool _movable) :6 ODEObj<NetEnt::ODEBox, dBox>( game, entid)5 ODEBox::ODEBox(NetGame::pointer _game, uint16_t entid, bool _movable) : 6 ODEObj<NetEnt::ODEBox, dBox>(_game, entid) 7 7 { 8 8 geom.create(get_space(), 1.0, 1.0, 1.0); 9 LOGDBG("HA"); 10 //TODO: somethin' like enable()/disable() 11 // get_game()->geom2odeobj[geom.id()]=shared_from_this(); 12 LOGDBG("HU"); 9 13 classname="ODEBox"; 10 14 if (_movable) … … 12 16 } 13 17 18 void ODEBox::update(NetMsg::pointer msg) { 19 ODEObj<NetEnt::ODEBox, dBox>::update(msg); 20 if (msg->get_state()==NetMsg::StatPacking) { 21 dVector3 lens; 22 geom.getLengths(lens); 23 LOGDBG("Lengths==["<<lens[0]<<","<<lens[1]<<","<<lens[2]<<"]"); 24 for(unsigned int i=0; i<3; i++) 25 msg->pack_ode(lens[i]); 26 } else if (msg->get_state()==NetMsg::StatUnpacking) { 27 dVector3 lens; 28 for(unsigned int i=0; i<3; i++) 29 msg->unpack_ode(lens[i]); 30 LOGDBG("Lengths==["<<lens[0]<<","<<lens[1]<<","<<lens[2]<<"]"); 31 geom.setLengths(lens[0],lens[1],lens[2]); 32 } else 33 throw std::runtime_error("NetMsg not in packing or unpacking state"); 34 } 35 -
branches/cpp-ode/src/libmmpong/ode_box.h
r541 r542 12 12 ODEBox(NetGame::pointer game, uint16_t entid, bool _movable=true); 13 13 private: 14 virtual void update(NetMsg::pointer msg) { 15 ODEObj<NetEnt::ODEBox, dBox>::update(msg); 16 if (msg->get_state()==NetMsg::StatPacking) { 17 dVector3 lens; 18 geom.getLengths(lens); 19 LOGDBG("Lengths==["<<lens[0]<<","<<lens[1]<<","<<lens[2]<<"]"); 20 for(unsigned int i=0; i<3; i++) 21 msg->pack_ode(lens[i]); 22 } else if (msg->get_state()==NetMsg::StatUnpacking) { 23 dVector3 lens; 24 for(unsigned int i=0; i<3; i++) 25 msg->unpack_ode(lens[i]); 26 LOGDBG("Lengths==["<<lens[0]<<","<<lens[1]<<","<<lens[2]<<"]"); 27 geom.setLengths(lens[0],lens[1],lens[2]); 28 } else 29 throw std::runtime_error("NetMsg not in packing or unpacking state"); 30 }; 14 virtual void update(NetMsg::pointer msg); 31 15 }; 32 16 -
branches/cpp-ode/src/libmmpong/ode_obj.h
r541 r542 36 36 movable=false; 37 37 }; 38 ~ODEObj() { 39 if (geom.id()) 40 game->geom2odeobj.erase(geom.id()); 41 } 38 42 39 43 bool movable; -
branches/cpp-ode/src/libmmpong/ode_sphere.cc
r541 r542 3 3 using namespace mmp; 4 4 5 ODESphere::ODESphere(NetGame::pointer game, uint16_t entid, bool _movable) :6 ODEObj<NetEnt::ODESphere, dSphere>( game, entid)5 ODESphere::ODESphere(NetGame::pointer _game, uint16_t entid, bool _movable) : 6 ODEObj<NetEnt::ODESphere, dSphere>(_game, entid) 7 7 { 8 8 geom.create(get_space(), 1.0); 9 geom.setBody(*this);9 //TODO get_game()->geom2odeobj[geom.id()]=shared_from_this(); 10 10 classname="ODESphere"; 11 11 if (_movable) … … 13 13 } 14 14 15 /*16 bool ObjSphere::serialize(ostream &o, NetObjMode type) {17 15 18 return true; 16 void ODESphere::update(NetMsg::pointer msg) { 17 ODEObj<NetEnt::ODESphere, dSphere>::update(msg); 18 if (msg->get_state()==NetMsg::StatPacking) { 19 msg->pack_ode(geom.getRadius()); 20 } else if (msg->get_state()==NetMsg::StatUnpacking) { 21 dReal r; 22 msg->unpack_ode(r); 23 geom.setRadius(r); 24 } else 25 throw std::runtime_error("NetMsg not in packing or unpacking state"); 19 26 } 20 */ 27 -
branches/cpp-ode/src/libmmpong/ode_sphere.h
r541 r542 11 11 ODESphere(NetGame::pointer game, uint16_t entid, bool _movable=true); 12 12 private: 13 virtual void update(NetMsg::pointer msg) { 14 ODEObj<NetEnt::ODESphere, dSphere>::update(msg); 15 if (msg->get_state()==NetMsg::StatPacking) { 16 msg->pack_ode(geom.getRadius()); 17 } else if (msg->get_state()==NetMsg::StatUnpacking) { 18 dReal r; 19 msg->unpack_ode(r); 20 geom.setRadius(r); 21 } else 22 throw std::runtime_error("NetMsg not in packing or unpacking state"); 23 }; 13 virtual void update(NetMsg::pointer msg); 24 14 }; 25 15
