From 262094237f12892792bba69c4fd200f308436eaf Mon Sep 17 00:00:00 2001 From: Kp Date: Wed, 6 Jul 2016 01:54:24 +0000 Subject: [PATCH] Rewrite simple numeric casts from C style to static_cast<> s/(\(int\|float\|fix\))\s*(/static_cast<\1>(/g --- common/main/gamefont.h | 2 +- similar/editor/group.cpp | 2 +- similar/editor/ksegsize.cpp | 2 +- similar/editor/segment.cpp | 12 ++++++------ similar/editor/seguvs.cpp | 8 ++++---- similar/main/gameseg.cpp | 8 ++++---- similar/main/multi.cpp | 16 ++++++++-------- similar/main/newdemo.cpp | 2 +- 8 files changed, 26 insertions(+), 26 deletions(-) diff --git a/common/main/gamefont.h b/common/main/gamefont.h index 8f071c6b6..c2bd13670 100644 --- a/common/main/gamefont.h +++ b/common/main/gamefont.h @@ -55,7 +55,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. extern float FNTScaleX, FNTScaleY; // add (scaled) spacing to given font coordinate -#define LINE_SPACING ((float)(FNTScaleY*(grd_curcanv->cv_font->ft_h+(GAME_FONT->ft_h/5)))) +#define LINE_SPACING (static_cast(FNTScaleY*(grd_curcanv->cv_font->ft_h+(GAME_FONT->ft_h/5)))) extern array Gamefonts; diff --git a/similar/editor/group.cpp b/similar/editor/group.cpp index fde46fb5a..64d87a0d1 100644 --- a/similar/editor/group.cpp +++ b/similar/editor/group.cpp @@ -888,7 +888,7 @@ int rotate_segment_new(const vms_angvec &pbh) int child_save; int current_group_save; - if (!IS_CHILD(Cursegp->children[(int) (Side_opposite[Curside])])) + if (!IS_CHILD(Cursegp->children[static_cast(Side_opposite[Curside])])) // -- I don't understand this, MK, 01/25/94: if (Cursegp->children[Curside] != group_seg-Segments) { editor_status("Error -- unable to rotate group, Cursegp:Side_opposite[Curside] cannot be free."); diff --git a/similar/editor/ksegsize.cpp b/similar/editor/ksegsize.cpp index f9bd68c97..96d91038a 100644 --- a/similar/editor/ksegsize.cpp +++ b/similar/editor/ksegsize.cpp @@ -231,7 +231,7 @@ static int segsize_common(int dimension, fix amount) int s; for (s=0; s(Side_opposite[i])]--; med_propagate_tmaps_to_segments(vsegptridx(c), Cursegp, 1); } } diff --git a/similar/editor/segment.cpp b/similar/editor/segment.cpp index 428390d55..41bc987f0 100644 --- a/similar/editor/segment.cpp +++ b/similar/editor/segment.cpp @@ -809,7 +809,7 @@ static int med_attach_segment_rotated(const vsegptridx_t destseg, const vsegptr_ // Set the vertex indices for the four vertices forming the front of the new side for (v=0; v<4; v++) - nsp->verts[v] = destseg->verts[(int) (dvp[v])]; + nsp->verts[v] = destseg->verts[static_cast(dvp[v])]; // The other 4 vertices must be created. // Their coordinates are determined by the 4 welded vertices and the vector from front @@ -1228,11 +1228,11 @@ int med_form_joint(const vsegptridx_t seg1, int side1, const vsegptridx_t seg2, // Make a copy of the list of vertices in seg2 which will be deleted and set the // associated vertex number, so that all occurrences of the vertices can be replaced. for (v=0; v<4; v++) - lost_vertices[v] = seg2->verts[(int) (vp2[v])]; + lost_vertices[v] = seg2->verts[static_cast(vp2[v])]; // Now, for each vertex in lost_vertices, determine which vertex it maps to. for (v=0; v<4; v++) - remap_vertices[3 - ((v + bfi) % 4)] = seg1->verts[(int) (vp1[v])]; + remap_vertices[3 - ((v + bfi) % 4)] = seg1->verts[static_cast(vp1[v])]; // Now, in all segments, replace all occurrences of vertices in lost_vertices with remap_vertices @@ -1300,7 +1300,7 @@ int med_form_bridge_segment(const vsegptridx_t seg1, int side1, const vsegptridx { auto &sv = Side_to_verts[side2]; for (v=0; v<4; v++) - bs->verts[(3-v)+4] = seg2->verts[(int) (sv[v])]; + bs->verts[(3-v)+4] = seg2->verts[static_cast(sv[v])]; } // Copy vertices from seg1 into first 4 vertices of bridge segment. @@ -1309,7 +1309,7 @@ int med_form_bridge_segment(const vsegptridx_t seg1, int side1, const vsegptridx { auto &sv = Side_to_verts[side1]; for (v=0; v<4; v++) - bs->verts[(v + bfi) % 4] = seg1->verts[(int) (sv[v])]; + bs->verts[(v + bfi) % 4] = seg1->verts[static_cast(sv[v])]; } // Form connections to children, first initialize all to unconnected. @@ -1335,7 +1335,7 @@ int med_form_bridge_segment(const vsegptridx_t seg1, int side1, const vsegptridx seg1->children[side1] = segment_none; seg2->children[side2] = segment_none; bs->children[AttachSide] = segment_none; - bs->children[(int) (Side_opposite[AttachSide])] = segment_none; + bs->children[static_cast(Side_opposite[AttachSide])] = segment_none; if (med_delete_segment(bs)) { Int3(); } diff --git a/similar/editor/seguvs.cpp b/similar/editor/seguvs.cpp index f19c5a199..f7481fb68 100644 --- a/similar/editor/seguvs.cpp +++ b/similar/editor/seguvs.cpp @@ -637,7 +637,7 @@ static void get_side_ids(const vsegptr_t base_seg, const vsegptr_t con_seg, int if (side != base_side) { auto &base_vp = Side_to_verts[side]; for (v0=0; v0<4; v0++) - if (((base_seg->verts[(int) (base_vp[v0])] == abs_id1) && (base_seg->verts[(int) (base_vp[(v0+1) % 4])] == abs_id2)) || ((base_seg->verts[(int) (base_vp[v0])] == abs_id2) && (base_seg->verts[(int)(base_vp[ (v0+1) % 4])] == abs_id1))) { + if (((base_seg->verts[static_cast(base_vp[v0])] == abs_id1) && (base_seg->verts[static_cast(base_vp[(v0+1) % 4])] == abs_id2)) || ((base_seg->verts[static_cast(base_vp[v0])] == abs_id2) && (base_seg->verts[static_cast(base_vp[ (v0+1) % 4])] == abs_id1))) { Assert(*base_common_side == -1); // This means two different sides shared the same edge with base_side == impossible! *base_common_side = side; } @@ -652,7 +652,7 @@ static void get_side_ids(const vsegptr_t base_seg, const vsegptr_t con_seg, int if (side != con_side) { auto &con_vp = Side_to_verts[side]; for (v0=0; v0<4; v0++) - if (((con_seg->verts[(int) (con_vp[(v0 + 1) % 4])] == abs_id1) && (con_seg->verts[(int) (con_vp[v0])] == abs_id2)) || ((con_seg->verts[(int) (con_vp[(v0 + 1) % 4])] == abs_id2) && (con_seg->verts[(int) (con_vp[v0])] == abs_id1))) { + if (((con_seg->verts[static_cast(con_vp[(v0 + 1) % 4])] == abs_id1) && (con_seg->verts[static_cast(con_vp[v0])] == abs_id2)) || ((con_seg->verts[static_cast(con_vp[(v0 + 1) % 4])] == abs_id2) && (con_seg->verts[static_cast(con_vp[v0])] == abs_id1))) { Assert(*con_common_side == -1); // This means two different sides shared the same edge with con_side == impossible! *con_common_side = side; } @@ -825,8 +825,8 @@ static void propagate_tmaps_to_segment_sides(const vsegptridx_t base_seg, int ba // Do for each edge on connecting face. for (v=0; v<4; v++) { - abs_id1 = base_seg->verts[(int) (base_vp[v])]; - abs_id2 = base_seg->verts[(int) (base_vp[(v+1) % 4])]; + abs_id1 = base_seg->verts[static_cast(base_vp[v])]; + abs_id2 = base_seg->verts[static_cast(base_vp[(v+1) % 4])]; propagate_tmaps_to_segment_side(base_seg, base_side, con_seg, con_side, abs_id1, abs_id2, uv_only_flag); } diff --git a/similar/main/gameseg.cpp b/similar/main/gameseg.cpp index cb81eb984..aa1365baf 100644 --- a/similar/main/gameseg.cpp +++ b/similar/main/gameseg.cpp @@ -1163,8 +1163,8 @@ static int check_for_degenerate_side(const vcsegptr_t sp, int sidenum) //vm_vec_sub(&vec2, &Vertices[sp->verts[vp[2]]], &Vertices[sp->verts[vp[1]]]); //vm_vec_normalize(&vec1); //vm_vec_normalize(&vec2); - vm_vec_normalized_dir(vec1, Vertices[sp->verts[(int) (vp[1])]], Vertices[sp->verts[(int) (vp[0])]]); - vm_vec_normalized_dir(vec2, Vertices[sp->verts[(int) (vp[2])]], Vertices[sp->verts[(int) (vp[1])]]); + vm_vec_normalized_dir(vec1, Vertices[sp->verts[static_cast(vp[1])]], Vertices[sp->verts[static_cast(vp[0])]]); + vm_vec_normalized_dir(vec2, Vertices[sp->verts[static_cast(vp[2])]], Vertices[sp->verts[static_cast(vp[1])]]); const auto cross0 = vm_vec_cross(vec1, vec2); dot = vm_vec_dot(vec_to_center, cross0); @@ -1175,8 +1175,8 @@ static int check_for_degenerate_side(const vcsegptr_t sp, int sidenum) //vm_vec_sub(&vec2, &Vertices[sp->verts[vp[3]]], &Vertices[sp->verts[vp[2]]]); //vm_vec_normalize(&vec1); //vm_vec_normalize(&vec2); - vm_vec_normalized_dir(vec1, Vertices[sp->verts[(int) (vp[2])]], Vertices[sp->verts[(int) (vp[1])]]); - vm_vec_normalized_dir(vec2, Vertices[sp->verts[(int) (vp[3])]], Vertices[sp->verts[(int) (vp[2])]]); + vm_vec_normalized_dir(vec1, Vertices[sp->verts[static_cast(vp[2])]], Vertices[sp->verts[static_cast(vp[1])]]); + vm_vec_normalized_dir(vec2, Vertices[sp->verts[static_cast(vp[3])]], Vertices[sp->verts[static_cast(vp[2])]]); const auto cross1 = vm_vec_cross(vec1, vec2); dot = vm_vec_dot(vec_to_center, cross1); diff --git a/similar/main/multi.cpp b/similar/main/multi.cpp index d38588797..25b145b77 100644 --- a/similar/main/multi.cpp +++ b/similar/main/multi.cpp @@ -1709,8 +1709,8 @@ static void multi_do_message(const uint8_t *const cbuf) const auto color = get_player_or_team_color(buf[1]); char xrgb = BM_XRGB(player_rgb[color].r,player_rgb[color].g,player_rgb[color].b); digi_play_sample(SOUND_HUD_MESSAGE, F1_0); - HUD_init_message(HM_MULTI, "%c%c%s:%c%c %s", CC_COLOR, xrgb, static_cast(Players[(int)(buf[1])].callsign), CC_COLOR, BM_XRGB(0, 31, 0), msgstart); - multi_sending_message[(int)(buf[1])] = msgsend_none; + HUD_init_message(HM_MULTI, "%c%c%s:%c%c %s", CC_COLOR, xrgb, static_cast(Players[static_cast(buf[1])].callsign), CC_COLOR, BM_XRGB(0, 31, 0), msgstart); + multi_sending_message[static_cast(buf[1])] = msgsend_none; } namespace dsx { @@ -1942,17 +1942,17 @@ static void multi_do_escape(const ubyte *buf) if (buf[2] == 0) { - HUD_init_message(HM_MULTI, "%s %s", static_cast(Players[(int)(buf[1])].callsign), TXT_HAS_ESCAPED); + HUD_init_message(HM_MULTI, "%s %s", static_cast(Players[static_cast(buf[1])].callsign), TXT_HAS_ESCAPED); if (Game_mode & GM_NETWORK) - Players[(int)(buf[1])].connected = CONNECT_ESCAPE_TUNNEL; + Players[static_cast(buf[1])].connected = CONNECT_ESCAPE_TUNNEL; if (!multi_goto_secret) multi_goto_secret = 2; } else if (buf[2] == 1) { - HUD_init_message(HM_MULTI, "%s %s", static_cast(Players[(int)(buf[1])].callsign), TXT_HAS_FOUND_SECRET); + HUD_init_message(HM_MULTI, "%s %s", static_cast(Players[static_cast(buf[1])].callsign), TXT_HAS_FOUND_SECRET); if (Game_mode & GM_NETWORK) - Players[(int)(buf[1])].connected = CONNECT_FOUND_SECRET; + Players[static_cast(buf[1])].connected = CONNECT_FOUND_SECRET; if (!multi_goto_secret) multi_goto_secret = 1; } @@ -2085,7 +2085,7 @@ static multi_do_quit(const ubyte *buf) if (!(Game_mode & GM_NETWORK)) return; - multi_disconnect_player((int)(buf[1])); + multi_disconnect_player(static_cast(buf[1])); } namespace dsx { @@ -4776,7 +4776,7 @@ void multi_restore_game(ubyte slot, uint id) static void multi_do_msgsend_state(const ubyte *buf) { - multi_sending_message[(int)(buf[1])] = (msgsend_state_t)buf[2]; + multi_sending_message[static_cast(buf[1])] = (msgsend_state_t)buf[2]; } void multi_send_msgsend_state(msgsend_state_t state) diff --git a/similar/main/newdemo.cpp b/similar/main/newdemo.cpp index 058d6ae64..c996fc5f6 100644 --- a/similar/main/newdemo.cpp +++ b/similar/main/newdemo.cpp @@ -640,7 +640,7 @@ static void nd_read_object(const vobjptridx_t obj) if (obj->lifeleft == -1) obj->lifeleft = IMMORTAL_TIME; else - obj->lifeleft = (fix)(static_cast(obj->lifeleft) << 12); + obj->lifeleft = static_cast(static_cast(obj->lifeleft) << 12); } if ((obj->type == OBJ_ROBOT) && !shareware) {