Subversion Repositories eduke32

Rev

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

Rev Author Line No. Line
476 terminx 1
// Base services interface declaration
2
// for the Build Engine
2456 hendricks2 3
// by Jonathon Fowler (jf@jonof.id.au)
476 terminx 4
 
5664 terminx 5
#pragma once
6
 
4747 terminx 7
#ifndef baselayer_h_
8
#define baselayer_h_
476 terminx 9
 
618 terminx 10
#include "compat.h"
895 terminx 11
#include "osd.h"
7976 terminx 12
#include "timer.h"
618 terminx 13
 
4766 hendricks2 14
#ifdef __cplusplus
476 terminx 15
extern "C" {
16
#endif
17
 
5828 terminx 18
extern int app_main(int argc, char const * const * argv);
4538 hendricks2 19
extern const char* AppProperName;
20
extern const char* AppTechnicalName;
21
 
4261 helixhorne 22
#ifdef DEBUGGINGAIDS
23
# define DEBUG_MASK_DRAWING
24
extern int32_t g_maskDrawMode;
25
#endif
26
 
476 terminx 27
extern char quitevent, appactive;
5794 terminx 28
extern char modechange;
8082 terminx 29
extern char nogl;
476 terminx 30
 
1205 terminx 31
extern int32_t vsync;
8063 terminx 32
extern int32_t r_borderless;
33
extern int32_t r_displayindex;
889 terminx 34
 
3221 hendricks2 35
extern void app_crashhandler(void);
36
 
194 terminx 37
// NOTE: these are implemented in game-land so they may be overridden in game specific ways
1205 terminx 38
extern int32_t startwin_open(void);
39
extern int32_t startwin_close(void);
40
extern int32_t startwin_puts(const char *);
41
extern int32_t startwin_settitle(const char *);
42
extern int32_t startwin_idle(void *);
4766 hendricks2 43
extern int32_t startwin_run(void);
194 terminx 44
 
476 terminx 45
// video
1712 helixhorne 46
extern int32_t r_usenewaspect, newaspect_enable;
7755 terminx 47
extern int32_t r_fpgrouscan;
2913 helixhorne 48
extern int32_t setaspect_new_use_dimen;
1712 helixhorne 49
extern uint32_t r_screenxy;
8612 terminx 50
extern int32_t xres, yres, bpp, fullscreen, bytesperline;
51
extern double refreshfreq;
618 terminx 52
extern intptr_t frameplace;
476 terminx 53
extern char offscreenrendering;
4997 terminx 54
extern int32_t nofog;
476 terminx 55
 
8716 terminx 56
extern int32_t r_maxfps;
57
extern int32_t r_maxfpsoffset;
58
 
3291 helixhorne 59
void calc_ylookup(int32_t bpl, int32_t lastyidx);
60
 
6828 terminx 61
int32_t videoCheckMode(int32_t *x, int32_t *y, int32_t c, int32_t fs, int32_t forced);
62
int32_t videoSetMode(int32_t x, int32_t y, int32_t c, int32_t fs);
63
void    videoGetModes(void);
64
void    videoResetMode(void);
65
void    videoEndDrawing(void);
66
void    videoShowFrame(int32_t);
67
int32_t videoUpdatePalette(int32_t start, int32_t num);
68
int32_t videoSetGamma(void);
69
int32_t videoSetVsync(int32_t newSync);
70
 
71
//#define DEBUG_FRAME_LOCKING
72
#if !defined DEBUG_FRAME_LOCKING
73
void videoBeginDrawing(void);
74
#else
75
void begindrawing_real(void);
76
# define BEGINDRAWING_SIZE 256
77
extern uint32_t begindrawing_line[BEGINDRAWING_SIZE];
78
extern const char *begindrawing_file[BEGINDRAWING_SIZE];
79
extern int32_t lockcount;
80
# define videoBeginDrawing() do {                     \
81
    if (lockcount < BEGINDRAWING_SIZE) {         \
82
        begindrawing_line[lockcount] = __LINE__; \
83
        begindrawing_file[lockcount] = __FILE__; \
84
    }                                            \
85
    begindrawing_real();                         \
86
} while(0)
87
#endif
88
 
89
extern float g_videoGamma, g_videoContrast, g_videoBrightness;
90
 
91
#define DEFAULT_GAMMA 1.0f
92
#define DEFAULT_CONTRAST 1.0f
93
#define DEFAULT_BRIGHTNESS 0.0f
94
 
95
#define GAMMA_CALC ((int32_t)(min(max((float)((g_videoGamma - 1.0f) * 10.0f), 0.f), 15.f)))
96
 
476 terminx 97
#ifdef USE_OPENGL
7154 terminx 98
extern int32_t (*baselayer_osdcmd_vidmode_func)(osdcmdptr_t parm);
99
extern int osdcmd_glinfo(osdcmdptr_t parm);
627 terminx 100
 
1625 terminx 101
struct glinfo_t {
476 terminx 102
    const char *vendor;
103
    const char *renderer;
104
    const char *version;
105
    const char *extensions;
106
 
1506 plagman 107
    float maxanisotropy;
8710 terminx 108
 
109
    int filled;
110
 
111
    union {
112
        uint32_t features;
113
        struct
114
        {
115
            int bgra             : 1;
116
            int bufferstorage    : 1;
117
            int clamptoedge      : 1;
118
            int debugoutput      : 1;
119
            int depthclamp       : 1;
120
            int depthtex         : 1;
121
            int fbos             : 1;
122
            int glsl             : 1;
123
            int multitex         : 1;
124
            int occlusionqueries : 1;
125
            int rect             : 1;
126
            int shadow           : 1;
127
            int sync             : 1;
128
            int texcompr         : 1;
129
            int texnpot          : 1;
130
            int vbos             : 1;
131
            int vsync            : 1;
132
        };
133
    };
476 terminx 134
};
1454 terminx 135
 
1625 terminx 136
extern struct glinfo_t glinfo;
8710 terminx 137
 
138
extern void fill_glinfo(void);
476 terminx 139
#endif
6827 terminx 140
 
7159 terminx 141
vec2_t CONSTEXPR const g_defaultVideoModes []
7223 terminx 142
= { { 2560, 1440 }, { 2560, 1200 }, { 2560, 1080 }, { 1920, 1440 }, { 1920, 1200 }, { 1920, 1080 }, { 1680, 1050 },
7159 terminx 143
    { 1600, 1200 }, { 1600, 900 },  { 1366, 768 },  { 1280, 1024 }, { 1280, 960 },  { 1280, 720 },  { 1152, 864 },
144
    { 1024, 768 },  { 1024, 600 },  { 800, 600 },   { 640, 480 },   { 640, 400 },   { 512, 384 },   { 480, 360 },
145
    { 400, 300 },   { 320, 240 },   { 320, 200 },   { 0, 0 } };
146
 
476 terminx 147
extern char inputdevices;
148
 
149
// keys
4472 hendricks2 150
#define NUMKEYS 256
476 terminx 151
#define KEYFIFOSIZ 64
152
 
7223 terminx 153
char CONSTEXPR const g_keyAsciiTable[128] = {
7159 terminx 154
 
155
    '[', ']', 0,   0,   'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', 39, '`', 0,   92,  'z', 'x', 'c', 'v', 'b', 'n', 'm', ',',
156
    '.', '/', 0,   '*', 0,   32,  0,   0,   0,   0,   0,   0,   0,   0,   0,  0,   0,   0,   0,   '7', '8', '9', '-', '4', '5', '6',
157
    '+', '1', '2', '3', '0', '.', 0,   0,   0,   0,   0,   0,   0,   0,   0,  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
158
 
159
};
160
 
8429 hendricks2 161
char CONSTEXPR const g_keyAsciiTableShift[128] = {
162
 
163
    '{', '}', 0,   0,   'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~', 0,   '|',  'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<',
164
    '>', '?', 0,   '*', 0,   32,  0,   0,   0,   0,   0,   0,   0,   0,   0,  0,   0,   0,   0,   '7', '8', '9', '-', '4', '5', '6',
165
    '+', '1', '2', '3', '0', '.', 0,   0,   0,   0,   0,   0,   0,   0,   0,  0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
166
 
167
};
168
 
6827 terminx 169
extern char    keystatus[NUMKEYS];
170
extern char    g_keyFIFO[KEYFIFOSIZ];
171
extern char    g_keyAsciiFIFO[KEYFIFOSIZ];
172
extern uint8_t g_keyAsciiPos;
173
extern uint8_t g_keyAsciiEnd;
174
extern uint8_t g_keyFIFOend;
175
extern char    g_keyRemapTable[NUMKEYS];
176
extern char    g_keyNameTable[NUMKEYS][24];
1819 plagman 177
 
6827 terminx 178
extern int32_t keyGetState(int32_t key);
179
extern void keySetState(int32_t key, int32_t state);
1652 terminx 180
 
476 terminx 181
// mouse
6827 terminx 182
extern vec2_t  g_mousePos;
183
extern vec2_t  g_mouseAbs;
184
extern int32_t g_mouseBits;
185
extern uint8_t g_mouseClickState;
186
extern bool    g_mouseGrabbed;
187
extern bool    g_mouseEnabled;
188
extern bool    g_mouseInsideWindow;
189
extern bool    g_mouseLockedToWindow;
190
 
4853 hendricks2 191
enum
192
{
6827 terminx 193
    MOUSE_IDLE = 0,
194
    MOUSE_PRESSED,
195
    MOUSE_HELD,
196
    MOUSE_RELEASED,
4853 hendricks2 197
};
6827 terminx 198
extern int32_t mouseAdvanceClickState(void);
476 terminx 199
 
200
// joystick
201
 
6827 terminx 202
typedef struct
203
{
204
    int32_t *pAxis;
205
    int32_t *pHat;
206
    void (*pCallback)(int32_t, int32_t);
207
    int32_t  bits;
208
    int32_t  numAxes;
8367 terminx 209
    int32_t  numBalls;
6827 terminx 210
    int32_t  numButtons;
211
    int32_t  numHats;
7958 hendricks2 212
    int32_t  isGameController;
6827 terminx 213
} controllerinput_t;
214
 
215
extern controllerinput_t joystick;
216
 
1205 terminx 217
extern int32_t qsetmode;
476 terminx 218
 
4039 terminx 219
#define in3dmode() (qsetmode==200)
3823 helixhorne 220
 
1205 terminx 221
int32_t initsystem(void);
476 terminx 222
void uninitsystem(void);
4090 hendricks2 223
void system_getcvars(void);
476 terminx 224
 
6827 terminx 225
extern int32_t g_logFlushWindow;
4555 hendricks2 226
void initputs(const char *);
227
#define buildputs initputs
1740 helixhorne 228
void initprintf(const char *, ...) ATTRIBUTE((format(printf,1,2)));
4555 hendricks2 229
#define buildprintf initprintf
1740 helixhorne 230
void debugprintf(const char *,...) ATTRIBUTE((format(printf,1,2)));
476 terminx 231
 
1205 terminx 232
int32_t handleevents(void);
3022 helixhorne 233
int32_t handleevents_peekkeys(void);
476 terminx 234
 
1652 terminx 235
extern void (*keypresscallback)(int32_t,int32_t);
6827 terminx 236
extern void (*g_mouseCallback)(int32_t,int32_t);
1652 terminx 237
 
8005 terminx 238
int32_t initinput(void);
476 terminx 239
void uninitinput(void);
6827 terminx 240
void keySetCallback(void (*callback)(int32_t,int32_t));
241
void mouseSetCallback(void (*callback)(int32_t,int32_t));
242
void joySetCallback(void (*callback)(int32_t,int32_t));
243
const char *keyGetName(int32_t num);
244
const char *joyGetName(int32_t what, int32_t num); // what: 0=axis, 1=button, 2=hat
7985 hendricks2 245
void joyScanDevices(void);
476 terminx 246
 
8429 hendricks2 247
char keyGetScan(void);
6827 terminx 248
char keyGetChar(void);
249
#define keyBufferWaiting() (g_keyAsciiPos != g_keyAsciiEnd)
1625 terminx 250
 
6827 terminx 251
static FORCE_INLINE int keyBufferFull(void)
4116 helixhorne 252
{
6827 terminx 253
    return ((g_keyAsciiEnd+1)&(KEYFIFOSIZ-1)) == g_keyAsciiPos;
4116 helixhorne 254
}
255
 
6827 terminx 256
static FORCE_INLINE void keyBufferInsert(char code)
4116 helixhorne 257
{
6827 terminx 258
    g_keyAsciiFIFO[g_keyAsciiEnd] = code;
259
    g_keyAsciiEnd = ((g_keyAsciiEnd+1)&(KEYFIFOSIZ-1));
4116 helixhorne 260
}
261
 
8429 hendricks2 262
void keyFlushScans(void);
6827 terminx 263
void keyFlushChars(void);
476 terminx 264
 
7181 terminx 265
void mouseInit(void);
6827 terminx 266
void mouseUninit(void);
7073 terminx 267
int32_t mouseReadAbs(vec2_t *pResult, vec2_t const *pInput);
6851 terminx 268
void mouseGrabInput(bool grab);
6827 terminx 269
void mouseLockToWindow(char a);
7181 terminx 270
int32_t mouseReadButtons(void);
6827 terminx 271
void mouseReadPos(int32_t *x, int32_t *y);
272
 
7073 terminx 273
void joyReadButtons(int32_t *pResult);
6827 terminx 274
void joySetDeadZone(int32_t axis, uint16_t dead, uint16_t satur);
275
void joyGetDeadZone(int32_t axis, uint16_t *dead, uint16_t *satur);
4200 hendricks2 276
extern int32_t inputchecked;
476 terminx 277
 
4558 hendricks2 278
int32_t wm_msgbox(const char *name, const char *fmt, ...) ATTRIBUTE((format(printf,2,3)));
279
int32_t wm_ynbox(const char *name, const char *fmt, ...) ATTRIBUTE((format(printf,2,3)));
280
void wm_setapptitle(const char *name);
476 terminx 281
 
282
// baselayer.c
1205 terminx 283
int32_t baselayer_init();
476 terminx 284
 
582 terminx 285
void makeasmwriteable(void);
3377 helixhorne 286
void maybe_redirect_outputs(void);
582 terminx 287
 
8716 terminx 288
extern uint64_t g_frameDelay;
289
static inline uint64_t calcFrameDelay(int const maxFPS, int const offset)
290
{
291
    uint64_t const perfFreq = timerGetPerformanceFrequency();
292
 
293
    if (maxFPS == -1)
294
        return perfFreq / (refreshfreq - ceil(refreshfreq / 60.0));
295
 
296
    return maxFPS ? perfFreq / (maxFPS + offset) : 0;
297
}
298
extern int engineFPSLimit(void);
4766 hendricks2 299
#ifdef __cplusplus
476 terminx 300
}
301
#endif
302
 
6139 hendricks2 303
#include "print.h"
304
 
4747 terminx 305
#endif // baselayer_h_
476 terminx 306