-
Notifications
You must be signed in to change notification settings - Fork 2
/
winsys.h
110 lines (95 loc) · 3.01 KB
/
winsys.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/* --------------------------------------------------------------------
EXTREME TUXRACER
Copyright (C) 1999-2001 Jasmin F. Patry (Tuxracer)
Copyright (C) 2010 Extreme Tuxracer Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
---------------------------------------------------------------------*/
#ifndef WINSYS_H
#define WINSYS_H
#include "bh.h"
#define NUM_RESOLUTIONS 10
typedef void (*TInitFuncN) (void);
typedef void (*TLoopFuncN) (double time_step);
typedef void (*TTermFuncN) (void);
typedef void (*TMouseFuncN) (int button, int state, int x, int y);
typedef void (*TMotionFuncN) (int x, int y);
typedef void (*TKeybFuncN) (unsigned int key, bool special, bool release, int x, int y);
typedef void (*TJAxisFuncN) (int axis, double value);
typedef void (*TJButtFuncN) (int button, int state);
typedef void (*TKeybFuncS) (SDL_Keysym sym, bool release);
typedef struct {
TInitFuncN init;
TLoopFuncN loop;
TTermFuncN term;
TKeybFuncN keyb;
TMouseFuncN mouse;
TMotionFuncN motion;
TJAxisFuncN jaxis;
TJButtFuncN jbutt;
TKeybFuncS keyb_spec;
} TModeFuncsN;
class CWinsys {
private:
// time
float clock_time;
float cur_time;
float lasttick;
float elapsed_time;
int remain_ticks;
// joystick
SDL_Joystick *joystick;
int numJoysticks;
bool joystick_active;
// sdl window
TScreenRes resolution[NUM_RESOLUTIONS];
int auto_x_resolution;
int auto_y_resolution;
SDL_Window *window;
SDL_Renderer *renderer;
SDL_GLContext context;
TScreenRes MakeRes (int width, int height);
double CalcScreenScale ();
// modes and loop
TModeFuncsN modefuncs [NUM_GAME_MODES];
TGameMode new_mode;
void IdleFunc ();
void PollEvent ();
void ChangeMode ();
void CallLoopFunction ();
public:
CWinsys ();
~CWinsys ();
// sdl window
TScreenRes GetResolution (int idx);
string GetResName (int idx);
void Init ();
void SetupVideoMode (TScreenRes resolution);
void SetupVideoMode (int idx);
void SetupVideoMode (int width, int height);
void KeyRepeat (bool repeat);
void SetFonttype ();
void PrintJoystickInfo ();
void ShowCursor (bool visible) {SDL_ShowCursor (visible);}
void SwapBuffers ();
void Delay (unsigned int ms);
void Quit ();
void InitJoystick ();
void CloseJoystick ();
void SetModeFuncs (
TGameMode mode, TInitFuncN init, TLoopFuncN loop, TTermFuncN term,
TKeybFuncN keyb, TMouseFuncN mouse, TMotionFuncN motion,
TJAxisFuncN jaxis, TJButtFuncN jbutt, TKeybFuncS keyb_spec);
void EventLoop ();
void SetMode (TGameMode mode) {new_mode = mode;}
bool ModePending ();
double ClockTime () {return SDL_GetTicks() * 1.e-3; }
};
extern CWinsys Winsys;
#endif