summaryrefslogtreecommitdiff
path: root/config.h
blob: 46a3cfcdf91ed7d454ffe7ad7aeeb2edf8ff7731 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
//
//  glgrav - OpenGL N-Body gravity simulator
//
//  Copyright (C) 2003  Ian Cowburn (ianc@noddybox.demon.co.uk)
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//  -------------------------------------------------------------------------
//
//  Data file handling
//
// $Id$
//
#ifndef CONFIG_H

#define CONFIG_H

#include "global.h"
#include <fstream>
#include "mass.h"

class Config
    {
    public:
	enum Flag {solid, lighting, texture, fog, num_flags};
	enum Collide {none, merge, delta_merge, shatter};

    	Config();
	virtual ~Config();

	// Note that the vector is added to.  It must be cleared beforehand
	// if required.
	//
	bool read(const string& file, vector<Mass>& mass);

	void getCamera(GLfloat& x, GLfloat& y, GLfloat& z, GLfloat& yaw) const;

	bool enabled(Flag flag) const;
	Collide collide() const;
	string light(GLfloat v[4]) const;
	double gravConst() const;
	double scale() const;

	void windowSize(int& w,int& h) const;

	void getShatter(int& num, double& delta,
			double& min_mass, double& max_mass,
			int& shield) const;

	bool sparksDefined() const;

    	void getSparks(int& num, GLfloat& alpha_dec, GLfloat& alpha_min,
		       int& length, GLfloat& delta) const;

	size_t maxMass() const;

	// Args set to -1 if undefined
	//
	void getLookAndTravel(int& look, int &travel) const;

	bool particlesDefined() const;

	void getParticles(GLfloat& alpha_dec, GLfloat& alpha_min,
			  GLfloat& size) const;

	void getFog(GLfloat& dist, GLfloat& r, GLfloat& g, GLfloat& b,
		    bool& fog_light);

	void look(vector<string>& l) const;

	string error() const;

    private:
	enum Plane {xy_plane, xz_plane, yz_plane};

	Plane	m_plane;

    	string	m_error;
	bool	m_flag[num_flags];
	Collide	m_collide;
	double	m_const;
	GLfloat	m_x,m_y,m_z,m_pitch,m_yaw;

	double	m_scale;

	string	m_light;
	GLfloat	m_lr,m_lg,m_lb;

	vector<string>	m_look;
	int	m_look_at;
	int	m_travel_as;

	bool	m_particles;
	GLfloat	m_p_adec;
	GLfloat	m_p_amin;
	GLfloat	m_p_size;

	GLuint	*m_glid;
	int	m_glid_no;
	int	m_glid_idx;

	int	m_s_no;
	double	m_s_delta;
	double	m_s_min;
	double	m_s_max;
	int	m_s_shield;

	bool	m_sparks;
	int	m_sp_no;
	GLfloat	m_sp_adec;
	GLfloat	m_sp_amin;
	int	m_sp_length;
	GLfloat	m_sp_delta;

	int	m_winw;
	int	m_winh;

	size_t	m_max_mass;

	GLfloat	m_fog_dist;
	GLfloat	m_fog_r;
	GLfloat	m_fog_g;
	GLfloat	m_fog_b;
	bool	m_fog_light;

	enum Command {enable_cmd, disable_cmd, collide_cmd, const_cmd,
		      body_cmd, radial_cmd, light_cmd, camera_cmd, look_cmd,
		      texture_cmd, num_texture_cmd, reuse_cmd, particles_cmd,
		      shatter_cmd, multiple_cmd, mreuse_cmd, plane_cmd,
		      scale_cmd, look_at_cmd, travel_as_cmd, window_size_cmd,
		      sparks_cmd, max_mass_cmd, mlook_cmd,
		      ring_cmd, mring_cmd, ring_texture_cmd, ring_reuse_cmd,
		      ring_mreuse_cmd, fog_cmd,
		      cmd_eof, cmd_error};

	enum GetWordStatus {GWOK, GWEof, GWSyntax,
			    GWTooFewArgs, GWTooManyArgs};

	bool CompareNoCase(const string& s1, const string& s2);
	GetWordStatus getWord(ifstream& fp, string& word,
			      const string& ignore, const string& term);
	bool getCommand(ifstream& fp, Command& cmd, vector<string>& val);

	void genRadial(Mass **newMass, const Mass& parent,
		       const string& name, double mass,
		       double dist, double ang, double spd,
		       GLfloat r, GLfloat g, GLfloat b, double rot);

	double toDouble(const string& s);
	GLfloat toGLfloat(const string& s);
	int toInt(const string& s);
	size_t toSize(const string& s);
	bool toYesNo(const string& s);

	bool bindTexture(const string& name, int w, int h, GLuint id);

	string makeName(string& name, int no);
    };

#endif

// END OF FILE //