-
Notifications
You must be signed in to change notification settings - Fork 271
/
Copy pathcdll_engine_int.cpp
2222 lines (1845 loc) · 62.2 KB
/
cdll_engine_int.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 Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// 4-23-98
// JOHN: implementation of interface between client-side DLL and game engine.
// The cdll shouldn't have to know anything about networking or file formats.
// This file is Win32-dependant
//
//=============================================================================//
#include "client_pch.h"
#include "getintersectingsurfaces_struct.h"
#include "gl_model_private.h"
#include "surfinfo.h"
#include "vstdlib/random.h"
#include "cdll_int.h"
#include "cmodel_engine.h"
#include "tmessage.h"
#include "console.h"
#include "snd_audio_source.h"
#include <vgui_controls/Controls.h>
#include <vgui/IInput.h>
#include "iengine.h"
#include "keys.h"
#include "con_nprint.h"
#include "tier0/vprof.h"
#include "sound.h"
#include "gl_rmain.h"
#include "proto_version.h"
#include "client_class.h"
#include "gl_rsurf.h"
#include "server.h"
#include "r_local.h"
#include "lightcache.h"
#include "gl_matsysiface.h"
#include "materialsystem/imaterialsystemhardwareconfig.h"
#include "materialsystem/materialsystem_config.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialvar.h"
#include "materialsystem/itexture.h"
#include "istudiorender.h"
#include "l_studio.h"
#include "voice.h"
#include "enginestats.h"
#include "testscriptmgr.h"
#include "r_areaportal.h"
#include "host.h"
#include "host_cmd.h"
#include "vox.h"
#include "iprediction.h"
#include "icliententitylist.h"
#include "eiface.h"
#include "ivguicenterprint.h"
#include "engine/IClientLeafSystem.h"
#include "dt_recv_eng.h"
#include <vgui/IVGui.h>
#include "sys_dll.h"
#include "vphysics_interface.h"
#include "materialsystem/imesh.h"
#include "IOcclusionSystem.h"
#include "filesystem_engine.h"
#include "tier0/icommandline.h"
#include "client_textmessage.h"
#include "host_saverestore.h"
#include "cl_main.h"
#include "demo.h"
#include "appframework/ilaunchermgr.h"
#include "vgui_baseui_interface.h"
#include "LocalNetworkBackdoor.h"
#include "lightcache.h"
#include "vgui/ISystem.h"
#include "ivideomode.h"
#include "icolorcorrectiontools.h"
#include "toolframework/itoolframework.h"
#include "engine/view_sharedv1.h"
#include "view.h"
#include "game/client/iclientrendertargets.h"
#include "tier2/tier2.h"
#include "matchmaking.h"
#include "inputsystem/iinputsystem.h"
#include "iachievementmgr.h"
#include "profile.h"
#include "cl_steamauth.h"
#include "download.h"
#include "replay/iclientreplay.h"
#include "demofile.h"
#include "igame.h"
#include "iclientvirtualreality.h"
#include "sourcevr/isourcevirtualreality.h"
#include "cl_check_process.h"
#include "enginethreads.h"
#if defined( REPLAY_ENABLED )
#include "replay_internal.h"
#include "replay/replaylib.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// forward declarations
//-----------------------------------------------------------------------------
IMaterial* BrushModel_GetLightingAndMaterial( const Vector &start,
const Vector &end, Vector &diffuseLightColor, Vector &baseColor );
const char *Key_NameForBinding( const char *pBinding );
void CL_GetBackgroundLevelName( char *pszBackgroundName, int bufSize, bool bMapName );
CreateInterfaceFn g_ClientFactory = NULL;
extern CGlobalVars g_ServerGlobalVariables;
//-----------------------------------------------------------------------------
// globals
//-----------------------------------------------------------------------------
CSysModule *g_ClientDLLModule = NULL; // also used by materialproxyfactory.cpp
bool g_bClientGameDLLGreaterThanV13;
void AddIntersectingLeafSurfaces( mleaf_t *pLeaf, GetIntersectingSurfaces_Struct *pStruct )
{
SurfaceHandle_t *pHandle = &host_state.worldbrush->marksurfaces[pLeaf->firstmarksurface];
for ( int iSurf=0; iSurf < pLeaf->nummarksurfaces; iSurf++ )
{
SurfaceHandle_t surfID = pHandle[iSurf];
ASSERT_SURF_VALID( surfID );
if ( MSurf_Flags(surfID) & SURFDRAW_SKY )
continue;
// Make sure we haven't already processed this one.
bool foundSurf = false;
for(int iTest=0; iTest < pStruct->m_nSetInfos; iTest++)
{
if(pStruct->m_pInfos[iTest].m_pEngineData == (void *)surfID)
{
foundSurf = true;
break;
}
}
if ( foundSurf )
continue;
// Make sure there's output room.
if(pStruct->m_nSetInfos >= pStruct->m_nMaxInfos)
return;
SurfInfo *pOut = &pStruct->m_pInfos[pStruct->m_nSetInfos];
pOut->m_nVerts = 0;
pOut->m_pEngineData = (void *)surfID;
// Build vertex list and bounding box.
Vector vMin( 1000000.0f, 1000000.0f, 1000000.0f);
Vector vMax(-1000000.0f, -1000000.0f, -1000000.0f);
for(int iVert=0; iVert < MSurf_VertCount( surfID ); iVert++)
{
int vertIndex = pStruct->m_pModel->brush.pShared->vertindices[MSurf_FirstVertIndex( surfID ) + iVert];
pOut->m_Verts[pOut->m_nVerts] = pStruct->m_pModel->brush.pShared->vertexes[vertIndex].position;
vMin = vMin.Min(pOut->m_Verts[pOut->m_nVerts]);
vMax = vMax.Max(pOut->m_Verts[pOut->m_nVerts]);
++pOut->m_nVerts;
if(pOut->m_nVerts >= MAX_SURFINFO_VERTS)
break;
}
// See if the sphere intersects the box.
int iDim=0;
for(; iDim < 3; iDim++)
{
if(((*pStruct->m_pCenter)[iDim]+pStruct->m_Radius) < vMin[iDim] ||
((*pStruct->m_pCenter)[iDim]-pStruct->m_Radius) > vMax[iDim])
{
break;
}
}
if(iDim == 3)
{
// (Couldn't reject the sphere in the loop above).
pOut->m_Plane = MSurf_GetForwardFacingPlane( surfID );
++pStruct->m_nSetInfos;
}
}
}
void GetIntersectingSurfaces_R(
GetIntersectingSurfaces_Struct *pStruct,
mnode_t *pNode
)
{
if(pStruct->m_nSetInfos >= pStruct->m_nMaxInfos)
return;
// Ok, this is a leaf. Check its surfaces.
if(pNode->contents >= 0)
{
mleaf_t *pLeaf = (mleaf_t*)pNode;
if(pStruct->m_bOnlyVisible && pStruct->m_pCenterPVS)
{
if(pLeaf->cluster < 0)
return;
if(!(pStruct->m_pCenterPVS[pLeaf->cluster>>3] & (1 << (pLeaf->cluster&7))))
return;
}
// First, add tris from displacements.
for ( int i = 0; i < pLeaf->dispCount; i++ )
{
IDispInfo *pDispInfo = MLeaf_Disaplcement( pLeaf, i );
pDispInfo->GetIntersectingSurfaces( pStruct );
}
// Next, add brush tris.
AddIntersectingLeafSurfaces( pLeaf, pStruct );
return;
}
// Recurse.
float dot;
cplane_t *plane = pNode->plane;
if ( plane->type < 3 )
{
dot = (*pStruct->m_pCenter)[plane->type] - plane->dist;
}
else
{
dot = pStruct->m_pCenter->Dot(plane->normal) - plane->dist;
}
// Recurse into child nodes.
if(dot > -pStruct->m_Radius)
GetIntersectingSurfaces_R(pStruct, pNode->children[SIDE_FRONT]);
if(dot < pStruct->m_Radius)
GetIntersectingSurfaces_R(pStruct, pNode->children[SIDE_BACK]);
}
//-----------------------------------------------------------------------------
// slow routine to draw a physics model
// NOTE: very slow code!!! just for debugging!
//-----------------------------------------------------------------------------
void DebugDrawPhysCollide( const CPhysCollide *pCollide, IMaterial *pMaterial, matrix3x4_t& transform, const color32 &color, bool drawAxes )
{
if ( !pMaterial )
{
pMaterial = materials->FindMaterial("shadertest/wireframevertexcolor", TEXTURE_GROUP_OTHER);
}
CMatRenderContextPtr pRenderContext( materials );
Vector *outVerts;
int vertCount = physcollision->CreateDebugMesh( pCollide, &outVerts );
if ( vertCount )
{
IMesh *pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, pMaterial );
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_TRIANGLES, vertCount/3 );
for ( int j = 0; j < vertCount; j++ )
{
Vector out;
VectorTransform( outVerts[j].Base(), transform, out.Base() );
meshBuilder.Position3fv( out.Base() );
meshBuilder.Color4ub( color.r, color.g, color.b, color.a );
meshBuilder.TexCoord2f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
}
meshBuilder.End();
pMesh->Draw();
}
physcollision->DestroyDebugMesh( vertCount, outVerts );
// draw the axes
if ( drawAxes )
{
Vector xaxis(10,0,0), yaxis(0,10,0), zaxis(0,0,10);
Vector center;
Vector out;
MatrixGetColumn( transform, 3, center );
IMesh *pMesh = pRenderContext->GetDynamicMesh( true, NULL, NULL, pMaterial );
CMeshBuilder meshBuilder;
meshBuilder.Begin( pMesh, MATERIAL_LINES, 3 );
// X
meshBuilder.Position3fv( center.Base() );
meshBuilder.Color4ub( 255, 0, 0, 255 );
meshBuilder.TexCoord2f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
VectorTransform( xaxis.Base(), transform, out.Base() );
meshBuilder.Position3fv( out.Base() );
meshBuilder.Color4ub( 255, 0, 0, 255 );
meshBuilder.TexCoord2f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
// Y
meshBuilder.Position3fv( center.Base() );
meshBuilder.Color4ub( 0, 255, 0, 255 );
meshBuilder.TexCoord2f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
VectorTransform( yaxis.Base(), transform, out.Base() );
meshBuilder.Position3fv( out.Base() );
meshBuilder.Color4ub( 0, 255, 0, 255 );
meshBuilder.TexCoord2f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
// Z
meshBuilder.Position3fv( center.Base() );
meshBuilder.Color4ub( 0, 0, 255, 255 );
meshBuilder.TexCoord2f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
VectorTransform( zaxis.Base(), transform, out.Base() );
meshBuilder.Position3fv( out.Base() );
meshBuilder.Color4ub( 0, 0, 255, 255 );
meshBuilder.TexCoord2f( 0, 0, 0 );
meshBuilder.AdvanceVertex();
meshBuilder.End();
pMesh->Draw();
}
}
//-----------------------------------------------------------------------------
//
// implementation of IVEngineHud
//
//-----------------------------------------------------------------------------
// UNDONE: Move this to hud export code, subsume previous functions
class CEngineClient : public IVEngineClient
{
public:
CEngineClient();
int GetIntersectingSurfaces(
const model_t *model,
const Vector &vCenter,
const float radius,
const bool bOnlyVisible,
SurfInfo *pInfos,
const int nMaxInfos);
Vector GetLightForPoint(const Vector &pos, bool bClamp);
Vector GetLightForPointFast(const Vector &pos, bool bClamp);
const char *ParseFile( const char *data, char *token, int maxlen );
virtual bool CopyLocalFile( const char *source, const char *destination );
void GetScreenSize( int& w, int &h );
void ServerCmd( const char *szCmdString, bool bReliable );
void ClientCmd( const char *szCmdString );
void ClientCmd_Unrestricted( const char *szCmdString );
void SetRestrictServerCommands( bool bRestrict );
void SetRestrictClientCommands( bool bRestrict );
bool GetPlayerInfo( int ent_num, player_info_t *pinfo );
client_textmessage_t *TextMessageGet( const char *pName );
bool Con_IsVisible( void );
int GetLocalPlayer( void );
float GetLastTimeStamp( void );
const model_t *LoadModel( const char *pName, bool bProp );
void UnloadModel( const model_t *model, bool bProp );
CSentence *GetSentence( CAudioSource *pAudioSource );
float GetSentenceLength( CAudioSource *pAudioSource );
bool IsStreaming( CAudioSource *pAudioSource ) const;
void AddPhonemeFile( const char *pszPhonemeFile );
// FIXME, move entirely to client .dll
void GetViewAngles( QAngle& va );
void SetViewAngles( QAngle& va );
int GetMaxClients( void );
void Key_Event( ButtonCode_t key, int down );
const char *Key_LookupBinding( const char *pBinding );
const char *Key_LookupBindingExact( const char *pBinding );
const char *Key_BindingForKey( ButtonCode_t code );
void StartKeyTrapMode( void );
bool CheckDoneKeyTrapping( ButtonCode_t &key );
bool IsInGame( void );
bool IsConnected( void );
bool IsDrawingLoadingImage( void );
void Con_NPrintf( int pos, const char *fmt, ... );
void Con_NXPrintf( const struct con_nprint_s *info, const char *fmt, ... );
IMaterial *TraceLineMaterialAndLighting( const Vector &start, const Vector &end,
Vector &diffuseLightColor, Vector &baseColor );
int IsBoxVisible( const Vector& mins, const Vector& maxs );
int IsBoxInViewCluster( const Vector& mins, const Vector& maxs );
float Time();
void Sound_ExtraUpdate( void );
bool CullBox ( const Vector& mins, const Vector& maxs );
const char *GetGameDirectory( void );
const VMatrix& WorldToScreenMatrix();
const VMatrix& WorldToViewMatrix();
// Loads a game lump off disk
int GameLumpVersion( int lumpId ) const;
int GameLumpSize( int lumpId ) const;
bool LoadGameLump( int lumpId, void* pBuffer, int size );
// Returns the number of leaves in the level
int LevelLeafCount() const;
virtual ISpatialQuery* GetBSPTreeQuery();
// Convert texlight to gamma...
virtual void LinearToGamma( float* linear, float* gamma );
// Get the lightstyle value
virtual float LightStyleValue( int style );
virtual void DrawPortals();
// Computes light due to dynamic lighting at a point
// If the normal isn't specified, then it'll return the maximum lighting
virtual void ComputeDynamicLighting( Vector const& pt, Vector const* pNormal, Vector& color );
// Computes light due to dynamic lighting at a point
// If the normal isn't specified, then it'll return the maximum lighting
// If pBoxColors is specified (it's an array of 6), then it'll copy the light contribution at each box side.
virtual void ComputeLighting( const Vector& pt, const Vector* pNormal, bool bClamp, Vector& color, Vector *pBoxColors );
// Returns the color of the ambient light
virtual void GetAmbientLightColor( Vector& color );
// Returns the dx support level
virtual int GetDXSupportLevel();
virtual bool SupportsHDR();
virtual void Mat_Stub( IMaterialSystem *pMatSys );
// menu display
virtual void GetChapterName( char *pchBuff, int iMaxLength );
virtual char const *GetLevelName( void );
virtual int GetLevelVersion( void );
virtual bool IsLevelMainMenuBackground( void );
virtual void GetMainMenuBackgroundName( char *dest, int destlen );
// Occlusion system control
virtual void SetOcclusionParameters( const OcclusionParams_t ¶ms );
//-----------------------------------------------------------------------------
// Purpose: Takes a trackerID and returns which player slot that user is in
// returns 0 if no player found with that ID
//-----------------------------------------------------------------------------
virtual int GetPlayerForUserID(int userID);
#if !defined( NO_VOICE )
virtual struct IVoiceTweak_s *GetVoiceTweakAPI( void );
#endif
virtual void EngineStats_BeginFrame( void );
virtual void EngineStats_EndFrame( void );
virtual void FireEvents();
virtual void CheckPoint( const char *pName );
virtual int GetLeavesArea( int *pLeaves, int nLeaves );
virtual bool DoesBoxTouchAreaFrustum( const Vector &mins, const Vector &maxs, int iArea );
// Sets the hearing origin
virtual void SetAudioState( const AudioState_t &audioState );
//-----------------------------------------------------------------------------
//
// Sentence API
//
//-----------------------------------------------------------------------------
virtual int SentenceGroupPick( int groupIndex, char *name, int nameLen );
virtual int SentenceGroupPickSequential( int groupIndex, char *name, int nameLen, int sentenceIndex, int reset );
virtual int SentenceIndexFromName( const char *pSentenceName );
virtual const char *SentenceNameFromIndex( int sentenceIndex );
virtual int SentenceGroupIndexFromName( const char *pGroupName );
virtual const char *SentenceGroupNameFromIndex( int groupIndex );
virtual float SentenceLength( int sentenceIndex );
virtual void DebugDrawPhysCollide( const CPhysCollide *pCollide, IMaterial *pMaterial, matrix3x4_t& transform, const color32 &color );
// Activates/deactivates an occluder...
virtual void ActivateOccluder( int nOccluderIndex, bool bActive );
virtual bool IsOccluded( const Vector &vecAbsMins, const Vector &vecAbsMaxs );
virtual void *SaveAllocMemory( size_t num, size_t size );
virtual void SaveFreeMemory( void *pSaveMem );
virtual INetChannelInfo *GetNetChannelInfo( void );
virtual bool IsPlayingDemo( void );
virtual bool IsRecordingDemo( void );
virtual bool IsPlayingTimeDemo( void );
virtual int GetDemoRecordingTick( void );
virtual int GetDemoPlaybackTick( void );
virtual int GetDemoPlaybackStartTick( void );
virtual float GetDemoPlaybackTimeScale( void );
virtual int GetDemoPlaybackTotalTicks( void );
virtual bool IsPaused( void );
virtual bool IsTakingScreenshot( void );
virtual bool IsHLTV( void );
virtual void GetVideoModes( int &nCount, vmode_s *&pModes );
virtual void GetUILanguage( char *dest, int destlen );
// Can skybox be seen from a particular point?
virtual SkyboxVisibility_t IsSkyboxVisibleFromPoint( const Vector &vecPoint );
virtual const char* GetMapEntitiesString();
virtual bool IsInEditMode( void );
virtual bool IsInCommentaryMode( void );
virtual float GetScreenAspectRatio();
virtual unsigned int GetEngineBuildNumber() { return PROTOCOL_VERSION; }
virtual const char * GetProductVersionString() { return GetSteamInfIDVersionInfo().szVersionString; }
virtual void GrabPreColorCorrectedFrame( int x, int y, int width, int height );
virtual bool IsHammerRunning( ) const;
// Stuffs the cmd into the buffer & executes it immediately (vs ClientCmd() which executes it next frame)
virtual void ExecuteClientCmd( const char *szCmdString );
virtual bool MapHasHDRLighting( void) ;
virtual int GetAppID();
virtual void SetOverlayBindProxy( int iOverlayID, void *pBindProxy );
virtual bool CopyFrameBufferToMaterial( const char *pMaterialName );
// Matchmaking
void ChangeTeam( const char *pTeamName );
virtual void ReadConfiguration( const bool readDefault = false );
virtual void SetAchievementMgr( IAchievementMgr *pAchievementMgr );
virtual IAchievementMgr *GetAchievementMgr();
virtual bool MapLoadFailed( void );
virtual void SetMapLoadFailed( bool bState );
virtual bool IsLowViolence();
virtual const char *GetMostRecentSaveGame( void );
virtual void SetMostRecentSaveGame( const char *lpszFilename );
virtual void StartXboxExitingProcess();
virtual bool IsSaveInProgress();
virtual uint OnStorageDeviceAttached( void );
virtual void OnStorageDeviceDetached( void );
virtual void ResetDemoInterpolation( void );
virtual bool REMOVED_SteamRefreshLogin( const char *password, bool isSecure ) { return false; }
virtual bool REMOVED_SteamProcessCall( bool & finished ) { return false; }
virtual ISPSharedMemory *GetSinglePlayerSharedMemorySpace( const char *handle, int ent_num = MAX_EDICTS );
virtual void SetGamestatsData( CGamestatsData *pGamestatsData );
virtual CGamestatsData *GetGamestatsData();
#if defined( USE_SDL )
virtual void GetMouseDelta( int &x, int &y, bool bIgnoreNextMouseDelta );
#endif
virtual void ServerCmdKeyValues( KeyValues *pKeyValues );
virtual bool IsSkippingPlayback( void );
virtual bool IsLoadingDemo( void );
virtual bool IsPlayingDemoALocallyRecordedDemo();
virtual uint GetProtocolVersion( void );
virtual bool IsWindowedMode( void );
virtual void FlashWindow();
virtual int GetClientVersion() const; // engines build
virtual bool IsActiveApp();
virtual void DisconnectInternal();
virtual int GetInstancesRunningCount( );
virtual float GetPausedExpireTime( void ) OVERRIDE;
virtual bool StartDemoRecording( const char *pszFilename, const char *pszFolder = NULL );
virtual void StopDemoRecording( void );
virtual void TakeScreenshot( const char *pszFilename, const char *pszFolder = NULL );
};
//-----------------------------------------------------------------------------
// Singleton
//-----------------------------------------------------------------------------
static CEngineClient s_VEngineClient;
IVEngineClient *engineClient = &s_VEngineClient;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CEngineClient, IVEngineClient, VENGINE_CLIENT_INTERFACE_VERSION, s_VEngineClient );
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CEngineClient, IVEngineClient013, VENGINE_CLIENT_INTERFACE_VERSION_13, s_VEngineClient );
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CEngineClient::CEngineClient()
{
}
int CEngineClient::GetIntersectingSurfaces(
const model_t *model,
const Vector &vCenter,
const float radius,
const bool bOnlyVisible,
SurfInfo *pInfos,
const int nMaxInfos)
{
if ( !model )
return 0;
byte pvs[MAX_MAP_LEAFS/8];
GetIntersectingSurfaces_Struct theStruct;
theStruct.m_pModel = ( model_t * )model;
theStruct.m_pCenter = &vCenter;
theStruct.m_pCenterPVS = CM_Vis( pvs, sizeof(pvs), CM_LeafCluster( CM_PointLeafnum( vCenter ) ), DVIS_PVS );
theStruct.m_Radius = radius;
theStruct.m_bOnlyVisible = bOnlyVisible;
theStruct.m_pInfos = pInfos;
theStruct.m_nMaxInfos = nMaxInfos;
theStruct.m_nSetInfos = 0;
// Go down the BSP.
GetIntersectingSurfaces_R(
&theStruct,
&model->brush.pShared->nodes[ model->brush.firstnode ] );
return theStruct.m_nSetInfos;
}
Vector CEngineClient::GetLightForPoint(const Vector &pos, bool bClamp)
{
Vector vRet;
ComputeLighting( pos, NULL, bClamp, vRet, NULL );
return vRet;
}
Vector CEngineClient::GetLightForPointFast(const Vector &pos, bool bClamp)
{
Vector vRet;
int leafIndex = CM_PointLeafnum(pos);
vRet.Init();
Vector cube[6];
Mod_LeafAmbientColorAtPos( cube, pos, leafIndex );
for ( int i = 0; i < 6; i++ )
{
vRet.x = fpmax(vRet.x, cube[i].x );
vRet.y = fpmax(vRet.y, cube[i].y );
vRet.z = fpmax(vRet.z, cube[i].z );
}
if ( bClamp )
{
if ( vRet.x > 1.0f )
vRet.x = 1.0f;
if ( vRet.y > 1.0f )
vRet.y = 1.0f;
if ( vRet.z > 1.0f )
vRet.z = 1.0f;
}
return vRet;
}
const char *CEngineClient::ParseFile( const char *data, char *token, int maxlen )
{
return ::COM_ParseFile( data, token, maxlen );
}
bool CEngineClient::CopyLocalFile( const char *source, const char *destination )
{
return ::COM_CopyFile( source, destination );
}
void CEngineClient::GetScreenSize( int& w, int &h )
{
CMatRenderContextPtr pRenderContext( materials );
pRenderContext->GetWindowSize( w, h );
}
void CEngineClient::ServerCmd( const char *szCmdString, bool bReliable )
{
// info handling
char buf[255];
Q_snprintf( buf, sizeof( buf ), "cmd %s", szCmdString );
CCommand args;
args.Tokenize( buf );
Cmd_ForwardToServer( args, bReliable );
}
void CEngineClient::ClientCmd( const char *szCmdString )
{
// Check that we can add the two execution markers
if ( cl.m_bRestrictClientCommands && !Cbuf_HasRoomForExecutionMarkers( 2 ) )
{
AssertMsg( false, "CEngineClient::ClientCmd called but there is no room for the execution markers. Ignoring command." );
return;
}
// Only let them run commands marked with FCVAR_CLIENTCMD_CAN_EXECUTE.
if ( cl.m_bRestrictClientCommands )
Cbuf_AddTextWithMarkers( eCmdExecutionMarker_Enable_FCVAR_CLIENTCMD_CAN_EXECUTE, szCmdString, eCmdExecutionMarker_Disable_FCVAR_CLIENTCMD_CAN_EXECUTE );
else
Cbuf_AddText( szCmdString );
}
void CEngineClient::ClientCmd_Unrestricted( const char *szCmdString )
{
Cbuf_AddText( szCmdString );
}
void CEngineClient::SetRestrictServerCommands( bool bRestrict )
{
cl.m_bRestrictServerCommands = bRestrict;
}
void CEngineClient::SetRestrictClientCommands( bool bRestrict )
{
cl.m_bRestrictClientCommands = bRestrict;
}
void CEngineClient::ExecuteClientCmd( const char *szCmdString )
{
Cbuf_AddText( szCmdString );
Cbuf_Execute();
}
bool CEngineClient::GetPlayerInfo( int ent_num, player_info_t *pinfo )
{
ent_num--; // player list if offset by 1 from ents
if ( ent_num >= cl.m_nMaxClients || ent_num < 0 )
{
Q_memset( pinfo, 0, sizeof( player_info_t ) );
return false;
}
Assert( cl.m_pUserInfoTable );
if ( !cl.m_pUserInfoTable )
{
Q_memset( pinfo, 0, sizeof( player_info_t ) );
return false;
}
Assert( ent_num < cl.m_pUserInfoTable->GetNumStrings() );
if ( ent_num >= cl.m_pUserInfoTable->GetNumStrings() )
{
Q_memset( pinfo, 0, sizeof( player_info_t ) );
return false;
}
int cubPlayerInfo;
player_info_t *pi = (player_info_t*) cl.m_pUserInfoTable->GetStringUserData( ent_num, &cubPlayerInfo );
if ( !pi || cubPlayerInfo < sizeof( player_info_t ) )
{
Q_memset( pinfo, 0, sizeof( player_info_t ) );
return false;
}
Q_memcpy( pinfo, pi, sizeof( player_info_t ) );
// Fixup from network order (little endian)
CByteswap byteswap;
byteswap.SetTargetBigEndian( false );
byteswap.SwapFieldsToTargetEndian( pinfo );
return true;
}
client_textmessage_t *CEngineClient::TextMessageGet( const char *pName )
{
return ::TextMessageGet( pName );
}
bool CEngineClient::Con_IsVisible( void )
{
return ::Con_IsVisible();
}
int CEngineClient::GetLocalPlayer( void )
{
return cl.m_nPlayerSlot + 1;
}
float CEngineClient::GetLastTimeStamp( void )
{
return cl.m_flLastServerTickTime;
}
bool CEngineClient::MapHasHDRLighting( void)
{
return modelloader->LastLoadedMapHasHDRLighting();
}
const model_t *CEngineClient::LoadModel( const char *pName, bool bProp )
{
return modelloader->GetModelForName( pName, bProp ? IModelLoader::FMODELLOADER_DETAILPROP : IModelLoader::FMODELLOADER_CLIENTDLL );
}
CSentence *CEngineClient::GetSentence( CAudioSource *pAudioSource )
{
if (pAudioSource)
{
return pAudioSource->GetSentence();
}
return NULL;
}
void AddPhonemesFromFile( const char *pszFileName );
void CEngineClient::AddPhonemeFile( const char *pszPhonemeFile )
{
AddPhonemesFromFile( pszPhonemeFile );
}
float CEngineClient::GetSentenceLength( CAudioSource *pAudioSource )
{
if (pAudioSource && pAudioSource->SampleRate() > 0 )
{
float length = (float)pAudioSource->SampleCount() / (float)pAudioSource->SampleRate();
return length;
}
return 0.0f;
}
bool CEngineClient::IsStreaming( CAudioSource *pAudioSource ) const
{
if ( pAudioSource )
{
return pAudioSource->IsStreaming();
}
return false;
}
// FIXME, move entirely to client .dll
void CEngineClient::GetViewAngles( QAngle& va )
{
VectorCopy( cl.viewangles, va );
}
void CEngineClient::SetViewAngles( QAngle& va )
{
cl.viewangles.x = AngleNormalize( va.x );
cl.viewangles.y = AngleNormalize( va.y );
cl.viewangles.z = AngleNormalize( va.z );
Assert( !IS_NAN(cl.viewangles.x ) );
Assert( !IS_NAN(cl.viewangles.y ) );
Assert( !IS_NAN(cl.viewangles.z ) );
}
int CEngineClient::GetMaxClients( void )
{
return cl.m_nMaxClients;
}
void CEngineClient::SetMapLoadFailed( bool bState )
{
g_ServerGlobalVariables.bMapLoadFailed = bState;
}
bool CEngineClient::MapLoadFailed( void )
{
return g_ServerGlobalVariables.bMapLoadFailed;
}
void CEngineClient::ReadConfiguration( const bool readDefault /*= false*/ )
{
Host_ReadConfiguration();
}
const char *CEngineClient::Key_LookupBinding( const char *pBinding )
{
return ::Key_NameForBinding( pBinding );
}
const char *CEngineClient::Key_LookupBindingExact( const char *pBinding )
{
return ::Key_NameForBindingExact( pBinding );
}
const char *CEngineClient::Key_BindingForKey( ButtonCode_t code )
{
return ::Key_BindingForKey( code );
}
void CEngineClient::StartKeyTrapMode( void )
{
Key_StartTrapMode();
}
bool CEngineClient::CheckDoneKeyTrapping( ButtonCode_t &code )
{
return Key_CheckDoneTrapping( code );
}
bool CEngineClient::IsInGame( void )
{
return cl.IsActive();
}
bool CEngineClient::IsConnected( void )
{
return cl.IsConnected();
}
bool CEngineClient::IsDrawingLoadingImage( void )
{
return scr_drawloading;
}
void CEngineClient::Con_NPrintf( int pos, const char *fmt, ... )
{
va_list argptr;
char text[4096];
va_start (argptr, fmt);
Q_vsnprintf(text, sizeof( text ), fmt, argptr);
va_end (argptr);
::Con_NPrintf( pos, "%s", text );
}
void CEngineClient::Con_NXPrintf( const struct con_nprint_s *info, const char *fmt, ... )
{
va_list argptr;
char text[4096];
va_start (argptr, fmt);
Q_vsnprintf(text, sizeof( text ), fmt, argptr);
va_end (argptr);
::Con_NXPrintf( info, "%s", text );
}
IMaterial *CEngineClient::TraceLineMaterialAndLighting( const Vector &start, const Vector &end,
Vector &diffuseLightColor, Vector &baseColor )
{
return BrushModel_GetLightingAndMaterial( start, end, diffuseLightColor, baseColor );
}
int CEngineClient::IsBoxVisible( const Vector& mins, const Vector& maxs )
{
return CM_BoxVisible( mins, maxs, Map_VisCurrent(), CM_ClusterPVSSize() );
}
int CEngineClient::IsBoxInViewCluster( const Vector& mins, const Vector& maxs )
{
// See comments in Map_VisCurrentCluster for why we might get a negative number.
int curCluster = Map_VisCurrentCluster();
if ( curCluster < 0 )
return false;
byte pvs[MAX_MAP_LEAFS/8];
const byte *ppvs = CM_Vis( pvs, sizeof(pvs), curCluster, DVIS_PVS );
return CM_BoxVisible(mins, maxs, ppvs, sizeof(pvs) );
}
float CEngineClient::Time()
{
return Sys_FloatTime();
}
void CEngineClient::Sound_ExtraUpdate( void )
{
// On xbox this is not necessary except for long pauses, so unhook this one
if ( IsX360() )
return;
VPROF_BUDGET( "CEngineClient::Sound_ExtraUpdate()", VPROF_BUDGETGROUP_OTHER_SOUND );
S_ExtraUpdate();
}
bool CEngineClient::CullBox ( const Vector& mins, const Vector& maxs )
{
return R_CullBoxSkipNear( mins, maxs, g_Frustum );
}
const char *CEngineClient::GetGameDirectory( void )
{
return com_gamedir;
}
const VMatrix& CEngineClient::WorldToScreenMatrix()
{
// FIXME: this is only valid if we're currently rendering. If not, it should use the player, or it really should pass one in.
return g_EngineRenderer->WorldToScreenMatrix();
}
const VMatrix& CEngineClient::WorldToViewMatrix()
{
// FIXME: this is only valid if we're currently rendering. If not, it should use the player, or it really should pass one in.
return g_EngineRenderer->ViewMatrix();
}
// Loads a game lump off disk
int CEngineClient::GameLumpVersion( int lumpId ) const
{
return Mod_GameLumpVersion( lumpId );
}
int CEngineClient::GameLumpSize( int lumpId ) const
{
return Mod_GameLumpSize( lumpId );
}
bool CEngineClient::LoadGameLump( int lumpId, void* pBuffer, int size )
{
return Mod_LoadGameLump( lumpId, pBuffer, size );
}