Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

world.H

Go to the documentation of this file.
00001 #ifndef WORLD_H
00002 #define WORLD_H
00003 
00004 #include "std/support.H"
00005 #include "std/time.H"
00006 #include "geom/geom.H"
00007 #include "geom/command.H"
00008 
00009 class LOADER {
00010    protected:
00011       static LOADER *_all;
00012       LOADER        *_next;
00013       virtual bool try_load(Cstr_ptr &path) = 0;
00014       LOADER();
00015       virtual ~LOADER() {}
00016    public:
00017       static  bool load(Cstr_ptr &path);
00018 };
00019 
00020 
00021 
00022 #define CWORLDptr const WORLDptr
00023 //-----------------------------------------------
00024 // WORLD
00025 //    Top level SCHEDULER, handles UNDO list, messages
00026 //    wraps object create/display/undisplay/deletion,
00027 //-----------------------------------------------
00028 class NetStream;
00029 class RenderThread;
00030 class ThreadSync;
00031 class REF_CLASS(WORLD) : public SCHEDULER {
00032  protected :
00033    static WORLD    *_w;
00034    ARRAY<TTYfd *>   _fds;
00035 
00036    LIST<COMMANDptr> _undoable;
00037    LIST<COMMANDptr> _redoable;
00038 
00039    HASH             _hash;
00040 
00041    static bool _is_over; // set to true during program exit cleanup
00042 
00043 #ifdef USE_PTHREAD
00044    ThreadSync      *_tsync;
00045    RenderThread    *_threads;
00046    bool             _doMultithread;
00047 #endif   
00048 
00049    virtual   void    _add_command(COMMANDptr c);
00050    virtual   void    _undo();
00051    virtual   void    _redo();
00052    virtual   void    _clear_redoable();
00053 
00054    static DATA_ITEM *_default_decoder(STDdstream &, Cstr_ptr &, DATA_ITEM *);
00055 
00056    virtual void  _Message(Cstr_ptr &m, double secs=3,
00057                           mlib::CXYpt &pos=mlib::XYpt(0,.9));
00058    virtual void  _Multi_Message(Cstr_list &m, double secs=3,
00059                                 mlib::CXYpt &pos=mlib::XYpt(0,.9));
00060    //used in _Multi_Message
00061    virtual str_list format_str(Cstr_ptr &str, const int line_length);
00062    virtual int      get_next(Cstr_ptr &str, int loc, char chr);
00063  public:
00064        WORLD();
00065 
00066 static void       set_world     (WORLD    *d) { _w = d; }
00067 static WORLD*     get_world     ()            { return _w; }
00068 static int        world_set     ()            { return _w != 0;}
00069 static void       timer_callback(CFRAMEobsptr &o){_w->schedule(o); }
00070 
00071  static bool       is_over() { return _is_over; }
00072 
00073 //static STROKElist*hash          (Cstr_ptr &t) { return _w->_Hash(t); }
00074 //static void       hash_add      (Cstr_ptr &t, STROKElist*l){_w->_Hash_add(t,l);}
00075 
00076        //!METHS:  wrappers on the EXIST list variable
00077 static GEOMptr lookup (Cstr_ptr &s);
00078 static void       create        (CGELptr &o, bool undoable=true);
00079 static void       destroy       (CGELptr &o, bool undoable=true);
00080 static void       destroy       (CGELlist& gels, bool undoable=true);
00081 
00082 static str_ptr    unique_name   (Cstr_ptr &s) { return EXIST.unique_name(s);}
00083 static str_ptr    unique_dupname(Cstr_ptr &s) { return EXIST.unique_dupname(s);}
00084        //!METHS: wrappers on the DRAWN list variable
00085 static void       display       (CGELptr& o,     bool undoable=true);
00086 static void       display_gels  (CGELlist& gels, bool undoable=true);
00087 static void       undisplay     (CGELptr& o,     bool undoable=true);
00088 static void       undisplay_gels(CGELlist& gels, bool undoable=true);
00089 static int        toggle_display(CGELptr& o,     bool undoable=true); 
00090 
00091 static bool is_displayed(CGELptr& o);
00092 
00093  // For debugging: show locations, lines, etc. graphically:  
00094  // (width is measured in pixels.)
00095  // 
00096  // show a Wpt
00097  static GELptr show(
00098     mlib::CWpt &p, double width=8, CCOLOR& col=COLOR::blue, double alpha=1,
00099     bool depth_test=true
00100     );
00101  // show a set of points in world space
00102  static GELptr show_pts(
00103     mlib::CWpt_list& pts, double width=8.0, CCOLOR& col=COLOR::blue, double alpha=1,
00104     bool depth_test=true
00105     );
00106  // show a line segment:
00107  static GELptr show(
00108     mlib::CWpt& a, mlib::CWpt& b, double width=2, CCOLOR& col=COLOR::blue, double alpha=1,
00109     bool depth_test=true
00110     );
00111  // show a line segment:
00112  static GELptr show(
00113     mlib::CWpt& p, mlib::CWvec& v, double width=2, CCOLOR& col=COLOR::blue, double alpha=1,
00114     bool depth_test=true) {
00115     return show(p, p+v, width, col, alpha, depth_test);
00116  }
00117  // show a polyline in world space
00118  static GELptr show_polyline(
00119     mlib::CWpt_list& pts, double width=2.0, CCOLOR& col=COLOR::blue, double alpha=1,
00120     bool depth_test=true
00121     );
00122 
00123  // show a Wtransf
00124  static GELptr show(mlib::CWtransf& xf, double axis_length=15.0);
00125 
00126 static void message(Cstr_ptr&m, double sec=3.0, mlib::CXYpt&pos=mlib::XYpt(0,.9)) {
00127    _w->_Message(m, sec, pos);
00128 }
00129 static void multi_message(Cstr_list &m, double sec=3.0, mlib::CXYpt&pos=mlib::XYpt(0,.9)) {
00130    _w->_Multi_Message(m, sec, pos);
00131 }
00132 
00133 // Execute a command and add it to the undoable list.
00134 static void    add_command(COMMANDptr c) { _w->_add_command(c); }
00135 
00136 // Undo or redo the last command.
00137 static void    undo() { _w->_undo(); }
00138 static void    redo() { _w->_redo(); }
00139 
00140 static void       Quit          () { _w->quit(); }
00141 static void       Clean_On_Exit () { _is_over = true; if (_w) _w->clean_on_exit();}
00142 
00143 virtual void      clean_on_exit () const;    // pre-quit cleanup
00144 virtual void      quit() const;              // quits program
00145 
00146    //!METHS: objects that are "active"
00147    virtual   void    add_fd  (TTYfd *f)       { _fds.add(f); }
00148 
00149    //!METHS: access all the world's lists
00150           FRAMEobslist &scheduled ()          { return _scheduled; }
00151          CFRAMEobslist &scheduled ()  const   { return _scheduled; }
00152 
00153    virtual void         poll(void);      // poll pollable dev's
00154 
00155    virtual void         draw(void);      // Draw all views
00156 
00157 
00158 #ifdef USE_PTHREAD
00159    //!METHS: thread syncronization
00160    ThreadSync *get_threadsync() { return _tsync; }
00161 #endif
00162 };
00163 
00164 //
00165 // Xfscaler - linearly interpolate between two transforms over time
00166 //
00167 // XXX - need a MAKE_PTR_SUBC macro that works with templated sub-classes
00168 template <class OBJ_TYPE, class OBJ_TYPE_PTR>
00169 class XFscaler : public FRAMEobs
00170 {
00171  protected:
00172    double    _dur;
00173    double    _begin_time;
00174    mlib::Wtransf   _start, _end;
00175    OBJ_TYPE  _obj;
00176 
00177    void (OBJ_TYPE_PTR::*_fptr)(mlib::CWtransf &);
00178 
00179  public:
00180    XFscaler( double dur,
00181              mlib::CWtransf &s,
00182              mlib::CWtransf &e,
00183              OBJ_TYPE obj,
00184              void (OBJ_TYPE_PTR::*fptr)(mlib::CWtransf &)
00185       ) : _dur(dur), _start(s), _end(e), _obj(obj), _fptr(fptr)
00186    {
00187       // install
00188       WORLD::timer_callback(this);
00189       _begin_time = the_time();
00190    }
00191 
00192    virtual int tick() {
00193       double u = clamp((the_time() - _begin_time) / _dur, 0.0, 1.0);
00194 
00195       mlib::Wpt start_o, end_o;
00196       mlib::Wvec start_x, start_y, start_z, end_x, end_y, end_z;
00197       _start.get_coord_system(start_o, start_x, start_y, start_z);
00198       _end.get_coord_system(end_o  , end_x,   end_y,   end_z);
00199 
00200       mlib::Wpt  o = start_o + u*(end_o - start_o);
00201       mlib::Wvec x = start_x + u*(end_x - start_x);
00202       mlib::Wvec y = start_y + u*(end_y - start_y);
00203       mlib::Wvec z = start_z + u*(end_z - start_z);
00204 
00205       mlib::Wtransf mat = mlib::Wtransf::align_and_scale(o,x,y,z);
00206       ((&*_obj)->*_fptr)(mat);
00207 
00208       if (u == 1.0)
00209          return -1;
00210 
00211       return 0;
00212    }
00213 };
00214 #endif

Generated on Mon Sep 18 11:39:34 2006 for jot by  doxygen 1.4.4