/
cdll_engine_int.cpp
3059 lines (2536 loc) · 87.7 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 (c) 1996-2005, 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 "client_class.h"
#include "gl_rsurf.h"
#include "server.h"
#include "r_local.h"
#include "lightcache.h"
#include "gl_matsysiface.h"
#include "inputsystem/iinputstacksystem.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 "vox.h"
#include "iprediction.h"
#include "icliententitylist.h"
#include "eiface.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 "vgui_baseui_interface.h"
#include "LocalNetworkBackdoor.h"
#include "lightcache.h"
#include "vgui/ISystem.h"
#include "Steam.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 "inputsystem/iinputsystem.h"
#include "iachievementmgr.h"
#include "profile.h"
#include "singleplayersharedmemory.h"
#include "cl_demo.h"
#include "MapReslistGenerator.h"
#include "iclientalphaproperty.h"
#include "cl_steamauth.h"
#include "enginebugreporter.h"
#include "world.h"
#include "staticpropmgr.h"
#include "sv_uploadgamestats.h"
#include "host_cmd.h"
#include "ixboxsystem.h"
#include "matchmaking/imatchframework.h"
#include "appframework/ilaunchermgr.h"
#include "paint.h"
#include "igame.h"
#include "sys_mainwind.h"
#include "dbginput.h"
#include "cl_broadcast.h"
#if defined( _PS3 )
#include "engine_helper_ps3.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, int userId );
void CL_GetBackgroundLevelName( char *pszBackgroundName, int bufSize, bool bMapName );
CreateInterfaceFn g_ClientFactory = NULL;
extern CGlobalVars g_ServerGlobalVariables;
extern ConVar host_timescale;
//-----------------------------------------------------------------------------
// 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, const matrix3x4_t& transform, const color32 &color, bool drawAxes )
{
if ( !pMaterial )
{
pMaterial = materials->FindMaterial("debug/debugwireframevertexcolor", 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();
~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, bool fromConsoleOrKeybind = false );
void ClientCmd_Unrestricted( const char *szCmdString, bool fromConsoleOrKeybind, int nUserSlot, bool bCheckValidSlot = true );
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 );
virtual int GetLastAcknowledgedCommand( void );
virtual int GetServerTick( 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;
// 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_BindingForKey( ButtonCode_t code );
void Key_SetBinding( ButtonCode_t code, const char *pBinding );
void StartKeyTrapMode( void );
bool CheckDoneKeyTrapping( ButtonCode_t &key );
bool IsInGame( void );
bool IsConnected( void );
bool IsDrawingLoadingImage( void );
void HideLoadingPlaque( 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 );
void Sound_ExtraUpdate( void );
#if defined(_PS3)
void Sound_ServerUpdateSoundsPS3( void );
#endif
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 char const *GetLevelNameShort( void );
virtual char const *GetMapGroupName( 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 );
virtual void SetVoiceCasterID( uint32 casterID );
#endif
virtual void EngineStats_BeginFrame( void );
virtual void EngineStats_EndFrame( void );
virtual void FireEvents();
virtual void ClearEvents();
virtual void CheckPoint( const char *pName );
virtual int GetLeavesArea( unsigned short *pLeaves, int nLeaves );
virtual bool DoesBoxTouchAreaFrustum( const Vector &mins, const Vector &maxs, int iArea );
virtual int GetFrustumList( Frustum_t **pList, int listMax );
virtual bool ShouldUseAreaFrustum( int area );
// 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, const matrix3x4_t& transform, const color32 &color );
// Activates/deactivates an occluder...
virtual void ActivateOccluder( int nOccluderIndex, bool bActive );
virtual bool IsOccluded( int occlusionViewId, const Vector &vecAbsMins, const Vector &vecAbsMaxs );
virtual int GetOcclusionViewId() const;
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 CDemoPlaybackParameters_t const * GetDemoPlaybackParameters() OVERRIDE;
virtual bool IsDemoSkipping( void ) OVERRIDE;
virtual int GetConnectionDataProtocol() const OVERRIDE;
virtual bool EngineGotvSyncPacket( const CEngineGotvSyncPacket *pPkt ) OVERRIDE;
virtual void SetDemoImportantEventData( const KeyValues *pData ) OVERRIDE;
virtual bool IsPaused( void );
virtual float GetTimescale( void ) const;
virtual bool IsTakingScreenshot( void );
virtual void WriteScreenshot( const char *pFilename );
virtual bool IsHLTV( void );
virtual bool IsReplay( void );
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( int viewportWidth, int viewportHeight );
virtual unsigned int GetEngineBuildNumber() { return GetHostVersion(); }
virtual const char * GetProductVersionString() { return Sys_GetVersionString(); }
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 bool MapHasLightMapAlphaData(void);
virtual int GetAppID();
virtual void SetOverlayBindProxy( int iOverlayID, void *pBindProxy );
virtual bool CopyFrameBufferToMaterial( const char *pMaterialName );
// Matchmaking
virtual void ReadConfiguration( const int iController, const bool readDefault );
virtual void SetAchievementMgr( IAchievementMgr *pAchievementMgr );
virtual IAchievementMgr *GetAchievementMgr();
virtual bool MapLoadFailed( void );
virtual void SetMapLoadFailed( bool bState );
virtual bool IsLowViolence();
virtual const char *GetMostRecentSaveGame( bool bEnsureExists );
virtual void SetMostRecentSaveGame( const char *lpszFilename );
virtual void StartXboxExitingProcess();
virtual bool IsSaveInProgress();
virtual bool IsAutoSaveDangerousInProgress();
virtual bool IsAutoSaveInProgress();
virtual const char * GetSaveDirName(); // get a pointer to the path where saves should go (with a trailing slash already added)
virtual uint OnStorageDeviceAttached( int iController );
virtual void OnStorageDeviceDetached( int iController );
virtual void ResetDemoInterpolation( void );
virtual bool REMOVED_SteamRefreshLogin( const char *password, bool isSecure ) { return false; }
virtual bool REMOVED_SteamProcessCall( bool & finished ) { return false; }
// For non-split screen games this will always be zero
virtual int GetActiveSplitScreenPlayerSlot();
virtual int SetActiveSplitScreenPlayerSlot( int slot );
virtual bool SetLocalPlayerIsResolvable( char const *pchContext, int nLine, bool bResolvable );
virtual bool IsLocalPlayerResolvable();
virtual int GetSplitScreenPlayer( int nSlot );
virtual bool IsSplitScreenActive();
virtual bool IsValidSplitScreenSlot( int nSlot );
virtual int FirstValidSplitScreenSlot(); // -1 == invalid
virtual int NextValidSplitScreenSlot( int nPreviousSlot ); // -1 == invalid
virtual ISPSharedMemory * GetSinglePlayerSharedMemorySpace( const char *handle, int ent_num = MAX_EDICTS );
// Computes an ambient cube that includes ALL dynamic lights
virtual void ComputeLightingCube( const Vector& pt, bool bClamp, Vector *pBoxColors );
//All callbacks have to be registered before demo recording begins. TODO: Macro'ize a way to do it at startup
virtual void RegisterDemoCustomDataCallback( string_t szCallbackSaveID, pfnDemoCustomDataCallback pCallback );
virtual void RecordDemoCustomData( pfnDemoCustomDataCallback pCallback, const void *pData, size_t iDataLength );
virtual void SetLeafFlag( int nLeafIndex, int nFlagBits );
// you must call this once done modifying flags. Not super fast.
virtual void RecalculateBSPLeafFlags( void );
virtual bool DSPGetCurrentDASRoomNew(void);
virtual bool DSPGetCurrentDASRoomChanged(void);
virtual bool DSPGetCurrentDASRoomSkyAbove(void);
virtual float DSPGetCurrentDASRoomSkyPercent(void);
virtual void SetMixGroupOfCurrentMixer( const char *szgroupname, const char *szparam, float val, int setMixerType );
virtual int GetMixLayerIndex( const char *szmixlayername );
virtual void SetMixLayerLevel(int index, float level );
virtual int GetMixGroupIndex( const char *pMixGroupName );
virtual void SetMixLayerTriggerFactor( int nMixLayerIndex, int nMixGroupIndex, float flFactor );
virtual void SetMixLayerTriggerFactor( const char *pMixLayerIndex, const char *pMixGroupIndex, float flFactor );
virtual bool IsCreatingReslist();
virtual bool IsCreatingXboxReslist();
virtual void SetTimescale( float flTimescale );
virtual void SetGamestatsData( CGamestatsData *pGamestatsData );
virtual CGamestatsData *GetGamestatsData();
virtual const char *Key_LookupBindingEx( const char *pBinding, int iUserId = -1, int iStartCount = 0, BindingLookupOption_t nFlags = BINDINGLOOKUP_ALL );
virtual int Key_CodeForBinding( const char *pBinding, int iUserId = -1, int iStartCount = 0, BindingLookupOption_t nFlags = BINDINGLOOKUP_ALL );
virtual void UpdateDAndELights( void );
// Methods to get bug count for internal dev work stat tracking.
// Will get the bug count and clear it every map transition
virtual int GetBugSubmissionCount() const;
virtual void ClearBugSubmissionCount();
virtual bool DoesLevelContainWater() const;
virtual float GetServerSimulationFrameTime() const;
virtual void SolidMoved( IClientEntity *pSolidEnt, ICollideable *pSolidCollide, const Vector* pPrevAbsOrigin, bool accurateBboxTriggerChecks );
virtual void TriggerMoved( IClientEntity *pTriggerEnt, bool accurateBboxTriggerChecks );
virtual void ComputeLeavesConnected( const Vector &vecOrigin, int nCount, const int *pLeaves, bool *pIsConnected );
virtual void SetBlurFade( float scale );
virtual bool IsTransitioningToLoad();
virtual void SearchPathsChangedAfterInstall();
virtual void ConfigureSystemLevel( int nCPULevel, int nGPULevel );
virtual void SetConnectionPassword( char const *pchCurrentPW );
virtual CSteamAPIContext* GetSteamAPIContext();
virtual void SubmitStatRecord( char const *szMapName, uint uiBlobVersion, uint uiBlobSize, const void *pvBlob );
virtual void ServerCmdKeyValues( KeyValues *pKeyValues );
virtual void SendMessageToServer( INetMessage *pMessage, bool bForceReliable, bool bVoice ) OVERRIDE;
// global sound pitch scaling
virtual void SetPitchScale( float flPitchScale );
virtual float GetPitchScale( void );
// Load/unload the SFM - used by Replay
virtual bool LoadFilmmaker();
virtual void UnloadFilmmaker();
//paint stuff
virtual bool SpherePaintSurface( const model_t *pModel, const Vector& vPosition, BYTE color, float flSphereRadius, float flPaintCoatPercent );
virtual bool HasPaintmap();
virtual void EnablePaintmapRender();
virtual void SphereTracePaintSurface( const model_t *pModel, const Vector& vPosition, const Vector& vContactNormal, float flSphereRadius, CUtlVector<BYTE>& surfColors );
virtual void RemoveAllPaint();
virtual void PaintAllSurfaces( BYTE color );
virtual void RemovePaint( const model_t *pModel );
virtual bool IsActiveApp();
// is this client running inside the same process as an active server?
virtual bool IsClientLocalToActiveServer();
#if defined( USE_SDL ) || defined ( OSX )
virtual void GetMouseDelta( int &x, int &y, bool bIgnoreNextMouseDelta );
#endif
// Callback for LevelInit to tick the progress bar during time consuming operations
virtual void TickProgressBar();
// Returns the requested input context
virtual InputContextHandle_t GetInputContext( EngineInputContextId_t id );
virtual void GetStartupImage( char *pOutBuffer, int nOutBufferSize );
virtual bool IsUsingLocalNetworkBackdoor();
virtual bool SaveGame( const char *pSaveFilename, bool bIsXSave, char *pOutName, int nOutNameSize, char *pOutComment, int nOutCommentSize );
// Request 'generic' memory stats (returns a list of N named values; caller should assume this list will change over time)
virtual int GetGenericMemoryStats( GenericMemoryStat_t **ppMemoryStats );
// On exit from a map, this becomes true once all map-related assets are flushed from memory:
virtual bool GameHasShutdownAndFlushedMemory();
virtual void FinishContainerWrites( int iController );
virtual void FinishAsyncSave();
const char *GetModDirectory( void );
virtual void AudioLanguageChanged();
virtual void StartLoadingScreenForCommand( const char* command );
virtual void StartLoadingScreenForKeyValues( KeyValues* keyValues );
virtual bool SOSSetOpvarFloat( const char *pOpVarName, float flValue );
virtual bool SOSGetOpvarFloat( const char *pOpVarName, float &flValue );
#if defined(_PS3)
virtual void* GetHostStateWorldBrush( void );
virtual bool PS3_IsUserRestrictedFromChat( void );
virtual bool PS3_IsUserRestrictedFromOnline( void );
virtual bool PS3_PendingInvitesFound( void );
virtual void PS3_ShowInviteOverlay( void );
virtual bool bOverrideCSMConvars( void );
virtual bool bDrawWorldIntoCSM( void );
virtual bool bDrawStaticPropsIntoCSM( void );
virtual float GetCSMMaxDist( void );
#endif
virtual bool IsSubscribedMap( const char *pchMapName, bool bOnlyOnDisk );
virtual bool IsFeaturedMap( const char *pchMapName, bool bOnlyOnDisk );
virtual int GetClientVersion() const;
virtual float GetSafeZoneXMin( void ) const;
virtual bool IsVoiceRecording() const OVERRIDE;
virtual void ForceVoiceRecordOn() const OVERRIDE;
virtual const char* AliasToCommandString( const char* szAliasName ) OVERRIDE;
};
//-----------------------------------------------------------------------------
// Singleton
//-----------------------------------------------------------------------------
static CEngineClient s_VEngineClient;
IVEngineClient *engineClient = &s_VEngineClient;
EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CEngineClient, IVEngineClient, VENGINE_CLIENT_INTERFACE_VERSION, s_VEngineClient );
//-----------------------------------------------------------------------------
// Constructor
//-----------------------------------------------------------------------------
CEngineClient::CEngineClient()
{
}
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;
}
#if defined( OSX ) || defined( USE_SDL )
void CEngineClient::GetMouseDelta( int &x, int &y, bool bIgnoreNextMouseDelta )
{
g_pLauncherMgr->GetMouseDelta( x, y, bIgnoreNextMouseDelta );
}
#endif
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 );
}
// NOTE: This code runs client commands *from the client*; it doesn't execute commands from the server.
// You will want to use g_pVEngineServer->ClientCommand() for that, but that is subject to the
// much more rigorous restriction of FCVAR_SERVER_CAN_EXECUTE since it is a remote command
// execution path.
void CEngineClient::ClientCmd( const char *szCmdString )
{
cmd_source_t commandSrc = kCommandSrcClientCmd;
// If we aren't restricting client commands, then this is just something "from code"
if ( !GetBaseLocalClient().m_bRestrictClientCommands )
commandSrc = kCommandSrcCode;
Cbuf_AddText( Cbuf_GetCurrentPlayer(), szCmdString, commandSrc );
}
extern ConVar in_forceuser;
void CEngineClient::ClientCmd_Unrestricted( const char *szCmdString, bool fromConsoleOrKeybind )
{
int nSplitScreenPlayerSlot = 0;
if ( splitscreen->IsValidSplitScreenSlot( in_forceuser.GetInt() ) )
{
nSplitScreenPlayerSlot = in_forceuser.GetInt();
}
ACTIVE_SPLITSCREEN_PLAYER_GUARD( nSplitScreenPlayerSlot );
Cbuf_AddText( Cbuf_GetCurrentPlayer(), szCmdString, fromConsoleOrKeybind ? kCommandSrcUserInput : kCommandSrcCode );
}
void CEngineClient::ClientCmd_Unrestricted( const char *szCmdString, bool fromConsoleOrKeybind, int nUserSlot, bool bCheckValidSlot )
{
if ( nUserSlot < 0 || nUserSlot >= host_state.max_splitscreen_players )
{
return;
}
if ( bCheckValidSlot )
{
if ( !splitscreen->IsValidSplitScreenSlot( nUserSlot ) )
{
return;
}
}
ACTIVE_SPLITSCREEN_PLAYER_GUARD( nUserSlot );
Cbuf_AddText( Cbuf_GetCurrentPlayer(), szCmdString, fromConsoleOrKeybind ? kCommandSrcUserInput : kCommandSrcCode );
}
void CEngineClient::SetRestrictServerCommands( bool bRestrict )
{
GetBaseLocalClient().m_bRestrictServerCommands = bRestrict;
}
void CEngineClient::SetRestrictClientCommands( bool bRestrict )
{
GetBaseLocalClient().m_bRestrictClientCommands = bRestrict;
}
void CEngineClient::ExecuteClientCmd( const char *szCmdString )
{
Cbuf_AddText( Cbuf_GetCurrentPlayer(), 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 >= GetBaseLocalClient().m_nMaxClients || ent_num < 0 )
{
Q_memset( pinfo, 0, sizeof( player_info_t ) );
return false;
}
Assert( GetBaseLocalClient().m_pUserInfoTable );
if ( !GetBaseLocalClient().m_pUserInfoTable )
{
Q_memset( pinfo, 0, sizeof( player_info_t ) );
return false;
}
Assert( ent_num < GetBaseLocalClient().m_pUserInfoTable->GetNumStrings() );
if ( ent_num >= GetBaseLocalClient().m_pUserInfoTable->GetNumStrings() )
{
Q_memset( pinfo, 0, sizeof( player_info_t ) );
return false;
}
player_info_t *pi = (player_info_t*) GetBaseLocalClient().m_pUserInfoTable->GetStringUserData( ent_num, NULL );
if ( !pi )
{
Q_memset( pinfo, 0, sizeof( player_info_t ) );
return false;
}
// Check the version of player info coming in
uint64 iVersion = BigQWord( pi->version );
if ( iVersion != CDLL_PLAYER_INFO_S_VERSION_CURRENT )
{
// This is "old version 1"
player_info_t_version_1 * pi_old_version_1 = reinterpret_cast< player_info_t_version_1 * >( pi );
pinfo->version = BigQWord( CDLL_PLAYER_INFO_S_VERSION_CURRENT );
Q_memcpy( &pinfo->xuid, &pi_old_version_1->xuid, sizeof( pi_old_version_1->xuid ) );
Q_memcpy( pinfo->name, pi_old_version_1->name, sizeof( pi_old_version_1->name ) );
Q_memcpy( &pinfo->userID, &pi_old_version_1->userID, sizeof( pi_old_version_1->userID ) );
Q_memcpy( pinfo->guid, pi_old_version_1->guid, sizeof( pi_old_version_1->guid ) );
Q_memcpy( &pinfo->friendsID, &pi_old_version_1->friendsID, sizeof( pi_old_version_1->friendsID ) );
Q_memcpy( pinfo->friendsName, pi_old_version_1->friendsName, sizeof( pi_old_version_1->friendsName ) );
Q_memcpy( &pinfo->fakeplayer, &pi_old_version_1->fakeplayer, sizeof( pi_old_version_1->fakeplayer ) );
Q_memcpy( &pinfo->ishltv, &pi_old_version_1->ishltv, sizeof( pi_old_version_1->ishltv ) );
Q_memcpy( pinfo->customFiles, pi_old_version_1->customFiles, sizeof( pi_old_version_1->customFiles ) );
Q_memcpy( &pinfo->filesDownloaded, &pi_old_version_1->filesDownloaded, sizeof( pi_old_version_1->filesDownloaded ) );
}
else
{
Q_memcpy( pinfo, pi, sizeof( player_info_t ) );
}
// Fixup from network order (big endian)
CByteswap byteswap;
byteswap.SetTargetBigEndian( true );
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 GetLocalClient().m_nPlayerSlot + 1;
}
float CEngineClient::GetLastTimeStamp( void )
{
return GetBaseLocalClient().m_flLastServerTickTime;
}
int CEngineClient::GetLastAcknowledgedCommand( void )
{
return GetBaseLocalClient().command_ack;
}