Subversion Repositories eduke32

Rev

Rev 5037 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
99 terminx 1
#include "compat.h"
2
#include "osd.h"
3
#include "build.h"
4
#include "baselayer.h"
5
 
3221 hendricks2 6
#include "renderlayer.h"
99 terminx 7
 
3291 helixhorne 8
#include "a.h"
1488 terminx 9
#include "polymost.h"
10
 
1652 terminx 11
// input
12
char inputdevices=0;
4697 terminx 13
char keystatus[KEYSTATUSSIZ], keyfifo[KEYFIFOSIZ], keyasciififo[KEYFIFOSIZ];
14
uint8_t keyfifoplc, keyfifoend, keyasciififoplc, keyasciififoend;
4808 hendricks2 15
char keyremap[KEYSTATUSSIZ];
16
int32_t keyremapinit=0;
4472 hendricks2 17
char key_names[NUMKEYS][24];
4853 hendricks2 18
int32_t mousex=0,mousey=0,mouseb=0;
19
vec2_t mouseabs;
20
uint8_t mousepressstate;
4738 hendricks2 21
uint8_t moustat = 0, mousegrab = 0, mouseinwindow = 1, AppMouseGrab = 1;
4853 hendricks2 22
 
23
int32_t mousepressstateadvance(void)
24
{
25
    if (mousepressstate == Mouse_Pressed)
26
    {
27
        mousepressstate = Mouse_Held;
28
        return 1;
29
    }
30
    else if (mousepressstate == Mouse_Released)
31
    {
32
        mousepressstate = Mouse_Idle;
33
        return 1;
34
    }
4919 terminx 35
    else if (mousepressstate == Mouse_Held)
36
        return 1;
4853 hendricks2 37
 
38
    return 0;
39
}
40
 
1652 terminx 41
int32_t *joyaxis = NULL, joyb=0, *joyhat = NULL;
42
char joyisgamepad=0, joynumaxes=0, joynumbuttons=0, joynumhats=0;
43
int32_t joyaxespresent=0;
44
 
45
void(*keypresscallback)(int32_t,int32_t) = 0;
46
void(*mousepresscallback)(int32_t,int32_t) = 0;
47
void(*joypresscallback)(int32_t,int32_t) = 0;
48
 
1665 terminx 49
extern int16_t brightness;
50
 
1652 terminx 51
//
52
// set{key|mouse|joy}presscallback() -- sets a callback which gets notified when keys are pressed
53
//
54
void setkeypresscallback(void (*callback)(int32_t, int32_t)) { keypresscallback = callback; }
55
void setmousepresscallback(void (*callback)(int32_t, int32_t)) { mousepresscallback = callback; }
56
void setjoypresscallback(void (*callback)(int32_t, int32_t)) { joypresscallback = callback; }
57
 
831 terminx 58
char scantoasc[128] =
59
{
60
    0,0,'1','2','3','4','5','6','7','8','9','0','-','=',0,0,
61
    'q','w','e','r','t','y','u','i','o','p','[',']',0,0,'a','s',
62
    'd','f','g','h','j','k','l',';',39,'`',0,92,'z','x','c','v',
63
    'b','n','m',',','.','/',0,'*',0,32,0,0,0,0,0,0,
64
    0,0,0,0,0,0,0,'7','8','9','-','4','5','6','+','1',
65
    '2','3','0','.',0,0,0,0,0,0,0,0,0,0,0,0,
66
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
67
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
68
};
69
 
1819 plagman 70
int32_t defaultres[][2] =
71
{
3793 helixhorne 72
    {1920, 1440}, {1920, 1200}, {1920, 1080}, {1680, 1050}, {1600, 1200}, {1600, 900}, {1366, 768}, {1280, 1024},
1823 terminx 73
    {1280, 960}, {1152, 864}, {1024, 768}, {1024, 600}, {800, 600}, {640, 480}, {640, 400},
74
    {512, 384}, {480, 360}, {400, 300}, {320, 240}, {320, 200}, {0, 0}
1819 plagman 75
};
76
 
77
 
4269 hendricks2 78
int32_t GetKey(int32_t key)
79
{
4808 hendricks2 80
    return keystatus[keyremap[key]];
4269 hendricks2 81
}
4749 terminx 82
 
1652 terminx 83
void SetKey(int32_t key, int32_t state)
84
{
4808 hendricks2 85
    keystatus[keyremap[key]] = state;
1652 terminx 86
 
1762 terminx 87
    if (state)
1652 terminx 88
    {
4808 hendricks2 89
        keyfifo[keyfifoend] = keyremap[key];
1652 terminx 90
        keyfifo[(keyfifoend+1)&(KEYFIFOSIZ-1)] = state;
91
        keyfifoend = ((keyfifoend+2)&(KEYFIFOSIZ-1));
92
    }
93
}
94
 
95
//
96
// bgetchar, bflushchars -- character-based input functions
97
//
98
char bgetchar(void)
99
{
100
    if (keyasciififoplc == keyasciififoend)
101
        return 0;
102
 
103
    {
104
        char c = keyasciififo[keyasciififoplc];
105
        keyasciififoplc = ((keyasciififoplc+1)&(KEYFIFOSIZ-1));
106
        return c;
107
    }
108
}
109
 
110
void bflushchars(void)
111
{
112
    Bmemset(&keyasciififo,0,sizeof(keyasciififo));
113
    keyasciififoplc = keyasciififoend = 0;
114
}
115
 
116
const char *getkeyname(int32_t num)
117
{
118
    return ((unsigned)num >= 256) ? NULL : key_names[num];
119
}
120
 
1857 terminx 121
void readmousexy(int32_t *x, int32_t *y)
122
{
123
    if (!moustat || !mousegrab || !appactive) { *x = *y = 0; return; }
124
    *x = mousex;
125
    *y = mousey;
126
    mousex = mousey = 0;
127
}
128
 
4853 hendricks2 129
int32_t readmouseabsxy(vec2_t * const destination, vec2_t const * const source)
2623 helixhorne 130
{
4738 hendricks2 131
    int32_t xwidth;
132
 
4908 terminx 133
    if (!moustat || !appactive || !mouseinwindow || (osd && osd->flags & OSD_CAPTURE))
4738 hendricks2 134
        return 0;
135
 
136
    xwidth = max(scale(240<<16, xdim, ydim), 320<<16);
137
 
4853 hendricks2 138
    destination->x = scale(source->x, xwidth, xdim) - ((xwidth>>1) - (320<<15));
139
    destination->y = scale(source->y, 200<<16, ydim);
4738 hendricks2 140
 
141
    return 1;
2623 helixhorne 142
}
143
 
1857 terminx 144
void readmousebstatus(int32_t *b)
145
{
4908 terminx 146
    if (!moustat || !appactive || !mouseinwindow || (osd && osd->flags & OSD_CAPTURE)) { *b = 0; return; }
1857 terminx 147
    *b = mouseb;
148
}
149
 
2728 hendricks2 150
void readjoybstatus(int32_t *b)
151
{
152
    if (!appactive) { *b = 0; return; }
153
    *b = joyb;
154
}
155
 
4719 terminx 156
#if defined _WIN32
157
# define WIN32_LEAN_AND_MEAN
158
# include <windows.h>
5037 hendricks2 159
#elif defined __linux || defined EDUKE32_BSD || defined __APPLE__
4719 terminx 160
# include <sys/mman.h>
161
#endif
162
 
163
#if !defined(NOASM) && !defined(GEKKO) && !defined(__ANDROID__)
164
#ifdef __cplusplus
165
extern "C" {
166
#endif
167
    extern intptr_t dep_begin, dep_end;
168
#ifdef __cplusplus
4766 hendricks2 169
}
4719 terminx 170
#endif
171
#endif
172
 
4723 terminx 173
#if !defined(NOASM) && !defined(GEKKO) && !defined(__ANDROID__)
4719 terminx 174
int32_t nx_unprotect(intptr_t beg, intptr_t end)
175
{
176
# if defined _WIN32
177
    DWORD oldprot;
178
 
179
    if (!VirtualProtect((LPVOID) beg, (SIZE_T)end - (SIZE_T)beg, PAGE_EXECUTE_READWRITE, &oldprot))
180
    {
181
        initprintf("VirtualProtect() error! Crashing in 3... 2... 1...\n");
182
        return 1;
183
    }
5037 hendricks2 184
# elif defined __linux || defined EDUKE32_BSD || defined __APPLE__
4719 terminx 185
    int32_t pagesize;
186
    size_t dep_begin_page;
187
    pagesize = sysconf(_SC_PAGE_SIZE);
188
    if (pagesize == -1)
189
    {
190
        initprintf("Error getting system page size\n");
191
        return 1;
192
    }
193
    dep_begin_page = ((size_t)beg) & ~(pagesize-1);
194
    if (mprotect((void *) dep_begin_page, (size_t)end - dep_begin_page, PROT_READ|PROT_WRITE) < 0)
195
    {
196
        initprintf("Error making code writeable (errno=%d)\n", errno);
197
        return 1;
198
    }
199
# else
200
#  error "Don't know how to unprotect the self-modifying assembly on this platform!"
201
# endif
202
 
203
    return 0;
204
}
4723 terminx 205
#endif
4719 terminx 206
 
207
 
3291 helixhorne 208
// Calculate ylookup[] and call setvlinebpl()
209
void calc_ylookup(int32_t bpl, int32_t lastyidx)
210
{
211
    int32_t i, j=0;
4724 helixhorne 212
    static int32_t ylookupsiz;
3291 helixhorne 213
 
4724 helixhorne 214
    Bassert(lastyidx <= MAXYDIM);
215
 
4719 terminx 216
    lastyidx++;
217
 
4695 terminx 218
    if (lastyidx > ylookupsiz)
3291 helixhorne 219
    {
4724 helixhorne 220
        Baligned_free(ylookup);
4695 terminx 221
 
222
        ylookup = (intptr_t *)Xaligned_alloc(16, lastyidx * sizeof(intptr_t));
4719 terminx 223
#if !defined(NOASM) && !defined(GEKKO) && !defined(__ANDROID__)
224
        nx_unprotect((intptr_t)ylookup, (intptr_t)ylookup + (lastyidx * sizeof(intptr_t)));
225
#endif
4695 terminx 226
        ylookupsiz = lastyidx;
227
    }
228
 
229
    for (i=0; i<=lastyidx-4; i+=4)
230
    {
3291 helixhorne 231
        ylookup[i] = j;
4695 terminx 232
        ylookup[i + 1] = j + bpl;
233
        ylookup[i + 2] = j + (bpl << 1);
234
        ylookup[i + 3] = j + (bpl * 3);
235
        j += (bpl << 2);
236
    }
237
 
4724 helixhorne 238
    for (; i<lastyidx; i++)
4695 terminx 239
    {
240
        ylookup[i] = j;
3291 helixhorne 241
        j += bpl;
242
    }
243
 
244
    setvlinebpl(bpl);
245
}
246
 
4719 terminx 247
 
248
void makeasmwriteable(void)
249
{
250
#if !defined(NOASM) && !defined(GEKKO) && !defined(__ANDROID__)
251
    nx_unprotect((intptr_t)&dep_begin, (intptr_t)&dep_end);
252
#endif
253
}
254
 
99 terminx 255
#ifdef USE_OPENGL
5001 terminx 256
extern int32_t nofog;
257
 
3263 helixhorne 258
void fullscreen_tint_gl(uint8_t r, uint8_t g, uint8_t b, uint8_t f)
259
{
260
    bglMatrixMode(GL_PROJECTION);
261
    bglPushMatrix();
262
    bglLoadIdentity();
263
    bglMatrixMode(GL_MODELVIEW);
264
    bglPushMatrix();
265
    bglLoadIdentity();
266
 
267
    bglDisable(GL_DEPTH_TEST);
268
    bglDisable(GL_ALPHA_TEST);
269
    bglDisable(GL_TEXTURE_2D);
4176 helixhorne 270
    bglDisable(GL_FOG);
3263 helixhorne 271
 
4617 terminx 272
    bglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3263 helixhorne 273
    bglEnable(GL_BLEND);
274
    bglColor4ub(r, g, b, f);
275
 
276
    bglBegin(GL_TRIANGLES);
277
    bglVertex2f(-2.5f, 1.f);
278
    bglVertex2f(2.5f, 1.f);
279
    bglVertex2f(.0f, -2.5f);
280
    bglEnd();
281
 
282
    bglPopMatrix();
283
    bglMatrixMode(GL_PROJECTION);
284
    bglPopMatrix();
285
}
286
 
1625 terminx 287
struct glinfo_t glinfo =
584 terminx 288
{
1506 plagman 289
    "Unknown",  // vendor
290
    "Unknown",  // renderer
291
    "0.0.0",    // version
292
    "",         // extensions
109 terminx 293
 
1506 plagman 294
    1.0,        // max anisotropy
295
    0,          // brga texture format
296
    0,          // clamp-to-edge support
297
    0,          // texture compression
298
    0,          // non-power-of-two textures
299
    0,          // multisampling
300
    0,          // nvidia multisampling hint
301
    0,          // ARBfp
302
    0,          // depth textures
303
    0,          // shadow comparison
304
    0,          // Frame Buffer Objects
305
    0,          // rectangle textures
306
    0,          // multitexturing
307
    0,          // env_combine
308
    0,          // Vertex Buffer Objects
309
    0,          // VSync support
310
    0,          // Shader Model 4 support
311
    0,          // Occlusion Queries
312
    0,          // GLSL
2056 plagman 313
    0,          // Debug Output
1506 plagman 314
    0,          // GL info dumped
584 terminx 315
};
99 terminx 316
#endif
317
 
1430 terminx 318
int32_t flushlogwindow = 1;
1203 terminx 319
 
1820 terminx 320
#ifdef USE_OPENGL
4015 helixhorne 321
// Used to register the game's / editor's osdcmd_vidmode() functions here.
322
int32_t (*baselayer_osdcmd_vidmode_func)(const osdfuncparm_t *parm);
323
 
1205 terminx 324
static int32_t osdfunc_setrendermode(const osdfuncparm_t *parm)
99 terminx 325
{
1205 terminx 326
    int32_t m;
109 terminx 327
    char *p;
99 terminx 328
 
4015 helixhorne 329
    if (parm->numparms != 1)
330
        return OSDCMD_SHOWHELP;
331
 
109 terminx 332
    m = Bstrtol(parm->parms[0], &p, 10);
99 terminx 333
 
4015 helixhorne 334
    if (m != REND_CLASSIC && m != REND_POLYMOST && m != REND_POLYMER)
335
        return OSDCMD_SHOWHELP;
99 terminx 336
 
4015 helixhorne 337
    if ((m==REND_CLASSIC) != (bpp==8) && baselayer_osdcmd_vidmode_func)
338
    {
339
        // Mismatch between video mode and requested renderer, do auto switch.
340
        osdfuncparm_t parm;
341
        char arg[4];
342
 
343
        const char *ptrptr[1];
344
        ptrptr[0] = arg;
345
 
346
        Bmemset(&parm, 0, sizeof(parm));
347
 
348
        if (m==REND_CLASSIC)
349
            Bmemcpy(&arg, "8", 2);
350
        else
351
            Bmemcpy(&arg, "32", 3);
352
 
353
        // CAUTION: we assume that the osdcmd_vidmode function doesn't use any
354
        // other member!
355
        parm.numparms = 1;
356
        parm.parms = ptrptr;
357
 
358
        baselayer_osdcmd_vidmode_func(&parm);
359
    }
360
 
109 terminx 361
    setrendermode(m);
99 terminx 362
 
4015 helixhorne 363
    switch (getrendermode())
3347 terminx 364
    {
365
    case REND_CLASSIC:
366
        p = "classic software";
367
        break;
368
    case REND_POLYMOST:
369
        p = "polygonal OpenGL";
370
        break;
371
    case REND_POLYMER:
372
        p = "great justice (Polymer)";
373
        break;
374
    }
375
 
376
    OSD_Printf("Rendering method changed to %s\n", p);
377
 
109 terminx 378
    return OSDCMD_OK;
99 terminx 379
}
855 terminx 380
#if defined(USE_OPENGL)
99 terminx 381
#ifdef DEBUGGINGAIDS
1205 terminx 382
static int32_t osdcmd_hicsetpalettetint(const osdfuncparm_t *parm)
99 terminx 383
{
1205 terminx 384
    int32_t pal, cols[3], eff;
109 terminx 385
 
386
    if (parm->numparms != 5) return OSDCMD_SHOWHELP;
387
 
388
    pal = Batol(parm->parms[0]);
389
    cols[0] = Batol(parm->parms[1]);
390
    cols[1] = Batol(parm->parms[2]);
391
    cols[2] = Batol(parm->parms[3]);
392
    eff = Batol(parm->parms[4]);
393
 
394
    hicsetpalettetint(pal,cols[0],cols[1],cols[2],eff);
395
 
396
    return OSDCMD_OK;
99 terminx 397
}
398
#endif
399
 
1205 terminx 400
int32_t osdcmd_glinfo(const osdfuncparm_t *parm)
99 terminx 401
{
109 terminx 402
    char *s,*t,*u,i;
99 terminx 403
 
654 terminx 404
    UNREFERENCED_PARAMETER(parm);
405
 
584 terminx 406
    if (bpp == 8)
407
    {
5001 terminx 408
        initprintf("glinfo: not in OpenGL mode!\n");
109 terminx 409
        return OSDCMD_OK;
410
    }
411
 
5001 terminx 412
    initprintf("OpenGL information\n %s %s %s\n",
413
               glinfo.vendor, glinfo.renderer, glinfo.version);
848 terminx 414
 
415
    if (!glinfo.dumped)
416
        return OSDCMD_OK;
417
 
418
    initprintf(" Maximum anisotropy:      %.1f%s\n"
109 terminx 419
               " BGRA textures:           %s\n"
1506 plagman 420
               " Non-power-of-2 textures: %s\n"
5001 terminx 421
               " Clamp-to-edge:           %s\n"
422
               " Multitexturing:          %s\n"
423
               " Frame Buffer Objects:    %s\n"
109 terminx 424
               " Texure compression:      %s\n"
5001 terminx 425
#ifndef EDUKE32_GLES
109 terminx 426
               " Multisampling:           %s\n"
5001 terminx 427
               " NVIDIA multisample hint: %s\n"
446 Plagman 428
               " ARBfp fragment programs: %s\n"
429
               " Depth textures:          %s\n"
430
               " Shadow textures:         %s\n"
431
               " Rectangle textures:      %s\n"
519 Plagman 432
               " env_combine:             %s\n"
433
               " Vertex Buffer Objects:   %s\n"
1222 plagman 434
               " Shader Model 4:          %s\n"
1506 plagman 435
               " Occlusion queries:       %s\n"
436
               " GLSL:                    %s\n"
2056 plagman 437
               " Debug Output:            %s\n"
5001 terminx 438
#endif
109 terminx 439
               " Extensions:\n",
440
               glinfo.maxanisotropy, glinfo.maxanisotropy>1.0?"":" (no anisotropic filtering)",
441
               glinfo.bgra ? "supported": "not supported",
442
               glinfo.texnpot ? "supported": "not supported",
443
               glinfo.clamptoedge ? "supported": "not supported",
5001 terminx 444
               glinfo.multitex ? "supported": "not supported",
445
               glinfo.fbos ? "supported": "not supported",
446
               glinfo.texcompr ? "supported": "not supported"
447
#ifndef EDUKE32_GLES
448
               ,glinfo.multisample ? "supported": "not supported",
446 Plagman 449
               glinfo.nvmultisamplehint ? "supported": "not supported",
450
               glinfo.arbfp ? "supported": "not supported",
451
               glinfo.depthtex ? "supported": "not supported",
452
               glinfo.shadow ? "supported": "not supported",
519 Plagman 453
               glinfo.rect ? "supported": "not supported",
454
               glinfo.envcombine ? "supported": "not supported",
1222 plagman 455
               glinfo.vbos ? "supported": "not supported",
1506 plagman 456
               glinfo.sm4 ? "supported": "not supported",
457
               glinfo.occlusionqueries ? "supported": "not supported",
2056 plagman 458
               glinfo.glsl ? "supported": "not supported",
459
               glinfo.debugoutput ? "supported": "not supported"
5001 terminx 460
#endif
109 terminx 461
              );
462
 
463
    s = Bstrdup(glinfo.extensions);
1740 helixhorne 464
    if (!s) initprintf("%s", glinfo.extensions);
584 terminx 465
    else
466
    {
109 terminx 467
        i = 0; t = u = s;
584 terminx 468
        while (*t)
469
        {
470
            if (*t == ' ')
471
            {
472
                if (i&1)
473
                {
109 terminx 474
                    *t = 0;
627 terminx 475
                    initprintf("   %s\n",u);
109 terminx 476
                    u = t+1;
477
                }
478
                i++;
479
            }
480
            t++;
481
        }
627 terminx 482
        if (i&1) initprintf("   %s\n",u);
109 terminx 483
        Bfree(s);
484
    }
485
 
486
    return OSDCMD_OK;
99 terminx 487
}
488
#endif
855 terminx 489
#endif
99 terminx 490
 
1665 terminx 491
static int32_t osdcmd_cvar_set_baselayer(const osdfuncparm_t *parm)
99 terminx 492
{
1665 terminx 493
    int32_t r = osdcmd_cvar_set(parm);
109 terminx 494
 
1665 terminx 495
    if (r != OSDCMD_OK) return r;
496
 
497
    if (!Bstrcasecmp(parm->name, "vid_gamma") || !Bstrcasecmp(parm->name, "vid_brightness") || !Bstrcasecmp(parm->name, "vid_contrast"))
498
    {
1781 plagman 499
        setbrightness(GAMMA_CALC,0,0);
1665 terminx 500
 
501
        return r;
109 terminx 502
    }
1665 terminx 503
 
504
    return r;
99 terminx 505
}
506
 
1205 terminx 507
int32_t baselayer_init(void)
99 terminx 508
{
1352 terminx 509
    uint32_t i;
2601 helixhorne 510
#ifdef _WIN32
511
// on Windows, don't save the "r_screenaspect" cvar because the physical screen size is
512
// determined at startup
513
# define SCREENASPECT_CVAR_TYPE (CVAR_UINT|CVAR_NOSAVE)
514
#else
515
# define SCREENASPECT_CVAR_TYPE (CVAR_UINT)
516
#endif
1352 terminx 517
    cvar_t cvars_engine[] =
518
    {
3783 terminx 519
        { "r_usenewaspect","enable/disable new screen aspect ratio determination code",(void *) &r_usenewaspect, CVAR_BOOL, 0, 1 },
520
        { "r_screenaspect","if using r_usenewaspect and in fullscreen, screen aspect ratio in the form XXYY, e.g. 1609 for 16:9",
2959 helixhorne 521
          (void *) &r_screenxy, SCREENASPECT_CVAR_TYPE, 0, 9999 },
3783 terminx 522
        { "r_novoxmips","turn off/on the use of mipmaps when rendering 8-bit voxels",(void *) &novoxmips, CVAR_BOOL, 0, 1 },
523
        { "r_voxels","enable/disable automatic sprite->voxel rendering",(void *) &usevoxels, CVAR_BOOL, 0, 1 },
2024 helixhorne 524
#ifdef YAX_ENABLE
3783 terminx 525
        { "r_tror_nomaskpass", "enable/disable additional pass in TROR software rendering", (void *)&r_tror_nomaskpass, CVAR_BOOL, 0, 1 },
2024 helixhorne 526
#endif
4327 terminx 527
        { "r_windowpositioning", "enable/disable window position memory", (void *) &windowpos, CVAR_BOOL, 0, 1 },
4664 terminx 528
        { "vid_gamma","adjusts gamma component of gamma ramp",(void *) &vid_gamma, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
529
        { "vid_contrast","adjusts contrast component of gamma ramp",(void *) &vid_contrast, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
530
        { "vid_brightness","adjusts brightness component of gamma ramp",(void *) &vid_brightness, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
3349 terminx 531
#ifdef DEBUGGINGAIDS
1762 terminx 532
        { "debug1","debug counter",(void *) &debug1, CVAR_FLOAT, -100000, 100000 },
533
        { "debug2","debug counter",(void *) &debug2, CVAR_FLOAT, -100000, 100000 },
3349 terminx 534
#endif
4261 helixhorne 535
#ifdef DEBUG_MASK_DRAWING
4264 helixhorne 536
        { "debug_maskdrawmode", "Show mask draw orders", (void *)&g_maskDrawMode, CVAR_BOOL, 0, 1 },
4261 helixhorne 537
#endif
1352 terminx 538
    };
539
 
4385 terminx 540
    for (i=0; i<ARRAY_SIZE(cvars_engine); i++)
1352 terminx 541
    {
1625 terminx 542
        if (OSD_RegisterCvar(&cvars_engine[i]))
543
            continue;
544
 
1857 terminx 545
        OSD_RegisterFunction(cvars_engine[i].name, cvars_engine[i].desc,
1762 terminx 546
                             (cvars_engine[i].type & CVAR_FUNCPTR) ? osdcmd_cvar_set_baselayer : osdcmd_cvar_set);
1352 terminx 547
    }
548
 
1820 terminx 549
#ifdef USE_OPENGL
109 terminx 550
    OSD_RegisterFunction("setrendermode","setrendermode <number>: sets the engine's rendering mode.\n"
551
                         "Mode numbers are:\n"
552
                         "   0 - Classic Build software\n"
99 terminx 553
#ifdef USE_OPENGL
109 terminx 554
                         "   3 - Polygonal OpenGL\n"
1652 terminx 555
                         "   4 - Great justice renderer (Polymer)\n"
99 terminx 556
#endif
109 terminx 557
                         ,
558
                         osdfunc_setrendermode);
1564 plagman 559
#ifdef USE_OPENGL
560
# ifdef DEBUGGINGAIDS
109 terminx 561
    OSD_RegisterFunction("hicsetpalettetint","hicsetpalettetint: sets palette tinting values",osdcmd_hicsetpalettetint);
1564 plagman 562
# endif
109 terminx 563
    OSD_RegisterFunction("glinfo","glinfo: shows OpenGL information about the current OpenGL mode",osdcmd_glinfo);
1365 plagman 564
#endif
1352 terminx 565
    polymost_initosdfuncs();
99 terminx 566
#endif
1352 terminx 567
 
109 terminx 568
    return 0;
99 terminx 569
}
570
 
3377 helixhorne 571
void maybe_redirect_outputs(void)
572
{
573
#if !(defined __APPLE__ && defined __BIG_ENDIAN__)
574
    char *argp;
575
 
576
    // pipe standard outputs to files
577
    if ((argp = Bgetenv("BUILD_LOGSTDOUT")) != NULL)
578
        if (!Bstrcasecmp(argp, "TRUE"))
579
        {
580
            FILE *fp = freopen("stdout.txt", "w", stdout);
581
 
582
            if (!fp)
583
                fp = fopen("stdout.txt", "w");
584
 
585
            if (fp)
586
            {
587
                setvbuf(fp, 0, _IONBF, 0);
588
                *stdout = *fp;
589
                *stderr = *fp;
590
            }
591
        }
592
#endif
593
}