-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathltshell.cpp
More file actions
1821 lines (1534 loc) · 54.9 KB
/
Copy pathltshell.cpp
File metadata and controls
1821 lines (1534 loc) · 54.9 KB
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
#include "common.h"
#if TARGET == PC
#include "resource.h"
#include "DX.h"
#include "System.h"
#include "CLIParams.h"
#include "ParticleTexture.h"
#include "tgaloader.h"
#include "imposter.h"
#include "VertexShader.h"
#include "deviceobject.h"
#include "console.h"
#include "DebugText.h"
#include "renderinfo.h"
#include "imagehlp.h"
#include "process.h"
#include "game.h"
#include "modelviewer.h"
#include "cutsceneeditor.h"
#include "frontend.h"
#pragma comment(lib, "imagehlp.lib")
#pragma comment(lib, "d3dx8.lib")
#pragma comment(lib, "d3d8.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "dinput8.lib")
#pragma comment(lib, "dxguid.lib")
#pragma comment(lib, "d3dxof.lib")
PCLTShell LT;
DWORD PCLTShell::mRenderStates[N_RENDERSTATES];
DWORD PCLTShell::mTextureStageStates[8][N_TEXTURESTAGESTATES];
#ifdef LT_DEBUG
DWORD PCLTShell::mRenderStates2[N_RENDERSTATES];
DWORD PCLTShell::mTextureStageStates2[8][N_TEXTURESTAGESTATES];
#endif
IDirect3DBaseTexture8* PCLTShell::mCurrentTextures[8];
DWORD PCLTShell::mLastVertexShader;
#ifndef EDITORBUILD2
#define PCLTShellSUPERTYPE CD3DApplication
#else
#define PCLTShellSUPERTYPE CEditorD3DApp
#endif
//-----------------------------------------------------------------------------
DeviceObject* PCLTShell::mDeviceObjects=0;
//*********************************************************************************
// Critical exception error handler
//*********************************************************************************
#define EWRITE0(x) \
{ \
sprintf(buffer,x); \
TRACE(buffer); \
fwrite(&buffer,strlen(buffer),1,fout); \
}
#define EWRITE1(x,a) \
{ \
sprintf(buffer,x,a); \
TRACE(buffer); \
fwrite(&buffer,strlen(buffer),1,fout); \
}
#define EWRITE2(x,a,b) \
{ \
sprintf(buffer,x,a,b); \
TRACE(buffer); \
fwrite(&buffer,strlen(buffer),1,fout); \
}
#define EWRITE3(x,a,b,c) \
{ \
sprintf(buffer,x,a,b,c); \
TRACE(buffer); \
fwrite(&buffer,strlen(buffer),1,fout); \
}
#define EWRITE4(x,a,b,c,d) \
{ \
sprintf(buffer,x,a,b,c,d); \
TRACE(buffer); \
fwrite(&buffer,strlen(buffer),1,fout); \
}
void resolvesymbolmodule(DWORD addr,char *name)
{
IMAGEHLP_MODULE modinfo;
memset(&modinfo,0,sizeof(IMAGEHLP_MODULE));
modinfo.SizeOfStruct=sizeof(IMAGEHLP_MODULE);
if (SymGetModuleInfo(GetCurrentProcess(),addr,&modinfo))
{
strcpy(name,modinfo.ModuleName);
}
else
{
strcpy(name,"N/A");
}
}
void resolvesymbolname(DWORD addr,char *name)
{
DWORD displacement;
byte staticspace[sizeof(IMAGEHLP_SYMBOL)+256];
IMAGEHLP_SYMBOL *symbol=(IMAGEHLP_SYMBOL *) &staticspace;
memset(symbol,0,sizeof(IMAGEHLP_SYMBOL)+256);
symbol->SizeOfStruct=sizeof(IMAGEHLP_SYMBOL)+256;
symbol->MaxNameLength=256;
if (SymGetSymFromAddr(GetCurrentProcess(),addr,&displacement,symbol))
{
if (displacement==0)
sprintf(name,"%s",symbol->Name);
else
sprintf(name,"%s (+0x%08x)",symbol->Name,displacement);
}
else
{
strcpy(name,"N/A");
}
}
BOOL resolvesymbolline(DWORD addr,char *filename,DWORD *lineno)
{
IMAGEHLP_LINE line;
memset(&line,0,sizeof(IMAGEHLP_LINE));
line.SizeOfStruct=sizeof(IMAGEHLP_LINE);
// Walk backward until we hit a valid line
BOOL done=FALSE;
DWORD offset=0;
DWORD displacement;
while ((!done) && (offset<128))
{
done=SymGetLineFromAddr(GetCurrentProcess(),addr-offset,&displacement,&line);
offset++;
}
if (done)
{
strcpy(filename,line.FileName);
*lineno=line.LineNumber;
return(TRUE);
}
return(FALSE);
}
void resolvesymbolinfo(DWORD addr,char *name)
{
char mod[4096];
resolvesymbolmodule(addr,mod);
resolvesymbolname(addr,name);
strcat(name," (");
strcat(name,mod);
strcat(name,")");
}
LONG __stdcall ExceptionHandler(EXCEPTION_POINTERS *info)
{
SetUnhandledExceptionFilter(NULL); // We don't want re-entrant exception handling!
FILE *fout=fopen("OnslaughtException.txt","wt");
char buffer[4096];
char name[4096];
EWRITE0("-- Onslaught exception handler --\n")
// Setup symbol services
char cli[4096];
strcpy(cli,FromTCHAR(GetCommandLine()));
char *start=cli;
char *p=start;
if (*p=='"')
{
// Find end quote and terminate string there
p++;
start++;
while (*p!=0)
{
if (*p=='"')
{
*p=0;
}
p++;
}
}
else
{
// Find first space and terminate there
while (*p!=0)
{
if (*p==32)
*p=0;
p++;
}
}
// Find last slash and terminate there
char *lastslash=0;
p=start;
while (*p!=0)
{
if (*p=='\\')
lastslash=p;
p++;
}
if (lastslash)
*lastslash=0;
EWRITE1("\nExecutable path : %s\n",start);
SymSetOptions(SYMOPT_LOAD_LINES);
if (!SymInitialize(GetCurrentProcess(),start,TRUE))
{
EWRITE0("\nFailed to initialise symbol services :-(\n\n");
}
// Write out exception details
EXCEPTION_RECORD *current=info->ExceptionRecord;
int exceptionnum=0;
while (current)
{
EWRITE1("\n--Exception info (%d)--\n\n",exceptionnum)
EWRITE0("Type : ")
if (current->ExceptionCode==EXCEPTION_ACCESS_VIOLATION)
{
EWRITE0("Access violation\n");
if (current->NumberParameters>=2)
{
if (current->ExceptionInformation[0]==0)
EWRITE0("Access : Read access attempted\n")
else
EWRITE0("Access : Write access attempted\n")
EWRITE1("Address : 0x%08x\n",current->ExceptionInformation[1])
}
else
{
EWRITE0("Exception parameter frame invalid!?\n")
}
}
else if (current->ExceptionCode==EXCEPTION_ARRAY_BOUNDS_EXCEEDED)
EWRITE0("Array bounds exceeded\n")
else if (current->ExceptionCode==EXCEPTION_BREAKPOINT)
EWRITE0("Breakpoint hit\n")
else if (current->ExceptionCode==EXCEPTION_DATATYPE_MISALIGNMENT)
EWRITE0("Data misalignment\n")
else if (current->ExceptionCode==EXCEPTION_FLT_DENORMAL_OPERAND)
EWRITE0("FPU denormal operand\n")
else if (current->ExceptionCode==EXCEPTION_FLT_DIVIDE_BY_ZERO)
EWRITE0("FPU divide by zero\n")
else if (current->ExceptionCode==EXCEPTION_FLT_INEXACT_RESULT)
EWRITE0("FPU inexact result(!)\n")
else if (current->ExceptionCode==EXCEPTION_FLT_INVALID_OPERATION)
EWRITE0("FPU invalid operation\n")
else if (current->ExceptionCode==EXCEPTION_FLT_OVERFLOW)
EWRITE0("FPU overflow\n")
else if (current->ExceptionCode==EXCEPTION_FLT_STACK_CHECK)
EWRITE0("FPU stack over/underflow\n")
else if (current->ExceptionCode==EXCEPTION_FLT_UNDERFLOW)
EWRITE0("FPU result underflow\n")
else if (current->ExceptionCode==EXCEPTION_ILLEGAL_INSTRUCTION)
EWRITE0("Illegal instruction\n")
else if (current->ExceptionCode==EXCEPTION_IN_PAGE_ERROR)
EWRITE0("Page in failed\n")
else if (current->ExceptionCode==EXCEPTION_INT_DIVIDE_BY_ZERO)
EWRITE0("Integer divide by zero\n")
else if (current->ExceptionCode==EXCEPTION_INT_OVERFLOW)
EWRITE0("Integer overflow\n")
else if (current->ExceptionCode==EXCEPTION_INVALID_DISPOSITION)
EWRITE0("Invalid exception handler disposition\n")
else if (current->ExceptionCode==EXCEPTION_NONCONTINUABLE_EXCEPTION)
EWRITE0("Noncontinuable exception was continued\n")
else if (current->ExceptionCode==EXCEPTION_PRIV_INSTRUCTION)
EWRITE0("Unauthorised privileged instruction execution\n")
else if (current->ExceptionCode==EXCEPTION_SINGLE_STEP)
EWRITE0("Single step trap\n")
else if (current->ExceptionCode==EXCEPTION_STACK_OVERFLOW)
EWRITE0("Stack overflow\n")
else
EWRITE1("*Unknown exception code (%d)*\n",current->ExceptionCode)
EWRITE1("PC : 0x%08x\n",current->ExceptionAddress)
if (current->ExceptionFlags==0)
EWRITE0("Continuable : Yes\n")
else if (current->ExceptionFlags==EXCEPTION_NONCONTINUABLE)
EWRITE0("Continuable : No\n")
else
EWRITE1("*Unknown exception flags (%d)*\n",current->ExceptionFlags)
// Do symbol lookups
DWORD pc=(DWORD) current->ExceptionAddress;
HANDLE pid=GetCurrentProcess();
IMAGEHLP_MODULE modinfo;
memset(&modinfo,0,sizeof(IMAGEHLP_MODULE));
modinfo.SizeOfStruct=sizeof(IMAGEHLP_MODULE);
resolvesymbolinfo(pc,name);
EWRITE1("PC in : %s\n",name)
DWORD lineno;
if (resolvesymbolline(pc,name,&lineno))
{
EWRITE1("File : %s\n",name);
EWRITE1("Line : %d\n",lineno);
}
else
{
DWORD err=GetLastError();
EWRITE1("Unable to resolve line (error 0x%08x)\n",err)
}
EWRITE0("\n--Stack trace--\n\n")
STACKFRAME sf;
memset(&sf,0,sizeof(sf));
sf.AddrPC.Offset=pc;
sf.AddrStack.Offset=info->ContextRecord->Esp;
sf.AddrFrame.Offset=info->ContextRecord->Ebp;
sf.AddrPC.Mode=AddrModeFlat;
sf.AddrStack.Mode=AddrModeFlat;
sf.AddrFrame.Mode=AddrModeFlat;
int maxdump=128;
while ((StackWalk(IMAGE_FILE_MACHINE_I386,GetCurrentProcess(),GetCurrentThread(),&sf,NULL,NULL,SymFunctionTableAccess,SymGetModuleBase,NULL)) && (maxdump>0))
{
DWORD line;
char filename[512];
resolvesymbolname((DWORD) sf.AddrPC.Offset,name);
resolvesymbolline((DWORD) sf.AddrPC.Offset,filename,&line);
EWRITE2("0x%08x %s\n",sf.AddrPC.Offset,name)
EWRITE2(" %s line %d\n",filename,line)
EWRITE4(" Parameters may be 0x%08x,0x%08x,0x%08x,0x%08x\n",sf.Params[0],sf.Params[1],sf.Params[2],sf.Params[3]);
EWRITE1(" Stack frame at 0x%08x\n",sf.AddrFrame.Offset);
if (sf.Virtual)
{
EWRITE0(" [Virtual frame]\n");
}
if (sf.Far)
{
EWRITE0(" [Far call]\n");
}
EWRITE0("\n");
maxdump--;
}
EWRITE0("-Module info-\n\n");
if (SymGetModuleInfo(pid,pc,&modinfo))
{
EWRITE1("Module name : %s\n",modinfo.ModuleName)
EWRITE1("Base address : 0x%08x\n",modinfo.BaseOfImage)
EWRITE1("Loaded symbols : %d\n",modinfo.NumSyms)
EWRITE1("Checksum : 0x%08x\n",modinfo.CheckSum)
}
else
{
EWRITE0("Could not resolve module information!\n")
}
exceptionnum++;
current=current->ExceptionRecord;
}
EWRITE0("\n--End of exception info--\n\n")
EWRITE0("--Context information--\n\n")
CONTEXT *c=info->ContextRecord;
EWRITE1("Dr0 = 0x%08x\n",c->Dr0)
EWRITE1("Dr1 = 0x%08x\n",c->Dr1)
EWRITE1("Dr2 = 0x%08x\n",c->Dr2)
EWRITE1("Dr3 = 0x%08x\n",c->Dr3)
EWRITE1("Dr6 = 0x%08x\n",c->Dr6)
EWRITE1("Dr7 = 0x%08x\n",c->Dr7)
EWRITE0("\n")
EWRITE1("SegGs = 0x%08x\n",c->SegGs)
EWRITE1("SegFs = 0x%08x\n",c->SegFs)
EWRITE1("SegEs = 0x%08x\n",c->SegEs)
EWRITE1("SegDs = 0x%08x\n",c->SegDs)
EWRITE0("\n")
resolvesymbolinfo(c->Edi,name);
EWRITE2("EDI = 0x%08x (%s)\n",c->Edi,name)
resolvesymbolinfo(c->Esi,name);
EWRITE2("ESI = 0x%08x (%s)\n",c->Esi,name)
resolvesymbolinfo(c->Eax,name);
EWRITE2("EAX = 0x%08x (%s)\n",c->Eax,name)
resolvesymbolinfo(c->Ebx,name);
EWRITE2("EBX = 0x%08x (%s)\n",c->Ebx,name)
resolvesymbolinfo(c->Ecx,name);
EWRITE2("ECX = 0x%08x (%s)\n",c->Ecx,name)
resolvesymbolinfo(c->Edx,name);
EWRITE2("EDX = 0x%08x (%s)\n",c->Edx,name)
EWRITE0("\n")
resolvesymbolinfo(c->Ebp,name);
EWRITE2("EBP = 0x%08x (%s)\n",c->Ebp,name)
resolvesymbolinfo(c->Eip,name);
EWRITE2("EIP = 0x%08x (%s)\n",c->Eip,name)
resolvesymbolinfo(c->Esp,name);
EWRITE2("ESP = 0x%08x (%s)\n",c->Esp,name)
resolvesymbolinfo(c->SegCs,name);
EWRITE2("SegCs = 0x%08x (%s)\n",c->SegCs,name)
resolvesymbolinfo(c->SegSs,name);
EWRITE2("SegSs = 0x%08x (%s)\n",c->SegSs,name)
EWRITE1("EFlags = 0x%08x\n",c->EFlags)
EWRITE0("\n--End of exception dump--\n")
fclose(fout);
// Trigger userdump
char arga[256];
char argb[256];
sprintf(arga,"userdump.exe");
sprintf(argb,"%d",getpid());
// DeleteFile("onslaught.dmp");
// execl("userdump.exe",arga,argb,NULL);
return(EXCEPTION_EXECUTE_HANDLER);
}
#include "debuglog.h"
//-----------------------------------------------------------------------------
#ifndef EDITORBUILD
//-----------------------------------------------------------------------------
void ExitCode()
{
TRACE("Cleaning up memory manager...\n");
MEM_MANAGER.SetMerge( TRUE );
MEM_MANAGER.Cleanup();
// We can't call this because we can't be sure all the global destructors have been called...
TRACE("Shutting down memory manager...\n");
MEM_MANAGER.Shutdown();
TRACE("Memory Manager Shutdown...\n");
}
//inline int Qf(float x) {
// float t=((x-0.5f/256.0f))+(float)(1.0f*(1<<15));
// return *(int*)&t;
//}
//-----------------------------------------------------------------------------
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
// --- Setup debugging services ---
// _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
// Setup our exception handler
SetUnhandledExceptionFilter(&ExceptionHandler);
#ifdef _DEBUG
// Turn on FPU exceptions (except FPU_INEXACT and FPU_UNDERFLOW)
// Note that d3dapp.cpp needs to turn on the FPU_PRESERVE flag
// for the device in order for this to work!
_controlfp(_EM_INEXACT | _EM_UNDERFLOW | _EM_OVERFLOW | _EM_ZERODIVIDE | _EM_INVALID, _MCW_EM);
#endif
// --- End of debugging services ---
// Set up our exit handler
atexit(ExitCode);
PLATFORM.SetMemorySize(96*1024*1024); // Default memory size
// JCL - process command line
CLIPARAMS.GetParams(lpCmdLine);
LOG.AddMessage("Init game with %d bytes", PLATFORM.GetMemorySize()) ;
#ifndef VANILLA_MEMORYMANAGER
MEM_MANAGER.Init(PLATFORM.GetMemorySize());
#endif
LT.mhInstance=hInstance;
if( FAILED( LT.Create( hInstance/*, GetCommandLine()*/ ) ) )
return 0;
if(!LT.SetupSystemMessageHandler()) return LT.MsgInfo();
LT.SetRunning(true);
return LT.MainLoop();
}
#endif
//-----------------------------------------------------------------------------
void con_whatami(char *cmd)
{
LT.ShowGFXCardInfo();
}
//-----------------------------------------------------------------------------
int PCLTShell::MainLoop()
{
// JCL - new main loop - bit simpler!
if (SYSTEM.Init())
{
CONSOLE.RegisterCommand("cg_whatami","Shows the current graphics card details",&con_whatami);
CONSOLE.Print("Memory heap at %dMb\n",(PLATFORM.GetMemorySize()/(1024*1024)));
//if(mJoypads!=0) // We can't do this because it causes the modelviewer to exit!
SYSTEM.Run();
SYSTEM.Shutdown();
Cleanup3DEnvironment();
}
/* if( FAILED( hr = GAME.Init())) return 0;
while(!LT.WantsToQuit())
{
if(!LT.HandlingSystemStuff())
{
if( FAILED( hr = GAME.Update() ) ) LT.IWantToQuit();
if( FAILED( hr = GAME.Process() ) ) LT.IWantToQuit();
}
}
GAME.Shutdown(); // this doesn't work after shutdowns below :-(*/
DestroyMenu( GetMenu(LT.GetHWnd()) );
DestroyWindow( LT.GetHWnd() );
// if ( _CrtDumpMemoryLeaks() )
// ::MessageBox( NULL , "Memory leaks detected on exit!\nCheck debugging traces for details." ,
// "Onslaught" , MB_ICONEXCLAMATION|MB_OK );
return LT.MsgInfo();
}
//-----------------------------------------------------------------------------
BOOL PCLTShell::SetupSystemMessageHandler()
{
// Load keyboard accelerators
mhAccel = LoadAccelerators( NULL, MAKEINTRESOURCE(IDR_MAIN_ACCEL) );
// Now we're ready to recieve and process Windows messages.
PeekMessage( &mMsg, NULL, 0U, 0U, PM_NOREMOVE );
if( WM_QUIT != mMsg.message) return TRUE;
else
{
ASSERT(0); // does this ever happen?
return FALSE;
}
}
//-----------------------------------------------------------------------------
BOOL PCLTShell::HandlingSystemStuff()
{
BOOL bGotMsg;
BOOL cant_proc=TRUE;
// Use PeekMessage() if the app is active, so we can use idle time to
// render the scene. Else, use GetMessage() to avoid eating CPU time.
if( m_bActive )
bGotMsg = PeekMessage( &mMsg, NULL, 0U, 0U, PM_REMOVE );
else
bGotMsg = GetMessage( &mMsg, NULL, 0U, 0U );
if( bGotMsg )
{
// Translate and dispatch the message
if( 0 == TranslateAccelerator( m_hWnd, mhAccel, &mMsg ) )
{
TranslateMessage( &mMsg );
DispatchMessage( &mMsg );
cant_proc = TRUE;
}
}
else
{
// Render a frame during idle time (no messages are waiting)
if( m_bActive && m_bReady )
{
cant_proc = FALSE;
}
}
if(!cant_proc) // stuff from top of Render3DEnvironment()
{
HRESULT hr;
// Test the cooperative level to see if it's okay to render
if( FAILED( hr = m_pd3dDevice->TestCooperativeLevel() ) )
{
// If the device was lost, do not render until we get it back
if( D3DERR_DEVICELOST == hr )
cant_proc = TRUE;
// Check if the device needs to be resized.
if( D3DERR_DEVICENOTRESET == hr )
{
// If we are windowed, read the desktop mode and use the same format for
// the back buffer
if( m_bWindowed )
{
D3DAdapterInfo* pAdapterInfo = &m_Adapters[m_dwAdapter];
m_pD3D->GetAdapterDisplayMode( m_dwAdapter, &pAdapterInfo->d3ddmDesktop );
m_d3dpp.BackBufferFormat = pAdapterInfo->d3ddmDesktop.Format;
}
if( FAILED( hr = Resize3DEnvironment() ) )
{
SendMessage( LT.GetHWnd(), WM_CLOSE, 0, 0 );
cant_proc = TRUE;
}
}
cant_proc = TRUE;
}
// Get the app's time, in seconds. Skip rendering if no time elapsed
FLOAT fAppTime = DXUtil_Timer( TIMER_GETAPPTIME );
FLOAT fElapsedAppTime = DXUtil_Timer( TIMER_GETELAPSEDTIME );
if( ( 0.0f == fElapsedAppTime ) && m_bFrameMoving )
return S_OK;
// Not sure about this shite
// FrameMove (animate) the scene
if( m_bFrameMoving || m_bSingleStep )
{
// Store the time for the app
m_fTime = fAppTime;
m_fElapsedTime = fElapsedAppTime;
// Frame move the scene
// if( FAILED( hr = FrameMove() ) )
// return hr;
m_bSingleStep = FALSE;
}
// end of shite
}
// process joystick
for (int i=0;i<MAX_JOYPADS;i++)
{
UpdateJoystick(i);
}
/* if(mJoyState[0]->rgbButtons[11]) // hack to turn full screen on
{
if( m_bActive && m_bReady )
{
if( m_bWindowed )
GetWindowRect( m_hWnd, &m_rcWindowBounds );
if( FAILED( ToggleFullscreen() ) )
{
DisplayErrorMsg( D3DAPPERR_RESIZEFAILED, MSGERR_APPMUSTEXIT );
return 0;
}
}
}*/
return cant_proc;
}
//-----------------------------------------------------------------------------
void PCLTShell::DisplayScreen()
{
// Keep track of the frame count
/* {
static FLOAT fLastTime = 0.0f;
static DWORD dwFrames = 0L;
FLOAT fTime = DXUtil_Timer( TIMER_GETABSOLUTETIME );
++dwFrames;
// Update the scene stats once per second
if( fTime - fLastTime > 1.0f )
{
m_fFPS = dwFrames / (fTime - fLastTime);
fLastTime = fTime;
dwFrames = 0L;
// Get adapter's current mode so we can report
// bit depth (back buffer depth may be unknown)
D3DDISPLAYMODE mode;
m_pD3D->GetAdapterDisplayMode(m_dwAdapter, &mode);
char buffer[256];
sprintf(buffer,"%.02f fps (%dx%dx%d)", m_fFPS,
m_d3dsdBackBuffer.Width, m_d3dsdBackBuffer.Height,
mode.Format==D3DFMT_X8R8G8B8?32:16 );
_tcscpy(m_strFrameStats,ToTCHAR(buffer));
if( m_bUseDepthBuffer )
{
D3DAdapterInfo* pAdapterInfo = &m_Adapters[m_dwAdapter];
D3DDeviceInfo* pDeviceInfo = &pAdapterInfo->devices[pAdapterInfo->dwCurrentDevice];
D3DModeInfo* pModeInfo = &pDeviceInfo->modes[pDeviceInfo->dwCurrentMode];
switch( pModeInfo->DepthStencilFormat )
{
case D3DFMT_D16:
lstrcat( m_strFrameStats, ToTCHAR(" (D16)") );
break;
case D3DFMT_D15S1:
lstrcat( m_strFrameStats, ToTCHAR(" (D15S1)") );
break;
case D3DFMT_D24X8:
lstrcat( m_strFrameStats, ToTCHAR(" (D24X8)") );
break;
case D3DFMT_D24S8:
lstrcat( m_strFrameStats, ToTCHAR(" (D24S8)") );
break;
case D3DFMT_D24X4S4:
lstrcat( m_strFrameStats, ToTCHAR(" (D24X4S4)") );
break;
case D3DFMT_D32:
lstrcat( m_strFrameStats, ToTCHAR(" (D32)") );
break;
}
}
}
}
*/
// Show the frame on the primary surface.
m_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}
//-----------------------------------------------------------------------------
// Name: CMyD3DApplication()
// Desc: Application constructor. Sets attributes for the app.
//-----------------------------------------------------------------------------
PCLTShell::PCLTShell()
:PCLTShellSUPERTYPE()
{
pDI = NULL;
for (int i=0;i<MAX_JOYPADS;i++)
{
pJoystick[i] = NULL;
mRumbleInitialised[i] = FALSE;
mJoyState[i]=NULL;
mOldJoyState[i]=NULL;
}
mRumbleEnabled = TRUE;
m_strWindowTitle = ToTCHAR("Battle Engine Aquila");
m_bUseDepthBuffer = TRUE;
// m_DepthBufferFormat = D3DFMT_UNKNOWN_D16;
m_bWindowed = FALSE;
mJoypads=0;
m_bTextureCompressionDisabled = FALSE;
}
PCLTShell::~PCLTShell()
{
}
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: This creates all device-dependant managed objects, such as managed
// textures and managed vertex buffers.
//-----------------------------------------------------------------------------
HRESULT PCLTShell::InitDeviceObjects()
{
HRESULT res;
mD3DActive = TRUE;
//! JCL
// if (res != S_OK)
// return res;
for (int i=0;i<MAX_JOYPADS;i++)
{
mJoyState[i] = new( MEMTYPE_UNKNOWN ) DIJOYSTATE2;
mOldJoyState[i] = new( MEMTYPE_UNKNOWN ) DIJOYSTATE2;
}
// Initialize device objects
DeviceObject* devob = mDeviceObjects;
while(devob)
{
devob->InitDeviceObjects();
devob=devob->mNext;
}
//##GC This is a bit naughty really...
CIMPOSTER::InvalidateImposters();
//!PD
CPARTICLETEXTURE::RecreateAllSurfaces();
res = InitDirectInput( m_hWnd );
if(res==S_FALSE) return S_FALSE;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: RestoreDeviceObjects()
// Desc: Restore device-memory objects and state after a device is created or
// resized.
//-----------------------------------------------------------------------------
HRESULT PCLTShell::RestoreDeviceObjects()
{
DeviceObject* devob = mDeviceObjects;
while(devob)
{
HRESULT result=devob->RestoreDeviceObjects();
if (result!=S_OK)
devob=devob;
devob=devob->mNext;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: InvalidateDeviceObjects()
// Desc: Called when the device-dependant objects are about to be lost.
//-----------------------------------------------------------------------------
HRESULT PCLTShell::InvalidateDeviceObjects()
{
DeviceObject* devob = mDeviceObjects;
while(devob)
{
devob->InvalidateDeviceObjects();
devob=devob->mNext;
}
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: DeleteDeviceObjects()
// Desc: Called when the app is exitting, or the device is being changed,
// this function deletes any device dependant objects.
//-----------------------------------------------------------------------------
HRESULT PCLTShell::DeleteDeviceObjects()
{
for (int i=0;i<MAX_JOYPADS;i++)
{
SAFE_DELETE(mJoyState[i]);
SAFE_DELETE(mOldJoyState[i]);
}
DeviceObject* devob = mDeviceObjects;
while(devob)
{
HRESULT hr = devob->DeleteDeviceObjects();
ASSERT(hr==S_OK);
devob=devob->mNext;
}
FreeDirectInput();
CPARTICLETEXTURE::FreeAllSurfaces();
mD3DActive = FALSE;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: FinalCleanup()
// Desc: Called before the app exits, this function gives the app the chance
// to cleanup after itself.
//-----------------------------------------------------------------------------
HRESULT PCLTShell::FinalCleanup()
{
// GAME.Shutdown();
mRunning=false;
return S_OK;
}
//-----------------------------------------------------------------------------
// Name: ConfirmDevice()
// Desc: Called during device intialization, this code checks the device
// for some minimum set of capabilities
//-----------------------------------------------------------------------------
HRESULT PCLTShell::ConfirmDevice( D3DCAPS8* pCaps, DWORD dwBehavior,
D3DFORMAT Format )
{
if (CVertexShader::VertexShadersEnabled)
{
// Ensure we have vertex shader support
/* int majorv=((pCaps->VertexShaderVersion >> 8) & 0xFF);
int minorv=(pCaps->VertexShaderVersion & 0xFF);
char buffer[256];
sprintf(buffer,"VShader v%d.%d\n",majorv,minorv);
OutputDebugString(buffer);*/
if ((dwBehavior & D3DCREATE_SOFTWARE_VERTEXPROCESSING) ||
(dwBehavior & D3DCREATE_MIXED_VERTEXPROCESSING))
{
// Assume we'll be OK with emulation - this is *bad*, but there
// doesn't seem to be another way
}
else
{
// Hardware VP
if( pCaps->VertexShaderVersion < D3DVS_VERSION(1,0) )
return E_FAIL;
}
}
// This is necessary to make the reference rasteriser work as it will
// default to using a pure device which disallows stuff we're doing
if (CLIPARAMS.mPureDevice)
{
if (!(dwBehavior & D3DCREATE_PUREDEVICE))
return E_FAIL;
}
else
{
if ((dwBehavior & D3DCREATE_PUREDEVICE))
return E_FAIL;
}
if ((!(pCaps->TextureCaps & D3DPTEXTURECAPS_ALPHAPALETTE)) &&
(!(pCaps->TextureCaps & D3DPTEXTURECAPS_ALPHA)))
return E_FAIL;
return S_OK;
}
//======================================================-==--=-- -- -
//
// stuff added for LT. shell
//
//======================================================-==--=-- -- -
BOOL PCLTShell::RemoveDeviceObject(DeviceObject* devob)
{
DeviceObject* tdos = mDeviceObjects;
DeviceObject* prevdo = 0;
while(tdos)
{
if(tdos==devob)
{
if(prevdo) prevdo->mNext = devob->mNext;
else mDeviceObjects = devob->mNext;
return TRUE;
}
prevdo = tdos;
tdos=tdos->mNext;
}
return FALSE;