1 // $Id: world.hxx,v 1.23 2003/07/27 18:46:11 grumbel Exp $
3 // Construo - A wire-frame construction game
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #ifndef HEADER_CONSTRUO_WORLD_HXX
21 #define HEADER_CONSTRUO_WORLD_HXX
25 #include "particle.hxx"
26 #include "collider.hxx"
27 #include "bounding_box.hxx"
30 class ParticleFactory
;
33 /** This class holds all particles and springs */
37 typedef std::vector
<Collider
*> Colliders
;
38 typedef std::vector
<Spring
*>::iterator SpringIter
;
39 typedef std::vector
<Spring
*>::const_iterator CSpringIter
;
41 /** Version number of the file, used to ensure backward compability */
42 unsigned int file_version
;
44 friend class ParticleFactory
;
46 ParticleFactory
* particle_mgr
;
48 std::vector
<Spring
*> springs
;
52 void parse_scene (lisp_object_t
* lst
);
53 void parse_springs (lisp_object_t
* lst
);
54 void parse_particles (lisp_object_t
* lst
);
55 void parse_colliders (lisp_object_t
* lst
);
58 /** Create an empty world */
61 /** Copy an existing world */
62 World (const World
& w
);
64 /** load a world from file */
65 World (const std::string
& filename
);
68 void draw (ZoomGraphicContext
* gc
);
69 void draw_springs (ZoomGraphicContext
* gc
);
70 void draw_colliders (ZoomGraphicContext
* gc
);
71 void draw_particles (ZoomGraphicContext
* gc
);
73 void update (float delta
);
75 World
* duplicate () { return new World (*this); }
77 /** @return the particles closed to the given coordinates */
78 Particle
* get_particle (float x
, float y
);
79 /** All particles inside the given rectangle */
80 std::vector
<Particle
*> get_particles (float x1
, float y1
, float x2
, float y2
);
81 Spring
* get_spring (float x
, float y
);
83 void add_rect_collider(const Vector2d
&, const Vector2d
&);
84 void add_spring (Particle
*, Particle
*);
86 /** removes the given particle and all objects/springs which
88 void remove_particle (Particle
*);
90 /** remove the given spring */
91 void remove_spring (Spring
*);
93 /** Remove the gives collider from the world */
94 void remove_collider (Collider
*);
96 ParticleFactory
* get_particle_mgr() { return particle_mgr
; }
97 std::vector
<Spring
*>& get_spring_mgr () { return springs
; }
98 Colliders
& get_colliders() { return colliders
; }
100 /** removes everything from the world */
103 bool get_has_been_run () { return has_been_run
; }
105 /** Sets the velocity of all particles to zero, usefull if the
106 particles are getting out of order (aka. explode). Also usefull
107 to fix broken model files */
108 void zero_out_velocity ();
110 /** Write the current world down to a file */
111 void write_lisp (const std::string
& filename
);
113 /** @return the number of particles in the world */
114 int get_num_particles();
116 /** @return the number of springs in the world */
117 int get_num_springs();
119 /** Callculate the bounding box of the world from the particle and
120 * collider it contains. */
121 BoundingBox
calc_bounding_box();
123 static World
* current_world
;
125 /** @return pointer to the current world */
126 static World
* current() { return current_world
; }
128 World
& operator= (const World
&);