diff --git a/code/ai/aicode.cpp b/code/ai/aicode.cpp index 693506786b..22162764f4 100644 --- a/code/ai/aicode.cpp +++ b/code/ai/aicode.cpp @@ -359,9 +359,9 @@ void ai_good_secondary_time( int team, int weapon_index, int max_fire_count, cha // which can be fired on target_objp int is_preferred_weapon(int weapon_num, object *firer_objp, object *target_objp) { - int i, firer_team, target_signature; + int firer_team, target_signature; ship *firer_ship; - huge_fire_info *hfi = NULL; + SCP_vector::iterator hfi; Assert( firer_objp->type == OBJ_SHIP ); firer_ship = &Ships[firer_objp->instance]; @@ -369,10 +369,9 @@ int is_preferred_weapon(int weapon_num, object *firer_objp, object *target_objp) // get target object's signature and try to find it in the list. target_signature = target_objp->signature; - for ( i = 0; i < (int)Ai_huge_fire_info.size(); i++ ) { + for (hfi = Ai_huge_fire_info.begin();hfi != Ai_huge_fire_info.end(); ++hfi ) { int ship_index, signature; - hfi = &Ai_huge_fire_info[i]; if ( hfi->weapon_index == -1 ) continue; @@ -388,7 +387,7 @@ int is_preferred_weapon(int weapon_num, object *firer_objp, object *target_objp) } // return -1 if not found - if ( i == (int)Ai_huge_fire_info.size() ) + if ( hfi == Ai_huge_fire_info.end() ) return -1; // otherwise, we can return the max number of weapons we can fire against target_objps diff --git a/code/asteroid/asteroid.cpp b/code/asteroid/asteroid.cpp index de7988ca19..956ec3c0ec 100644 --- a/code/asteroid/asteroid.cpp +++ b/code/asteroid/asteroid.cpp @@ -603,8 +603,9 @@ void asteroid_level_init() Num_asteroids = 0; Next_asteroid_throw = timestamp(1); asteroid_obj_list_init(); - for (size_t t=0; t::iterator ast; + for (ast = Asteroid_info.begin(); ast != Asteroid_info.end(); ++ast) + ast->damage_type_idx = ast->damage_type_idx_sav; } // return !0 if asteroid should be wrapped, 0 otherwise. Multiplayer clients will always return diff --git a/code/autopilot/autopilot.cpp b/code/autopilot/autopilot.cpp index 9ac9477f64..857e9ee040 100644 --- a/code/autopilot/autopilot.cpp +++ b/code/autopilot/autopilot.cpp @@ -372,8 +372,7 @@ bool StartAutopilot() { capshipPresent = true; - capIndexes.resize(capIndexes.size()+1); - capIndexes[capIndexes.size()-1] = i; + capIndexes.push_back(i); // ok.. what size class if (Ship_info[Ships[i].ship_info_index].flags & (SIF_CAPITAL | SIF_SUPERCAP)) @@ -559,13 +558,13 @@ bool StartAutopilot() // position capships vec3d right, front, up, offset; - for (i = 0; i < (int)capIndexes.size(); i++) + for (SCP_vector::iterator idx = capIndexes.begin(); idx != capIndexes.end(); idx++) { vm_vec_add(&right, &Autopilot_flight_leader->orient.vec.rvec, &zero); vm_vec_add(&front, &Autopilot_flight_leader->orient.vec.fvec, &zero); vm_vec_add(&up, &Autopilot_flight_leader->orient.vec.uvec, &zero); vm_vec_add(&offset, &zero, &zero); - if (Ship_info[Ships[capIndexes[i]].ship_info_index].flags & (SIF_CAPITAL | SIF_SUPERCAP)) + if (Ship_info[Ships[*idx].ship_info_index].flags & (SIF_CAPITAL | SIF_SUPERCAP)) { //0 - below - three lines of position @@ -599,7 +598,7 @@ bool StartAutopilot() capship_placed[0]++; } - else if (Ship_info[Ships[capIndexes[i]].ship_info_index].flags & SIF_CORVETTE) + else if (Ship_info[Ships[*idx].ship_info_index].flags & SIF_CORVETTE) { //1 above - 3 lines of position // front/back to zero @@ -708,7 +707,7 @@ bool StartAutopilot() // global scale the position by 50% //vm_vec_scale(&offset, 1.5); - vm_vec_add(&Objects[Ships[capIndexes[i]].objnum].pos, &Autopilot_flight_leader->pos, &offset); + vm_vec_add(&Objects[Ships[*idx].objnum].pos, &Autopilot_flight_leader->pos, &offset); if (vm_vec_dist_quick(&Autopilot_flight_leader->pos, &Objects[Ships[i].objnum].pos) > distance) { diff --git a/code/camera/camera.cpp b/code/camera/camera.cpp index 0a5552d496..5e0415ade0 100644 --- a/code/camera/camera.cpp +++ b/code/camera/camera.cpp @@ -791,9 +791,10 @@ void subtitle::do_frame(float frametime) int x = text_pos.x; int y = text_pos.y; - for(unsigned int i = 0; i < text_lines.size(); i++) + + for(SCP_vector::iterator line = text_lines.begin(); line != text_lines.end(); line++) { - gr_string(x, y, (char*)text_lines[i].c_str(), false); + gr_string(x, y, (char*)line->c_str(), false); y += font_height; } @@ -843,11 +844,8 @@ subtitle::~subtitle() void subtitle::clone(const subtitle &sub) { - uint i = 0; - for (i = 0; i < sub.text_lines.size(); i++) { - text_lines.push_back(sub.text_lines[i]); - } + text_lines = sub.text_lines; text_fontnum = sub.text_fontnum; // copy the structs @@ -944,14 +942,6 @@ void cam_close() { //Set Current_camera to nothing Current_camera = camid(); - for(unsigned int i = 0; i < Cameras.size(); i++) - { - if(Cameras[i] != NULL) - { - delete Cameras[i]; - Cameras[i] = NULL; - } - } Cameras.clear(); } @@ -984,29 +974,9 @@ camid cam_create(char *n_name, vec3d *n_pos, matrix *n_ori, object *n_object, in strncpy(buf, n_name, NAME_LENGTH-1); //Find a free slot - for(uint i = 0; i < Cameras.size(); i++) - { - if(Cameras[i] == NULL) - { - cam = new camera(buf, sig); - cid = camid(i, sig); - Cameras[i] = cam; - break; - } - else if(Cameras[i]->is_empty()) - { - delete Cameras[i]; - cam = new camera(buf, sig); - cid = camid(i, sig); - Cameras[i] = cam; - } - } - if(cam == NULL) - { - cam = new camera(buf, sig); - cid = camid(Cameras.size(), sig); - Cameras.push_back(cam); - } + cam = new camera(buf, sig); + cid = camid(Cameras.size(), sig); + Cameras.push_back(cam); //Set attributes if(n_pos != NULL) @@ -1134,20 +1104,20 @@ void subtitles_close() void subtitles_do_frame(float frametime) { - unsigned int i,size=Subtitles.size(); - for(i = 0; i < size; i++) + SCP_vector::iterator sub; + for(sub = Subtitles.begin(); sub != Subtitles.end(); sub++) { - if ( !Subtitles[i].is_post_shaded( ) ) - Subtitles[i].do_frame(frametime); + if ( !sub->is_post_shaded( ) ) + sub->do_frame(frametime); } } void subtitles_do_frame_post_shaded(float frametime) { - unsigned int i,size=Subtitles.size(); - for(i = 0; i < size; i++) + SCP_vector::iterator sub; + for(sub = Subtitles.begin(); sub != Subtitles.end(); sub++) { - if ( Subtitles[i].is_post_shaded( ) ) - Subtitles[i].do_frame(frametime); + if ( sub->is_post_shaded( ) ) + sub->do_frame(frametime); } } \ No newline at end of file diff --git a/code/cfile/cfilesystem.cpp b/code/cfile/cfilesystem.cpp index 6b35fe9b7a..49f46a2eca 100644 --- a/code/cfile/cfilesystem.cpp +++ b/code/cfile/cfilesystem.cpp @@ -1214,17 +1214,10 @@ int cf_find_file_location_ext( char *filename, const int ext_num, const char **e file_list_index.push_back( f ); } - size_t file_list_size = file_list_index.size(); - - // quick exit test - if (file_list_size < 1) - goto Bail; - - // now try and find our preferred match for (cur_ext = 0; cur_ext < ext_num; cur_ext++) { - for (size_t i = 0; i < file_list_size; i++) { - cf_file *f = file_list_index[i]; + for (SCP_vector::iterator fli = file_list_index.begin(); fli != file_list_index.end(); fli++) { + cf_file *f = *fli; strcat_s( filespec, ext_list[cur_ext] ); @@ -1303,10 +1296,6 @@ int cf_find_file_location_ext( char *filename, const int ext_num, const char **e } } -Bail: - // didn't find anything, bail... - file_list_index.clear(); - return -1; } diff --git a/code/cutscene/cutscenes.cpp b/code/cutscene/cutscenes.cpp index 2bcf3d373f..2080b9829e 100644 --- a/code/cutscene/cutscenes.cpp +++ b/code/cutscene/cutscenes.cpp @@ -42,13 +42,9 @@ SCP_vector Cutscenes; //extern int All_movies_enabled; // If set, all movies may be viewed. Keyed off cheat code. void cutscene_close() { - for(size_t i = 0; i < Cutscenes.size(); i++) - { - if(Cutscenes[i].description) - { - vm_free(Cutscenes[i].description); - } - } + for(SCP_vector::iterator cut = Cutscenes.begin(); cut != Cutscenes.end(); cut++) + if(cut->description) + vm_free(cut->description); } // initialization stuff for cutscenes @@ -110,9 +106,9 @@ void cutscene_init() // returns -1 on failure. int cutscenes_get_cd_num( char *filename ) { - for (size_t i = 0; i < Cutscenes.size(); i++ ) { - if ( !stricmp(Cutscenes[i].filename, filename) ) { - return (Cutscenes[i].cd - 1); + for (SCP_vector::iterator cut = Cutscenes.begin(); cut != Cutscenes.end(); cut++) { + if ( !stricmp(cut->filename, filename) ) { + return (cut->cd - 1); } } @@ -136,10 +132,10 @@ void cutscene_mark_viewable(char *filename) // change to lower case strlwr(file); - - for (size_t i = 0; i < Cutscenes.size(); i++ ) { + int i = 0; + for (SCP_vector::iterator cut = Cutscenes.begin(); cut != Cutscenes.end(); cut++) { // change the cutscene file name to lower case - strcpy_s(cut_file, Cutscenes[i].filename); + strcpy_s(cut_file, cut->filename); strlwr(cut_file); // see if the stripped filename matches the cutscene filename @@ -147,6 +143,7 @@ void cutscene_mark_viewable(char *filename) Cutscenes_viewable |= (1<instance].model_instance_num); // turn off all rotating submodels and test for collision - for (size_t j=0; jsubmodel[submodel_vector[j]].collision_checked = true; + for (SCP_vector::iterator smv = submodel_vector.begin(); smv != submodel_vector.end(); smv++) { + pmi->submodel[*smv].collision_checked = true; } // reset flags to check MC_CHECK_MODEL | MC_CHECK_SPHERELINE and maybe MC_CHECK_INVISIBLE_FACES and MC_SUBMODEL_INSTANCE mc.flags = copy_flags | MC_SUBMODEL_INSTANCE; // check each submodel in turn - for (size_t i=0; i::iterator smv = submodel_vector.begin(); smv != submodel_vector.end(); smv++) { // turn on submodel for collision test - pmi->submodel[submodel_vector[i]].collision_checked = false; + pmi->submodel[*smv].collision_checked = false; // set angles for last frame (need to set to prev to get p0) - angles copy_angles = pmi->submodel[submodel_vector[i]].angs; + angles copy_angles = pmi->submodel[*smv].angs; // find the start and end positions of the sphere in submodel RF - pmi->submodel[submodel_vector[i]].angs = pmi->submodel[submodel_vector[i]].prev_angs; - world_find_model_instance_point(&p0, &light_obj->last_pos, pm, pmi, submodel_vector[i], &heavy_obj->last_orient, &heavy_obj->last_pos); + pmi->submodel[*smv].angs = pmi->submodel[*smv].prev_angs; + world_find_model_instance_point(&p0, &light_obj->last_pos, pm, pmi, *smv, &heavy_obj->last_orient, &heavy_obj->last_pos); - pmi->submodel[submodel_vector[i]].angs = copy_angles; - world_find_model_instance_point(&p1, &light_obj->pos, pm, pmi, submodel_vector[i], &heavy_obj->orient, &heavy_obj->pos); + pmi->submodel[*smv].angs = copy_angles; + world_find_model_instance_point(&p1, &light_obj->pos, pm, pmi, *smv, &heavy_obj->orient, &heavy_obj->pos); mc.p0 = &p0; mc.p1 = &p1; // mc.pos = zero // in submodel RF mc.orient = &vmd_identity_matrix; - mc.submodel_num = submodel_vector[i]; + mc.submodel_num = *smv; if ( model_collide(&mc) ) { if ( mc.hit_dist < debris_hit_info->hit_time ) { @@ -991,7 +991,7 @@ int debris_check_collision(object *pdebris, object *other_obj, vec3d *hitpos, co } } // Don't look at this submodel again - pmi->submodel[submodel_vector[i]].collision_checked = true; + pmi->submodel[*smv].collision_checked = true; } } diff --git a/code/fireball/fireballs.cpp b/code/fireball/fireballs.cpp index 8556f40111..0f799384db 100644 --- a/code/fireball/fireballs.cpp +++ b/code/fireball/fireballs.cpp @@ -239,7 +239,7 @@ void parse_fireball_tbl(char *filename) void fireball_parse_tbl() { - int i, j; + int i = 0 , j; memset( &Fireball_info, 0, sizeof(fireball_info) * MAX_FIREBALL_TYPES ); @@ -251,10 +251,10 @@ void fireball_parse_tbl() // we've got our list so pass it off for final checking and loading. // we assume that entries in fireball.tbl are in the correct order - for (i = 0; i < (int)LOD_checker.size(); i++) { - if ( (i < MAX_FIREBALL_TYPES) && (LOD_checker[i].override < 0) ) { - strcpy_s( Fireball_info[i].lod[0].filename, LOD_checker[i].filename ); - Fireball_info[i].lod_count = LOD_checker[i].num_lods; + for (SCP_vector::iterator lod = LOD_checker.begin(); lod != LOD_checker.end(); lod++) { + if ( (i < MAX_FIREBALL_TYPES) && (lod->override < 0) ) { + strcpy_s( Fireball_info[i].lod[0].filename, lod->filename ); + Fireball_info[i].lod_count = lod->num_lods; Num_fireball_types++; if (LOD_color[i].alpha == 255) { @@ -265,22 +265,24 @@ void fireball_parse_tbl() fireball_set_default_color(i); } } + i++; } // having to do this twice is less than optimal, but less error prone too. // this handles (and should only have to handle) TBM related entries - for (i = 0; i < (int)LOD_checker.size(); i++) { + i = 0; + for (SCP_vector::iterator lod = LOD_checker.begin(); lod != LOD_checker.end(); lod++) { // try entry replacement - if ( (LOD_checker[i].override >= 0) && (LOD_checker[i].override < Num_fireball_types) ) { - strcpy_s( Fireball_info[LOD_checker[i].override].lod[0].filename, LOD_checker[i].filename ); - Fireball_info[LOD_checker[i].override].lod_count = LOD_checker[i].num_lods; + if ( (lod->override >= 0) && (lod->override < Num_fireball_types) ) { + strcpy_s( Fireball_info[lod->override].lod[0].filename, lod->filename ); + Fireball_info[lod->override].lod_count = lod->num_lods; if (LOD_color[i].alpha == 255) { - Fireball_info[LOD_checker[i].override].exp_color[0] = (LOD_color[i].red / 255.0f); - Fireball_info[LOD_checker[i].override].exp_color[1] = (LOD_color[i].green / 255.0f); - Fireball_info[LOD_checker[i].override].exp_color[2] = (LOD_color[i].blue / 255.0f); + Fireball_info[lod->override].exp_color[0] = (LOD_color[i].red / 255.0f); + Fireball_info[lod->override].exp_color[1] = (LOD_color[i].green / 255.0f); + Fireball_info[lod->override].exp_color[2] = (LOD_color[i].blue / 255.0f); } else { - fireball_set_default_color(LOD_checker[i].override); + fireball_set_default_color(lod->override); } } } diff --git a/code/fs2netd/fs2netd_client.cpp b/code/fs2netd/fs2netd_client.cpp index 512b05a7a8..41639fca2e 100644 --- a/code/fs2netd/fs2netd_client.cpp +++ b/code/fs2netd/fs2netd_client.cpp @@ -1183,8 +1183,8 @@ void fs2netd_update_ban_list() CFILE *banlist_cfg = cfopen("banlist.cfg", "wt", CFILE_NORMAL, CF_TYPE_DATA); if (banlist_cfg != NULL) { - for (uint i = 0; i < FS2NetD_ban_list.size(); i++) { - cfputs( const_cast(FS2NetD_ban_list[i].c_str()), banlist_cfg ); + for (SCP_vector::iterator bl = FS2NetD_ban_list.begin(); bl != FS2NetD_ban_list.end(); bl++) { + cfputs( const_cast(bl->c_str()), banlist_cfg ); } cfclose(banlist_cfg); @@ -1267,7 +1267,6 @@ int fs2netd_get_valid_missions_do() char valid_status = MVALID_STATUS_UNKNOWN; char full_name[MAX_FILENAME_LEN], wild_card[10]; char val_text[MAX_FILENAME_LEN+15]; - int i; uint checksum = 0; if (file_names == NULL) { @@ -1332,9 +1331,9 @@ int fs2netd_get_valid_missions_do() found = false; if (file_index >= 0) { - for (i = 0; (i < (int)FS2NetD_file_list.size()) && (!found); i++) { - if ( !stricmp(full_name, FS2NetD_file_list[i].name) ) { - if (FS2NetD_file_list[i].crc32 == checksum) { + for (SCP_vector::iterator fr = FS2NetD_file_list.begin(); fr != FS2NetD_file_list.end() && !found; fr++) { + if ( !stricmp(full_name, fr->name) ) { + if (fr->crc32 == checksum) { found = true; valid_status = MVALID_STATUS_VALID; } else { @@ -1512,11 +1511,11 @@ int fs2netd_update_valid_tables() } // output the status of table validity to multi.log - for (uint i = 0; i < Table_valid_status.size(); i++) { - if (Table_valid_status[i].valid) { - ml_printf("FS2NetD Table Check: '%s' -- Valid!", Table_valid_status[i].name); + for (SCP_vector::iterator tvs = Table_valid_status.begin(); tvs != Table_valid_status.end(); tvs++) { + if (tvs->valid) { + ml_printf("FS2NetD Table Check: '%s' -- Valid!", tvs->name); } else { - ml_printf("FS2NetD Table Check: '%s' -- INVALID (0x%x)!", Table_valid_status[i].name, Table_valid_status[i].crc32); + ml_printf("FS2NetD Table Check: '%s' -- INVALID (0x%x)!", tvs->name, tvs->crc32); hacked = 1; } } @@ -1645,7 +1644,7 @@ void fs2netd_update_game_count(char *chan_name) void fs2netd_spew_table_checksums(char *outfile) { char full_name[MAX_PATH_LEN]; - int count, idx; + int count; FILE *out = NULL; char description[512] = { 0 }; char filename[65] = { 0 }; @@ -1684,9 +1683,9 @@ void fs2netd_spew_table_checksums(char *outfile) count = (int)Table_valid_status.size(); // do all the checksums - for (idx = 0; idx < count; idx++) { + for (SCP_vector::iterator tvs = Table_valid_status.begin(); tvs != Table_valid_status.end(); tvs++) { offset = 0; - p = Table_valid_status[idx].name; + p = tvs->name; while (*p && (offset < sizeof(filename))) { if (*p == '"') { @@ -1701,7 +1700,7 @@ void fs2netd_spew_table_checksums(char *outfile) filename[offset] = '\0'; - fprintf(out, "\"%s\",%u,\"%s\"\r\n", filename, Table_valid_status[idx].crc32, description); + fprintf(out, "\"%s\",%u,\"%s\"\r\n", filename, tvs->crc32, description); } fflush(out); diff --git a/code/fs2netd/tcp_client.cpp b/code/fs2netd/tcp_client.cpp index ffbb714bec..e971fa67a9 100644 --- a/code/fs2netd/tcp_client.cpp +++ b/code/fs2netd/tcp_client.cpp @@ -686,7 +686,6 @@ int FS2NetD_ValidateTableList(bool do_send) int buffer_size, buffer_offset; bool my_packet = false; char buffer[4096]; - uint i; ushort num_tables = 0; if (do_send) { @@ -697,9 +696,9 @@ int FS2NetD_ValidateTableList(bool do_send) PXO_ADD_USHORT( num_tables ); - for (i = 0; i < Table_valid_status.size(); i++) { - PXO_ADD_STRING( Table_valid_status[i].name ); - PXO_ADD_UINT( Table_valid_status[i].crc32 ); + for (SCP_vector::iterator tvs = Table_valid_status.begin(); tvs != Table_valid_status.end(); tvs++) { + PXO_ADD_STRING(tvs->name ); + PXO_ADD_UINT( tvs->crc32 ); } DONE_PACKET(); @@ -761,11 +760,11 @@ int FS2NetD_ValidateTableList(bool do_send) return -1; } - for (i = 0; i < Table_valid_status.size(); i++) { + for (SCP_vector::iterator tvs = Table_valid_status.begin(); tvs != Table_valid_status.end(); tvs++) { PXO_GET_DATA( tbl_valid_status ); Assert( (tbl_valid_status == 0) || (tbl_valid_status == 1) ); - Table_valid_status[i].valid = tbl_valid_status; + tvs->valid = tbl_valid_status; } return 2; diff --git a/code/gamesnd/gamesnd.cpp b/code/gamesnd/gamesnd.cpp index f0987b044d..426b8f470a 100644 --- a/code/gamesnd/gamesnd.cpp +++ b/code/gamesnd/gamesnd.cpp @@ -39,20 +39,22 @@ void gamesnd_play_iface(int n) int gamesnd_get_by_name(char* name) { Assert( Snds.size() <= INT_MAX ); - for(int i = 0; i < (int)Snds.size(); i++) + int i = 0; + for(SCP_vector::iterator snd = Snds.begin(); snd != Snds.end(); snd++) { - char *p = strrchr( Snds[i].filename, '.' ); + char *p = strrchr( snd->filename, '.' ); if(p == NULL) { - if(!stricmp(Snds[i].filename, name)) + if(!stricmp(snd->filename, name)) { return i; } } - else if(!strnicmp(Snds[i].filename, name, p-Snds[i].filename)) + else if(!strnicmp(snd->filename, name, p-snd->filename)) { return i; } + i++; } return -1; } @@ -63,11 +65,13 @@ int gamesnd_get_by_tbl_index(int index) if (index == -1) return -1; Assert( Snds.size() <= INT_MAX ); - for(int i = 0; i < (int)Snds.size(); i++) { - if ( Snds[i].sig == index ) + int i = 0; + for(SCP_vector::iterator snd = Snds.begin(); snd != Snds.end(); snd++) { + if ( snd->sig == index ) { return i; } + i++; } return -1; } @@ -76,11 +80,13 @@ int gamesnd_get_by_iface_tbl_index(int index) { Assert( Snds_iface.size() <= INT_MAX ); Assert( Snds_iface.size() == Snds_iface_handle.size() ); - for(int i = 0; i < (int)Snds_iface.size(); i++) { - if ( Snds_iface[i].sig == index ) + int i = 0; + for(SCP_vector::iterator snd = Snds.begin(); snd != Snds.end(); snd++) { + if ( snd->sig == index ) { return i; } + i++; } return -1; } @@ -125,19 +131,15 @@ void parse_sound(char* tag, int *idx_dest, char* object_name) // fly (too slow). void gamesnd_preload_common_sounds() { - int i; - game_snd *gs; - if ( !Sound_enabled ) return; Assert( Snds.size() <= INT_MAX ); - for ( i = 0; i < (int)Snds.size(); i++ ) { - gs = &Snds[i]; + for (SCP_vector::iterator gs = Snds.begin(); gs != Snds.end(); gs++) { if ( gs->filename[0] != 0 && strnicmp(gs->filename, NOX("none.wav"), 4) ) { if ( gs->preload ) { game_busy( NOX("** preloading common game sounds **") ); // Animate loading cursor... does nothing if loading screen not active. - gs->id = snd_load(gs); + gs->id = snd_load(&(*gs)); } } } @@ -150,19 +152,15 @@ void gamesnd_preload_common_sounds() // void gamesnd_load_gameplay_sounds() { - int i; - game_snd *gs; - if ( !Sound_enabled ) return; Assert( Snds.size() <= INT_MAX ); - for ( i = 0; i < (int)Snds.size(); i++ ) { - gs = &Snds[i]; + for (SCP_vector::iterator gs = Snds.begin(); gs != Snds.end(); gs++) { if ( gs->filename[0] != 0 && strnicmp(gs->filename, NOX("none.wav"), 4) ) { if ( !gs->preload ) { // don't try to load anything that's already preloaded game_busy( NOX("** preloading gameplay sounds **") ); // Animate loading cursor... does nothing if loading screen not active. - gs->id = snd_load(gs); + gs->id = snd_load(&(*gs)); } } } @@ -175,12 +173,8 @@ void gamesnd_load_gameplay_sounds() // void gamesnd_unload_gameplay_sounds() { - int i; - game_snd *gs; - Assert( Snds.size() <= INT_MAX ); - for ( i = 0; i < (int)Snds.size(); i++ ) { - gs = &Snds[i]; + for (SCP_vector::iterator gs = Snds.begin(); gs != Snds.end(); gs++) { if ( gs->id != -1 ) { snd_unload( gs->id ); gs->id = -1; @@ -195,17 +189,13 @@ void gamesnd_unload_gameplay_sounds() // void gamesnd_load_interface_sounds() { - int i; - game_snd *gs; - if ( !Sound_enabled ) return; Assert( Snds_iface.size() < INT_MAX ); - for ( i = 0; i < (int)Snds_iface.size(); i++ ) { - gs = &Snds_iface[i]; - if ( gs->filename[0] != 0 && strnicmp(gs->filename, NOX("none.wav"), 4) ) { - gs->id = snd_load(gs); + for (SCP_vector::iterator si = Snds_iface.begin(); si != Snds_iface.end(); si++) { + if ( si->filename[0] != 0 && strnicmp(si->filename, NOX("none.wav"), 4) ) { + si->id = snd_load(&(*si)); } } } @@ -217,16 +207,12 @@ void gamesnd_load_interface_sounds() // void gamesnd_unload_interface_sounds() { - int i; - game_snd *gs; - Assert( Snds_iface.size() < INT_MAX ); - for ( i = 0; i < (int)Snds_iface.size(); i++ ) { - gs = &Snds_iface[i]; - if ( gs->id != -1 ) { - snd_unload( gs->id ); - gs->id = -1; - gs->id_sig = -1; + for (SCP_vector::iterator si = Snds_iface.begin(); si != Snds_iface.end(); si++) { + if ( si->id != -1 ) { + snd_unload( si->id ); + si->id = -1; + si->id_sig = -1; } } } @@ -522,7 +508,7 @@ void gamesnd_init_struct(game_snd *gs) // void gamesnd_init_sounds() { - int i; + int i = 0; Snds.clear(); Snds.resize(MIN_GAME_SOUNDS); @@ -531,8 +517,8 @@ void gamesnd_init_sounds() Assert( Snds.size() <= INT_MAX ); // init the gameplay sounds - for ( i = 0; i < (int)Snds.size(); i++ ) { - gamesnd_init_struct(&Snds[i]); + for (SCP_vector::iterator gs = Snds.begin(); gs != Snds.end(); gs++) { + gamesnd_init_struct(&(*gs)); } Snds_iface.clear(); @@ -543,9 +529,11 @@ void gamesnd_init_sounds() Assert( Snds_iface.size() < INT_MAX ); // init the interface sounds - for ( i = 0; i < (int)Snds_iface.size(); i++ ) { - gamesnd_init_struct(&Snds_iface[i]); + + for (SCP_vector::iterator si = Snds_iface.begin(); si != Snds_iface.end(); si++) { + gamesnd_init_struct(&(*si)); Snds_iface_handle[i] = -1; + i++; } } diff --git a/code/lighting/lighting.cpp b/code/lighting/lighting.cpp index a2993fcd1f..8111f1a257 100644 --- a/code/lighting/lighting.cpp +++ b/code/lighting/lighting.cpp @@ -392,7 +392,8 @@ void light_add_point_unique( vec3d * pos, float r1, float r2, float intensity, f }*/ } -// for now, tube lights only affect one ship (to keep the filter stuff simple) +// beams affect every ship except the firing ship +extern int Use_GLSL; void light_add_tube(vec3d *p0, vec3d *p1, float r1, float r2, float intensity, float r, float g, float b, int affected_objnum, float spec_r, float spec_g, float spec_b, bool specular ) { Assert(r1 >0); @@ -431,8 +432,8 @@ void light_add_tube(vec3d *p0, vec3d *p1, float r1, float r2, float intensity, f l->radb = r2; l->rada_squared = l->rada*l->rada; l->radb_squared = l->radb*l->radb; - l->light_ignore_objnum = -1; - l->affected_objnum = affected_objnum; + l->light_ignore_objnum = Use_GLSL>1 ?affected_objnum : -1; + l->affected_objnum = Use_GLSL>1 ? -1 : affected_objnum; l->instance = Num_lights-1; Assert( Num_light_levels <= 1 ); @@ -529,9 +530,23 @@ int light_filter_push( int objnum, vec3d *pos, float rad ) // hmm. this could probably be more optimal case LT_TUBE: - // all tubes are "unique" light sources for now - if((l->affected_objnum >= 0) && (objnum == l->affected_objnum)){ - Relevent_lights[Num_relevent_lights[n2]++][n2] = l; + if(Use_GLSL > 1) { + if(l->light_ignore_objnum != objnum){ + vec3d nearest; + float dist_squared, max_dist_squared; + vm_vec_dist_squared_to_line(pos,&l->vec,&l->vec2,&nearest,&dist_squared); + + max_dist_squared = l->radb+rad; + max_dist_squared *= max_dist_squared; + + if ( dist_squared < max_dist_squared ) + Relevent_lights[Num_relevent_lights[n2]++][n2] = l; + } + } + else { + // all tubes are "unique" light sources for now + if((l->affected_objnum >= 0) && (objnum == l->affected_objnum)) + Relevent_lights[Num_relevent_lights[n2]++][n2] = l; } break; diff --git a/code/math/fvi.cpp b/code/math/fvi.cpp index 2a568b20c9..f40bd90c98 100644 --- a/code/math/fvi.cpp +++ b/code/math/fvi.cpp @@ -1010,8 +1010,9 @@ int fvi_polyedge_sphereline(vec3d *hit_point, vec3d *xs0, vec3d *vs, float Rs, i discriminant = B*B - 4*A*C; if (discriminant > 0) { root = fl_sqrt(discriminant); - root1 = (float) ((-B + root)/(2*A)); - root2 = (float) ((-B - root)/(2*A)); + float inv2A = 1.0f/(2*A); + root1 = (float) ((-B + root)*inv2A); + root2 = (float) ((-B - root)*inv2A); // sort root1 and root2 @@ -1056,8 +1057,9 @@ int fvi_polyedge_sphereline(vec3d *hit_point, vec3d *xs0, vec3d *vs, float Rs, i } root = fl_sqrt(discriminant); - root1 = (float) ((-B + root)/(2*A)); - root2 = (float) ((-B - root)/(2*A)); + float inv2A = 1.0f/(2*A); + root1 = (float) ((-B + root)*inv2A); + root2 = (float) ((-B - root)*inv2A); // given sphere position, find which edge time (position) allows a valid solution if ( (root1 >= 0) && (root1 <= 1) ) { @@ -1104,8 +1106,9 @@ TryVertex: discriminant = B*B - 4*A*C; if (discriminant > 0) { root = fl_sqrt(discriminant); - root1 = (float) ((-B + root)/(2*A)); - root2 = (float) ((-B - root)/(2*A)); + float inv2A = 1.0f/(2*A); + root1 = (float) ((-B + root)*inv2A); + root2 = (float) ((-B - root)*inv2A); if (root1 > root2) { temp = root1; @@ -1137,8 +1140,9 @@ TryVertex: discriminant = B*B - 4*A*C; if (discriminant > 0) { root = fl_sqrt(discriminant); - root1 = (float) ((-B + root)/(2*A)); - root2 = (float) ((-B - root)/(2*A)); + float inv2A = 1.0f/(2*A); + root1 = (float) ((-B + root)*inv2A); + root2 = (float) ((-B - root)*inv2A); if (root1 > root2) { temp = root1; diff --git a/code/math/vecmat.cpp b/code/math/vecmat.cpp index 7a317e764c..739b263104 100644 --- a/code/math/vecmat.cpp +++ b/code/math/vecmat.cpp @@ -14,7 +14,7 @@ #include "math/vecmat.h" #include "math/floating.h" - +#include #define SMALL_NUM 1e-7 @@ -341,12 +341,7 @@ float vm_vec_mag(vec3d *v) mag1 = x+y+z; - if ( mag1 < 0.0 ) - return 0; - mag2 = fl_sqrt(mag1); - if ( mag2 < 0.0 ) - Int3(); return mag2; } @@ -510,8 +505,16 @@ float vm_vec_normalize_safe(vec3d *v) //returns approximation of 1/magnitude of a vector float vm_vec_imag(vec3d *v) { -// return 1.0f / sqrt( (v->xyz.x*v->xyz.x)+(v->xyz.y*v->xyz.y)+(v->xyz.z*v->xyz.z) ); - return fl_isqrt( (v->xyz.x*v->xyz.x)+(v->xyz.y*v->xyz.y)+(v->xyz.z*v->xyz.z) ); +#if _M_IX86_FP < 1 + return 1.0f / sqrt( (v->xyz.x*v->xyz.x)+(v->xyz.y*v->xyz.y)+(v->xyz.z*v->xyz.z) ); +#else + float x = (v->xyz.x*v->xyz.x)+(v->xyz.y*v->xyz.y)+(v->xyz.z*v->xyz.z); + __m128 xx = _mm_load_ss( & x ); + xx = _mm_rsqrt_ss( xx ); + _mm_store_ss( & x, xx ); + + return x; +#endif } //normalize a vector. returns 1/mag of source vec. uses approx 1/mag @@ -809,6 +812,31 @@ matrix *vm_vec_ang_2_matrix(matrix *m,vec3d *v,float a) return t; } +//generate the vectors for the vm_vector_2_matrix() an vm_vector_2_matrix_norm() functions so we can avoid goto +void vm_vector_2_matrix_gen_vectors(matrix *m) +{ + vec3d *xvec=&m->vec.rvec; + vec3d *yvec=&m->vec.uvec; + vec3d *zvec=&m->vec.fvec; + + if ((zvec->xyz.x==0.0f) && (zvec->xyz.z==0.0f)) { //forward vec is straight up or down + m->vec.rvec.xyz.x = 1.0f; + m->vec.uvec.xyz.z = (zvec->xyz.y<0.0f)?1.0f:-1.0f; + + m->vec.rvec.xyz.y = m->vec.rvec.xyz.z = m->vec.uvec.xyz.x = m->vec.uvec.xyz.y = 0.0f; + } + else { //not straight up or down + + xvec->xyz.x = zvec->xyz.z; + xvec->xyz.y = 0.0f; + xvec->xyz.z = -zvec->xyz.x; + + vm_vec_normalize(xvec); + + vm_vec_crossprod(yvec,zvec,xvec); + + } +} //computes a matrix from one or more vectors. The forward vector is required, //with the other two being optional. If both up & right vectors are passed, @@ -819,72 +847,44 @@ matrix *vm_vector_2_matrix(matrix *m,vec3d *fvec,vec3d *uvec,vec3d *rvec) { vec3d *xvec=&m->vec.rvec,*yvec=&m->vec.uvec,*zvec=&m->vec.fvec; - Assert(fvec != NULL); - // This had been commented out, but that's bogus. Code below relies on a valid zvec. + // This had been commented out, but that's bogus. Code below relies on a valid zvec. if (vm_vec_copy_normalize(zvec,fvec) == 0.0f) { Assert(0); return m; } if (uvec == NULL) { - - if (rvec == NULL) { //just forward vec - -bad_vector2: - ; - - if ((zvec->xyz.x==0.0f) && (zvec->xyz.z==0.0f)) { //forward vec is straight up or down - - m->vec.rvec.xyz.x = 1.0f; - m->vec.uvec.xyz.z = (zvec->xyz.y<0.0)?1.0f:-1.0f; - - m->vec.rvec.xyz.y = m->vec.rvec.xyz.z = m->vec.uvec.xyz.x = m->vec.uvec.xyz.y = 0.0f; - } - else { //not straight up or down - - xvec->xyz.x = zvec->xyz.z; - xvec->xyz.y = 0.0f; - xvec->xyz.z = -zvec->xyz.x; - - vm_vec_normalize(xvec); - - vm_vec_crossprod(yvec,zvec,xvec); - - } - + if (rvec == NULL) { //just forward vec + vm_vector_2_matrix_gen_vectors(m); } - else { //use right vec - + else { //use right vec if (vm_vec_copy_normalize(xvec,rvec) == 0.0f) - goto bad_vector2; + vm_vector_2_matrix_gen_vectors(m); vm_vec_crossprod(yvec,zvec,xvec); //normalize new perpendicular vector if (vm_vec_normalize(yvec) == 0.0f) - goto bad_vector2; + vm_vector_2_matrix_gen_vectors(m); //now recompute right vector, in case it wasn't entirely perpendiclar vm_vec_crossprod(xvec,yvec,zvec); - } } - else { //use up vec - + else { //use up vec if (vm_vec_copy_normalize(yvec,uvec) == 0.0f) - goto bad_vector2; + vm_vector_2_matrix_gen_vectors(m); vm_vec_crossprod(xvec,yvec,zvec); - + //normalize new perpendicular vector if (vm_vec_normalize(xvec) == 0.0f) - goto bad_vector2; + vm_vector_2_matrix_gen_vectors(m); //now recompute up vector, in case it wasn't entirely perpendiclar vm_vec_crossprod(yvec,zvec,xvec); - } return m; } @@ -896,65 +896,35 @@ matrix *vm_vector_2_matrix_norm(matrix *m,vec3d *fvec,vec3d *uvec,vec3d *rvec) vec3d *yvec=&m->vec.uvec; vec3d *zvec=&m->vec.fvec; - Assert(fvec != NULL); *zvec = *fvec; if (uvec == NULL) { - - if (rvec == NULL) { //just forward vec - -bad_vector2: - ; - - if ((zvec->xyz.x==0.0f) && (zvec->xyz.z==0.0f)) { //forward vec is straight up or down - - m->vec.rvec.xyz.x = 1.0f; - m->vec.uvec.xyz.z = (zvec->xyz.y<0.0f)?1.0f:-1.0f; - - m->vec.rvec.xyz.y = m->vec.rvec.xyz.z = m->vec.uvec.xyz.x = m->vec.uvec.xyz.y = 0.0f; - } - else { //not straight up or down - - xvec->xyz.x = zvec->xyz.z; - xvec->xyz.y = 0.0f; - xvec->xyz.z = -zvec->xyz.x; - - vm_vec_normalize(xvec); - - vm_vec_crossprod(yvec,zvec,xvec); - - } - + if (rvec == NULL) { //just forward vec + vm_vector_2_matrix_gen_vectors(m); } - else { //use right vec - + else { //use right vec vm_vec_crossprod(yvec,zvec,xvec); //normalize new perpendicular vector if (vm_vec_normalize(yvec) == 0.0f) - goto bad_vector2; + vm_vector_2_matrix_gen_vectors(m); //now recompute right vector, in case it wasn't entirely perpendiclar vm_vec_crossprod(xvec,yvec,zvec); - } } - else { //use up vec - + else { //use up vec vm_vec_crossprod(xvec,yvec,zvec); - + //normalize new perpendicular vector if (vm_vec_normalize(xvec) == 0.0f) - goto bad_vector2; + vm_vector_2_matrix_gen_vectors(m); //now recompute up vector, in case it wasn't entirely perpendiclar vm_vec_crossprod(yvec,zvec,xvec); - } - - return m; } diff --git a/code/object/collideshipship.cpp b/code/object/collideshipship.cpp index 4c76a3cf12..5d74928646 100644 --- a/code/object/collideshipship.cpp +++ b/code/object/collideshipship.cpp @@ -271,34 +271,34 @@ int ship_ship_check_collision(collision_info_struct *ship_ship_hit_info, vec3d * pmi = model_get_instance(heavy_shipp->model_instance_num); // turn off all rotating submodels and test for collision - for (size_t j=0; jsubmodel[submodel_vector[j]].collision_checked = true; + for (SCP_vector::iterator smv = submodel_vector.begin(); smv != submodel_vector.end(); smv++) { + pmi->submodel[*smv].collision_checked = true; } // reset flags to check MC_CHECK_MODEL | MC_CHECK_SPHERELINE and maybe MC_CHECK_INVISIBLE_FACES and MC_SUBMODEL_INSTANCE mc.flags = copy_flags | MC_SUBMODEL_INSTANCE; // check each submodel in turn - for (size_t i=0; i::iterator smv = submodel_vector.begin(); smv != submodel_vector.end(); smv++) { // turn on submodel for collision test - pmi->submodel[submodel_vector[i]].collision_checked = false; + pmi->submodel[*smv].collision_checked = false; // set angles for last frame - angles copy_angles = pmi->submodel[submodel_vector[i]].angs; + angles copy_angles = pmi->submodel[*smv].angs; // find the start and end positions of the sphere in submodel RF - pmi->submodel[submodel_vector[i]].angs = pmi->submodel[submodel_vector[i]].prev_angs; - world_find_model_instance_point(&p0, &light_obj->last_pos, pm, pmi, submodel_vector[i], &heavy_obj->last_orient, &heavy_obj->last_pos); + pmi->submodel[*smv].angs = pmi->submodel[*smv].prev_angs; + world_find_model_instance_point(&p0, &light_obj->last_pos, pm, pmi, *smv, &heavy_obj->last_orient, &heavy_obj->last_pos); - pmi->submodel[submodel_vector[i]].angs = copy_angles; - world_find_model_instance_point(&p1, &light_obj->pos, pm, pmi, submodel_vector[i], &heavy_obj->orient, &heavy_obj->pos); + pmi->submodel[*smv].angs = copy_angles; + world_find_model_instance_point(&p1, &light_obj->pos, pm, pmi, *smv, &heavy_obj->orient, &heavy_obj->pos); mc.p0 = &p0; mc.p1 = &p1; // mc.pos = zero // in submodel RF mc.orient = &vmd_identity_matrix; - mc.submodel_num = submodel_vector[i]; + mc.submodel_num = *smv; if ( model_collide(&mc) ) { if (mc.hit_dist < ship_ship_hit_info->hit_time ) { @@ -342,17 +342,17 @@ int ship_ship_check_collision(collision_info_struct *ship_ship_hit_info, vec3d * // set submodel angle at time of collision // TODO: generalize... what happens when angle passes 0 or 2PI angles temp_angs; - vm_vec_sub(&diff, (vec3d*)&pm->submodel[submodel_vector[i]].angs, (vec3d*)&pm->submodel[submodel_vector[i]].sii->prev_angs); - vm_vec_scale_add((vec3d*)&temp_angs, (vec3d *)&pm->submodel[submodel_vector[i]].sii->prev_angs, &diff, mc.hit_dist); - pm->submodel[submodel_vector[i]].angs = temp_angs; + vm_vec_sub(&diff, (vec3d*)&pm->submodel[*smv].angs, (vec3d*)&pm->submodel[*smv].sii->prev_angs); + vm_vec_scale_add((vec3d*)&temp_angs, (vec3d *)&pm->submodel[*smv].sii->prev_angs, &diff, mc.hit_dist); + pm->submodel[*smv].angs = temp_angs; // find intersection point in submodel RF - THEN advance to end of frametime. vec3d temp = int_light_pos; - world_find_model_point(&int_submodel_pos, &int_light_pos, pm, submodel_vector[i], &int_heavy_orient, &int_heavy_pos); + world_find_model_point(&int_submodel_pos, &int_light_pos, pm, *smv, &int_heavy_orient, &int_heavy_pos); vec3d temp2; // Advance to end of frametime - pm->submodel[submodel_vector[i]].angs = copy_angles; + pm->submodel[*smv].angs = copy_angles; model_find_world_point(&ship_ship_hit_info->light_collision_cm_pos, &int_submodel_pos, mc.model_num, mc.hit_submodel, mc.orient, &zero); vm_vec_sub(&temp2, &ship_ship_hit_info->light_collision_cm_pos, &ship_ship_hit_info->hit_pos); */ @@ -362,7 +362,7 @@ int ship_ship_check_collision(collision_info_struct *ship_ship_hit_info, vec3d * } } // Don't look at this submodel again - pmi->submodel[submodel_vector[i]].collision_checked = true; + pmi->submodel[*smv].collision_checked = true; } } diff --git a/code/parse/lua.cpp b/code/parse/lua.cpp index ad94233bbf..05a5c70e0d 100644 --- a/code/parse/lua.cpp +++ b/code/parse/lua.cpp @@ -13157,6 +13157,7 @@ static int ade_index_handler(lua_State *L) char *type_name = NULL; uint ade_id = UINT_MAX; int mtb_ldx = INT_MAX; + ade_table_entry* entry = 0; //*****STEP 1: Check for user-defined objects if(lua_istable(L, obj_ldx) && !ADE_SETTING_VAR) @@ -13176,7 +13177,7 @@ static int ade_index_handler(lua_State *L) lua_pushcfunction(L, ade_friendly_error); int err_ldx = lua_gettop(L); int i; - + //*****WMC - go for the type name lua_pushstring(L, "__adeid"); lua_rawget(L, mtb_ldx); @@ -13184,7 +13185,10 @@ static int ade_index_handler(lua_State *L) { ade_id = (uint) lua_tonumber(L, -1); if(ade_id < Ade_table_entries.size()) - type_name = Ade_table_entries[ade_id].Name; + { + entry = &Ade_table_entries[ade_id]; + type_name = entry->Name; + } } lua_pop(L, 1); @@ -13196,7 +13200,7 @@ static int ade_index_handler(lua_State *L) //Get userdata sig char *ud = (char *)lua_touserdata(L, obj_ldx); - ODATA_SIG_TYPE sig = *(ODATA_SIG_TYPE*)(ud + Ade_table_entries[ade_id].Value.Object.size); + ODATA_SIG_TYPE sig = *(ODATA_SIG_TYPE*)(ud + entry->Value.Object.size); //Now use it to index the table with that # lua_pushnumber(L, sig); @@ -13319,7 +13323,7 @@ static int ade_index_handler(lua_State *L) //Get userdata sig char *ud = (char *)lua_touserdata(L, obj_ldx); - ODATA_SIG_TYPE sig = *(ODATA_SIG_TYPE*)(ud + Ade_table_entries[ade_id].Value.Object.size); + ODATA_SIG_TYPE sig = *(ODATA_SIG_TYPE*)(ud + entry->Value.Object.size); //Now use it to index the table with that # lua_pushnumber(L, sig); diff --git a/code/parse/scripting.cpp b/code/parse/scripting.cpp index 737c6c96c9..a8d1e46be4 100644 --- a/code/parse/scripting.cpp +++ b/code/parse/scripting.cpp @@ -398,10 +398,8 @@ bool ConditionedHook::Run(script_state *sys, int action, char format, void *data Assert(sys != NULL); //Do the actions - script_action *sap; - for(uint i = 0; i < Actions.size(); i++) + for(SCP_vector::iterator sap = Actions.begin(); sap != Actions.end(); sap++) { - sap = &Actions[i]; if(sap->action_type == action) sys->RunBytecode(sap->hook, format, data); } @@ -415,10 +413,8 @@ bool ConditionedHook::IsOverride(script_state *sys, int action) //bool b = false; //Do the actions - script_action *sap; - for(uint i = 0; i < Actions.size(); i++) + for(SCP_vector::iterator sap = Actions.begin(); sap != Actions.end(); sap++) { - sap = &Actions[i]; if(sap->action_type == action) { if(sys->IsOverride(sap->hook)) @@ -805,11 +801,9 @@ int script_state::RunBytecode(script_hook &hd, char format, void *data) int script_state::RunCondition(int action, char format, void *data, object *objp) { - ConditionedHook *chp = NULL; int num = 0; - for(uint i= 0; i < ConditionalHooks.size(); i++) + for(SCP_vector::iterator chp = ConditionalHooks.begin(); chp != ConditionalHooks.end(); chp++) { - chp = &ConditionalHooks[i]; if(chp->ConditionsValid(action, objp)) { chp->Run(this, action, format, data); @@ -821,11 +815,9 @@ int script_state::RunCondition(int action, char format, void *data, object *objp bool script_state::IsConditionOverride(int action, object *objp) { - ConditionedHook *chp = NULL; //bool b = false; - for(uint i= 0; i < ConditionalHooks.size(); i++) + for(SCP_vector::iterator chp = ConditionalHooks.begin(); chp != ConditionalHooks.end(); chp++) { - chp = &ConditionalHooks[i]; if(chp->ConditionsValid(action, objp)) { if(chp->IsOverride(this, action)) diff --git a/code/sound/sound.cpp b/code/sound/sound.cpp index be78a5b4ec..66c061e1e1 100644 --- a/code/sound/sound.cpp +++ b/code/sound/sound.cpp @@ -197,7 +197,6 @@ void snd_spew_debug_info() int message_sounds = 0; int interface_sounds = 0; int done = 0; - size_t s_idx; if(!Sound_spew){ return; @@ -212,16 +211,16 @@ void snd_spew_debug_info() done = 0; // what kind of sound is this - for(s_idx=0; s_idx < Snds.size(); s_idx++){ - if(!stricmp(Snds[s_idx].filename, Sounds[idx].filename)){ + for(SCP_vector::iterator gs = Snds.begin(); gs != Snds.end(); gs++){ + if(!stricmp(gs->filename, Sounds[idx].filename)){ game_sounds++; done = 1; } } if(!done){ - for(s_idx=0; s_idx < Snds.size(); s_idx++){ - if(!stricmp(Snds_iface[s_idx].filename, Sounds[idx].filename)){ + for(SCP_vector::iterator gs = Snds.begin(); gs != Snds.end(); gs++){ + if(!stricmp(gs->filename, Sounds[idx].filename)){ interface_sounds++; done = 1; } diff --git a/code/weapon/beam.cpp b/code/weapon/beam.cpp index 9fca5e8f12..565a462636 100644 --- a/code/weapon/beam.cpp +++ b/code/weapon/beam.cpp @@ -241,6 +241,7 @@ float beam_get_ship_damage(beam *b, object *objp); // if the beam is likely to tool a given target before its lifetime expires int beam_will_tool_target(beam *b, object *objp); +extern int Use_GLSL; // ------------------------------------------------------------------------------------------------ // BEAM WEAPON FUNCTIONS @@ -1052,6 +1053,10 @@ void beam_move_all_post() } } + // add tube light for the beam + if(Use_GLSL > 1) + beam_add_light(moveup, OBJ_INDEX(moveup->objp), 1, NULL); + // stop shooting? if(bf_status <= 0){ next_one = GET_NEXT(moveup); @@ -1592,7 +1597,6 @@ void beam_add_light_small(beam *bm, object *objp, vec3d *pt_override = NULL) light_add_point_unique(&near_pt, light_rad * 0.0001f, light_rad, pct, fr, fg, fb, OBJ_INDEX(objp)); } -extern int Use_GLSL; // call to add a light source to a large object void beam_add_light_large(beam *bm, object *objp, vec3d *pt0, vec3d *pt1) { @@ -1629,24 +1633,20 @@ void beam_add_light_large(beam *bm, object *objp, vec3d *pt0, vec3d *pt1) float fg = (float)wip->laser_color_1.green / 255.0f; float fb = (float)wip->laser_color_1.blue / 255.0f; - vec3d near_pt, a, b, c; - float dist; - - vm_vec_sub(&a, pt1, pt0); - vm_vec_normalize_quick(&a); - vm_vec_dist_to_line(&objp->pos, pt0, pt1, &near_pt, &dist); // Calculate nearest point for fallback fake tube pointlight - vm_vec_scale_add(&b, &near_pt, &a, bwi->beam_muzzle_radius * (-3.0f)); // Valathil: Move the light away from the ship somewhat - vm_vec_sub(&c, &objp->pos, &near_pt); - dist = vm_vec_mag_quick(&c); - - if ( dist > (light_rad + objp->radius) ) { - return; // Too far away - } - if ( Use_GLSL > 1 ) light_add_tube(pt0, pt1, 1.0f, light_rad, 1.0f * noise, fr, fg, fb, OBJ_INDEX(objp)); - else - light_add_tube(pt0, &b, 1.0f, light_rad, 1.0f * noise, fr, fg, fb, OBJ_INDEX(objp)); + else { + vec3d near_pt, a; + float dist,max_dist; + vm_vec_sub(&a, pt1, pt0); + vm_vec_normalize_quick(&a); + vm_vec_dist_squared_to_line(&objp->pos, pt0, pt1, &near_pt, &dist); // Calculate nearest point for fallback fake tube pointlight + max_dist = light_rad + objp->radius; + max_dist *= max_dist; + if ( dist > max_dist) + return; // Too far away + light_add_tube(pt0, &near_pt, 1.0f, light_rad, 1.0f * noise, fr, fg, fb, OBJ_INDEX(objp)); + } } // mark an object as being lit @@ -2387,7 +2387,8 @@ int beam_collide_ship(obj_pair *pair) } // add this guy to the lighting list - beam_add_light(b, OBJ_INDEX(ship_objp), 1, NULL); + if(Use_GLSL < 2) + beam_add_light(b, OBJ_INDEX(ship_objp), 1, NULL); // reset timestamp to timeout immediately pair->next_check_time = timestamp(0); @@ -2459,7 +2460,8 @@ int beam_collide_asteroid(obj_pair *pair) } // add this guy to the lighting list - beam_add_light(b, OBJ_INDEX(pair->b), 1, NULL); + if(Use_GLSL < 2) + beam_add_light(b, OBJ_INDEX(pair->b), 1, NULL); // reset timestamp to timeout immediately pair->next_check_time = timestamp(0); @@ -2596,7 +2598,8 @@ int beam_collide_debris(obj_pair *pair) } // add this guy to the lighting list - beam_add_light(b, OBJ_INDEX(pair->b), 1, NULL); + if(Use_GLSL < 2) + beam_add_light(b, OBJ_INDEX(pair->b), 1, NULL); // reset timestamp to timeout immediately pair->next_check_time = timestamp(0); @@ -2801,7 +2804,8 @@ void beam_handle_collisions(beam *b) } // add lighting - beam_add_light(b, target, 2, &b->f_collisions[idx].cinfo.hit_point_world); + if(Use_GLSL < 2) + beam_add_light(b, target, 2, &b->f_collisions[idx].cinfo.hit_point_world); // add to the recent collision list r_coll[r_coll_count].c_objnum = target;