~evan-nelson/armagetronad/armagetronad+pcm

« back to all changes in this revision

Viewing changes to src/render/rViewport.cpp

Attempting to create a timeout for PLAYER_CENTER_MESSAGE.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 
3
 
*************************************************************************
4
 
 
5
 
ArmageTron -- Just another Tron Lightcycle Game in 3D.
6
 
Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
7
 
 
8
 
**************************************************************************
9
 
 
10
 
This program is free software; you can redistribute it and/or
11
 
modify it under the terms of the GNU General Public License
12
 
as published by the Free Software Foundation; either version 2
13
 
of the License, or (at your option) any later version.
14
 
 
15
 
This program is distributed in the hope that it will be useful,
16
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
GNU General Public License for more details.
19
 
 
20
 
You should have received a copy of the GNU General Public License
21
 
along with this program; if not, write to the Free Software
22
 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 
  
24
 
***************************************************************************
25
 
 
26
 
*/
27
 
 
28
 
#include "rFont.h"
29
 
#include "rScreen.h"
30
 
#include "rViewport.h"
31
 
#include "rConsole.h"
32
 
#include "tConfiguration.h"
33
 
 
34
 
#ifndef DEDICATED
35
 
#include "rGL.h"
36
 
//#include <GL/glu>
37
 
#ifdef POWERPAK_DEB
38
 
#include "PowerPak/powerdraw.h"
39
 
#endif
40
 
#endif
41
 
 
42
 
#ifndef DEDICATED
43
 
void rViewport::Select(){
44
 
    if (sr_glOut)
45
 
        glViewport (GLsizei(sr_screenWidth*left),
46
 
                    GLsizei(sr_screenHeight*bottom),
47
 
                    GLsizei(sr_screenWidth*width),
48
 
                    GLsizei(sr_screenHeight*height));
49
 
}
50
 
#endif
51
 
 
52
 
 
53
 
REAL rViewport::UpDownFOV(REAL fov){
54
 
    REAL ratio=currentScreensetting.aspect*(width*sr_screenWidth)/(height*sr_screenHeight);
55
 
 
56
 
    // clamp ratio to 5/3
57
 
    REAL maxratio = 5.0/3.0;
58
 
    if (ratio > maxratio)
59
 
        ratio = maxratio;
60
 
 
61
 
    return 360*atan(tan(M_PI*fov/360)/ratio)/M_PI;
62
 
}
63
 
 
64
 
void rViewport::Perspective(REAL fov,REAL nnear,REAL ffar){
65
 
#ifndef DEDICATED
66
 
    if (!sr_glOut)
67
 
        return;
68
 
 
69
 
    // Jonathan's improved version
70
 
    REAL aspectratio = (height * sr_screenHeight) / (width * sr_screenWidth * currentScreensetting.aspect);
71
 
    REAL ensureverticalfov = fmax((3.0 / 5.0) * aspectratio, 1.0);
72
 
    REAL xmul = ensureverticalfov * tan((M_PI / 360.0) * fov);
73
 
    REAL ymul = ensureverticalfov * aspectratio * xmul;
74
 
    glMatrixMode(GL_PROJECTION);
75
 
    glFrustum(-nnear * xmul, nnear * xmul, -nnear * ymul, nnear * ymul, nnear, ffar);
76
 
 
77
 
#if 0 // Z-Man's old and clumsy version
78
 
    REAL ratio=currentScreensetting.aspect*(width*sr_screenWidth)/(height*sr_screenHeight);
79
 
    // REAL udfov=360*atan(tan(M_PI*fov/360)/ratio)/M_PI;
80
 
    REAL udfov=UpDownFOV(fov);
81
 
    glMatrixMode(GL_PROJECTION);
82
 
    gluPerspective(
83
 
        udfov,
84
 
        ratio,
85
 
        nnear,
86
 
        ffar
87
 
    );
88
 
#endif
89
 
 
90
 
#endif
91
 
}
92
 
 
93
 
rViewport rViewport::s_viewportFullscreen(0,0,1,1);
94
 
 
95
 
rViewport rViewport::s_viewportTop(0,.5,1,.5);
96
 
rViewport rViewport::s_viewportBottom(0,0,1,.5);
97
 
 
98
 
rViewport rViewport::s_viewportLeft(0,0,.5,1);
99
 
rViewport rViewport::s_viewportRight(.5,0,.5,1);
100
 
 
101
 
rViewport rViewport::s_viewportTopLeft(0,.5,.5,.5);
102
 
rViewport rViewport::s_viewportBottomLeft(0,0,.5,.5);
103
 
rViewport rViewport::s_viewportTopRight(.5,.5,.5,.5);
104
 
rViewport rViewport::s_viewportBottomRight(.5,0,.5,.5);
105
 
rViewport rViewport::s_viewportDemonstation(.55,.05,.4,.4);
106
 
 
107
 
int   sr_viewportBelongsToPlayer[MAX_VIEWPORTS],
108
 
s_newViewportBelongsToPlayer[MAX_VIEWPORTS];
109
 
 
110
 
// ***********************************************************
111
 
 
112
 
 
113
 
rViewportConfiguration::rViewportConfiguration(rViewport *first)
114
 
        :num_viewports(1){
115
 
    viewports[0]=first;
116
 
}
117
 
 
118
 
rViewportConfiguration::rViewportConfiguration(rViewport *first,
119
 
        rViewport *second)
120
 
        :num_viewports(2){
121
 
    viewports[0]=first;
122
 
    viewports[1]=second;
123
 
}
124
 
 
125
 
rViewportConfiguration::rViewportConfiguration(rViewport *first,
126
 
        rViewport *second,
127
 
        rViewport *third)
128
 
        :num_viewports(3){
129
 
    viewports[0]=first;
130
 
    viewports[1]=second;
131
 
    viewports[2]=third;
132
 
}
133
 
 
134
 
rViewportConfiguration::rViewportConfiguration(rViewport *first,
135
 
        rViewport *second,
136
 
        rViewport *third,
137
 
        rViewport *forth)
138
 
        :num_viewports(4){
139
 
    viewports[0]=first;
140
 
    viewports[1]=second;
141
 
    viewports[2]=third;
142
 
    viewports[3]=forth;
143
 
}
144
 
 
145
 
#ifndef DEDICATED
146
 
void rViewportConfiguration::Select(int i){
147
 
    if (i>=0 && i <num_viewports)
148
 
        viewports[i]->Select();
149
 
}
150
 
#endif
151
 
 
152
 
rViewport * rViewportConfiguration::Port(int i){
153
 
    if (i>=0 && i <num_viewports)
154
 
        return viewports[i];
155
 
    else
156
 
        return NULL;
157
 
}
158
 
 
159
 
static rViewportConfiguration single_vp(&rViewport::s_viewportFullscreen);
160
 
static rViewportConfiguration two_vp(&rViewport::s_viewportTop,
161
 
                                     &rViewport::s_viewportBottom);
162
 
static rViewportConfiguration two_b(&rViewport::s_viewportLeft,
163
 
                                    &rViewport::s_viewportRight);
164
 
static rViewportConfiguration three_a(&rViewport::s_viewportTop,
165
 
                                      &rViewport::s_viewportBottomLeft,
166
 
                                      &rViewport::s_viewportBottomRight);
167
 
static rViewportConfiguration three_b(&rViewport::s_viewportTopLeft,
168
 
                                      &rViewport::s_viewportTopRight,
169
 
                                      &rViewport::s_viewportBottom);
170
 
static rViewportConfiguration four_vp(&rViewport::s_viewportTopLeft,
171
 
                                      &rViewport::s_viewportTopRight,
172
 
                                      &rViewport::s_viewportBottomLeft,
173
 
                                      &rViewport::s_viewportBottomRight);
174
 
 
175
 
rViewportConfiguration *rViewportConfiguration::s_viewportConfigurations[]={
176
 
            &single_vp,&two_vp,&two_b,&three_a,&three_b,&four_vp};
177
 
 
178
 
char const * rViewportConfiguration::s_viewportConfigurationNames[]=
179
 
    {"$viewport_conf_name_0",
180
 
     "$viewport_conf_name_1",
181
 
     "$viewport_conf_name_2",
182
 
     "$viewport_conf_name_3",
183
 
     "$viewport_conf_name_4",
184
 
     "$viewport_conf_name_5"};
185
 
 
186
 
const int  rViewportConfiguration::s_viewportNumConfigurations=6;
187
 
 
188
 
 
189
 
 
190
 
// *******************************************************
191
 
//   Player menu
192
 
// *******************************************************
193
 
 
194
 
static int conf_num=0;
195
 
int rViewportConfiguration::next_conf_num=0;
196
 
 
197
 
static tConfItem<int> confn("VIEWPORT_CONF",
198
 
                            rViewportConfiguration::next_conf_num);
199
 
 
200
 
rViewportConfiguration *rViewportConfiguration::CurrentViewportConfiguration(){
201
 
    if (conf_num<0) conf_num=0;
202
 
    if (conf_num>=s_viewportNumConfigurations)
203
 
        conf_num=s_viewportNumConfigurations-1;
204
 
 
205
 
    return s_viewportConfigurations[conf_num];
206
 
}
207
 
 
208
 
#ifndef DEDICATED
209
 
void rViewportConfiguration::DemonstrateViewport(tString *titles){
210
 
    if (!sr_glOut)
211
 
        return;
212
 
 
213
 
    for(int i=s_viewportConfigurations[next_conf_num]->num_viewports-1;i>=0;i--){
214
 
        rViewport sub(rViewport::s_viewportDemonstation,*(s_viewportConfigurations[next_conf_num]->Port(i)));
215
 
        sub.Select();
216
 
 
217
 
        glDisable(GL_TEXTURE_2D);
218
 
        glDisable(GL_DEPTH_TEST);
219
 
 
220
 
        glColor3f(.1,.1,.4);
221
 
        glRectf(-.9,-.9,.9,.9);
222
 
 
223
 
        glColor3f(.6,.6,.6);
224
 
        glBegin(GL_LINE_LOOP);
225
 
        glVertex2f(-1,-1);
226
 
        glVertex2f(-1,1);
227
 
        glVertex2f(1,1);
228
 
        glVertex2f(1,-1);
229
 
        glEnd();
230
 
 
231
 
        glColor3f(1,1,1);
232
 
        DisplayText(0,0,.15,.5,titles[i]);
233
 
    }
234
 
 
235
 
    rViewport::s_viewportFullscreen.Select();
236
 
}
237
 
#endif
238
 
 
239
 
 
240
 
rViewport * rViewportConfiguration::CurrentViewport(int i){
241
 
    return CurrentViewportConfiguration()->Port(i);
242
 
}
243
 
 
244
 
void rViewportConfiguration::UpdateConf(){
245
 
    conf_num = next_conf_num;
246
 
}
247
 
 
248
 
 
249
 
static int vpb_dir[MAX_VIEWPORTS];
250
 
 
251
 
void rViewport::CorrectViewport(int i, int MAX_PLAYERS){
252
 
    if (vpb_dir[i]!=1 && vpb_dir[i]!=-1)
253
 
        vpb_dir[i]=1;
254
 
 
255
 
    int starta=rViewportConfiguration::s_viewportConfigurations[rViewportConfiguration::next_conf_num]->num_viewports-1;
256
 
    int startb=rViewportConfiguration::s_viewportConfigurations[     conf_num]->num_viewports-1;
257
 
    if (starta>startb)
258
 
        startb=starta;
259
 
    
260
 
    s_newViewportBelongsToPlayer[i]+=MAX_PLAYERS-vpb_dir[i];
261
 
    s_newViewportBelongsToPlayer[i]%=MAX_PLAYERS;
262
 
 
263
 
    int oldValue = s_newViewportBelongsToPlayer[i];
264
 
 
265
 
    bool again;
266
 
    bool expectChange = false;
267
 
    do{
268
 
        // rotate player assignemnt
269
 
        s_newViewportBelongsToPlayer[i]+=MAX_PLAYERS+vpb_dir[i];
270
 
        s_newViewportBelongsToPlayer[i]%=MAX_PLAYERS;
271
 
 
272
 
        // check for conflicts
273
 
        again=false;
274
 
        for(int j=starta;j>=0;j--)
275
 
            if (i!=j && s_newViewportBelongsToPlayer[i]
276
 
                    ==s_newViewportBelongsToPlayer[j])
277
 
            {
278
 
                again=true;
279
 
                expectChange=true;
280
 
            }
281
 
    } while(again);
282
 
 
283
 
    if ( oldValue == s_newViewportBelongsToPlayer[i] && expectChange )
284
 
    {
285
 
        // no change? swap players.
286
 
        s_newViewportBelongsToPlayer[i]+=MAX_PLAYERS+vpb_dir[i];
287
 
        s_newViewportBelongsToPlayer[i]%=MAX_PLAYERS;
288
 
 
289
 
        for(int j=starta;j>=0;j--)
290
 
            if (i!=j && s_newViewportBelongsToPlayer[i]
291
 
                    ==s_newViewportBelongsToPlayer[j])
292
 
            {
293
 
                s_newViewportBelongsToPlayer[j] = oldValue;
294
 
            }
295
 
    }
296
 
}
297
 
 
298
 
void rViewport::CorrectViewports(int MAX_PLAYERS){
299
 
    for (int i=rViewportConfiguration::s_viewportConfigurations[conf_num]->num_viewports-1;i>=0;i--)
300
 
        CorrectViewport(i, MAX_PLAYERS);
301
 
}
302
 
 
303
 
 
304
 
void rViewport::Update(int MAX_PLAYERS){
305
 
    rViewportConfiguration::UpdateConf();
306
 
    CorrectViewports(MAX_PLAYERS);
307
 
 
308
 
    int i;
309
 
    for(i=MAX_VIEWPORTS-1;i>=0;i--)
310
 
        sr_viewportBelongsToPlayer[i]=s_newViewportBelongsToPlayer[i];
311
 
}
312
 
 
313
 
void rViewport::SetDirectionOfCorrection(int vp, int dir){
314
 
    vpb_dir[vp] = dir;
315
 
}
316
 
 
317
 
// *******************************************************************************************
318
 
// *
319
 
// *    CorrectAspectBottom
320
 
// *
321
 
// *******************************************************************************************
322
 
//!
323
 
//!             @return
324
 
//!
325
 
// *******************************************************************************************
326
 
 
327
 
rViewport rViewport::CorrectAspectBottom( void ) const
328
 
{
329
 
    rViewport ret( *this );
330
 
    ret.height = width * 4.0 / 3.0;
331
 
 
332
 
    return ret;
333
 
}
334
 
 
335