Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
recoilbase.c
Go to the documentation of this file.
1 class RecoilBase
2 {
3  bool m_DebugMode;
4 
5  Weapon_Base m_Weapon;
6  PlayerBase m_Player;
7  protected bool m_DeleteRequested;
8  protected float m_Time;//how much time has elapsed since first update
9  protected float m_ReloadTime;//reload time config parameter of the weapon
10  protected vector m_RecoilModifier;
11  protected bool m_IsClient;
12  // for mouse offset
13  float m_MouseOffsetRangeMin;//in degrees min
14  float m_MouseOffsetRangeMax;//in degrees max
15  float m_MouseOffsetRelativeTime = 1;//[0..1] a time it takes to move the mouse the required distance relative to the reload time of the weapon(firing mode)
16  float m_HandsOffsetRelativeTime = 1;//[0..1] a time it takes to move the hands the required distance given by the curve relative to the reload time of the weapon(firing mode)
17  float m_CamOffsetRelativeTime = 1;//[0..1] a time it takes to move the camera the required distance relative to the reload time of the weapon(firing mode)
18  float m_CamOffsetDistance = 0.05;//how far the camera will travel along the z-axis in cm
19  float m_MouseOffsetDistance;//how far should the mouse travel
20  float m_TimeNormalized;
21  //protected float m_MouseOffsetResult;//in degrees max
22  protected vector m_MouseOffsetTarget;//move the mouse towards this point
23  protected vector m_MouseOffsetTargetAccum;//the overall mouse offset so far(all deltas accumulated)
24  protected float m_Angle;//result between the min and max
25  // mouse end
26 
27  protected ref array<vector> m_HandsCurvePoints;
28 
29  void RecoilBase(Weapon_Base weapon)
30  {
31  m_Weapon = weapon;
32  //m_DebugMode = false;
33  m_DebugMode = GetDayZGame().IsAimLogEnabled();
34  m_Player = PlayerBase.Cast(weapon.GetHierarchyRootPlayer());
35  m_HandsCurvePoints = new array<vector>;
36  Init();
37  PostInit(weapon);
38  }
39 
40  void Init();
41 
42  Weapon_Base GetWeapon()
43  {
44  return m_Weapon;
45  }
46 
47  void PostInit(Weapon_Base weapon)
48  {
49  int muzzleIndex = weapon.GetCurrentMuzzle();
50  m_Angle = m_Player.GetRandomGeneratorSyncManager().GetRandomInRange(RandomGeneratorSyncUsage.RGSRecoil, m_MouseOffsetRangeMin, m_MouseOffsetRangeMax);
51  m_RecoilModifier = GetRecoilModifier( GetWeapon() );
52  if(m_DebugMode) Print(m_Angle);
53 
54  m_ReloadTime = weapon.GetReloadTime(muzzleIndex);
55  m_MouseOffsetTarget = vector.YawToVector(m_Angle);
56  m_MouseOffsetTarget = m_MouseOffsetTarget * m_MouseOffsetDistance;
57  m_IsClient = !GetGame().IsDedicatedServer();
58  m_CamOffsetDistance *= m_RecoilModifier[2];
59  }
60 
62  void Destroy()
63  {
64  m_DeleteRequested = true;
65  }
66 
67  // called externally per update, not to be overriden in children
68  void Update( SDayZPlayerAimingModel pModel, out float axis_mouse_x, out float axis_mouse_y, out float axis_hands_x, out float axis_hands_y, float pDt )
69  {
70  if( m_DeleteRequested )
71  {
72  delete this;
73  }
74 
75  m_TimeNormalized = Math.InverseLerp(0, m_ReloadTime, m_Time);
76  m_TimeNormalized = Math.Clamp(m_TimeNormalized, 0,0.99);
77 
78  ApplyMouseOffset(pDt, axis_mouse_x, axis_mouse_y);
79  ApplyHandsOffset(pDt, axis_hands_x, axis_hands_y);
80  if(m_IsClient)
81  ApplyCamOffset(pModel);
82  #ifdef DEVELOPER
83  if(m_DebugMode)
84  PrintString("RecoilBase | BEFORE | axis_mouse_y: " + axis_mouse_y.ToString());
85  #endif
86  axis_mouse_x = axis_mouse_x * m_RecoilModifier[0];
87  axis_mouse_y = axis_mouse_y * m_RecoilModifier[1];
88 
89  axis_hands_x = axis_hands_x * m_RecoilModifier[0];
90  axis_hands_y = axis_hands_y * m_RecoilModifier[1];
91 
92  #ifdef DEVELOPER
93  if(m_DebugMode)
94  {
95  PrintString("RecoilBase | AFTER | axis_mouse_y: " + axis_mouse_y.ToString());
96  }
97  #endif
98  m_Time += pDt;
99 
100  if( m_Time >= m_ReloadTime )
101  {
102  Destroy();
103  }
104  }
105 
106  void ApplyCamOffset(SDayZPlayerAimingModel pModel)
107  {
108  float time_rel = Math.Clamp(Math.InverseLerp(0, m_CamOffsetRelativeTime, m_TimeNormalized), 0, 1);
109  float offset = 0;
110  float time = Easing.EaseOutBack(time_rel);
111  if(time == 1)
112  {
113  offset = 0;
114  }
115  else
116  {
117  offset = Math.Lerp(0,m_CamOffsetDistance,time);
118  }
119 
120  pModel.m_fCamPosOffsetZ = offset;
121 
122  m_Player.GetCurrentCamera().SendRecoilOffsetZ(offset);
123  }
124 
125  void ApplyHandsOffset(float pDt, out float pRecResultX, out float pRecResultY)
126  {
127  float relative_time = m_TimeNormalized / Math.Clamp(m_HandsOffsetRelativeTime, 0.001,1);
128  vector pos_on_curve = GetPositionOnCurve(m_HandsCurvePoints, relative_time);
129 
130  /*if(m_DebugMode)
131  {
132  PrintString("pos_on_curve: " + pos_on_curve.ToString());
133  PrintString("normalized time: " + m_TimeNormalized.ToString());
134  PrintString("elapsed time: " + m_Time.ToString());
135  PrintString("curve pos x: " + pos_on_curve[0].ToString());
136  PrintString("curve pos y: " + pos_on_curve[1].ToString());
137  PrintString("relative_time: " + relative_time.ToString());
138  }*/
139 
140  pRecResultX = pos_on_curve[0];
141  pRecResultY = pos_on_curve[1];
142  }
143 
144  void ApplyMouseOffset(float pDt, out float pRecResultX, out float pRecResultY)
145  {
146  #ifdef DEVELOPER
147  if(m_DebugMode)
148  {
149  bool b1 = m_MouseOffsetTargetAccum[1] < m_MouseOffsetTarget[1];
150  PrintString( "RecoilBase | ApplyMouseOffset processing: " + b1 );
151  PrintString( "RecoilBase | m_MouseOffsetTargetAccum : " + m_MouseOffsetTargetAccum.ToString() );
152  PrintString( "RecoilBase | m_MouseOffsetTarget : " + m_MouseOffsetTarget.ToString() );
153  }
154  #endif
155 
156  if( m_MouseOffsetTargetAccum[1] < m_MouseOffsetTarget[1] )
157  {
158  float relative_delta = pDt / m_ReloadTime / Math.Clamp(m_MouseOffsetRelativeTime, 0.001,1);
159 
160  float delta_mouse_offset_x = m_MouseOffsetTarget[0] * relative_delta;
161  float delta_mouse_offset_y = m_MouseOffsetTarget[1] * relative_delta;
162 
163  if( ( m_MouseOffsetTargetAccum[1] + delta_mouse_offset_y) > m_MouseOffsetTarget[1] )
164  {
165  delta_mouse_offset_x = m_MouseOffsetTarget[0] - m_MouseOffsetTargetAccum[0];
166  delta_mouse_offset_y = m_MouseOffsetTarget[1] - m_MouseOffsetTargetAccum[1];
167  }
168 
169  m_MouseOffsetTargetAccum[0] = m_MouseOffsetTargetAccum[0] + delta_mouse_offset_x;
170  m_MouseOffsetTargetAccum[1] = m_MouseOffsetTargetAccum[1] + delta_mouse_offset_y;
171 
172  pRecResultX = delta_mouse_offset_x;
173  pRecResultY = delta_mouse_offset_y;
174 
175  /*if(m_DebugMode)
176  {
177  PrintString( "delta x: "+ delta_mouse_offset_x );
178  PrintString( "delta y: "+ delta_mouse_offset_y );
179  PrintString( "target x: "+ m_MouseOffsetTarget[0] );
180  PrintString( "target y: "+ m_MouseOffsetTarget[1] );
181  PrintString( "accum x: "+ m_MouseOffsetTargetAccum[0] );
182  PrintString( "accum y: "+ m_MouseOffsetTargetAccum[1] );
183  }*/
184  }
185  #ifdef DEVELOPER
186  if(m_DebugMode)
187  {
188  PrintString( "RecoilBase | pRecResultY: " + pRecResultY );
189  }
190  #endif
191  }
192 
193  vector GetRecoilModifier(Weapon_Base weapon)
194  {
195  if( weapon )
196  {
197  return weapon.GetPropertyModifierObject().m_RecoilModifiers;
198  }
199  else return "1 1 1";
200  }
201 
202  vector GetPositionOnCurve(array<vector> points, float time)
203  {
204  return Math3D.Curve(ECurveType.CatmullRom, time, points);
205  }
206 }
GetGame
proto native CGame GetGame()
m_Time
protected float m_Time
Definition: carscript.c:146
ECurveType
ECurveType
Definition: enmath3d.c:20
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
SDayZPlayerAimingModel
Definition: dayzplayer.c:1088
Print
proto void Print(void var)
Prints content of variable to console/log.
Easing
Input value between 0 and 1, returns value adjusted by easing, no automatic clamping of input(do your...
Definition: easing.c:2
m_DeleteRequested
bool m_DeleteRequested
Definition: bleedingsource.c:24
m_Weapon
protected InventoryItem m_Weapon
Weapons - cache.
Definition: dayzplayerimplementmeleecombat.c:57
RandomGeneratorSyncUsage
RandomGeneratorSyncUsage
Definition: randomgeneratorsyncmanager.c:1
PlayerBase
Definition: playerbaseclient.c:1
vector
Definition: enconvert.c:105
RecoilBase
Definition: recoilbase.c:1
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
PrintString
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition: enscript.c:345
array< vector >
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
Math
Definition: enmath.c:6
Math3D
Definition: enmath3d.c:27
points
< h scale="0.8">< image set="dayz_gui" name="icon_pin"/> Welcome to the DayZ Stress Test Branch</h >< h scale="0.6"> This branch serves for time limited development tests that are open to the community Our goal in each of these tests is to gather performance and stability data from servers under heavy load</h ></br >< h scale="0.8">< image set="dayz_gui" name="icon_pin"/> Stress test Schedule</h >< h scale="0.6"> We ll only run the Stress Tests when our development team needs data and or specific feedback Stress Tests will be announced on our Twitter and and will usually run for a couple of hours</h ></br >< h scale="0.8">< image set="dayz_gui" name="icon_pin"/> Current Stress Test</h >< h scale="0.6"> In the first bunch of Stress we ll mostly focus on watching server performance under heavy PvP gameplay load For detailed information about an ongoing Stress please visit dayz com dev hub</h ></br >< h scale="0.8">< image set="dayz_gui" name="icon_pin"/> Important Note</h >< h scale="0.6"> Stress Tests do not represent a typical DayZ gameplay experience Spawn points
Definition: news_feed.txt:26