/
dd_main.c
1241 lines (1018 loc) · 30.4 KB
/
dd_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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**\file
*\section License
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2007 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2008 Daniel Swanson <danij@dengine.net>
*\author Copyright © 2006-2007 Jamie Jones <jamie_jones_au@yahoo.com.au>
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* \bug Not 64bit clean: In function 'DD_GetInteger': cast from pointer to integer of different size
* \bug Not 64bit clean: In function 'DD_SetInteger': cast to pointer from integer of different size
*/
/**
* dd_main.c: Engine Core
*/
// HEADER FILES ------------------------------------------------------------
#ifdef WIN32
# define _WIN32_DCOM
# include <objbase.h>
#endif
#include "de_platform.h"
#ifdef WIN32
# include <direct.h>
#endif
#ifdef UNIX
# include <ctype.h>
# include <SDL.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include "de_base.h"
#include "de_system.h"
#include "de_console.h"
#include "de_network.h"
#include "de_play.h"
#include "de_refresh.h"
#include "de_render.h"
#include "de_graphics.h"
#include "de_audio.h"
#include "de_misc.h"
#include "de_dam.h"
#include "dd_pinit.h"
// MACROS ------------------------------------------------------------------
#define MAXWADFILES 4096
// TYPES -------------------------------------------------------------------
typedef struct ddvalue_s {
int *readPtr;
int *writePtr;
} ddvalue_t;
typedef struct autoload_s {
boolean loadFiles; // Should files be loaded right away.
int count; // Number of files loaded successfully.
} autoload_t;
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
void G_CheckDemoStatus();
void F_Drawer(void);
void S_InitScript(void);
void Net_Drawer(void);
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
static int DD_StartupWorker(void *parm);
static int DD_StartupWorker2(void *parm);
static void HandleArgs(int state);
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
#ifdef WIN32
extern HINSTANCE hInstDGL;
#endif
extern int renderTextures;
extern char skyFlatName[9];
extern int gotFrame;
extern int monochrome;
extern int gameDataFormat;
extern int gameDrawHUD;
extern material_t *skyMaskMaterial;
// PUBLIC DATA DEFINITIONS -------------------------------------------------
directory_t ddRuntimeDir, ddBinDir;
int verbose = 0; // For debug messages (-verbose).
boolean cmdfrag; // true if a CMD_FRAG packet should be sent out
int isDedicated = false;
int maxZone = 0x2000000; // Default zone heap. (32meg)
boolean autoStart;
FILE *outFile; // Output file for console messages.
char *iwadList[64];
char *defaultWads = ""; /* A list of wad names, whitespace in between
(in .cfg). */
filename_t configFileName;
filename_t bindingsConfigFileName;
filename_t defsFileName, topDefsFileName;
filename_t ddBasePath = ""; // Doomsday root directory is at...?
int queryResult = 0;
// PRIVATE DATA DEFINITIONS ------------------------------------------------
static char *wadFiles[MAXWADFILES];
// CODE --------------------------------------------------------------------
/**
* Convert propertyType enum constant into a string for error/debug messages.
*/
const char* value_Str(int val)
{
static char valStr[40];
struct val_s {
int val;
const char* str;
} valuetypes[] =
{
{ DDVT_BOOL, "DDVT_BOOL" },
{ DDVT_BYTE, "DDVT_BYTE" },
{ DDVT_SHORT, "DDVT_SHORT" },
{ DDVT_INT, "DDVT_INT" },
{ DDVT_UINT, "DDVT_UINT" },
{ DDVT_FIXED, "DDVT_FIXED" },
{ DDVT_ANGLE, "DDVT_ANGLE" },
{ DDVT_FLOAT, "DDVT_FLOAT" },
{ DDVT_LONG, "DDVT_LONG" },
{ DDVT_ULONG, "DDVT_ULONG" },
{ DDVT_PTR, "DDVT_PTR" },
{ DDVT_FLAT_INDEX, "DDVT_FLAT_INDEX" },
{ DDVT_BLENDMODE, "DDVT_BLENDMODE" },
{ DDVT_VERT_IDX, "DDVT_VERT_IDX" },
{ DDVT_LINE_IDX, "DDVT_LINE_IDX" },
{ DDVT_SIDE_IDX, "DDVT_SIDE_IDX" },
{ DDVT_SECT_IDX, "DDVT_SECT_IDX" },
{ DDVT_SEG_IDX, "DDVT_SEG_IDX" },
{ 0, NULL }
};
uint i;
for(i = 0; valuetypes[i].str; ++i)
if(valuetypes[i].val == val)
return valuetypes[i].str;
sprintf(valStr, "(unnamed %i)", val);
return valStr;
}
/**
* Adds the given IWAD to the list of default IWADs.
*/
void DD_AddIWAD(const char *path)
{
int i = 0;
char buf[256];
while(iwadList[i])
i++;
M_TranslatePath(path, buf);
iwadList[i] = M_Calloc(strlen(buf) + 1); // This mem is not freed?
strcpy(iwadList[i], buf);
}
#define ATWSEPS ",; \t"
static void AddToWadList(char *list)
{
size_t len = strlen(list);
char *buffer = M_Malloc(len + 1), *token;
strcpy(buffer, list);
token = strtok(buffer, ATWSEPS);
while(token)
{
DD_AddStartupWAD(token /*, false */ );
token = strtok(NULL, ATWSEPS);
}
M_Free(buffer);
}
/**
* (f_forall_func_t)
*/
static int autoDataAdder(const char *fileName, filetype_t type, void *ptr)
{
autoload_t *data = ptr;
// Skip directories.
if(type == FT_DIRECTORY)
return true;
if(data->loadFiles)
{
if(W_AddFile(fileName, false))
++data->count;
}
else
{
DD_AddStartupWAD(fileName);
}
// Continue searching.
return true;
}
/**
* Files with the extensions wad, lmp, pk3, zip and deh in the automatical data
* directory are added to the wadFiles list. Returns the number of new
* files that were loaded.
*/
int DD_AddAutoData(boolean loadFiles)
{
autoload_t data;
const char *extensions[] = {
"wad", "lmp", "pk3", "zip", "deh",
#ifdef UNIX
"WAD", "LMP", "PK3", "ZIP", "DEH", // upper case alternatives
#endif
NULL
};
char pattern[256];
uint i;
data.loadFiles = loadFiles;
data.count = 0;
for(i = 0; extensions[i]; ++i)
{
sprintf(pattern, "%sauto\\*.%s", R_GetDataPath(), extensions[i]);
Dir_FixSlashes(pattern);
F_ForAll(pattern, &data, autoDataAdder);
}
return data.count;
}
void DD_SetConfigFile(char *filename)
{
strcpy(configFileName, filename);
Dir_FixSlashes(configFileName);
strcpy(bindingsConfigFileName, configFileName);
strcpy(bindingsConfigFileName + strlen(bindingsConfigFileName) - 4,
"-bindings.cfg");
}
/**
* Set the primary DED file, which is included immediately after
* Doomsday.ded.
*/
void DD_SetDefsFile(char *filename)
{
sprintf(topDefsFileName, "%sdefs\\%s", ddBasePath, filename);
Dir_FixSlashes(topDefsFileName);
}
/**
* Define Auto mappings for the runtime directory.
*/
void DD_DefineBuiltinVDM(void)
{
filename_t dest;
// Data files.
sprintf(dest, "%sauto", R_GetDataPath());
F_AddMapping("auto", dest);
// Definition files.
Def_GetAutoPath(dest);
F_AddMapping("auto", dest);
}
/**
* Looks for new files to autoload. Runs until there are no more files to
* autoload.
*/
void DD_AutoLoad(void)
{
int p;
/**
* Load files from the Auto directory. (If already loaded, won't
* be loaded again.) This is done again because virtual files may
* now exist in the Auto directory. Repeated until no new files
* found.
*/
while((p = DD_AddAutoData(true)) > 0)
{
VERBOSE(Con_Message("Autoload round completed with %i new files.\n",
p));
}
}
/**
* Engine and game initialization. When complete, starts the game loop.
*/
int DD_Main(void)
{
int winWidth, winHeight, winBPP, winX, winY;
uint winFlags = DDWF_VISIBLE | DDWF_CENTER;
boolean noCenter = false;
int exitCode;
// By default, use the resolution defined in (default).cfg.
winX = 0;
winY = 0;
winWidth = defResX;
winHeight = defResY;
winBPP = defBPP;
winFlags |= (defFullscreen? DDWF_FULLSCREEN : 0);
// Check for command line options modifying the defaults.
if(ArgCheckWith("-width", 1))
winWidth = atoi(ArgNext());
if(ArgCheckWith("-height", 1))
winHeight = atoi(ArgNext());
if(ArgCheckWith("-winsize", 2))
{
winWidth = atoi(ArgNext());
winHeight = atoi(ArgNext());
}
if(ArgCheckWith("-bpp", 1))
winBPP = atoi(ArgNext());
// Ensure a valid value.
if(winBPP != 16 && winBPP != 32)
winBPP = 32;
if(ArgCheck("-nocenter"))
noCenter = true;
if(ArgCheckWith("-xpos", 1))
{
winX = atoi(ArgNext());
noCenter = true;
}
if(ArgCheckWith("-ypos", 1))
{
winY = atoi(ArgNext());
noCenter = true;
}
if(noCenter)
winFlags &= ~DDWF_CENTER;
if(ArgExists("-nofullscreen") || ArgExists("-window"))
winFlags &= ~DDWF_FULLSCREEN;
if(!Sys_SetWindow(windowIDX, winX, winY, winWidth, winHeight, winBPP,
winFlags, 0))
return -1;
if(!isDedicated)
{
if(!GL_EarlyInit())
{
Sys_CriticalMessage("GL_EarlyInit() failed.");
return -1;
}
}
/**
* \note This must be called from the main thread due to issues with
* the devices we use via the WINAPI, MCI (cdaudio, mixer etc).
*/
Con_Message("Sys_Init: Setting up machine state.\n");
Sys_Init();
// Enter busy mode until startup complete.
Con_InitProgress(200);
Con_Busy(BUSYF_NO_UPLOADS | BUSYF_STARTUP | BUSYF_PROGRESS_BAR
| (verbose? BUSYF_CONSOLE_OUTPUT : 0), DD_StartupWorker, NULL);
// Engine initialization is complete. Now finish up with the GL.
if(!isDedicated)
{
GL_Init();
GL_InitRefresh(true, true);
}
// Do deferred uploads.
Con_Busy(BUSYF_PROGRESS_BAR | BUSYF_STARTUP | BUSYF_ACTIVITY
| (verbose? BUSYF_CONSOLE_OUTPUT : 0), DD_StartupWorker2, NULL);
// Client connection command.
if(ArgCheckWith("-connect", 1))
Con_Executef(CMDS_CMDLINE, false, "connect %s", ArgNext());
// Server start command.
// (shortcut for -command "net init tcpip; net server start").
if(ArgExists("-server"))
{
if(!N_InitService(true))
Con_Message("Can't start server: network init failed.\n");
else
Con_Executef(CMDS_CMDLINE, false, "net server start");
}
// Final preparations for using the console UI.
Con_InitUI();
// Start the game loop.
exitCode = DD_GameLoop();
// Time to shutdown.
if(netGame)
{ // Quit netGame if one is in progress.
Con_Execute(CMDS_DDAY, isServer ? "net server close" : "net disconnect",
true, false);
}
Demo_StopPlayback();
Con_SaveDefaults();
Sys_Shutdown();
B_Shutdown();
return exitCode;
}
static int DD_StartupWorker(void *parm)
{
int p = 0;
#ifdef WIN32
// Initialize COM for this thread (needed for DirectInput).
CoInitialize(NULL);
#endif
F_InitMapping();
// Initialize the key mappings.
DD_InitInput();
Con_SetProgress(10);
// Any startup hooks?
Plug_DoHook(HOOK_STARTUP, 0, 0);
Con_SetProgress(20);
DD_AddStartupWAD("}data\\doomsday.pk3");
R_InitExternalResources();
// The name of the .cfg will invariably be overwritten by the Game.
strcpy(configFileName, "doomsday.cfg");
sprintf(defsFileName, "%sdefs\\doomsday.ded", ddBasePath);
// Was the change to userdir OK?
if(!app.userDirOk)
Con_Message("--(!)-- User directory not found " "(check -userdir).\n");
bamsInit(); // Binary angle calculations.
// Initialize the zip file database.
Zip_Init();
Def_Init();
autoStart = false;
HandleArgs(0); // Everything but WADs.
novideo = ArgCheck("-novideo") || isDedicated;
DAM_Init();
if(gx.PreInit)
gx.PreInit();
Con_SetProgress(30);
// We now accept no more custom properties.
//DAM_LockCustomPropertys();
// Automatically create an Auto mapping in the runtime directory.
DD_DefineBuiltinVDM();
// Initialize subsystems
Net_Init(); // Network before anything else.
// Now we can hide the mouse cursor for good.
Sys_HideMouse();
// Load defaults before initing other systems
Con_Message("Parsing configuration files.\n");
// Check for a custom config file.
if(ArgCheckWith("-config", 1))
{
// This will override the default config file.
strcpy(configFileName, ArgNext());
Con_Message("Custom config file: %s\n", configFileName);
}
// This'll be the default config file.
Con_ParseCommands(configFileName, true);
// Parse additional files (that should be parsed BEFORE init).
if(ArgCheckWith("-cparse", 1))
{
for(;;)
{
char *arg = ArgNext();
if(!arg || arg[0] == '-')
break;
Con_Message("Parsing: %s\n", arg);
Con_ParseCommands(arg, false);
}
}
Con_SetProgress(40);
if(defaultWads)
AddToWadList(defaultWads); // These must take precedence.
HandleArgs(1); // Only the WADs.
Con_Message("W_Init: Init WADfiles.\n");
// Add real files from the Auto directory to the wadFiles list.
DD_AddAutoData(false);
W_InitMultipleFiles(wadFiles);
F_InitDirec();
Con_SetProgress(75);
// Load help resources. Now virtual files are available as well.
if(!isDedicated)
DD_InitHelp();
// Final autoload round.
DD_AutoLoad();
Con_SetProgress(80);
// No more WADs will be loaded in startup mode after this point.
W_EndStartup();
VERBOSE(W_PrintMapList());
// Execute the startup script (Startup.cfg).
Con_ParseCommands("startup.cfg", false);
// Now the game can identify the game mode.
gx.UpdateState(DD_GAME_MODE);
// Now that we've read the WADs we can initialize definitions.
Def_Read();
#ifdef WIN32
if(ArgCheck("-nowsk")) // No Windows system keys?
{
// Disable Alt-Tab, Alt-Esc, Ctrl-Alt-Del.
// A bit of a hack, I'm afraid...
SystemParametersInfo(SPI_SETSCREENSAVERRUNNING, TRUE, 0, 0);
Con_Message("Windows system keys disabled.\n");
}
#endif
if(ArgCheckWith("-dumplump", 1))
{
char *arg = ArgNext();
char fname[100];
FILE *file;
int lump = W_GetNumForName(arg);
byte *lumpPtr = W_CacheLumpNum(lump, PU_STATIC);
sprintf(fname, "%s.dum", arg);
file = fopen(fname, "wb");
if(!file)
{
Con_Error("Couldn't open %s for writing. %s\n", fname,
strerror(errno));
}
fwrite(lumpPtr, 1, lumpInfo[lump].size, file);
fclose(file);
Con_Error("%s dumped to %s.\n", arg, fname);
}
if(ArgCheck("-dumpwaddir"))
{
char buff[10];
printf("Lumps (%d total):\n", numLumps);
for(p = 0; p < numLumps; p++)
{
strncpy(buff, lumpInfo[p].name, 8);
buff[8] = 0;
printf("%04i - %-8s (hndl: %p, pos: %i, size: %lu)\n", p, buff,
lumpInfo[p].handle, lumpInfo[p].position,
(unsigned long) lumpInfo[p].size);
}
Con_Error("---End of lumps---\n");
}
Con_SetProgress(100);
Con_Message("B_Init: Init bindings.\n");
B_Init();
Con_ParseCommands(bindingsConfigFileName, false);
Con_SetProgress(125);
Con_Message("R_Init: Init the refresh daemon.\n");
R_Init();
Con_SetProgress(199);
// Palette information will be needed for preparing textures.
GL_EarlyInitTextureManager();
Con_Message("Net_InitGame: Initializing game data.\n");
Net_InitGame();
Demo_Init();
if(gx.PostInit)
gx.PostInit();
// Now the defs have been read we can init the map format info
P_InitData();
// Try to load the autoexec file. This is done here to make sure
// everything is initialized: the user can do here anything that
// s/he'd be able to do in the game.
Con_ParseCommands("autoexec.cfg", false);
// Parse additional files.
if(ArgCheckWith("-parse", 1))
{
for(;;)
{
char *arg = ArgNext();
if(!arg || arg[0] == '-')
break;
Con_Message("Parsing: %s\n", arg);
Con_ParseCommands(arg, false);
}
}
// A console command on the command line?
for(p = 1; p < Argc() - 1; p++)
{
if(stricmp(Argv(p), "-command") && stricmp(Argv(p), "-cmd"))
continue;
for(++p; p < Argc(); p++)
{
char *arg = Argv(p);
if(arg[0] == '-')
{
p--;
break;
}
Con_Execute(CMDS_CMDLINE, arg, false, false);
}
}
// In dedicated mode the console must be opened, so all input events
// will be handled by it.
if(isDedicated)
Con_Open(true);
Con_SetProgress(200);
Plug_DoHook(HOOK_INIT, 0, 0); // Any initialization hooks?
Con_UpdateKnownWords(); // For word completion (with Tab).
#ifdef WIN32
// This thread has finished using COM.
CoUninitialize();
#endif
Con_BusyWorkerEnd();
return 0;
}
/**
* This only exists so we have something to call while the deferred uploads of the
* startup are processed.
*/
static int DD_StartupWorker2(void *parm)
{
Con_SetProgress(200);
Con_BusyWorkerEnd();
return 0;
}
static void HandleArgs(int state)
{
int order, p;
if(state == 0)
{
renderTextures = !ArgExists("-notex");
}
// Process all -iwad and -file options. -iwad options are processed
// first so that the loading order remains correct.
if(state)
{
for(order = 0; order < 2; order++)
{
for(p = 0; p < Argc(); p++)
{
if((order == 1 &&
(stricmp(Argv(p), "-f") && stricmp(Argv(p), "-file"))) ||
(order == 0 &&
stricmp(Argv(p), "-iwad")))
continue;
while(++p != Argc() && !ArgIsOption(p))
DD_AddStartupWAD(Argv(p));
p--;/* For ArgIsOption(p) necessary, for p==Argc() harmless */
}
}
}
}
void DD_CheckTimeDemo(void)
{
static boolean checked = false;
if(!checked)
{
checked = true;
if(ArgCheckWith("-timedemo", 1) || // Timedemo mode.
ArgCheckWith("-playdemo", 1)) // Play-once mode.
{
char buf[200];
sprintf(buf, "playdemo %s", ArgNext());
Con_Execute(CMDS_CMDLINE, buf, false, false);
}
}
}
/**
* This is a 'public' WAD file addition routine. The caller can put a
* greater-than character (>) in front of the name to prepend the base
* path to the file name (providing it's a relative path).
*/
void DD_AddStartupWAD(const char *file)
{
int i;
char *new, temp[300];
i = 0;
while(wadFiles[i])
i++;
M_TranslatePath(file, temp);
new = M_Calloc(strlen(temp) + 1); // This is never freed?
strcat(new, temp);
wadFiles[i] = new;
}
void DD_UpdateEngineState(void)
{
// Update refresh.
Con_Message("Updating state...\n");
// Update the dir/WAD translations.
F_InitDirec();
gx.UpdateState(DD_PRE);
R_Update();
gx.UpdateState(DD_POST);
// Reset the anim groups (if in-game)
R_ResetAnimGroups();
// \fixme We need to update surfaces.
//R_UpdateAllSurfaces(true);
}
/**
* Queries are a (poor) way to extend the API without adding new functions.
*/
void DD_CheckQuery(int query, int parm)
{
switch(query)
{
case DD_TEXTURE_HEIGHT_QUERY:
queryResult = textures[parm]->info.height;
break;
#if 0
// Unused
case DD_NET_QUERY:
switch (parm)
{
case DD_PROTOCOL:
queryResult = (int) N_GetProtocolName();
break;
}
break;
#endif
default:
break;
}
}
/* *INDENT-OFF* */
ddvalue_t ddValues[DD_LAST_VALUE - DD_FIRST_VALUE - 1] = {
{&netGame, 0},
{&isServer, 0}, // An *open* server?
{&isClient, 0},
{&allowFrames, &allowFrames},
{0, 0},
{&viewwindowx, &viewwindowx},
{&viewwindowy, &viewwindowy},
{&viewwidth, &viewwidth},
{&viewheight, &viewheight},
{&consolePlayer, &consolePlayer},
{&displayPlayer, &displayPlayer},
{0, 0},
{&mipmapping, 0},
{&linearRaw, 0},
{&defResX, &defResX},
{&defResY, &defResY},
{&skyDetail, 0},
{&sfx_volume, &sfx_volume},
{&mus_volume, &mus_volume},
{0, 0}, //{&mouseInverseY, &mouseInverseY},
{&queryResult, 0},
{&levelFullBright, &levelFullBright},
{&CmdReturnValue, 0},
{&gameReady, &gameReady},
{0, 0},
{0, 0},
{0, 0},
{0, 0},
{&isDedicated, 0},
{&novideo, 0},
{&defs.count.mobjs.num, 0},
{&gotFrame, 0},
{&playback, 0},
{&defs.count.sounds.num, 0},
{&defs.count.music.num, 0},
{&numLumps, 0},
{&clientPaused, &clientPaused},
{&weaponOffsetScaleY, &weaponOffsetScaleY},
{&monochrome, &monochrome},
{&gameDataFormat, &gameDataFormat},
{&gameDrawHUD, 0},
{&upscaleAndSharpenPatches, &upscaleAndSharpenPatches}
};
/* *INDENT-ON* */
/**
* Get a 32-bit signed integer value.
*/
int DD_GetInteger(int ddvalue)
{
if(ddvalue >= DD_LAST_VALUE || ddvalue <= DD_FIRST_VALUE)
{
// How about some specials?
switch(ddvalue)
{
case DD_DYNLIGHT_TEXTURE:
return (int) GL_PrepareLSTexture(LST_DYNAMIC, NULL);
case DD_MAP_MUSIC:
{
gamemap_t *map = P_GetCurrentMap();
ded_mapinfo_t *mapInfo = Def_GetMapInfo(P_GetMapID(map));
if(mapInfo)
return Def_GetMusicNum(mapInfo->music);
return -1;
}
case DD_WINDOW_WIDTH:
return theWindow->width;
case DD_WINDOW_HEIGHT:
return theWindow->height;
case DD_SKYMASKMATERIAL_NUM:
if(skyMaskMaterial)
return skyMaskMaterial->ofTypeID;
return 0;
default:
break;
}
return 0;
}
// We have to separately calculate the 35 Hz ticks.
if(ddvalue == DD_GAMETIC)
return SECONDS_TO_TICKS(gameTime);
if(ddValues[ddvalue].readPtr == NULL)
return 0;
return *ddValues[ddvalue].readPtr;
}
/**
* Set a 32-bit signed integer value.
*/
void DD_SetInteger(int ddvalue, int parm)
{
if(ddvalue <= DD_FIRST_VALUE || ddvalue >= DD_LAST_VALUE)
{
DD_CheckQuery(ddvalue, parm);
// How about some special values?
return;
}
if(ddValues[ddvalue].writePtr)
*ddValues[ddvalue].writePtr = parm;
}
/**
* Get a pointer to the value of a variable. Not all variables support
* this. Added for 64-bit support.
*/
void* DD_GetVariable(int ddvalue)
{
if(ddvalue >= DD_LAST_VALUE || ddvalue <= DD_FIRST_VALUE)
{
// How about some specials?
switch(ddvalue)
{
case DD_SKYMASKMATERIAL_NUM:
if(skyMaskMaterial)
return &skyMaskMaterial->ofTypeID;
return 0;
case DD_VIEWX:
return &viewX;
case DD_VIEWY:
return &viewY;
case DD_VIEWZ:
return &viewZ;
case DD_VIEWX_OFFSET:
return &viewXOffset;
case DD_VIEWY_OFFSET:
return &viewYOffset;
case DD_VIEWZ_OFFSET:
return &viewZOffset;
case DD_VIEWANGLE:
return &viewAngle;
case DD_VIEWANGLE_OFFSET:
return &viewAngleOffset;
case DD_SECTOR_COUNT:
return &numSectors;
case DD_LINE_COUNT:
return &numLineDefs;
case DD_SIDE_COUNT:
return &numSideDefs;
case DD_VERTEX_COUNT:
return &numVertexes;
case DD_POLYOBJ_COUNT:
return &numPolyObjs;