-
Notifications
You must be signed in to change notification settings - Fork 2
/
win32_msg.cpp
executable file
·1649 lines (1348 loc) · 40.5 KB
/
win32_msg.cpp
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
/*
Copyright (C) 2010 Matthew Baranowski, Sander van Rossen & Raven software.
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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifdef WIN32
#include "system.h"
#include "ndictionary.h"
#include "md3gl.h"
#include "md3view.h"
#include "Resource.h"
#include "AFXRES.H"
#include "text.h"
#include "oddbits.h"
#include "animation.h"
#include "bmp.h"
#include "clipboard.h"
extern HINSTANCE WinhInstance;
extern NodeSequenceInfo tagMenuList;
HDC hDC_;
bool sys_rbuttondown = false;
bool sys_lbuttondown = false;
bool sys_mbuttondown = false;
OPENFILENAME *FileOpenDialog(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl, int type);
OPENFILENAME *FileSaveDialog(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl, int type);
/*
selects a 16 bit color file format, could be higher though it wouldn't work with a voodoo
*/
void SetPixelFormat( HDC hdc)
{
PIXELFORMATDESCRIPTOR pfd, *ppfd;
int pixelformat;
ppfd = &pfd;
memset(ppfd, 0, sizeof(PIXELFORMATDESCRIPTOR));
ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR);
ppfd->nVersion = 1;
ppfd->dwFlags = PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
ppfd->dwLayerMask = PFD_MAIN_PLANE;
ppfd->iPixelType = PFD_TYPE_RGBA;
ppfd->cColorBits = 16;
ppfd->cDepthBits = 16;
ppfd->cAccumBits = 0;
ppfd->cStencilBits = 0;
pixelformat = ChoosePixelFormat( hdc, ppfd);
if ( pixelformat == 0) {
Error("ChoosePixelFormat failed");
}
if (ppfd->dwFlags & PFD_NEED_PALETTE) {
Error ("ChoosePixelFormat needs palette" );
}
if (SetPixelFormat( hdc, pixelformat, ppfd) == FALSE) {
Error("SetPixelFormat failed");
}
}
/*
** ChoosePFD
**
** Helper function that replaces ChoosePixelFormat.
*/
#define MAX_PFDS 256
static int GLW_ChoosePFD( HDC hDC, PIXELFORMATDESCRIPTOR *pPFD )
{
PIXELFORMATDESCRIPTOR pfds[MAX_PFDS+1];
int maxPFD = 0;
int i;
int bestMatch = 0;
OutputDebugString( va("...GLW_ChoosePFD( %d, %d, %d )\n", ( int ) pPFD->cColorBits, ( int ) pPFD->cDepthBits, ( int ) pPFD->cStencilBits) );
// count number of PFDs
//
maxPFD = DescribePixelFormat( hDC, 1, sizeof( PIXELFORMATDESCRIPTOR ), &pfds[0] );
if ( maxPFD > MAX_PFDS )
{
OutputDebugString( va( "...numPFDs > MAX_PFDS (%d > %d)\n", maxPFD, MAX_PFDS) );
maxPFD = MAX_PFDS;
}
OutputDebugString( va("...%d PFDs found\n", maxPFD - 1) );
FILE *handle = fopen("MD3View_GL_report.txt","wt");
fprintf(handle,"Total PFDs: %d\n\n",maxPFD);
// grab information
for ( i = 1; i <= maxPFD; i++ )
{
DescribePixelFormat( hDC, i, sizeof( PIXELFORMATDESCRIPTOR ), &pfds[i] );
fprintf(handle,"PFD %d/%d\n",i,maxPFD);
fprintf(handle,"=========\n");
#define FLAGDUMP(flag) if ( (pfds[i].dwFlags & flag ) != 0 ) fprintf(handle,"(flag: %s)\n",#flag);
FLAGDUMP( PFD_DOUBLEBUFFER );
FLAGDUMP( PFD_STEREO );
FLAGDUMP( PFD_DRAW_TO_WINDOW );
FLAGDUMP( PFD_DRAW_TO_BITMAP );
FLAGDUMP( PFD_SUPPORT_GDI );
FLAGDUMP( PFD_SUPPORT_OPENGL );
FLAGDUMP( PFD_GENERIC_FORMAT );
FLAGDUMP( PFD_NEED_PALETTE );
FLAGDUMP( PFD_NEED_SYSTEM_PALETTE );
FLAGDUMP( PFD_SWAP_EXCHANGE );
FLAGDUMP( PFD_SWAP_COPY );
FLAGDUMP( PFD_SWAP_LAYER_BUFFERS );
FLAGDUMP( PFD_GENERIC_ACCELERATED );
FLAGDUMP( PFD_SUPPORT_DIRECTDRAW );
if ( pfds[i].iPixelType == PFD_TYPE_RGBA )
{
// fprintf(handle,"RGBA mode\n");
}
else
{
fprintf(handle,"NOT RGBA mode!!!!!!!!!!!!\n");
}
fprintf(handle, "Colour bits: %d\n",pfds[i].cColorBits);
fprintf(handle, "Depth bits: %d\n",pfds[i].cDepthBits);
fprintf(handle,"\n");
}
// look for a best match
for ( i = 1; i <= maxPFD; i++ )
{
fprintf(handle,"(bestMatch: %d)\n",bestMatch );
//
// make sure this has hardware acceleration
//
if ( ( pfds[i].dwFlags & PFD_GENERIC_FORMAT ) != 0 )
{
// if ( !r_allowSoftwareGL->integer )
{
// if ( r_verbose->integer )
{
fprintf(handle,//OutputDebugString(
va ("...PFD %d rejected, software acceleration\n", i ));
}
continue;
}
}
// verify pixel type
if ( pfds[i].iPixelType != PFD_TYPE_RGBA )
{
// if ( r_verbose->integer )
{
fprintf(handle,//OutputDebugString(
va("...PFD %d rejected, not RGBA\n", i) );
}
continue;
}
// verify proper flags
if ( ( ( pfds[i].dwFlags & pPFD->dwFlags ) & pPFD->dwFlags ) != pPFD->dwFlags )
{
// if ( r_verbose->integer )
{
fprintf(handle,//OutputDebugString(
va("...PFD %d rejected, improper flags (0x%x instead of 0x%x)\n", i, pfds[i].dwFlags, pPFD->dwFlags) );
}
continue;
}
// verify enough bits
if ( pfds[i].cDepthBits < 15 )
{
fprintf(handle,va("...PFD %d rejected, depth bits only %d (<15)\n", i, pfds[i].cDepthBits) );
continue;
}
/* if ( ( pfds[i].cStencilBits < 4 ) && ( pPFD->cStencilBits > 0 ) )
{
continue;
}
*/
//
// selection criteria (in order of priority):
//
// PFD_STEREO
// colorBits
// depthBits
// stencilBits
//
if ( bestMatch )
{
/*
// check stereo
if ( ( pfds[i].dwFlags & PFD_STEREO ) && ( !( pfds[bestMatch].dwFlags & PFD_STEREO ) ) && ( pPFD->dwFlags & PFD_STEREO ) )
{
bestMatch = i;
continue;
}
if ( !( pfds[i].dwFlags & PFD_STEREO ) && ( pfds[bestMatch].dwFlags & PFD_STEREO ) && ( pPFD->dwFlags & PFD_STEREO ) )
{
bestMatch = i;
continue;
}
*/
// check color
if ( pfds[bestMatch].cColorBits != pPFD->cColorBits )
{
// prefer perfect match
if ( pfds[i].cColorBits == pPFD->cColorBits )
{
bestMatch = i;
continue;
}
// otherwise if this PFD has more bits than our best, use it
else if ( pfds[i].cColorBits > pfds[bestMatch].cColorBits )
{
bestMatch = i;
continue;
}
}
// check depth
if ( pfds[bestMatch].cDepthBits != pPFD->cDepthBits )
{
// prefer perfect match
if ( pfds[i].cDepthBits == pPFD->cDepthBits )
{
bestMatch = i;
continue;
}
// otherwise if this PFD has more bits than our best, use it
else if ( pfds[i].cDepthBits > pfds[bestMatch].cDepthBits )
{
bestMatch = i;
continue;
}
}
/*
// check stencil
if ( pfds[bestMatch].cStencilBits != pPFD->cStencilBits )
{
// prefer perfect match
if ( pfds[i].cStencilBits == pPFD->cStencilBits )
{
bestMatch = i;
continue;
}
// otherwise if this PFD has more bits than our best, use it
else if ( ( pfds[i].cStencilBits > pfds[bestMatch].cStencilBits ) &&
( pPFD->cStencilBits > 0 ) )
{
bestMatch = i;
continue;
}
}
*/
}
else
{
bestMatch = i;
}
}
fprintf(handle,"Bestmode: %d\n",bestMatch);
if ( !bestMatch )
{
fprintf(handle,"No decent mode found!\n");
fclose(handle);
return 0;
}
if ( ( pfds[bestMatch].dwFlags & PFD_GENERIC_FORMAT ) != 0 )
{
// if ( !r_allowSoftwareGL->integer )
// {
// ri.Printf( PRINT_ALL, "...no hardware acceleration found\n" );
// return 0;
// }
// else
{
fprintf(handle,//OutputDebugString(
"...using software emulation\n" );
}
}
else if ( pfds[bestMatch].dwFlags & PFD_GENERIC_ACCELERATED )
{
fprintf(handle,//OutputDebugString(
"...MCD acceleration found\n" );
}
else
{
fprintf(handle,//OutputDebugString(
"...hardware acceleration found\n" );
}
*pPFD = pfds[bestMatch];
fclose(handle);
return bestMatch;
}
/*
creates an OpenGL rendering context and makes it current
*/
void InitOpenGL( HWND hwnd )
{
HDC hdc = GetDC( hwnd );
mdview.hdc = hdc;
static PIXELFORMATDESCRIPTOR pfd =
{
sizeof(PIXELFORMATDESCRIPTOR), // WORD nSize;
1, // WORD nVersion;
PFD_DRAW_TO_WINDOW | // DWORD dwFlags;
PFD_DOUBLEBUFFER | //
PFD_SUPPORT_OPENGL, //
PFD_TYPE_RGBA, // BYTE iPixelType;
24, // BYTE cColorBits;
// not used to select mode...
//
0, // BYTE cRedBits;
0, // BYTE cRedShift;
0, // BYTE cGreenBits;
0, // BYTE cGreenShift;
0, // BYTE cBlueBits;
0, // BYTE cBlueShift;
0, // BYTE cAlphaBits;
0, // BYTE cAlphaShift;
0, // BYTE cAccumBits;
0, // BYTE cAccumRedBits;
0, // BYTE cAccumGreenBits;
0, // BYTE cAccumBlueBits;
0, // BYTE cAccumAlphaBits;
32,//24, // BYTE cDepthBits;
// not used to select mode...
0, // BYTE cStencilBits;
0, // BYTE cAuxBuffers;
PFD_MAIN_PLANE, // BYTE iLayerType;
// not used to select mode...
0, // BYTE bReserved;
0, // DWORD dwLayerMask;
0, // DWORD dwVisibleMask;
0 // DWORD dwDamageMask;
};
/*
// choose a pixel format that best matches the one we want...
//
int iPixelFormat = ChoosePixelFormat(hdc,&pfd);
//
// set the pixel format for this device context...
//
*/
int iPixelFormat = GLW_ChoosePFD( hdc, &pfd );
VERIFY(SetPixelFormat(hdc, iPixelFormat, &pfd));
// SetPixelFormat( hdc );
HGLRC glrc = wglCreateContext( hdc );
mdview.glrc = glrc;
if ( glrc == NULL) {
Error("Failed on wglCreateContext( HDC hdc )");
}
if (!wglMakeCurrent( hdc, glrc)) {
Error("Failed on wglMakeCurrent(..)" );
}
}
bool gbMinimised = false;
/*
called every pass of the event loop
*/
void SysOnIdle()
{
// OutputDebugString("Idle\n");
if (!gbMinimised)
{
animation_loop();
}
else
{
Sleep(0);
}
}
/*
renders the model with simple viewing parameters
*/
void SysOnPaint( HWND hwnd, bool bFlip /* = true */ )
{
if (!gbMinimised)
{
PAINTSTRUCT ps;
BeginPaint(hwnd, &ps);
wglMakeCurrent( mdview.hdc, mdview.glrc );
render_mdview();
if (bFlip)
{
HDC hDC = GetDC(hwnd);
SwapBuffers( hDC );
ReleaseDC(hwnd,hDC);
}
EndPaint(hwnd, &ps);
}
}
/*
notifies md3view of resize event
*/
void SysOnSize(HWND hwnd, UINT state, int cx, int cy)
{
RECT rect;
GetClientRect( hwnd, &rect );
set_windowSize( rect.right, rect.bottom );
g_iScreenWidth = rect.right - rect.left;
g_iScreenHeight= rect.bottom- rect.top;
gbMinimised = (state == SIZE_MINIMIZED);
InvalidateRect( hwnd, NULL, FALSE );
}
/*
sets quit parameter to break out of the message loop
*/
int SysOnDestroy(HWND hWnd)
{
Text_Destroy(); // while GL context still valid
if (mdview.glrc)
{
wglDeleteContext( mdview.glrc );
mdview.glrc = NULL;
}
if (mdview.hdc)
{
ReleaseDC(mdview.hwnd,mdview.hdc);
mdview.hdc = NULL;
}
extern void FakeCvars_Shutdown(void);
FakeCvars_Shutdown();
mdview.done = true;
return 0;
}
/*
passes control to drag.cpp drag function
*/
POINT DragStartPoint;
void SysOnMouseMove(HWND hwnd, int x, int y, UINT keyFlags)
{
POINT point;
GetCursorPos(&point);
if (!(sys_rbuttondown || sys_lbuttondown || sys_mbuttondown))
{
//ScreenToClient(&point);
return;
}
if (drag( (mkey_enum)keyFlags, point.x, point.y ))
{
SetCursorPos(DragStartPoint.x,DragStartPoint.y);
}
}
/*
releases and shows the cursor again
*/
void SysOnRButtonUp(HWND hwnd, int x, int y, UINT flags)
{
if (!sys_rbuttondown) return;
ReleaseCapture();
ShowCursor( true );
end_drag( (mkey_enum)flags, x, y );
sys_rbuttondown = false;
}
/*
same as above
*/
void SysOnLButtonUp(HWND hwnd, int x, int y, UINT flags)
{
if (!sys_lbuttondown) return;
ReleaseCapture();
ShowCursor( true );
end_drag( (mkey_enum)flags, x, y );
sys_lbuttondown = false;
}
/*
on mouse down, hide the cursor and capture it to window
*/
void SysOnRButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
{
GetCursorPos(&DragStartPoint);
start_drag( (mkey_enum)keyFlags, DragStartPoint.x, DragStartPoint.y );
SetCapture( hwnd );
ShowCursor( false );
sys_rbuttondown = true;
}
/*
*/
void SysOnLButtonDown(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags)
{
GetCursorPos(&DragStartPoint);
start_drag( (mkey_enum)keyFlags, DragStartPoint.x, DragStartPoint.y );
SetCapture( hwnd );
ShowCursor( false );
sys_lbuttondown = true;
}
/*
processes command issued from the tag menu
*/
// I've added an extra param to this call, it won't affect anyone else if you pass NULL as that param,
// this involved a slight change below, but it's safe -slc
//
void SysOnTagCommand( HWND hwnd, int id, HWND hwndCtl, UINT codeNotify, char *psFullFilenameToUseInstead )
{
int i = 0, tagID = id - ID_TAG_START;
NodePosition pos;
GLMODEL_DBLPTR dblptr;
for (pos=tagMenuList.first() ; pos!=NULL ; pos=tagMenuList.after(pos)) {
if (i == tagID) break;
i++;
}
#ifdef DEBUG_PARANOID
if (pos==NULL) Debug("tagMenuList entry not found");
#endif
dblptr = (GLMODEL_DBLPTR)pos->element();
char fullName[256]={0};
OPENFILENAME *ofn=NULL;
if (psFullFilenameToUseInstead)
{
strcpy(fullName,psFullFilenameToUseInstead);
}
else
{
ofn = FileOpenDialog(hwnd, id, codeNotify, hwndCtl, IDS_FILESTRING );
if (ofn)
{
strcpy( fullName, ofn->lpstrFile );
strcat( fullName, ofn->lpstrFileTitle );
}
}
if (strlen(fullName))
{
if (dblptr != 0) freemdl_fromtag(dblptr);
loadmdl_totag( fullName, dblptr );
InvalidateRect( hwnd, NULL, FALSE );
//leave this here!! without the screen doesn't
//refresh properly sometimes!!
InvalidateRect( mdview.hwnd, NULL, FALSE );
if (ofn)
free( ofn );
}
else
{
if (dblptr != 0)
{
freemdl_fromtag( dblptr );
}
}
}
// we get here when the user selects one of the anim sequences on the new pulldown menus...
//
void SysOnAnimsCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
// OutputDebugString(va("Menu item code %d\n",id));
if (id < ID_MENUITEMS_LOWERANIMS)
{
// upper anim clicked on...
//
int iSelection = id-ID_MENUITEMS_UPPERANIMS;
// 0 = choose seq
// 1 = choose multi-seq
// 2 = none
// 3 = 1st seq
// 4 = 2nd seq etc...
switch (iSelection)
{
case 0: // choose seq
case 1: // choose multi-seq
ErrorBox("Ignore this for now");
iAnimLockNumber_Upper = 0; // xxxxxxxxxxxxxxxxxxxxx for now...
break;
default:
iAnimLockNumber_Upper = iSelection-2;
break;
}
}
else
{
// lower anim clicked on...
//
int iSelection = id-ID_MENUITEMS_LOWERANIMS;
// 0 = choose seq
// 1 = choose multi-seq
// 2 = none
// 3 = 1st seq
// 4 = 2nd seq etc...
switch (iSelection)
{
case 0: // choose seq
case 1: // choose multi-seq
ErrorBox("Ignore this for now");
iAnimLockNumber_Lower = 0; // xxxxxxxxxxxxxxxxxxxxx for now...
break;
default:
iAnimLockNumber_Lower = iSelection-2;
break;
}
}
}
#if 0
// takes (eg) "q:\quake\baseq3\textures\borg\name.tga"
//
// and produces "q:\quake\baseq3\" // note the trailing backslash, for this app only!!!!!!!!!!!!!!!!!!!!
//
// (copied from ShaderEd, but this app doesn't have MFC, so no CStrings...)
//
LPCSTR Filename_QUAKEBASEONLY(LPCSTR psFullPathedName /* CString &string */)
{
static char sLine[1024];
char *p;
strcpy(sLine,psFullPathedName);
while ((p=strchr(sLine,'/'))!=0) *p='\\'; // string.Replace("/","\\");
strlwr(sLine); // string.MakeLower();
/* int loc = string.Find("\\quake");
if (loc>=0)
{
loc = string.Find("\\",loc+1); // pointing at "\\baseq3" (or "demoq3" etc)
if (loc>=0)
{
loc = string.Find("\\",loc+1); // pointing at first part of string past the quake dir stuff
string = string.Left(loc);
}
}
*/
p = strstr(sLine,"\\quake");
if (p)
{
p = strstr(p+1,"\\"); // pointing at "\\baseq3" (or "demoq3" etc)
if (p)
{
p = p = strstr(p+1,"\\"); // pointing at first part of string past the quake dir stuff
*(p+1)=0; // +1 ensures trailing slash is left on as well
}
}
return sLine;
}
#endif
#define BASEDIRNAME "base"
char qdir[1024];
char gamedir[1024]; // q:\quake\baseef
// totally hacky and awful code pasted from other bits of crud
LPCSTR Filename_QUAKEBASEONLY(LPCSTR psFullPathedName )
{
static char sLine[1024];
char temp[1024];
char *path = temp;
const char *c;
const char *sep;
int len, count;
sLine[0]=0;
strcpy(path,psFullPathedName);
_strlwr(path);
// search for "base" in path from the RIGHT hand side (and must have a [back]slash just before it)
len = strlen(BASEDIRNAME);
for (c=path+strlen(path)-1 ; c != path ; c--)
{
// int i;
if (!strnicmp (c, BASEDIRNAME, len)
&&
(*(c-1) == '/' || *(c-1) == '\\') // would be more efficient to do this first, but only checking after a strncasecmp ok ensures no invalid pointer-1 access
)
{
sep = c + len;
count = 1;
while (*sep && *sep != '/' && *sep != '\\')
{
sep++;
count++;
}
strncpy (gamedir, path, c+len+count-path);
gamedir[c+len+count-path]=0;
strncpy (qdir, path, c-path);
qdir[c-path] = 0;
}
}
strcpy(sLine,gamedir);
while ((path=strchr(sLine,'/'))!=NULL) *path='\\';
return sLine;
}
bool ExportThisModel( LPCSTR psFilename, gl_model* pModel, bool bExportAsMD3);
bool R_ExportModel( gl_model* pModel, bool bMD3)
{
bool bReturn = true;
if (pModel)
{
OutputDebugString(va("Exporting model \"%s\"\n",pModel->sMDXFullPathname));
// export this model...
//
ExportThisModel( va("%s%s",Filename_WithoutExt(pModel->sMDXFullPathname), bMD3?".md3":".glm"), pModel, bMD3 );
// export its children...
//
for (UINT j=0; j<pModel->iNumTags ; j++)
{
gl_model *pChild = pModel->linkedModels[j];
if (pChild)
{
if (!R_ExportModel(pChild, bMD3))
{
bReturn = false;
}
}
}
}
return bReturn;
}
void ExportMD3(void)
{
if (GetYesNo("Export as MD3, are you sure?"))
{
if (!R_ExportModel( mdview.baseModel, true ))
{
ErrorBox("Errors occured, unable to export as MD3!");
}
else
{
ExportThisModel( NULL, NULL, true); // bool bExportAsMD3
}
}
}
bool g_bPerfect = false;
void ExportG2(bool bPerfect)
{
g_bPerfect = bPerfect;
if ( mdview.baseModel )
{
if (GetYesNo(va("Export as Ghoul2 .GLM/.GLA files%s, are you sure?",bPerfect?" ( *without* 90-degree skew )":"")))
{
if (!R_ExportModel( mdview.baseModel, false ))
{
ErrorBox("Errors occured, unable to export as Ghoul2!");
}
else
{
ExportThisModel( NULL, NULL, false); // bool bExportAsMD3
}
}
}
else
{
ErrorBox( "No model loaded!");
}
}
/*
processes events from the menu
*/
void SysOnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
// process tag menu requests
if ((id >= ID_TAG_START) && (id < ID_TAG_START+tagMenuList.size())) {
SysOnTagCommand( hwnd, id, hwndCtl, codeNotify, NULL );
InvalidateRect( mdview.hwnd, NULL, FALSE );
}
if (id >= ID_MENUITEMS_UPPERANIMS && id<ID_MENUITEMS_NEXT)
{
SysOnAnimsCommand(hwnd, id, hwndCtl, codeNotify );
FrameAdvanceAnim(0); // cheat, force it to re-evaluate legaliser in case new locks are on
InvalidateRect( hwnd, NULL, FALSE );
}
switch(id)
{
case ID_FILE_OPEN:
{
char sFullName[256];
strcpy(sFullName,"");
if (getCmdLine())
{
strcpy( sFullName, getCmdLine() );
FreeCmdLine();
}
else
{
OPENFILENAME *ofn;
ofn = FileOpenDialog(hwnd, id, codeNotify, hwndCtl, IDS_FILESTRING );
if (ofn)
{
strcpy( sFullName, ofn->lpstrFile );
strcat( sFullName, ofn->lpstrFileTitle );
free( ofn );
}
}
if (strlen(sFullName))
{
strcpy( mdview.basepath, Filename_QUAKEBASEONLY(sFullName));
free_mdviewdata();
bool bOk = loadmdl( sFullName );
// if model loaded ok, and it was called lower.md3, and had a tag called "tag_torso", then
// automatically (try) load "upper.md3" from the same place
bool bLowerMD3 = !stricmp(Filename_WithoutPath(sFullName),"lower.md3");
bool bLowerMDR = !stricmp(Filename_WithoutPath(sFullName),"lower.mdr");
if (bOk)
{
if ((bLowerMD3||bLowerMDR) && giTagMenuSubtractValue_Torso!=-1)
{
char sFullPathedName_Upper[MAX_PATH];
strcpy(sFullPathedName_Upper,va("%s\\upper.%s",Filename_PathOnly(sFullName),bLowerMD3?"md3":"mdr"));
if (file_exists(sFullPathedName_Upper))
{
pModel_Lower = pLastLoadedModel;
pLastLoadedModel = NULL;
int newID = tagMenuList.size(); // get to end of tag list
newID-= giTagMenuSubtractValue_Torso; // back up to "tag_torso"
newID+= ID_TAG_START; // account for resource.h value
SysOnTagCommand( hwnd, newID, hwndCtl, codeNotify, sFullPathedName_Upper);
pModel_Upper = pLastLoadedModel; // NULL or ptr
// switch on flat texturing and filtering (looks better for what we need)...
//
SysOnCommand(hwnd, ID_VIEW_TEXTURED, hwndCtl, codeNotify);
SysOnCommand(hwnd, ID_VIEW_FILTEREDTEXTURE, hwndCtl, codeNotify);
// now try auto-loading the head...
//
if (giTagMenuSubtractValue_Head!=-1)
{
char sFullPathedName_Head[MAX_PATH];
strcpy(sFullPathedName_Head,va("%s\\head.md3",Filename_PathOnly(sFullName)));
if (file_exists(sFullPathedName_Head))
{
pLastLoadedModel = NULL;
int newID = tagMenuList.size(); // get to end of tag list
newID-= giTagMenuSubtractValue_Head; // back up to "tag_head"
newID+= ID_TAG_START; // account for resource.h value
SysOnTagCommand( hwnd, newID, hwndCtl, codeNotify, sFullPathedName_Head);
}
}
}
// now attempt the animation stuff... (this is now done whether or not an UPPER model exists, to
// cope with weird stuff like the vermin model)
//
HDC hDC = GetDC(hwnd);
LoadAnimationCFG(va("%s\\animation.cfg",Filename_PathOnly(sFullName)),hDC);
ReleaseDC(hwnd,hDC);
InvalidateRect( hwnd, NULL, FALSE );
}
else
{
// if you load something with "weapon" in it's path somewhere, and that ends in "_hand.md3", then
// try and auto-load the main components of a weapon onto the appropriate tags...
//
if (strstr(String_ToLower(sFullName),"weapon") && strstr(String_ToLower(sFullName),"_hand.md3"))
{
char sWeaponBasename[MAX_PATH];
strcpy(sWeaponBasename,Filename_WithoutExt(Filename_WithoutPath(sFullName)));
*strrchr(sWeaponBasename,'_')=0; // '_' will be present at this point
int iWeaponID = tagMenuList.size(); // get to end of tag list
iWeaponID-= giTagMenuSubtractValue_Weapon; // back up to correct tag
iWeaponID+= ID_TAG_START; // account for resource.h value
int iBarrelID = tagMenuList.size(); // get to end of tag list
iBarrelID-= giTagMenuSubtractValue_Barrel; // back up to correct tag
iBarrelID+= ID_TAG_START; // account for resource.h value
int iBarrel2ID = tagMenuList.size(); // get to end of tag list