void check_safe_memory_counter (void) { if (report_safe_memory_warnings) { if (safe_memory_counter == 0) { debug_colour_log (DEBUG_COLOUR_AMBER, "NOTE! Safe memory counter == 0"); } else { debug_colour_log (DEBUG_COLOUR_AMBER, "WARNING! Safe memory counter != 0 (counter = %d)", safe_memory_counter); } } }
void delete_screen_image_and_viewpoint_data (void) { char filename[100], large_image_filename[100], small_image_filename[100], viewpoint_data_filename[100]; debug_colour_log (DEBUG_COLOUR_RED, "Deleting all screen images"); for (screen_shot_index = 0; screen_shot_index < MAX_SCREEN_SHOT_INDEX; screen_shot_index++) { sprintf (filename, "IMAGE%03d", screen_shot_index); sprintf (large_image_filename, "%s%s.TGA", LARGE_IMAGE_PATH, filename); sprintf (small_image_filename, "%s%s.TGA", SMALL_IMAGE_PATH, filename); sprintf (viewpoint_data_filename, "%s%s.TXT", VIEWPOINT_DATA_PATH, filename); remove (large_image_filename); remove (small_image_filename); remove (viewpoint_data_filename); } found_first_screen_shot_index = TRUE; screen_shot_index = 0; }
void display_entity_system_statistics (void) { entity_types type; debug_colour_log (DEBUG_COLOUR_AMBER, "====================================="); debug_colour_log (DEBUG_COLOUR_AMBER, "ENTITY SYSTEM STATISTICS"); debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------"); debug_colour_log ( DEBUG_COLOUR_RED, "%-25.25s: entity peak count = %d (%.2f percent usage)", "ENTITY PEAK USAGE", entity_peak_count, ((float) entity_peak_count * 100.0) / (float) number_of_entities ); for (type = 0; type < NUM_ENTITY_TYPES; type++) { debug_colour_log ( DEBUG_COLOUR_AMBER, "%-25.25s: total created = %5d, count = %5d, peak count = %5d, sizeof = %5d", get_entity_type_name (type), entity_type_stats[type].total_created, entity_type_stats[type].count, entity_type_stats[type].peak_count, entity_type_database[type].size_of_data ); } debug_colour_log (DEBUG_COLOUR_AMBER, "====================================="); }
void reset_safe_memory_counter (void) { if (report_safe_memory_warnings) { debug_colour_log (DEBUG_COLOUR_AMBER, "NOTE! Safe memory counter reset"); } safe_memory_counter = 0; debug_watch ("Total safe memory allocated: %d", MT_INT, &total_safe_memory_allocated); debug_watch ("Maximum safe memory allocated: %d", MT_INT, &maximum_safe_memory_allocated); debug_watch ("Safe memory counter: %d", MT_INT, &safe_memory_counter ); }
//Xhit: Same type of behaviour as get_free_entity. Here the local entity pointers are set instead. (030428) entity *get_free_local_entity (int index) { entity *en; if (index == ENTITY_INDEX_CREATE_LOCAL) { en = first_free_local_entity; if (en) { // // unlink local_entity from start of free list // first_free_local_entity = en->succ; if (en->succ) { en->succ->pred = NULL; } // // insert local_entity into start of used list (en->pred already set to NULL) // en->succ = first_used_local_entity; if (en->succ) { en->succ->pred = en; } first_used_local_entity = en; } else { debug_colour_log (DEBUG_COLOUR_RED, "WARNING! Failed to get a free local_entity"); } } else { debug_fatal ("Entity already in use: %s (index = %d)", entity_type_names[index], index); } return (en); }
void save_global_options_data (void) { FILE *file_ptr; if (!(file_ptr = fopen (global_options_filename, "wb"))) { debug_fatal ("Global: Error saving global options data"); } fwrite (&global_options, sizeof (global_options), 1, file_ptr); fclose (file_ptr); add_file_to_uninstall_log ( global_options_filename ); debug_colour_log ( DEBUG_COLOUR_DARK_RED, "SAVED GLOBAL OPTIONS" ); }
static void check_no_entities_in_use (void) { if (first_used_entity) { debug_colour_log (DEBUG_COLOUR_RED, "WARNING! Entities still in use"); #if DEBUG_MODULE { entity *en; en = first_used_entity; while (en) { debug_log ("->ENTITY: %s (index = %d)", get_local_entity_type_name (en), get_local_entity_index (en)); en = get_local_entity_succ (en); } } #endif } }
void update_cinematic_camera (camera *raw) { // // pre-amble // ASSERT (raw); ASSERT (raw->external_view_entity); //////////////////////////////////////// // // This code has been added to protect against cases where an object // and its destroyed version have a different number of cameras. // switch (raw->cinematic_camera_index) { case OBJECT_3D_CAMERA_SCENIC_MOVING: case OBJECT_3D_CAMERA_SCENIC_STATIC: { object_3d_instance *inst3d; inst3d = get_local_entity_ptr_value (raw->external_view_entity, PTR_TYPE_INSTANCE_3D_OBJECT); if (raw->cinematic_camera_depth >= get_number_of_3d_object_cameras (inst3d, raw->cinematic_camera_index)) { #if DEBUG_MODULE debug_colour_log (DEBUG_COLOUR_RED, "CINEMATIC CAMERA ERROR - forced reset!!!"); #endif reset_cinematic_camera (raw); } break; } } // //////////////////////////////////////// // // update timer // raw->cinematic_camera_timer += get_delta_time (); if (raw->cinematic_camera_timer > raw->cinematic_camera_lifetime) { if (raw->auto_edit) { switch_auto_edit_entity (raw); if (switch_auto_edit_camera_mode (raw)) { // // switched to a different camera // return; } } reset_cinematic_camera (raw); } // // continue update // update_cinematic_camera_continued (raw); }
void save_screen_image_and_viewpoint_data (void) { char filename[100], large_image_filename[100], small_image_filename[100], viewpoint_data_filename[100]; FILE *fp; int x_sec, z_sec; // // find first screen shot index // if (!found_first_screen_shot_index) { while (TRUE) { sprintf (large_image_filename, "%sIMAGE%03d.TGA", LARGE_IMAGE_PATH, screen_shot_index); if (file_exist (large_image_filename)) { screen_shot_index++; if (screen_shot_index == 1000) { break; } } else { found_first_screen_shot_index = TRUE; break; } } } // // write screen files and viewpoint data file // if (screen_shot_index <= MAX_SCREEN_SHOT_INDEX) { sprintf (filename, "IMAGE%03d", screen_shot_index); debug_log ("Saving screen image (%s)", filename); sprintf (large_image_filename, "%s%s.TGA", LARGE_IMAGE_PATH, filename); sprintf (small_image_filename, "%s%s.TGA", SMALL_IMAGE_PATH, filename); sprintf (viewpoint_data_filename, "%s%s.TXT", VIEWPOINT_DATA_PATH, filename); //////////////////////////////////////// if (lock_screen (video_screen)) { save_tga_screen_with_thumbnail (large_image_filename, small_image_filename); unlock_screen (video_screen); } //////////////////////////////////////// fp = safe_fopen (viewpoint_data_filename, "w"); fprintf (fp, "Image viewpoint data:\n\n"); fprintf (fp, "Map : unknown\n"); fprintf (fp, "X : %.2f\n", main_vp.x); fprintf (fp, "Y : %.2f\n", main_vp.y); fprintf (fp, "Z : %.2f\n", main_vp.z); get_terrain_3d_sector (main_vp.x, main_vp.z, &x_sec, &z_sec); fprintf (fp, "X sector (3D) : %d\n", x_sec); fprintf (fp, "Z sector (3D) : %d\n", z_sec); get_x_sector (x_sec, main_vp.x); get_z_sector (z_sec, main_vp.z); fprintf (fp, "X sector (AI) : %d\n", x_sec); fprintf (fp, "Z sector (AI) : %d\n", z_sec); fprintf (fp, "Heading (degs): %.2f\n", deg (get_heading_from_attitude_matrix (main_vp.attitude))); fprintf (fp, "Pitch (degs) : %.2f\n", deg (get_pitch_from_attitude_matrix (main_vp.attitude))); fprintf (fp, "Roll (degs) : %.2f\n", deg (get_roll_from_attitude_matrix (main_vp.attitude))); safe_fclose (fp); //////////////////////////////////////// screen_shot_index++; } else { debug_colour_log (DEBUG_COLOUR_RED, "Exceeded screen image limit"); } }
void save_high_res_screen_image ( void ) { char filename[100], image_filename[100]; int x, y, x_repeat, y_repeat, screen_width, screen_height, screen_pitch; unsigned short int *huge_screen_shot_memory; unsigned char *screen_data; x_repeat = 8; y_repeat = 8; screen_width = get_screen_width ( video_screen ); screen_height = get_screen_height ( video_screen ); huge_screen_shot_memory = ( unsigned short int * ) safe_malloc ( sizeof ( unsigned short int ) * screen_width * screen_height * x_repeat * y_repeat ); for ( y = 0; y < y_repeat; y++ ) { for ( x = 0; x < x_repeat; x++ ) { unsigned short int *destination_ptr, *screen_line; int screen_y; // // Render the big views // draw_application_highres_screen ( x, y, x_repeat, y_repeat ); if ( lock_screen ( video_screen ) ) { screen_data = get_screen_data ( video_screen ); screen_pitch = get_screen_pitch ( video_screen ); destination_ptr = huge_screen_shot_memory + ( y * x_repeat * screen_width * screen_height ) + ( x * screen_width ); for ( screen_y = 0; screen_y < screen_height; screen_y++ ) { screen_line = ( unsigned short int * ) ( screen_data + ( screen_y * screen_pitch ) ); memcpy ( destination_ptr, screen_line, screen_width * sizeof ( unsigned short int ) ); destination_ptr += x_repeat * screen_width; } unlock_screen ( video_screen ); } } } // // find first screen shot index // if (!found_first_screen_shot_index) { while (TRUE) { sprintf (image_filename, "%sIMAGE%03d.PSD", LARGE_IMAGE_PATH, screen_shot_index); if (file_exist (image_filename)) { screen_shot_index++; if (screen_shot_index == 1000) { break; } } else { found_first_screen_shot_index = TRUE; break; } } } // // write screen files and viewpoint data file // if (screen_shot_index <= MAX_SCREEN_SHOT_INDEX) { sprintf (filename, "IMAGE%03d", screen_shot_index); debug_log ("Saving screen image (%s)", filename); sprintf (image_filename, "%s%s.PSD", LARGE_IMAGE_PATH, filename); write_psd_screen_file ( image_filename, screen_width * x_repeat, screen_height * y_repeat, screen_width * x_repeat * sizeof ( unsigned short int ), ( unsigned char * ) huge_screen_shot_memory ); screen_shot_index++; } else { debug_colour_log (DEBUG_COLOUR_RED, "Exceeded screen image limit"); } safe_free ( huge_screen_shot_memory ); }
void update_weapon_lock_type (target_acquisition_systems system) { entity *source, *target; entity_sub_types selected_weapon_type; float target_range, theta, weapon_min_range, weapon_max_range; vec3d *source_position, *target_position, *weapon_vector, *weapon_to_target_vector; //////////////////////////////////////// // // WEAPON_LOCK_NO_ACQUIRE // //////////////////////////////////////// if (system == TARGET_ACQUISITION_SYSTEM_OFF) { weapon_lock_type = WEAPON_LOCK_NO_ACQUIRE; return; } //////////////////////////////////////// // // WEAPON_LOCK_NO_WEAPON // //////////////////////////////////////// source = get_gunship_entity (); selected_weapon_type = get_local_entity_int_value (source, INT_TYPE_SELECTED_WEAPON); if (selected_weapon_type == ENTITY_SUB_TYPE_WEAPON_NO_WEAPON) { weapon_lock_type = WEAPON_LOCK_NO_WEAPON; return; } //////////////////////////////////////// // // WEAPON_LOCK_NO_TARGET // //////////////////////////////////////// target = get_local_entity_parent (source, LIST_TYPE_TARGET); if (!target) { weapon_lock_type = WEAPON_LOCK_NO_TARGET; return; } //////////////////////////////////////// // // WEAPON_LOCK_INVALID_TARGET // //////////////////////////////////////// // // infra-red air-to-air weapons require an airborne target // if (weapon_database[selected_weapon_type].guidance_type == WEAPON_GUIDANCE_TYPE_PASSIVE_INFRA_RED) { if (weapon_database[selected_weapon_type].weapon_class & WEAPON_CLASS_AIR_TO_AIR) { if (!get_local_entity_int_value (target, INT_TYPE_AIRBORNE_AIRCRAFT)) { weapon_lock_type = WEAPON_LOCK_INVALID_TARGET; return; } } } //////////////////////////////////////// // // WEAPON_LOCK_SEEKER_LIMIT // //////////////////////////////////////// // // if guided weapon check target is inside the seeker limit // if (weapon_database[selected_weapon_type].guidance_type != WEAPON_GUIDANCE_TYPE_NONE) { update_entity_weapon_system_weapon_and_target_vectors (source); if (get_local_entity_int_value (source, INT_TYPE_WEAPON_AND_TARGET_VECTORS_VALID)) { weapon_vector = get_local_entity_vec3d_ptr (source, VEC3D_TYPE_WEAPON_VECTOR); weapon_to_target_vector = get_local_entity_vec3d_ptr (source, VEC3D_TYPE_WEAPON_TO_TARGET_VECTOR); theta = get_3d_unit_vector_dot_product (weapon_vector, weapon_to_target_vector); theta = fabs (acos (theta)); if (theta > weapon_database[selected_weapon_type].max_launch_angle_error) { weapon_lock_type = WEAPON_LOCK_SEEKER_LIMIT; return; } } else { // // this should never happen // debug_colour_log (DEBUG_COLOUR_RED, "WARNING! Target and weapon vectors are not valid"); } } //////////////////////////////////////// // // WEAPON_LOCK_NO_LOS // //////////////////////////////////////// // // if air or ground radar then check line of sight // if ((system == TARGET_ACQUISITION_SYSTEM_GROUND_RADAR) || (system == TARGET_ACQUISITION_SYSTEM_AIR_RADAR)) { if (!get_local_entity_int_value (target, INT_TYPE_GUNSHIP_RADAR_LOS_CLEAR)) { weapon_lock_type = WEAPON_LOCK_NO_LOS; return; } } //////////////////////////////////////// // // WEAPON_LOCK_NO_BORESIGHT // //////////////////////////////////////// // // a boresight_weapon will be an unguided weapon so the seeker limit test is not being repeated here // if (weapon_database[selected_weapon_type].boresight_weapon) { update_entity_weapon_system_weapon_and_target_vectors (source); if (get_local_entity_int_value (source, INT_TYPE_WEAPON_AND_TARGET_VECTORS_VALID)) { weapon_vector = get_local_entity_vec3d_ptr (source, VEC3D_TYPE_WEAPON_VECTOR); weapon_to_target_vector = get_local_entity_vec3d_ptr (source, VEC3D_TYPE_WEAPON_TO_TARGET_VECTOR); theta = get_3d_unit_vector_dot_product (weapon_vector, weapon_to_target_vector); theta = fabs (acos (theta)); if (theta > rad (1.0)) { weapon_lock_type = WEAPON_LOCK_NO_BORESIGHT; return; } } else { // // this should never happen // debug_colour_log (DEBUG_COLOUR_RED, "WARNING! Target and weapon vectors are not valid"); } } //////////////////////////////////////// // // WEAPON_LOCK_MIN_RANGE // WEAPON_LOCK_MAX_RANGE // //////////////////////////////////////// source_position = get_local_entity_vec3d_ptr (source, VEC3D_TYPE_POSITION); target_position = get_local_entity_vec3d_ptr (target, VEC3D_TYPE_POSITION); target_range = get_3d_range (source_position, target_position); weapon_min_range = weapon_database[selected_weapon_type].min_range; if (weapon_database[selected_weapon_type].hellfire_flight_profile) { if (get_local_entity_int_value (source, INT_TYPE_LOCK_ON_AFTER_LAUNCH)) { weapon_min_range = weapon_database[selected_weapon_type].min_range_loal; } } if (target_range < weapon_min_range) { weapon_lock_type = WEAPON_LOCK_MIN_RANGE; return; } weapon_max_range = weapon_database[selected_weapon_type].max_range; if (weapon_database[selected_weapon_type].hellfire_flight_profile) { if (get_local_entity_int_value (source, INT_TYPE_LOCK_ON_AFTER_LAUNCH)) { weapon_max_range = weapon_database[selected_weapon_type].max_range_loal; } } if (target_range > weapon_max_range) { weapon_lock_type = WEAPON_LOCK_MAX_RANGE; return; } //////////////////////////////////////// // // WEAPON_LOCK_VALID // //////////////////////////////////////// weapon_lock_type = WEAPON_LOCK_VALID; }
entity *get_free_entity (int index) { entity *en; if (index == ENTITY_INDEX_DONT_CARE) { en = first_free_entity; if (en) { // // unlink entity from start of free list // first_free_entity = en->succ; if (en->succ) { en->succ->pred = NULL; } // // insert entity into start of used list (en->pred already set to NULL) // en->succ = first_used_entity; if (en->succ) { en->succ->pred = en; } first_used_entity = en; } else { debug_colour_log (DEBUG_COLOUR_RED, "WARNING! Failed to get a free entity"); } } else { ASSERT ((index >= 0) && (index < number_of_entities)); en = get_local_entity_ptr (index); if (get_local_entity_type (en) != ENTITY_TYPE_UNKNOWN) { debug_fatal ("Entity already in use: %s (index = %d)", get_local_entity_type_name (en), index); } // // unlink entity from free list // if (en->pred) { en->pred->succ = en->succ; } else { first_free_entity = en->succ; } if (en->succ) { en->succ->pred = en->pred; } // // insert entity into start of used list // en->succ = first_used_entity; if (en->succ) { en->succ->pred = en; } en->pred = NULL; first_used_entity = en; } //debug_log ("EN_HEAP: index %d", get_local_entity_index (en)); return (en); }
void dump_aircraft_and_vehicle_count (void) { entity *en; entity_sub_types sub_type; int total_count, total_blue_aircraft_count, total_blue_vehicle_count, total_red_aircraft_count, total_red_vehicle_count, blue_aircraft_count[NUM_ENTITY_SUB_TYPE_AIRCRAFT], blue_vehicle_count[NUM_ENTITY_SUB_TYPE_VEHICLES], red_aircraft_count[NUM_ENTITY_SUB_TYPE_AIRCRAFT], red_vehicle_count[NUM_ENTITY_SUB_TYPE_VEHICLES]; total_count = 0; total_blue_aircraft_count = 0; total_blue_vehicle_count = 0; total_red_aircraft_count = 0; total_red_vehicle_count = 0; memset (blue_aircraft_count, 0, sizeof (blue_aircraft_count)); memset (blue_vehicle_count, 0, sizeof (blue_vehicle_count)); memset (red_aircraft_count, 0, sizeof (red_aircraft_count)); memset (red_vehicle_count, 0, sizeof (red_vehicle_count)); en = first_used_entity; while (en) { sub_type = get_local_entity_int_value (en, INT_TYPE_ENTITY_SUB_TYPE); if (get_local_entity_int_value (en, INT_TYPE_IDENTIFY_AIRCRAFT)) { ASSERT (entity_sub_type_aircraft_valid (sub_type)); if (get_local_entity_int_value (en, INT_TYPE_SIDE) == ENTITY_SIDE_BLUE_FORCE) { total_count++; blue_aircraft_count[sub_type]++; total_blue_aircraft_count++; } else if (get_local_entity_int_value (en, INT_TYPE_SIDE) == ENTITY_SIDE_RED_FORCE) { total_count++; red_aircraft_count[sub_type]++; total_red_aircraft_count++; } } else if (get_local_entity_int_value (en, INT_TYPE_IDENTIFY_VEHICLE)) { ASSERT (entity_sub_type_vehicle_valid (get_local_entity_int_value (en, INT_TYPE_ENTITY_SUB_TYPE))); if (get_local_entity_int_value (en, INT_TYPE_SIDE) == ENTITY_SIDE_BLUE_FORCE) { total_count++; blue_vehicle_count[sub_type]++; total_blue_vehicle_count++; } else if (get_local_entity_int_value (en, INT_TYPE_SIDE) == ENTITY_SIDE_RED_FORCE) { total_count++; red_vehicle_count[sub_type]++; total_red_vehicle_count++; } } en = get_local_entity_succ (en); } debug_colour_log (DEBUG_COLOUR_AMBER, "====================================="); debug_colour_log (DEBUG_COLOUR_AMBER, "START FORCE COUNT (total = %d)", total_count); debug_colour_log (DEBUG_COLOUR_AMBER, "====================================="); //////////////////////////////////////// debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------"); debug_colour_log (DEBUG_COLOUR_AMBER, "BLUE AIRCRAFT (total = %d)", total_blue_aircraft_count); debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------"); for (sub_type = 0; sub_type < NUM_ENTITY_SUB_TYPE_AIRCRAFT; sub_type++) { if (get_aircraft_side (sub_type) == ENTITY_SIDE_BLUE_FORCE) { debug_colour_log (DEBUG_COLOUR_AMBER, "%4dx %s", blue_aircraft_count[sub_type], entity_sub_type_aircraft_names[sub_type]); } } //////////////////////////////////////// debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------"); debug_colour_log (DEBUG_COLOUR_AMBER, "BLUE VEHICLES (total = %d)", total_blue_vehicle_count); debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------"); for (sub_type = 0; sub_type < NUM_ENTITY_SUB_TYPE_VEHICLES; sub_type++) { if (get_vehicle_side (sub_type) == ENTITY_SIDE_BLUE_FORCE) { debug_colour_log (DEBUG_COLOUR_AMBER, "%4dx %s", blue_vehicle_count[sub_type], entity_sub_type_vehicle_names[sub_type]); } } //////////////////////////////////////// debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------"); debug_colour_log (DEBUG_COLOUR_AMBER, "RED AIRCRAFT (total = %d)", total_red_aircraft_count); debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------"); for (sub_type = 0; sub_type < NUM_ENTITY_SUB_TYPE_AIRCRAFT; sub_type++) { if (get_aircraft_side (sub_type) == ENTITY_SIDE_RED_FORCE) { debug_colour_log (DEBUG_COLOUR_AMBER, "%4dx %s", red_aircraft_count[sub_type], entity_sub_type_aircraft_names[sub_type]); } } //////////////////////////////////////// debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------"); debug_colour_log (DEBUG_COLOUR_AMBER, "RED VEHICLES (total = %d)", total_red_vehicle_count); debug_colour_log (DEBUG_COLOUR_AMBER, "-------------------------------------"); for (sub_type = 0; sub_type < NUM_ENTITY_SUB_TYPE_VEHICLES; sub_type++) { if (get_vehicle_side (sub_type) == ENTITY_SIDE_RED_FORCE) { debug_colour_log (DEBUG_COLOUR_AMBER, "%4dx %s", red_vehicle_count[sub_type], entity_sub_type_vehicle_names[sub_type]); } } //////////////////////////////////////// debug_colour_log (DEBUG_COLOUR_AMBER, "====================================="); debug_colour_log (DEBUG_COLOUR_AMBER, "END FORCE COUNT"); debug_colour_log (DEBUG_COLOUR_AMBER, "====================================="); }
void display_entity_system_statistics (void) { debug_colour_log (DEBUG_COLOUR_RED, "WARNING! Entity system statistics are not enabled"); }