00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef LUX_RENDERFARM_H
00024 #define LUX_RENDERFARM_H
00025
00026 #include <vector>
00027 #include <string>
00028 #include <sstream>
00029
00030 #include <boost/thread.hpp>
00031 #include <boost/thread/xtime.hpp>
00032
00033 #include "fleximage.h"
00034
00035 namespace lux
00036 {
00037
00038 class RenderFarm;
00039
00040 class FilmUpdaterThread : public boost::noncopyable {
00041 public:
00042 FilmUpdaterThread(RenderFarm *renderFarm, Scene *scene) :
00043 renderFarm(renderFarm), scene(scene), thread(NULL), signal(SIG_NONE) { }
00044
00045 ~FilmUpdaterThread() {
00046 delete thread;
00047 }
00048
00049 void interrupt() {
00050 signal = SIG_EXIT;
00051 thread->join();
00052 }
00053
00054 friend class RenderFarm;
00055 private:
00056 static void updateFilm(FilmUpdaterThread *filmUpdaterThread);
00057
00058 RenderFarm *renderFarm;
00059 Scene *scene;
00060 boost::thread *thread;
00061
00062
00063 int signal;
00064 static const int SIG_NONE = 0;
00065 static const int SIG_EXIT = 1;
00066 };
00067
00068 class RenderFarm {
00069 public:
00070 RenderFarm() : serverUpdateInterval(3*60), filmUpdateThread(NULL) {}
00071 ~RenderFarm() {
00072 if (filmUpdateThread)
00073 delete filmUpdateThread;
00074 }
00075
00076 bool connect(const string &serverName);
00077
00078 void disconnectAll();
00079
00080 void send(const std::string &command);
00081 void send(const std::string &command, const std::string &name, const ParamSet ¶ms);
00082 void send(const std::string &command, const std::string &name);
00083 void send(const std::string &command, float x, float y, float z);
00084 void send(const std::string &command, float a, float x, float y, float z);
00085 void send(const std::string &command, float ex, float ey, float ez, float lx, float ly, float lz, float ux, float uy, float uz);
00086 void send(const std::string &command, float tr[16]);
00087 void send(const std::string &command, const string &name, const string &type, const string &texname, const ParamSet ¶ms);
00088
00090 void flush();
00091
00092 int getServerCount() { return serverList.size(); }
00093
00094
00095 void startFilmUpdater(Scene *scene);
00096 void stopFilmUpdater();
00098 void updateFilm(Scene *scene);
00099
00100 public:
00101
00102 int serverUpdateInterval;
00103
00104 private:
00105 std::vector<std::string> serverList;
00106 std::stringstream netBuffer;
00107
00108
00109 FilmUpdaterThread *filmUpdateThread;
00110 };
00111
00112 }
00113
00114 #endif //LUX_ERROR_H