Subversion Repositories eduke32

Rev

Rev 5547 | 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
5309 helixhorne 314
    0,          // Buffer storage
1506 plagman 315
    0,          // GL info dumped
584 terminx 316
};
99 terminx 317
#endif
318
 
1430 terminx 319
int32_t flushlogwindow = 1;
1203 terminx 320
 
1820 terminx 321
#ifdef USE_OPENGL
4015 helixhorne 322
// Used to register the game's / editor's osdcmd_vidmode() functions here.
323
int32_t (*baselayer_osdcmd_vidmode_func)(const osdfuncparm_t *parm);
324
 
1205 terminx 325
static int32_t osdfunc_setrendermode(const osdfuncparm_t *parm)
99 terminx 326
{
4015 helixhorne 327
    if (parm->numparms != 1)
328
        return OSDCMD_SHOWHELP;
329
 
5547 terminx 330
    char *p;
331
    int32_t m = Bstrtol(parm->parms[0], &p, 10);
99 terminx 332
 
4015 helixhorne 333
    if (m != REND_CLASSIC && m != REND_POLYMOST && m != REND_POLYMER)
334
        return OSDCMD_SHOWHELP;
99 terminx 335
 
4015 helixhorne 336
    if ((m==REND_CLASSIC) != (bpp==8) && baselayer_osdcmd_vidmode_func)
337
    {
338
        // Mismatch between video mode and requested renderer, do auto switch.
339
        osdfuncparm_t parm;
340
        char arg[4];
341
 
342
        const char *ptrptr[1];
343
        ptrptr[0] = arg;
344
 
345
        Bmemset(&parm, 0, sizeof(parm));
346
 
347
        if (m==REND_CLASSIC)
348
            Bmemcpy(&arg, "8", 2);
349
        else
350
            Bmemcpy(&arg, "32", 3);
351
 
352
        // CAUTION: we assume that the osdcmd_vidmode function doesn't use any
353
        // other member!
354
        parm.numparms = 1;
355
        parm.parms = ptrptr;
356
 
357
        baselayer_osdcmd_vidmode_func(&parm);
358
    }
359
 
109 terminx 360
    setrendermode(m);
99 terminx 361
 
5547 terminx 362
    char const *renderer;
363
 
4015 helixhorne 364
    switch (getrendermode())
3347 terminx 365
    {
366
    case REND_CLASSIC:
5547 terminx 367
        renderer = "classic software";
3347 terminx 368
        break;
369
    case REND_POLYMOST:
5547 terminx 370
        renderer = "polygonal OpenGL";
3347 terminx 371
        break;
372
    case REND_POLYMER:
5547 terminx 373
        renderer = "great justice (Polymer)";
3347 terminx 374
        break;
5558 hendricks2 375
    default:
376
        EDUKE32_UNREACHABLE_SECTION(break);
3347 terminx 377
    }
378
 
5547 terminx 379
    OSD_Printf("Rendering method changed to %s\n", renderer);
3347 terminx 380
 
109 terminx 381
    return OSDCMD_OK;
99 terminx 382
}
855 terminx 383
#if defined(USE_OPENGL)
99 terminx 384
#ifdef DEBUGGINGAIDS
1205 terminx 385
static int32_t osdcmd_hicsetpalettetint(const osdfuncparm_t *parm)
99 terminx 386
{
1205 terminx 387
    int32_t pal, cols[3], eff;
109 terminx 388
 
389
    if (parm->numparms != 5) return OSDCMD_SHOWHELP;
390
 
391
    pal = Batol(parm->parms[0]);
392
    cols[0] = Batol(parm->parms[1]);
393
    cols[1] = Batol(parm->parms[2]);
394
    cols[2] = Batol(parm->parms[3]);
395
    eff = Batol(parm->parms[4]);
396
 
397
    hicsetpalettetint(pal,cols[0],cols[1],cols[2],eff);
398
 
399
    return OSDCMD_OK;
99 terminx 400
}
401
#endif
402
 
1205 terminx 403
int32_t osdcmd_glinfo(const osdfuncparm_t *parm)
99 terminx 404
{
109 terminx 405
    char *s,*t,*u,i;
99 terminx 406
 
654 terminx 407
    UNREFERENCED_PARAMETER(parm);
408
 
584 terminx 409
    if (bpp == 8)
410
    {
5001 terminx 411
        initprintf("glinfo: not in OpenGL mode!\n");
109 terminx 412
        return OSDCMD_OK;
413
    }
414
 
5001 terminx 415
    initprintf("OpenGL information\n %s %s %s\n",
416
               glinfo.vendor, glinfo.renderer, glinfo.version);
848 terminx 417
 
418
    if (!glinfo.dumped)
419
        return OSDCMD_OK;
420
 
421
    initprintf(" Maximum anisotropy:      %.1f%s\n"
109 terminx 422
               " BGRA textures:           %s\n"
1506 plagman 423
               " Non-power-of-2 textures: %s\n"
5001 terminx 424
               " Clamp-to-edge:           %s\n"
425
               " Multitexturing:          %s\n"
426
               " Frame Buffer Objects:    %s\n"
109 terminx 427
               " Texure compression:      %s\n"
5001 terminx 428
#ifndef EDUKE32_GLES
109 terminx 429
               " Multisampling:           %s\n"
5001 terminx 430
               " NVIDIA multisample hint: %s\n"
446 Plagman 431
               " ARBfp fragment programs: %s\n"
432
               " Depth textures:          %s\n"
433
               " Shadow textures:         %s\n"
434
               " Rectangle textures:      %s\n"
519 Plagman 435
               " env_combine:             %s\n"
436
               " Vertex Buffer Objects:   %s\n"
1222 plagman 437
               " Shader Model 4:          %s\n"
1506 plagman 438
               " Occlusion queries:       %s\n"
439
               " GLSL:                    %s\n"
2056 plagman 440
               " Debug Output:            %s\n"
5298 Plagman 441
               " Buffer Storage:          %s\n"
5001 terminx 442
#endif
109 terminx 443
               " Extensions:\n",
444
               glinfo.maxanisotropy, glinfo.maxanisotropy>1.0?"":" (no anisotropic filtering)",
445
               glinfo.bgra ? "supported": "not supported",
446
               glinfo.texnpot ? "supported": "not supported",
447
               glinfo.clamptoedge ? "supported": "not supported",
5001 terminx 448
               glinfo.multitex ? "supported": "not supported",
449
               glinfo.fbos ? "supported": "not supported",
450
               glinfo.texcompr ? "supported": "not supported"
451
#ifndef EDUKE32_GLES
452
               ,glinfo.multisample ? "supported": "not supported",
446 Plagman 453
               glinfo.nvmultisamplehint ? "supported": "not supported",
454
               glinfo.arbfp ? "supported": "not supported",
455
               glinfo.depthtex ? "supported": "not supported",
456
               glinfo.shadow ? "supported": "not supported",
519 Plagman 457
               glinfo.rect ? "supported": "not supported",
458
               glinfo.envcombine ? "supported": "not supported",
1222 plagman 459
               glinfo.vbos ? "supported": "not supported",
1506 plagman 460
               glinfo.sm4 ? "supported": "not supported",
461
               glinfo.occlusionqueries ? "supported": "not supported",
2056 plagman 462
               glinfo.glsl ? "supported": "not supported",
5298 Plagman 463
               glinfo.debugoutput ? "supported": "not supported",
464
               glinfo.bufferstorage ? "supported" : "not supported"
5001 terminx 465
#endif
109 terminx 466
              );
467
 
468
    s = Bstrdup(glinfo.extensions);
1740 helixhorne 469
    if (!s) initprintf("%s", glinfo.extensions);
584 terminx 470
    else
471
    {
109 terminx 472
        i = 0; t = u = s;
584 terminx 473
        while (*t)
474
        {
475
            if (*t == ' ')
476
            {
477
                if (i&1)
478
                {
109 terminx 479
                    *t = 0;
627 terminx 480
                    initprintf("   %s\n",u);
109 terminx 481
                    u = t+1;
482
                }
483
                i++;
484
            }
485
            t++;
486
        }
627 terminx 487
        if (i&1) initprintf("   %s\n",u);
109 terminx 488
        Bfree(s);
489
    }
490
 
491
    return OSDCMD_OK;
99 terminx 492
}
493
#endif
855 terminx 494
#endif
99 terminx 495
 
1665 terminx 496
static int32_t osdcmd_cvar_set_baselayer(const osdfuncparm_t *parm)
99 terminx 497
{
1665 terminx 498
    int32_t r = osdcmd_cvar_set(parm);
109 terminx 499
 
1665 terminx 500
    if (r != OSDCMD_OK) return r;
501
 
502
    if (!Bstrcasecmp(parm->name, "vid_gamma") || !Bstrcasecmp(parm->name, "vid_brightness") || !Bstrcasecmp(parm->name, "vid_contrast"))
503
    {
1781 plagman 504
        setbrightness(GAMMA_CALC,0,0);
1665 terminx 505
 
506
        return r;
109 terminx 507
    }
1665 terminx 508
 
509
    return r;
99 terminx 510
}
511
 
1205 terminx 512
int32_t baselayer_init(void)
99 terminx 513
{
1352 terminx 514
    uint32_t i;
2601 helixhorne 515
#ifdef _WIN32
516
// on Windows, don't save the "r_screenaspect" cvar because the physical screen size is
517
// determined at startup
518
# define SCREENASPECT_CVAR_TYPE (CVAR_UINT|CVAR_NOSAVE)
519
#else
520
# define SCREENASPECT_CVAR_TYPE (CVAR_UINT)
521
#endif
1352 terminx 522
    cvar_t cvars_engine[] =
523
    {
3783 terminx 524
        { "r_usenewaspect","enable/disable new screen aspect ratio determination code",(void *) &r_usenewaspect, CVAR_BOOL, 0, 1 },
525
        { "r_screenaspect","if using r_usenewaspect and in fullscreen, screen aspect ratio in the form XXYY, e.g. 1609 for 16:9",
2959 helixhorne 526
          (void *) &r_screenxy, SCREENASPECT_CVAR_TYPE, 0, 9999 },
3783 terminx 527
        { "r_novoxmips","turn off/on the use of mipmaps when rendering 8-bit voxels",(void *) &novoxmips, CVAR_BOOL, 0, 1 },
528
        { "r_voxels","enable/disable automatic sprite->voxel rendering",(void *) &usevoxels, CVAR_BOOL, 0, 1 },
2024 helixhorne 529
#ifdef YAX_ENABLE
3783 terminx 530
        { "r_tror_nomaskpass", "enable/disable additional pass in TROR software rendering", (void *)&r_tror_nomaskpass, CVAR_BOOL, 0, 1 },
2024 helixhorne 531
#endif
4327 terminx 532
        { "r_windowpositioning", "enable/disable window position memory", (void *) &windowpos, CVAR_BOOL, 0, 1 },
4664 terminx 533
        { "vid_gamma","adjusts gamma component of gamma ramp",(void *) &vid_gamma, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
534
        { "vid_contrast","adjusts contrast component of gamma ramp",(void *) &vid_contrast, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
535
        { "vid_brightness","adjusts brightness component of gamma ramp",(void *) &vid_brightness, CVAR_FLOAT|CVAR_FUNCPTR, 0, 10 },
3349 terminx 536
#ifdef DEBUGGINGAIDS
1762 terminx 537
        { "debug1","debug counter",(void *) &debug1, CVAR_FLOAT, -100000, 100000 },
538
        { "debug2","debug counter",(void *) &debug2, CVAR_FLOAT, -100000, 100000 },
3349 terminx 539
#endif
4261 helixhorne 540
#ifdef DEBUG_MASK_DRAWING
4264 helixhorne 541
        { "debug_maskdrawmode", "Show mask draw orders", (void *)&g_maskDrawMode, CVAR_BOOL, 0, 1 },
4261 helixhorne 542
#endif
1352 terminx 543
    };
544
 
4385 terminx 545
    for (i=0; i<ARRAY_SIZE(cvars_engine); i++)
1352 terminx 546
    {
1625 terminx 547
        if (OSD_RegisterCvar(&cvars_engine[i]))
548
            continue;
549
 
1857 terminx 550
        OSD_RegisterFunction(cvars_engine[i].name, cvars_engine[i].desc,
1762 terminx 551
                             (cvars_engine[i].type & CVAR_FUNCPTR) ? osdcmd_cvar_set_baselayer : osdcmd_cvar_set);
1352 terminx 552
    }
553
 
1820 terminx 554
#ifdef USE_OPENGL
109 terminx 555
    OSD_RegisterFunction("setrendermode","setrendermode <number>: sets the engine's rendering mode.\n"
556
                         "Mode numbers are:\n"
557
                         "   0 - Classic Build software\n"
558
                         "   3 - Polygonal OpenGL\n"
1652 terminx 559
                         "   4 - Great justice renderer (Polymer)\n"
109 terminx 560
                         ,
561
                         osdfunc_setrendermode);
5419 hendricks2 562
 
1564 plagman 563
# ifdef DEBUGGINGAIDS
109 terminx 564
    OSD_RegisterFunction("hicsetpalettetint","hicsetpalettetint: sets palette tinting values",osdcmd_hicsetpalettetint);
1564 plagman 565
# endif
5419 hendricks2 566
 
109 terminx 567
    OSD_RegisterFunction("glinfo","glinfo: shows OpenGL information about the current OpenGL mode",osdcmd_glinfo);
5419 hendricks2 568
 
1352 terminx 569
    polymost_initosdfuncs();
99 terminx 570
#endif
1352 terminx 571
 
109 terminx 572
    return 0;
99 terminx 573
}
574
 
3377 helixhorne 575
void maybe_redirect_outputs(void)
576
{
577
#if !(defined __APPLE__ && defined __BIG_ENDIAN__)
578
    char *argp;
579
 
580
    // pipe standard outputs to files
581
    if ((argp = Bgetenv("BUILD_LOGSTDOUT")) != NULL)
582
        if (!Bstrcasecmp(argp, "TRUE"))
583
        {
584
            FILE *fp = freopen("stdout.txt", "w", stdout);
585
 
586
            if (!fp)
587
                fp = fopen("stdout.txt", "w");
588
 
589
            if (fp)
590
            {
591
                setvbuf(fp, 0, _IONBF, 0);
592
                *stdout = *fp;
593
                *stderr = *fp;
594
            }
595
        }
596
#endif
597
}