From 150e2d2686605df4ba79795e76ed21998f7aa6d3 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 19 Apr 2015 04:18:49 +0000 Subject: [PATCH] Convert local arrays to array<> --- common/3d/rod.cpp | 4 ++-- common/include/editor/editor.h | 2 +- common/include/key.h | 2 +- common/main/config.h | 2 +- common/main/robot.h | 1 - common/misc/hmp.cpp | 2 +- common/ui/dialog.cpp | 2 +- common/ui/file.cpp | 4 ++-- common/ui/keypad.cpp | 3 +-- common/ui/keypress.cpp | 5 +++-- d2x-rebirth/main/escort.cpp | 9 +++++---- similar/arch/sdl/gr.cpp | 17 ++++++++--------- similar/arch/sdl/key.cpp | 4 ++-- similar/editor/med.cpp | 4 ++-- similar/editor/segment.cpp | 5 ++--- similar/editor/seguvs.cpp | 5 +++-- similar/main/ai.cpp | 2 +- similar/main/aipath.cpp | 10 +++++----- similar/main/automap.cpp | 4 ++-- similar/main/playsave.cpp | 7 ++++--- similar/main/robot.cpp | 3 ++- 21 files changed, 49 insertions(+), 48 deletions(-) diff --git a/common/3d/rod.cpp b/common/3d/rod.cpp index c53864602..6b3ffec47 100644 --- a/common/3d/rod.cpp +++ b/common/3d/rod.cpp @@ -23,7 +23,7 @@ struct rod_4point { array point_list; - g3s_point points[4]; + array points; }; //compute the corners of a rod. fills in vertbuf. @@ -68,7 +68,7 @@ static int calc_rod_corners(rod_4point &rod_point_group, const g3s_point &bot_po rod_point_group.point_list[1] = &rod_point_group.points[1]; rod_point_group.point_list[2] = &rod_point_group.points[2]; rod_point_group.point_list[3] = &rod_point_group.points[3]; - g3s_point (&rod_points)[4] = rod_point_group.points; + auto &rod_points = rod_point_group.points; vm_vec_add(rod_points[0].p3_vec,top_point.p3_vec,tempv); vm_vec_sub(rod_points[1].p3_vec,top_point.p3_vec,tempv); diff --git a/common/include/editor/editor.h b/common/include/editor/editor.h index 9ee42c6f5..6a449c2f4 100644 --- a/common/include/editor/editor.h +++ b/common/include/editor/editor.h @@ -292,7 +292,7 @@ struct vms_equation { union { struct {fix x3, x2, x1, x0, y3, y2, y1, y0, z3, z2, z1, z0;} n; - fix xyz[3][4]; + array, 3> xyz; }; }; diff --git a/common/include/key.h b/common/include/key.h index 26fd5fa1d..7cbbc0906 100644 --- a/common/include/key.h +++ b/common/include/key.h @@ -58,7 +58,7 @@ extern int event_key_get_raw(const d_event &event); // same as above but without extern unsigned char key_ascii(); // Set to 1 if the key is currently down, else 0 -extern volatile unsigned char keyd_pressed[256]; +extern array keyd_pressed; extern volatile unsigned char keyd_last_pressed; extern volatile unsigned char keyd_last_released; diff --git a/common/main/config.h b/common/main/config.h index 5d5689504..09d4d09a9 100644 --- a/common/main/config.h +++ b/common/main/config.h @@ -42,7 +42,7 @@ struct Cfg : prohibit_void_ptr bool OrigTrackOrder; int MusicType; int CMLevelMusicPlayOrder; - int CMLevelMusicTrack[2]; + array CMLevelMusicTrack; ntstring CMLevelMusicPath; array, 5> CMMiscMusic; int GammaLevel; diff --git a/common/main/robot.h b/common/main/robot.h index 2cf377198..9fd20d3e5 100644 --- a/common/main/robot.h +++ b/common/main/robot.h @@ -140,7 +140,6 @@ struct robot_info : prohibit_void_ptr //boss_flag, companion, thief, & pursuit probably should also be bits in the flags byte. ubyte flags; // misc properties - ubyte pad[3]; // alignment ubyte deathroll_sound; // if has deathroll, what sound? ubyte glow; // apply this light to robot itself. stored as 4:4 fixed-point diff --git a/common/misc/hmp.cpp b/common/misc/hmp.cpp index 3a43a1e2f..768b56d65 100644 --- a/common/misc/hmp.cpp +++ b/common/misc/hmp.cpp @@ -180,7 +180,7 @@ static int get_var_num(unsigned char *data, int datalen, } static int get_event(hmp_file *hmp, event *ev) { - static const int cmdlen[7]={3,3,3,3,2,2,3}; + static const array cmdlen{{3,3,3,3,2,2,3}}; unsigned long got; unsigned long mindelta, delta; int ev_num; diff --git a/common/ui/dialog.cpp b/common/ui/dialog.cpp index c6bbe3e5f..c09e33208 100644 --- a/common/ui/dialog.cpp +++ b/common/ui/dialog.cpp @@ -62,7 +62,7 @@ static UI_EVENT * EventBuffer = NULL; static int Record = 0; static int RecordFlags = 0; -static unsigned char SavedState[256]; +static array SavedState; static int PlaybackSpeed = 1; diff --git a/common/ui/file.cpp b/common/ui/file.cpp index 778dde01d..114e49759 100644 --- a/common/ui/file.cpp +++ b/common/ui/file.cpp @@ -118,7 +118,7 @@ struct browser std::unique_ptr listbox1, listbox2; std::unique_ptr user_file; int num_files, num_dirs; - char spaces[35]; + array spaces; }; static int browser_handler(UI_DIALOG *dlg,const d_event &event, browser *b) @@ -133,7 +133,7 @@ static int browser_handler(UI_DIALOG *dlg,const d_event &event, browser *b) ui_dprintf_at( dlg, 20, 86,"&Files" ); ui_dprintf_at( dlg, 210, 86,"&Dirs" ); - ui_dputs_at( dlg, 20, 60, b->spaces ); + ui_dputs_at(dlg, 20, 60, b->spaces.data()); ui_dputs_at( dlg, 20, 60, b->view_dir ); return 1; diff --git a/common/ui/keypad.cpp b/common/ui/keypad.cpp index 011d98011..e32d45068 100644 --- a/common/ui/keypad.cpp +++ b/common/ui/keypad.cpp @@ -42,8 +42,7 @@ static int active_pad; static int desc_x, desc_y; -static int HotKey[17]; -static int HotKey1[17]; +static array HotKey, HotKey1; int ui_pad_get_current() { diff --git a/common/ui/keypress.cpp b/common/ui/keypress.cpp index 16c37b2bc..e2f7ca638 100644 --- a/common/ui/keypress.cpp +++ b/common/ui/keypress.cpp @@ -30,7 +30,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "key.h" #include "window.h" -static const char *const KeyDesc[256] = { \ +static const array KeyDesc{{ "","{Esc}","{1}","{2}","{3}","{4}","{5}","{6}","{7}","{8}","{9}","{0}","{-}", \ "{=}","{Backspace}","{Tab}","{Q}","{W}","{E}","{R}","{T}","{Y}","{U}","{I}","{O}", \ "{P}","{[}","{]}","{Enter}","{LeftCtrl}","{A}","{S}","{D}","{F}", \ @@ -50,7 +50,8 @@ static const char *const KeyDesc[256] = { \ "","{Left}","","{Right}","","{End}","{Down}","{PageDown}","{Insert}", \ "{Delete}","","","","","","","","","","","","","","","","","", \ "","","","","","","","","","","","","","","","","","","","", \ -"","","","","","","" }; +"","","","","","","" +}}; diff --git a/d2x-rebirth/main/escort.cpp b/d2x-rebirth/main/escort.cpp index f63d35260..6d6a5d6d4 100644 --- a/d2x-rebirth/main/escort.cpp +++ b/d2x-rebirth/main/escort.cpp @@ -74,7 +74,7 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #endif static void say_escort_goal(int goal_num); -static void show_escort_menu(char *msg); +static void show_escort_menu(const array &); static const char Escort_goal_text[MAX_ESCORT_GOALS][12] = { @@ -1552,7 +1552,7 @@ void drop_stolen_items(const vcobjptr_t objp) // -------------------------------------------------------------------------------------------------------------- struct escort_menu : ignore_window_pointer_t { - char msg[300]; + array msg; }; static window_event_result escort_menu_keycommand(window *wind,const d_event &event, escort_menu *) @@ -1714,7 +1714,7 @@ void do_escort_menu(void) else tstr = "Enable"; - sprintf(menu->msg, "Select Guide-Bot Command:\n\n\n" + snprintf(menu->msg.data(), menu->msg.size(), "Select Guide-Bot Command:\n\n\n" "0. Next Goal: %s" CC_LSPACING_S "3\n\n" "\x84. Find Energy Powerup" CC_LSPACING_S "3\n\n" "2. Find Energy Center" CC_LSPACING_S "3\n\n" @@ -1732,8 +1732,9 @@ void do_escort_menu(void) // ------------------------------------------------------------------------------- // Show the Buddy menu! -void show_escort_menu(char *msg) +void show_escort_menu(const array &amsg) { + const auto msg = amsg.data(); int w,h,aw; int x,y; diff --git a/similar/arch/sdl/gr.cpp b/similar/arch/sdl/gr.cpp index 6276b7f2e..3b126f0b7 100644 --- a/similar/arch/sdl/gr.cpp +++ b/similar/arch/sdl/gr.cpp @@ -10,6 +10,7 @@ * */ +#include #include #include #include @@ -28,6 +29,8 @@ #include "compiler-make_unique.h" +using std::min; + static int sdl_video_flags = SDL_SWSURFACE | SDL_HWPALETTE | SDL_DOUBLEBUF; SDL_Surface *screen,*canvas; static int gr_installed; @@ -219,7 +222,7 @@ void gr_palette_step_up( int r, int g, int b ) palette_array_t &p = gr_palette; int temp; SDL_Palette *palette; - SDL_Color colors[256]; + array colors; if ( (r==last_r) && (g==last_g) && (b==last_b) ) return; @@ -260,18 +263,14 @@ void gr_palette_step_up( int r, int g, int b ) colors[i].b = temp * 4; } - - SDL_SetColors(canvas, colors, 0, 256); + SDL_SetColors(canvas, colors.data(), 0, colors.size()); } -#undef min -static inline int min(int x, int y) { return x < y ? x : y; } - void gr_palette_load( palette_array_t &pal ) { SDL_Palette *palette; - SDL_Color colors[256]; - ubyte gamma[64]; + array colors; + array gamma; if (pal != gr_current_pal) SDL_FillRect(canvas, NULL, SDL_MapRGB(canvas->format, 0, 0, 0)); @@ -300,7 +299,7 @@ void gr_palette_load( palette_array_t &pal ) i++; } - SDL_SetColors(canvas, colors, 0, 256); + SDL_SetColors(canvas, colors.data(), 0, colors.size()); init_computed_colors(); gr_remap_color_fonts(); gr_remap_mono_fonts(); diff --git a/similar/arch/sdl/key.cpp b/similar/arch/sdl/key.cpp index 5ef282cc0..67188caa3 100644 --- a/similar/arch/sdl/key.cpp +++ b/similar/arch/sdl/key.cpp @@ -34,13 +34,13 @@ static unsigned char Installed = 0; int keyd_repeat = 0; // 1 = use repeats, 0 no repeats volatile unsigned char keyd_last_pressed; volatile unsigned char keyd_last_released; -volatile unsigned char keyd_pressed[256]; +array keyd_pressed; fix64 keyd_time_when_last_pressed; array unicode_frame_buffer; struct keyboard { - ubyte state[256]; + array state; }; static keyboard key_data; diff --git a/similar/editor/med.cpp b/similar/editor/med.cpp index 6675c8e63..e61f4d55a 100644 --- a/similar/editor/med.cpp +++ b/similar/editor/med.cpp @@ -529,8 +529,8 @@ int SetPlayerFromCursegAndRotate() //far enough away to see all of curside int SetPlayerFromCursegMinusOne() { - vms_vector corner_v[4]; - g3s_point corner_p[4]; + array corner_v; + array corner_p; int i; fix max,view_dist=f1_0*10; static int edgenum=0; diff --git a/similar/editor/segment.cpp b/similar/editor/segment.cpp index 354042fff..9ec063524 100644 --- a/similar/editor/segment.cpp +++ b/similar/editor/segment.cpp @@ -1226,8 +1226,7 @@ next_side: ; int med_form_joint(const vsegptridx_t seg1, int side1, const vsegptridx_t seg2, int side2) { int bfi,v,s1; - int lost_vertices[4]; - array remap_vertices; + array lost_vertices, remap_vertices; int validation_list[MAX_VALIDATIONS]; uint_fast32_t nv; @@ -1609,7 +1608,7 @@ void warn_if_concave_segment(const vsegptridx_t s) int med_find_adjacent_segment_side(const vcsegptridx_t sp, int side, segptridx_t &adj_sp, int *adj_side) { int s; - int abs_verts[4]; + array abs_verts; // Stuff abs_verts[4] array with absolute vertex indices for (unsigned v=0; v < 4; v++) diff --git a/similar/editor/seguvs.cpp b/similar/editor/seguvs.cpp index 9e94005d9..b1096f09c 100644 --- a/similar/editor/seguvs.cpp +++ b/similar/editor/seguvs.cpp @@ -273,7 +273,7 @@ static void validate_uv_coordinates(const vsegptr_t segp) // --------------------------------------------------------------------------------------------- // For all faces in side, copy uv coordinates from uvs array to face. -static void copy_uvs_from_side_to_faces(const vsegptr_t segp, int sidenum, uvl uvls[]) +static void copy_uvs_from_side_to_faces(const vsegptr_t segp, int sidenum, array &uvls) { int v; side *sidep = &segp->sides[sidenum]; @@ -320,7 +320,8 @@ fix Stretch_scale_y = F1_0; static void assign_uvs_to_side(const vsegptridx_t segp, int sidenum, uvl *uva, uvl *uvb, int va, int vb) { int vlo,vhi,v0,v1,v2,v3; - uvl uvls[4],ruvmag,fuvmag,uvlo,uvhi; + array uvls; + uvl ruvmag,fuvmag,uvlo,uvhi; fix fmag,mag01; Assert( (va<4) && (vb<4) ); Assert((abs(va - vb) == 1) || (abs(va - vb) == 3)); // make sure the verticies specify an edge diff --git a/similar/main/ai.cpp b/similar/main/ai.cpp index 5d1db3c22..203eacd4d 100644 --- a/similar/main/ai.cpp +++ b/similar/main/ai.cpp @@ -256,7 +256,7 @@ static const char mode_text[][16] = { }; // Index into this array with aip->behavior -static const char behavior_text[6][9] = { +const array behavior_text{ "STILL ", "NORMAL ", "HIDE ", diff --git a/similar/main/aipath.cpp b/similar/main/aipath.cpp index fdf13727a..a1a5a6386 100644 --- a/similar/main/aipath.cpp +++ b/similar/main/aipath.cpp @@ -153,7 +153,7 @@ static uint_fast32_t insert_center_points(point_seg *psegs, uint_fast32_t count) static void move_towards_outside(point_seg *psegs, int *num_points, const vobjptridx_t objp, int rand_flag) { int i; - point_seg new_psegs[200]; + array new_psegs; Assert(*num_points < 200); @@ -1475,7 +1475,7 @@ int Test_size = 1000; static void test_create_path_many(void) __attribute_used; static void test_create_path_many(void) { - point_seg point_segs[200]; + array point_segs; short num_points; int i; @@ -1483,7 +1483,7 @@ static void test_create_path_many(void) for (i=0; i point_segs; short num_points; - create_path_points(object_first, Cursegp-Segments, Markedsegp-Segments, point_segs, &num_points, -1, 0, 0, segment_none); + create_path_points(object_first, Cursegp-Segments, Markedsegp-Segments, point_segs.begin(), &num_points, -1, 0, 0, segment_none); } diff --git a/similar/main/automap.cpp b/similar/main/automap.cpp index a6eea61b9..4bb40ffe7 100644 --- a/similar/main/automap.cpp +++ b/similar/main/automap.cpp @@ -98,8 +98,8 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. struct Edge_info { array verts; // 8 bytes - ubyte sides[4]; // 4 bytes - segnum_t segnum[4]; // 16 bytes // This might not need to be stored... If you can access the normals of a side. + array sides; // 4 bytes + array segnum; // 16 bytes // This might not need to be stored... If you can access the normals of a side. ubyte flags; // 1 bytes // See the EF_??? defines above. color_t color; // 1 bytes ubyte num_faces; // 1 bytes // 31 bytes... diff --git a/similar/main/playsave.cpp b/similar/main/playsave.cpp index 9167a563e..df746df7d 100644 --- a/similar/main/playsave.cpp +++ b/similar/main/playsave.cpp @@ -596,7 +596,8 @@ void plyr_save_stats() { int kills = PlayerCfg.NetlifeKills,deaths = PlayerCfg.NetlifeKilled, neg, i; char filename[PATH_MAX]; - unsigned char buf[16],buf2[16],a; + array buf, buf2; + uint8_t a; memset(filename, '\0', PATH_MAX); snprintf(filename,sizeof(filename),PLAYER_EFFECTIVENESS_FILENAME_FORMAT,static_cast(Players[Player_num].callsign)); auto f = PHYSFSX_openWriteBuffered(filename); @@ -634,7 +635,7 @@ void plyr_save_stats() else i+='A'; - PHYSFSX_printf(f,"%c%s %c%s ",i,buf,i,buf2); + PHYSFSX_printf(f,"%c%s %c%s ",i,buf.data(),i,buf2.data()); if (deaths < 0) { @@ -662,7 +663,7 @@ void plyr_save_stats() else i+='A'; - PHYSFSX_printf(f,"%c%s %c%s\n",i,buf,i,buf2); + PHYSFSX_printf(f, "%c%s %c%s\n", i, buf.data(), i, buf2.data()); } #endif diff --git a/similar/main/robot.cpp b/similar/main/robot.cpp index 5551ac732..0e9900d5d 100644 --- a/similar/main/robot.cpp +++ b/similar/main/robot.cpp @@ -283,7 +283,8 @@ void robot_info_read(PHYSFS_File *fp, robot_info &ri) ri.death_roll = PHYSFSX_readByte(fp); ri.flags = PHYSFSX_readByte(fp); - PHYSFS_read(fp, ri.pad, 3, 1); + array pad; + PHYSFS_read(fp, pad, pad.size(), 1); ri.deathroll_sound = PHYSFSX_readByte(fp); ri.glow = PHYSFSX_readByte(fp);