| 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 |
* |
| 31 |
*----------------------------------------------------------------------------- |
| 32 |
*/ |
| 33 |
|
| 34 |
#include "doomdef.h" |
| 35 |
#include "dsda/demo.h" |
| 36 |
#include "r_patch.h" |
| 37 |
#include "st_stuff.h" |
| 38 |
#ifdef HAVE_CONFIG_H |
| 39 |
#include "config.h" |
| 40 |
#endif |
| 41 |
#ifdef _WIN32 |
| 42 |
#define WIN32_LEAN_AND_MEAN |
| 43 |
#include <windows.h> |
| 44 |
#include <direct.h> |
| 45 |
#include <winreg.h> |
| 46 |
#endif |
| 47 |
#include <SDL_opengl.h> |
| 48 |
#include <string.h> |
| 49 |
#include <math.h> |
| 50 |
|
| 51 |
#include <stdio.h> |
| 52 |
#include <stdarg.h> |
| 53 |
#include <stdlib.h> |
| 54 |
|
| 55 |
#include "SDL.h" |
| 56 |
#ifdef _WIN32 |
| 57 |
#include <SDL_syswm.h> |
| 58 |
#endif |
| 59 |
|
| 60 |
#include "hu_lib.h" |
| 61 |
|
| 62 |
#include "doomtype.h" |
| 63 |
#include "doomstat.h" |
| 64 |
#include "d_main.h" |
| 65 |
#include "s_sound.h" |
| 66 |
#include "i_system.h" |
| 67 |
#include "i_main.h" |
| 68 |
#include "i_sound.h" |
| 69 |
#include "m_menu.h" |
| 70 |
#include "lprintf.h" |
| 71 |
#include "m_file.h" |
| 72 |
#include "i_system.h" |
| 73 |
#include "p_maputl.h" |
| 74 |
#include "p_map.h" |
| 75 |
#include "p_setup.h" |
| 76 |
#include "i_video.h" |
| 77 |
#include "info.h" |
| 78 |
#include "r_main.h" |
| 79 |
#include "r_things.h" |
| 80 |
#include "r_sky.h" |
| 81 |
#include "am_map.h" |
| 82 |
#include "dsda.h" |
| 83 |
#include "dsda/settings.h" |
| 84 |
#include "gl_struct.h" |
| 85 |
#include "gl_intern.h" |
| 86 |
#include "g_game.h" |
| 87 |
#include "d_deh.h" |
| 88 |
#include "e6y.h" |
| 89 |
#include "m_file.h" |
| 90 |
#include "v_video.h" |
| 91 |
|
| 92 |
#include "dsda/args.h" |
| 93 |
#include "dsda/configuration.h" |
| 94 |
#include "dsda/excmd.h" |
| 95 |
#include "dsda/key_frame.h" |
| 96 |
#include "dsda/map_format.h" |
| 97 |
#include "dsda/mapinfo.h" |
| 98 |
#include "dsda/playback.h" |
| 99 |
#include "dsda/skip.h" |
| 100 |
#include "dsda/stretch.h" |
| 101 |
|
| 102 |
dboolean wasWiped = false; |
| 103 |
|
| 104 |
int secretfound; |
| 105 |
int demo_playerscount; |
| 106 |
int demo_tics_count; |
| 107 |
char demo_len_st[80]; |
| 108 |
|
| 109 |
int mouse_handler; |
| 110 |
int gl_render_fov = 90; |
| 111 |
|
| 112 |
camera_t walkcamera; |
| 113 |
|
| 114 |
angle_t viewpitch; |
| 115 |
float skyscale; |
| 116 |
float screen_skybox_zplane; |
| 117 |
float tan_pitch; |
| 118 |
float skyUpAngle; |
| 119 |
float skyUpShift; |
| 120 |
float skyXShift; |
| 121 |
float skyYShift; |
| 122 |
|
| 123 |
#ifdef _WIN32 |
| 124 |
const char* WINError(void) |
| 125 |
{ |
| 126 |
static char *WinEBuff = NULL; |
| 127 |
DWORD err = GetLastError(); |
| 128 |
char *ch; |
| 129 |
|
| 130 |
if (WinEBuff) |
| 131 |
{ |
| 132 |
LocalFree(WinEBuff); |
| 133 |
} |
| 134 |
|
| 135 |
if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, |
| 136 |
NULL, err, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
| 137 |
(LPTSTR) &WinEBuff, 0, NULL) == 0) |
| 138 |
{ |
| 139 |
return "Unknown error"; |
| 140 |
} |
| 141 |
|
| 142 |
if ((ch = strchr(WinEBuff, '\n')) != 0) |
| 143 |
*ch = 0; |
| 144 |
if ((ch = strchr(WinEBuff, '\r')) != 0) |
| 145 |
*ch = 0; |
| 146 |
|
| 147 |
return WinEBuff; |
| 148 |
} |
| 149 |
#endif |
| 150 |
|
| 151 |
//-------------------------------------------------- |
| 152 |
|
| 153 |
/* ParamsMatchingCheck |
| 154 |
* Conflicting command-line parameters could cause the engine to be confused |
| 155 |
* in some cases. Added checks to prevent this. |
| 156 |
* Example: dsda-doom.exe -record mydemo -playdemo demoname |
| 157 |
*/ |
| 158 |
void ParamsMatchingCheck() |
| 159 |
{ |
| 160 |
dboolean recording_attempt = |
| 161 |
dsda_Flag(dsda_arg_record) || |
| 162 |
dsda_Flag(dsda_arg_recordfromto); |
| 163 |
|
| 164 |
dboolean playbacking_attempt = |
| 165 |
dsda_Flag(dsda_arg_playdemo) || |
| 166 |
dsda_Flag(dsda_arg_timedemo) || |
| 167 |
dsda_Flag(dsda_arg_fastdemo); |
| 168 |
|
| 169 |
if (recording_attempt && playbacking_attempt) |
| 170 |
I_Error("Params are not matching: Can not being played back and recorded at the same time."); |
| 171 |
} |
| 172 |
|
| 173 |
prboom_comp_t prboom_comp[PC_MAX] = { |
| 174 |
{0xffffffff, 0x02020615, 0, dsda_arg_force_monster_avoid_hazards}, |
| 175 |
{0x00000000, 0x02040601, 0, dsda_arg_force_remove_slime_trails}, |
| 176 |
{0x02020200, 0x02040801, 0, dsda_arg_force_no_dropoff}, |
| 177 |
{0x00000000, 0x02040801, 0, dsda_arg_force_truncated_sector_specials}, |
| 178 |
{0x00000000, 0x02040802, 0, dsda_arg_force_boom_brainawake}, |
| 179 |
{0x00000000, 0x02040802, 0, dsda_arg_force_prboom_friction}, |
| 180 |
{0x02020500, 0x02040000, 0, dsda_arg_reject_pad_with_ff}, |
| 181 |
{0xffffffff, 0x02040802, 0, dsda_arg_force_lxdoom_demo_compatibility}, |
| 182 |
{0x00000000, 0x0202061b, 0, dsda_arg_allow_ssg_direct}, |
| 183 |
{0x00000000, 0x02040601, 0, dsda_arg_treat_no_clipping_things_as_not_blocking}, |
| 184 |
{0x00000000, 0x02040803, 0, dsda_arg_force_incorrect_processing_of_respawn_frame_entry}, |
| 185 |
{0x00000000, 0x02040601, 0, dsda_arg_force_correct_code_for_3_keys_doors_in_mbf}, |
| 186 |
{0x00000000, 0x02040601, 0, dsda_arg_uninitialize_crush_field_for_stairs}, |
| 187 |
{0x00000000, 0x02040802, 0, dsda_arg_force_boom_findnexthighestfloor}, |
| 188 |
{0x00000000, 0x02040802, 0, dsda_arg_allow_sky_transfer_in_boom}, |
| 189 |
{0x00000000, 0x02040803, 0, dsda_arg_apply_green_armor_class_to_armor_bonuses}, |
| 190 |
{0x00000000, 0x02040803, 0, dsda_arg_apply_blue_armor_class_to_megasphere}, |
| 191 |
{0x02020200, 0x02050003, 0, dsda_arg_force_incorrect_bobbing_in_boom}, |
| 192 |
{0xffffffff, 0x00000000, 0, dsda_arg_boom_deh_parser}, |
| 193 |
{0x00000000, 0x02050007, 0, dsda_arg_mbf_remove_thinker_in_killmobj}, |
| 194 |
{0x00000000, 0x02050007, 0, dsda_arg_do_not_inherit_friendlyness_flag_on_spawn}, |
| 195 |
{0x00000000, 0x02050007, 0, dsda_arg_do_not_use_misc12_frame_parameters_in_a_mushroom}, |
| 196 |
{0x00000000, 0x02050102, 0, dsda_arg_apply_mbf_codepointers_to_any_complevel}, |
| 197 |
{0x00000000, 0x02050104, 0, dsda_arg_reset_monsterspawner_params_after_loading}, |
| 198 |
}; |
| 199 |
|
| 200 |
void M_ChangeShorttics(void) |
| 201 |
{ |
| 202 |
shorttics = dsda_IntConfig(dsda_config_movement_shorttics) || dsda_Flag(dsda_arg_shorttics); |
| 203 |
} |
| 204 |
|
| 205 |
void e6y_InitCommandLine(void) |
| 206 |
{ |
| 207 |
stats_level = dsda_Flag(dsda_arg_levelstat); |
| 208 |
|
| 209 |
if ((stroller = dsda_Flag(dsda_arg_stroller))) |
| 210 |
dsda_UpdateIntArg(dsda_arg_turbo, "50"); |
| 211 |
|
| 212 |
dsda_ReadCommandLine(); |
| 213 |
|
| 214 |
M_ChangeShorttics(); |
| 215 |
} |
| 216 |
|
| 217 |
int G_ReloadLevel(void) |
| 218 |
{ |
| 219 |
int result = false; |
| 220 |
|
| 221 |
if ((gamestate == GS_LEVEL || gamestate == GS_INTERMISSION) && |
| 222 |
allow_incompatibility && |
| 223 |
!menuactive) |
| 224 |
{ |
| 225 |
G_DeferedInitNew(gameskill, gameepisode, gamemap); |
| 226 |
result = true; |
| 227 |
} |
| 228 |
|
| 229 |
if (demoplayback) |
| 230 |
{ |
| 231 |
dsda_RestartPlayback(); |
| 232 |
result = true; |
| 233 |
} |
| 234 |
|
| 235 |
dsda_WatchLevelReload(&result); |
| 236 |
|
| 237 |
return result; |
| 238 |
} |
| 239 |
|
| 240 |
int G_GotoNextLevel(void) |
| 241 |
{ |
| 242 |
int epsd, map; |
| 243 |
int changed = false; |
| 244 |
|
| 245 |
dsda_NextMap(&epsd, &map); |
| 246 |
|
| 247 |
if ((gamestate == GS_LEVEL) && |
| 248 |
allow_incompatibility && |
| 249 |
!menuactive) |
| 250 |
{ |
| 251 |
G_DeferedInitNew(gameskill, epsd, map); |
| 252 |
changed = true; |
| 253 |
} |
| 254 |
|
| 255 |
return changed; |
| 256 |
} |
| 257 |
|
| 258 |
int G_GotoPrevLevel(void) |
| 259 |
{ |
| 260 |
int epsd, map; |
| 261 |
int changed = false; |
| 262 |
|
| 263 |
dsda_PrevMap(&epsd, &map); |
| 264 |
|
| 265 |
if ((gamestate == GS_LEVEL) && |
| 266 |
allow_incompatibility && |
| 267 |
!menuactive) |
| 268 |
{ |
| 269 |
G_DeferedInitNew(gameskill, epsd, map); |
| 270 |
changed = true; |
| 271 |
} |
| 272 |
|
| 273 |
return changed; |
| 274 |
} |
| 275 |
|
| 276 |
void M_ChangeSpeed(void) |
| 277 |
{ |
| 278 |
G_SetSpeed(true); |
| 279 |
} |
| 280 |
|
| 281 |
void M_ChangeSkyMode(void) |
| 282 |
{ |
| 283 |
int gl_skymode; |
| 284 |
|
| 285 |
viewpitch = 0; |
| 286 |
|
| 287 |
R_InitSkyMap(); |
| 288 |
|
| 289 |
gl_skymode = dsda_IntConfig(dsda_config_gl_skymode); |
| 290 |
|
| 291 |
if (gl_skymode == skytype_auto) |
| 292 |
gl_drawskys = (dsda_FreeAim() ? skytype_skydome : skytype_standard); |
| 293 |
else |
| 294 |
gl_drawskys = gl_skymode; |
| 295 |
} |
| 296 |
|
| 297 |
static const int upViewPitchLimit = -ANG90 + (1 << ANGLETOFINESHIFT); |
| 298 |
static const int downViewPitchLimit = ANG90 - (1 << ANGLETOFINESHIFT); |
| 299 |
|
| 300 |
void M_ChangeScreenMultipleFactor(void) |
| 301 |
{ |
| 302 |
V_ChangeScreenResolution(); |
| 303 |
} |
| 304 |
|
| 305 |
dboolean HaveMouseLook(void) |
| 306 |
{ |
| 307 |
return (viewpitch != 0); |
| 308 |
} |
| 309 |
|
| 310 |
void CheckPitch(signed int *pitch) |
| 311 |
{ |
| 312 |
if (*pitch < upViewPitchLimit) |
| 313 |
*pitch = upViewPitchLimit; |
| 314 |
|
| 315 |
if (*pitch > downViewPitchLimit) |
| 316 |
*pitch = downViewPitchLimit; |
| 317 |
|
| 318 |
(*pitch) >>= 16; |
| 319 |
(*pitch) <<= 16; |
| 320 |
} |
| 321 |
|
| 322 |
float gl_render_ratio; |
| 323 |
float gl_render_fovratio; |
| 324 |
float gl_render_fovy = FOV90; |
| 325 |
float gl_render_multiplier; |
| 326 |
|
| 327 |
void M_ChangeAspectRatio(void) |
| 328 |
{ |
| 329 |
M_ChangeFOV(); |
| 330 |
|
| 331 |
R_SetViewSize(); |
| 332 |
} |
| 333 |
|
| 334 |
void M_ChangeStretch(void) |
| 335 |
{ |
| 336 |
render_stretch_hud = dsda_IntConfig(dsda_config_render_stretch_hud); |
| 337 |
|
| 338 |
R_SetViewSize(); |
| 339 |
} |
| 340 |
|
| 341 |
void M_ChangeFOV(void) |
| 342 |
{ |
| 343 |
float f1, f2; |
| 344 |
dsda_arg_t* arg; |
| 345 |
int gl_render_aspect_width, gl_render_aspect_height; |
| 346 |
|
| 347 |
arg = dsda_Arg(dsda_arg_aspect); |
| 348 |
if ( |
| 349 |
arg->found && |
| 350 |
sscanf(arg->value.v_string, "%dx%d", &gl_render_aspect_width, &gl_render_aspect_height) == 2 |
| 351 |
) |
| 352 |
{ |
| 353 |
SetRatio(SCREENWIDTH, SCREENHEIGHT); |
| 354 |
gl_render_fovratio = (float)gl_render_aspect_width / (float)gl_render_aspect_height; |
| 355 |
gl_render_ratio = RMUL * gl_render_fovratio; |
| 356 |
gl_render_multiplier = 64.0f / gl_render_fovratio / RMUL; |
| 357 |
} |
| 358 |
else |
| 359 |
{ |
| 360 |
SetRatio(SCREENWIDTH, SCREENHEIGHT); |
| 361 |
gl_render_ratio = gl_ratio; |
| 362 |
gl_render_multiplier = (float)ratio_multiplier; |
| 363 |
if (!tallscreen) |
| 364 |
{ |
| 365 |
gl_render_fovratio = 1.6f; |
| 366 |
} |
| 367 |
else |
| 368 |
{ |
| 369 |
gl_render_fovratio = gl_render_ratio; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
gl_render_fovy = (float)(2 * RAD2DEG(atan(tan(DEG2RAD(gl_render_fov) / 2) / gl_render_fovratio))); |
| 374 |
|
| 375 |
screen_skybox_zplane = 320.0f/2.0f/(float)tan(DEG2RAD(gl_render_fov/2)); |
| 376 |
|
| 377 |
f1 = (float)(320.0f / 200.0f * (float)gl_render_fov / (float)FOV90 - 0.2f); |
| 378 |
f2 = (float)tan(DEG2RAD(gl_render_fovy)/2.0f); |
| 379 |
if (f1-f2<1) |
| 380 |
skyUpAngle = (float)-RAD2DEG(asin(f1-f2)); |
| 381 |
else |
| 382 |
skyUpAngle = -90.0f; |
| 383 |
|
| 384 |
skyUpShift = (float)tan(DEG2RAD(gl_render_fovy)/2.0f); |
| 385 |
|
| 386 |
skyscale = 1.0f / (float)tan(DEG2RAD(gl_render_fov / 2)); |
| 387 |
} |
| 388 |
|
| 389 |
float viewPitch; |
| 390 |
|
| 391 |
int StepwiseSum(int value, int direction, int minval, int maxval, int defval) |
| 392 |
{ |
| 393 |
int newvalue; |
| 394 |
int val = (direction > 0 ? value : value - 1); |
| 395 |
|
| 396 |
if (direction == 0) |
| 397 |
return defval; |
| 398 |
|
| 399 |
direction = (direction > 0 ? 1 : -1); |
| 400 |
|
| 401 |
{ |
| 402 |
int exp = 1; |
| 403 |
while (exp * 10 <= val) |
| 404 |
exp *= 10; |
| 405 |
newvalue = direction * (val < exp * 5 && exp > 1 ? exp / 2 : exp); |
| 406 |
newvalue = (value + newvalue) / newvalue * newvalue; |
| 407 |
} |
| 408 |
|
| 409 |
if (newvalue > maxval) newvalue = maxval; |
| 410 |
if (newvalue < minval) newvalue = minval; |
| 411 |
|
| 412 |
if ((value < defval && newvalue > defval) || (value > defval && newvalue < defval)) |
| 413 |
newvalue = defval; |
| 414 |
|
| 415 |
return newvalue; |
| 416 |
} |
| 417 |
|
| 418 |
void I_vWarning(const char *message, va_list argList) |
| 419 |
{ |
| 420 |
char msg[1024]; |
| 421 |
vsnprintf(msg,sizeof(msg),message,argList); |
| 422 |
lprintf(LO_ERROR, "%s\n", msg); |
| 423 |
#ifdef _WIN32 |
| 424 |
I_MessageBox(msg, PRB_MB_OK); |
| 425 |
#endif |
| 426 |
} |
| 427 |
|
| 428 |
int I_MessageBox(const char* text, unsigned int type) |
| 429 |
{ |
| 430 |
#ifdef _WIN32 |
| 431 |
int result = PRB_IDCANCEL; |
| 432 |
|
| 433 |
if (!dsda_Flag(dsda_arg_no_message_box)) |
| 434 |
{ |
| 435 |
HWND current_hwnd = GetForegroundWindow(); |
| 436 |
wchar_t *wtext = ConvertUtf8ToWide(text); |
| 437 |
wchar_t *wpackage = ConvertUtf8ToWide(PROJECT_NAME); |
| 438 |
result = MessageBoxW(GetDesktopWindow(), wtext, wpackage, type|MB_TASKMODAL|MB_TOPMOST); |
| 439 |
Z_Free(wtext); |
| 440 |
Z_Free(wpackage); |
| 441 |
I_SwitchToWindow(current_hwnd); |
| 442 |
return result; |
| 443 |
} |
| 444 |
#endif |
| 445 |
|
| 446 |
return PRB_IDCANCEL; |
| 447 |
} |
| 448 |
|
| 449 |
int stats_level; |
| 450 |
int stroller; |
| 451 |
int numlevels = 0; |
| 452 |
int levels_max = 0; |
| 453 |
timetable_t *stats = NULL; |
| 454 |
|
| 455 |
void e6y_G_DoCompleted(void) |
| 456 |
{ |
| 457 |
int i; |
| 458 |
|
| 459 |
dsda_EvaluateSkipModeDoCompleted(); |
| 460 |
|
| 461 |
if(!stats_level) |
| 462 |
return; |
| 463 |
|
| 464 |
if (numlevels >= levels_max) |
| 465 |
{ |
| 466 |
levels_max = levels_max ? levels_max*2 : 32; |
| 467 |
stats = Z_Realloc(stats,sizeof(*stats)*levels_max); |
| 468 |
} |
| 469 |
|
| 470 |
memset(&stats[numlevels], 0, sizeof(timetable_t)); |
| 471 |
|
| 472 |
snprintf(stats[numlevels].map, sizeof(stats[numlevels].map), "%s", dsda_MapLumpName(gameepisode, gamemap)); |
| 473 |
|
| 474 |
if (secretexit) |
| 475 |
{ |
| 476 |
size_t end_of_string = strlen(stats[numlevels].map); |
| 477 |
if (end_of_string < 15) |
| 478 |
stats[numlevels].map[end_of_string] = 's'; |
| 479 |
} |
| 480 |
|
| 481 |
stats[numlevels].stat[TT_TIME] = leveltime; |
| 482 |
stats[numlevels].stat[TT_TOTALTIME] = totalleveltimes; |
| 483 |
stats[numlevels].stat[TT_TOTALKILL] = totalkills; |
| 484 |
stats[numlevels].stat[TT_TOTALITEM] = totalitems; |
| 485 |
stats[numlevels].stat[TT_TOTALSECRET] = totalsecret; |
| 486 |
|
| 487 |
for (i = 0; i < g_maxplayers; i++) |
| 488 |
{ |
| 489 |
if (playeringame[i]) |
| 490 |
{ |
| 491 |
stats[numlevels].kill[i] = players[i].killcount - players[i].maxkilldiscount; |
| 492 |
stats[numlevels].item[i] = players[i].itemcount; |
| 493 |
stats[numlevels].secret[i] = players[i].secretcount; |
| 494 |
|
| 495 |
stats[numlevels].stat[TT_ALLKILL] += stats[numlevels].kill[i]; |
| 496 |
stats[numlevels].stat[TT_ALLITEM] += stats[numlevels].item[i]; |
| 497 |
stats[numlevels].stat[TT_ALLSECRET] += stats[numlevels].secret[i]; |
| 498 |
} |
| 499 |
} |
| 500 |
|
| 501 |
numlevels++; |
| 502 |
|
| 503 |
e6y_WriteStats(); |
| 504 |
} |
| 505 |
|
| 506 |
typedef struct tmpdata_s |
| 507 |
{ |
| 508 |
char kill[200]; |
| 509 |
char item[200]; |
| 510 |
char secret[200]; |
| 511 |
} tmpdata_t; |
| 512 |
|
| 513 |
void e6y_WriteStats(void) |
| 514 |
{ |
| 515 |
FILE *f; |
| 516 |
char str[200]; |
| 517 |
int i, level, playerscount; |
| 518 |
timetable_t max; |
| 519 |
tmpdata_t tmp; |
| 520 |
tmpdata_t *all; |
| 521 |
size_t allkills_len=0, allitems_len=0, allsecrets_len=0; |
| 522 |
|
| 523 |
f = M_OpenFile("levelstat.txt", "wb"); |
| 524 |
|
| 525 |
if (f == NULL) |
| 526 |
{ |
| 527 |
lprintf(LO_ERROR, "Unable to open levelstat.txt for writing\n"); |
| 528 |
return; |
| 529 |
} |
| 530 |
|
| 531 |
all = Z_Malloc(sizeof(*all) * numlevels); |
| 532 |
memset(&max, 0, sizeof(timetable_t)); |
| 533 |
|
| 534 |
playerscount = 0; |
| 535 |
for (i = 0; i < g_maxplayers; i++) |
| 536 |
if (playeringame[i]) |
| 537 |
playerscount++; |
| 538 |
|
| 539 |
for (level=0;level<numlevels;level++) |
| 540 |
{ |
| 541 |
memset(&tmp, 0, sizeof(tmpdata_t)); |
| 542 |
for (i = 0; i < g_maxplayers; i++) |
| 543 |
{ |
| 544 |
if (playeringame[i]) |
| 545 |
{ |
| 546 |
char strtmp[200]; |
| 547 |
strcpy(str, tmp.kill[0] == '\0' ? "%s%d" : "%s+%d"); |
| 548 |
|
| 549 |
snprintf(strtmp, sizeof(strtmp), str, tmp.kill, stats[level].kill[i]); |
| 550 |
strcpy(tmp.kill, strtmp); |
| 551 |
|
| 552 |
snprintf(strtmp, sizeof(strtmp), str, tmp.item, stats[level].item[i]); |
| 553 |
strcpy(tmp.item, strtmp); |
| 554 |
|
| 555 |
snprintf(strtmp, sizeof(strtmp), str, tmp.secret, stats[level].secret[i]); |
| 556 |
strcpy(tmp.secret, strtmp); |
| 557 |
} |
| 558 |
} |
| 559 |
if (playerscount<2) |
| 560 |
memset(&all[level], 0, sizeof(tmpdata_t)); |
| 561 |
else |
| 562 |
{ |
| 563 |
snprintf(all[level].kill, sizeof(all[level].kill), " (%s)", tmp.kill ); |
| 564 |
snprintf(all[level].item, sizeof(all[level].item), " (%s)", tmp.item ); |
| 565 |
snprintf(all[level].secret, sizeof(all[level].secret), " (%s)", tmp.secret); |
| 566 |
} |
| 567 |
|
| 568 |
if (strlen(all[level].kill) > allkills_len) |
| 569 |
allkills_len = strlen(all[level].kill); |
| 570 |
if (strlen(all[level].item) > allitems_len) |
| 571 |
allitems_len = strlen(all[level].item); |
| 572 |
if (strlen(all[level].secret) > allsecrets_len) |
| 573 |
allsecrets_len = strlen(all[level].secret); |
| 574 |
|
| 575 |
for(i=0; i<TT_MAX; i++) |
| 576 |
if (stats[level].stat[i] > max.stat[i]) |
| 577 |
max.stat[i] = stats[level].stat[i]; |
| 578 |
} |
| 579 |
max.stat[TT_TIME] = max.stat[TT_TIME]/TICRATE/60; |
| 580 |
max.stat[TT_TOTALTIME] = max.stat[TT_TOTALTIME]/TICRATE/60; |
| 581 |
|
| 582 |
for(i=0; i<TT_MAX; i++) { |
| 583 |
snprintf(str, sizeof(str), "%d", max.stat[i]); |
| 584 |
max.stat[i] = strlen(str); |
| 585 |
} |
| 586 |
|
| 587 |
for (level=0;level<numlevels;level++) |
| 588 |
{ |
| 589 |
snprintf(str, sizeof(str), |
| 590 |
"%%s - %%%dd:%%05.2f (%%%dd:%%02d) K: %%%dd/%%-%dd%%%lds I: %%%dd/%%-%dd%%%lds S: %%%dd/%%-%dd %%%lds\r\n", |
| 591 |
max.stat[TT_TIME], max.stat[TT_TOTALTIME], |
| 592 |
max.stat[TT_ALLKILL], max.stat[TT_TOTALKILL], (long)allkills_len, |
| 593 |
max.stat[TT_ALLITEM], max.stat[TT_TOTALITEM], (long)allitems_len, |
| 594 |
max.stat[TT_ALLSECRET], max.stat[TT_TOTALSECRET], (long)allsecrets_len); |
| 595 |
|
| 596 |
fprintf(f, str, stats[level].map, |
| 597 |
stats[level].stat[TT_TIME]/TICRATE/60, |
| 598 |
(float)(stats[level].stat[TT_TIME]%(60*TICRATE))/TICRATE, |
| 599 |
(stats[level].stat[TT_TOTALTIME])/TICRATE/60, |
| 600 |
(stats[level].stat[TT_TOTALTIME]%(60*TICRATE))/TICRATE, |
| 601 |
stats[level].stat[TT_ALLKILL], stats[level].stat[TT_TOTALKILL], all[level].kill, |
| 602 |
stats[level].stat[TT_ALLITEM], stats[level].stat[TT_TOTALITEM], all[level].item, |
| 603 |
stats[level].stat[TT_ALLSECRET],stats[level].stat[TT_TOTALSECRET], all[level].secret |
| 604 |
); |
| 605 |
|
| 606 |
} |
| 607 |
|
| 608 |
Z_Free(all); |
| 609 |
fclose(f); |
| 610 |
} |
| 611 |
|
| 612 |
//-------------------------------------------------- |
| 613 |
|
| 614 |
static double mouse_accelfactor; |
| 615 |
static double analog_accelfactor; |
| 616 |
|
| 617 |
void AccelChanging(void) |
| 618 |
{ |
| 619 |
int mouse_acceleration; |
| 620 |
int analog_acceleration; |
| 621 |
|
| 622 |
mouse_acceleration = dsda_IntConfig(dsda_config_mouse_acceleration); |
| 623 |
mouse_accelfactor = (double) mouse_acceleration / 100.0 + 1.0; |
| 624 |
|
| 625 |
analog_acceleration = dsda_IntConfig(dsda_config_analog_look_acceleration); |
| 626 |
analog_accelfactor = (double) analog_acceleration / 100.0 + 1.0; |
| 627 |
} |
| 628 |
|
| 629 |
int AccelerateMouse(int val) |
| 630 |
{ |
| 631 |
if (!mouse_accelfactor) |
| 632 |
return val; |
| 633 |
|
| 634 |
if (val < 0) |
| 635 |
return -AccelerateMouse(-val); |
| 636 |
|
| 637 |
return M_DoubleToInt(pow((double) val, mouse_accelfactor)); |
| 638 |
} |
| 639 |
|
| 640 |
int AccelerateAnalog(float val) |
| 641 |
{ |
| 642 |
if (!analog_accelfactor) |
| 643 |
return val; |
| 644 |
|
| 645 |
if (val < 0) |
| 646 |
return -AccelerateAnalog(-val); |
| 647 |
|
| 648 |
return M_DoubleToInt(pow((double) val, analog_accelfactor)); |
| 649 |
} |
| 650 |
|
| 651 |
int mlooky = 0; |
| 652 |
|
| 653 |
void e6y_G_Compatibility(void) |
| 654 |
{ |
| 655 |
deh_applyCompatibility(); |
| 656 |
|
| 657 |
if (dsda_PlaybackName()) |
| 658 |
{ |
| 659 |
int i; |
| 660 |
dsda_arg_t* arg; |
| 661 |
|
| 662 |
//"2.4.8.2" -> 0x02040802 |
| 663 |
arg = dsda_Arg(dsda_arg_emulate); |
| 664 |
if (arg->found) |
| 665 |
{ |
| 666 |
unsigned int emulated_version = 0; |
| 667 |
int b[4], k = 1; |
| 668 |
memset(b, 0, sizeof(b)); |
| 669 |
sscanf(arg->value.v_string, "%d.%d.%d.%d", &b[0], &b[1], &b[2], &b[3]); |
| 670 |
for (i = 3; i >= 0; i--, k *= 256) |
| 671 |
{ |
| 672 |
#ifdef RANGECHECK |
| 673 |
if (b[i] >= 256) |
| 674 |
I_Error("Wrong version number of package: %s", PROJECT_VERSION); |
| 675 |
#endif |
| 676 |
emulated_version += b[i] * k; |
| 677 |
} |
| 678 |
|
| 679 |
for (i = 0; i < PC_MAX; i++) |
| 680 |
{ |
| 681 |
prboom_comp[i].state = |
| 682 |
(emulated_version >= prboom_comp[i].minver && |
| 683 |
emulated_version < prboom_comp[i].maxver); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
for (i = 0; i < PC_MAX; i++) |
| 688 |
{ |
| 689 |
if (dsda_Flag(prboom_comp[i].arg_id)) |
| 690 |
prboom_comp[i].state = true; |
| 691 |
} |
| 692 |
} |
| 693 |
|
| 694 |
P_CrossSubsector = P_CrossSubsector_PrBoom; |
| 695 |
if (!prboom_comp[PC_FORCE_LXDOOM_DEMO_COMPATIBILITY].state) |
| 696 |
{ |
| 697 |
if (demo_compatibility) |
| 698 |
P_CrossSubsector = P_CrossSubsector_Doom; |
| 699 |
|
| 700 |
switch (compatibility_level) |
| 701 |
{ |
| 702 |
case boom_compatibility_compatibility: |
| 703 |
case boom_201_compatibility: |
| 704 |
case boom_202_compatibility: |
| 705 |
case mbf_compatibility: |
| 706 |
case mbf21_compatibility: |
| 707 |
P_CrossSubsector = P_CrossSubsector_Boom; |
| 708 |
break; |
| 709 |
} |
| 710 |
} |
| 711 |
} |
| 712 |
|
| 713 |
const char* PathFindFileName(const char* pPath) |
| 714 |
{ |
| 715 |
const char* pT = pPath; |
| 716 |
|
| 717 |
if (pPath) |
| 718 |
{ |
| 719 |
for ( ; *pPath; pPath++) |
| 720 |
{ |
| 721 |
if ((pPath[0] == '\\' || pPath[0] == ':' || pPath[0] == '/') |
| 722 |
&& pPath[1] && pPath[1] != '\\' && pPath[1] != '/') |
| 723 |
pT = pPath + 1; |
| 724 |
} |
| 725 |
} |
| 726 |
|
| 727 |
return pT; |
| 728 |
} |
| 729 |
|
| 730 |
int levelstarttic; |
| 731 |
|
| 732 |
int force_singletics_to = 0; |
| 733 |
|
| 734 |
int HU_DrawDemoProgress(int force) |
| 735 |
{ |
| 736 |
extern int mouse_hide_timer; |
| 737 |
static unsigned int last_update = 0; |
| 738 |
static int prev_len = -1; |
| 739 |
|
| 740 |
int len, tics_count, diff; |
| 741 |
unsigned int tick, max_period; |
| 742 |
|
| 743 |
if (gamestate == GS_DEMOSCREEN || !demoplayback) |
| 744 |
return false; |
| 745 |
|
| 746 |
tics_count = demo_tics_count * demo_playerscount; |
| 747 |
len = MIN(SCREENWIDTH, (int)((int64_t)SCREENWIDTH * dsda_DemoTic() / tics_count)); |
| 748 |
|
| 749 |
if (!force) |
| 750 |
{ |
| 751 |
max_period = ((tics_count - dsda_DemoTic() > 35 * demo_playerscount) ? 500 : 15); |
| 752 |
|
| 753 |
// Unnecessary updates of progress bar |
| 754 |
// can slow down demo skipping and playback |
| 755 |
tick = SDL_GetTicks(); |
| 756 |
if (tick - last_update < max_period) |
| 757 |
return false; |
| 758 |
last_update = tick; |
| 759 |
|
| 760 |
// Do not update progress bar if difference is small |
| 761 |
diff = len - prev_len; |
| 762 |
if (diff == 0 || diff == 1) // because of static prev_len |
| 763 |
return false; |
| 764 |
} |
| 765 |
|
| 766 |
prev_len = len; |
| 767 |
|
| 768 |
if (dsda_IntConfig(dsda_config_playback_mouse_controls) && mouse_hide_timer > 0 && !timingdemo && !walkcamera.type) |
| 769 |
{ |
| 770 |
extern auto_kf_t* auto_key_frames; |
| 771 |
extern int auto_kf_size; |
| 772 |
extern dsda_key_frame_t* playback_key_frames; |
| 773 |
extern int playback_kf_size; |
| 774 |
extern dsda_key_frame_t quick_kf; |
| 775 |
int x; |
| 776 |
|
| 777 |
int bar_h = ST_SCALED_HEIGHT / 6; |
| 778 |
int bar_y = SCREENHEIGHT - bar_h; |
| 779 |
int inner_h = bar_h * 2/3; |
| 780 |
int inner_y = SCREENHEIGHT - bar_h + (bar_h - inner_h) / 2; |
| 781 |
|
| 782 |
V_FillRect(0, 0, bar_y, len, bar_h, playpal_lightest); |
| 783 |
if (len > 4) |
| 784 |
V_FillRect(0, 2, inner_y, len - 4, inner_h, playpal_darkest); |
| 785 |
|
| 786 |
// playback key frames in light blue |
| 787 |
for (int i = 0; i < playback_kf_size; i++) |
| 788 |
{ |
| 789 |
if (!playback_key_frames[i].buffer) continue; |
| 790 |
x = MIN(SCREENWIDTH, (int)((int64_t)SCREENWIDTH * playback_key_frames[i].game_tic_count / tics_count)); |
| 791 |
V_FillRect(0, x, inner_y, 1, inner_h, colrngs[CR_LIGHTBLUE][playpal_lightest]); |
| 792 |
} |
| 793 |
|
| 794 |
// rewind key frames in green |
| 795 |
for (int i = 0; i < auto_kf_size; i++) |
| 796 |
{ |
| 797 |
if (!auto_key_frames[i].kf.buffer) continue; |
| 798 |
x= MIN(SCREENWIDTH, (int)((int64_t)SCREENWIDTH * auto_key_frames[i].kf.game_tic_count / tics_count)); |
| 799 |
V_FillRect(0, x, inner_y, 1, inner_h, colrngs[CR_GREEN][playpal_lightest]); |
| 800 |
} |
| 801 |
|
| 802 |
// quick key frame in red |
| 803 |
if (quick_kf.buffer) |
| 804 |
{ |
| 805 |
x = MIN(SCREENWIDTH, (int)((int64_t)SCREENWIDTH * quick_kf.game_tic_count / tics_count)); |
| 806 |
V_FillRect(0, x, inner_y, 1, inner_h, colrngs[CR_RED][playpal_lightest]); |
| 807 |
} |
| 808 |
|
| 809 |
V_FillRect(0, len - 1, bar_y, 2, bar_h, playpal_lightest); |
| 810 |
|
| 811 |
return true; |
| 812 |
} |
| 813 |
else if (dsda_IntConfig(dsda_config_hudadd_demoprogressbar)) |
| 814 |
{ |
| 815 |
V_FillRect(0, 0, SCREENHEIGHT - 4, len - 0, 4, playpal_lightest); |
| 816 |
if (len > 4) |
| 817 |
V_FillRect(0, 2, SCREENHEIGHT - 3, len - 4, 2, playpal_darkest); |
| 818 |
|
| 819 |
return true; |
| 820 |
} |
| 821 |
|
| 822 |
return false; |
| 823 |
} |
| 824 |
|
| 825 |
#ifdef _WIN32 |
| 826 |
int GetFullPath(const char* FileName, const char* ext, char *Buffer, size_t BufferLength) |
| 827 |
{ |
| 828 |
int i, Result; |
| 829 |
char *p; |
| 830 |
char dir[PATH_MAX]; |
| 831 |
|
| 832 |
for (i=0; i<3; i++) |
| 833 |
{ |
| 834 |
switch(i) |
| 835 |
{ |
| 836 |
case 0: |
| 837 |
M_getcwd(dir, sizeof(dir)); |
| 838 |
break; |
| 839 |
case 1: |
| 840 |
if (!M_getenv("DOOMWADDIR")) |
| 841 |
continue; |
| 842 |
strcpy(dir, M_getenv("DOOMWADDIR")); |
| 843 |
break; |
| 844 |
case 2: |
| 845 |
strcpy(dir, I_ConfigDir()); |
| 846 |
break; |
| 847 |
} |
| 848 |
|
| 849 |
Result = SearchPath(dir,FileName,ext,BufferLength,Buffer,&p); |
| 850 |
if (Result) |
| 851 |
return Result; |
| 852 |
} |
| 853 |
|
| 854 |
return false; |
| 855 |
} |
| 856 |
#endif |