~swag/armagetronad/0.2.9-sty+ct+ap-fork

« back to all changes in this revision

Viewing changes to src/tron/gHud.cpp

  • Committer: wrtlprnft
  • Date: 2008-03-24 08:28:20 UTC
  • mfrom: (563.1.226)
  • Revision ID: wrtlprnft@users.sf.net-20080324082820-235q3jssjh059s53
Merged changes from the 0.2.8 branch.
The pighack help text got replaced by the new help menu.
To emulate the old behavior use:
REMOVE_HELP_TOPIC commands
HELP_INTRODUCTORY_BLURB <your help text>

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
 
67
67
void GLmeter_subby(float value,float max, float locx, float locy, float size, const char * t,bool displayvalue = true, bool reverse = false, REAL r=.5, REAL g=.5, REAL b=1)
68
68
{
 
69
 
 
70
#ifndef DEDICATED
 
71
    if (!sr_glOut)
 
72
        return;
 
73
#endif
 
74
 
69
75
    tString title( t );
70
76
 
71
 
    sr_ResetRenderState(0); //needs this because rFont has bugs i presume.. Ie I have problems as soon as rTextFirld is used
72
 
    // z-man: actually, it is needed because per-frame-tasks get called without rendering context, so it has to be set.
73
77
    float x, y;
74
78
    char string[50];
75
79
    value>max?value=max:1;
94
98
 
95
99
        RenderEnd();*/
96
100
 
 
101
    glDisable(GL_TEXTURE_2D);
 
102
    Color(r,g, b);
97
103
    BeginLines();
98
 
    Color(r,g, b);
99
104
    Vertex(-.1*x*size+locx,.1*y*size+locy,0);
100
105
    Vertex(-x*size+locx,y*size+locy,0);
101
106
    RenderEnd();
117
122
        rTextField titletext(locx-((.15*size*(length-1.5))/2.0),locy,.12*size,.24*size); //centre  -1.0 for null char and -.5 for half a char width = -1.5
118
123
        titletext << "0xff3333" << title;
119
124
    }
120
 
 
121
 
#ifndef DEDICATED
122
 
    if (!sr_glOut)
123
 
        return;
124
 
 
125
 
    glColor3f(1,1,1);
126
 
#endif
127
 
 
128
125
}
129
126
 
 
127
class gGLMeter
 
128
{
 
129
public:
 
130
    gGLMeter()
 
131
    : oldTime_( -100 ), oldRel_( -100 )
 
132
    {
 
133
    }
 
134
 
 
135
    void Display( float value,float max, float locx, float locy, float size, const char * t,bool displayvalue = true, bool reverse = false, REAL r=.5, REAL g=.5, REAL b=1)
 
136
    {
 
137
        REAL rel = value/max;
 
138
        REAL time = se_GameTime();
 
139
        REAL change = rel - oldRel_;
 
140
 
 
141
        // see if the gauge change is enough to warrant an update
 
142
        if ( change * change * ( time - oldTime_ ) > .000001 || time < oldTime_ )
 
143
        {
 
144
            list_.Clear();
 
145
        }
 
146
 
 
147
        if ( !list_.Call() )
 
148
        {
 
149
            oldRel_ = rel;
 
150
            oldTime_ = time;
 
151
 
 
152
            rDisplayListFiller filler( list_ );
 
153
            GLmeter_subby(value, max,  locx, locy, size, t, displayvalue, reverse, r, g, b );
 
154
        }
 
155
    }
 
156
private:
 
157
    REAL oldTime_;      // last rendered game time
 
158
    REAL oldRel_;       // last rendered gauge position
 
159
    rDisplayList list_; // caching display list
 
160
};
 
161
 
 
162
// caches stuff based on two float properties
 
163
class gTextCache
 
164
{
 
165
public:
 
166
    gTextCache()
 
167
    : propa_(-1), propb_(-1)
 
168
    {
 
169
    }
 
170
 
 
171
    bool Call( REAL propa, REAL propb )
 
172
    {
 
173
        if ( propa != propa_ || propb != propb_ )
 
174
        {
 
175
            propa_ = propa;
 
176
            propb_ = propb;
 
177
            list_.Clear();
 
178
            return false;
 
179
        }
 
180
        else
 
181
        {
 
182
            return list_.Call();
 
183
        }
 
184
    }
 
185
    
 
186
    rDisplayList list_;
 
187
private:
 
188
    REAL propa_, propb_;
 
189
};
 
190
 
130
191
static int alivepeople, alivemates, thetopscore, hudfpscount;
131
192
 
132
193
static void tank_display_hud( ePlayerNetID* me ){
147
208
            lastTime = newtime;
148
209
        }
149
210
 
150
 
        sr_ResetRenderState(false);
151
211
        Color(1,1,1);
152
212
        rTextField c(-.9,-.6);
153
213
 
241
301
            se_mainGameTimer->speed < 1.1 &&
242
302
            se_mainGameTimer->IsSynced() )
243
303
    {
244
 
        sr_ResetRenderState(false);
245
304
        Color(1,1,1);
246
305
        rTextField c(-.9,-.85);
247
306
        rTextField t(.6,.98);
331
390
                        myping = me->ping;
332
391
 
333
392
                        if(subby_ShowSpeedMeter)
334
 
                            GLmeter_subby(h->Speed(),maxmeterspeed,subby_SpeedGaugeLocX,subby_SpeedGaugeLocY,subby_SpeedGaugeSize,"Speed");  // easy to use configurable meters
 
393
                        {
 
394
                            static gGLMeter meter[MAX_PLAYERS];
 
395
                            meter[player->ID()].Display(h->Speed(),maxmeterspeed,subby_SpeedGaugeLocX,subby_SpeedGaugeLocY,subby_SpeedGaugeSize,"Speed");  // easy to use configurable meters
 
396
                        }
335
397
                        if(subby_ShowRubberMeter)
336
398
                        {
337
 
                            GLmeter_subby(h->GetRubber(),sg_rubberCycle,subby_RubberGaugeLocX,subby_RubberGaugeLocY,subby_RubberGaugeSize," Rubber Used");
 
399
                            static gGLMeter meter[MAX_PLAYERS];
 
400
                            meter[player->ID()].Display(h->GetRubber(),sg_rubberCycle,subby_RubberGaugeLocX,subby_RubberGaugeLocY,subby_RubberGaugeSize," Rubber Used");
338
401
                            if ( gCycle::RubberMalusActive() )
339
 
                                GLmeter_subby(100/(1+h->GetRubberMalus()),100,subby_RubberGaugeLocX,subby_RubberGaugeLocY,subby_RubberGaugeSize,"",true, false, 1,.5,.5);
 
402
                            {
 
403
                                static gGLMeter meter2[MAX_PLAYERS];
 
404
                                meter2[player->ID()].Display(100/(1+h->GetRubberMalus()),100,subby_RubberGaugeLocX,subby_RubberGaugeLocY,subby_RubberGaugeSize,"",true, false, 1,.5,.5);
 
405
                            }
340
406
                        }
341
407
                        if(subby_ShowBrakeMeter)
342
 
                            GLmeter_subby(h->GetBrakingReservoir(), 1.0,subby_BrakeGaugeLocX,subby_BrakeGaugeLocY,subby_BrakeGaugeSize, " Brakes");
 
408
                        {
 
409
                            static gGLMeter meter[MAX_PLAYERS];
 
410
                            meter[player->ID()].Display(h->GetBrakingReservoir(), 1.0,subby_BrakeGaugeLocX,subby_BrakeGaugeLocY,subby_BrakeGaugeSize, " Brakes");
 
411
                        }
343
412
 
344
413
                        //  bool displayfastest = true;// put into global, set via menusytem... subby to do.make sr_DISPLAYFASTESTout
345
414
 
346
415
                        if(subby_ShowSpeedFastest)
347
416
                        {
348
 
 
349
 
                            float size= subby_FastestSize;
350
 
                            tColoredString message,messageColor;
351
 
                            messageColor << "0xbf9d50";
352
 
 
353
 
                            sprintf(fasteststring,"%.1f",max);
354
 
                            message << "  Fastest: " << name << " " << fasteststring;
355
 
                            message.RemoveHex(); //cheers tank;
356
 
                            int length = message.Len();
357
 
 
358
 
                            rTextField speed_fastest(subby_FastestLocX-((.15*size*(length-1.5))/2.0),subby_FastestLocY,.15*size,.3*size);
 
417
                            static gTextCache cacheArray[MAX_PLAYERS];
 
418
                            gTextCache & cache = cacheArray[player->ID()];
 
419
                            if ( !cache.Call( max, 0 ) )
 
420
                            {
 
421
                                rDisplayListFiller filler( cache.list_ );
 
422
 
 
423
                                float size= subby_FastestSize;
 
424
                                tColoredString message,messageColor;
 
425
                                messageColor << "0xbf9d50";
 
426
 
 
427
                                sprintf(fasteststring,"%.1f",max);
 
428
                                message << "  Fastest: " << name << " " << fasteststring;
 
429
                                message.RemoveHex(); //cheers tank;
 
430
                                int length = message.Len();
 
431
 
 
432
                                rTextField speed_fastest(subby_FastestLocX-((.15*size*(length-1.5))/2.0),subby_FastestLocY,.15*size,.3*size);
359
433
                            /*   rTextField speed_fastest(.7-((.15*size*(length-1.5))/2.0),.65,.15*size,.3*size); */
360
434
 
361
 
                            speed_fastest << messageColor << message;
362
 
 
363
 
 
364
 
 
 
435
                                speed_fastest << messageColor << message;
 
436
                            }
365
437
                        }
366
438
 
367
439
                        if(subby_ShowScore){
368
 
                            tString colour;
369
 
                            if(myscore==topscore){
370
 
                                colour = "0xff9d50";
371
 
                            }else if (myscore > topscore){
372
 
                                colour = "0x11ff11";
373
 
                            }else{
374
 
                                colour = "0x11ffff";
 
440
                            static gTextCache cacheArray[MAX_PLAYERS];
 
441
                            gTextCache & cache = cacheArray[player->ID()];
 
442
                            if ( !cache.Call( topscore, myscore ) )
 
443
                            {
 
444
                                rDisplayListFiller filler( cache.list_ );
 
445
 
 
446
                                tString colour;
 
447
                                if(myscore==topscore){
 
448
                                    colour = "0xff9d50";
 
449
                                }else if (myscore > topscore){
 
450
                                    colour = "0x11ff11";
 
451
                                }else{
 
452
                                    colour = "0x11ffff";
 
453
                                }
 
454
 
 
455
                                float size = subby_ScoreSize;
 
456
                                rTextField score(subby_ScoreLocX,subby_ScoreLocY,.15*size,.3*size);
 
457
                                score <<               " Scores\n";
 
458
                                score << "0xefefef" << "Me:  Top:\n";
 
459
                                score << colour << myscore << "     0xffff00" << topscore ;
375
460
                            }
376
 
 
377
 
                            float size = subby_ScoreSize;
378
 
                            rTextField score(subby_ScoreLocX,subby_ScoreLocY,.15*size,.3*size);
379
 
                            score <<               " Scores\n";
380
 
                            score << "0xefefef" << "Me:  Top:\n";
381
 
                            score << colour << myscore << "     0xffff00" << topscore ;
382
461
                        }
383
462
 
384
463
                        if(subby_ShowAlivePeople){
385
 
                            tString message;
386
 
                            message << "Enemies: " << alivepeople << " Friends: " << alivemates;
387
 
                            int length = message.Len();
388
 
                            float size = subby_AlivePeopleSize;
389
 
                            rTextField enemies_alive(subby_AlivePeopleLocX-((.15*size*(length-1.5))/2.0),subby_AlivePeopleLocY,.15*size,.3*size);
390
 
                            enemies_alive << "0xfefefe" << message;
 
464
                            static gTextCache cacheArray[MAX_PLAYERS];
 
465
                            gTextCache & cache = cacheArray[player->ID()];
 
466
                            if ( !cache.Call( alivepeople, alivemates ) )
 
467
                            {
 
468
                                rDisplayListFiller filler( cache.list_ );
 
469
 
 
470
                                tString message;
 
471
                                message << "Enemies: " << alivepeople << " Friends: " << alivemates;
 
472
                                int length = message.Len();
 
473
                                float size = subby_AlivePeopleSize;
 
474
                                rTextField enemies_alive(subby_AlivePeopleLocX-((.15*size*(length-1.5))/2.0),subby_AlivePeopleLocY,.15*size,.3*size);
 
475
                                enemies_alive << "0xfefefe" << message;
 
476
                            }
391
477
                        }
392
478
 
393
479
                        if(subby_ShowPing){
394
 
                            tString message;
395
 
                            message << "Ping: " << int(myping * 1000) << " ms" ;
396
 
                            int length = message.Len();
397
 
                            float size = subby_PingSize;
398
 
                            rTextField ping(subby_PingLocX-((.15*size*(length-1.5))/2.0),subby_PingLocY,.15*size,.3*size);
399
 
                            ping << "0xfefefe" << message;
 
480
                            static gTextCache cacheArray[MAX_PLAYERS];
 
481
                            gTextCache & cache = cacheArray[player->ID()];
 
482
                            if ( !cache.Call( 0, myping ) )
 
483
                            {
 
484
                                rDisplayListFiller filler( cache.list_ );
 
485
 
 
486
                                tString message;
 
487
                                message << "Ping: " << int(myping * 1000) << " ms" ;
 
488
                                int length = message.Len();
 
489
                                float size = subby_PingSize;
 
490
                                rTextField ping(subby_PingLocX-((.15*size*(length-1.5))/2.0),subby_PingLocY,.15*size,.3*size);
 
491
                                ping << "0xfefefe" << message;
 
492
                            }
400
493
                        }
401
494
                    }
402
495
                }
422
515
    REAL newtime = tSysTimeFloat();
423
516
    REAL ts      = newtime - lastTime;
424
517
 
 
518
    static gTextCache cache;
 
519
    if ( cache.Call( fps, (int)tSysTimeFloat() ) )
 
520
    {
 
521
        return;
 
522
    }
 
523
    if ( tRecorder::IsRunning() )
 
524
    {
 
525
        cache.list_.Clear();
 
526
    }
 
527
    rDisplayListFiller filler( cache.list_ );
 
528
 
425
529
    float size =.15;
426
530
    rTextField c2(.7,.85,.15*size, .3*size);
427
531