‪Black Ops 3 Source Code Explorer  0.1
‪An script explorer for Black Ops 3 by ZeRoY
postfx_shared.csc
Go to the documentation of this file.
1 #using scripts\codescripts\struct;
2 
3 #using scripts\shared\callbacks_shared;
4 #using scripts\shared\filter_shared;
5 #using scripts\shared\math_shared;
6 #using scripts\shared\system_shared;
7 #using scripts\shared\util_shared;
8 #using scripts\shared\gfx_shared;
9 #using scripts\shared\duplicaterenderbundle; // Just so it will be included
10 
11 #insert scripts\shared\shared.gsh;
12 
13 #namespace postfx;
14 
15 #define MAX_NUM_QUADS 2048
16 
17 //-----------------------------------------------------------------------------
18 ‪REGISTER_SYSTEM( "postfx_bundle", &‪__init__, undefined )
19 
20 function ‪__init__()
21 {
23 }
24 
25 function ‪localplayer_postfx_bundle_init( localClientNum )
26 {
28 }
29 
30 //-----------------------------------------------------------------------------
32 {
33  if ( isdefined( self.postfxBundelsInited ) )
34  return;
35 
36  self.postfxBundelsInited = true;
37  self.playingPostfxBundle = "";
38  self.forceStopPostfxBundle = false;
39  self.exitPostfxBundle = false;
40 }
41 
42 //-----------------------------------------------------------------------------
43 
44 function ‪playPostfxBundle( playBundleName )
45 {
46  self endon("entityshutdown");
47  self endon("death");
48 
50 
52 
53  bundle = ‪struct::get_script_bundle( "postfxbundle", playBundleName );
54  if ( !isdefined( bundle ) )
55  {
56  /#
57  println( "ERROR: postfx bundle '" + playBundleName + "' not found" );
58  #/
59  return;
60  }
61 
62  filterid = 0;
63  totalAccumTime = 0;
64 
66 
67  self.playingPostfxBundle = playBundleName;
68 
69  localClientNum = self.localClientNum;
70 
71  looping = false;
72  enterStage = false;
73  exitStage = false;
74  finishLoopOnExit = false;
75  firstPersonOnly = false;
76 
77  ‪SET_IF_DEFINED( looping, bundle.looping );
78  ‪SET_IF_DEFINED( enterStage, bundle.enterStage );
79  ‪SET_IF_DEFINED( exitStage, bundle.exitStage );
80  ‪SET_IF_DEFINED( finishLoopOnExit, bundle.finishLoopOnExit );
81  ‪SET_IF_DEFINED( firstPersonOnly, bundle.firstPersonOnly );
82 
83  if ( looping )
84  {
85  num_stages = 1;
86  if ( enterStage )
87  num_stages++;
88  if ( exitStage )
89  num_stages++;
90  }
91  else
92  {
93  num_stages = bundle.num_stages;
94  }
95 
96  self.captureImageName = undefined;
97  if ( isDefined( bundle.screenCapture ) && bundle.screenCapture )
98  {
99  self.captureImageName = playBundleName;
100  CreateSceneCodeImage( localClientNum, self.captureImageName );
101  CaptureFrame( localClientNum, self.captureImageName );
102  setFilterPassCodeTexture( localClientNum, filterid, 0, 0, self.captureImageName );
103  }
104 
105  self thread ‪watchEntityShutdown( localClientNum, filterid );
106  for ( stageIdx = 0 ; stageIdx < num_stages && !self.forceStopPostfxBundle ; stageIdx++ )
107  {
108  stagePrefix = "s";
109  if ( stageIdx < 10 ) stagePrefix += "0";
110  stagePrefix += stageIdx + "_";
111 
112  stageLength = GetStructField( bundle, stagePrefix + "length" );
113  if ( !isdefined( stageLength ) )
114  {
115  ‪finishPlayingPostfxBundle( localClientNum, stagePrefix + "length not defined", filterid );
116  return;
117  }
118  stageLength *= 1000;
119 
120  stageMaterial = GetStructField( bundle, stagePrefix + "material" );
121  if ( !isdefined( stageMaterial ) )
122  {
123  ‪finishPlayingPostfxBundle( localClientNum, stagePrefix + "material not defined", filterid );
124  return;
125  }
126 
127  ‪filter::map_material_helper( self, stageMaterial );
128  setFilterPassMaterial( localClientNum, filterid, 0, ‪filter::mapped_material_id( stageMaterial ) );
129  setFilterPassEnabled( localClientNum, filterid, 0, true, false, firstPersonOnly );
130 
131  stageCapture = GetStructField( bundle, stagePrefix + "screenCapture" );
132  if ( isDefined( stageCapture ) && stageCapture )
133  {
134  if ( isDefined( self.captureImageName ) )
135  {
136  FreeCodeImage( localClientNum, self.captureImageName );
137  self.captureImageName = undefined;
138  setFilterPassCodeTexture( localClientNum, filterid, 0, 0, "" );
139  }
140 
141  self.captureImageName = stagePrefix + playBundleName;
142  CreateSceneCodeImage( localClientNum, self.captureImageName );
143  captureFrame( localClientNum, self.captureImageName );
144  setFilterPassCodeTexture( localClientNum, filterid, 0, 0, self.captureImageName );
145  }
146 
147  stageSprite = GetStructField( bundle, stagePrefix + "spriteFilter" );
148  if ( isDefined( stageSprite ) && stageSprite )
149  {
150  setfilterpassquads( localClientNum, filterid, 0, ‪MAX_NUM_QUADS );
151  }
152  else
153  {
154  setfilterpassquads( localClientNum, filterid, 0, 0 );
155  }
156 
157  thermal = GetStructField( bundle, stagePrefix + "thermal" );
158  EnableThermalDraw( localClientNum, isDefined( thermal ) && thermal );
159 
160  loopingStage = looping && ( !enterStage && stageIdx == 0 || enterStage && stageIdx == 1 );
161 
162  accumTime = 0;
163  prevTime = self GetClientTime();
164  while ( ( loopingStage || accumTime < stageLength ) && !self.forceStopPostfxBundle )
165  {
166 
167  ‪gfx::SetStage( localClientNum, bundle, filterid, stagePrefix, stageLength, accumTime, totalAccumTime, &‪SetFilterConstants );
168 
170 
171  currTime = self GetClientTime();
172  deltaTime = currTime - prevTime;
173  accumTime += deltaTime;
174  totalAccumTime += deltaTime;
175 
176  prevTime = currTime;
177 
178  if ( loopingStage )
179  {
180  while ( accumTime >= stageLength )
181  accumTime -= stageLength;
182 
183  if ( self.‪exitPostfxBundle )
184  {
185  loopingStage = false;
186  if ( !finishLoopOnExit )
187  break;
188  }
189  }
190  }
191 
192  setFilterPassEnabled( localClientNum, filterid, 0, false );
193  }
194 
195  ‪finishPlayingPostfxBundle( localClientNum, "Finished " + playBundleName, filterid );
196 }
197 
198 function ‪watchEntityShutdown( localClientNum, filterid )
199 {
200  self ‪util::waittill_any( "entityshutdown", "death", "finished_playing_postfx_bundle" );
201 
202  ‪finishPlayingPostfxBundle( localClientNum, "Entity Shutdown", filterid );
203 }
204 
205 //-----------------------------------------------------------------------------------------------------------
206 function ‪SetFilterConstants( localClientNum, shaderConstantName, filterid, values )
207 {
208  baseShaderConstIndex = ‪gfx::getShaderConstantIndex( shaderConstantName );
209  setFilterPassConstant( localClientNum, filterid, 0, baseShaderConstIndex + 0, values[0] );
210  setFilterPassConstant( localClientNum, filterid, 0, baseShaderConstIndex + 1, values[1] );
211  setFilterPassConstant( localClientNum, filterid, 0, baseShaderConstIndex + 2, values[2] );
212  setFilterPassConstant( localClientNum, filterid, 0, baseShaderConstIndex + 3, values[3] );
213 }
214 
215 //-----------------------------------------------------------------------------
216 
217 function ‪finishPlayingPostfxBundle( localClientNum, msg, filterid )
218 {
219  if( isDefined( self ) )
220  {
221  self notify ( "finished_playing_postfx_bundle" );
222  self.forceStopPostfxBundle = false;
223  self.exitPostfxBundle = false;
224  self.playingPostfxBundle = "";
225  }
226 
227  setFilterPassQuads( localClientNum, filterid, 0, 0 );
228  setFilterPassEnabled( localClientNum, filterid, 0, false );
229  EnableThermalDraw( localClientNum, false );
230 
231  if ( isDefined( self.captureImageName ) )
232  {
233  setFilterPassCodeTexture( localClientNum, filterid, 0, 0, "" );
234  FreeCodeImage( localClientNum, self.captureImageName );
235  self.captureImageName = undefined;
236  }
237 }
238 
239 //-----------------------------------------------------------------------------
240 
242 {
243  if ( self.playingPostfxBundle != "" )
244  {
246  }
247 }
248 
250 {
251  self notify( "stopPostfxBundle_singleton" );
252  self endon( "stopPostfxBundle_singleton" );
253 
254  if ( isdefined( self.playingPostfxBundle ) && self.playingPostfxBundle != "" )
255  {
256  self.forceStopPostfxBundle = true;
257 
258  while ( self.playingPostfxBundle != "" )
259  {
261 
262  if ( !isdefined( self ) )
263  {
264  return;
265  }
266  }
267  }
268 }
269 
271 {
272  if ( !‪IS_TRUE( self.‪exitPostfxBundle ) && isdefined( self.playingPostfxBundle ) && self.playingPostfxBundle != "" )
273  {
274  self.exitPostfxBundle = true;
275  }
276 }
277 
278 
279 function ‪setFrontendStreamingOverlay( localClientNum, system, enabled )
280 {
281  if( !isdefined( self.overlayClients ) )
282  {
283  self.overlayClients = [];
284  }
285 
286  if( !isdefined( self.overlayClients[localClientNum] ) )
287  {
288  self.overlayClients[localClientNum] = [];
289  }
290 
291  self.overlayClients[localClientNum][system] = enabled;
292 
293  foreach( _, en in self.overlayClients[localClientNum] )
294  {
295  if( en )
296  {
297  EnableFrontendStreamingOverlay( localClientNum, true );
298  return;
299  }
300  }
301 
302  EnableFrontendStreamingOverlay( localClientNum, false );
303 }
304 
‪on_localplayer_spawned
‪function on_localplayer_spawned(local_client_num)
Definition: _perks.csc:109
‪getShaderConstantIndex
‪function getShaderConstantIndex(codeConstName)
Definition: gfx_shared.csc:198
‪stopPostfxBundle
‪function stopPostfxBundle()
Definition: postfx_shared.csc:249
‪init_postfx_bundles
‪function init_postfx_bundles()
Definition: postfx_shared.csc:31
‪SetStage
‪function SetStage(localClientNum, bundle, filterid, stagePrefix, stageLength, accumTime, totalAccumTime, setConstants)
Definition: gfx_shared.csc:16
‪setFrontendStreamingOverlay
‪function setFrontendStreamingOverlay(localClientNum, system, enabled)
Definition: postfx_shared.csc:279
‪init_filter_indices
‪function init_filter_indices()
Definition: filter_shared.csc:7
‪IS_TRUE
‪#define IS_TRUE(__a)
Definition: shared.gsh:251
‪__init__
‪function __init__()
Definition: postfx_shared.csc:20
‪SetFilterConstants
‪function SetFilterConstants(localClientNum, shaderConstantName, filterid, values)
Definition: postfx_shared.csc:206
‪waittill_any
‪function waittill_any(str_notify1, str_notify2, str_notify3, str_notify4, str_notify5)
Definition: util_shared.csc:375
‪REGISTER_SYSTEM
‪#define REGISTER_SYSTEM(__sys, __func_init_preload, __reqs)
Definition: shared.gsh:204
‪SET_IF_DEFINED
‪#define SET_IF_DEFINED(__target, __src)
Definition: shared.gsh:442
‪map_material_helper
‪function map_material_helper(player, materialname)
Definition: filter_shared.csc:29
‪stopPlayingPostfxBundle
‪function stopPlayingPostfxBundle()
Definition: postfx_shared.csc:241
‪watchEntityShutdown
‪function watchEntityShutdown(localClientNum, filterid)
Definition: postfx_shared.csc:198
‪exitPostfxBundle
‪function exitPostfxBundle()
Definition: postfx_shared.csc:270
‪get_script_bundle
‪function get_script_bundle(str_type, str_name)
Definition: struct.csc:45
‪finishPlayingPostfxBundle
‪function finishPlayingPostfxBundle(localClientNum, msg, filterid)
Definition: postfx_shared.csc:217
‪playPostfxBundle
‪function playPostfxBundle(playBundleName)
Definition: postfx_shared.csc:44
‪MAX_NUM_QUADS
‪#define MAX_NUM_QUADS
Definition: postfx_shared.csc:15
‪WAIT_CLIENT_FRAME
‪#define WAIT_CLIENT_FRAME
Definition: shared.gsh:266
‪localplayer_postfx_bundle_init
‪function localplayer_postfx_bundle_init(localClientNum)
Definition: postfx_shared.csc:25
‪mapped_material_id
‪function mapped_material_id(materialname)
Definition: filter_shared.csc:35