| 1 |
// |
| 2 |
// Copyright(C) 2022 by Ryan Krafnick |
| 3 |
// |
| 4 |
// This program is free software; you can redistribute it and/or |
| 5 |
// modify it under the terms of the GNU General Public License |
| 6 |
// as published by the Free Software Foundation; either version 2 |
| 7 |
// of the License, or (at your option) any later version. |
| 8 |
// |
| 9 |
// This program is distributed in the hope that it will be useful, |
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
// GNU General Public License for more details. |
| 13 |
// |
| 14 |
// DESCRIPTION: |
| 15 |
// DSDA Skip Mode |
| 16 |
// |
| 17 |
|
| 18 |
#include "d_main.h" |
| 19 |
#include "doomstat.h" |
| 20 |
#include "e6y.h" |
| 21 |
#include "i_main.h" |
| 22 |
#include "i_sound.h" |
| 23 |
#include "s_sound.h" |
| 24 |
#include "smooth.h" |
| 25 |
#include "v_video.h" |
| 26 |
#include "gl_struct.h" |
| 27 |
|
| 28 |
#include "dsda/args.h" |
| 29 |
#include "dsda/build.h" |
| 30 |
#include "dsda/demo.h" |
| 31 |
#include "dsda/features.h" |
| 32 |
#include "dsda/pause.h" |
| 33 |
#include "dsda/playback.h" |
| 34 |
|
| 35 |
#include "skip.h" |
| 36 |
|
| 37 |
static dboolean skip_mode; |
| 38 |
|
| 39 |
static int demo_skiptics; |
| 40 |
static dboolean skip_until_next_map; |
| 41 |
static dboolean skip_until_end_of_map; |
| 42 |
static dboolean skip_until_logictic; |
| 43 |
static dboolean demo_warp_reached; |
| 44 |
static int skip_until_map; |
| 45 |
static int skip_until_episode; |
| 46 |
|
| 47 |
dboolean dsda_SkipMode(void) { |
| 48 |
return skip_mode; |
| 49 |
} |
| 50 |
|
| 51 |
static void dsda_CacheSkipSetting(dboolean* old, dboolean* current) { |
| 52 |
*old = *current; |
| 53 |
*current = true; |
| 54 |
} |
| 55 |
|
| 56 |
static dboolean old_fastdemo, old_nodrawers, old_nosfxparm, old_nomusicparm; |
| 57 |
|
| 58 |
static void dsda_ApplySkipSettings(void) { |
| 59 |
if (skip_mode) |
| 60 |
return; |
| 61 |
|
| 62 |
dsda_CacheSkipSetting(&old_fastdemo, &fastdemo); |
| 63 |
dsda_CacheSkipSetting(&old_nodrawers, &nodrawers); |
| 64 |
dsda_CacheSkipSetting(&old_nosfxparm, &nosfxparm); |
| 65 |
dsda_CacheSkipSetting(&old_nomusicparm, &nomusicparm); |
| 66 |
} |
| 67 |
|
| 68 |
static void dsda_ResetSkipSettings(void) { |
| 69 |
fastdemo = old_fastdemo; |
| 70 |
nodrawers = old_nodrawers; |
| 71 |
nosfxparm = old_nosfxparm; |
| 72 |
nomusicparm = old_nomusicparm; |
| 73 |
} |
| 74 |
|
| 75 |
void dsda_EnterSkipMode(void) { |
| 76 |
extern void M_ClearMenus(void); |
| 77 |
|
| 78 |
dsda_TrackFeature(uf_skip); |
| 79 |
dsda_ApplySkipSettings(); |
| 80 |
|
| 81 |
skip_mode = true; |
| 82 |
|
| 83 |
M_ClearMenus(); |
| 84 |
dsda_ResetPauseMode(); |
| 85 |
S_StopMusic(); |
| 86 |
I_Init2(); |
| 87 |
|
| 88 |
if (dsda_BuildMode()) |
| 89 |
dsda_ApplyPauseMode(PAUSE_BUILDMODE); |
| 90 |
} |
| 91 |
|
| 92 |
void dsda_ExitSkipMode(void) { |
| 93 |
skip_mode = false; |
| 94 |
|
| 95 |
dsda_ResetSkipSettings(); |
| 96 |
|
| 97 |
skip_until_next_map = false; |
| 98 |
skip_until_end_of_map = false; |
| 99 |
skip_until_logictic = 0; |
| 100 |
skip_until_map = -1; |
| 101 |
skip_until_episode = -1; |
| 102 |
demo_warp_reached = false; |
| 103 |
demo_skiptics = 0; |
| 104 |
|
| 105 |
I_Init2(); |
| 106 |
I_InitSound(); |
| 107 |
S_Init(); |
| 108 |
S_RestartMusic(); |
| 109 |
|
| 110 |
if (V_IsOpenGLMode()) |
| 111 |
gld_PreprocessLevel(); |
| 112 |
} |
| 113 |
|
| 114 |
void dsda_ToggleSkipMode(void) { |
| 115 |
dsda_SkipMode() ? dsda_ExitSkipMode() : dsda_EnterSkipMode(); |
| 116 |
} |
| 117 |
|
| 118 |
void dsda_SkipToNextMap(void) { |
| 119 |
skip_until_next_map = true; |
| 120 |
dsda_EnterSkipMode(); |
| 121 |
} |
| 122 |
|
| 123 |
void dsda_SkipToEndOfMap(void) { |
| 124 |
skip_until_end_of_map = true; |
| 125 |
dsda_EnterSkipMode(); |
| 126 |
} |
| 127 |
|
| 128 |
void dsda_SkipToLogicTic(int tic) { |
| 129 |
skip_until_logictic = tic; |
| 130 |
dsda_EnterSkipMode(); |
| 131 |
} |
| 132 |
|
| 133 |
void dsda_EvaluateSkipModeGTicker(void) { |
| 134 |
if (dsda_SkipMode() && skip_until_logictic && skip_until_logictic <= true_logictic) |
| 135 |
dsda_ExitSkipMode(); |
| 136 |
} |
| 137 |
|
| 138 |
void dsda_EvaluateSkipModeInitNew(void) { |
| 139 |
if (dsda_SkipMode() && skip_until_map == gamemap && skip_until_episode == gameepisode) |
| 140 |
demo_warp_reached = true; |
| 141 |
} |
| 142 |
|
| 143 |
void dsda_EvaluateSkipModeBuildTiccmd(void) { |
| 144 |
if (dsda_SkipMode() && gametic > 0) |
| 145 |
if ( |
| 146 |
( |
| 147 |
!skip_until_logictic && |
| 148 |
skip_until_map == -1 && |
| 149 |
demo_skiptics && |
| 150 |
( |
| 151 |
demo_skiptics > 0 ? |
| 152 |
gametic > demo_skiptics : |
| 153 |
dsda_DemoTic() - demo_skiptics >= demo_tics_count |
| 154 |
) |
| 155 |
) || |
| 156 |
( |
| 157 |
demo_warp_reached && gametic - levelstarttic > demo_skiptics |
| 158 |
) |
| 159 |
) |
| 160 |
dsda_ExitSkipMode(); |
| 161 |
} |
| 162 |
|
| 163 |
void dsda_EvaluateSkipModeDoCompleted(void) { |
| 164 |
if (dsda_SkipMode() && (skip_until_end_of_map || demo_warp_reached)) |
| 165 |
dsda_ExitSkipMode(); |
| 166 |
} |
| 167 |
|
| 168 |
void dsda_EvaluateSkipModeDoTeleportNewMap(void) { |
| 169 |
if (dsda_SkipMode()) { |
| 170 |
static int firstmap = 1; |
| 171 |
|
| 172 |
demo_warp_reached = skip_until_next_map || |
| 173 |
( |
| 174 |
gamemode == commercial ? |
| 175 |
(skip_until_map == gamemap) : |
| 176 |
(skip_until_episode == gameepisode && skip_until_map == gamemap) |
| 177 |
); |
| 178 |
|
| 179 |
if (demo_warp_reached && demo_skiptics == 0 && !firstmap) |
| 180 |
dsda_ExitSkipMode(); |
| 181 |
|
| 182 |
firstmap = 0; |
| 183 |
} |
| 184 |
} |
| 185 |
|
| 186 |
void dsda_EvaluateSkipModeDoWorldDone(void) { |
| 187 |
if (dsda_SkipMode()) { |
| 188 |
static int firstmap = 1; |
| 189 |
|
| 190 |
demo_warp_reached = skip_until_next_map || |
| 191 |
( |
| 192 |
gamemode == commercial ? |
| 193 |
(skip_until_map == gamemap) : |
| 194 |
(skip_until_episode == gameepisode && skip_until_map == gamemap) |
| 195 |
); |
| 196 |
|
| 197 |
if (demo_warp_reached && demo_skiptics == 0 && !firstmap) |
| 198 |
dsda_ExitSkipMode(); |
| 199 |
|
| 200 |
firstmap = 0; |
| 201 |
} |
| 202 |
} |
| 203 |
|
| 204 |
void dsda_EvaluateSkipModeCheckDemoStatus(void) { |
| 205 |
if (dsda_SkipMode() && (skip_until_end_of_map || skip_until_next_map)) |
| 206 |
dsda_ExitSkipMode(); |
| 207 |
} |
| 208 |
|
| 209 |
void dsda_HandleSkip(void) { |
| 210 |
extern int warpmap; |
| 211 |
extern int warpepisode; |
| 212 |
|
| 213 |
dsda_arg_t* arg; |
| 214 |
|
| 215 |
arg = dsda_Arg(dsda_arg_skipsec); |
| 216 |
if (arg->found) { |
| 217 |
float min, sec; |
| 218 |
|
| 219 |
if (sscanf(arg->value.v_string, "%f:%f", &min, &sec) == 2) |
| 220 |
demo_skiptics = (int) ((60 * min + sec) * TICRATE); |
| 221 |
else if (sscanf(arg->value.v_string, "%f", &sec) == 1) |
| 222 |
demo_skiptics = (int) (sec * TICRATE); |
| 223 |
} |
| 224 |
|
| 225 |
arg = dsda_Arg(dsda_arg_skiptic); |
| 226 |
if (arg->found) |
| 227 |
demo_skiptics = arg->value.v_int; |
| 228 |
|
| 229 |
if (dsda_PlaybackName() && (warpmap != -1 || demo_skiptics)) { |
| 230 |
skip_until_map = warpmap; |
| 231 |
skip_until_episode = warpepisode; |
| 232 |
|
| 233 |
dsda_EnterSkipMode(); |
| 234 |
} |
| 235 |
} |