-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD3dapp.c
1468 lines (1396 loc) · 48.5 KB
/
D3dapp.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
/*
* The X Men, June 1996
* Copyright (c) 1996 Probe Entertainment Limited
* All Rights Reserved
*
* $Revision: 38 $
*
* $Header: /PcProjectX/D3dapp.c 38 11/11/98 16:00 Philipy $
*
* $Log: /PcProjectX/D3dapp.c $
*
* 38 11/11/98 16:00 Philipy
* various fixes for warnings / errors when compiling under VC6
*
* 37 3/09/98 14:25 Philipy
* tidied up window mode slightly
* ( no resize allowed, removed menu bar )
*
* 36 18/08/98 18:14 Philipy
* all pings in server game are now from server perspective
* windowed mode re-enabled ( still needs some work )
*
* 35 15/06/98 15:42 Collinsd
* Fixed software menus in demo mode.
*
* 34 10/04/98 18:03 Collinsd
*
* 33 10/04/98 17:11 Philipy
*
* 32 8/04/98 10:14 Philipy
* removed error message when checking alt+tabbing back into game on 3dfx
*
* 31 7/04/98 22:13 Collinsd
* Hack for chris's goals. CWClear screen added.
*
* 30 4/04/98 17:38 Collinsd
* Updated Software
*
* 29 3/04/98 11:25 Collinsd
* Mono lighting and acclaim logo now work and display of goals added
* again.
*
* 28 26/03/98 15:15 Collinsd
* Mods for Chris
*
* 27 6/03/98 14:25 Collinsd
*
* 26 16/02/98 16:53 Collinsd
* Added Chris's new code.
*
* 25 5/01/98 19:58 Oliverc
* Current screen mode, texture format and sound volume settings now saved
* to registry on exit and restored on startup
*
* 24 12/11/97 18:26 Collinsd
*
* 23 7/11/97 14:25 Philipy
* fixed bug when changing mode from title room: InitTitle was not being
* called
*
* 22 23/10/97 13:52 Collinsd
* Added code to enable/disable compilation of software version.
* SOFTWARE_ENABLE & softblit.lib.
*
* 21 22/09/97 10:40 Collinsd
* Software version works again. ( Now with trasnsluecency )
*
* 20 9/18/97 12:16p Phillipd
*
* 19 17/09/97 16:37 Collinsd
* Blit now works in software.
*
* 18 17/09/97 9:55 Collinsd
* Blitting now works in software versions in 320x240 mode.
*
* 17 16/09/97 17:52 Collinsd
* More of Chris's stuff works.
*
* 16 16/09/97 10:59 Collinsd
* Added Chris's code
*
* 15 31/07/97 15:57 Oliverc
* Added special SELF_PLAY features, including disabling critical unused
* code and setting default values appropriate to demo attract mode
*
* 14 6/16/97 2:57p Phillipd
* Tripple buffering can now be done....
*
* 13 1/10/97 11:30a Phillipd
* movies are now doable
*
* 12 11/06/96 6:10p Phillipd
* Got rid of some useless files...
*
* 11 5/11/96 17:19 Oliverc
* Added calls to FlipToGDISurface() when in fullscreen mode and entering
* DPlay Wizard or pausing game to use menus so that 3Dfx card works
*
* 10 10/24/96 3:01p Phillipd
*
* 9 10/23/96 4:23p Phillipd
* Lots of crap taken out of D3dapp and its associated functions and
* files....
*
* 8 10/03/96 9:09a Phillipd
*
* 7 17/09/96 16:19 Oliverc
* Added auto unpause whenever window moved or resized
*
* 6 9/17/96 11:26a Phillipd
*
* 5 7/26/96 4:27p Phillipd
*
* 4 7/22/96 11:16a Phillipd
*
* 3 4/07/96 11:56 Oliverc
*
* 2 6/25/96 11:37a Phillipd
* First SS update
*
*/
/*
* Copyright (C) 1995, 1996 Microsoft Corporation. All Rights Reserved.
*
* File: d3dapp.c
*
* Top level D3DApp functions and internal global variables. See
* d3dapp.h for more information.
*
* D3DApp is a collection of helper functions for Direct3D applications.
* D3DApp consists of the following files:
* d3dapp.h Main D3DApp header to be included by application
* d3dappi.h Internal header
* d3dapp.c D3DApp functions seen by application.
* ddcalls.c All calls to DirectDraw objects except textures
* d3dcalls.c All calls to Direct3D objects except textures
* texture.c Texture loading and managing texture list
* misc.c Miscellaneous calls
*/
#include "typedefs.h"
#include "d3dappi.h"
#include "main.h"
#include "title.h"
extern void SetCursorClip( void );
extern BOOL cursorclipped;
extern BOOL DrawPanel;
extern BOOL DrawCrosshair;
extern uint16 PanelHeight;
extern void ProcessTextItems (void);
extern int TexturePalettized;
extern int TextureRedBPP;
extern int TextureGreenBPP;
extern int TextureBlueBPP;
extern int TextureAlphaBPP;
extern int TextureIndexBPP;
extern BOOL CanRenderWindowed;
extern d3dmainglobals myglobs; /* collection of global variables */
//#define INITGUID
#ifdef SOFTWARE_ENABLE
/*---------------------------------------------------------------------------
Chris Walsh's code
---------------------------------------------------------------------------*/
extern void SetVTables();
extern void CWFlip( void );
//extern void CWStretchBlit( WORD, WORD, long, char *);
extern long LineWidth;
extern char * ScreenBase;
extern WORD SurfBpp;
extern void ClrOT();
extern void SWRendView();
extern long Highestz;
extern char DrawnYet;
extern WORD SurfWidth, SurfHeight;
extern BYTE MyGameStatus;
extern BOOL ServerMode;
extern BOOL DrawSimplePanel;
extern BOOL JustExitedMenu;
extern BOOL Our_CalculateFrameRate(void);
extern BOOL SoftwareVersion;
extern void CWAfterModeSwitch(void);
extern long zRW;
void CWClearScreen( void );
char CWInTitle = 1;
/*-------------------------------------------------------------------------*/
#endif
/***************************************************************************/
/* GLOBAL VARIABLES */
/***************************************************************************/
/*
* All DD and D3D objects which are also available to the application
* See d3dapp.h for typedef
*/
D3DAppInfo d3dappi;
/*
* Internal record of the render state. See d3dapp.h for typedef
*/
D3DAppRenderState d3dapprs;
/*
* Callback functions for D3D device creation and destruction
*/
BOOL(*D3DDeviceDestroyCallback)(LPVOID);
LPVOID D3DDeviceDestroyCallbackContext;
BOOL(*D3DDeviceCreateCallback)(int, int, LPDIRECT3DVIEWPORT*, LPVOID);
LPVOID D3DDeviceCreateCallbackContext;
/*
* The last error code and string
*/
HRESULT LastError;
char LastErrorString[256];
/*
* List of texture handles which is copied to D3DAppInfo structure when
* necessary
*/
void InitModeCase(void);
LPDIRECTDRAWCLIPPER lpClipper; /* Clipper in windowed case */
LPDIRECTDRAWPALETTE lpPalette; /* Front buffer's palette */
PALETTEENTRY ppe[256]; /* Current palette entries */
PALETTEENTRY Originalppe[256]; /* Windows palette entries at startup */
BOOL bD3DAppInitialized; /* Is D3DApp initialized? */
BOOL bPrimaryPalettized; /* Is the front buffer palettized? */
BOOL bPaletteActivate; /* Is the front buffer's palette valid? */
BOOL bIgnoreWM_SIZE; /* Ignore this WM_SIZE messages */
SIZE szLastClient; /* Dimensions of the last window */
SIZE szBuffers; /* Current buffer dimensions, not necessarily
the same as the client window */
int CallbackRefCount; /* How many times DeviceCreateCallback has
been called in a row */
/***************************************************************************/
/* FUNCTIONS */
/***************************************************************************/
/*
* D3DAppCreateFromHWND
*/
BOOL D3DAppCreateFromHWND(DWORD flags, HWND hwnd,
BOOL(*DeviceCreateCallback)(int, int,
LPDIRECT3DVIEWPORT*,
LPVOID),
LPVOID lpCreateContext,
BOOL(*DeviceDestroyCallback)(LPVOID),
LPVOID lpDestroyContext,
D3DAppInfo** D3DApp)
{
int driver, mode, w, h;
/*
* Clean the global varaibles and check the flags
*/
D3DAppISetDefaults();
if (flags & D3DAPP_ONLYSYSTEMMEMORY) {
d3dappi.bOnlySystemMemory = TRUE;
d3dappi.bOnlyEmulation = TRUE;
}
if (flags & D3DAPP_ONLYD3DEMULATION)
d3dappi.bOnlyEmulation = TRUE;
/*
* Create DirectDraw, remember the Windows display mode and enumerate the
* display modes
*/
ATTEMPT(D3DAppICreateDD(d3dappi.bOnlyEmulation ?
D3DAPP_ONLYDDEMULATION : 0L));
ATTEMPT(D3DAppIRememberWindowsMode());
ATTEMPT(D3DAppIEnumDisplayModes());
/*
* Create Direct3D and enumerate the D3D drivers
*/
ATTEMPT(D3DAppICreateD3D());
ATTEMPT(D3DAppIEnumDrivers());
/*
* Set the device creation and destroy callback functions
*/
D3DDeviceDestroyCallback = DeviceDestroyCallback;
D3DDeviceDestroyCallbackContext = lpDestroyContext;
D3DDeviceCreateCallback = DeviceCreateCallback;
D3DDeviceCreateCallbackContext = lpCreateContext;
*D3DApp = &d3dappi;
d3dappi.hwnd = hwnd;
/*
* Choose a driver and display mode. Using the current window is
* prefered, but a fullscreen mode may be selected. Set the cooperative
* level and create the front and back buffers for this mode.
*/
driver = D3DAPP_YOUDECIDE;
mode = D3DAPP_YOUDECIDE;
ATTEMPT(D3DAppIVerifyDriverAndMode(&driver, &mode));
D3DAppIGetClientWin(hwnd);
if (mode == D3DAPP_USEWINDOW) {
w = d3dappi.szClient.cx;
h = d3dappi.szClient.cy;
ATTEMPT(D3DAppISetCoopLevel(hwnd, FALSE));
ATTEMPT(D3DAppICreateBuffers(hwnd, w, h, D3DAPP_BOGUS, FALSE));
} else {
szLastClient = d3dappi.szClient;
w = d3dappi.Mode[mode].w;
h = d3dappi.Mode[mode].h;
d3dappi.szClient.cx = w; d3dappi.szClient.cy = h;
ATTEMPT(D3DAppISetCoopLevel(hwnd, TRUE));
ATTEMPT(D3DAppISetDisplayMode(w, h, d3dappi.Mode[mode].bpp));
d3dappi.CurrMode = mode;
ATTEMPT(D3DAppICreateBuffers(hwnd, w, h, d3dappi.Mode[mode].bpp, TRUE));
}
/*
* If the front buffer is palettized, initialize its palette
*/
ATTEMPT(D3DAppICheckForPalettized());
/*
* Create the Z-buffer
*/
ATTEMPT(D3DAppICreateZBuffer(w, h, driver));
/*
* Create the D3D device, load the textures, call the device create
* callback and set a default render state
*/
ATTEMPT(D3DAppICreateDevice(driver));
ATTEMPT(D3DAppIFilterDisplayModes(driver)); /* bThisDriverCanDo flags */
ATTEMPT(D3DAppICallDeviceCreateCallback(w, h));
ATTEMPT(D3DAppISetRenderState());
/*
* Ready to render
*/
bD3DAppInitialized = TRUE;
d3dappi.bRenderingIsOK = TRUE;
#ifdef SOFTWARE_ENABLE
if( SoftwareVersion )
{
CWAfterModeSwitch();
}
#endif
return TRUE;
exit_with_error:
D3DAppICallDeviceDestroyCallback();
RELEASE(d3dappi.lpD3DDevice);
RELEASE(d3dappi.lpZBuffer);
RELEASE(lpPalette);
RELEASE(lpClipper);
RELEASE(d3dappi.lpBackBuffer);
RELEASE(d3dappi.lpFrontBuffer);
if (d3dappi.bFullscreen) {
D3DAppIRestoreDispMode();
D3DAppISetCoopLevel(hwnd, FALSE);
}
RELEASE(d3dappi.lpD3D);
RELEASE(d3dappi.lpDD);
return FALSE;
}
/*
* D3DAppFullscreen
*/
BOOL D3DAppFullscreen(int mode)
{
int w, h, bpp;
BOOL b; /* was already in a fullscreen mode? */
d3dappi.bRenderingIsOK = FALSE;
/*
* Make sure this is a valid request, otherwise doctor mode so it will
* work with this driver.
*/
ATTEMPT(D3DAppIVerifyDriverAndMode(&d3dappi.CurrDriver, &mode));
/*
* Release everything
*/
ATTEMPT(D3DAppICallDeviceDestroyCallback());
if (d3dappi.bFullscreen) {
ATTEMPT(D3DAppIClearBuffers());
}
RELEASE(d3dappi.lpD3DDevice);
RELEASE(d3dappi.lpZBuffer);
RELEASE(lpPalette);
RELEASE(lpClipper);
RELEASE(d3dappi.lpBackBuffer);
RELEASE(d3dappi.lpFrontBuffer);
/*
* Record information about the current status
*/
b = d3dappi.bFullscreen;
w = d3dappi.Mode[mode].w;
h = d3dappi.Mode[mode].h;
bpp = d3dappi.Mode[mode].bpp;
if (!b) {
/*
* If this is not a fullscreen mode, we'll need to record the window
* size for when we return to it.
*/
szLastClient = d3dappi.szClient;
}
/*
* Set the cooperative level and create front and back buffers
*/
d3dappi.szClient.cx = w; d3dappi.szClient.cy = h;
InitModeCase();
ATTEMPT(D3DAppISetCoopLevel(d3dappi.hwnd, TRUE));
ATTEMPT(D3DAppISetDisplayMode(w, h, bpp));
d3dappi.CurrMode = mode;
ATTEMPT(D3DAppICreateBuffers(d3dappi.hwnd, w, h, bpp, TRUE));
/*
* If the front buffer is palettized, initialize its palette
*/
ATTEMPT(D3DAppICheckForPalettized());
/*
* Create the Z-buffer
*/
ATTEMPT(D3DAppICreateZBuffer(w, h, d3dappi.CurrDriver));
/*
* Create the D3D device, load the textures, call the device create
* callback and set a default render state
*/
ATTEMPT(D3DAppICreateDevice(d3dappi.CurrDriver));
ATTEMPT(D3DAppICallDeviceCreateCallback(w, h));
ATTEMPT(D3DAppISetRenderState());
/*
* Set current mode
*/
d3dappi.CurrMode = mode;
d3dappi.bRenderingIsOK = TRUE;
#ifdef SOFTWARE_ENABLE
if( SoftwareVersion )
{
CWAfterModeSwitch();
}
#endif
return TRUE;
exit_with_error:
D3DAppICallDeviceDestroyCallback();
RELEASE(d3dappi.lpD3DDevice);
RELEASE(d3dappi.lpZBuffer);
RELEASE(lpPalette);
RELEASE(lpClipper);
RELEASE(d3dappi.lpBackBuffer);
RELEASE(d3dappi.lpFrontBuffer);
if (!b) {
D3DAppIRestoreDispMode();
D3DAppISetCoopLevel(d3dappi.hwnd, FALSE);
}
return FALSE;
}
/*
* D3DAppWindow
*/
BOOL
D3DAppWindow(int w, int h)
{
BOOL b; /* changing from a fullscreen mode? */
/*
if (!d3dappi.bIsPrimary) {
D3DAppISetErrorString("It is not possible to create a D3D window with a hardware DirectDraw device. Check the bIsPrimary flag before calling D3DAppWindow.");
return FALSE;
}
*/
if ( !CanRenderWindowed )
{
Msg("this video card cannot render to a window\n");
return FALSE;
}
b = d3dappi.bFullscreen;
/*
* If asked to set the window size, return it to the last value or use
* a default value.
*/
if (w == D3DAPP_YOUDECIDE) {
w = b ? szLastClient.cx : D3DAPP_DEFAULTWINDOWDIM;
}
if (h == D3DAPP_YOUDECIDE) {
h = b ? szLastClient.cy : D3DAPP_DEFAULTWINDOWDIM;
}
/*
* Release everything
*/
d3dappi.bRenderingIsOK = FALSE;
ATTEMPT(D3DAppICallDeviceDestroyCallback());
if (b) {
ATTEMPT(D3DAppIClearBuffers());
}
RELEASE(d3dappi.lpD3DDevice);
RELEASE(d3dappi.lpZBuffer);
RELEASE(lpPalette);
RELEASE(lpClipper);
RELEASE(d3dappi.lpBackBuffer);
RELEASE(d3dappi.lpFrontBuffer);
/*
* Restore the display mode if we were in a fullscreen mode
*/
if (b) {
D3DAppIRestoreDispMode();
}
/*
* Set the cooperative level and create front and back buffers
*/
D3DAppISetCoopLevel(d3dappi.hwnd, FALSE);
D3DAppISetClientSize(d3dappi.hwnd, w, h, b);
ATTEMPT(D3DAppICreateBuffers(d3dappi.hwnd, w, h, D3DAPP_BOGUS, FALSE));
/*
* If the front buffer is palettized, initialize its palette
*/
ATTEMPT(D3DAppICheckForPalettized());
/*
* Create the Z-buffer
*/
ATTEMPT(D3DAppICreateZBuffer(szBuffers.cx, szBuffers.cy,
d3dappi.CurrDriver));
/*
* Create the D3D device, load the textures, call the device create
* callback and set a default render state
*/
ATTEMPT(D3DAppICreateDevice(d3dappi.CurrDriver));
ATTEMPT(D3DAppICallDeviceCreateCallback(szBuffers.cx, szBuffers.cy));
ATTEMPT(D3DAppISetRenderState());
d3dappi.bRenderingIsOK = TRUE;
return TRUE;
exit_with_error:
D3DAppICallDeviceDestroyCallback();
RELEASE(d3dappi.lpD3DDevice);
RELEASE(d3dappi.lpZBuffer);
RELEASE(lpPalette);
RELEASE(lpClipper);
RELEASE(d3dappi.lpBackBuffer);
RELEASE(d3dappi.lpFrontBuffer);
return FALSE;
}
/*
* D3DAppChangeDriver
*/
BOOL
D3DAppChangeDriver(int driver, DWORD flags)
{
int mode;
/*
* Verify the compatibility of this mode with the specified driver.
* The mode may change.
*/
if (d3dappi.bFullscreen)
mode = d3dappi.CurrMode;
else
mode = D3DAPP_USEWINDOW;
ATTEMPT(D3DAppIVerifyDriverAndMode(&driver, &mode));
if (driver == D3DAPP_BOGUS || mode == D3DAPP_BOGUS)
goto exit_with_error;
/*
* Update the current driver and set bThisDriverCanDo flags
*/
d3dappi.CurrDriver = driver;
ATTEMPT(D3DAppIFilterDisplayModes(driver));
/*
* Either call D3DAppWindow or D3DAppFullscreen depending on mode
*/
if (mode == D3DAPP_USEWINDOW) {
if (d3dappi.bFullscreen) {
/*
* We need to switch to a window. D3DApp will either use the
* size of the last window it saw or use a default size.
*/
ATTEMPT(D3DAppWindow(D3DAPP_YOUDECIDE, D3DAPP_YOUDECIDE));
} else {
/*
* We need to recreate the current window. Don't let D3DApp
* decide on the size.
*/
ATTEMPT(D3DAppWindow(d3dappi.szClient.cx, d3dappi.szClient.cy));
}
/*
* Change the currently selected mode if it's not compatible with
* this driver. Just to make sure that CurrMode is always a mode the
* current driver can do.
*/
if (!(d3dappi.Driver[driver].Desc.dwDeviceRenderBitDepth &
D3DAppIBPPToDDBD(d3dappi.Mode[d3dappi.CurrMode].bpp))){
ATTEMPT(D3DAppIPickDisplayMode(&d3dappi.CurrMode,
d3dappi.Driver[driver].Desc.dwDeviceRenderBitDepth));
}
return TRUE;
} else {
/*
* We need to switch to fullscreen or switch fullscreen modes or stay
* in the same fullscreen mode. In any of these cases, we call the
* same function.
*/
ATTEMPT(D3DAppFullscreen(mode));
return TRUE;
}
exit_with_error:
/*
* The failed mode setting call would have released everything
*/
return FALSE;
}
/*
* D3DAppWindowProc
*/
BOOL
D3DAppWindowProc(BOOL* bStopProcessing, LRESULT* lresult, HWND hwnd,
UINT message, WPARAM wParam, LPARAM lParam)
{
PAINTSTRUCT ps;
*bStopProcessing = FALSE;
if (!bD3DAppInitialized)
return TRUE;
/*
* Look for messages which effect rendering. In some cases, we will not
* want the app to continue processing the message, so set the flag and
* provide a return value in lresult.
*/
switch(message) {
case WM_WINDOWPOSCHANGED:
d3dappi.pClientOnPrimary.x = d3dappi.pClientOnPrimary.y = 0;
ClientToScreen(hwnd, &d3dappi.pClientOnPrimary);
SetCursorClip();
break;
case WM_SIZE:
#if 0
if (!bIgnoreWM_SIZE) {
/*
* Too long to fit here, see ddcalls.c. Updates the buffers
* and re-creates the device.
*/
ATTEMPT(D3DAppIHandleWM_SIZE(lresult, d3dappi.hwnd, message,
wParam, lParam));
*bStopProcessing = TRUE;
}
#endif
break;
case WM_MOVE:
/*
* Update client window position information
*/
d3dappi.pClientOnPrimary.x = d3dappi.pClientOnPrimary.y = 0;
ClientToScreen(hwnd, &d3dappi.pClientOnPrimary);
break;
#if 1
case WM_MOUSEACTIVATE:
if (d3dappi.bFullscreen && !d3dappi.bPaused) {
*lresult = MA_ACTIVATEANDEAT;
*bStopProcessing = TRUE;
return TRUE;
}
break;
#endif
case WM_ACTIVATE:
/*
* Set the front buffer's palette
*/
if (bPaletteActivate && bPrimaryPalettized &&
d3dappi.lpFrontBuffer) {
d3dappi.lpFrontBuffer->lpVtbl->SetPalette(d3dappi.lpFrontBuffer,
lpPalette);
}
// handle cursor clipping
if ( LOWORD( wParam ) == WA_INACTIVE )
{
cursorclipped = FALSE;
}
else
{
cursorclipped = !d3dappi.bPaused;
}
SetCursorClip();
break;
case WM_ACTIVATEAPP:
d3dappi.bAppActive = (BOOL)wParam;
break;
case WM_SETCURSOR:
/*
* Prevent the cursor from being shown in fullscreen
*/
if (d3dappi.bFullscreen && !d3dappi.bPaused) {
// SetCursor(NULL);
*lresult = 1;
*bStopProcessing = TRUE;
return TRUE;
}
break;
case WM_MOVING:
/*
* Prevent the window from moving in fullscreen
*/
if (d3dappi.bFullscreen) {
GetWindowRect(hwnd, (LPRECT)lParam);
*lresult = 1;
*bStopProcessing = TRUE;
return TRUE;
}
break;
case WM_GETMINMAXINFO:
/*
* Ensure the window won't resize in fullscreen
*/
if (d3dappi.bFullscreen) {
((LPMINMAXINFO)lParam)->ptMaxTrackSize.x= d3dappi.ThisMode.w;
((LPMINMAXINFO)lParam)->ptMaxTrackSize.y= d3dappi.ThisMode.h;
((LPMINMAXINFO)lParam)->ptMinTrackSize.x= d3dappi.ThisMode.w;
((LPMINMAXINFO)lParam)->ptMinTrackSize.y= d3dappi.ThisMode.h;
*lresult = 0;
*bStopProcessing = TRUE;
return TRUE;
} else {
((LPMINMAXINFO)lParam)->ptMaxTrackSize.x =
d3dappi.WindowsDisplay.w;
((LPMINMAXINFO)lParam)->ptMaxTrackSize.y =
d3dappi.WindowsDisplay.h;
*lresult = 0;
*bStopProcessing = TRUE;
return TRUE;
}
break;
case WM_PAINT:
/*
* Clear the rectangle and blt the backbuffer image
*/
BeginPaint(hwnd, &ps);
if (d3dappi.bRenderingIsOK && !d3dappi.bFullscreen) {
D3DAppShowBackBuffer(D3DAPP_SHOWALL);
}
EndPaint(hwnd, &ps);
*lresult = 1;
*bStopProcessing = TRUE;
return TRUE;
case WM_NCPAINT:
/*
* When in fullscreen mode, don't draw the window frame.
*/
if (d3dappi.bFullscreen && !d3dappi.bPaused) {
*lresult = 0;
*bStopProcessing = TRUE;
return TRUE;
}
break;
}
return TRUE;
}
/*
* D3DAppChangeTextureFormat
*/
BOOL
D3DAppChangeTextureFormat(int format)
{
/*
* Release all the textures, change the format and load them again
*/
d3dappi.bRenderingIsOK = FALSE;
d3dappi.CurrTextureFormat = format;
memcpy(&d3dappi.ThisTextureFormat, &d3dappi.TextureFormat[format],
sizeof(D3DAppTextureFormat));
TexturePalettized = d3dappi.ThisTextureFormat.bPalettized;
TextureRedBPP = d3dappi.ThisTextureFormat.RedBPP;
TextureGreenBPP = d3dappi.ThisTextureFormat.GreenBPP;
TextureBlueBPP = d3dappi.ThisTextureFormat.BlueBPP;
TextureAlphaBPP = d3dappi.ThisTextureFormat.AlphaBPP;
TextureIndexBPP = d3dappi.ThisTextureFormat.IndexBPP;
d3dappi.bRenderingIsOK = TRUE;
return TRUE;
}
/*
* D3DAppSetRenderState
*/
BOOL
D3DAppSetRenderState(D3DAppRenderState* lpState)
{
/*
* If none was provided, reset the current render state.
*/
if (!lpState)
lpState = &d3dapprs;
/*
* Record this render state and set it.
*/
if (lpState != &d3dapprs)
memcpy(&d3dapprs, lpState, sizeof(D3DAppRenderState));
if (d3dappi.bRenderingIsOK) {
ATTEMPT(D3DAppISetRenderState());
}
return TRUE;
exit_with_error:
return FALSE;
}
/*
* D3DAppGetRenderState
*/
BOOL
D3DAppGetRenderState(D3DAppRenderState* lpState)
{
memcpy(lpState, &d3dapprs, sizeof(D3DAppRenderState));
return TRUE;
}
/*
* D3DAppShowBackBuffer
*/
BOOL
D3DAppShowBackBuffer(DWORD flags)
{
if (!d3dappi.bRenderingIsOK) {
D3DAppISetErrorString("Cannot call D3DAppShowBackBuffer while bRenderingIsOK is FALSE.\n");
return FALSE;
}
if (d3dappi.bPaused)
return TRUE;
#ifdef SOFTWARE_ENABLE
if( SoftwareVersion )
{
/*-----------------------------------------------------------------------------
Chris Walsh's Code
-----------------------------------------------------------------------------*/
// SETUP V TABLE.
if (d3dappi.bFullscreen)
{
// . . . . . . . . . F U L L S C R E E N M O D E . . . . . . . . . . .
// LOCK THE BACK BUFFER.
if ( (SurfBpp!=8 && SurfBpp!=16) ) //|| (SurfBpp==16 && CWInTitle) )
{
CWInTitle = 0;
ClrOT();
LastError = d3dappi.lpFrontBuffer->lpVtbl->Flip(d3dappi.lpFrontBuffer,
d3dappi.lpBackBuffer,
0);
if (LastError == DDERR_SURFACELOST)
{
d3dappi.lpFrontBuffer->lpVtbl->Restore(d3dappi.lpFrontBuffer);
d3dappi.lpBackBuffer->lpVtbl->Restore(d3dappi.lpBackBuffer);
//D3DAppIClearBuffers();
}
else if (LastError != DD_OK)
{
return TRUE; //FALSE;
}
return TRUE;
}
SetVTables();
if( CWInTitle )
{
zRW = 1;
}
SWRendView();
d3dappi.lpBackBuffer->lpVtbl->Unlock( d3dappi.lpBackBuffer, NULL );
if( CWInTitle )
{
ProcessTextItems();
}
else
{
if( (MyGameStatus == STATUS_Normal) || (MyGameStatus == STATUS_PlayingDemo) ||(MyGameStatus == STATUS_SinglePlayer) )
{
if( Our_CalculateFrameRate() != TRUE)
return FALSE;
if( CurrentMenu && CurrentMenuItem )
{
MenuDraw( CurrentMenu );
MenuItemDrawCursor( CurrentMenuItem );
if ( DrawSimplePanel )
TestBlt();
MenuProcess();
// Just to make sure that another press of escape doesnt take you back into the menu you wanted to exit!!
JustExitedMenu = TRUE;
}
else
{
if( !ServerMode )
{
TestBlt();
}
// TaskDispatch();
}
}
}
CWInTitle = 0;
Highestz = 1; //cw: for next time round.
#if 0
if (SurfWidth == 320 && SurfHeight == 240)
{
if (!DrawnYet || (SurfWidth==320 && SurfHeight==240))
LastError = d3dappi.lpFrontBuffer->lpVtbl->Flip(d3dappi.lpFrontBuffer,
d3dappi.lpBackBuffer,
0);
if (LastError == DDERR_SURFACELOST)
{
d3dappi.lpFrontBuffer->lpVtbl->Restore(d3dappi.lpFrontBuffer);
d3dappi.lpBackBuffer->lpVtbl->Restore(d3dappi.lpBackBuffer);
//D3DAppIClearBuffers();
}
else if (LastError != DD_OK)
{
return TRUE; //FALSE;
}
}
else
{
CWStretchBlit( SurfWidth, SurfHeight, LineWidth, ScreenBase); // Stretch it up..
}
#else
CWFlip();
#endif
}
/*---------------------------------------------------------------------------*/
}
else
#endif
{
if (d3dappi.bFullscreen) {
/*
* Flip the back and front buffers
*/
LastError = d3dappi.lpFrontBuffer->lpVtbl->Flip(d3dappi.lpFrontBuffer,
d3dappi.lpBackBuffer,
1);
// LastError = d3dappi.lpFrontBuffer->lpVtbl->Flip(d3dappi.lpFrontBuffer,
// NULL,
// DDFLIP_WAIT );
if (LastError == DDERR_SURFACELOST) {
d3dappi.lpFrontBuffer->lpVtbl->Restore(d3dappi.lpFrontBuffer);
d3dappi.lpBackBuffer->lpVtbl->Restore(d3dappi.lpBackBuffer);
D3DAppIClearBuffers();
} else if (LastError != DD_OK) {
//D3DAppISetErrorString("Flipping complex display surface failed.\n%s", D3DAppErrorToString(LastError));
//return FALSE;
return TRUE;
}
} else {
RECT front;
RECT buffer;
/*
* Set the rectangle to blt from the back to front bufer ..Set to entire client window
*/
SetRect(&buffer, 0, 0, d3dappi.szClient.cx,
d3dappi.szClient.cy);
SetRect(&front,
d3dappi.pClientOnPrimary.x, d3dappi.pClientOnPrimary.y,
d3dappi.szClient.cx + d3dappi.pClientOnPrimary.x,
d3dappi.szClient.cy + d3dappi.pClientOnPrimary.y);
/*
* Blt the list of rectangles from the back to front buffer
*/
LastError = d3dappi.lpFrontBuffer->lpVtbl->Blt(d3dappi.lpFrontBuffer,
&front, d3dappi.lpBackBuffer,
&buffer, DDBLT_WAIT , NULL);
if (LastError == DDERR_SURFACELOST) {
d3dappi.lpFrontBuffer->lpVtbl->Restore(d3dappi.lpFrontBuffer);
d3dappi.lpBackBuffer->lpVtbl->Restore(d3dappi.lpBackBuffer);
D3DAppIClearBuffers();
} else if (LastError != DD_OK) {
D3DAppISetErrorString("Blt of back buffer to front buffer failed.\n%s", D3DAppErrorToString(LastError));
return FALSE;
}
}
}
return TRUE;
}
/*
* D3DAppClearScreenOnly
*/
BOOL