-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathd_main.c
168 lines (131 loc) · 3.65 KB
/
d_main.c
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* Emacs style mode select -*- C++ -*-
*-----------------------------------------------------------------------------
*
*
* PrBoom: a Doom port merged with LxDoom and LSDLDoom
* based on BOOM, a modified and improved DOOM engine
* Copyright (C) 1999 by
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman
* Copyright (C) 1999-2004 by
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze
* Copyright 2005, 2006 by
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko
* Copyright 2023, 2024 by
* Frenkel Smeijers
*
* 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.
*
* DESCRIPTION:
* DOOM main program (D_DoomMain) and game loop (D_DoomLoop),
* plus functions to
* parse command line parameters, configure game parameters (turbo),
* and call the startup functions.
*
*-----------------------------------------------------------------------------
*/
#include <stdint.h>
#include "doomdef.h"
#include "doomtype.h"
#include "d_player.h"
#include "d_englsh.h"
#include "sounds.h"
#include "z_zone.h"
#include "w_wad.h"
#include "v_video.h"
#include "i_system.h"
#include "g_game.h"
#include "st_stuff.h"
#include "p_setup.h"
#include "r_main.h"
#include "d_main.h"
#include "globdata.h"
static int16_t maketic;
static void D_BuildNewTiccmds(void)
{
// Somehow the Macintosh build doesn't work when this code is removed
#if defined macintosh
static int16_t lastmadetic = 0;
static int16_t ticcount = 0;
int16_t newtics = ++ticcount - lastmadetic; // newtics == 1
lastmadetic += newtics;
while (newtics--)
{
if (maketic - _g_gametic > 3)
break;
G_BuildTiccmd();
maketic++;
}
#endif
}
//
// D_Display
// draw current display, possibly wiping it from the previous
//
static void D_Display (void)
{
if (!G_IsGameticEqualToBasetic())
{ // In a level
// Now do the drawing
R_RenderPlayerView (&_g_player);
ST_doPaletteStuff();
ST_Drawer();
}
D_BuildNewTiccmds();
// normal update
I_FinishUpdate (); // page flip or blit buffer
}
//
// D_DoomLoop()
//
static void _Noreturn D_DoomLoop(void)
{
for (;;)
{
// frame syncronous IO operations
// process one or more tics
G_BuildTiccmd ();
G_Ticker ();
_g_gametic++;
maketic++;
// Update display, next frame, with current state.
D_Display();
}
}
//
// D_DoomMainSetup
//
// CPhipps - the old contents of D_DoomMain, but moved out of the main
// line of execution so its stack space can be freed
static void D_DoomMainSetup(void)
{
// init subsystems
Z_Init();
G_ReloadDefaults(); // killough 3/4/98: set defaults just loaded.
W_Init(); // CPhipps - handling of wadfiles init changed
R_Init();
P_Init();
ST_Init();
I_InitGraphics();
G_DeferedPlayDemo();
}
//
// D_DoomMain
//
void D_DoomMain(void)
{
D_DoomMainSetup(); // CPhipps - setup out of main execution stack
D_DoomLoop (); // never returns
}