00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __WORLD_H__
00024 #define __WORLD_H
00025
00026 #include <thread.h>
00027 #include <vector>
00028 #include "log.h"
00029 #include "boundingbox.h"
00030
00031
00032 class Client;
00033 class Agent;
00034 class Cylinder;
00035 class CommCenter;
00036
00037 class MessageAir{
00038 public:
00039 char *data;
00040 unsigned long int size;
00041 Agent *agent;
00042
00043 MessageAir(const char *_data, unsigned long int _size, Agent *_agent){
00044 data=new char[_size]; memcpy(data,_data, _size);
00045 size=_size; agent=_agent;
00046 }
00047
00048 ~MessageAir(){
00049 if (NULL!=data) delete data;
00050 }
00051 };
00052
00053
00054
00055
00056
00057
00058 class World{
00059 protected:
00060
00061 vector<Agent *> agents;
00062
00063
00064 vector<Cylinder *> cylinders;
00065
00066 BoundingBox bbox;
00067
00068 bool quit;
00069
00070 CommCenter *commCenter;
00071
00072 vector<MessageAir> messages;
00073
00074
00075
00076
00077
00078
00079 static double gravity;
00080
00081 static double linearDragCoefficient;
00082
00083 static double angularDragCoefficient;
00084
00085 static double groundRestitutionCoefficient;
00086
00087 static double groundFrictionCoefficient;
00088
00089 static double springCoefficient;
00090
00091 static double damperCoefficient;
00092
00093
00094 public:
00095
00096 World(CommCenter *_commCenter,BoundingBox _bbox=BoundingBox());
00097
00098
00099
00100 void newAgent(Cylinder *cyl, const char *creationMessage, unsigned long int messageSize);
00101
00102 void newAgent(Agent *);
00103
00104 void clientOut(Client *);
00105
00106
00107 void setQuit(){ quit=true; }
00108
00109 bool getQuit(){ return quit; }
00110
00111 Agent *getAgent(unsigned long int agentId);
00112
00113 vector<Agent*> getAgents(BoundingBox box=BoundingBox());
00114
00115 string getStats();
00116
00117 void step();
00118
00119 void step(double lowerLimit, double upperLimit);
00120
00121 void addCylinder(Cylinder *);
00122
00123 void delCylinder(Cylinder *);
00124
00125 void addMessage(const char *data, unsigned long int size, Agent *agent){ messages.push_back(MessageAir(data,size,agent)); };
00126
00127
00128 unsigned long int getNumCylinders(){ return cylinders.size(); };
00129
00130 Cylinder *getCylinder(unsigned long int i){ return cylinders[i]; };
00131
00132
00133
00134
00135
00136
00137 static inline double getGravity(){ return gravity; };
00138
00139 static inline double getLinearDragCoefficient(){ return linearDragCoefficient; };
00140
00141 static inline double getAngularDragCoefficient(){ return angularDragCoefficient; };
00142
00143 static inline double getGroundRestitutionCoefficient(){ return groundRestitutionCoefficient; };
00144
00145 static inline double getGroundFrictionCoefficient(){ return groundFrictionCoefficient; };
00146
00147 static inline double getSpringCoefficient(){ return springCoefficient; };
00148
00149 static inline double getDamperCoefficient(){ return damperCoefficient; };
00150
00151
00152
00153 ost::AtomicCounter numClients;
00154 };
00155
00156 #endif