Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

world.h

Go to the documentation of this file.
00001 /*
00002   svas_server -- virtual World Server of Svas
00003   Copyright (c) 2001, 2002 David Moreno Montero
00004  
00005  
00006   This program is free software; you can redistribute it and/or modify
00007   it under the terms of the GNU General Public License as published by
00008   the Free Software Foundation; either version 2 of the License, or
00009   (at your option) any later version.
00010  
00011   This program is distributed in the hope that it will be useful, but
00012   WITHOUT ANY WARRANTY; without even the implied warranty of
00013   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014   General Public License for more details.
00015  
00016   You should have received a copy of the GNU General Public License
00017   along with this program; if not, write to the Free Software
00018   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019   02111-1307, USA.  
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  * The world where the agents live in. The world have agents, and the
00055  * agents are composed of cylinders. The world have size limits (or
00056  * not).
00057  */
00058 class World{
00059  protected:
00060   /// The agents that are in this world 
00061   vector<Agent *> agents;
00062   /// Some cylinders are not attached to agents, as the energy
00063   /// cylinders, and those on the ground
00064   vector<Cylinder *> cylinders;
00065   /// The limits of this world. 
00066   BoundingBox bbox;
00067   ///   If I want to destroy this world
00068   bool quit;
00069   /// The commCenter that communicates this world
00070   CommCenter *commCenter;
00071   /// The messages that are in the air in current cycle
00072   vector<MessageAir> messages;
00073 
00074   /**
00075    * @name some constants of this universe
00076    * @{
00077    */
00078   /// gravity of this world
00079   static double gravity;
00080   /// Linear drag coefficient
00081   static double linearDragCoefficient;
00082   /// Angular drag coefficient
00083   static double angularDragCoefficient;
00084   /// Ground restitution coefficient
00085   static double groundRestitutionCoefficient;
00086   /// Ground friction coefficient
00087   static double groundFrictionCoefficient;
00088   /// Spring coefficient (glue)
00089   static double springCoefficient;
00090   /// Damper coefficient (resistance to union/separation in glue)
00091   static double damperCoefficient;
00092   /** @} */
00093 
00094  public:
00095   /// Creates a world that is contained in the bounding box
00096   World(CommCenter *_commCenter,BoundingBox _bbox=BoundingBox());
00097       
00098 
00099   /// Creates and adds a new agent to the world
00100   void newAgent(Cylinder *cyl, const char *creationMessage, unsigned long int messageSize);
00101   /// Adds a existing agent to this world
00102   void newAgent(Agent *);
00103   /// Delete the agents that depend on this client 
00104   void clientOut(Client *);
00105 
00106   /// Make this world disappear 
00107   void setQuit(){ quit=true; }
00108   /// Do I wanna quit?
00109   bool getQuit(){ return quit; }
00110   /// Get an Agent 
00111   Agent *getAgent(unsigned long int agentId);
00112   /// Get agents in this area
00113   vector<Agent*> getAgents(BoundingBox box=BoundingBox());
00114   /// Get a string with stats about the world
00115   string getStats();
00116   /// Run a time step (move objects...)
00117   void step();
00118   /// Seccond part of step, this is the collision detection/response part
00119   void step(double lowerLimit, double upperLimit);
00120   /// Adds a new cylinder to the cylinders in the world
00121   void addCylinder(Cylinder *);
00122   /// Deletes a new cylinder to the cylinders in the world
00123   void delCylinder(Cylinder *);
00124   /// Adds a message to the air
00125   void addMessage(const char *data, unsigned long int size, Agent *agent){ messages.push_back(MessageAir(data,size,agent)); };
00126 
00127   /// Number of world owned cylinders 
00128   unsigned long int getNumCylinders(){ return cylinders.size(); };
00129   /// Get a world cylinder
00130   Cylinder *getCylinder(unsigned long int i){ return cylinders[i]; };
00131 
00132   /** 
00133    * @name Get some constant properties of the world
00134    * @{
00135    */
00136   /// Get the gravitation of this world
00137   static inline double getGravity(){ return gravity; };
00138   /// Get the linear drag coefficient of this world
00139   static inline double getLinearDragCoefficient(){ return linearDragCoefficient; };
00140   /// Get the angular drag coefficient of this world
00141   static inline double getAngularDragCoefficient(){ return angularDragCoefficient; };
00142   /// Get the coefficient of restitution of ground of this world
00143   static inline double getGroundRestitutionCoefficient(){ return groundRestitutionCoefficient; };
00144   /// Get the coefficient of friction of ground of this world
00145   static inline double getGroundFrictionCoefficient(){ return groundFrictionCoefficient; };
00146   /// Get the coefficient spring (glue)
00147   static inline double getSpringCoefficient(){ return springCoefficient; };
00148   /// Get the coefficient of damper (resistance to motion in glue)
00149   static inline double getDamperCoefficient(){ return damperCoefficient; };
00150 
00151   /** @} */
00152   /// Number of clients to wait for
00153   ost::AtomicCounter numClients;
00154 };
00155 
00156 #endif

Generated on Mon Jun 17 19:53:44 2002 for Svas Server by doxygen1.2.16