| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright (C) 1999 by |
| 8 |
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 |
* Copyright (C) 1999-2000 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: |
| 30 |
* Contains the main wait loop, waiting for the next tic. |
| 31 |
* Rewritten for LxDoom, but based around bits of the old code. |
| 32 |
* |
| 33 |
*----------------------------------------------------------------------------- |
| 34 |
*/ |
| 35 |
|
| 36 |
#ifdef HAVE_CONFIG_H |
| 37 |
#include "config.h" |
| 38 |
#endif |
| 39 |
#include <sys/types.h> |
| 40 |
#ifdef HAVE_UNISTD_H |
| 41 |
#include <unistd.h> |
| 42 |
#endif |
| 43 |
#ifdef HAVE_SYS_WAIT_H |
| 44 |
#include <sys/wait.h> |
| 45 |
#endif |
| 46 |
|
| 47 |
#include "doomtype.h" |
| 48 |
#include "doomstat.h" |
| 49 |
#include "d_net.h" |
| 50 |
#include "z_zone.h" |
| 51 |
|
| 52 |
#include "d_main.h" |
| 53 |
#include "g_game.h" |
| 54 |
#include "m_menu.h" |
| 55 |
|
| 56 |
#include "i_system.h" |
| 57 |
#include "i_main.h" |
| 58 |
#include "i_video.h" |
| 59 |
#include "r_fps.h" |
| 60 |
#include "lprintf.h" |
| 61 |
#include "e6y.h" |
| 62 |
|
| 63 |
#include "dsda/args.h" |
| 64 |
#include "dsda/settings.h" |
| 65 |
#include "dsda/time.h" |
| 66 |
|
| 67 |
ticcmd_t local_cmds[MAX_MAXPLAYERS][BACKUPTICS]; |
| 68 |
int maketic; |
| 69 |
int solo_net = 0; |
| 70 |
|
| 71 |
void D_InitFakeNetGame (void) |
| 72 |
{ |
| 73 |
int i; |
| 74 |
|
| 75 |
consoleplayer = displayplayer = 0; |
| 76 |
solo_net = dsda_Flag(dsda_arg_solo_net); |
| 77 |
coop_spawns = dsda_Flag(dsda_arg_coop_spawns); |
| 78 |
netgame = solo_net; |
| 79 |
|
| 80 |
playeringame[0] = true; |
| 81 |
for (i = 1; i < g_maxplayers; i++) |
| 82 |
playeringame[i] = false; |
| 83 |
} |
| 84 |
|
| 85 |
void FakeNetUpdate(void) |
| 86 |
{ |
| 87 |
static int lastmadetic; |
| 88 |
|
| 89 |
if (isExtraDDisplay) |
| 90 |
return; |
| 91 |
|
| 92 |
{ // Build new ticcmds |
| 93 |
int newtics = dsda_GetTick() - lastmadetic; |
| 94 |
lastmadetic += newtics; |
| 95 |
|
| 96 |
while (newtics--) { |
| 97 |
I_StartTic(); |
| 98 |
if (maketic - gametic > BACKUPTICS/2) break; |
| 99 |
|
| 100 |
// e6y |
| 101 |
// Eliminating the sudden jump of six frames(BACKUPTICS/2) |
| 102 |
// after change of game_speed. |
| 103 |
if (maketic - gametic && gametic <= force_singletics_to && dsda_GameSpeed() < 200) break; |
| 104 |
|
| 105 |
G_BuildTiccmd(&local_cmds[0][maketic%BACKUPTICS]); |
| 106 |
maketic++; |
| 107 |
} |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
// Implicitly tracked whenever we check the current tick |
| 112 |
int ms_to_next_tick; |
| 113 |
|
| 114 |
void TryRunTics (void) |
| 115 |
{ |
| 116 |
int runtics; |
| 117 |
int entertime = dsda_GetTick(); |
| 118 |
|
| 119 |
// Wait for tics to run |
| 120 |
while (1) { |
| 121 |
FakeNetUpdate(); |
| 122 |
runtics = maketic - gametic; |
| 123 |
if (!runtics) { |
| 124 |
if (!movement_smooth) { |
| 125 |
I_uSleep(ms_to_next_tick*1000); |
| 126 |
} |
| 127 |
if (dsda_GetTick() - entertime > 10) { |
| 128 |
M_Ticker(); return; |
| 129 |
} |
| 130 |
|
| 131 |
if (gametic > 0) |
| 132 |
{ |
| 133 |
WasRenderedInTryRunTics = true; |
| 134 |
if (movement_smooth && gamestate==wipegamestate) |
| 135 |
{ |
| 136 |
isExtraDDisplay = true; |
| 137 |
D_Display(-1); |
| 138 |
isExtraDDisplay = false; |
| 139 |
} |
| 140 |
} |
| 141 |
} else break; |
| 142 |
} |
| 143 |
|
| 144 |
while (runtics--) { |
| 145 |
if (advancedemo) |
| 146 |
D_DoAdvanceDemo (); |
| 147 |
M_Ticker (); |
| 148 |
G_Ticker (); |
| 149 |
gametic++; |
| 150 |
FakeNetUpdate(); |
| 151 |
} |
| 152 |
} |