1 /*
2 ===========================================================================
3 Copyright (C) 2000 - 2013, Raven Software, Inc.
4 Copyright (C) 2001 - 2013, Activision, Inc.
5 Copyright (C) 2013 - 2015, OpenJK contributors
6
7 This file is part of the OpenJK source code.
8
9 OpenJK is free software; you can redistribute it and/or modify it
10 under the terms of the GNU General Public License version 2 as
11 published by the Free Software Foundation.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 ===========================================================================
21 */
22
23 #include "client.h"
24 #include "cl_cgameapi.h"
25 #include "FxScheduler.h"
26 #include "ghoul2/G2.h"
27
28 cvar_t *fx_debug;
29 #ifdef _DEBUG
30 cvar_t *fx_freeze;
31 #endif
32 cvar_t *fx_countScale;
33 cvar_t *fx_nearCull;
34
35 #define DEFAULT_EXPLOSION_RADIUS 512
36
37 // Stuff for the FxHelper
38 //------------------------------------------------------
SFxHelper()39 SFxHelper::SFxHelper() :
40 mTime(0),
41 mOldTime(0),
42 mFrameTime(0),
43 mTimeFrozen(false),
44 refdef(0)
45 {
46 }
47
ReInit(refdef_t * pRefdef)48 void SFxHelper::ReInit(refdef_t* pRefdef)
49 {
50 mTime = 0;
51 mOldTime = 0;
52 mFrameTime = 0;
53 mTimeFrozen = false;
54 refdef = pRefdef;
55 }
56
57 //------------------------------------------------------
Print(const char * msg,...)58 void SFxHelper::Print( const char *msg, ... )
59 {
60 va_list argptr;
61 char text[1024];
62
63 va_start( argptr, msg );
64 Q_vsnprintf(text, sizeof(text), msg, argptr);
65 va_end( argptr );
66
67 Com_DPrintf( text );
68 }
69
70 //------------------------------------------------------
AdjustTime(int frametime)71 void SFxHelper::AdjustTime( int frametime )
72 {
73 #ifdef _DEBUG
74 if ( fx_freeze->integer || ( frametime <= 0 ))
75 #else
76 if ( frametime <= 0 )
77 #endif
78 {
79 // Allow no time progression when we are paused.
80 mFrameTime = 0;
81 mRealTime = 0.0f;
82 }
83 else
84 {
85 mOldTime = mTime;
86 mTime = frametime;
87 mFrameTime = mTime - mOldTime;
88
89 mRealTime = mFrameTime * 0.001f;
90
91
92 /* mFrameTime = frametime;
93 mTime += mFrameTime;
94 mRealTime = mFrameTime * 0.001f;*/
95
96 // mHalfRealTimeSq = mRealTime * mRealTime * 0.5f;
97 }
98 }
99
100 //------------------------------------------------------
CameraShake(vec3_t origin,float intensity,int radius,int time)101 void SFxHelper::CameraShake( vec3_t origin, float intensity, int radius, int time )
102 {
103 TCGCameraShake *data = (TCGCameraShake *)cl.mSharedMemory;
104
105 VectorCopy(origin, data->mOrigin);
106 data->mIntensity = intensity;
107 data->mRadius = radius;
108 data->mTime = time;
109
110 CGVM_CameraShake();
111 }
112
113 //------------------------------------------------------
GetOriginAxisFromBolt(CGhoul2Info_v * pGhoul2,int mEntNum,int modelNum,int boltNum,vec3_t origin,vec3_t axis[3])114 qboolean SFxHelper::GetOriginAxisFromBolt(CGhoul2Info_v *pGhoul2, int mEntNum, int modelNum, int boltNum, vec3_t /*out*/origin, vec3_t /*out*/axis[3])
115 {
116 qboolean doesBoltExist;
117 mdxaBone_t boltMatrix;
118 TCGGetBoltData *data = (TCGGetBoltData*)cl.mSharedMemory;
119 data->mEntityNum = mEntNum;
120 CGVM_GetLerpData();//this func will zero out pitch and roll for players, and ridable vehicles
121
122 //Fixme: optimize these VM calls away by storing
123
124 // go away and get me the bolt position for this frame please
125 doesBoltExist = re->G2API_GetBoltMatrix(*pGhoul2, modelNum, boltNum,
126 &boltMatrix, data->mAngles, data->mOrigin, theFxHelper.mOldTime, 0, data->mScale);
127
128 if (doesBoltExist)
129 { // set up the axis and origin we need for the actual effect spawning
130 origin[0] = boltMatrix.matrix[0][3];
131 origin[1] = boltMatrix.matrix[1][3];
132 origin[2] = boltMatrix.matrix[2][3];
133
134 axis[1][0] = boltMatrix.matrix[0][0];
135 axis[1][1] = boltMatrix.matrix[1][0];
136 axis[1][2] = boltMatrix.matrix[2][0];
137
138 axis[0][0] = boltMatrix.matrix[0][1];
139 axis[0][1] = boltMatrix.matrix[1][1];
140 axis[0][2] = boltMatrix.matrix[2][1];
141
142 axis[2][0] = boltMatrix.matrix[0][2];
143 axis[2][1] = boltMatrix.matrix[1][2];
144 axis[2][2] = boltMatrix.matrix[2][2];
145 }
146 return doesBoltExist;
147 }
148