This is a legacy Trac instance left read-only for reference purposes. More info. dev main | home

Changeset 188

Show
Ignore:
Timestamp:
02/27/2010 11:38:01 PM (2 years ago)
Author:
mceier
Message:

Sim2 tests

Signed-off-by: Mariusz Ceier <mceier@gmail.com>

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/include/waterworld/config.h.in

    r110 r188  
    33 
    44#cmakedefine WATERWORLD_WIN32 
     5#cmakedefine USE_SIM2 
    56 
    67#endif/*CONFIG_INCLUDED*/ 
  • trunk/include/waterworld/sim2/IntrusivePtrBase.h

    r175 r188  
    2323                IntrusivePtrBase &operator=(IntrusivePtrBase const &); 
    2424                virtual ~IntrusivePtrBase(); 
     25        public: 
     26                uintmax_t getRefCount() const; 
    2527        }; 
    2628 
  • trunk/include/waterworld/sim2/PhysicalBody.h

    r185 r188  
    2222        class PhysicalBody : public IntrusivePtrBase, private boost::noncopyable 
    2323        { 
    24                 boost::intrusive_ptr<Animat> m_animat;                 
     24                Animat *m_animat;              
    2525                PhysicalBody(PhysicalBody const &body); 
    2626                PhysicalBody &operator=(PhysicalBody const &body); 
     
    2929                 
    3030                PhysicalBody(); 
    31                 PhysicalBody(boost::intrusive_ptr<Animat> animat); 
     31                PhysicalBody(Animat *animat); 
    3232                /** 
    3333                 * \return Animat 
    3434                 */ 
    35                 boost::intrusive_ptr<Animat> getAnimat() const; 
     35                Animat *getAnimat() const; 
    3636                /** 
    3737                 * Set animat 
    3838                 */ 
    39                 void setAnimat(boost::intrusive_ptr<Animat> newAnimat); 
     39                void setAnimat(Animat *newAnimat); 
    4040                /** 
    4141                 * Set PAL body 
  • trunk/include/waterworld/sim2/World.h

    r186 r188  
    44namespace waterworld 
    55{ 
     6        /** 
     7         * \class World 
     8         * \brief World class containing all animats -  
     9         *      only 1 World instance at the same time is supported 
     10         */ 
    611        class World; 
    712} 
     
    1621 
    1722/** 
    18  * PAL classe
     23 * PAL Physics clas
    1924 */ 
    2025class palPhysics; 
     26/** 
     27 * PAL collision detection class 
     28 */ 
    2129class palCollisionDetection; 
    2230 
     
    2634        { 
    2735                Animats m_animats; 
    28                 //Bodies m_bodies; 
    2936                World(); 
    3037                World(World const &); 
    3138                World &operator=(World const &); 
    3239        public: 
     40                /** 
     41                 * \return Animats (read-only) 
     42                 */ 
    3343                Animats const &getAnimats() const; 
     44                /** 
     45                 * \return Animats 
     46                 */ 
    3447                Animats &getAnimats(); 
     48                /** 
     49                 * Starts events thread 
     50                 */ 
    3551                void startEventsThread(); 
     52                /** 
     53                 * Stops events thread 
     54                 */ 
    3655                void stopEventsThread(); 
     56                /** 
     57                 * Simulation step 
     58                 * \param dt delta time 
     59                 */ 
    3760                void step(real_t dt); 
     61                /** 
     62                 * \return PAL Physics object 
     63                 */ 
    3864                palPhysics *getPhysics() const; 
     65                /** 
     66                 * \return PAL Collision Detection object 
     67                 */ 
    3968                palCollisionDetection *getCollisionDetection() const; 
     69                /** 
     70                 * Create animats body 
     71                 * \param animat Which animat should have this body 
     72                 * \param radius radius of new body ( of new sphere ) 
     73                 * \param mass Mass of new body 
     74                 * \param position Position of new body 
     75                 */ 
    4076                boost::intrusive_ptr<PhysicalBody> createAnimatsBody( 
    4177                        boost::intrusive_ptr<Animat> animat, 
    4278                        Radius radius, Mass mass, Position position); 
     79                /** 
     80                 * \return Events queue 
     81                 */ 
    4382                boost::intrusive_ptr<EventsQueue<Event> > getEventsQueue(); 
     83                /** 
     84                 * \return Handlers registry 
     85                 */ 
    4486                boost::intrusive_ptr<HandlersRegistry> getHandlersRegistry(); 
     87                /** 
     88                 * Create new world ( only 1 world at a time is supported ) 
     89                 * \return new world 
     90                 */ 
    4591                static boost::intrusive_ptr<World> createWorld(); 
     92                /** 
     93                 * Remove animats body 
     94                 */ 
     95                void removeAnimatsBody(boost::intrusive_ptr<Animat> animat); 
     96                /** 
     97                 * Remove animat 
     98                 */ 
     99                void removeAnimat(boost::intrusive_ptr<Animat> animat); 
    46100                virtual ~World(); 
    47101        private: 
  • trunk/src/CMakeLists.txt

    r186 r188  
    4545        TARGET_LINK_LIBRARIES(WaterWorldGUI ${WATERWORLD_LIBRARY} ${WATERWORLD_LIBRARIES} ${WATERWORLD_GUI_LIBRARIES}) 
    4646ELSE(USE_SIM2) 
     47 
    4748        SET(WATERWORLD_GUI_SOURCES  
    4849                waterworld.cpp init_sdl.cpp 
  • trunk/src/tests/CMakeLists.txt

    r175 r188  
    1919 
    2020        ADD_TEST(Events TestEvents) 
     21 
     22        SET(TEST_WORLD_SOURCES test_sim2_world.cpp) 
     23        ADD_EXECUTABLE(TestWorld ${TEST_WORLD_SOURCES}) 
     24        TARGET_LINK_LIBRARIES(TestWorld ${TESTS_LIBRARIES}) 
     25 
     26        ADD_TEST(World TestWorld) 
     27 
     28        SET(TEST_SENSOR_SOURCES test_sim2_sensor.cpp) 
     29        ADD_EXECUTABLE(TestSensor ${TEST_SENSOR_SOURCES}) 
     30        TARGET_LINK_LIBRARIES(TestSensor ${TESTS_LIBRARIES}) 
     31 
     32        ADD_TEST(Sensor TestSensor) 
     33 
     34        SET(TEST_COLLISION_SENSOR_SOURCES test_sim2_collision_sensor.cpp) 
     35        ADD_EXECUTABLE(TestCollisionSensor ${TEST_COLLISION_SENSOR_SOURCES}) 
     36        TARGET_LINK_LIBRARIES(TestCollisionSensor ${TESTS_LIBRARIES}) 
     37 
     38        ADD_TEST(CollisionSensor TestCollisionSensor) 
    2139 
    2240ELSE(USE_SIM2) 
  • trunk/src/waterworld/sim2/IntrusivePtrBase.cpp

    r175 r188  
    1010        { 
    1111                return *this; 
     12        } 
     13 
     14        uintmax_t IntrusivePtrBase::getRefCount() const 
     15        { 
     16                return m_refCount; 
    1217        } 
    1318 
  • trunk/src/waterworld/sim2/PhysicalBody.cpp

    r175 r188  
    1010        } 
    1111 
    12         PhysicalBody::PhysicalBody(boost::intrusive_ptr<Animat> animat) : 
     12        PhysicalBody::PhysicalBody(Animat *animat) : 
    1313                m_animat(animat), 
    1414                m_body(NULL) 
     
    3737        */ 
    3838 
    39         boost::intrusive_ptr<Animat> PhysicalBody::getAnimat() const 
     39        Animat *PhysicalBody::getAnimat() const 
    4040        { 
    4141                return m_animat; 
    4242        } 
    4343 
    44         void PhysicalBody::setAnimat(boost::intrusive_ptr<Animat> newAnimat) 
     44        void PhysicalBody::setAnimat(Animat *newAnimat) 
    4545        { 
    4646                m_animat = newAnimat; 
  • trunk/src/waterworld/sim2/World.cpp

    r186 r188  
    4242                        return g_pcd; 
    4343                } 
     44                 
     45                static void cleanupPhysics() 
     46                { 
     47                        PF->Cleanup(); 
     48                        g_pcd = NULL; 
     49                        g_physics = NULL; 
     50                } 
    4451        } 
    4552 
     
    7279        boost::intrusive_ptr<World> World::createWorld() 
    7380        { 
    74                 initPhysics(); 
     81                if(g_physics==NULL) 
     82                        initPhysics(); 
    7583                return new World(); 
    7684        } 
     
    104112                Radius radius, Mass mass, Position p) 
    105113        { 
    106                 boost::intrusive_ptr<PhysicalBody> body = new PhysicalBody(animat); 
     114                boost::intrusive_ptr<PhysicalBody> body = new PhysicalBody(animat.get()); 
    107115                palSphere *sphere = PF->CreateSphere(); 
    108116                sphere->Init(p(0),p(1),p(2),radius,mass); 
     
    122130        } 
    123131 
     132        void World::removeAnimatsBody(boost::intrusive_ptr<Animat> animat) 
     133        { 
     134                animat->setPhysicalBody(NULL); 
     135        } 
     136 
     137        void World::removeAnimat(boost::intrusive_ptr<Animat> animat) 
     138        { 
     139                m_animats.erase(animat); 
     140                removeAnimatsBody(animat); 
     141        } 
     142 
    124143        World::~World() 
    125144        { 
    126145                stopEventsThread(); 
    127                 PF->Cleanup(); 
     146                cleanupPhysics(); 
    128147        } 
    129148}