~ubuntu-branches/ubuntu/natty/gav/natty

« back to all changes in this revision

Viewing changes to Configuration.h

  • Committer: Bazaar Package Importer
  • Author(s): Ari Pollak
  • Date: 2006-05-27 17:49:14 UTC
  • mfrom: (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060527174914-3hgcv8ov8y6hbqpb
Tags: 0.9.0-1
* New upstream release
  - Now saves settings between games (Closes: #261197)

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
/* Configuration options */
24
24
 
 
25
#include <string>
 
26
#include <sstream>
 
27
#include "aarg.h"
 
28
 
25
29
#ifndef __CONFIGURATION_H__
26
30
#define __CONFIGURATION_H__
27
31
 
28
 
#define MAX_PLAYERS (12)
29
 
#define FPS (50)
30
 
#define WINNING_SCORE (15)
 
32
#define MAX_PLAYERS (4)
 
33
#define DEFAULT_FPS (50)
 
34
#define DEFAULT_WINNING_SCORE (15)
31
35
 
32
36
#define DEFAULT_BALL_AMPLIFY 5
33
37
 
 
38
#define DEFAULT_FRAME_SKIP 0
 
39
 
 
40
#define DEFAULT_THEME "classic"
 
41
 
 
42
#define DEFAULT_FULLSCREEN false
 
43
 
 
44
#define DEFAULT_SOUND true
 
45
 
34
46
#define DEFAULT_NPLAYERFRAMES 4
35
47
#define DEFAULT_PLAYERSTILLB  1
36
48
#define DEFAULT_PLAYERSTILLE  1
45
57
#define DEFAULT_NBALLFRAMES   4
46
58
#define DEFAULT_BALLPERIOD    1000
47
59
 
 
60
#define BALL_SPEED_INC        3
 
61
 
 
62
#define DEFAULT_CONF_FILENAME     ".gav"
 
63
#define ALTERNATIVE_CONF_FILENAME "gav.ini"
 
64
 
 
65
#define ENVIRONMENT_WIDTH  (640)
 
66
#define ENVIRONMENT_HEIGHT (400)
 
67
 
 
68
#define BIG_ENVIRONMENT_WIDTH  (1000)
 
69
#define BIG_ENVIRONMENT_HEIGHT (400)
 
70
 
 
71
 
48
72
enum { PLAYER_NONE, PLAYER_HUMAN, PLAYER_COMPUTER};
49
73
enum { MONITOR_NORMAL, MONITOR_OLD, MONITOR_VERYOLD, MONITOR_VERYVERYOLD};
50
74
 
66
90
  unsigned short ballPeriod;
67
91
} BallFrameConf_t;
68
92
 
 
93
typedef struct Resolution_s {
 
94
  unsigned short x;
 
95
  unsigned short y;
 
96
  float ratioX;
 
97
  float ratioY;
 
98
} Resolution_t;
 
99
 
 
100
typedef struct Environment_s {
 
101
  unsigned short w;
 
102
  unsigned short h;
 
103
} Environment_t;
 
104
 
69
105
class Configuration {
70
106
public:
71
107
  int left_nplayers;
74
110
  int right_players[MAX_PLAYERS/2];
75
111
  PlayerFrameConf_t playerFrameConf;
76
112
  BallFrameConf_t ballFrameConf;
77
 
 
 
113
  Resolution_t resolution;
 
114
  Resolution_t desiredResolution;
 
115
  Environment_t env;
 
116
  std::string currentTheme;
 
117
  
 
118
  /* Constants that depend on the screen size */
 
119
  int SCREEN_WIDTH;
 
120
  int SCREEN_HEIGHT;
 
121
  float SPEEDY;
 
122
  int FLOOR_ORD;
 
123
  int SPEED_MULTIPLIER;
 
124
  int NET_X;
 
125
  int NET_Y;
 
126
  int CEILING;
 
127
  int LEFT_WALL;
 
128
  int RIGHT_WALL;
 
129
  int DEFAULT_SPEED;
78
130
 
79
131
  /* To add: something meaningful to record the controls... */
80
132
 
81
 
  int sound;
 
133
  bool sound;
82
134
  int winning_score;
83
135
 
84
136
  int monitor_type;
87
139
  unsigned int fps;            // fps of the update (not graphical)
88
140
  unsigned int mill_per_frame; // caches the # of msecs per frame (1000/fps)
89
141
  bool bgBig;                  // if the background is big
 
142
  bool fullscreen;
90
143
  unsigned int ballAmplify;
91
144
 
92
145
  Configuration() : left_nplayers(1), right_nplayers(1),
93
 
                    sound(1), winning_score(WINNING_SCORE) {
 
146
                    sound(DEFAULT_SOUND),
 
147
                    winning_score(DEFAULT_WINNING_SCORE) {
94
148
    monitor_type = MONITOR_NORMAL;
95
 
    frame_skip = 0;
96
 
    fps = FPS;
 
149
    frame_skip = DEFAULT_FRAME_SKIP;
 
150
    fps = DEFAULT_FPS;
97
151
    mill_per_frame = 1000 / fps;
98
152
    left_players[0] = PLAYER_HUMAN;
99
153
    right_players[0] = PLAYER_COMPUTER;
102
156
      right_players[i] = PLAYER_NONE;
103
157
    }
104
158
    bgBig = false;
 
159
    fullscreen = DEFAULT_FULLSCREEN;
105
160
    ballAmplify = DEFAULT_BALL_AMPLIFY;
106
161
    setDefaultFrameConf();
 
162
    currentTheme = "classic";
 
163
    scaleFactors(ENVIRONMENT_WIDTH, ENVIRONMENT_HEIGHT);
 
164
    env.w = ENVIRONMENT_WIDTH;
 
165
    env.h = ENVIRONMENT_HEIGHT;
 
166
    setDesiredResolution(ENVIRONMENT_WIDTH, ENVIRONMENT_HEIGHT);
 
167
    setResolution(ENVIRONMENT_WIDTH, ENVIRONMENT_HEIGHT);
 
168
  }
 
169
 
 
170
  void scaleFactors(int width, int height) {
 
171
    SCREEN_WIDTH = width;
 
172
    SCREEN_HEIGHT = height;
 
173
    SPEEDY = ((float) SCREEN_HEIGHT / 2.5);
 
174
    FLOOR_ORD = SCREEN_HEIGHT -(SCREEN_HEIGHT / 200);
 
175
    NET_X = width / 2 - width / 80;
 
176
    NET_Y = height / 2 + ( 3*height / 200 );
 
177
    CEILING = (int) (height / 17);
 
178
    LEFT_WALL = (int) (width / 80);
 
179
    RIGHT_WALL = (int) (width - width / 40);
 
180
    DEFAULT_SPEED = (int) (bgBig)?(width/4):(25*width/64);
 
181
  }
 
182
 
 
183
  inline void setResolution(int w, int h) {
 
184
    resolution.x = w;
 
185
    resolution.y = h;
 
186
    resolution.ratioX = (float) resolution.x / (float) env.w;
 
187
    resolution.ratioY = (float) resolution.y / (float) env.h;
 
188
  }
 
189
 
 
190
  inline void setResolutionToDesired() {
 
191
    setResolution(desiredResolution.x, desiredResolution.y);
 
192
  }
 
193
 
 
194
  inline void setDesiredResolution(int w, int h) {
 
195
    desiredResolution.x = w;
 
196
    desiredResolution.y = h;
 
197
    desiredResolution.ratioX = (float) desiredResolution.x / (float) env.w;
 
198
    desiredResolution.ratioY = (float) desiredResolution.y / (float) env.h;
107
199
  }
108
200
 
109
201
  inline void setDefaultFrameConf() {
126
218
    fps = val;
127
219
    mill_per_frame = 1000 / val;
128
220
  }
 
221
 
 
222
  std::string toString(int v) {
 
223
    std::ostringstream os;
 
224
    
 
225
    os << v;
 
226
    
 
227
    return os.str();
 
228
  }
 
229
 
 
230
  int loadConfiguration();
 
231
  int saveConfiguration(std::string fname);
 
232
  int createConfigurationFile();
 
233
  std::string confFileName();
 
234
  //void scaleFactors(int width, int height);
129
235
};
130
236
 
131
237
#endif