30 #include <boost/thread.hpp>
31 #include <boost/enable_shared_from_this.hpp>
32 #include <boost/shared_ptr.hpp>
63 class World :
public boost::enable_shared_from_this<World>
69 public:
explicit World(
const std::string &_name =
"");
78 public:
void Load(sdf::ElementPtr _sdf);
84 public:
void Save(
const std::string &_filename);
96 public:
void Run(
unsigned int _iterations = 0);
113 public:
void Clear();
117 public: std::string
GetName()
const;
156 public:
void Reset();
262 public: std::string
StripWorldName(
const std::string &_name)
const;
284 public:
void LoadPlugin(
const std::string &_filename,
285 const std::string &_name,
286 sdf::ElementPtr _sdf);
295 {
return this->setWorldPoseMutex;}
300 {
return this->enablePhysicsEngine;}
305 {this->enablePhysicsEngine = _enable;}
328 private:
ModelPtr GetModelById(
unsigned int _id);
334 private:
void LoadPlugins();
339 private:
void LoadEntities(sdf::ElementPtr _sdf,
BasePtr _parent);
360 private:
void RunLoop();
363 private:
void Step();
366 private:
void LogStep();
369 private:
void Update();
373 private:
void OnPause(
bool _p);
376 private:
void OnStep();
380 private:
void OnControl(ConstWorldControlPtr &_data);
384 private:
void OnRequest(ConstRequestPtr &_msg);
388 private:
void SetSelectedEntityCB(
const std::string &_name);
394 private:
void BuildSceneMsg(msgs::Scene &_scene,
BasePtr _entity);
398 private:
void JointLog(ConstJointPtr &_msg);
402 private:
void OnFactoryMsg(ConstFactoryPtr &_data);
406 private:
void OnModelMsg(ConstModelPtr &_msg);
409 private:
void ModelUpdateTBB();
412 private:
void ModelUpdateSingleLoop();
416 private:
void LoadPlugin(sdf::ElementPtr _sdf);
421 private:
void FillModelMsg(msgs::Model &_msg,
ModelPtr _model);
425 private:
void ProcessEntityMsgs();
429 private:
void ProcessRequestMsgs();
433 private:
void ProcessFactoryMsgs();
438 private:
void RemoveModel(
const std::string &_name);
442 private:
void ProcessModelMsgs();
445 private:
bool OnLog(std::ostringstream &_stream);
448 private:
void ProcessMessages();
451 private:
void PublishWorldStats();
454 private:
void LogWorker();
469 private: boost::thread *thread;
478 private: std::string name;
493 private:
int stepInc;
544 private: msgs::WorldStatistics worldStatsMsg;
547 private: msgs::Scene sceneMsg;
550 private: void (
World::*modelUpdateFunc)();
562 private: boost::recursive_mutex *receiveMutex;
565 private: boost::mutex *loadModelMutex;
571 private: boost::mutex *setWorldPoseMutex;
579 private: boost::recursive_mutex *worldUpdateMutex;
582 private: sdf::ElementPtr sdf;
585 private: std::vector<WorldPluginPtr> plugins;
588 private: std::list<std::string> deleteEntity;
596 private: std::list<msgs::Request> requestMsgs;
599 private: std::list<msgs::Factory> factoryMsgs;
602 private: std::list<msgs::Model> modelMsgs;
605 private:
bool needsReset;
608 private:
bool resetAll;
611 private:
bool resetTimeOnly;
614 private:
bool resetModelOnly;
617 private:
bool initialized;
620 private:
bool loaded;
623 private:
bool enablePhysicsEngine;
629 private:
bool pluginsLoaded;
641 private: std::deque<WorldState> states[2];
644 private:
int currentStateBuffer;
647 private:
int stateToggle;
649 private: sdf::ElementPtr logPlayStateSDF;
654 private: sdf::SDFPtr factorySDF;
657 private: std::set<ModelPtr> publishModelPoses;
663 private: uint64_t iterations;
666 private: uint64_t stopIterations;
669 private: boost::condition_variable logCondition;
673 private: boost::condition_variable logContinueCondition;
676 private: uint64_t logPrevIteration;
682 private: boost::mutex logMutex;
685 private: boost::mutex logBufferMutex;
688 private: boost::mutex entityDeleteMutex;
691 private: boost::thread *logThread;