static void pack_local_data (entity *en, pack_modes mode) { ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES)); switch (mode) { //////////////////////////////////////// case PACK_MODE_SERVER_SESSION: case PACK_MODE_CLIENT_SESSION: //////////////////////////////////////// { sound_effect *raw; int loop; raw = get_local_entity_data (en); if (effect_database [raw->eff.sub_type].constructed_locally) { return; } if (mode == PACK_MODE_SERVER_SESSION) { if (get_local_entity_type (raw->eff.special_effect_link.parent) == ENTITY_TYPE_SESSION) { return; } } pack_entity_type (get_local_entity_type (en)); pack_entity_safe_ptr (en); // // pack effect data // pack_effect_data (en, &raw->eff, mode); // // pack sound effect data // pack_int_value (en, INT_TYPE_SOUND_EFFECT_SEQUENCE_COUNT, raw->sound_effect_sequence_count); for (loop = 0; loop < raw->sound_effect_sequence_count; loop ++) { pack_int_value (en, INT_TYPE_SOUND_EFFECT_INDEX, raw->effect_index [loop]); } pack_float_value (en, FLOAT_TYPE_AMPLIFICATION, raw->amplification); pack_float_value (en, FLOAT_TYPE_EFFECT_LIFETIME, raw->effect_lifetime); pack_float_value (en, FLOAT_TYPE_VALID_EFFECT_LIFETIME, raw->valid_effect_lifetime); // sound_effect_data pack_int_value (en, INT_TYPE_SOUND_CHANNEL, raw->sound_channel); pack_int_value (en, INT_TYPE_SOUND_LOCALITY, raw->sound_locality); pack_int_value (en, INT_TYPE_VALID_SOUND_EFFECT, raw->valid_sound_effect); pack_int_value (en, INT_TYPE_SOUND_EFFECT_LOOPING, raw->looping); pack_int_value (en, INT_TYPE_SOUND_EFFECT_PANNING, raw->panning); if (get_local_entity_parent (en, LIST_TYPE_UPDATE)) { pack_int_value (en, INT_TYPE_VALID, TRUE); } else { pack_int_value (en, INT_TYPE_VALID, FALSE); } #if DEBUG_MODULE debug_log ("SE_PACK: Packed %d - Sub-type %d", get_local_entity_safe_index (en), raw->eff.sub_type); #endif break; } //////////////////////////////////////// case PACK_MODE_BROWSE_SESSION: //////////////////////////////////////// { break; } //////////////////////////////////////// case PACK_MODE_UPDATE_ENTITY: //////////////////////////////////////// { break; } } }
int pack_session (char *buffer, int *buffer_size, pack_modes mode) { entity *en; int packed_data_size, pack_buffer_overflow; #if DEBUG_MODULE int pack_size, last_pack_size; #endif ASSERT (buffer); ASSERT (*buffer_size > 0); ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES)); #if !DEBUG_MODULE_PACK_ALL disable_debug_log_entity_args (); #endif #if DEBUG_MODULE_PACK_ALL debug_log (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); debug_log ("PACK SESSION: buffer_size = %d", *buffer_size); debug_log (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); #endif open_pack_buffer (buffer, *buffer_size); // // kill any entities that are marked 'kill next update' // //kill_entities_awaiting_update (); // // Unlink all killed "local_only" entities from lists. Just // #if DEBUG_MODULE debug_log ("EN_SESSN: starting to pack current_pack_buffer_bit_size = %d", get_current_pack_buffer_bit_size ()); memset (entity_pack_size_array, 0, sizeof (entity_pack_size_type) * NUM_ENTITY_TYPES); #endif // // pack sector entities first // pack_local_sector_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after sector", get_current_pack_buffer_bit_size ()); #endif // // pack pylon entities // pack_local_pylon_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after pylon", get_current_pack_buffer_bit_size ()); #endif // // pack segment entities // pack_local_segment_data (mode); // // pack bridge entities // pack_local_bridge_data (mode); // // pack Session and Force entities first // pack_local_session_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after session", get_current_pack_buffer_bit_size ()); #endif en = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE); while (en) { pack_local_force_data (en, mode); en = get_local_entity_child_succ (en, LIST_TYPE_FORCE); } #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after force", get_current_pack_buffer_bit_size ()); #endif // // pack remaining entities // en = get_local_entity_list (); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after segment", get_current_pack_buffer_bit_size ()); last_pack_size = get_current_pack_buffer_bit_size (); #endif while (en) { pack_local_entity_data (en, mode); #if DEBUG_MODULE debug_log ("EN_SESSN: packing entity %s index %d, pack_buffer_size %d", get_local_entity_type_name (en), get_local_entity_index (en), get_current_pack_buffer_bit_size () / 8); pack_size = get_current_pack_buffer_bit_size () - last_pack_size; last_pack_size = get_current_pack_buffer_bit_size (); entity_pack_size_array [en->type].count ++; entity_pack_size_array [en->type].size += pack_size; #endif en = get_local_entity_succ (en); } // // mark end of session data // pack_entity_type (ENTITY_TYPE_UNKNOWN); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after session_data", get_current_pack_buffer_bit_size ()); #endif // // pack other entity data // pack_local_keysite_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after keysite", get_current_pack_buffer_bit_size ()); #endif pack_local_regen_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after regen", get_current_pack_buffer_bit_size ()); #endif pack_local_city_building_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after city_building", get_current_pack_buffer_bit_size ()); #endif pack_local_scenic_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after scenic", get_current_pack_buffer_bit_size ()); #endif pack_local_site_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after site", get_current_pack_buffer_bit_size ()); #endif pack_local_site_updatable_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after site_updatable", get_current_pack_buffer_bit_size ()); #endif pack_local_anti_aircraft_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after anti_aircraft", get_current_pack_buffer_bit_size ()); #endif pack_local_group_data (mode); #if DEBUG_MODULE debug_log ("EN_SESSN: current_pack_buffer_bit_size = %d, after local groups", get_current_pack_buffer_bit_size ()); #endif pack_local_division_database (mode); pack_local_message_log (mode); pack_group_callsign_database (mode); #if LANDING_ROUTE_CHECK pack_debug_entity_landing_locks (mode); #endif pack_buffer_overflow = get_pack_buffer_overflow (); packed_data_size = close_pack_buffer (); #if DEBUG_MODULE_PACK_ALL debug_log (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); debug_log ("PACK SESSION: packed_data_size = %d", packed_data_size); debug_log ("PACK SESSION: pack_buffer_overflow = %d", pack_buffer_overflow); debug_log (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); #endif *buffer_size = packed_data_size; #if !DEBUG_MODULE_PACK_ALL enable_debug_log_entity_args (); #endif #if DEBUG_MODULE { int loop; for (loop = 0; loop < NUM_ENTITY_TYPES; loop ++) { if (entity_pack_size_array [loop].size) { debug_log ("EN_SESSN: %d bytes (%f each) for %d entity %s", entity_pack_size_array [loop].size / 8, (float) (entity_pack_size_array [loop].size / 8) / entity_pack_size_array [loop].count, entity_pack_size_array [loop].count, entity_type_names [loop]); } } } #endif // // // return (pack_buffer_overflow); }
static void pack_local_data (entity *en, pack_modes mode) { ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES)); switch (mode) { //////////////////////////////////////// case PACK_MODE_SERVER_SESSION: case PACK_MODE_CLIENT_SESSION: //////////////////////////////////////// { routed_vehicle *raw; raw = (routed_vehicle *) get_local_entity_data (en); pack_entity_type (get_local_entity_type (en)); pack_entity_safe_ptr (en); // // pack vehicle data // pack_vehicle_data (en, &raw->vh, mode); ///////////////////////////////////////////////////////////////// if ((raw->vh.mob.velocity == 0.0) && (raw->desired_velocity == 0.0)) { pack_int_value (en, INT_TYPE_VALID, TRUE); } else { pack_int_value (en, INT_TYPE_VALID, FALSE); pack_float_value (en, FLOAT_TYPE_LOW_VELOCITY, raw->vh.mob.velocity); pack_float_value (en, FLOAT_TYPE_DESIRED_VELOCITY, raw->desired_velocity); } ///////////////////////////////////////////////////////////////// // // pack routed data // ///////////////////////////////////////////////////////////////// if ((raw->sub_waypoint_count == 0) && (raw->waypoint_next_index == 0) && (raw->waypoint_this_index == 0)) { pack_int_value (en, INT_TYPE_VALID, FALSE); } else { pack_int_value (en, INT_TYPE_VALID, TRUE); pack_int_value (en, INT_TYPE_SUB_WAYPOINT_COUNT, raw->sub_waypoint_count); pack_int_value (en, INT_TYPE_WAYPOINT_NEXT_INDEX, raw->waypoint_next_index); pack_int_value (en, INT_TYPE_WAYPOINT_THIS_INDEX, raw->waypoint_this_index); } ///////////////////////////////////////////////////////////////// // sub_waypoint_list reconstructed locally // // spin through special effects link and pack up local only smoke trails // pack_routed_vehicle_meta_smoke_lists (en, mode); pack_mobile_local_sound_effects (en, mode); break; } //////////////////////////////////////// case PACK_MODE_BROWSE_SESSION: //////////////////////////////////////// { break; } //////////////////////////////////////// case PACK_MODE_UPDATE_ENTITY: //////////////////////////////////////// { routed_vehicle *raw; raw = (routed_vehicle *) get_local_entity_data (en); pack_vec3d (en, VEC3D_TYPE_POSITION, &raw->vh.mob.position); pack_attitude_matrix (en, raw->vh.mob.attitude); pack_int_value (en, INT_TYPE_SUB_WAYPOINT_COUNT, raw->sub_waypoint_count); break; } } }
static void pack_local_data (entity *en, pack_modes mode) { ASSERT ((mode >= 0) && (mode < NUM_PACK_MODES)); switch (mode) { //////////////////////////////////////// case PACK_MODE_SERVER_SESSION: //////////////////////////////////////// { break; } //////////////////////////////////////// case PACK_MODE_CLIENT_SESSION: //////////////////////////////////////// { pilot *raw; raw = get_local_entity_data (en); pack_entity_type (get_local_entity_type (en)); pack_entity_safe_ptr (en); // // pack data // pack_int_value (en, INT_TYPE_ENTITY_SUB_TYPE, raw->sub_type); pack_string (en, STRING_TYPE_PILOTS_NAME, raw->pilots_name); pack_int_value (en, INT_TYPE_PILOT_RANK, raw->rank); pack_int_value (en, INT_TYPE_KILLS, raw->kills); pack_int_value (en, INT_TYPE_UNIQUE_ID, raw->unique_id); // crew_role pack_list_root (en, LIST_TYPE_PILOT_LOCK, &raw->pilot_lock_root); pack_list_link (en, LIST_TYPE_AIRCREW, &raw->aircrew_link); pack_list_link (en, LIST_TYPE_PILOT, &raw->pilot_link); pack_list_link (en, LIST_TYPE_PLAYER_TASK, &raw->player_task_link); pack_int_value (en, INT_TYPE_SIDE, raw->side); pack_int_value (en, INT_TYPE_DIFFICULTY_LEVEL, raw->difficulty_level); break; } //////////////////////////////////////// case PACK_MODE_BROWSE_SESSION: //////////////////////////////////////// { pilot *raw; raw = get_local_entity_data (en); pack_entity_type (get_local_entity_type (en)); pack_entity_safe_ptr (en); // // pack data // pack_int_value (en, INT_TYPE_ENTITY_SUB_TYPE, raw->sub_type); pack_string (en, STRING_TYPE_PILOTS_NAME, raw->pilots_name); pack_int_value (en, INT_TYPE_PILOT_RANK, raw->rank); pack_int_value (en, INT_TYPE_KILLS, raw->kills); pack_int_value (en, INT_TYPE_UNIQUE_ID, raw->unique_id); // crew_role // aircrew_link pack_list_link (en, LIST_TYPE_PILOT, &raw->pilot_link); pack_int_value (en, INT_TYPE_SIDE, raw->side); // difficulty level break; } //////////////////////////////////////// case PACK_MODE_UPDATE_ENTITY: //////////////////////////////////////// { break; } } }