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

world.hxx

Go to the documentation of this file.
00001 //  $Id: world.hxx,v 1.20 2003/01/10 20:44:09 grumbel Exp $
00002 // 
00003 //  Construo - A wire-frame construction game
00004 //  Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU 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  02111-1307, USA.
00019 
00020 #ifndef HEADER_CONSTRUO_WORLD_HXX
00021 #define HEADER_CONSTRUO_WORLD_HXX
00022 
00023 #include <vector>
00024 #include "spring.hxx"
00025 #include "particle.hxx"
00026 #include "collider.hxx"
00027 
00028 class Particle;
00029 class ParticleFactory;
00030 class Spring;
00031 
00032 struct WorldBoundingBox
00033 {
00034   float x1;
00035   float y1;
00036   float x2;
00037   float y2;
00038 };
00039 
00041 class World
00042 {
00043 public:
00044   typedef std::vector<Collider*> Colliders;
00045   typedef std::vector<Spring*>::iterator SpringIter;
00046   typedef std::vector<Spring*>::const_iterator CSpringIter;
00047 private:
00049   unsigned int file_version;
00050 
00051   friend class ParticleFactory;
00052   bool has_been_run;
00053   ParticleFactory* particle_mgr;
00054 
00055   std::vector<Spring*> springs;
00056 
00057   Colliders colliders;
00058 
00059   void parse_scene (lisp_object_t* lst);
00060   void parse_springs (lisp_object_t* lst);
00061   void parse_particles (lisp_object_t* lst);
00062   void parse_colliders (lisp_object_t* lst);
00063 
00064 public:
00066   World ();
00067 
00069   World (const World& w);
00070 
00072   World (const std::string& filename);
00073   ~World ();
00074 
00075   void draw (ZoomGraphicContext* gc);
00076   void draw_springs (ZoomGraphicContext* gc);
00077   void draw_colliders (ZoomGraphicContext* gc);
00078   void draw_particles (ZoomGraphicContext* gc);
00079 
00080   void update (float delta);
00081 
00082   World* duplicate () { return new World (*this); }
00083 
00085   Particle* get_particle (float x, float y);
00087   std::vector<Particle*> get_particles (float x1, float y1, float x2, float y2);
00088   Spring*   get_spring (float x, float y);
00089 
00090   void add_rect_collider(const Vector2d&, const Vector2d&);
00091   void add_spring (Particle*, Particle*);
00092 
00094   void remove_particle (Particle*);
00095 
00097   void remove_spring (Spring*);
00098 
00099   void remove_collider (Collider*);
00100 
00101   ParticleFactory* get_particle_mgr() { return particle_mgr; }
00102   std::vector<Spring*>& get_spring_mgr () { return springs; }
00103   Colliders& get_colliders() { return colliders; }
00104 
00106   void clear ();
00107   
00108   bool get_has_been_run () { return has_been_run; }
00109 
00113   void zero_out_velocity ();
00114 
00115   void write_lisp (const std::string& filename);
00116 
00117   int get_num_particles();
00118   int get_num_springs();
00119 
00120   WorldBoundingBox calc_bounding_box();
00121 private:
00122   static World* current_world;
00123 public:
00125   static World* current() { return current_world; }
00126 private:
00127   World& operator= (const World&);
00128 };
00129 
00130 #endif
00131 
00132 /* EOF */

Generated on Thu Jul 24 10:24:31 2003 for Construo by doxygen1.3-rc3

Rabisu Mirror Service We provide mirrors to support Open source communities. Our mirror server is located in Istanbul/Turkey region.

Please do not hesitate to contact mirror@rabisu.com for new open source mirror submissions.