1 #using scripts\shared\callbacks_shared;
2 #using scripts\shared\clientfield_shared;
3 #using scripts\shared\filter_shared;
4 #using scripts\shared\postfx_shared;
5 #using scripts\shared\system_shared;
6 #using scripts\shared\util_shared;
8 #insert scripts\shared\shared.gsh;
9 #insert scripts\shared\version.gsh;
10 #insert scripts\mp\killstreaks\_killstreaks.gsh;
12 #define VSMGR_OVERLAY_STYLE_NONE 0
13 #define VSMGR_OVERLAY_STYLE_POSTFX_BUNDLE 1
14 #define VSMGR_OVERLAY_STYLE_FILTER 2
15 #define VSMGR_OVERLAY_STYLE_BLUR 3
16 #define VSMGR_OVERLAY_STYLE_ELECTRIFIED 4
17 #define VSMGR_OVERLAY_STYLE_BURN 5
18 #define VSMGR_OVERLAY_STYLE_POISON 6
19 #define VSMGR_OVERLAY_STYLE_TRANSPORTED 7
20 #define VSMGR_OVERLAY_STYLE_SPEED_BLUR 8
22 #define VSMGR_VISIONSET_TYPE_NAKED 0
23 #define VSMGR_VISIONSET_TYPE_LASTSTAND 6
25 #namespace visionset_mgr;
31 level.vsmgr_initializing =
true;
32 level.vsmgr_default_info_name =
"__none";
35 level.vsmgr_states_inited = [];
36 level.vsmgr_filter_custom_enable = [];
37 level.vsmgr_filter_custom_disable = [];
57 level.vsmgr[
"visionset"].info[
name].visionset_from = visionset_from;
58 level.vsmgr[
"visionset"].info[
name].visionset_to = visionset_to;
59 level.vsmgr[
"visionset"].info[
name].visionset_type = visionset_type;
82 level.vsmgr[
"overlay"].info[
name].filter_index = filter_index;
83 level.vsmgr[
"overlay"].info[
name].pass_index = pass_index;
84 level.vsmgr[
"overlay"].info[
name].material_name = material_name;
85 level.vsmgr[
"overlay"].info[
name].constant_index = constant_index;
98 level.vsmgr[
"overlay"].info[
name].transition_in = transition_in;
99 level.vsmgr[
"overlay"].info[
name].transition_out = transition_out;
100 level.vsmgr[
"overlay"].info[
name].magnitude = magnitude;
113 level.vsmgr[
"overlay"].info[
name].duration = duration;
126 level.vsmgr[
"overlay"].info[
name].duration = duration;
151 level.vsmgr[
"overlay"].info[
name].duration = duration;
155 function register_overlay_info_style_speed_blur(
name, version, lerp_step_count, amount, inner_radius, outer_radius, velocity_should_scale, velocity_scale, blur_in, blur_out, should_offset )
164 level.vsmgr[
"overlay"].info[
name].amount = amount;
165 level.vsmgr[
"overlay"].info[
name].inner_radius = inner_radius;
166 level.vsmgr[
"overlay"].info[
name].outer_radius = outer_radius;
167 level.vsmgr[
"overlay"].info[
name].velocity_should_scale = velocity_should_scale;
168 level.vsmgr[
"overlay"].info[
name].velocity_scale = velocity_scale;
169 level.vsmgr[
"overlay"].info[
name].blur_in = blur_in;
170 level.vsmgr[
"overlay"].info[
name].blur_out = blur_out;
171 level.vsmgr[
"overlay"].info[
name].should_offset = should_offset;
183 level.vsmgr[
"overlay"].info[
name].bundle = bundle;
184 level.vsmgr[
"overlay"].info[
name].duration = duration;
190 if ( !level.vsmgr[type].in_use )
196 curr_info =
get_info( type, state.curr_slot );
198 return (curr_info.name == level.vsmgr_default_info_name);
204 level.vsmgr[type] = spawnstruct();
206 level.vsmgr[type].type = type;
207 level.vsmgr[type].in_use =
false;
208 level.vsmgr[type].highest_version = 0;
209 level.vsmgr[type].server_version = getserverhighestclientfieldversion();
210 level.vsmgr[type].cf_slot_name = type +
"_slot";
211 level.vsmgr[type].cf_lerp_name = type +
"_lerp";
212 level.vsmgr[type].cf_slot_cb = cf_slot_cb;
213 level.vsmgr[type].cf_lerp_cb = cf_lerp_cb;
214 level.vsmgr[type].update_cb = update_cb;
215 level.vsmgr[type].info = [];
216 level.vsmgr[type].sorted_name_keys = [];
223 if( !isdefined( level._fv2vs_default_visionset ) )
232 typeKeys = GetArrayKeys( level.vsmgr );
233 for ( type_index = 0; type_index < typeKeys.size; type_index++ )
238 level.vsmgr_initializing =
false;
244 /#println(
"visionset_mgr [" +
self.type +
"] client registrations:" );#/
246 if ( 1 >=
self.info.size )
252 self.cf_slot_bit_count = GetMinBitCountForNum(
self.info.size - 1 );
253 self.cf_lerp_bit_count =
self.info[
self.sorted_name_keys[0]].lerp_bit_count;
255 for ( i = 0; i <
self.sorted_name_keys.size; i++ )
257 self.info[
self.sorted_name_keys[i]].slot_index = i;
259 if (
self.info[
self.sorted_name_keys[i]].lerp_bit_count >
self.cf_lerp_bit_count )
261 self.cf_lerp_bit_count =
self.info[
self.sorted_name_keys[i]].lerp_bit_count;
264 /#println(
" name: " +
self.info[
self.sorted_name_keys[i]].
name +
", version: " +
self.info[
self.sorted_name_keys[i]].version +
", lerp_step_count: " +
self.info[
self.sorted_name_keys[i]].lerp_step_count +
"" );#/
270 if ( 1 <
self.cf_lerp_bit_count )
279 keys = GetArrayKeys( level.vsmgr );
280 for ( i = 0; i < keys.size; i++ )
282 if ( type == keys[i] )
288 assert( i < keys.size,
"In visionset_mgr, type '" + type +
"'is unknown" );
290 if ( version > level.vsmgr[type].server_version )
295 if ( isdefined( level.vsmgr[type].info[
name] ) && version < level.vsmgr[type].info[
name].version )
297 if ( version < level.vsmgr[type].info[
name].version )
303 level.vsmgr[type].info[
name] = undefined;
312 for ( i = 0; i < level.vsmgr[type].sorted_name_keys.size; i++ )
314 if (
name < level.vsmgr[type].sorted_name_keys[i] )
320 ArrayInsert( level.vsmgr[type].sorted_name_keys,
name, i );
328 self.version = version;
329 self.lerp_step_count = lerp_step_count;
330 self.lerp_bit_count = GetMinBitCountForNum( lerp_step_count );
336 assert( level.vsmgr_initializing,
"All info registration in the visionset_mgr system must occur during the first frame while the system is initializing" );
338 lower_name = ToLower(
name );
347 level.vsmgr[type].info[lower_name] = spawnstruct();
348 level.vsmgr[type].info[lower_name]
add_info( type, lower_name, version, lerp_step_count );
350 if ( version > level.vsmgr[type].highest_version )
352 level.vsmgr[type].highest_version = version;
359 function slot_cb( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump, type )
363 level.vsmgr[type].state[localClientNum].curr_slot = newVal;
365 if ( bNewEnt || bInitialSnap )
367 level.vsmgr[type].state[localClientNum].force_update =
true;
372 function visionset_slot_cb( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
374 self slot_cb( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump,
"visionset" );
378 function overlay_slot_cb( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
380 self slot_cb( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump,
"overlay" );
384 function lerp_cb( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump, type )
388 level.vsmgr[type].state[localClientNum].curr_lerp = newVal;
390 if ( bNewEnt || bInitialSnap )
392 level.vsmgr[type].state[localClientNum].force_update =
true;
397 function visionset_lerp_cb( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
399 self lerp_cb( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump,
"visionset" );
403 function overlay_lerp_cb( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump )
405 self lerp_cb( localClientNum, oldVal, newVal, bNewEnt, bInitialSnap, fieldName, bWasTimeJump,
"overlay" );
411 return level.vsmgr[type].info[level.vsmgr[type].sorted_name_keys[slot]];
417 return level.vsmgr[type].state[localClientNum];
423 return (
self.force_update || (
self.prev_slot !=
self.curr_slot) || (
self.prev_lerp !=
self.curr_lerp));
429 self.prev_slot =
self.curr_slot;
430 self.prev_lerp =
self.curr_lerp;
431 self.force_update =
false;
437 if ( isdefined( level.vsmgr_states_inited[localClientNum] ) )
442 typeKeys = GetArrayKeys( level.vsmgr );
444 for ( type_index = 0; type_index < typeKeys.size; type_index++ )
446 type = typeKeys[type_index];
448 if ( !level.vsmgr[type].in_use )
453 if ( !isdefined( level.vsmgr[type].state ) )
455 level.vsmgr[type].state = [];
458 level.vsmgr[type].state[localClientNum] = spawnstruct();
460 level.vsmgr[type].state[localClientNum].prev_slot = level.vsmgr[type].info[level.vsmgr_default_info_name].slot_index;
461 level.vsmgr[type].state[localClientNum].curr_slot = level.vsmgr[type].info[level.vsmgr_default_info_name].slot_index;
464 level.vsmgr[type].state[localClientNum].prev_lerp = 1;
465 level.vsmgr[type].state[localClientNum].curr_lerp = 1;
467 level.vsmgr[type].state[localClientNum].force_update =
false;
470 level.vsmgr_states_inited[localClientNum] =
true;
475 if ( !level.isDemoPlaying )
480 typeKeys = GetArrayKeys( level.vsmgr );
487 for ( type_index = 0; type_index < typeKeys.size; type_index++ )
489 type = typeKeys[type_index];
491 if ( !level.vsmgr[type].in_use )
496 level.vsmgr[type].state[0].force_update =
true;
504 if ( !level.isDemoPlaying )
509 typeKeys = GetArrayKeys( level.vsmgr );
513 if ( IsSpectating( 0,
false ) )
515 if ( !
IS_TRUE( level.vsmgr_is_spectating ) )
518 level notify(
"visionset_mgr_reset" );
521 level.vsmgr_is_spectating =
true;
525 if (
IS_TRUE( level.vsmgr_is_spectating ) )
527 level notify(
"visionset_mgr_reset" );
530 level.vsmgr_is_spectating =
false;
539 while ( level.vsmgr_initializing )
544 if (
IS_TRUE(level.isDemoPlaying) )
550 typeKeys = GetArrayKeys( level.vsmgr );
554 for ( type_index = 0; type_index < typeKeys.size; type_index++ )
556 type = typeKeys[type_index];
558 if ( !level.vsmgr[type].in_use )
563 for ( localClientNum = 0; localClientNum < level.localPlayers.size; localClientNum++ )
569 level.vsmgr[type] thread [[level.vsmgr[type].update_cb]]( localClientNum, type );
582 if ( visionset_to == visionset_vehicle )
584 if ( isdefined(
self.vehicletype ) && (
self.vehicletype != vehicletype ) )
594 if ( visionset_to == visionset_vehicle )
596 if ( !
self IsPlayer() )
607 curr_info =
get_info( type, state.curr_slot );
608 prev_info =
get_info( type, state.prev_slot );
614 if (
IS_TRUE( level.isDemoPlaying ) && IsSpectating( localClientNum,
true ) )
616 VisionSetNaked( localClientNum, level._fv2vs_default_visionset, 0 );
620 if ( level.vsmgr_default_info_name == curr_info.name )
626 player = GetLocalPlayer( localClientNum );
627 if( player getinkillcam( localClientNum ) )
629 if ( isdefined( curr_info.visionset_to ) )
631 killcament = player getkillcamentity( localClientNum );
635 if( ( killcament.type ==
"vehicle" ) && !( killcament
clientfield::get(
"mothership" ) ) )
641 if( ( killcament.type ==
"vehicle" ) )
656 if ( !IsDefined( curr_info.visionset_from ) )
660 VisionSetLaststandLerp( localClientNum, curr_info.visionset_to, level._fv2vs_prev_visionsets[localClientNum], state.curr_lerp );
664 VisionSetNakedLerp( localClientNum, curr_info.visionset_to, level._fv2vs_prev_visionsets[localClientNum], state.curr_lerp );
671 VisionSetLaststandLerp( localClientNum, curr_info.visionset_to, curr_info.visionset_from, state.curr_lerp );
675 VisionSetNakedLerp( localClientNum, curr_info.visionset_to, curr_info.visionset_from, state.curr_lerp );
683 SetDvar(
"r_poisonFX_debug_enable", 1 );
684 SetDvar(
"r_poisonFX_pulse", 2 );
685 SetDvar(
"r_poisonFX_warpX", -.3 );
686 SetDvar(
"r_poisonFX_warpY", .15 );
687 SetDvar(
"r_poisonFX_dvisionA", 0 );
688 SetDvar(
"r_poisonFX_dvisionX", 0 );
689 SetDvar(
"r_poisonFX_dvisionY", 0 );
690 SetDvar(
"r_poisonFX_blurMin", 0 );
691 SetDvar(
"r_poisonFX_blurMax", 3 );
693 SetDvar(
"r_poisonFX_debug_amount", amount );
698 SetDvar(
"r_poisonFX_debug_amount", 0 );
699 SetDvar(
"r_poisonFX_debug_enable", 0 );
705 curr_info =
get_info( type, state.curr_slot );
706 prev_info =
get_info( type, state.prev_slot );
707 player = level.localPlayers[localClientNum];
713 if ( state.force_update || state.prev_slot != state.curr_slot )
715 switch ( prev_info.style )
724 if ( IsDefined( level.vsmgr_filter_custom_disable[ curr_info.material_name ] ) )
726 player [[ level.vsmgr_filter_custom_disable[ curr_info.material_name ] ]]( state, prev_info, curr_info );
730 setfilterpassenabled( localClientNum, prev_info.filter_index, prev_info.pass_index,
false );
734 SetBlurByLocalClientNum( localClientNum, 0, prev_info.transition_out );
737 SetElectrified( localClientNum, 0 );
740 SetBurn( localClientNum, 0 );
749 DisableSpeedBlur( localClientNum );
754 if (
IS_TRUE( level.isDemoPlaying ) && IsSpectating( localClientNum,
false ) )
759 switch ( curr_info.style )
765 if ( state.force_update || state.prev_slot != state.curr_slot || state.prev_lerp <= state.curr_lerp )
767 player thread postfx::PlayPostfxBundle( curr_info.bundle );
771 if ( state.force_update || state.prev_slot != state.curr_slot || state.prev_lerp != state.curr_lerp )
773 if ( IsDefined( level.vsmgr_filter_custom_enable[ curr_info.material_name ] ) )
775 player [[ level.vsmgr_filter_custom_enable[ curr_info.material_name ] ]]( state, prev_info, curr_info );
779 setfilterpassmaterial( localClientNum, curr_info.filter_index, curr_info.pass_index, level.filter_matid[curr_info.material_name] );
780 setfilterpassenabled( localClientNum, curr_info.filter_index, curr_info.pass_index,
true );
782 if ( IsDefined( curr_info.constant_index ) )
784 setfilterpassconstant( localClientNum, curr_info.filter_index, curr_info.pass_index, curr_info.constant_index, state.curr_lerp );
790 if ( state.force_update || state.prev_slot != state.curr_slot || state.prev_lerp <= state.curr_lerp )
792 SetBlurByLocalClientNum( localClientNum, curr_info.magnitude, curr_info.transition_in );
796 if ( state.force_update || state.prev_slot != state.curr_slot || state.prev_lerp <= state.curr_lerp )
798 SetElectrified( localClientNum, (curr_info.duration * state.curr_lerp) );
802 if ( state.force_update || state.prev_slot != state.curr_slot || state.prev_lerp <= state.curr_lerp )
804 SetBurn( localClientNum, (curr_info.duration * state.curr_lerp) );
808 if ( state.force_update || state.prev_slot != state.curr_slot || state.prev_lerp != state.curr_lerp )
814 if ( state.force_update || state.prev_slot != state.curr_slot || state.prev_lerp <= state.curr_lerp )
820 if ( state.force_update || state.prev_slot != state.curr_slot || state.prev_lerp <= state.curr_lerp )
822 if( isDefined( curr_info.should_offset ) )
824 EnableSpeedBlur( localClientNum, curr_info.amount, curr_info.inner_radius, curr_info.outer_radius, curr_info.velocity_should_scale, curr_info.velocity_scale, curr_info.blur_in, curr_info.blur_out, curr_info.should_offset );
826 else if ( isdefined(curr_info.blur_out) )
828 EnableSpeedBlur( localClientNum, curr_info.amount, curr_info.inner_radius, curr_info.outer_radius, curr_info.velocity_should_scale, curr_info.velocity_scale, curr_info.blur_in, curr_info.blur_out );
830 else if ( isdefined(curr_info.blur_in) )
832 EnableSpeedBlur( localClientNum, curr_info.amount, curr_info.inner_radius, curr_info.outer_radius, curr_info.velocity_should_scale, curr_info.velocity_scale, curr_info.blur_in );
834 else if ( isdefined(curr_info.velocity_scale) )
836 EnableSpeedBlur( localClientNum, curr_info.amount, curr_info.inner_radius, curr_info.outer_radius, curr_info.velocity_should_scale, curr_info.velocity_scale );
838 else if ( isdefined(curr_info.velocity_should_scale) )
840 EnableSpeedBlur( localClientNum, curr_info.amount, curr_info.inner_radius, curr_info.outer_radius, curr_info.velocity_should_scale );
844 EnableSpeedBlur( localClientNum, curr_info.amount, curr_info.inner_radius, curr_info.outer_radius );
855 level._fv2vs_default_visionset = default_visionset;
856 level._fv2vs_default_trans_in = default_trans_in;
857 level._fv2vs_suffix =
"";
858 level._fv2vs_unset_visionset =
"_fv2vs_unset";
860 level._fv2vs_prev_visionsets = [];
861 level._fv2vs_prev_visionsets[0] = level._fv2vs_unset_visionset;
862 level._fv2vs_prev_visionsets[1] = level._fv2vs_unset_visionset;
863 level._fv2vs_prev_visionsets[2] = level._fv2vs_unset_visionset;
864 level._fv2vs_prev_visionsets[3] = level._fv2vs_unset_visionset;
866 level._fv2vs_force_instant_transition = [];
867 level._fv2vs_force_instant_transition[0] =
false;
868 level._fv2vs_force_instant_transition[1] =
false;
869 level._fv2vs_force_instant_transition[2] =
false;
870 level._fv2vs_force_instant_transition[3] =
false;
872 if ( !isdefined( host_migration_active ) )
874 level._fv2vs_infos = [];
879 level._fv2vs_inited =
true;
888 level._fv2vs_suffix = suffix;
894 if ( !IsDefined( trans_in ) )
896 trans_in = level._fv2vs_default_trans_in;
899 level._fv2vs_infos[id] = SpawnStruct();
901 level._fv2vs_infos[id].visionset = visionset;
902 level._fv2vs_infos[id].trans_in = trans_in;
908 if ( !
IS_TRUE( level._fv2vs_inited ) )
913 level._fv2vs_force_instant_transition[localClientNum] =
true;
919 level endon(
"hmo" );
931 players = GetLocalPlayers();
932 for ( localClientNum = 0; localClientNum < players.size; localClientNum++ )
934 level._fv2vs_force_instant_transition[localClientNum] =
true;
941 level waittill(
"hmo" );
952 level notify(
"visionset_mgr_reset" );
958 level endon(
"hmo" );
962 was_not_in_default_type = [];
963 was_not_in_default_type[0] =
false;
964 was_not_in_default_type[1] =
false;
965 was_not_in_default_type[2] =
false;
966 was_not_in_default_type[3] =
false;
973 players = GetLocalPlayers();
974 for ( localClientNum = 0; localClientNum < players.size; localClientNum++ )
978 was_not_in_default_type[localClientNum] =
true;
982 id = GetWorldFogScriptID( localClientNum );
985 if ( !IsDefined( level._fv2vs_infos[
id] ) )
990 new_visionset = level._fv2vs_infos[id].visionset + level._fv2vs_suffix;
992 if ( was_not_in_default_type[localClientNum] || level._fv2vs_prev_visionsets[localClientNum] != new_visionset || level._fv2vs_force_instant_transition[localClientNum] )
997 trans = level._fv2vs_infos[id].trans_in;
998 if ( level._fv2vs_force_instant_transition[localClientNum] )
1007 VisionSetNaked( localClientNum, new_visionset, trans );
1008 level._fv2vs_prev_visionsets[localClientNum] = new_visionset;
1011 level._fv2vs_force_instant_transition[localClientNum] =
false;
1012 was_not_in_default_type[localClientNum] =
false;
1019 level endon(
"hmo" );
1023 level waittill(
"respawn" );
1024 players = GetLocalPlayers();
1025 for ( localClientNum = 0; localClientNum < players.size; localClientNum++ )
1027 level._fv2vs_prev_visionsets[localClientNum] = level._fv2vs_unset_visionset;