-
Notifications
You must be signed in to change notification settings - Fork 655
Expand file tree
/
Copy pathcl_cgameapi.cpp
More file actions
1939 lines (1529 loc) · 61.3 KB
/
cl_cgameapi.cpp
File metadata and controls
1939 lines (1529 loc) · 61.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
===========================================================================
Copyright (C) 2013 - 2015, OpenJK contributors
This file is part of the OpenJK source code.
OpenJK is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, see <http://www.gnu.org/licenses/>.
===========================================================================
*/
// cl_cgameapi.cpp -- client system interaction with client game
#include "qcommon/cm_public.h"
#include "qcommon/RoffSystem.h"
#include "qcommon/stringed_ingame.h"
#include "qcommon/timing.h"
#include "client.h"
#include "cl_uiapi.h"
#include "botlib/botlib.h"
#include "snd_ambient.h"
#include "FXExport.h"
#include "FxUtil.h"
extern IHeapAllocator *G2VertSpaceClient;
extern botlib_export_t *botlib_export;
// cgame interface
static cgameExport_t *cge; // cgame export table
static vm_t *cgvm; // cgame vm, valid for legacy and new api
//
// cgame vmMain calls
//
void CGVM_Init( int serverMessageNum, int serverCommandSequence, int clientNum ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_INIT, serverMessageNum, serverCommandSequence, clientNum );
return;
}
VMSwap v( cgvm );
cge->Init( serverMessageNum, serverCommandSequence, clientNum );
}
void CGVM_Shutdown( void ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_SHUTDOWN );
return;
}
VMSwap v( cgvm );
cge->Shutdown();
}
qboolean CGVM_ConsoleCommand( void ) {
if ( cgvm->isLegacy ) {
return (qboolean)VM_Call( cgvm, CG_CONSOLE_COMMAND );
}
VMSwap v( cgvm );
return cge->ConsoleCommand();
}
void CGVM_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demoPlayback ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_DRAW_ACTIVE_FRAME, serverTime, stereoView, demoPlayback );
return;
}
VMSwap v( cgvm );
cge->DrawActiveFrame( serverTime, stereoView, demoPlayback );
}
int CGVM_CrosshairPlayer( void ) {
if ( cgvm->isLegacy ) {
return VM_Call( cgvm, CG_CROSSHAIR_PLAYER );
}
VMSwap v( cgvm );
return cge->CrosshairPlayer();
}
int CGVM_LastAttacker( void ) {
if ( cgvm->isLegacy ) {
return VM_Call( cgvm, CG_LAST_ATTACKER );
}
VMSwap v( cgvm );
return cge->LastAttacker();
}
void CGVM_KeyEvent( int key, qboolean down ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_KEY_EVENT, key, down );
return;
}
VMSwap v( cgvm );
cge->KeyEvent( key, down );
}
void CGVM_MouseEvent( int x, int y ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_MOUSE_EVENT, x, y );
return;
}
VMSwap v( cgvm );
cge->MouseEvent( x, y );
}
void CGVM_EventHandling( int type ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_EVENT_HANDLING, type );
return;
}
VMSwap v( cgvm );
cge->EventHandling( type );
}
int CGVM_PointContents( void ) {
if ( cgvm->isLegacy ) {
return VM_Call( cgvm, CG_POINT_CONTENTS );
}
VMSwap v( cgvm );
return cge->PointContents();
}
void CGVM_GetLerpOrigin( void ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_GET_LERP_ORIGIN );
return;
}
VMSwap v( cgvm );
cge->GetLerpOrigin();
}
void CGVM_GetLerpData( void ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_GET_LERP_DATA );
return;
}
VMSwap v( cgvm );
cge->GetLerpData();
}
void CGVM_Trace( void ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_TRACE );
return;
}
VMSwap v( cgvm );
cge->Trace();
}
void CGVM_G2Trace( void ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_G2TRACE );
return;
}
VMSwap v( cgvm );
cge->G2Trace();
}
void CGVM_G2Mark( void ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_G2MARK );
return;
}
VMSwap v( cgvm );
cge->G2Mark();
}
int CGVM_RagCallback( int callType ) {
if ( cgvm->isLegacy ) {
return VM_Call( cgvm, CG_RAG_CALLBACK, callType );
}
VMSwap v( cgvm );
return cge->RagCallback( callType );
}
qboolean CGVM_IncomingConsoleCommand( void ) {
if ( cgvm->isLegacy ) {
return (qboolean)VM_Call( cgvm, CG_INCOMING_CONSOLE_COMMAND );
}
VMSwap v( cgvm );
return cge->IncomingConsoleCommand();
}
qboolean CGVM_NoUseableForce( void ) {
if ( cgvm->isLegacy ) {
return (qboolean)VM_Call( cgvm, CG_GET_USEABLE_FORCE );
}
VMSwap v( cgvm );
return cge->NoUseableForce();
}
void CGVM_GetOrigin( int entID, vec3_t out ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_GET_ORIGIN, entID, reinterpret_cast< intptr_t >( out ) );
return;
}
VMSwap v( cgvm );
cge->GetOrigin( entID, out );
}
void CGVM_GetAngles( int entID, vec3_t out ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_GET_ANGLES, entID, reinterpret_cast< intptr_t >( out ) );
return;
}
VMSwap v( cgvm );
cge->GetAngles( entID, out );
}
trajectory_t *CGVM_GetOriginTrajectory( int entID ) {
if ( cgvm->isLegacy ) {
return (trajectory_t *)VM_Call( cgvm, CG_GET_ORIGIN_TRAJECTORY, entID );
}
VMSwap v( cgvm );
return cge->GetOriginTrajectory( entID );
}
trajectory_t *CGVM_GetAngleTrajectory( int entID ) {
if ( cgvm->isLegacy ) {
return (trajectory_t *)VM_Call( cgvm, CG_GET_ANGLE_TRAJECTORY, entID );
}
VMSwap v( cgvm );
return cge->GetAngleTrajectory( entID );
}
void CGVM_ROFF_NotetrackCallback( int entID, const char *notetrack ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_ROFF_NOTETRACK_CALLBACK, entID, reinterpret_cast< intptr_t >( notetrack ) );
return;
}
VMSwap v( cgvm );
cge->ROFF_NotetrackCallback( entID, notetrack );
}
void CGVM_MapChange( void ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_MAP_CHANGE );
return;
}
VMSwap v( cgvm );
cge->MapChange();
}
void CGVM_AutomapInput( void ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_AUTOMAP_INPUT );
return;
}
VMSwap v( cgvm );
cge->AutomapInput();
}
void CGVM_MiscEnt( void ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_MISC_ENT );
return;
}
VMSwap v( cgvm );
cge->MiscEnt();
}
void CGVM_CameraShake( void ) {
if ( cgvm->isLegacy ) {
VM_Call( cgvm, CG_FX_CAMERASHAKE );
return;
}
VMSwap v( cgvm );
cge->CameraShake();
}
//
// cgame syscalls
// only used by legacy mods!
//
extern int CL_GetValueForHidden( const char *s ); //cl_parse.cpp
extern qboolean cl_bUseFighterPitch; //cl_input.cpp
int CM_LoadSubBSP( const char *name, qboolean clientload ); //cm_load.cpp
void FX_FeedTrail( effectTrailArgStruct_t *a ); //FxPrimitives.cpp
// wrappers and such
static void CL_AddCgameCommand( const char *cmdName ) {
Cmd_AddCommand( cmdName, NULL );
}
static void CL_CM_LoadMap( const char *mapname, qboolean subBSP ) {
if ( subBSP ) CM_LoadSubBSP( va( "maps/%s.bsp", mapname+1 ), qfalse );
else CM_LoadMap( mapname, qtrue, NULL );
}
static void CL_GetGlconfig( glconfig_t *glconfig ) {
*glconfig = cls.glconfig;
}
static void CL_GetGameState( gameState_t *gs ) {
*gs = cl.gameState;
}
static void RegisterSharedMemory( char *memory ) {
cl.mSharedMemory = memory;
}
static int CL_Milliseconds( void ) {
return Sys_Milliseconds();
}
static void CL_AddReliableCommand2( const char *cmd ) {
CL_AddReliableCommand( cmd, qfalse );
}
static int CL_CM_RegisterTerrain( const char *config ) {
return 0;
}
extern int s_entityWavVol[MAX_GENTITIES];
static int CL_S_GetVoiceVolume( int entID ) {
return s_entityWavVol[entID];
}
static void CL_S_Shutup( qboolean shutup ) {
s_shutUp = shutup;
}
static int CL_GetCurrentCmdNumber( void ) {
return cl.cmdNumber;
}
static void _CL_SetUserCmdValue( int stateValue, float sensitivityScale, float mPitchOverride, float mYawOverride, float mSensitivityOverride, int fpSel, int invenSel, qboolean fighterControls ) {
cl_bUseFighterPitch = fighterControls;
CL_SetUserCmdValue( stateValue, sensitivityScale, mPitchOverride, mYawOverride, mSensitivityOverride, fpSel, invenSel );
}
static void CL_OpenUIMenu( int menuID ) {
UIVM_SetActiveMenu( (uiMenuCommand_t)menuID );
}
static void CGFX_AddLine( vec3_t start, vec3_t end, float size1, float size2, float sizeParm, float alpha1, float alpha2, float alphaParm, vec3_t sRGB, vec3_t eRGB, float rgbParm, int killTime, qhandle_t shader, int flags ) {
FX_AddLine( start, end, size1, size2, sizeParm, alpha1, alpha2, alphaParm, sRGB, eRGB, rgbParm, killTime, shader, flags );
}
static void CGFX_AddPoly( addpolyArgStruct_t *p ) {
FX_AddPoly( p->p, p->ev, p->numVerts, p->vel, p->accel, p->alpha1, p->alpha2, p->alphaParm, p->rgb1, p->rgb2, p->rgbParm, p->rotationDelta, p->bounce, p->motionDelay, p->killTime, p->shader, p->flags );
}
static void CGFX_AddBezier( addbezierArgStruct_t *b ) {
FX_AddBezier( b->start, b->end, b->control1, b->control1Vel, b->control2, b->control2Vel, b->size1, b->size2, b->sizeParm, b->alpha1, b->alpha2, b->alphaParm, b->sRGB, b->eRGB, b->rgbParm, b->killTime, b->shader, b->flags );
}
static void CGFX_AddPrimitive( effectTrailArgStruct_t *e ) {
FX_FeedTrail( e );
}
static void CGFX_AddSprite( addspriteArgStruct_t *s ) {
vec3_t rgb = { 1.0f, 1.0f, 1.0f };
FX_AddParticle( s->origin, s->vel, s->accel, s->scale, s->dscale, 0, s->sAlpha, s->eAlpha, 0, rgb, rgb, 0, s->rotation, 0, vec3_origin, vec3_origin, s->bounce, 0, 0, s->life, s->shader, s->flags );
}
static void CGFX_AddElectricity( addElectricityArgStruct_t *p ) {
FX_AddElectricity( p->start, p->end, p->size1, p->size2, p->sizeParm, p->alpha1, p->alpha2, p->alphaParm, p->sRGB, p->eRGB, p->rgbParm, p->chaos, p->killTime, p->shader, p->flags );
}
static qboolean CL_ROFF_Clean( void ) {
return theROFFSystem.Clean( qtrue );
}
static void CL_ROFF_UpdateEntities( void ) {
theROFFSystem.UpdateEntities( qtrue );
}
static int CL_ROFF_Cache( char *file ) {
return theROFFSystem.Cache( file, qtrue );
}
static qboolean CL_ROFF_Play( int entID, int roffID, qboolean doTranslation ) {
return theROFFSystem.Play( entID, roffID, doTranslation, qtrue );
}
static qboolean CL_ROFF_Purge_Ent( int entID ) {
return theROFFSystem.PurgeEnt( entID, qtrue );
}
static void CL_GetCurrentSnapshotNumber( int *snapshotNumber, int *serverTime ) {
*snapshotNumber = cl.snap.messageNum;
*serverTime = cl.snap.serverTime;
}
static void CL_SetClientForceAngle( int time, vec3_t angle ) {
cl.cgameViewAngleForceTime = time;
VectorCopy(angle, cl.cgameViewAngleForce);
}
static void CL_PrecisionTimerStart( void **p ) {
timing_c *newTimer = new timing_c; //create the new timer
*p = newTimer; //assign the pointer within the pointer to point at the mem addr of our new timer
newTimer->Start(); //start the timer
}
static int CL_PrecisionTimerEnd( void *p ) {
int r = 0;
timing_c *timer = (timing_c *)p; //this is the pointer we assigned in start, so we can directly cast it back
r = timer->End(); //get the result
delete timer; //delete the timer since we're done with it
return r; //return the result
}
static void CL_RMG_Init( int /* terrainID */, const char * /* terrainInfo */ ) { }
static qboolean CGFX_PlayBoltedEffectID( int id, vec3_t org, void *ghoul2, const int boltNum, const int entNum, const int modelNum, int iLooptime, qboolean isRelative ) {
if ( !ghoul2 ) return qfalse;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghoul2);
int boltInfo=0;
if ( re->G2API_AttachEnt( &boltInfo, g2, modelNum, boltNum, entNum, modelNum ) )
{
FX_PlayBoltedEffectID(id, org, boltInfo, &g2, iLooptime, isRelative );
return qtrue;
}
return qfalse;
}
static qboolean CL_SE_GetStringTextString( const char *text, char *buffer, int bufferLength ) {
const char *str;
assert( text && buffer );
str = SE_GetString( text );
if ( str[0] ) {
Q_strncpyz( buffer, str, bufferLength );
return qtrue;
}
Com_sprintf( buffer, bufferLength, "??%s", str );
return qfalse;
}
static void CL_G2API_ListModelSurfaces( void *ghlInfo ) {
re->G2API_ListSurfaces( (CGhoul2Info *)ghlInfo );
}
static void CL_G2API_ListModelBones( void *ghlInfo, int frame ) {
re->G2API_ListBones( (CGhoul2Info *)ghlInfo, frame );
}
static void CL_G2API_SetGhoul2ModelIndexes( void *ghoul2, qhandle_t *modelList, qhandle_t *skinList ) {
if ( !ghoul2 ) return;
re->G2API_SetGhoul2ModelIndexes( *((CGhoul2Info_v *)ghoul2), modelList, skinList );
}
static qboolean CL_G2API_HaveWeGhoul2Models( void *ghoul2) {
if ( !ghoul2 ) return qfalse;
return re->G2API_HaveWeGhoul2Models( *((CGhoul2Info_v *)ghoul2) );
}
static qboolean CL_G2API_GetBoltMatrix( void *ghoul2, const int modelIndex, const int boltIndex, mdxaBone_t *matrix, const vec3_t angles, const vec3_t position, const int frameNum, qhandle_t *modelList, vec3_t scale ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_GetBoltMatrix( *((CGhoul2Info_v *)ghoul2), modelIndex, boltIndex, matrix, angles, position, frameNum, modelList, scale );
}
static qboolean CL_G2API_GetBoltMatrix_NoReconstruct( void *ghoul2, const int modelIndex, const int boltIndex, mdxaBone_t *matrix, const vec3_t angles, const vec3_t position, const int frameNum, qhandle_t *modelList, vec3_t scale ) {
if ( !ghoul2 ) return qfalse;
re->G2API_BoltMatrixReconstruction( qfalse );
return re->G2API_GetBoltMatrix( *((CGhoul2Info_v *)ghoul2), modelIndex, boltIndex, matrix, angles, position, frameNum, modelList, scale );
}
static qboolean CL_G2API_GetBoltMatrix_NoRecNoRot( void *ghoul2, const int modelIndex, const int boltIndex, mdxaBone_t *matrix, const vec3_t angles, const vec3_t position, const int frameNum, qhandle_t *modelList, vec3_t scale ) {
if ( !ghoul2 ) return qfalse;
// Intentionally not setting bolt matrix reconstruction state per original code comments
re->G2API_BoltMatrixSPMethod( qtrue );
return re->G2API_GetBoltMatrix( *((CGhoul2Info_v *)ghoul2), modelIndex, boltIndex, matrix, angles, position, frameNum, modelList, scale );
}
static int CL_G2API_InitGhoul2Model( void **ghoul2Ptr, const char *fileName, int modelIndex, qhandle_t customSkin, qhandle_t customShader, int modelFlags, int lodBias ) {
#ifdef _FULL_G2_LEAK_CHECKING
g_G2AllocServer = 0;
#endif
return re->G2API_InitGhoul2Model( (CGhoul2Info_v **)ghoul2Ptr, fileName, modelIndex, customSkin, customShader, modelFlags, lodBias );
}
static qboolean CL_G2API_SetSkin( void *ghoul2, int modelIndex, qhandle_t customSkin, qhandle_t renderSkin ) {
if ( !ghoul2 ) return qfalse;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghoul2);
return re->G2API_SetSkin( g2, modelIndex, customSkin, renderSkin );
}
static void CL_G2API_CollisionDetect( CollisionRecord_t *collRecMap, void* ghoul2, const vec3_t angles, const vec3_t position, int frameNumber, int entNum, vec3_t rayStart, vec3_t rayEnd, vec3_t scale, int traceFlags, int useLod, float fRadius ) {
if ( !ghoul2 ) return;
re->G2API_CollisionDetect( collRecMap, *((CGhoul2Info_v *)ghoul2), angles, position, frameNumber, entNum, rayStart, rayEnd, scale, G2VertSpaceClient, traceFlags, useLod, fRadius );
}
static void CL_G2API_CollisionDetectCache( CollisionRecord_t *collRecMap, void* ghoul2, const vec3_t angles, const vec3_t position, int frameNumber, int entNum, vec3_t rayStart, vec3_t rayEnd, vec3_t scale, int traceFlags, int useLod, float fRadius ) {
if ( !ghoul2 ) return;
re->G2API_CollisionDetectCache( collRecMap, *((CGhoul2Info_v *)ghoul2), angles, position, frameNumber, entNum, rayStart, rayEnd, scale, G2VertSpaceClient, traceFlags, useLod, fRadius );
}
static void CL_G2API_CleanGhoul2Models( void **ghoul2Ptr ) {
#ifdef _FULL_G2_LEAK_CHECKING
g_G2AllocServer = 0;
#endif
re->G2API_CleanGhoul2Models( (CGhoul2Info_v **)ghoul2Ptr );
}
static qboolean CL_G2API_SetBoneAngles( void *ghoul2, int modelIndex, const char *boneName, const vec3_t angles, const int flags, const int up, const int right, const int forward, qhandle_t *modelList, int blendTime , int currentTime ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_SetBoneAngles( *((CGhoul2Info_v *)ghoul2), modelIndex, boneName, angles, flags, (const Eorientations)up, (const Eorientations)right, (const Eorientations)forward, modelList, blendTime , currentTime );
}
static qboolean CL_G2API_SetBoneAnim( void *ghoul2, const int modelIndex, const char *boneName, const int startFrame, const int endFrame, const int flags, const float animSpeed, const int currentTime, const float setFrame, const int blendTime ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_SetBoneAnim( *((CGhoul2Info_v *)ghoul2), modelIndex, boneName, startFrame, endFrame, flags, animSpeed, currentTime, setFrame, blendTime );
}
static qboolean CL_G2API_GetBoneAnim( void *ghoul2, const char *boneName, const int currentTime, float *currentFrame, int *startFrame, int *endFrame, int *flags, float *animSpeed, int *modelList, const int modelIndex ) {
if ( !ghoul2 ) return qfalse;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghoul2);
return re->G2API_GetBoneAnim( g2, modelIndex, boneName, currentTime, currentFrame, startFrame, endFrame, flags, animSpeed, modelList );
}
static qboolean CL_G2API_GetBoneFrame( void *ghoul2, const char *boneName, const int currentTime, float *currentFrame, int *modelList, const int modelIndex ) {
if ( !ghoul2 ) return qfalse;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghoul2);
int iDontCare1 = 0, iDontCare2 = 0, iDontCare3 = 0;
float fDontCare1 = 0;
return re->G2API_GetBoneAnim(g2, modelIndex, boneName, currentTime, currentFrame, &iDontCare1, &iDontCare2, &iDontCare3, &fDontCare1, modelList);
}
static void CL_G2API_GetGLAName( void *ghoul2, int modelIndex, char *fillBuf ) {
if ( !ghoul2 )
{
fillBuf[0] = '\0';
return;
}
char *tmp = re->G2API_GetGLAName( *((CGhoul2Info_v *)ghoul2), modelIndex );
if ( tmp )
strcpy( fillBuf, tmp );
else
fillBuf[0] = '\0';
}
static int CL_G2API_CopyGhoul2Instance( void *g2From, void *g2To, int modelIndex ) {
if ( !g2From || !g2To ) return 0;
return re->G2API_CopyGhoul2Instance( *((CGhoul2Info_v *)g2From), *((CGhoul2Info_v *)g2To), modelIndex );
}
static void CL_G2API_CopySpecificGhoul2Model( void *g2From, int modelFrom, void *g2To, int modelTo ) {
if ( !g2From || !g2To) return;
re->G2API_CopySpecificG2Model( *((CGhoul2Info_v *)g2From), modelFrom, *((CGhoul2Info_v *)g2To), modelTo );
}
static void CL_G2API_DuplicateGhoul2Instance( void *g2From, void **g2To ) {
#ifdef _FULL_G2_LEAK_CHECKING
g_G2AllocServer = 0;
#endif
if ( !g2From || !g2To ) return;
re->G2API_DuplicateGhoul2Instance( *((CGhoul2Info_v *)g2From), (CGhoul2Info_v **)g2To );
}
static qboolean CL_G2API_HasGhoul2ModelOnIndex( void *ghlInfo, int modelIndex ) {
return re->G2API_HasGhoul2ModelOnIndex( (CGhoul2Info_v **)ghlInfo, modelIndex );
}
static qboolean CL_G2API_RemoveGhoul2Model( void *ghlInfo, int modelIndex ) {
#ifdef _FULL_G2_LEAK_CHECKING
g_G2AllocServer = 0;
#endif
return re->G2API_RemoveGhoul2Model( (CGhoul2Info_v **)ghlInfo, modelIndex );
}
static qboolean CL_G2API_SkinlessModel( void *ghlInfo, int modelIndex ) {
if ( !ghlInfo ) return qfalse;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghlInfo);
return re->G2API_SkinlessModel( g2, modelIndex );
}
static int CL_G2API_GetNumGoreMarks( void *ghlInfo, int modelIndex ) {
#ifdef _G2_GORE
if ( !ghlInfo ) return 0;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghlInfo);
return re->G2API_GetNumGoreMarks( g2, modelIndex );
#else
return 0;
#endif
}
static void CL_G2API_AddSkinGore( void *ghlInfo, SSkinGoreData *gore ) {
#ifdef _G2_GORE
if ( !ghlInfo ) return;
re->G2API_AddSkinGore( *((CGhoul2Info_v *)ghlInfo), *(SSkinGoreData *)gore );
#endif
}
static void CL_G2API_ClearSkinGore( void *ghlInfo ) {
#ifdef _G2_GORE
if ( !ghlInfo ) return;
re->G2API_ClearSkinGore( *((CGhoul2Info_v *)ghlInfo) );
#endif
}
static int CL_G2API_Ghoul2Size( void *ghlInfo ) {
if ( !ghlInfo ) return 0;
return re->G2API_Ghoul2Size( *((CGhoul2Info_v *)ghlInfo) );
}
static int CL_G2API_AddBolt( void *ghoul2, int modelIndex, const char *boneName ) {
if ( !ghoul2 ) return -1;
return re->G2API_AddBolt( *((CGhoul2Info_v *)ghoul2), modelIndex, boneName );
}
static qboolean CL_G2API_AttachEnt( int *boltInfo, void *ghlInfoTo, int toBoltIndex, int entNum, int toModelNum ) {
if ( !ghlInfoTo ) return qfalse;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghlInfoTo);
return re->G2API_AttachEnt( boltInfo, g2, 0, toBoltIndex, entNum, toModelNum );
}
static void CL_G2API_SetBoltInfo( void *ghoul2, int modelIndex, int boltInfo ) {
if ( !ghoul2 ) return;
re->G2API_SetBoltInfo( *((CGhoul2Info_v *)ghoul2), modelIndex, boltInfo );
}
static qboolean CL_G2API_SetRootSurface( void *ghoul2, const int modelIndex, const char *surfaceName ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_SetRootSurface( *((CGhoul2Info_v *)ghoul2), modelIndex, surfaceName );
}
static qboolean CL_G2API_SetSurfaceOnOff( void *ghoul2, const char *surfaceName, const int flags ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_SetSurfaceOnOff( *((CGhoul2Info_v *)ghoul2), surfaceName, flags );
}
static qboolean CL_G2API_SetNewOrigin( void *ghoul2, const int boltIndex ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_SetNewOrigin( *((CGhoul2Info_v *)ghoul2), boltIndex );
}
static qboolean CL_G2API_DoesBoneExist( void *ghoul2, int modelIndex, const char *boneName ) {
if ( !ghoul2 ) return qfalse;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghoul2);
return re->G2API_DoesBoneExist( g2, modelIndex, boneName );
}
static int CL_G2API_GetSurfaceRenderStatus( void *ghoul2, const int modelIndex, const char *surfaceName ) {
if ( !ghoul2 ) return -1;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghoul2);
return re->G2API_GetSurfaceRenderStatus( g2, modelIndex, surfaceName );
}
static int CL_G2API_GetTime( void ) {
return re->G2API_GetTime( 0 );
}
static void CL_G2API_SetTime( int time, int clock ) {
re->G2API_SetTime( time, clock );
}
static void CL_G2API_AbsurdSmoothing( void *ghoul2, qboolean status ) {
if ( !ghoul2 ) return;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghoul2);
re->G2API_AbsurdSmoothing( g2, status );
}
static void CL_G2API_SetRagDoll( void *ghoul2, sharedRagDollParams_t *params ) {
if ( !ghoul2 ) return;
CRagDollParams rdParams;
if ( !params ) {
re->G2API_ResetRagDoll( *((CGhoul2Info_v *)ghoul2) );
return;
}
VectorCopy( params->angles, rdParams.angles );
VectorCopy( params->position, rdParams.position );
VectorCopy( params->scale, rdParams.scale );
VectorCopy( params->pelvisAnglesOffset, rdParams.pelvisAnglesOffset );
VectorCopy( params->pelvisPositionOffset, rdParams.pelvisPositionOffset );
rdParams.fImpactStrength = params->fImpactStrength;
rdParams.fShotStrength = params->fShotStrength;
rdParams.me = params->me;
rdParams.startFrame = params->startFrame;
rdParams.endFrame = params->endFrame;
rdParams.collisionType = params->collisionType;
rdParams.CallRagDollBegin = params->CallRagDollBegin;
rdParams.RagPhase = (CRagDollParams::ERagPhase)params->RagPhase;
rdParams.effectorsToTurnOff = (CRagDollParams::ERagEffector)params->effectorsToTurnOff;
re->G2API_SetRagDoll( *((CGhoul2Info_v *)ghoul2), &rdParams );
}
static void CL_G2API_AnimateG2Models( void *ghoul2, int time, sharedRagDollUpdateParams_t *params ) {
if ( !ghoul2 ) return;
if ( !params ) return;
CRagDollUpdateParams rduParams;
VectorCopy( params->angles, rduParams.angles );
VectorCopy( params->position, rduParams.position );
VectorCopy( params->scale, rduParams.scale );
VectorCopy( params->velocity, rduParams.velocity );
rduParams.me = params->me;
rduParams.settleFrame = params->settleFrame;
re->G2API_AnimateG2ModelsRag( *((CGhoul2Info_v *)ghoul2), time, &rduParams );
}
static qboolean CL_G2API_RagPCJConstraint( void *ghoul2, const char *boneName, vec3_t min, vec3_t max ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_RagPCJConstraint( *((CGhoul2Info_v *)ghoul2), boneName, min, max );
}
static qboolean CL_G2API_RagPCJGradientSpeed( void *ghoul2, const char *boneName, const float speed ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_RagPCJGradientSpeed( *((CGhoul2Info_v *)ghoul2), boneName, speed );
}
static qboolean CL_G2API_RagEffectorGoal( void *ghoul2, const char *boneName, vec3_t pos ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_RagEffectorGoal( *((CGhoul2Info_v *)ghoul2), boneName, pos );
}
static qboolean CL_G2API_GetRagBonePos( void *ghoul2, const char *boneName, vec3_t pos, vec3_t entAngles, vec3_t entPos, vec3_t entScale ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_GetRagBonePos( *((CGhoul2Info_v *)ghoul2), boneName, pos, entAngles, entPos, entScale );
}
static qboolean CL_G2API_RagEffectorKick( void *ghoul2, const char *boneName, vec3_t velocity ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_RagEffectorKick( *((CGhoul2Info_v *)ghoul2), boneName, velocity );
}
static qboolean CL_G2API_RagForceSolve( void *ghoul2, qboolean force ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_RagForceSolve( *((CGhoul2Info_v *)ghoul2), force );
}
static qboolean CL_G2API_SetBoneIKState( void *ghoul2, int time, const char *boneName, int ikState, sharedSetBoneIKStateParams_t *params ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_SetBoneIKState( *((CGhoul2Info_v *)ghoul2), time, boneName, ikState, params );
}
static qboolean CL_G2API_IKMove( void *ghoul2, int time, sharedIKMoveParams_t *params ) {
if ( !ghoul2 ) return qfalse;
return re->G2API_IKMove( *((CGhoul2Info_v *)ghoul2), time, params );
}
static qboolean CL_G2API_RemoveBone( void *ghoul2, const char *boneName, int modelIndex ) {
if ( !ghoul2 ) return qfalse;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghoul2);
return re->G2API_RemoveBone( g2, modelIndex, boneName );
}
static void CL_G2API_AttachInstanceToEntNum( void *ghoul2, int entityNum, qboolean server ) {
if ( !ghoul2 ) return;
re->G2API_AttachInstanceToEntNum( *((CGhoul2Info_v *)ghoul2), entityNum, server );
}
static void CL_G2API_ClearAttachedInstance( int entityNum ) {
re->G2API_ClearAttachedInstance( entityNum );
}
static void CL_G2API_CleanEntAttachments( void ) {
re->G2API_CleanEntAttachments();
}
static qboolean CL_G2API_OverrideServer( void *serverInstance ) {
if ( !serverInstance ) return qfalse;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)serverInstance);
return re->G2API_OverrideServerWithClientData( g2, 0 );
}
static void CL_G2API_GetSurfaceName( void *ghoul2, int surfNumber, int modelIndex, char *fillBuf ) {
if ( !ghoul2 ) return;
CGhoul2Info_v &g2 = *((CGhoul2Info_v *)ghoul2);
char *tmp = re->G2API_GetSurfaceName( g2, modelIndex, surfNumber );
strcpy( fillBuf, tmp );
}
static void CL_Key_SetCatcher( int catcher ) {
// Don't allow the cgame module to close the console
Key_SetCatcher( catcher | ( Key_GetCatcher( ) & KEYCATCH_CONSOLE ) );
}
static void CGVM_Cvar_Set( const char *var_name, const char *value ) {
Cvar_VM_Set( var_name, value, VM_CGAME );
}
static void CGVM_Cmd_RemoveCommand( const char *cmd_name ) {
Cmd_VM_RemoveCommand( cmd_name, VM_CGAME );
}
// legacy syscall
intptr_t CL_CgameSystemCalls( intptr_t *args ) {
switch ( args[0] ) {
//rww - alright, DO NOT EVER add a GAME/CGAME/UI generic call without adding a trap to match, and
//all of these traps must be shared and have cases in sv_game, cl_cgame, and cl_ui. They must also
//all be in the same order, and start at 100.
case TRAP_MEMSET:
Com_Memset( VMA(1), args[2], args[3] );
return 0;
case TRAP_MEMCPY:
Com_Memcpy( VMA(1), VMA(2), args[3] );
return 0;
case TRAP_STRNCPY:
strncpy( (char *)VMA(1), (const char *)VMA(2), args[3] );
return args[1];
case TRAP_SIN:
return FloatAsInt( sin( VMF(1) ) );
case TRAP_COS:
return FloatAsInt( cos( VMF(1) ) );
case TRAP_ATAN2:
return FloatAsInt( atan2( VMF(1), VMF(2) ) );
case TRAP_SQRT:
return FloatAsInt( sqrt( VMF(1) ) );
case TRAP_MATRIXMULTIPLY:
MatrixMultiply( (vec3_t *)VMA(1), (vec3_t *)VMA(2), (vec3_t *)VMA(3) );
return 0;
case TRAP_ANGLEVECTORS:
AngleVectors( (const float *)VMA(1), (float *)VMA(2), (float *)VMA(3), (float *)VMA(4) );
return 0;
case TRAP_PERPENDICULARVECTOR:
PerpendicularVector( (float *)VMA(1), (const float *)VMA(2) );
return 0;
case TRAP_FLOOR:
return FloatAsInt( floor( VMF(1) ) );
case TRAP_CEIL:
return FloatAsInt( ceil( VMF(1) ) );
case TRAP_TESTPRINTINT:
return 0;
case TRAP_TESTPRINTFLOAT:
return 0;
case TRAP_ACOS:
return FloatAsInt( Q_acos( VMF(1) ) );
case TRAP_ASIN:
return FloatAsInt( Q_asin( VMF(1) ) );
case CG_PRINT:
Com_Printf( "%s", (const char*)VMA(1) );
return 0;
case CG_ERROR:
Com_Error( ERR_DROP, "%s", (const char*)VMA(1) );
return 0;
case CG_MILLISECONDS:
return CL_Milliseconds();
//rww - precision timer funcs... -ALWAYS- call end after start with supplied ptr, or you'll get a nasty memory leak.
//not that you should be using these outside of debug anyway.. because you shouldn't be. So don't.
case CG_PRECISIONTIMER_START:
CL_PrecisionTimerStart( (void **)VMA(1) );
return 0;
case CG_PRECISIONTIMER_END:
return CL_PrecisionTimerEnd( (void *)args[1] );
case CG_CVAR_REGISTER:
Cvar_Register( (vmCvar_t *)VMA(1), (const char *)VMA(2), (const char *)VMA(3), args[4] );
return 0;
case CG_CVAR_UPDATE:
Cvar_Update( (vmCvar_t *)VMA(1) );
return 0;
case CG_CVAR_SET:
Cvar_VM_Set( (const char *)VMA(1), (const char *)VMA(2), VM_CGAME );
return 0;
case CG_CVAR_VARIABLESTRINGBUFFER:
Cvar_VariableStringBuffer( (const char *)VMA(1), (char *)VMA(2), args[3] );
return 0;
case CG_CVAR_GETHIDDENVALUE:
return CL_GetValueForHidden((const char *)VMA(1));
case CG_ARGC:
return Cmd_Argc();
case CG_ARGV:
Cmd_ArgvBuffer( args[1], (char *)VMA(2), args[3] );
return 0;
case CG_ARGS:
Cmd_ArgsBuffer( (char *)VMA(1), args[2] );
return 0;
case CG_FS_FOPENFILE:
return FS_FOpenFileByMode( (const char *)VMA(1), (int *)VMA(2), (fsMode_t)args[3] );
case CG_FS_READ:
FS_Read( VMA(1), args[2], args[3] );
return 0;
case CG_FS_WRITE:
FS_Write( VMA(1), args[2], args[3] );
return 0;
case CG_FS_FCLOSEFILE:
FS_FCloseFile( args[1] );
return 0;
case CG_FS_GETFILELIST:
return FS_GetFileList( (const char *)VMA(1), (const char *)VMA(2), (char *)VMA(3), args[4] );
case CG_SENDCONSOLECOMMAND:
Cbuf_AddText( (const char *)VMA(1) );
return 0;
case CG_ADDCOMMAND:
CL_AddCgameCommand( (const char *)VMA(1) );
return 0;
case CG_REMOVECOMMAND:
Cmd_VM_RemoveCommand( (const char *)VMA(1), VM_CGAME );
return 0;
case CG_SENDCLIENTCOMMAND:
CL_AddReliableCommand2( (const char *)VMA(1) );
return 0;
case CG_UPDATESCREEN:
// this is used during lengthy level loading, so pump message loop
// Com_EventLoop(); // FIXME: if a server restarts here, BAD THINGS HAPPEN!
// We can't call Com_EventLoop here, a restart will crash and this _does_ happen
// if there is a map change while we are downloading at pk3.
// ZOID
SCR_UpdateScreen();
return 0;
case CG_CM_LOADMAP:
CL_CM_LoadMap( (const char *)VMA(1), (qboolean)args[2] );
return 0;
case CG_CM_NUMINLINEMODELS:
return CM_NumInlineModels();
case CG_CM_INLINEMODEL:
return CM_InlineModel( args[1] );
case CG_CM_TEMPBOXMODEL:
return CM_TempBoxModel( (const float *)VMA(1), (const float *)VMA(2), /*int capsule*/ qfalse );
case CG_CM_TEMPCAPSULEMODEL:
return CM_TempBoxModel( (const float *)VMA(1), (const float *)VMA(2), /*int capsule*/ qtrue );