00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 #include <thread.h>
00025 #include <math.h>
00026 #include <socket.h>
00027 #include "world.h"
00028 #include "graphicClient.h"
00029 #include "log.h"
00030 #include "cylinder.h"
00031 #include "agent.h"
00032 
00033 GraphicClient::GraphicClient(ost::TCPSocket &sock, World *w) : baseClient(sock, w){
00034   ;
00035 }
00036 
00037 void GraphicClient::Run(void){
00038   log <<"Running new Graphic Client"<<endl;
00039 
00040   bool quit=false;
00041   while(!quit){
00042     
00043     if (stream->isPending(ost::SOCKET_PENDING_INPUT,0)){
00044       string st;
00045       *stream >> st;
00046       if (st==""){
00047     quit=true;
00048     continue;
00049       }
00050       else if (st=="BYE"){
00051     quit=true;
00052     continue;
00053       }
00054 
00055       float a,b,c,d,e,f;
00056       int n=sscanf(st.data(),"(%g, %g, %g)(%g, %g, %g)",&a,&b,&c,&d,&e,&f);
00057       if (n!=6){
00058     log <<"Not valid vectors for graphicClient ("<<st.data()<<")"<<endl;
00059     continue;
00060       }
00061 
00062       unsigned int j;
00063       for (j=world->getNumCylinders();j--;){
00064     Cylinder *cyl=world->getCylinder(j);
00065     if (NULL!=cyl){
00066       *stream <<(cyl->getPosition()).toString()
00067           <<Vector3d(cyl->getWidth(),cyl->getHeight(),cyl->getEnergy()/cyl->getMass()).toString()
00068           <<cyl->getOrientation().toString()<<endl;
00069     }
00070       }
00071       
00072       *stream <<"OK"<<endl;
00073       stream->flush();
00074 
00075     }
00076     dontWalk();
00077   }
00078 
00079   log <<"End of Graphic Client"<<endl;
00080   alive=false;
00081 }