Google

Main Page   Class Hierarchy   Compound List   File List   Compound Members  

world.h

00001 /*
00002     Dynamics/Kinematics modeling and simulation library.
00003     Copyright (C) 1999 by Michael Alexander Ewert & Noah Gibbs
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public
00016     License along with this library; if not, write to the Free
00017     Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 */
00020 
00021 #ifndef PHYZ_WORLD_H
00022 #define PHYZ_WORLD_H
00023 
00024 #include "csphyzik/phyztype.h"
00025 #include "csphyzik/entity.h"
00026 #include "csphyzik/phyzent.h"
00027 #include "csphyzik/linklist.h"
00028 #include "csphyzik/odesolve.h"
00029 #include "csphyzik/ctcat.h"
00030 #include "csutil/csdllist.h"
00031 
00032 enum worldstate { CTWS_NORMAL, CTWS_REWOUND };
00033 
00034 enum errorcode { WORLD_NOERR, WORLD_ERR_NULLPARAMETER, WORLD_ERR_NOODE,
00035                  WORLD_ERR_SHITHAPPEND, WORLD_ERR_OTHERSTUFF };
00036 
00037 #define DEFAULT_INIT_MAX_STATE_SIZE  1024
00038 #define STATE_RESIZE_EXTRA 256
00039 
00040 class ctForce;
00041 // State-alloc tracking structure:
00042 class AllocNode
00043 {
00044  public:
00045   int offset;
00046   int size;
00047 };
00048 
00049 class ctWorld : public ctEntity
00050 {
00051 public:
00052 
00053   ctWorld ();
00055   virtual ~ctWorld ();
00056 
00057   void calc_delta_state ( real t, const real y[], real ydot[] );
00058 
00060   errorcode evolve ( real t1, real t2 );
00061 
00066   errorcode rewind ( real t1, real t2 );
00067 
00069   void set_max_time_subdivisions ( long pmt )
00070   { max_time_subdivisions = pmt; }
00071 
00072   void register_catastrophe_manager ( ctCatastropheManager *pcm );
00073 
00074   void solve ( real t );
00075   errorcode add_entity ( ctEntity *pe );
00076   errorcode add_enviro_force ( ctForce *f );
00077 
00078   errorcode delete_entity ( ctEntity *pb );
00079 
00081   void set_ODE_solver ( OdeSolver *pode )
00082   {
00083     if( ode_to_math ) delete ode_to_math;
00084     ode_to_math = pode;
00085   }
00086 
00088   void apply_function_to_body_list ( void(*fcn)( ctEntity *pe ) );
00089 
00095   virtual void dydt_eval (real t, const real y[], real dy[]);
00096 
00098   void resolve_collision ( ctCollidingContact *cont );
00099   ctVector3 get_relative_v
00100    ( ctPhysicalEntity *body_a, ctPhysicalEntity *body_b, const ctVector3 &the_p );
00101 
00102   virtual int get_state_size ()
00103   { return 0; }
00105   virtual int set_state ( real * )
00106   { return 0; }
00108   virtual int get_state ( const real * )
00109   { return 0; }
00111   virtual int set_delta_state ( real * )
00112   { return 0; }
00113 
00115   int state_size;
00116   csDLinkList free_blocks;
00117   csDLinkList used_blocks;
00118 
00120   virtual int  state_alloc (int size);
00121   virtual void state_free (int offset);
00122   virtual int  state_realloc (int offset, int newsize)
00123   {
00124     int newloc = state_alloc(newsize);
00125     if(!newloc) return 0;
00126     // Okay, got state-space -- free old loc, return new one
00127     state_free(offset);
00128     return newloc;
00129   }
00130 
00132 
00138   AllocNode *sa_make_unused (int offset);
00139 
00144   bool sa_make_used (AllocNode *block);
00145 
00146 protected:
00148   errorcode do_time_step( real t1, real t2 );
00149 
00154   void load_state ( real *state_array );
00155 
00161   void reintegrate_state ( const real *state_array );
00162 
00164   void load_delta_state ( real *state_array );
00165 
00166   void init_state ();
00167 
00168   void collide ();
00169 
00170   void resize_state_vector ( long new_size );
00171 
00173   worldstate fsm_state;
00174   real rewound_from;
00175 
00176   ctLinkList<ctEntity> body_list;
00177   ctLinkList<ctForce> enviro_force_list;
00178   ctLinkList<ctCatastropheManager> catastrophe_list;
00179 
00181   OdeSolver *ode_to_math;
00182 
00184 
00186   real *y_save;
00187   real *y0;
00188   real *y1;
00189 
00192   bool was_catastrophe_last_frame;
00193 
00195   long max_time_subdivisions;
00196 
00197   long y_save_size;
00198   long max_state_size;
00199 };
00200 
00201 
00202 #endif

Generated for Crystal Space by doxygen 1.2.5 written by Dimitri van Heesch, ©1997-2000