-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_sdl.c
More file actions
138 lines (105 loc) · 3.32 KB
/
main_sdl.c
File metadata and controls
138 lines (105 loc) · 3.32 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
Copyright (C) 1996-2001 Id Software, Inc.
Copyright (C) 2002-2005 John Fitzgibbons and others
Copyright (C) 2007-2008 Kristian Duske
Copyright (C) 2010-2014 QuakeSpasm developers
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.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include "quakedef.h"
#include <SDL2/SDL.h>
#include <stdio.h>
static void Sys_AtExit(void) {
SDL_Quit();
}
static void Sys_InitSDL(void) {
#if defined(USE_SDL2)
SDL_version v;
SDL_version* sdl_version = &v;
SDL_GetVersion(&v);
#else
const SDL_version* sdl_version = SDL_Linked_Version();
#endif
Sys_Printf("Found SDL version %i.%i.%i\n", sdl_version->major,
sdl_version->minor, sdl_version->patch);
if (SDL_Init(0) < 0) {
Sys_Error("Couldn't init SDL: %s", SDL_GetError());
}
atexit(Sys_AtExit);
}
#define DEFAULT_MEMORY \
(256 * 1024 * 1024) // ericw -- was 72MB (64-bit) / 64MB (32-bit)
static quakeparms_t parms;
// On OS X we call SDL_main from the launcher, but SDL2 doesn't redefine main
// as SDL_main on OS X anymore, so we do it ourselves.
/* #if defined(USE_SDL2) && defined(__APPLE__) */
/* #define main SDL_main */
/* #endif */
int main(int argc, char* argv[]) {
int t;
double time, oldtime, newtime;
host_parms = &parms;
parms.basedir = ".";
parms.argc = argc;
parms.argv = argv;
parms.errstate = 0;
COM_InitArgv(parms.argc, parms.argv);
isDedicated = (COM_CheckParm("-dedicated") != 0);
Sys_InitSDL();
Sys_Init();
Sys_Printf("Initializing QuakeSpasm v%s\n", QUAKESPASM_VER_STRING);
parms.memsize = DEFAULT_MEMORY;
if (COM_CheckParm("-heapsize")) {
t = COM_CheckParm("-heapsize") + 1;
if (t < com_argc)
parms.memsize = Q_atoi(com_argv[t]) * 1024;
}
parms.membase = malloc(parms.memsize);
if (!parms.membase)
Sys_Error("Not enough memory free; check disk space\n");
Sys_Printf("Host_Init\n");
Host_Init();
oldtime = Sys_DoubleTime();
if (isDedicated) {
while (1) {
newtime = Sys_DoubleTime();
time = newtime - oldtime;
while (time < sys_ticrate.value) {
SDL_Delay(1);
newtime = Sys_DoubleTime();
time = newtime - oldtime;
}
Host_Frame(time);
oldtime = newtime;
}
} else
while (1) {
/* If we have no input focus at all, sleep a bit */
if (!VID_HasMouseOrInputFocus() || cl.paused) {
SDL_Delay(16);
}
/* If we're minimised, sleep a bit more */
if (VID_IsMinimized()) {
scr_skipupdate = 1;
SDL_Delay(32);
} else {
scr_skipupdate = 0;
}
newtime = Sys_DoubleTime();
time = newtime - oldtime;
Host_Frame(time);
if (time < sys_throttle.value && !cls.timedemo)
SDL_Delay(1);
oldtime = newtime;
}
return 0;
}