Changeset 540

Show
Ignore:
Timestamp:
02/28/10 22:45:14 (5 months ago)
Author:
gaul@…
Message:
  • ball hits paddle (keep bouncin'!)
  • NOTE: physics are computed on client only (TODO: sync)
Location:
branches/cpp-ode/src
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • branches/cpp-ode/src/libmmpong/netgame.cc

    r526 r540  
    1414        ent_reg<ODESphere>(); 
    1515        ent_reg<Player>(); 
     16        world_time=boost::posix_time::microsec_clock::universal_time(); 
    1617}; 
    1718 
  • branches/cpp-ode/src/libmmpong/netgame.h

    r538 r540  
    55#include <set> 
    66#include <boost/thread/mutex.hpp> 
     7#include <boost/date_time/posix_time/posix_time.hpp> 
    78#include "netent.h" 
    89#include "netent_helper.h" 
     
    4546                //override in derived Game class implementing the actual  
    4647                //gameplay and physics 
    47                 virtual void advance(double step_ms) = 0; 
     48                //ATTENTION: the method should return exactly after the given time has passed 
     49                virtual void advance(const boost::posix_time::ptime endtime = boost::posix_time::microsec_clock::universal_time()) = 0; 
    4850                 
    49                 virtual double get_proposed_step_ms() { return 1.0/50; }; 
     51                //virtual double get_proposed_step_ms() { return 1.0/50; }; 
    5052 
    5153                //override in derived client class 
     
    116118                        return boost::dynamic_pointer_cast<CLASS>(get_ent(entid)); 
    117119                }; 
     120                 
     121                boost::posix_time::ptime world_time; //time of last advance() 
    118122 
    119123                //only server creates NetEnts 
  • branches/cpp-ode/src/libmmpong/netgame_ode.cc

    r528 r540  
    1212}; 
    1313 
    14 void NetGameODE::advance(double ms) { 
     14#define STEPSIZE 0.001f 
     15void NetGameODE::advance(const boost::posix_time::ptime endtime) { 
     16        lock(); 
     17        if (endtime < world_time) { 
     18                LOGWARN("endtime < world_time"); 
     19                unlock(); 
     20                return; 
     21        } 
     22         
     23        boost::posix_time::time_duration elapsed = endtime - world_time; 
    1524 
     25        //TODO (if necessary): improve (naive) time stepping by measuring computation times 
     26         
     27        double seconds= ((double)elapsed.total_microseconds())/1.e6; 
     28        unsigned int step_count= seconds/STEPSIZE; 
     29        LOGDBG("step world "<<seconds<<" seconds with "<<step_count << " iterations"); 
     30        for (unsigned int i=0; i<step_count; i++) { 
     31                collide(); 
     32                step(STEPSIZE); 
     33        } 
     34        world_time=endtime; 
     35         
     36        unlock(); 
    1637} 
    1738 
  • branches/cpp-ode/src/libmmpong/netgame_ode.h

    r526 r540  
    2222 
    2323                //(re-)implementation of virtual members 
    24                 virtual void advance(double ms); 
     24                virtual void advance(const boost::posix_time::ptime endtime); 
    2525                 
    2626                virtual NetEnt::pointer cln_ent_new(NetMsg::pointer msg); 
     
    3737                 
    3838                static void collideCallbackCaller /* ;) */ (void *data, dGeomID o1, dGeomID o2) { 
    39                         NetGameODE *pthis = (NetGameODE *)data; 
     39                        NetGameODE *pthis = dynamic_cast<NetGameODE *>((NetGameODE *)data); 
    4040                        //disable RTTI if this is bottleneck 
    41                         if (typeid(pthis)!=typeid(NetGameODE)) 
     41                        if (!pthis) 
    4242                                throw std::runtime_error("Given pointer in callback is not a NetGameODE object"); 
    4343                        pthis->collideCallback(NULL, o1, o2); 
  • branches/cpp-ode/src/libmmpong/netgame_ode_pong.cc

    r539 r540  
    2424        playerpad->geom.setLengths(0.05,0.5,0.05); 
    2525        double ang=M_PI*(1.0+2.0*newteamid/srv_teamid_cur); 
    26         playerpad->setPosition(cos(ang)*1.05, sin(ang)*1.05, 0.0); 
     26        playerpad->geom.setPosition(cos(ang)*1.05, sin(ang)*1.05, 0.0); 
    2727        uint16_t newpadid=playerpad->get_entid(); 
    2828        player2pad[newplayerid]=newpadid; 
     
    274274                boost::shared_ptr<ODEBox> pad=get_ent<ODEBox>(mypadid); 
    275275                double ang=M_PI*(1.0+2.0*myteamid/srv_teamid_cur); 
    276                 pad->setPosition(cos(ang)*1.05, -1.0 + 2.0 * mypadpos, 0.0); 
     276                pad->geom.setPosition(cos(ang)*1.05, -1.0 + 2.0 * mypadpos, 0.0); 
    277277                NetMsg::pointer msg=NetMsg::create(NetMsg::CmdGameCustom); 
    278278                msg->pack_begin(); 
  • branches/cpp-ode/src/libmmpong/netgame_ode_pong.h

    r538 r540  
    5555                                barbot=srv_ent_create<ODEBox>(); 
    5656                        bartop->geom.setLengths(2.0,0.05,0.05); 
    57                         bartop->setPosition(0.0, 1.05, 0.0); 
     57                        bartop->geom.setPosition(0.0, 1.05, 0.0); 
    5858                        barbot->geom.setLengths(2.0,0.05,0.05); 
    59                         barbot->setPosition(0.0, -1.05, 0.0); 
     59                        barbot->geom.setPosition(0.0, -1.05, 0.0); 
    6060                         
    6161                        boost::shared_ptr<ODESphere>  
    6262                                ball=srv_ent_create<ODESphere>(); 
    6363                        ball->geom.setRadius(0.025); 
     64                        ball->setLinearVel(-0.1, 0.0, 0.0); 
    6465                }; 
    6566                virtual void srv_con_start(NetCon::pointer con); 
  • branches/cpp-ode/src/libmmpong/ode_box.cc

    r532 r540  
    77{  
    88        geom.create(get_space(), 1.0, 1.0, 1.0); 
    9         geom.setBody(*this); 
     9        //geom.setBody(*this); 
    1010        classname="ODEBox"; 
    1111} 
  • branches/cpp-ode/src/libmmpong/ode_obj.h

    r528 r540  
    3737                virtual void update(NetMsg::pointer msg) { 
    3838                        if (msg->get_state()==NetMsg::StatPacking) { 
    39                                 const dReal *vals=getPosition(); 
     39                                const dReal *vals=geom.getPosition(); 
    4040                                LOGDBG("Position==["<<vals[0]<<","<<vals[1]<<","<<vals[2]<<"]"); 
    4141                                for(unsigned int i=0; i<3; i++) 
     
    4848 
    4949                                //check ODE alignment in dMatrix3 
    50                                 vals=getRotation(); 
     50                                vals=geom.getRotation(); 
    5151                                LOGDBG("Rotation==["<<vals[0]<<","<<vals[1]<<","<<vals[2]<<";"<<vals[4]<<","<<vals[5]<<","<<vals[6]<<";"<<vals[8]<<","<<vals[9]<<","<<vals[10]<<"]"); 
    5252                                for(unsigned int i=0; i<3; i++) 
     
    6666                                        msg->unpack_ode(vals[i]); 
    6767                                LOGDBG("Position==["<<vals[0]<<","<<vals[1]<<","<<vals[2]<<"]"); 
    68                                 setPosition(vals); 
     68                                geom.setPosition(vals[0], vals[1], vals[2]); 
    6969                                 
    7070                                for(unsigned int i=0; i<3; i++) 
     
    8080                                        msg->unpack_ode(vals[i]); 
    8181                                LOGDBG("Rotation==["<<vals[0]<<","<<vals[1]<<","<<vals[2]<<";"<<vals[4]<<","<<vals[5]<<","<<vals[6]<<";"<<vals[8]<<","<<vals[9]<<","<<vals[10]<<"]"); 
    82                                 setRotation(vals); 
     82                                geom.setRotation(vals); 
    8383 
    8484                                for(unsigned int i=0; i<3; i++) 
  • branches/cpp-ode/src/mmpong-gl/client_gl.cc

    r538 r540  
    111111                 
    112112                renderer.begin(); 
    113                 if (game) 
     113                if (game) { 
     114                        game->advance(); 
    114115                        game->render(); 
     116                } 
    115117                renderer.end(); 
    116118