Main Page | Modules | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

RoadPlayer.cc

Go to the documentation of this file.
00001 00005 #include <utils/Linear.h> 00006 00007 #include "RoadPlayer.h" 00008 00009 bool RoadPlayer::open(utils::ConfigFile& params, 00010 utils::SymbolTable* globals) 00011 { 00012 // setup the player manager 00013 // the player manager takes care of all of the interactions between the 00014 // data file and the time source 00015 if (!_mgr.open("Road.rad", params, globals)) 00016 return false; 00017 00018 // get the actual canned data reader from the manager 00019 _player = _mgr.getPlayer(); 00020 00021 // clear the input area 00022 memset(&_input_area, 0, sizeof(_input_area)); 00023 00024 // check versions 00025 int major_version = _mgr.getPlayer()->getHeader(). 00026 getInt("int DataFormat.version_major", 1); 00027 int minor_version = _mgr.getPlayer()->getHeader(). 00028 getInt("int DataFormat.version_minor", 1); 00029 // note, you don't have to simply reject other version, you can 00030 // try and adapt here 00031 if (major_version != 1 && minor_version != 0) { 00032 printf("RoadPlayer::init: Cannot read version %d.%d\n", 00033 major_version, minor_version); 00034 return false; 00035 } 00036 00037 // Tell the player to expect the points. We store a reference in _play_elem 00038 // so we can have the player properly manage the memory associated with the 00039 // points. 00040 _play_elem = _player->expect("points", ROAD_DATA_FMT, &_input_area); 00041 00042 // Ready the player for action 00043 return _player->setup(); 00044 } 00045 00046 bool RoadPlayer::advance() 00047 { 00048 // advance the file pointer, if necessary, 00049 // and cache the last read time for later 00050 // the player manager takes care of all the necessary interactions with 00051 // time, i.e., does reading advance time, or do we observe time to see 00052 // where to read. 00053 return _mgr.next(_play_time); 00054 } 00055 00056 bool RoadPlayer::getPoints(utils::Time& time, 00057 std::vector<utils::Vec3d> & points) 00058 { 00059 // transfer input area points 00060 points.clear(); 00061 for (int i=0;i<_input_area.num_points;i++) { 00062 RoadDataPoint& pt = _input_area.points[i]; 00063 points.push_back(utils::Vec3d(pt.x, pt.y, pt.z)); 00064 } 00065 00066 // release point memory back to the player 00067 _player->release(_play_elem); 00068 00069 // and set time from cached value 00070 time = _play_time; 00071 00072 return true; 00073 } 00074 00075 bool RoadPlayer::nextPoints(utils::Time& time, 00076 std::vector<utils::Vec3d> & points, 00077 bool blocking) 00078 { 00079 if (blocking || (!blocking && _mgr.poll())) { 00080 if (!advance()) 00081 return false; 00082 } 00083 return getPoints(time, points); 00084 } 00085 00086

Generated on Tue Sep 7 20:37:49 2004 for ModUtils by doxygen 1.3.8