Lots of people here don't seem to know how std::vectors and iterators work. I started a little code cleanup and fixing of some illogical coding but its just too much to do alone. Ill post the work i have done so far.
Theres also a little gem in there where i replaced the 1.0f/sqrt function for the quick inverse vector magnitude with the faster rsqrt sse instruction which calculates a aproximation of the inverse square root in a much faster fashion then inverting the normal sqrt. The comment for the function where the sse intruction is called says this should be only an approximation so there should be no accuracy problems cause the function is only used where low accuracy shouldnt be a problem.
Index: code/fireball/fireballs.cpp
===================================================================
--- code/fireball/fireballs.cpp (Revision 7347)
+++ code/fireball/fireballs.cpp (Arbeitskopie)
@@ -239,7 +239,7 @@
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 @@
// 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<lod_checker>::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 @@
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<lod_checker>::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);
}
}
}
Index: code/cfile/cfilesystem.cpp
===================================================================
--- code/cfile/cfilesystem.cpp (Revision 7347)
+++ code/cfile/cfilesystem.cpp (Arbeitskopie)
@@ -1213,17 +1213,10 @@
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<cf_file*>::iterator fli = file_list_index.begin(); fli != file_list_index.end(); fli++) {
+ cf_file *f = *fli;
strcat_s( filespec, ext_list[cur_ext] );
@@ -1302,10 +1295,6 @@
}
}
-Bail:
- // didn't find anything, bail...
- file_list_index.clear();
-
return -1;
}
Index: code/fs2netd/fs2netd_client.cpp
===================================================================
--- code/fs2netd/fs2netd_client.cpp (Revision 7347)
+++ code/fs2netd/fs2netd_client.cpp (Arbeitskopie)
@@ -1183,8 +1183,8 @@
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<char*>(FS2NetD_ban_list[i].c_str()), banlist_cfg );
+ for (SCP_vector<std::string>::iterator bl = FS2NetD_ban_list.begin(); bl != FS2NetD_ban_list.end(); bl++) {
+ cfputs( const_cast<char*>(bl->c_str()), banlist_cfg );
}
cfclose(banlist_cfg);
@@ -1267,7 +1267,6 @@
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 @@
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<file_record>::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 @@
}
// 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<crc_valid_status>::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_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 @@
count = (int)Table_valid_status.size();
// do all the checksums
- for (idx = 0; idx < count; idx++) {
+ for (SCP_vector<crc_valid_status>::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 @@
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);
Index: code/fs2netd/tcp_client.cpp
===================================================================
--- code/fs2netd/tcp_client.cpp (Revision 7347)
+++ code/fs2netd/tcp_client.cpp (Arbeitskopie)
@@ -686,7 +686,6 @@
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 @@
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<crc_valid_status>::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 @@
return -1;
}
- for (i = 0; i < Table_valid_status.size(); i++) {
+ for (SCP_vector<crc_valid_status>::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;
Index: code/asteroid/asteroid.cpp
===================================================================
--- code/asteroid/asteroid.cpp (Revision 7347)
+++ code/asteroid/asteroid.cpp (Arbeitskopie)
@@ -607,8 +607,9 @@
Num_asteroids = 0;
Next_asteroid_throw = timestamp(1);
asteroid_obj_list_init();
- for (size_t t=0; t<Asteroid_info.size(); t++)
- Asteroid_info[t].damage_type_idx = Asteroid_info[t].damage_type_idx_sav;
+ SCP_vector<asteroid_info>::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
Index: code/gamesnd/gamesnd.cpp
===================================================================
--- code/gamesnd/gamesnd.cpp (Revision 7347)
+++ code/gamesnd/gamesnd.cpp (Arbeitskopie)
@@ -39,20 +39,22 @@
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<game_snd>::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 @@
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<game_snd>::iterator snd = Snds.begin(); snd != Snds.end(); snd++) {
+ if ( snd->sig == index )
{
return i;
}
+ i++;
}
return -1;
}
@@ -76,11 +80,13 @@
{
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<game_snd>::iterator snd = Snds.begin(); snd != Snds.end(); snd++) {
+ if ( snd->sig == index )
{
return i;
}
+ i++;
}
return -1;
}
@@ -125,19 +131,15 @@
// 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<game_snd>::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_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<game_snd>::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_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<game_snd>::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_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<game_snd>::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_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<game_snd>::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_sounds()
{
- int i;
+ int i = 0;
Snds.clear();
Snds.resize(MIN_GAME_SOUNDS);
@@ -531,8 +517,8 @@
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<game_snd>::iterator gs = Snds.begin(); gs != Snds.end(); gs++) {
+ gamesnd_init_struct(&(*gs));
}
Snds_iface.clear();
@@ -543,9 +529,11 @@
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<game_snd>::iterator si = Snds_iface.begin(); si != Snds_iface.end(); si++) {
+ gamesnd_init_struct(&(*si));
Snds_iface_handle[i] = -1;
+ i++;
}
}
Index: code/camera/camera.cpp
===================================================================
--- code/camera/camera.cpp (Revision 7347)
+++ code/camera/camera.cpp (Arbeitskopie)
@@ -791,9 +791,10 @@
int x = text_pos.x;
int y = text_pos.y;
- for(unsigned int i = 0; i < text_lines.size(); i++)
+
+ for(SCP_vector<std::string>::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 @@
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 @@
{
//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 @@
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_do_frame(float frametime)
{
- unsigned int i,size=Subtitles.size();
- for(i = 0; i < size; i++)
+ SCP_vector<subtitle>::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<subtitle>::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
Index: code/object/collideshipship.cpp
===================================================================
--- code/object/collideshipship.cpp (Revision 7347)
+++ code/object/collideshipship.cpp (Arbeitskopie)
@@ -271,34 +271,34 @@
pmi = model_get_instance(heavy_shipp->model_instance_num);
// turn off all rotating submodels and test for collision
- for (size_t j=0; j<submodel_vector.size(); j++) {
- pmi->submodel[submodel_vector[j]].collision_checked = true;
+ for (SCP_vector<int>::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<submodel_vector.size(); i++) {
+ for (SCP_vector<int>::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 @@
// 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 @@
}
}
// Don't look at this submodel again
- pmi->submodel[submodel_vector[i]].collision_checked = true;
+ pmi->submodel[*smv].collision_checked = true;
}
}
Index: code/sound/sound.cpp
===================================================================
--- code/sound/sound.cpp (Revision 7347)
+++ code/sound/sound.cpp (Arbeitskopie)
@@ -197,7 +197,6 @@
int message_sounds = 0;
int interface_sounds = 0;
int done = 0;
- size_t s_idx;
if(!Sound_spew){
return;
@@ -212,16 +211,16 @@
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<game_snd>::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<game_snd>::iterator gs = Snds.begin(); gs != Snds.end(); gs++){
+ if(!stricmp(gs->filename, Sounds[idx].filename)){
interface_sounds++;
done = 1;
}
Index: code/math/vecmat.cpp
===================================================================
--- code/math/vecmat.cpp (Revision 7347)
+++ code/math/vecmat.cpp (Arbeitskopie)
@@ -341,12 +341,7 @@
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 @@
//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,7 +812,32 @@
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,
//the up vector is used. If only the forward vector is passed, a bank of
@@ -819,72 +847,44 @@
{
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 @@
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;
}
Index: code/math/fvi.cpp
===================================================================
--- code/math/fvi.cpp (Revision 7347)
+++ code/math/fvi.cpp (Arbeitskopie)
@@ -1010,8 +1010,9 @@
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 @@
}
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 @@
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 @@
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;
Index: code/debris/debris.cpp
===================================================================
--- code/debris/debris.cpp (Revision 7347)
+++ code/debris/debris.cpp (Arbeitskopie)
@@ -941,34 +941,34 @@
pmi = model_get_instance(Ships[heavy_obj->instance].model_instance_num);
// turn off all rotating submodels and test for collision
- for (size_t j=0; j<submodel_vector.size(); j++) {
- pmi->submodel[submodel_vector[j]].collision_checked = true;
+ for (SCP_vector<int>::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<submodel_vector.size(); i++) {
+ for (SCP_vector<int>::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 @@
}
}
// Don't look at this submodel again
- pmi->submodel[submodel_vector[i]].collision_checked = true;
+ pmi->submodel[*smv].collision_checked = true;
}
}
Index: code/cutscene/cutscenes.cpp
===================================================================
--- code/cutscene/cutscenes.cpp (Revision 7347)
+++ code/cutscene/cutscenes.cpp (Arbeitskopie)
@@ -42,13 +42,9 @@
//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<cutscene_info>::iterator cut = Cutscenes.begin(); cut != Cutscenes.end(); cut++)
+ if(cut->description)
+ vm_free(cut->description);
}
// initialization stuff for cutscenes
@@ -114,9 +110,9 @@
return 0; // only 1 cd for OEM
#else
- for (size_t i = 0; i < Cutscenes.size(); i++ ) {
- if ( !stricmp(Cutscenes[i].filename, filename) ) {
- return (Cutscenes[i].cd - 1);
+ for (SCP_vector<cutscene_info>::iterator cut = Cutscenes.begin(); cut != Cutscenes.end(); cut++) {
+ if ( !stricmp(cut->filename, filename) ) {
+ return (cut->cd - 1);
}
}
@@ -141,10 +137,10 @@
// change to lower case
strlwr(file);
-
- for (size_t i = 0; i < Cutscenes.size(); i++ ) {
+ int i = 0;
+ for (SCP_vector<cutscene_info>::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
@@ -152,6 +148,7 @@
Cutscenes_viewable |= (1<<i);
return;
}
+ i++;
}
}
@@ -507,7 +504,9 @@
// Cutscenes_viewable = 0xffffffff; // Cheat code enables all movies.
Cutscene_list.clear();
- for (size_t j = 0; j < Cutscenes.size(); j++ ) {
+
+ int size = Cutscenes.size();
+ for (int j=0;j < size;j++) {
if ( Cutscenes_viewable & (1<<j) ) {
Cutscene_list.push_back((int)j);
}
@@ -568,7 +567,8 @@
case KEY_CTRLED | KEY_SHIFTED | KEY_S:
{
Cutscene_list.clear();
- for (size_t t = 0; t < Cutscenes.size(); t++) {
+ unsigned int size = Cutscenes.size();
+ for (size_t t = 0; t < size; t++) {
Cutscene_list.push_back((int)t);
}
Index: code/parse/lua.cpp
===================================================================
--- code/parse/lua.cpp (Revision 7347)
+++ code/parse/lua.cpp (Arbeitskopie)
@@ -13135,6 +13135,7 @@
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)
@@ -13154,7 +13155,7 @@
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);
@@ -13162,7 +13163,10 @@
{
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);
@@ -13174,7 +13178,7 @@
//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);
@@ -13297,7 +13301,7 @@
//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);
Index: code/parse/scripting.cpp
===================================================================
--- code/parse/scripting.cpp (Revision 7347)
+++ code/parse/scripting.cpp (Arbeitskopie)
@@ -398,10 +398,8 @@
Assert(sys != NULL);
//Do the actions
- script_action *sap;
- for(uint i = 0; i < Actions.size(); i++)
+ for(SCP_vector<script_action>::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 b = false;
//Do the actions
- script_action *sap;
- for(uint i = 0; i < Actions.size(); i++)
+ for(SCP_vector<script_action>::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::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<ConditionedHook>::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 @@
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<ConditionedHook>::iterator chp = ConditionalHooks.begin(); chp != ConditionalHooks.end(); chp++)
{
- chp = &ConditionalHooks[i];
if(chp->ConditionsValid(action, objp))
{
if(chp->IsOverride(this, action))
Index: code/autopilot/autopilot.cpp
===================================================================
--- code/autopilot/autopilot.cpp (Revision 7347)
+++ code/autopilot/autopilot.cpp (Arbeitskopie)
@@ -372,8 +372,7 @@
{
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 @@
// position capships
vec3d right, front, up, offset;
- for (i = 0; i < (int)capIndexes.size(); i++)
+ for (SCP_vector<int>::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 @@
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 @@
// 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)
{
Index: code/ai/aicode.cpp
===================================================================
--- code/ai/aicode.cpp (Revision 7347)
+++ code/ai/aicode.cpp (Arbeitskopie)
@@ -359,20 +359,18 @@
// 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<huge_fire_info>::iterator hfi;
Assert( firer_objp->type == OBJ_SHIP );
firer_ship = &Ships[firer_objp->instance];
firer_team = firer_ship->team;
// 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 +386,7 @@
}
// 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