Subversion Repositories eduke32

Rev

Rev 5001 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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