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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "tier0/vprof.h"
#include "animation.h"
#include "studio.h"
#include "apparent_velocity_helper.h"
#include "utldict.h"
#include "multiplayer_animstate.h"
#include "activitylist.h"
#ifdef CLIENT_DLL
#include "c_baseplayer.h"
#include "engine/ivdebugoverlay.h"
#include "filesystem.h"
#include "eventlist.h"
ConVar anim_showmainactivity( "anim_showmainactivity", "0", FCVAR_CHEAT, "Show the idle, walk, run, and/or sprint activities." );
#else
#include "player.h"
#endif
#if defined(TF_CLIENT_DLL) || defined(TF_DLL)
#include "tf_gamerules.h"
#endif
#ifndef CALL_ATTRIB_HOOK_FLOAT_ON_OTHER
#define CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( o, r, n )
#endif
#define MOVING_MINIMUM_SPEED 0.5f
ConVar anim_showstate( "anim_showstate", "-1", FCVAR_CHEAT | FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "Show the (client) animation state for the specified entity (-1 for none)." );
ConVar anim_showstatelog( "anim_showstatelog", "0", FCVAR_CHEAT | FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "1 to output anim_showstate to Msg(). 2 to store in AnimState.log. 3 for both." );
ConVar mp_showgestureslots( "mp_showgestureslots", "-1", FCVAR_CHEAT | FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "Show multiplayer client/server gesture slot information for the specified player index (-1 for no one)." );
ConVar mp_slammoveyaw( "mp_slammoveyaw", "0", FCVAR_REPLICATED | FCVAR_DEVELOPMENTONLY, "Force movement yaw along an animation path." );
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pPlayer -
// &movementData -
//-----------------------------------------------------------------------------
CMultiPlayerAnimState::CMultiPlayerAnimState( CBasePlayer *pPlayer, MultiPlayerMovementData_t &movementData )
#ifdef CLIENT_DLL
: m_iv_flMaxGroundSpeed( "CMultiPlayerAnimState::m_iv_flMaxGroundSpeed" )
#endif
{
// Pose parameters.
m_bPoseParameterInit = false;
m_PoseParameterData.Init();
m_DebugAnimData.Init();
m_pPlayer = NULL;
m_angRender.Init();
m_bCurrentFeetYawInitialized = false;
m_flLastAnimationStateClearTime = 0.0f;
m_flEyeYaw = 0.0f;
m_flEyePitch = 0.0f;
m_flGoalFeetYaw = 0.0f;
m_flCurrentFeetYaw = 0.0f;
m_flLastAimTurnTime = 0.0f;
// Jumping.
m_bJumping = false;
m_flJumpStartTime = 0.0f;
m_bFirstJumpFrame = false;
// Swimming
m_bInSwim = false;
m_bFirstSwimFrame = true;
// Dying
m_bDying = false;
m_bFirstDyingFrame = true;
m_eCurrentMainSequenceActivity = ACT_INVALID;
m_nSpecificMainSequence = -1;
// Weapon data.
m_hActiveWeapon = NULL;
// Ground speed interpolators.
#ifdef CLIENT_DLL
m_iv_flMaxGroundSpeed.Setup( &m_flMaxGroundSpeed, LATCH_ANIMATION_VAR | INTERPOLATE_LINEAR_ONLY );
m_flLastGroundSpeedUpdateTime = 0.0f;
#endif
m_flMaxGroundSpeed = 0.0f;
// If you are forcing aim yaw, your code is almost definitely broken if you don't include a delay between
// teleporting and forcing yaw. This is due to an unfortunate interaction between the command lookback window,
// and the fact that m_flEyeYaw is never propogated from the server to the client.
// TODO: Fix this after Halloween 2014.
m_bForceAimYaw = false;
Init( pPlayer, movementData );
// movement playback options
m_nMovementSequence = -1;
m_LegAnimType = LEGANIM_9WAY;
InitGestureSlots();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
//-----------------------------------------------------------------------------
CMultiPlayerAnimState::~CMultiPlayerAnimState()
{
ShutdownGestureSlots();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pPlayer -
// &movementData -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::Init( CBasePlayer *pPlayer, MultiPlayerMovementData_t &movementData )
{
// Get the player this animation data works on.
m_pPlayer = pPlayer;
// Copy the movement data.
memcpy( &m_MovementData, &movementData, sizeof( MultiPlayerMovementData_t ) );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ClearAnimationState()
{
// Reset state.
m_bJumping = false;
m_bDying = false;
m_bCurrentFeetYawInitialized = false;
m_flLastAnimationStateClearTime = gpGlobals->curtime;
m_nSpecificMainSequence = -1;
ResetGestureSlots();
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : event -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::DoAnimationEvent( PlayerAnimEvent_t event, int nData )
{
switch( event )
{
case PLAYERANIMEVENT_ATTACK_PRIMARY:
{
// Weapon primary fire.
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_ATTACK_STAND_PRIMARYFIRE );
break;
}
case PLAYERANIMEVENT_ATTACK_SECONDARY:
{
// Weapon secondary fire.
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_ATTACK_STAND_SECONDARYFIRE );
break;
}
case PLAYERANIMEVENT_ATTACK_GRENADE:
{
// Grenade throw.
RestartGesture( GESTURE_SLOT_GRENADE, ACT_MP_ATTACK_STAND_GRENADE );
break;
}
case PLAYERANIMEVENT_RELOAD:
{
// Weapon reload.
if ( GetBasePlayer()->GetFlags() & FL_DUCKING )
{
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_RELOAD_CROUCH );
}
else if ( m_bInSwim )
{
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_RELOAD_SWIM );
}
else
{
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_RELOAD_STAND );
}
// Set the modified reload playback rate
float flPlaybackRate = 1.0f;
#if defined(TF_CLIENT_DLL) || defined(TF_DLL)
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( GetBasePlayer(), flPlaybackRate, mult_reload_time );
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( GetBasePlayer(), flPlaybackRate, mult_reload_time_hidden );
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( GetBasePlayer(), flPlaybackRate, fast_reload );
#endif
m_aGestureSlots[ GESTURE_SLOT_ATTACK_AND_RELOAD ].m_pAnimLayer->m_flPlaybackRate = flPlaybackRate;
break;
}
case PLAYERANIMEVENT_RELOAD_LOOP:
{
// Weapon reload.
if ( GetBasePlayer()->GetFlags() & FL_DUCKING )
{
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_RELOAD_CROUCH_LOOP );
}
else if ( m_bInSwim )
{
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_RELOAD_SWIM_LOOP );
}
else
{
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_RELOAD_STAND_LOOP );
}
// Set the modified reload playback rate
float flPlaybackRate = 1.0f;
#if defined(TF_CLIENT_DLL) || defined(TF_DLL)
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( GetBasePlayer(), flPlaybackRate, mult_reload_time );
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( GetBasePlayer(), flPlaybackRate, mult_reload_time_hidden );
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( GetBasePlayer(), flPlaybackRate, fast_reload );
#endif
m_aGestureSlots[ GESTURE_SLOT_ATTACK_AND_RELOAD ].m_pAnimLayer->m_flPlaybackRate = flPlaybackRate;
break;
}
case PLAYERANIMEVENT_RELOAD_END:
{
// Weapon reload.
if ( GetBasePlayer()->GetFlags() & FL_DUCKING )
{
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_RELOAD_CROUCH_END );
}
else if ( m_bInSwim )
{
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_RELOAD_SWIM_END );
}
else
{
RestartGesture( GESTURE_SLOT_ATTACK_AND_RELOAD, ACT_MP_RELOAD_STAND_END );
}
// Set the modified reload playback rate
float flPlaybackRate = 1.0f;
#if defined(TF_CLIENT_DLL) || defined(TF_DLL)
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( GetBasePlayer(), flPlaybackRate, mult_reload_time );
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( GetBasePlayer(), flPlaybackRate, mult_reload_time_hidden );
CALL_ATTRIB_HOOK_FLOAT_ON_OTHER( GetBasePlayer(), flPlaybackRate, fast_reload );
#endif
m_aGestureSlots[ GESTURE_SLOT_ATTACK_AND_RELOAD ].m_pAnimLayer->m_flPlaybackRate = flPlaybackRate;
break;
}
case PLAYERANIMEVENT_JUMP:
{
// Jump.
m_bJumping = true;
m_bFirstJumpFrame = true;
m_flJumpStartTime = gpGlobals->curtime;
RestartMainSequence();
break;
}
case PLAYERANIMEVENT_DIE:
{
// Should be here - not supporting this yet!
Assert( 0 );
// Start playing the death animation
m_bDying = true;
RestartMainSequence();
break;
}
case PLAYERANIMEVENT_SPAWN:
{
// Player has respawned. Clear flags.
ClearAnimationState();
break;
}
case PLAYERANIMEVENT_SNAP_YAW:
m_PoseParameterData.m_flLastAimTurnTime = 0.0f;
break;
case PLAYERANIMEVENT_CUSTOM:
{
Activity iIdealActivity = TranslateActivity( (Activity)nData );
m_nSpecificMainSequence = GetBasePlayer()->SelectWeightedSequence( iIdealActivity );
RestartMainSequence();
}
break;
case PLAYERANIMEVENT_CUSTOM_GESTURE:
// Weapon primary fire.
RestartGesture( GESTURE_SLOT_CUSTOM, (Activity)nData );
break;
case PLAYERANIMEVENT_CUSTOM_SEQUENCE:
m_nSpecificMainSequence = nData;
RestartMainSequence();
break;
case PLAYERANIMEVENT_CUSTOM_GESTURE_SEQUENCE:
// Weapon primary fire.
// RestartGestureSequence( nData, false );
break;
case PLAYERANIMEVENT_FLINCH_CHEST:
PlayFlinchGesture( ACT_MP_GESTURE_FLINCH_CHEST );
break;
case PLAYERANIMEVENT_FLINCH_HEAD:
PlayFlinchGesture( ACT_MP_GESTURE_FLINCH_HEAD );
break;
case PLAYERANIMEVENT_FLINCH_LEFTARM:
PlayFlinchGesture( ACT_MP_GESTURE_FLINCH_LEFTARM );
break;
case PLAYERANIMEVENT_FLINCH_RIGHTARM:
PlayFlinchGesture( ACT_MP_GESTURE_FLINCH_RIGHTARM );
break;
case PLAYERANIMEVENT_FLINCH_LEFTLEG:
PlayFlinchGesture( ACT_MP_GESTURE_FLINCH_LEFTLEG );
break;
case PLAYERANIMEVENT_FLINCH_RIGHTLEG:
PlayFlinchGesture( ACT_MP_GESTURE_FLINCH_RIGHTLEG );
break;
default:
break;
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::PlayFlinchGesture( Activity iActivity )
{
if ( !IsGestureSlotActive( GESTURE_SLOT_FLINCH ) )
{
// See if we have the custom flinch. If not, revert to chest
if ( iActivity != ACT_MP_GESTURE_FLINCH_CHEST && GetBasePlayer()->SelectWeightedSequence( iActivity ) == -1 )
{
RestartGesture( GESTURE_SLOT_FLINCH, ACT_MP_GESTURE_FLINCH_CHEST );
}
else
{
RestartGesture( GESTURE_SLOT_FLINCH, iActivity );
}
}
}
//=============================================================================
//
// Multiplayer gesture code.
//
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::InitGestureSlots( void )
{
// Setup the number of gesture slots.
m_aGestureSlots.AddMultipleToTail( GESTURE_SLOT_COUNT );
// Assign all of the the CAnimationLayer pointers to null early in case we bail.
for ( int iGesture = 0; iGesture < GESTURE_SLOT_COUNT; ++iGesture )
{
m_aGestureSlots[iGesture].m_pAnimLayer = NULL;
}
// Get the base player.
CBasePlayer *pPlayer = GetBasePlayer();
// Set the number of animation overlays we will use.
pPlayer->SetNumAnimOverlays( GESTURE_SLOT_COUNT );
for ( int iGesture = 0; iGesture < GESTURE_SLOT_COUNT; ++iGesture )
{
m_aGestureSlots[iGesture].m_pAnimLayer = pPlayer->GetAnimOverlay( iGesture );
if ( !m_aGestureSlots[iGesture].m_pAnimLayer )
return false;
ResetGestureSlot( iGesture );
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ShutdownGestureSlots( void )
{
// Clean up the gesture slots.
m_aGestureSlots.Purge();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ResetGestureSlots( void )
{
// Clear out all the gesture slots.
for ( int iGesture = 0; iGesture < GESTURE_SLOT_COUNT; ++iGesture )
{
ResetGestureSlot( iGesture );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ResetGestureSlot( int iGestureSlot )
{
// Sanity Check
Assert( iGestureSlot >= 0 && iGestureSlot < GESTURE_SLOT_COUNT );
if ( !VerifyAnimLayerInSlot( iGestureSlot ) )
return;
GestureSlot_t *pGestureSlot = &m_aGestureSlots[iGestureSlot];
if ( pGestureSlot )
{
#ifdef CLIENT_DLL
// briefly set to 1.0 so we catch the events, before we reset the slot
pGestureSlot->m_pAnimLayer->m_flCycle = 1.0;
RunGestureSlotAnimEventsToCompletion( pGestureSlot );
#endif
pGestureSlot->m_iGestureSlot = GESTURE_SLOT_INVALID;
pGestureSlot->m_iActivity = ACT_INVALID;
pGestureSlot->m_bAutoKill = false;
pGestureSlot->m_bActive = false;
if ( pGestureSlot->m_pAnimLayer )
{
pGestureSlot->m_pAnimLayer->SetOrder( CBaseAnimatingOverlay::MAX_OVERLAYS );
#ifdef CLIENT_DLL
pGestureSlot->m_pAnimLayer->Reset();
#endif
}
}
}
#ifdef CLIENT_DLL
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::RunGestureSlotAnimEventsToCompletion( GestureSlot_t *pGesture )
{
CBasePlayer *pPlayer = GetBasePlayer();
if( !pPlayer )
return;
// Get the studio header for the player.
CStudioHdr *pStudioHdr = pPlayer->GetModelPtr();
if ( !pStudioHdr )
return;
// Do all the anim events between previous cycle and 1.0, inclusive
mstudioseqdesc_t &seqdesc = pStudioHdr->pSeqdesc( pGesture->m_pAnimLayer->m_nSequence );
if ( seqdesc.numevents > 0 )
{
mstudioevent_t *pevent = seqdesc.pEvent( 0 );
for (int i = 0; i < (int)seqdesc.numevents; i++)
{
if ( pevent[i].type & AE_TYPE_NEWEVENTSYSTEM )
{
if ( !( pevent[i].type & AE_TYPE_CLIENT ) )
continue;
}
else if ( pevent[i].event < 5000 ) //Adrian - Support the old event system
continue;
if ( pevent[i].cycle > pGesture->m_pAnimLayer->m_flPrevCycle &&
pevent[i].cycle <= pGesture->m_pAnimLayer->m_flCycle )
{
pPlayer->FireEvent( pPlayer->GetAbsOrigin(), pPlayer->GetAbsAngles(), pevent[ i ].event, pevent[ i ].pszOptions() );
}
}
}
}
#endif
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::IsGestureSlotActive( int iGestureSlot )
{
// Sanity Check
Assert( iGestureSlot >= 0 && iGestureSlot < GESTURE_SLOT_COUNT );
return m_aGestureSlots[iGestureSlot].m_bActive;
}
//-----------------------------------------------------------------------------
// Purpose: Track down a crash
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::VerifyAnimLayerInSlot( int iGestureSlot )
{
if ( iGestureSlot < 0 || iGestureSlot >= GESTURE_SLOT_COUNT )
{
return false;
}
if ( GetBasePlayer()->GetNumAnimOverlays() < iGestureSlot + 1 )
{
AssertMsg2( false, "Player %d doesn't have gesture slot %d any more.", GetBasePlayer()->entindex(), iGestureSlot );
Msg( "Player %d doesn't have gesture slot %d any more.\n", GetBasePlayer()->entindex(), iGestureSlot );
m_aGestureSlots[iGestureSlot].m_pAnimLayer = NULL;
return false;
}
CAnimationLayer *pExpected = GetBasePlayer()->GetAnimOverlay( iGestureSlot );
if ( m_aGestureSlots[iGestureSlot].m_pAnimLayer != pExpected )
{
AssertMsg3( false, "Gesture slot %d pointing to wrong address %p. Updating to new address %p.", iGestureSlot, m_aGestureSlots[iGestureSlot].m_pAnimLayer, pExpected );
Msg( "Gesture slot %d pointing to wrong address %p. Updating to new address %p.\n", iGestureSlot, m_aGestureSlots[iGestureSlot].m_pAnimLayer, pExpected );
m_aGestureSlots[iGestureSlot].m_pAnimLayer = pExpected;
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::IsGestureSlotPlaying( int iGestureSlot, Activity iGestureActivity )
{
// Sanity Check
Assert( iGestureSlot >= 0 && iGestureSlot < GESTURE_SLOT_COUNT );
// Check to see if the slot is active.
if ( !IsGestureSlotActive( iGestureSlot ) )
return false;
return ( m_aGestureSlots[iGestureSlot].m_iActivity == iGestureActivity );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::RestartGesture( int iGestureSlot, Activity iGestureActivity, bool bAutoKill )
{
// Sanity Check
Assert( iGestureSlot >= 0 && iGestureSlot < GESTURE_SLOT_COUNT );
if ( !VerifyAnimLayerInSlot( iGestureSlot ) )
return;
if ( !IsGestureSlotPlaying( iGestureSlot, iGestureActivity ) )
{
#ifdef CLIENT_DLL
if ( IsGestureSlotActive( iGestureSlot ) )
{
GestureSlot_t *pGesture = &m_aGestureSlots[iGestureSlot];
if ( pGesture && pGesture->m_pAnimLayer )
{
pGesture->m_pAnimLayer->m_flCycle = 1.0; // run until the end
RunGestureSlotAnimEventsToCompletion( &m_aGestureSlots[iGestureSlot] );
}
}
#endif
Activity iIdealGestureActivity = TranslateActivity( iGestureActivity );
AddToGestureSlot( iGestureSlot, iIdealGestureActivity, bAutoKill );
return;
}
// Reset the cycle = restart the gesture.
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flCycle = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flPrevCycle = 0.0f;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::AddToGestureSlot( int iGestureSlot, Activity iGestureActivity, bool bAutoKill )
{
// Sanity Check
Assert( iGestureSlot >= 0 && iGestureSlot < GESTURE_SLOT_COUNT );
CBasePlayer *pPlayer = GetBasePlayer();
if ( !pPlayer )
return;
// Make sure we have a valid animation layer to fill out.
if ( !m_aGestureSlots[iGestureSlot].m_pAnimLayer )
return;
if ( !VerifyAnimLayerInSlot( iGestureSlot ) )
return;
// Get the sequence.
int iGestureSequence = pPlayer->SelectWeightedSequence( iGestureActivity );
if ( iGestureSequence <= 0 )
return;
#ifdef CLIENT_DLL
// Setup the gesture.
m_aGestureSlots[iGestureSlot].m_iGestureSlot = iGestureSlot;
m_aGestureSlots[iGestureSlot].m_iActivity = iGestureActivity;
m_aGestureSlots[iGestureSlot].m_bAutoKill = bAutoKill;
m_aGestureSlots[iGestureSlot].m_bActive = true;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nSequence = iGestureSequence;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nOrder = iGestureSlot;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flWeight = 1.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flPlaybackRate = 1.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flCycle = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flPrevCycle = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flLayerAnimtime = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flLayerFadeOuttime = 0.0f;
pPlayer->m_flOverlayPrevEventCycle[iGestureSlot] = -1.0;
#else
// Setup the gesture.
m_aGestureSlots[iGestureSlot].m_iGestureSlot = iGestureSlot;
m_aGestureSlots[iGestureSlot].m_iActivity = iGestureActivity;
m_aGestureSlots[iGestureSlot].m_bAutoKill = bAutoKill;
m_aGestureSlots[iGestureSlot].m_bActive = true;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nActivity = iGestureActivity;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nOrder = iGestureSlot;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nPriority = 0;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flCycle = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flPrevCycle = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flPlaybackRate = 1.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nActivity = iGestureActivity;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nSequence = iGestureSequence;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flWeight = 1.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flBlendIn = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flBlendOut = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_bSequenceFinished = false;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flLastEventCheck = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flLastEventCheck = gpGlobals->curtime;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_bLooping = false;//( ( GetSequenceFlags( GetModelPtr(), iGestureSequence ) & STUDIO_LOOPING ) != 0);
if ( bAutoKill )
{
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_fFlags |= ANIM_LAYER_AUTOKILL;
}
else
{
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_fFlags &= ~ANIM_LAYER_AUTOKILL;
}
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_fFlags |= ANIM_LAYER_ACTIVE;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::AddVCDSequenceToGestureSlot( int iGestureSlot, int iGestureSequence, float flCycle, bool bAutoKill )
{
// Sanity Check
Assert( iGestureSlot >= 0 && iGestureSlot < GESTURE_SLOT_COUNT );
CBasePlayer *pPlayer = GetBasePlayer();
if ( !pPlayer )
return;
// Make sure we have a valid animation layer to fill out.
if ( !m_aGestureSlots[iGestureSlot].m_pAnimLayer )
return;
if ( !VerifyAnimLayerInSlot( iGestureSlot ) )
return;
// Set the activity.
Activity iGestureActivity = ACT_MP_VCD;
#ifdef CLIENT_DLL
// Setup the gesture.
m_aGestureSlots[iGestureSlot].m_iGestureSlot = iGestureSlot;
m_aGestureSlots[iGestureSlot].m_iActivity = iGestureActivity;
m_aGestureSlots[iGestureSlot].m_bAutoKill = bAutoKill;
m_aGestureSlots[iGestureSlot].m_bActive = true;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nSequence = iGestureSequence;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nOrder = iGestureSlot;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flWeight = 1.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flPlaybackRate = 1.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flCycle = flCycle;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flPrevCycle = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flLayerAnimtime = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flLayerFadeOuttime = 0.0f;
pPlayer->m_flOverlayPrevEventCycle[iGestureSlot] = -1.0;
#else
// Setup the gesture.
m_aGestureSlots[iGestureSlot].m_iGestureSlot = iGestureSlot;
m_aGestureSlots[iGestureSlot].m_iActivity = iGestureActivity;
m_aGestureSlots[iGestureSlot].m_bAutoKill = bAutoKill;
m_aGestureSlots[iGestureSlot].m_bActive = true;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nActivity = iGestureActivity;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nOrder = iGestureSlot;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nPriority = 0;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flCycle = flCycle;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flPrevCycle = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flPlaybackRate = 1.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nActivity = iGestureActivity;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_nSequence = iGestureSequence;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flWeight = 1.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flBlendIn = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flBlendOut = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_bSequenceFinished = false;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flLastEventCheck = 0.0f;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_flLastEventCheck = gpGlobals->curtime;
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_bLooping = false;//( ( GetSequenceFlags( GetModelPtr(), iGestureSequence ) & STUDIO_LOOPING ) != 0);
if ( bAutoKill )
{
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_fFlags |= ANIM_LAYER_AUTOKILL;
}
else
{
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_fFlags &= ~ANIM_LAYER_AUTOKILL;
}
m_aGestureSlots[iGestureSlot].m_pAnimLayer->m_fFlags |= ANIM_LAYER_ACTIVE;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CAnimationLayer* CMultiPlayerAnimState::GetGestureSlotLayer( int iGestureSlot )
{
return m_aGestureSlots[iGestureSlot].m_pAnimLayer;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ShowDebugInfo( void )
{
if ( anim_showstate.GetInt() == GetBasePlayer()->entindex() )
{
DebugShowAnimStateForPlayer( GetBasePlayer()->IsServer() );
}
}
//-----------------------------------------------------------------------------
// Purpose: Cancel the current gesture and restart the main sequence.
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::RestartMainSequence( void )
{
CBaseAnimatingOverlay *pPlayer = GetBasePlayer();
if ( pPlayer )
{
pPlayer->m_flAnimTime = gpGlobals->curtime;
pPlayer->SetCycle( 0 );
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *idealActivity -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::HandleJumping( Activity &idealActivity )
{
if ( m_bJumping )
{
if ( m_bFirstJumpFrame )
{
m_bFirstJumpFrame = false;
RestartMainSequence(); // Reset the animation.
}
// Check to see if we hit water and stop jumping animation.
if ( GetBasePlayer()->GetWaterLevel() >= WL_Waist )
{
m_bJumping = false;
RestartMainSequence();
}
// Don't check if he's on the ground for a sec.. sometimes the client still has the
// on-ground flag set right when the message comes in.
else if ( gpGlobals->curtime - m_flJumpStartTime > 0.2f )
{
if ( GetBasePlayer()->GetFlags() & FL_ONGROUND )
{
m_bJumping = false;
RestartMainSequence();
}
}
}
if ( m_bJumping )
{
idealActivity = ACT_MP_JUMP;
return true;
}
else
{
return false;
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *idealActivity -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::HandleDucking( Activity &idealActivity )
{
if ( GetBasePlayer()->GetFlags() & FL_DUCKING )
{
if ( GetOuterXYSpeed() > MOVING_MINIMUM_SPEED )
{
idealActivity = ACT_MP_CROUCHWALK;
}
else
{
idealActivity = ACT_MP_CROUCH_IDLE;
}
return true;
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : &idealActivity -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::HandleSwimming( Activity &idealActivity )
{
if ( GetBasePlayer()->GetWaterLevel() >= WL_Waist )
{
if ( m_bFirstSwimFrame )
{
// Reset the animation.
RestartMainSequence();
m_bFirstSwimFrame = false;
}
idealActivity = ACT_MP_SWIM;
m_bInSwim = true;
return true;
}
else
{
m_bInSwim = false;
if ( !m_bFirstSwimFrame )
{
m_bFirstSwimFrame = true;
}
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *idealActivity -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::HandleDying( Activity &idealActivity )
{
if ( m_bDying )
{
if ( m_bFirstDyingFrame )
{
// Reset the animation.
RestartMainSequence();
m_bFirstDyingFrame = false;
}
idealActivity = ACT_DIESIMPLE;
return true;
}
else
{
if ( !m_bFirstDyingFrame )
{
m_bFirstDyingFrame = true;
}
}
return false;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *idealActivity -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::HandleMoving( Activity &idealActivity )
{
// In TF we run all the time now.
float flSpeed = GetOuterXYSpeed();
if ( flSpeed > MOVING_MINIMUM_SPEED )
{
// Always assume a run.
idealActivity = ACT_MP_RUN;
}
return true;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
// Output : Activity
//-----------------------------------------------------------------------------
Activity CMultiPlayerAnimState::CalcMainActivity()
{
Activity idealActivity = ACT_MP_STAND_IDLE;
if ( HandleJumping( idealActivity ) ||
HandleDucking( idealActivity ) ||
HandleSwimming( idealActivity ) ||
HandleDying( idealActivity ) )
{
// intentionally blank
}
else
{
HandleMoving( idealActivity );
}
ShowDebugInfo();
// Client specific.
#ifdef CLIENT_DLL
if ( anim_showmainactivity.GetBool() )
{
DebugShowActivity( idealActivity );
}
#endif
return idealActivity;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : actDesired -
// Output : Activity
//-----------------------------------------------------------------------------
Activity CMultiPlayerAnimState::TranslateActivity( Activity actDesired )
{
// Translate activities for swimming.
if ( m_bInSwim )
{
switch ( actDesired )
{
case ACT_MP_ATTACK_STAND_PRIMARYFIRE: { actDesired = ACT_MP_ATTACK_SWIM_PRIMARYFIRE; break; }
case ACT_MP_ATTACK_STAND_SECONDARYFIRE: { actDesired = ACT_MP_ATTACK_SWIM_SECONDARYFIRE; break; }
case ACT_MP_ATTACK_STAND_GRENADE: { actDesired = ACT_MP_ATTACK_SWIM_GRENADE; break; }
case ACT_MP_RELOAD_STAND: { actDesired = ACT_MP_RELOAD_SWIM; break; }
}
}
return actDesired;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
// Output : float
//-----------------------------------------------------------------------------
float CMultiPlayerAnimState::GetCurrentMaxGroundSpeed()
{
CStudioHdr *pStudioHdr = GetBasePlayer()->GetModelPtr();
if ( pStudioHdr == NULL )
return 1.0f;
float prevX = GetBasePlayer()->GetPoseParameter( m_PoseParameterData.m_iMoveX );
float prevY = GetBasePlayer()->GetPoseParameter( m_PoseParameterData.m_iMoveY );
float d = MAX( fabs( prevX ), fabs( prevY ) );
float newX, newY;
if ( d == 0.0 )
{
newX = 1.0;
newY = 0.0;
}
else
{
newX = prevX / d;
newY = prevY / d;
}
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveX, newX );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveY, newY );
float speed = GetBasePlayer()->GetSequenceGroundSpeed( GetBasePlayer()->GetSequence() );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveX, prevX );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveY, prevY );
return speed;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *bIsMoving -
// Output : float
//-----------------------------------------------------------------------------
float CMultiPlayerAnimState::CalcMovementSpeed( bool *bIsMoving )
{
// Get the player's current velocity and speed.
Vector vecVelocity;
GetOuterAbsVelocity( vecVelocity );
float flSpeed = vecVelocity.Length2D();
if ( flSpeed > MOVING_MINIMUM_SPEED )
{
*bIsMoving = true;
return flSpeed;
}
*bIsMoving = false;
return 0.0f;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *bIsMoving -
// Output : float
//-----------------------------------------------------------------------------
float CMultiPlayerAnimState::CalcMovementPlaybackRate( bool *bIsMoving )
{
float flSpeed = CalcMovementSpeed( bIsMoving );
float flReturn = 1.0f;
// If we are moving.
if ( *bIsMoving )
{
// float flGroundSpeed = GetInterpolatedGroundSpeed();
float flGroundSpeed = GetCurrentMaxGroundSpeed();
if ( flGroundSpeed < 0.001f )
{
flReturn = 0.01f;
}
else
{
// Note this gets set back to 1.0 if sequence changes due to ResetSequenceInfo below
flReturn = flSpeed / flGroundSpeed;
flReturn = clamp( flReturn, 0.01f, 10.0f );
}
}
return flReturn;
}
//-----------------------------------------------------------------------------
// Purpose:
// Output : float
//-----------------------------------------------------------------------------
float CMultiPlayerAnimState::GetInterpolatedGroundSpeed( void )
{
return m_flMaxGroundSpeed;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pStudioHdr -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ComputeSequences( CStudioHdr *pStudioHdr )
{
VPROF( "CBasePlayerAnimState::ComputeSequences" );
// Lower body (walk/run/idle).
ComputeMainSequence();
// The groundspeed interpolator uses the main sequence info.
UpdateInterpolators();
ComputeGestureSequence( pStudioHdr );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ComputeMainSequence()
{
VPROF( "CBasePlayerAnimState::ComputeMainSequence" );
CBaseAnimatingOverlay *pPlayer = GetBasePlayer();
// Have our class or the mod-specific class determine what the current activity is.
Activity idealActivity = CalcMainActivity();
#ifdef CLIENT_DLL
Activity oldActivity = m_eCurrentMainSequenceActivity;
#endif
// Store our current activity so the aim and fire layers know what to do.
m_eCurrentMainSequenceActivity = idealActivity;
// Hook to force playback of a specific requested full-body sequence
if ( m_nSpecificMainSequence >= 0 )
{
if ( pPlayer->GetSequence() != m_nSpecificMainSequence )
{
pPlayer->ResetSequence( m_nSpecificMainSequence );
ResetGroundSpeed();
return;
}
if ( !pPlayer->IsSequenceFinished() )
return;
m_nSpecificMainSequence = -1;
RestartMainSequence();
ResetGroundSpeed();
}
// Export to our outer class..
int animDesired = SelectWeightedSequence( TranslateActivity( idealActivity ) );
if ( pPlayer->GetSequenceActivity( pPlayer->GetSequence() ) == pPlayer->GetSequenceActivity( animDesired ) )
return;
if ( animDesired < 0 )
{
animDesired = 0;
}
pPlayer->ResetSequence( animDesired );
#ifdef CLIENT_DLL
// If we went from idle to walk, reset the interpolation history.
// Kind of hacky putting this here.. it might belong outside the base class.
if ( (oldActivity == ACT_MP_CROUCH_IDLE || oldActivity == ACT_MP_STAND_IDLE || oldActivity == ACT_MP_DEPLOYED_IDLE || oldActivity == ACT_MP_CROUCH_DEPLOYED_IDLE ) &&
(idealActivity == ACT_MP_WALK || idealActivity == ACT_MP_CROUCHWALK ) )
{
ResetGroundSpeed();
}
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ResetGroundSpeed( void )
{
#ifdef CLIENT_DLL
m_flMaxGroundSpeed = GetCurrentMaxGroundSpeed();
m_iv_flMaxGroundSpeed.Reset();
m_iv_flMaxGroundSpeed.NoteChanged( gpGlobals->curtime, 0, false );
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::UpdateInterpolators()
{
VPROF( "CBasePlayerAnimState::UpdateInterpolators" );
// First, figure out their current max speed based on their current activity.
float flCurMaxSpeed = GetCurrentMaxGroundSpeed();
#ifdef CLIENT_DLL
float flGroundSpeedInterval = 0.1;
// Only update this 10x/sec so it has an interval to interpolate over.
if ( gpGlobals->curtime - m_flLastGroundSpeedUpdateTime >= flGroundSpeedInterval )
{
m_flLastGroundSpeedUpdateTime = gpGlobals->curtime;
m_flMaxGroundSpeed = flCurMaxSpeed;
m_iv_flMaxGroundSpeed.NoteChanged( gpGlobals->curtime, flGroundSpeedInterval, false );
}
m_iv_flMaxGroundSpeed.Interpolate( gpGlobals->curtime, flGroundSpeedInterval );
#else
m_flMaxGroundSpeed = flCurMaxSpeed;
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ComputeFireSequence( void )
{
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pStudioHdr -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ComputeGestureSequence( CStudioHdr *pStudioHdr )
{
// Update all active gesture layers.
for ( int iGesture = 0; iGesture < GESTURE_SLOT_COUNT; ++iGesture )
{
if ( !m_aGestureSlots[iGesture].m_bActive )
continue;
if ( !VerifyAnimLayerInSlot( iGesture ) )
continue;
UpdateGestureLayer( pStudioHdr, &m_aGestureSlots[iGesture] );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::UpdateGestureLayer( CStudioHdr *pStudioHdr, GestureSlot_t *pGesture )
{
// Sanity check.
if ( !pStudioHdr || !pGesture )
return;
CBasePlayer *pPlayer = GetBasePlayer();
if( !pPlayer )
return;
#ifdef CLIENT_DLL
// Get the current cycle.
float flCycle = pGesture->m_pAnimLayer->m_flCycle;
flCycle += pPlayer->GetSequenceCycleRate( pStudioHdr, pGesture->m_pAnimLayer->m_nSequence ) * gpGlobals->frametime * GetGesturePlaybackRate() * pGesture->m_pAnimLayer->m_flPlaybackRate;
pGesture->m_pAnimLayer->m_flPrevCycle = pGesture->m_pAnimLayer->m_flCycle;
pGesture->m_pAnimLayer->m_flCycle = flCycle;
if( flCycle > 1.0f )
{
RunGestureSlotAnimEventsToCompletion( pGesture );
if ( pGesture->m_bAutoKill )
{
ResetGestureSlot( pGesture->m_iGestureSlot );
return;
}
else
{
pGesture->m_pAnimLayer->m_flCycle = 1.0f;
}
}
#else
if ( pGesture->m_iActivity != ACT_INVALID && pGesture->m_pAnimLayer->m_nActivity == ACT_INVALID )
{
ResetGestureSlot( pGesture->m_iGestureSlot );
}
#endif
}
extern ConVar mp_facefronttime;
extern ConVar mp_feetyawrate;
//-----------------------------------------------------------------------------
// Purpose:
// Input : eyeYaw -
// eyePitch -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::Update( float eyeYaw, float eyePitch )
{
// Profile the animation update.
VPROF( "CMultiPlayerAnimState::Update" );
// Get the studio header for the player.
CStudioHdr *pStudioHdr = GetBasePlayer()->GetModelPtr();
if ( !pStudioHdr )
return;
// Check to see if we should be updating the animation state - dead, ragdolled?
if ( !ShouldUpdateAnimState() )
{
ClearAnimationState();
return;
}
// Store the eye angles.
m_flEyeYaw = AngleNormalize( eyeYaw );
m_flEyePitch = AngleNormalize( eyePitch );
// Compute the player sequences.
ComputeSequences( pStudioHdr );
if ( SetupPoseParameters( pStudioHdr ) )
{
// Pose parameter - what direction are the player's legs running in.
ComputePoseParam_MoveYaw( pStudioHdr );
// Pose parameter - Torso aiming (up/down).
ComputePoseParam_AimPitch( pStudioHdr );
// Pose parameter - Torso aiming (rotation).
ComputePoseParam_AimYaw( pStudioHdr );
}
#ifdef CLIENT_DLL
if ( C_BasePlayer::ShouldDrawLocalPlayer() )
{
GetBasePlayer()->SetPlaybackRate( 1.0f );
}
#endif
if( mp_showgestureslots.GetInt() == GetBasePlayer()->entindex() )
{
DebugGestureInfo();
}
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
// Output : Returns true on success, false on failure.
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::ShouldUpdateAnimState()
{
// Don't update anim state if we're not visible
if ( GetBasePlayer()->IsEffectActive( EF_NODRAW ) )
return false;
// By default, don't update their animation state when they're dead because they're
// either a ragdoll or they're not drawn.
#ifdef CLIENT_DLL
if ( GetBasePlayer()->IsDormant() )
return false;
#endif
return (GetBasePlayer()->IsAlive() || m_bDying);
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CMultiPlayerAnimState::SetupPoseParameters( CStudioHdr *pStudioHdr )
{
// Check to see if this has already been done.
if ( m_bPoseParameterInit )
return true;
// Save off the pose parameter indices.
if ( !pStudioHdr )
return false;
m_bPoseParameterInit = true;
// Look for the movement blenders.
m_PoseParameterData.m_iMoveX = GetBasePlayer()->LookupPoseParameter( pStudioHdr, "move_x" );
m_PoseParameterData.m_iMoveY = GetBasePlayer()->LookupPoseParameter( pStudioHdr, "move_y" );
/*
if ( ( m_PoseParameterData.m_iMoveX < 0 ) || ( m_PoseParameterData.m_iMoveY < 0 ) )
return false;
*/
// Look for the aim pitch blender.
m_PoseParameterData.m_iAimPitch = GetBasePlayer()->LookupPoseParameter( pStudioHdr, "body_pitch" );
/*
if ( m_PoseParameterData.m_iAimPitch < 0 )
return false;
*/
// Look for aim yaw blender.
m_PoseParameterData.m_iAimYaw = GetBasePlayer()->LookupPoseParameter( pStudioHdr, "body_yaw" );
/*
if ( m_PoseParameterData.m_iAimYaw < 0 )
return false;
*/
m_PoseParameterData.m_iMoveYaw = GetBasePlayer()->LookupPoseParameter( pStudioHdr, "move_yaw" );
m_PoseParameterData.m_iMoveScale = GetBasePlayer()->LookupPoseParameter( pStudioHdr, "move_scale" );
/*
if ( ( m_PoseParameterData.m_iMoveYaw < 0 ) || ( m_PoseParameterData.m_iMoveScale < 0 ) )
return false;
*/
return true;
}
float SnapYawTo( float flValue )
{
float flSign = 1.0f;
if ( flValue < 0.0f )
{
flSign = -1.0f;
flValue = -flValue;
}
if ( flValue < 23.0f )
{
flValue = 0.0f;
}
else if ( flValue < 67.0f )
{
flValue = 45.0f;
}
else if ( flValue < 113.0f )
{
flValue = 90.0f;
}
else if ( flValue < 157 )
{
flValue = 135.0f;
}
else
{
flValue = 180.0f;
}
return ( flValue * flSign );
}
//-----------------------------------------------------------------------------
// Purpose: double check that the movement animations actually have movement
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::DoMovementTest( CStudioHdr *pStudioHdr, float flX, float flY )
{
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveX, flX );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveY, flY );
#ifdef STAGING_ONLY
float flTestSpeed = GetBasePlayer()->GetSequenceGroundSpeed( m_nMovementSequence );
if ( flTestSpeed < 10.0f )
{
Warning( "%s : %s (X %.0f Y %.0f) missing movement\n", pStudioHdr->pszName(), GetBasePlayer()->GetSequenceName( m_nMovementSequence ), flX, flY );
}
#endif
/*
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveX, flX );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveY, flY );
float flDuration = GetBasePlayer()->SequenceDuration( m_nMovementSequence );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveX, 1.0f );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveY, 0.0f );
float flForward = GetBasePlayer()->SequenceDuration( m_nMovementSequence );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveX, 0.0f );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveY, 0.0f );
float flCenter = GetBasePlayer()->SequenceDuration( m_nMovementSequence );
if ( flDuration > flForward * 1.1f || flDuration < flForward * 0.9f )
{
Warning( "%s : %s (X %.0f Y %.0f) mismatched duration with forward %.1f vs %.1f\n", pStudioHdr->pszName(), GetBasePlayer()->GetSequenceName( m_nMovementSequence ), flX, flY, flDuration, flForward );
}
if ( flDuration > flCenter * 1.1f || flDuration < flCenter * 0.9f )
{
Warning( "%s : %s (X %.0f Y %.0f) mismatched duration with center %.1f vs %.1f\n", pStudioHdr->pszName(), GetBasePlayer()->GetSequenceName( m_nMovementSequence ), flX, flY, flDuration, flCenter );
}
*/
}
void CMultiPlayerAnimState::DoMovementTest( CStudioHdr *pStudioHdr )
{
if ( m_LegAnimType == LEGANIM_9WAY )
{
DoMovementTest( pStudioHdr, -1.0f, -1.0f );
DoMovementTest( pStudioHdr, -1.0f, 0.0f );
DoMovementTest( pStudioHdr, -1.0f, 1.0f );
DoMovementTest( pStudioHdr, 0.0f, -1.0f );
DoMovementTest( pStudioHdr, 0.0f, 1.0f );
DoMovementTest( pStudioHdr, 1.0f, -1.0f );
DoMovementTest( pStudioHdr, 1.0f, 0.0f );
DoMovementTest( pStudioHdr, 1.0f, 1.0f );
}
}
void CMultiPlayerAnimState::GetMovementFlags( CStudioHdr *pStudioHdr )
{
if ( m_nMovementSequence == GetBasePlayer()->GetSequence() )
{
return;
}
m_nMovementSequence = GetBasePlayer()->GetSequence();
m_LegAnimType = LEGANIM_9WAY;
KeyValues *seqKeyValues = GetBasePlayer()->GetSequenceKeyValues( m_nMovementSequence );
// Msg("sequence %d : %s (%d)\n", sequence, GetOuter()->GetSequenceName( sequence ), seqKeyValues != NULL );
if (seqKeyValues)
{
KeyValues *pkvMovement = seqKeyValues->FindKey( "movement" );
if (pkvMovement)
{
const char *szStyle = pkvMovement->GetString();
if ( V_stricmp( szStyle, "robot2" ) == 0 )
{
m_LegAnimType = LEGANIM_8WAY;
}
}
seqKeyValues->deleteThis();
}
// skip tests if it's not a movement animation
if ( m_nMovementSequence < 0 || !( GetBasePlayer()->GetFlags() & FL_ONGROUND ) || pStudioHdr->pSeqdesc( m_nMovementSequence ).groupsize[0] == 1 )
{
return;
}
DoMovementTest( pStudioHdr );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : *pStudioHdr -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ComputePoseParam_MoveYaw( CStudioHdr *pStudioHdr )
{
// Get the estimated movement yaw.
EstimateYaw();
// Get the view yaw.
float flAngle = AngleNormalize( m_flEyeYaw );
// Calc side to side turning - the view vs. movement yaw.
float flYaw = flAngle - m_PoseParameterData.m_flEstimateYaw;
flYaw = AngleNormalize( -flYaw );
// Get the current speed the character is running.
bool bIsMoving;
float flSpeed = CalcMovementSpeed( &bIsMoving );
// Setup the 9-way blend parameters based on our speed and direction.
Vector2D vecCurrentMoveYaw( 0.0f, 0.0f );
if ( bIsMoving )
{
GetMovementFlags( pStudioHdr );
if ( mp_slammoveyaw.GetBool() )
{
flYaw = SnapYawTo( flYaw );
}
if ( m_LegAnimType == LEGANIM_9WAY )
{
// convert YAW back into vector
vecCurrentMoveYaw.x = cos( DEG2RAD( flYaw ) );
vecCurrentMoveYaw.y = -sin( DEG2RAD( flYaw ) );
// push edges out to -1 to 1 box
float flInvScale = MAX( fabs( vecCurrentMoveYaw.x ), fabs( vecCurrentMoveYaw.y ) );
if ( flInvScale != 0.0f )
{
vecCurrentMoveYaw.x /= flInvScale;
vecCurrentMoveYaw.y /= flInvScale;
}
// find what speed was actually authored
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveX, vecCurrentMoveYaw.x );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveY, vecCurrentMoveYaw.y );
float flMaxSpeed = GetBasePlayer()->GetSequenceGroundSpeed( GetBasePlayer()->GetSequence() );
// scale playback
if ( flMaxSpeed > flSpeed )
{
vecCurrentMoveYaw.x *= flSpeed / flMaxSpeed;
vecCurrentMoveYaw.y *= flSpeed / flMaxSpeed;
}
// Set the 9-way blend movement pose parameters.
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveX, vecCurrentMoveYaw.x );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveY, vecCurrentMoveYaw.y );
}
else
{
// find what speed was actually authored
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveYaw, flYaw );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveScale, 1.0f );
float flMaxSpeed = GetBasePlayer()->GetSequenceGroundSpeed( GetBasePlayer()->GetSequence() );
// scale playback
if ( flMaxSpeed > flSpeed )
{
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveScale, flSpeed / flMaxSpeed );
}
}
}
else
{
// Set the 9-way blend movement pose parameters.
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveX, 0.0f );
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iMoveY, 0.0f );
}
m_DebugAnimData.m_vecMoveYaw = vecCurrentMoveYaw;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::EstimateYaw( void )
{
// Get the frame time.
float flDeltaTime = gpGlobals->frametime;
if ( flDeltaTime == 0.0f )
return;
// Get the player's velocity and angles.
Vector vecEstVelocity;
GetOuterAbsVelocity( vecEstVelocity );
QAngle angles = GetBasePlayer()->GetLocalAngles();
// If we are not moving, sync up the feet and eyes slowly.
if ( vecEstVelocity.x == 0.0f && vecEstVelocity.y == 0.0f )
{
float flYawDelta = angles[YAW] - m_PoseParameterData.m_flEstimateYaw;
flYawDelta = AngleNormalize( flYawDelta );
if ( flDeltaTime < 0.25f )
{
flYawDelta *= ( flDeltaTime * 4.0f );
}
else
{
flYawDelta *= flDeltaTime;
}
m_PoseParameterData.m_flEstimateYaw += flYawDelta;
AngleNormalize( m_PoseParameterData.m_flEstimateYaw );
}
else
{
m_PoseParameterData.m_flEstimateYaw = ( atan2( vecEstVelocity.y, vecEstVelocity.x ) * 180.0f / M_PI );
m_PoseParameterData.m_flEstimateYaw = clamp( m_PoseParameterData.m_flEstimateYaw, -180.0f, 180.0f );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ComputePoseParam_AimPitch( CStudioHdr *pStudioHdr )
{
// Get the view pitch.
float flAimPitch = m_flEyePitch;
// Set the aim pitch pose parameter and save.
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iAimPitch, -flAimPitch );
m_DebugAnimData.m_flAimPitch = flAimPitch;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ComputePoseParam_AimYaw( CStudioHdr *pStudioHdr )
{
// Get the movement velocity.
Vector vecVelocity;
GetOuterAbsVelocity( vecVelocity );
// Check to see if we are moving.
bool bMoving = ( vecVelocity.Length() > 1.0f ) ? true : false;
// If we are moving or are prone and undeployed.
// If you are forcing aim yaw, your code is almost definitely broken if you don't include a delay between
// teleporting and forcing yaw. This is due to an unfortunate interaction between the command lookback window,
// and the fact that m_flEyeYaw is never propogated from the server to the client.
// TODO: Fix this after Halloween 2014.
if ( bMoving || m_bForceAimYaw )
{
// The feet match the eye direction when moving - the move yaw takes care of the rest.
m_flGoalFeetYaw = m_flEyeYaw;
}
// Else if we are not moving.
else
{
// Initialize the feet.
if ( m_PoseParameterData.m_flLastAimTurnTime <= 0.0f )
{
m_flGoalFeetYaw = m_flEyeYaw;
m_flCurrentFeetYaw = m_flEyeYaw;
m_PoseParameterData.m_flLastAimTurnTime = gpGlobals->curtime;
}
// Make sure the feet yaw isn't too far out of sync with the eye yaw.
// TODO: Do something better here!
else
{
float flYawDelta = AngleNormalize( m_flGoalFeetYaw - m_flEyeYaw );
if ( fabs( flYawDelta ) > 45.0f/*m_AnimConfig.m_flMaxBodyYawDegrees*/ )
{
float flSide = ( flYawDelta > 0.0f ) ? -1.0f : 1.0f;
m_flGoalFeetYaw += ( 45.0f/*m_AnimConfig.m_flMaxBodyYawDegrees*/ * flSide );
}
}
}
// Fix up the feet yaw.
m_flGoalFeetYaw = AngleNormalize( m_flGoalFeetYaw );
if ( m_flGoalFeetYaw != m_flCurrentFeetYaw )
{
// If you are forcing aim yaw, your code is almost definitely broken if you don't include a delay between
// teleporting and forcing yaw. This is due to an unfortunate interaction between the command lookback window,
// and the fact that m_flEyeYaw is never propogated from the server to the client.
// TODO: Fix this after Halloween 2014.
if ( m_bForceAimYaw )
{
m_flCurrentFeetYaw = m_flGoalFeetYaw;
}
else
{
ConvergeYawAngles( m_flGoalFeetYaw, /*DOD_BODYYAW_RATE*/720.0f, gpGlobals->frametime, m_flCurrentFeetYaw );
m_flLastAimTurnTime = gpGlobals->curtime;
}
}
// Rotate the body into position.
m_angRender[YAW] = m_flCurrentFeetYaw;
// Find the aim(torso) yaw base on the eye and feet yaws.
float flAimYaw = m_flEyeYaw - m_flCurrentFeetYaw;
flAimYaw = AngleNormalize( flAimYaw );
// Set the aim yaw and save.
GetBasePlayer()->SetPoseParameter( pStudioHdr, m_PoseParameterData.m_iAimYaw, -flAimYaw );
m_DebugAnimData.m_flAimYaw = flAimYaw;
// Turn off a force aim yaw - either we have already updated or we don't need to.
m_bForceAimYaw = false;
#ifndef CLIENT_DLL
QAngle angle = GetBasePlayer()->GetAbsAngles();
angle[YAW] = m_flCurrentFeetYaw;
GetBasePlayer()->SetAbsAngles( angle );
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : flGoalYaw -
// flYawRate -
// flDeltaTime -
// &flCurrentYaw -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::ConvergeYawAngles( float flGoalYaw, float flYawRate, float flDeltaTime, float &flCurrentYaw )
{
#define FADE_TURN_DEGREES 60.0f
// Find the yaw delta.
float flDeltaYaw = flGoalYaw - flCurrentYaw;
float flDeltaYawAbs = fabs( flDeltaYaw );
flDeltaYaw = AngleNormalize( flDeltaYaw );
// Always do at least a bit of the turn (1%).
float flScale = 1.0f;
flScale = flDeltaYawAbs / FADE_TURN_DEGREES;
flScale = clamp( flScale, 0.01f, 1.0f );
float flYaw = flYawRate * flDeltaTime * flScale;
if ( flDeltaYawAbs < flYaw )
{
flCurrentYaw = flGoalYaw;
}
else
{
float flSide = ( flDeltaYaw < 0.0f ) ? -1.0f : 1.0f;
flCurrentYaw += ( flYaw * flSide );
}
flCurrentYaw = AngleNormalize( flCurrentYaw );
#undef FADE_TURN_DEGREES
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
// Output : const QAngle&
//-----------------------------------------------------------------------------
const QAngle& CMultiPlayerAnimState::GetRenderAngles()
{
return m_angRender;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : vel -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::GetOuterAbsVelocity( Vector& vel )
{
#if defined( CLIENT_DLL )
GetBasePlayer()->EstimateAbsVelocity( vel );
#else
vel = GetBasePlayer()->GetAbsVelocity();
#endif
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::Release( void )
{
delete this;
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : -
// Output : float
//-----------------------------------------------------------------------------
float CMultiPlayerAnimState::GetOuterXYSpeed()
{
Vector vel;
GetOuterAbsVelocity( vel );
return vel.Length2D();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void Anim_StateLog( const char *pMsg, ... )
{
// Format the string.
char str[4096];
va_list marker;
va_start( marker, pMsg );
Q_vsnprintf( str, sizeof( str ), pMsg, marker );
va_end( marker );
// Log it?
if ( anim_showstatelog.GetInt() == 1 || anim_showstatelog.GetInt() == 3 )
{
Msg( "%s", str );
}
if ( anim_showstatelog.GetInt() > 1 )
{
// static FileHandle_t hFile = filesystem->Open( "AnimState.log", "wt" );
// filesystem->FPrintf( hFile, "%s", str );
// filesystem->Flush( hFile );
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void Anim_StatePrintf( int iLine, const char *pMsg, ... )
{
// Format the string.
char str[4096];
va_list marker;
va_start( marker, pMsg );
Q_vsnprintf( str, sizeof( str ), pMsg, marker );
va_end( marker );
// Show it with Con_NPrintf.
engine->Con_NPrintf( iLine, "%s", str );
// Log it.
Anim_StateLog( "%s\n", str );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::DebugShowAnimStateForPlayer( bool bIsServer )
{
// Get the player's velocity.
Vector vecVelocity;
GetOuterAbsVelocity( vecVelocity );
// Start animation state logging.
int iLine = 5;
if ( bIsServer )
{
iLine = 12;
}
// Anim_StateLog( "-------------%s: frame %d -----------------\n", bIsServer ? "Server" : "Client", gpGlobals->framecount );
Anim_StatePrintf( iLine++, "-------------%s: frame %d -----------------\n", bIsServer ? "Server" : "Client", gpGlobals->framecount );
// Write out the main sequence and its data.
Anim_StatePrintf( iLine++, "Main: %s, Cycle: %.2f\n", GetSequenceName( GetBasePlayer()->GetModelPtr(), GetBasePlayer()->GetSequence() ), GetBasePlayer()->GetCycle() );
#if 0
if ( m_bPlayingGesture )
{
Anim_StatePrintf( iLine++, "Gesture: %s, Cycle: %.2f\n",
GetSequenceName( GetBasePlayer()->GetModelPtr(), m_iGestureSequence ),
m_flGestureCycle );
}
#endif
// Write out the layers and their data.
for ( int iAnim = 0; iAnim < GetBasePlayer()->GetNumAnimOverlays(); ++iAnim )
{
#ifdef CLIENT_DLL
C_AnimationLayer *pLayer = GetBasePlayer()->GetAnimOverlay( iAnim );
if ( pLayer && ( pLayer->m_nOrder != CBaseAnimatingOverlay::MAX_OVERLAYS ) )
{
Anim_StatePrintf( iLine++, "Layer %s: Weight: %.2f, Cycle: %.2f", GetSequenceName( GetBasePlayer()->GetModelPtr(), pLayer->m_nSequence ), (float)pLayer->m_flWeight, (float)pLayer->m_flCycle );
}
#else
CAnimationLayer *pLayer = GetBasePlayer()->GetAnimOverlay( iAnim );
if ( pLayer && ( pLayer->m_nOrder != CBaseAnimatingOverlay::MAX_OVERLAYS ) )
{
Anim_StatePrintf( iLine++, "Layer %s: Weight: %.2f, Cycle: %.2f", GetSequenceName( GetBasePlayer()->GetModelPtr(), pLayer->m_nSequence ), (float)pLayer->m_flWeight, (float)pLayer->m_flCycle );
}
#endif
}
// Write out the speed data.
Anim_StatePrintf( iLine++, "Time: %.2f, Speed: %.2f, MaxSpeed: %.2f", gpGlobals->curtime, vecVelocity.Length2D(), GetCurrentMaxGroundSpeed() );
// Write out the 9-way blend data.
Anim_StatePrintf( iLine++, "EntityYaw: %.2f, AimYaw: %.2f, AimPitch: %.2f, MoveX: %.2f, MoveY: %.2f", m_angRender[YAW], m_DebugAnimData.m_flAimYaw, m_DebugAnimData.m_flAimPitch, m_DebugAnimData.m_vecMoveYaw.x, m_DebugAnimData.m_vecMoveYaw.y );
// Anim_StateLog( "--------------------------------------------\n\n" );
Anim_StatePrintf( iLine++, "--------------------------------------------\n\n" );
DebugShowEyeYaw();
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::DebugShowEyeYaw( void )
{
#ifdef _NDEBUG
float flBaseSize = 10;
float flHeight = 80;
Vector vecPos = GetOuter()->GetAbsOrigin() + Vector( 0.0f, 0.0f, 3.0f );
QAngle angles( 0.0f, 0.0f, 0.0f );
angles[YAW] = m_flEyeYaw;
Vector vecForward, vecRight, vecUp;
AngleVectors( angles, &vecForward, &vecRight, &vecUp );
// Draw a red triangle on the ground for the eye yaw.
debugoverlay->AddTriangleOverlay( ( vecPos + vecRight * flBaseSize / 2.0f ),
( vecPos - vecRight * flBaseSize / 2.0f ),
( vecPos + vecForward * flHeight, 255, 0, 0, 255, false, 0.01f );
#endif
}
#if defined( CLIENT_DLL )
//-----------------------------------------------------------------------------
// Purpose:
// Input : activity -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::DebugShowActivity( Activity activity )
{
#ifdef _DEBUG
const char *pszActivity = "other";
switch( activity )
{
case ACT_MP_STAND_IDLE:
{
pszActivity = "idle";
break;
}
case ACT_MP_SPRINT:
{
pszActivity = "sprint";
break;
}
case ACT_MP_WALK:
{
pszActivity = "walk";
break;
}
case ACT_MP_RUN:
{
pszActivity = "run";
break;
}
}
Msg( "Activity: %s\n", pszActivity );
#endif
}
#endif
//-----------------------------------------------------------------------------
// Purpose:
// Input : iStartLine -
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::DebugShowAnimState( int iStartLine )
{
Vector vOuterVel;
GetOuterAbsVelocity( vOuterVel );
Anim_StateLog( "----------------- frame %d -----------------\n", gpGlobals->framecount );
int iLine = iStartLine;
Anim_StatePrintf( iLine++, "main: %s, cycle: %.2f\n", GetSequenceName( GetBasePlayer()->GetModelPtr(), GetBasePlayer()->GetSequence() ), GetBasePlayer()->GetCycle() );
#if defined( CLIENT_DLL )
for ( int i=0; i < GetBasePlayer()->GetNumAnimOverlays()-1; i++ )
{
C_AnimationLayer *pLayer = GetBasePlayer()->GetAnimOverlay( i /*i+1?*/ );
Anim_StatePrintf( iLine++, "%s, weight: %.2f, cycle: %.2f, aim (%d)",
pLayer->m_nOrder == CBaseAnimatingOverlay::MAX_OVERLAYS ? "--" : GetSequenceName( GetBasePlayer()->GetModelPtr(), pLayer->m_nSequence ),
pLayer->m_nOrder == CBaseAnimatingOverlay::MAX_OVERLAYS ? -1 :(float)pLayer->m_flWeight,
pLayer->m_nOrder == CBaseAnimatingOverlay::MAX_OVERLAYS ? -1 :(float)pLayer->m_flCycle,
i
);
}
#endif
Anim_StatePrintf( iLine++, "vel: %.2f, time: %.2f, max: %.2f",
vOuterVel.Length2D(), gpGlobals->curtime, GetInterpolatedGroundSpeed() );
// AnimStatePrintf( iLine++, "ent yaw: %.2f, body_yaw: %.2f, body_pitch: %.2f, move_x: %.2f, move_y: %.2f",
// m_angRender[YAW], g_flLastBodyYaw, g_flLastBodyPitch, m_vLastMovePose.x, m_vLastMovePose.y );
Anim_StateLog( "--------------------------------------------\n\n" );
// Draw a red triangle on the ground for the eye yaw.
float flBaseSize = 10;
float flHeight = 80;
Vector vBasePos = GetBasePlayer()->GetAbsOrigin() + Vector( 0, 0, 3 );
QAngle angles( 0, 0, 0 );
angles[YAW] = m_flEyeYaw;
Vector vForward, vRight, vUp;
AngleVectors( angles, &vForward, &vRight, &vUp );
debugoverlay->AddTriangleOverlay( vBasePos+vRight*flBaseSize/2, vBasePos-vRight*flBaseSize/2, vBasePos+vForward*flHeight, 255, 0, 0, 255, false, 0.01 );
// Draw a blue triangle on the ground for the body yaw.
angles[YAW] = m_angRender[YAW];
AngleVectors( angles, &vForward, &vRight, &vUp );
debugoverlay->AddTriangleOverlay( vBasePos+vRight*flBaseSize/2, vBasePos-vRight*flBaseSize/2, vBasePos+vForward*flHeight, 0, 0, 255, 255, false, 0.01 );
}
// Debug!
const char *s_aGestureSlotNames[GESTURE_SLOT_COUNT] =
{
"Attack and Reload",
"Grenade",
"Jump",
"Swim",
"Flinch",
"VCD",
"Custom"
};
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::DebugGestureInfo( void )
{
CBasePlayer *pPlayer = GetBasePlayer();
if ( !pPlayer )
return;
int iLine = ( pPlayer->IsServer() ? 12 : ( 14 + GESTURE_SLOT_COUNT ) );
Anim_StatePrintf( iLine++, "%s\n", ( pPlayer->IsServer() ? "Server" : "Client" ) );
for ( int iGesture = 0; iGesture < GESTURE_SLOT_COUNT; ++iGesture )
{
GestureSlot_t *pGesture = &m_aGestureSlots[iGesture];
if ( pGesture )
{
if( pGesture->m_bActive )
{
Anim_StatePrintf( iLine++, "Gesture Slot %d(%s): %s %s(A:%s, C:%f P:%f)\n",
iGesture,
s_aGestureSlotNames[iGesture],
ActivityList_NameForIndex( pGesture->m_iActivity ),
GetSequenceName( pPlayer->GetModelPtr(), pGesture->m_pAnimLayer->m_nSequence ),
( pGesture->m_bAutoKill ? "true" : "false" ),
(float)pGesture->m_pAnimLayer->m_flCycle, (float)pGesture->m_pAnimLayer->m_flPlaybackRate );
}
else
{
Anim_StatePrintf( iLine++, "Gesture Slot %d(%s): NOT ACTIVE!\n", iGesture, s_aGestureSlotNames[iGesture] );
}
}
}
}
//-----------------------------------------------------------------------------
// Purpose: New Model, init the pose parameters
//-----------------------------------------------------------------------------
void CMultiPlayerAnimState::OnNewModel( void )
{
m_bPoseParameterInit = false;
m_PoseParameterData.Init();
ClearAnimationState();
}
|