-
Notifications
You must be signed in to change notification settings - Fork 716
/
gamemovement.cpp
5357 lines (4480 loc) · 148 KB
/
gamemovement.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 © 1996-2008, Valve Corporation, All rights reserved. ====
//
//=============================================================================
#include "cbase.h"
#include "gamemovement.h"
#include "in_buttons.h"
#include <stdarg.h>
#include "movevars_shared.h"
#include "engine/IEngineTrace.h"
#include "SoundEmitterSystem/isoundemittersystembase.h"
#include "decals.h"
#include "coordsize.h"
#include "rumble_shared.h"
#include "cstrike15/basecsgrenade_projectile.h"
#if defined(HL2_DLL) || defined(HL2_CLIENT_DLL)
#include "hl_movedata.h"
#endif
#if defined(HL2_EP3) && !defined(CLIENT_DLL)
#include "ep3/weapon_icegun.h"
#endif
#if (PREDICTION_ERROR_CHECK_LEVEL > 0) && (PREDICTION_ERROR_CHECK_STACKS_FOR_MISSING > 0)
#include "tier0/stacktools.h"
#endif
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
#define STOP_EPSILON 0.1
#define MAX_CLIP_PLANES 5
#include "filesystem.h"
#include <stdarg.h>
extern IFileSystem *filesystem;
#ifndef CLIENT_DLL
#include "env_player_surface_trigger.h"
static ConVar dispcoll_drawplane( "dispcoll_drawplane", "0" );
#endif
#if defined ( PORTAL2 ) && !defined ( CLIENT_DLL )
#include "portal_player.h"
#endif
// tickcount currently isn't set during prediction, although gpGlobals->curtime and
// gpGlobals->frametime are. We should probably set tickcount (to player->m_nTickBase),
// but we're REALLY close to shipping, so we can change that later and people can use
// player->CurrentCommandNumber() in the meantime.
#define tickcount USE_PLAYER_CURRENT_COMMAND_NUMBER__INSTEAD_OF_TICKCOUNT
#if defined( HL2_DLL )
ConVar xc_uncrouch_on_jump( "xc_uncrouch_on_jump", "1", FCVAR_ARCHIVE, "Uncrouch when jump occurs" );
#endif
#if defined( HL2_DLL ) || defined( HL2_CLIENT_DLL )
ConVar player_limit_jump_speed( "player_limit_jump_speed", "1", FCVAR_REPLICATED );
#endif
// [MD] I'll remove this eventually. For now, I want the ability to A/B the optimizations.
bool g_bMovementOptimizations = true;
// Roughly how often we want to update the info about the ground surface we're on.
// We don't need to do this very often.
#define CATEGORIZE_GROUND_SURFACE_INTERVAL 0.3f
#define CATEGORIZE_GROUND_SURFACE_TICK_INTERVAL ( (int)( CATEGORIZE_GROUND_SURFACE_INTERVAL / TICK_INTERVAL ) )
#define CHECK_STUCK_INTERVAL 1.0f
#define CHECK_STUCK_TICK_INTERVAL ( (int)( CHECK_STUCK_INTERVAL / TICK_INTERVAL ) )
#define CHECK_STUCK_INTERVAL_SP 0.2f
#define CHECK_STUCK_TICK_INTERVAL_SP ( (int)( CHECK_STUCK_INTERVAL_SP / TICK_INTERVAL ) )
//#define CHECK_LADDER_INTERVAL 0.2f
//#define CHECK_LADDER_TICK_INTERVAL ( (int)( CHECK_LADDER_INTERVAL / TICK_INTERVAL ) )
#define CHECK_LADDER_TICK_INTERVAL 2 // every other tick
#define CHECK_LADDER_WEDGE_INTERVAL 0.5f
#define CHECK_LADDER_WEDGE_TICK_INTERVAL ( (int)( CHECK_LADDER_WEDGE_INTERVAL / TICK_INTERVAL ) )
#define NUM_CROUCH_HINTS 3
#define MINIMUM_MOVE_FRACTION 0.0001f
#define EFFECTIVELY_HORIZONTAL_NORMAL_Z 0.0001f
extern IGameMovement *g_pGameMovement;
//-----------------------------------------------------------------------------
// Purpose:
// Input : &vecSrc -
// flDist -
// flDelta -
// Output : Vector
//-----------------------------------------------------------------------------
class CTraceFilterSkipTwoEntitiesAndCheckTeamMask : public CTraceFilterSkipTwoEntities
{
public:
CTraceFilterSkipTwoEntitiesAndCheckTeamMask( const IHandleEntity *passentity = NULL, const IHandleEntity *passentity2 = NULL, int collisionGroup = COLLISION_GROUP_NONE ) :
CTraceFilterSkipTwoEntities( passentity, passentity2, collisionGroup )
{
}
bool ShouldHitEntity( IHandleEntity *pHandleEntity, int contentsMask )
{
CBaseEntity *pEntity = EntityFromEntityHandle( pHandleEntity );
if ( !pEntity )
return false;
const CBaseEntity *pSelf = EntityFromEntityHandle( GetPassEntity() );
if ( !pSelf )
return false;
if ( GetCollisionGroup() == COLLISION_GROUP_PLAYER_MOVEMENT )
{
if ( pEntity->GetCollisionGroup() == COLLISION_GROUP_PROJECTILE && pSelf->GetTeamNumber() == pEntity->GetTeamNumber() )
return false;
unsigned int myTeamMask = ( pSelf->PhysicsSolidMaskForEntity() & ( CONTENTS_TEAM1 | CONTENTS_TEAM2 ) );
unsigned int otherTeamMask = ( pEntity->PhysicsSolidMaskForEntity() & ( CONTENTS_TEAM1 | CONTENTS_TEAM2 ) );
// See if we have a team and we're on the same team.
// If we are on the same team, then don't collide.
if ( myTeamMask != 0x0 && myTeamMask == otherTeamMask )
{
return false;
}
}
return CTraceFilterSkipTwoEntities::ShouldHitEntity( pHandleEntity, contentsMask );
}
};
#if defined( PLAYER_GETTING_STUCK_TESTING )
// If you ever get stuck walking around, then you can run this code to find the code which would leave the player in a bad spot
void CMoveData::SetAbsOrigin( const Vector &vec )
{
CGameMovement *gm = dynamic_cast< CGameMovement * >( g_pGameMovement );
if ( gm && gm->GetMoveData() &&
gm->player &&
gm->player->entindex() == 1 &&
gm->player->GetMoveType() == MOVETYPE_WALK )
{
trace_t pm;
gm->TracePlayerBBox( vec, vec, gm->PlayerSolidMask(), COLLISION_GROUP_PLAYER_MOVEMENT, pm );
if ( pm.startsolid || pm.allsolid || pm.fraction != 1.0f )
{
Msg( "Player will become stuck at %f %f %f\n", VectorExpand( vec ) );
}
}
m_vecAbsOrigin = vec;
}
#endif
// See shareddefs.h
#if PREDICTION_ERROR_CHECK_LEVEL > 0
static ConVar diffcheck( "diffcheck", "0", FCVAR_REPLICATED );
static ConVar diffcheck_playerslot( "diffcheck_playerslot", "0", FCVAR_REPLICATED );
static ConVar diffcheck_spew( "diffcheck_spew", "1", FCVAR_REPLICATED, "Actually show diffcheck results." );
class IDiffMgr
{
public:
virtual void StartCommand( int nSlot, bool bServer, int nCommandNumber ) = 0;
virtual void AddToDiff( int nSlot, bool bServer, int nCommandNumber, char const *string ) = 0;
virtual void Validate( int nSlot, bool bServer, int nCommandNumber ) = 0;
};
static IDiffMgr *g_pDiffMgr = NULL;
class CDiffStr
{
public:
CDiffStr()
{
m_str[ 0 ] = 0;
#if PREDICTION_ERROR_CHECK_STACKS_FOR_MISSING > 0
m_stackEntries = 0;
#endif
}
CDiffStr( char const *str )
{
Q_strncpy( m_str, str, sizeof( m_str ) );
#if PREDICTION_ERROR_CHECK_STACKS_FOR_MISSING > 0
m_stackEntries = GetCallStack( m_stackAddresses, ARRAYSIZE(m_stackAddresses), 4 ); //skip this constructor, IDiffMgr::AddToDiff(), DiffPrint(), and IGameMovement::DiffPrint()
#endif
}
CDiffStr( const CDiffStr &src )
{
Q_strncpy( m_str, src.m_str, sizeof( m_str ) );
#if PREDICTION_ERROR_CHECK_STACKS_FOR_MISSING > 0
memcpy( m_stackAddresses, src.m_stackAddresses, sizeof( m_stackAddresses ) );
m_stackEntries = src.m_stackEntries;
#endif
}
char const *String()
{
return m_str;
}
#if PREDICTION_ERROR_CHECK_STACKS_FOR_MISSING > 0
void **StackAddresses( void )
{
return m_stackAddresses;
}
const int StackEntries( void )
{
return m_stackEntries;
}
#endif
private:
char m_str[ 128 ];
#if PREDICTION_ERROR_CHECK_STACKS_FOR_MISSING > 0
void *m_stackAddresses[8];
int m_stackEntries;
#endif
};
// Per tick data
class CDiffInfo
{
public:
CDiffInfo() : m_nCommandNumber( 0 ) {}
CDiffInfo( const CDiffInfo& src )
{
m_nCommandNumber = src.m_nCommandNumber;
for ( int i = 0; i < src.m_Lines.Count(); ++i )
{
m_Lines.AddToTail( src.m_Lines[ i ] );
}
}
static bool Less( const CDiffInfo& lhs, const CDiffInfo& rhs )
{
return lhs.m_nCommandNumber < rhs.m_nCommandNumber;
}
int m_nCommandNumber;
CUtlVector< CDiffStr > m_Lines;
bool m_bChecked;
};
class CDiffManager : public IDiffMgr
{
public:
CDiffManager() :
m_flLastSpew( -1.0f )
{
g_pDiffMgr = this;
}
virtual void StartCommand( int nSlot, bool bServer, int nCommandNumber )
{
#if defined( CLIENT_DLL )
if ( !diffcheck.GetInt() )
return;
g_pDiffMgr = reinterpret_cast< IDiffMgr * >( diffcheck.GetInt() );
g_pDiffMgr->StartCommand( nSlot, bServer, nCommandNumber );
return;
#endif
// Msg( "%s Startcommand %d\n", bServer ? "sv" : "cl", nCommandNumber );
diffcheck.SetValue( reinterpret_cast< int >( this ) );
Assert( CBaseEntity::IsServer() );
CUtlRBTree< CDiffInfo, int >& rb = bServer ? m_Data[ nSlot ].m_Server : m_Data[ nSlot ].m_Client;
CDiffInfo search;
search.m_nCommandNumber = nCommandNumber;
int idx = rb.Find( search );
if ( idx == rb.InvalidIndex() )
{
idx = rb.Insert( search );
}
CDiffInfo *slot = &rb[ idx ];
slot->m_Lines.RemoveAll();
}
virtual void AddToDiff( int nSlot, bool bServer, int nCommandNumber, char const *string )
{
#if defined( CLIENT_DLL )
if ( !diffcheck.GetInt() )
return;
g_pDiffMgr = reinterpret_cast< IDiffMgr * >( diffcheck.GetInt() );
g_pDiffMgr->AddToDiff( nSlot, bServer, nCommandNumber, string );
return;
#endif
Assert( CBaseEntity::IsServer() );
// Msg( "%s Add %d %s\n", bServer ? "sv" : "cl", nCommandNumber, string );
CUtlRBTree< CDiffInfo, int >& rb = bServer ? m_Data[ nSlot ].m_Server : m_Data[ nSlot ].m_Client;
CDiffInfo search;
search.m_nCommandNumber = nCommandNumber;
int idx = rb.Find( search );
if ( idx == rb.InvalidIndex() )
{
Assert( 0 );
idx = rb.Insert( search );
}
CDiffInfo *slot = &rb[ idx ];
CDiffStr line( string );
slot->m_Lines.AddToTail( line );
}
enum EMismatched
{
DIFFCHECK_NOTREADY = 0,
DIFFCHECK_MATCHED,
DIFFCHECK_DIFFERS
};
bool ClientRecordExists( int nSlot, int cmd )
{
CDiffInfo clsearch;
clsearch.m_nCommandNumber = cmd;
int clidx = m_Data[ nSlot ].m_Client.Find( clsearch );
return m_Data[ nSlot ].m_Client.IsValidIndex( clidx );
}
EMismatched IsMismatched( int nSlot, int svidx )
{
CDiffInfo *serverslot = &m_Data[ nSlot ].m_Server[ svidx ];
// Now find the client version of this one
CDiffInfo clsearch;
clsearch.m_nCommandNumber = serverslot->m_nCommandNumber;
int clidx = m_Data[ nSlot ].m_Client.Find( clsearch );
if ( clidx == m_Data[ nSlot ].m_Client.InvalidIndex() )
return DIFFCHECK_NOTREADY;
// Now compare them
CDiffInfo *clientslot = &m_Data[ nSlot ].m_Client[ clidx ];
bool bSpew = false;
if ( serverslot->m_Lines.Count() !=
clientslot->m_Lines.Count() )
{
return DIFFCHECK_DIFFERS;
}
int maxSlot = MAX( serverslot->m_Lines.Count(), clientslot->m_Lines.Count() );
if ( !bSpew )
{
for ( int i = 0; i < maxSlot; ++i )
{
CDiffStr *sv = NULL;
CDiffStr *cl = NULL;
if ( i < serverslot->m_Lines.Count() )
{
sv = &serverslot->m_Lines[ i ];
}
if ( i < clientslot->m_Lines.Count() )
{
cl = &clientslot->m_Lines[ i ];
}
if ( Q_stricmp( sv ? sv->String() : "(missing)", cl ? cl->String() : "(missing)" ) )
{
return DIFFCHECK_DIFFERS;
}
}
}
return DIFFCHECK_MATCHED;
}
virtual void Validate( int nSlot, bool bServer, int nCommandNumber )
{
#if defined( CLIENT_DLL )
if ( !diffcheck.GetInt() )
return;
g_pDiffMgr = reinterpret_cast< IDiffMgr * >( diffcheck.GetInt() );
g_pDiffMgr->Validate( nSlot, bServer, nCommandNumber );
return;
#endif
Assert( CBaseEntity::IsServer() );
// Only do this on the client
if ( !bServer )
return;
if ( !diffcheck_spew.GetBool() )
return;
// Don't care about this player slot
if ( diffcheck_playerslot.GetInt() != nSlot )
return;
// Find the last server command number
if ( m_Data[ nSlot ].m_Server.Count() <= 0 )
return;
int svidx = m_Data[ nSlot ].m_Server.LastInorder();
EMismatched eMisMatched = IsMismatched( nSlot, svidx );
if ( eMisMatched == DIFFCHECK_NOTREADY )
{
return;
}
if ( eMisMatched == DIFFCHECK_DIFFERS )
{
CUtlVector< int > vecPrev;
int nCur = svidx;
do
{
int prev = m_Data[ nSlot ].m_Server.PrevInorder( nCur );
if ( m_Data[ nSlot ].m_Server.IsValidIndex( prev ) &&
ClientRecordExists( nSlot, m_Data[ nSlot ].m_Server[ prev ].m_nCommandNumber ) )
{
//SpewRecords( "prev", prev );
vecPrev.AddToHead( prev );
}
else
{
break;
}
nCur = prev;
} while ( vecPrev.Count() < 10 );
Msg( "-----\n" );
for ( int p = 0; p < vecPrev.Count(); ++p )
{
SpewRecords( nSlot, "prev", vecPrev[ p ] );
}
SpewRecords( nSlot, "bad ", svidx );
}
}
void SpewRecords( int nSlot, char const *prefix, int svidx )
{
CDiffInfo *serverslot = &m_Data[ nSlot ].m_Server[ svidx ];
// Now find the client version of this one
CDiffInfo clsearch;
clsearch.m_nCommandNumber = serverslot->m_nCommandNumber;
int clidx = m_Data[ nSlot ].m_Client.Find( clsearch );
if ( clidx == m_Data[ nSlot ].m_Client.InvalidIndex() )
return;
// Now compare them
CDiffInfo *clientslot = &m_Data[ nSlot ].m_Client[ clidx ];
int maxSlot = MAX( serverslot->m_Lines.Count(), clientslot->m_Lines.Count() );
for ( int i = 0; i < maxSlot; ++i )
{
char const *sv = "(missing)";
char const *cl = "(missing)";
#if PREDICTION_ERROR_CHECK_STACKS_FOR_MISSING > 0
int iHaveString = 0;
#endif
if ( i < serverslot->m_Lines.Count() )
{
sv = serverslot->m_Lines[ i ].String();
#if PREDICTION_ERROR_CHECK_STACKS_FOR_MISSING > 0
iHaveString |= 1;
#endif
}
if ( i < clientslot->m_Lines.Count() )
{
cl = clientslot->m_Lines[ i ].String();
#if PREDICTION_ERROR_CHECK_STACKS_FOR_MISSING > 0
iHaveString |= 2;
#endif
}
bool bDiffers = Q_stricmp( sv, cl ) ? true : false;
Msg( "%s%s%d: sv[%100.100s] cl[%100.100s]\n",
prefix,
bDiffers ? "+++" : " ",
serverslot->m_nCommandNumber,
sv,
cl );
#if PREDICTION_ERROR_CHECK_STACKS_FOR_MISSING > 0
if( (iHaveString > 0) && (iHaveString < 3) )
{
CDiffStr *pHaveString = (iHaveString == 1) ? &serverslot->m_Lines[ i ] : &clientslot->m_Lines[ i ];
char szFormattedStack[4096];
szFormattedStack[0] = '\0';
TranslateStackInfo( pHaveString->StackAddresses(), pHaveString->StackEntries(), szFormattedStack, ARRAYSIZE( szFormattedStack ), "\n\t" );
Msg( "Stack for existing side:\n\t%s\n", szFormattedStack );
}
#endif
}
}
private:
struct User_t
{
User_t() :
m_Client( 0, 0, CDiffInfo::Less ),
m_Server( 0, 0, CDiffInfo::Less )
{
}
CUtlRBTree< CDiffInfo, int > m_Server;
CUtlRBTree< CDiffInfo, int > m_Client;
};
User_t m_Data[ MAX_SPLITSCREEN_PLAYERS ];
float m_flLastSpew;
};
static CDiffManager g_DiffMgr;
bool IsValidForErrorCheck( CBasePlayer *pl )
{
Assert( pl );
if ( !pl->GetCurrentUserCommand() )
return false;
if ( pl->entindex() == 1 )
return true;
if ( pl->IsSplitScreenPlayer() )
return true;
return false;
}
void DiffPrint( bool bServer, int nCommandNumber, char const *fmt, ... )
{
// Only track stuff for local player
CBasePlayer *player = CBaseEntity::GetPredictionPlayer();
if ( !player || !IsValidForErrorCheck( player ) )
{
return;
}
va_list argptr;
char string[1024];
va_start (argptr,fmt);
int len = Q_vsnprintf(string, sizeof( string ), fmt,argptr);
va_end (argptr);
if ( g_pDiffMgr )
{
// Strip any \n at the end that the user accidently put int
if ( len > 0 && string[ len -1 ] == '\n' )
{
string[ len - 1 ] = 0;
}
g_pDiffMgr->AddToDiff( player->GetSplitScreenPlayerSlot(), bServer, nCommandNumber, string );
}
}
void _CheckV( int tick, char const *ctx, const Vector &vel )
{
DiffPrint( CBaseEntity::IsServer(), tick, "%20.20s %f %f %f", ctx, vel.x, vel.y, vel.z );
}
#define CheckV( tick, ctx, vel ) _CheckV( tick, ctx, vel );
static void StartCommand( bool bServer, int nCommandNumber )
{
// Only track stuff for local player
CBasePlayer *player = CBaseEntity::GetPredictionPlayer();
if ( !player || !IsValidForErrorCheck( player ) )
{
return;
}
if ( g_pDiffMgr )
{
g_pDiffMgr->StartCommand( player->GetSplitScreenPlayerSlot(), bServer, nCommandNumber );
}
}
static void Validate( bool bServer, int nCommandNumber )
{
// Only track stuff for local player
CBasePlayer *player = CBaseEntity::GetPredictionPlayer();
if ( !player || !IsValidForErrorCheck( player ) )
{
return;
}
if ( g_pDiffMgr )
{
g_pDiffMgr->Validate( player->GetSplitScreenPlayerSlot(), bServer, nCommandNumber );
}
}
void CGameMovement::DiffPrint( char const *fmt, ... )
{
if ( !player || !player->GetCurrentUserCommand() )
return;
va_list argptr;
char string[1024];
va_start (argptr,fmt);
Q_vsnprintf(string, sizeof( string ), fmt,argptr);
va_end (argptr);
::DiffPrint( CBaseEntity::IsServer(), player->CurrentCommandNumber(), "%s", string );
}
#else
void DiffPrint( bool bServer, int nCommandNumber, char const *fmt, ... )
{
// Nothing
}
static void StartCommand( bool bServer, int nCommandNumber )
{
}
static void Validate( bool bServer, int nCommandNumber )
{
}
#define CheckV( tick, ctx, vel )
void CGameMovement::DiffPrint( char const *fmt, ... )
{
}
#endif // !PREDICTION_ERROR_CHECK_LEVEL
void COM_Log( const char *pszFile, const char *fmt, ...)
{
va_list argptr;
char string[1024];
FileHandle_t fp;
const char *pfilename;
if ( !pszFile )
{
pfilename = "hllog.txt";
}
else
{
pfilename = pszFile;
}
va_start (argptr,fmt);
Q_vsnprintf(string, sizeof( string ), fmt,argptr);
va_end (argptr);
fp = filesystem->Open( pfilename, "a+t");
if (fp)
{
filesystem->FPrintf(fp, "%s", string);
filesystem->Close(fp);
}
}
#ifndef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose: Debug - draw the displacement collision plane.
//-----------------------------------------------------------------------------
void DrawDispCollPlane( CBaseTrace *pTrace )
{
float flLength = 30.0f;
// Create a basis, based on the impact normal.
int nMajorAxis = 0;
Vector vecBasisU, vecBasisV, vecNormal;
vecNormal = pTrace->plane.normal;
float flAxisValue = vecNormal[0];
if ( fabs( vecNormal[1] ) > fabs( flAxisValue ) ) { nMajorAxis = 1; flAxisValue = vecNormal[1]; }
if ( fabs( vecNormal[2] ) > fabs( flAxisValue ) ) { nMajorAxis = 2; }
if ( ( nMajorAxis == 1 ) || ( nMajorAxis == 2 ) )
{
vecBasisU.Init( 1.0f, 0.0f, 0.0f );
}
else
{
vecBasisU.Init( 0.0f, 1.0f, 0.0f );
}
vecBasisV = vecNormal.Cross( vecBasisU );
VectorNormalize( vecBasisV );
vecBasisU = vecBasisV.Cross( vecNormal );
VectorNormalize( vecBasisU );
// Create the impact point. Push off the surface a bit.
Vector vecImpactPoint = pTrace->startpos + pTrace->fraction * ( pTrace->endpos - pTrace->startpos );
vecImpactPoint += vecNormal;
// Generate a quad to represent the plane.
Vector vecPlanePoints[4];
vecPlanePoints[0] = vecImpactPoint + ( vecBasisU * -flLength ) + ( vecBasisV * -flLength );
vecPlanePoints[1] = vecImpactPoint + ( vecBasisU * -flLength ) + ( vecBasisV * flLength );
vecPlanePoints[2] = vecImpactPoint + ( vecBasisU * flLength ) + ( vecBasisV * flLength );
vecPlanePoints[3] = vecImpactPoint + ( vecBasisU * flLength ) + ( vecBasisV * -flLength );
#if 0
// Test facing.
Vector vecEdges[2];
vecEdges[0] = vecPlanePoints[1] - vecPlanePoints[0];
vecEdges[1] = vecPlanePoints[2] - vecPlanePoints[0];
Vector vecCross = vecEdges[0].Cross( vecEdges[1] );
if ( vecCross.Dot( vecNormal ) < 0.0f )
{
// Reverse winding.
}
#endif
// Draw the plane.
NDebugOverlay::Triangle( vecPlanePoints[0], vecPlanePoints[1], vecPlanePoints[2], 125, 125, 125, 125, false, 5.0f );
NDebugOverlay::Triangle( vecPlanePoints[0], vecPlanePoints[2], vecPlanePoints[3], 125, 125, 125, 125, false, 5.0f );
NDebugOverlay::Line( vecPlanePoints[0], vecPlanePoints[1], 255, 255, 255, false, 5.0f );
NDebugOverlay::Line( vecPlanePoints[1], vecPlanePoints[2], 255, 255, 255, false, 5.0f );
NDebugOverlay::Line( vecPlanePoints[2], vecPlanePoints[3], 255, 255, 255, false, 5.0f );
NDebugOverlay::Line( vecPlanePoints[3], vecPlanePoints[0], 255, 255, 255, false, 5.0f );
// Draw the normal.
NDebugOverlay::Line( vecImpactPoint, vecImpactPoint + ( vecNormal * flLength ), 255, 0, 0, false, 5.0f );
}
#endif
//-----------------------------------------------------------------------------
// Purpose: Constructs GameMovement interface
//-----------------------------------------------------------------------------
CGameMovement::CGameMovement( void )
{
m_nOldWaterLevel = WL_NotInWater;
m_flWaterEntryTime = 0;
m_nOnLadder = 0;
m_bProcessingMovement = false;
mv = NULL;
memset( m_flStuckCheckTime, 0, sizeof(m_flStuckCheckTime) );
m_pTraceListData = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Destructor
//-----------------------------------------------------------------------------
CGameMovement::~CGameMovement( void )
{
if ( enginetrace )
{
enginetrace->FreeTraceListData(m_pTraceListData);
}
}
//--------------------------------------------------------------------------------------------------------
enum
{
MAX_NESTING = 8
};
static CTraceFilterSkipTwoEntitiesAndCheckTeamMask s_TraceFilter[MAX_NESTING];
static int s_nTraceFilterCount = 0;
ITraceFilter *CGameMovement::LockTraceFilter( int collisionGroup )
{
// If this assertion triggers, you forgot to call UnlockTraceFilter
Assert( s_nTraceFilterCount < MAX_NESTING );
if ( s_nTraceFilterCount >= MAX_NESTING )
return NULL;
CTraceFilterSkipTwoEntitiesAndCheckTeamMask *pFilter = &s_TraceFilter[s_nTraceFilterCount++];
pFilter->SetPassEntity( mv->m_nPlayerHandle.Get() );
pFilter->SetCollisionGroup( collisionGroup );
return pFilter;
}
void CGameMovement::UnlockTraceFilter( ITraceFilter *&pFilter )
{
Assert( s_nTraceFilterCount > 0 );
--s_nTraceFilterCount;
Assert( &s_TraceFilter[s_nTraceFilterCount] == pFilter );
pFilter = NULL;
}
//-----------------------------------------------------------------------------
// Purpose: Allow bots etc to use slightly different solid masks
//-----------------------------------------------------------------------------
unsigned int CGameMovement::PlayerSolidMask( bool brushOnly, CBasePlayer *testPlayer ) const
{
return ( brushOnly ) ? MASK_PLAYERSOLID_BRUSHONLY : MASK_PLAYERSOLID;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : type -
// Output : int
//-----------------------------------------------------------------------------
int CGameMovement::GetCheckInterval( IntervalType_t type )
{
int tickInterval = 1;
switch ( type )
{
default:
tickInterval = 1;
break;
case GROUND:
tickInterval = CATEGORIZE_GROUND_SURFACE_TICK_INTERVAL;
break;
case STUCK:
// If we are in the process of being "stuck", then try a new position every command tick until m_StuckLast gets reset back down to zero
if ( player->m_StuckLast != 0 )
{
tickInterval = 1;
}
else
{
if ( gpGlobals->maxClients == 1 )
{
tickInterval = CHECK_STUCK_TICK_INTERVAL_SP;
}
else
{
tickInterval = CHECK_STUCK_TICK_INTERVAL;
}
}
break;
case LADDER:
tickInterval = CHECK_LADDER_TICK_INTERVAL;
break;
case LADDER_WEDGE:
tickInterval = CHECK_LADDER_WEDGE_TICK_INTERVAL;
break;
}
return tickInterval;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : type -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CGameMovement::CheckInterval( IntervalType_t type )
{
int tickInterval = GetCheckInterval( type );
if ( g_bMovementOptimizations )
{
return (player->CurrentCommandNumber() + player->entindex()) % tickInterval == 0;
}
else
{
return true;
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : ducked -
// Output : const Vector
//-----------------------------------------------------------------------------
const Vector& CGameMovement::GetPlayerMins( bool ducked ) const
{
return ducked ? VEC_DUCK_HULL_MIN : VEC_HULL_MIN;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : ducked -
// Output : const Vector
//-----------------------------------------------------------------------------
const Vector& CGameMovement::GetPlayerMaxs( bool ducked ) const
{
return ducked ? VEC_DUCK_HULL_MAX : VEC_HULL_MAX;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input :
// Output : const Vector
//-----------------------------------------------------------------------------
const Vector& CGameMovement::GetPlayerMins( void ) const
{
if ( player->IsObserver() )
{
return VEC_OBS_HULL_MIN;
}
else
{
return player->m_Local.m_bDucked ? VEC_DUCK_HULL_MIN : VEC_HULL_MIN;
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input :
// Output : const Vector
//-----------------------------------------------------------------------------
const Vector& CGameMovement::GetPlayerMaxs( void ) const
{
if ( player->IsObserver() )
{
return VEC_OBS_HULL_MAX;
}
else
{
return player->m_Local.m_bDucked ? VEC_DUCK_HULL_MAX : VEC_HULL_MAX;
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : ducked -
// Output : const Vector
//-----------------------------------------------------------------------------
const Vector& CGameMovement::GetPlayerViewOffset( bool ducked ) const
{
return ducked ? VEC_DUCK_VIEW : VEC_VIEW;
}
CBaseHandle CGameMovement::TestPlayerPosition( const Vector& pos, int collisionGroup, trace_t& pm )
{
++m_nTraceCount;
Ray_t ray;
ray.Init( pos, pos, GetPlayerMins(), GetPlayerMaxs() );
ITraceFilter *filter = LockTraceFilter( collisionGroup );
UTIL_TraceRay( ray, PlayerSolidMask(), filter, &pm );
UnlockTraceFilter( filter );
if ( (pm.contents & PlayerSolidMask()) && pm.m_pEnt )
return pm.m_pEnt->GetRefEHandle();
return INVALID_EHANDLE;
}
/*
// FIXME FIXME: Does this need to be hooked up?
bool CGameMovement::IsWet() const
{
return ((pev->flags & FL_INRAIN) != 0) || (m_WetTime >= gpGlobals->time);
}
//-----------------------------------------------------------------------------
// Plants player footprint decals
//-----------------------------------------------------------------------------
#define PLAYER_HALFWIDTH 12
void CGameMovement::PlantFootprint( surfacedata_t *psurface )
{
// Can't plant footprints on fake materials (ladders, wading)
if ( psurface->gameMaterial != 'X' )
{
int footprintDecal = -1;
// Figure out which footprint type to plant...
// Use the wet footprint if we're wet...
if (IsWet())
{
footprintDecal = DECAL_FOOTPRINT_WET;
}
else
{
// FIXME: Activate this once we decide to pull the trigger on it.
// NOTE: We could add in snow, mud, others here
// switch(psurface->gameMaterial)
// {
// case 'D':
// footprintDecal = DECAL_FOOTPRINT_DIRT;
// break;
// }
}
if (footprintDecal != -1)
{
Vector right;
AngleVectors( pev->angles, 0, &right, 0 );
// Figure out where the top of the stepping leg is
trace_t tr;
Vector hipOrigin;
VectorMA( pev->origin,
m_IsFootprintOnLeft ? -PLAYER_HALFWIDTH : PLAYER_HALFWIDTH,