From 3332984197cedbd742e960f0b440ee49a6915dc9 Mon Sep 17 00:00:00 2001 From: GravisZro Date: Sat, 1 Jun 2024 13:49:52 -0400 Subject: [PATCH] Modernize: Move some arrays to std::array Also replaces a macro with a template function --- Descent3/Game2DLL.cpp | 4 ++-- Descent3/LoadLevel.cpp | 8 ++++---- Descent3/Player.cpp | 2 +- Descent3/damage.cpp | 2 +- Descent3/door.cpp | 2 +- Descent3/door.h | 4 +++- Descent3/doorway.cpp | 4 ++-- Descent3/fireball.cpp | 2 +- Descent3/gamesave.cpp | 31 ++++++++++++++++--------------- Descent3/gamesequence.cpp | 2 +- Descent3/gametexture.cpp | 2 +- Descent3/gametexture.h | 3 ++- Descent3/multi.cpp | 2 +- Descent3/multi_dll_mgr.cpp | 4 ++-- Descent3/render.cpp | 34 +++++++++++++++++----------------- Descent3/room.cpp | 16 ++++++++-------- Descent3/room.h | 6 ++++-- Descent3/ship.cpp | 2 +- Descent3/ship.h | 4 +++- Descent3/weapon.cpp | 2 +- Descent3/weapon.h | 4 +++- lib/polymodel.h | 6 ++++-- model/newstyle.cpp | 4 ++-- model/polymodel.cpp | 9 +++++---- physics/Collide.cpp | 2 +- scripts/AIGame.cpp | 6 ++++-- scripts/LEVEL15.cpp | 32 ++++++++++++++++++++++---------- 27 files changed, 113 insertions(+), 86 deletions(-) diff --git a/Descent3/Game2DLL.cpp b/Descent3/Game2DLL.cpp index 568eb7cb5..4ab3712b5 100644 --- a/Descent3/Game2DLL.cpp +++ b/Descent3/Game2DLL.cpp @@ -137,7 +137,7 @@ static void DUMMYrend_DrawScaledBitmap(int x1, int y1, int x2, int y2, int bm, f void GetGameAPI(game_api *api) { api->objs = (int *)Objects; - api->rooms = (int *)Rooms; + api->rooms = (int *)std::data(Rooms); api->terrain = (int *)Terrain_seg; api->players = (int *)Players; api->netgame = (int *)&Netgame; @@ -145,7 +145,7 @@ void GetGameAPI(game_api *api) { api->ships = (int *)&Ships; api->weapons = (int *)&Weapons; api->Current_mission = (int *)&Current_mission; - api->GameTextures = (int *)GameTextures; + api->GameTextures = (int *)std::data(GameTextures); api->GameVClips = (int *)GameVClips; // Fill in function pointers here. The order here must match the order on the // DLL side diff --git a/Descent3/LoadLevel.cpp b/Descent3/LoadLevel.cpp index d46ee0440..5950b54a9 100644 --- a/Descent3/LoadLevel.cpp +++ b/Descent3/LoadLevel.cpp @@ -2499,7 +2499,7 @@ int ReadRoom(CFILE *ifile, room *rp, int version) { // Check for bad normal if (!t) { - mprintf(1, "WARNING: Room %d face %d has bad normal!\n", rp - Rooms, i); + mprintf(1, "WARNING: Room %d face %d has bad normal!\n", rp - std::data(Rooms), i); } } @@ -5105,7 +5105,7 @@ int SaveLevel(char *filename, bool f_save_room_AABB) { room *rp; int nrooms = 0, nverts = 0, nfaces = 0, nfaceverts = 0, nportals = 0; extern int CountRoomFaceVerts(room * rp); // TEMP: move to room.h - for (i = 0, rp = Rooms; i <= Highest_room_index; i++, rp++) // Count the number of faces, verts, etc. in the level + for (i = 0, rp = std::data(Rooms); i <= Highest_room_index; i++, rp++) // Count the number of faces, verts, etc. in the level if (rp->used) { nrooms++; nverts += rp->num_verts; @@ -5131,13 +5131,13 @@ int SaveLevel(char *filename, bool f_save_room_AABB) { EndChunk(ofile, chunk_start_pos); // Write room wind, if any rooms have wind - for (i = nrooms = 0, rp = Rooms; i <= Highest_room_index; i++, rp++) // Count the number of rooms with wind + for (i = nrooms = 0, rp = std::data(Rooms); i <= Highest_room_index; i++, rp++) // Count the number of rooms with wind if ((rp->wind.x != 0.0) || (rp->wind.y != 0.0) || (rp->wind.z != 0.0)) nrooms++; if (nrooms) { chunk_start_pos = StartChunk(ofile, CHUNK_ROOM_WIND); cf_WriteInt(ofile, nrooms); - for (i = 0, rp = Rooms; i <= Highest_room_index; i++, rp++) { // write the wind values + for (i = 0, rp = std::data(Rooms); i <= Highest_room_index; i++, rp++) { // write the wind values if ((rp->wind.x != 0.0) || (rp->wind.y != 0.0) || (rp->wind.z != 0.0)) { cf_WriteShort(ofile, i); cf_WriteVector(ofile, &rp->wind); diff --git a/Descent3/Player.cpp b/Descent3/Player.cpp index abbf567b1..a6116c736 100644 --- a/Descent3/Player.cpp +++ b/Descent3/Player.cpp @@ -3800,7 +3800,7 @@ void MakeAtuoWaypointList() { Num_waypoints = 0; // Clear room waypoint flags - for (i = 0, rp = Rooms; i <= Highest_room_index; i++, rp++) + for (i = 0, rp = std::data(Rooms); i <= Highest_room_index; i++, rp++) rp->flags &= ~RF_WAYPOINT; // Look through objects for waypoints diff --git a/Descent3/damage.cpp b/Descent3/damage.cpp index 72ff26c8d..59513e18f 100644 --- a/Descent3/damage.cpp +++ b/Descent3/damage.cpp @@ -1602,7 +1602,7 @@ void BreakGlassFace(room *rp, int facenum, vector *hitpnt, vector *hitvec) { MultiSendBreakGlass(rp, facenum); if (Num_broke_glass != MAX_BROKE_GLASS) { - Broke_glass_rooms[Num_broke_glass] = rp - Rooms; + Broke_glass_rooms[Num_broke_glass] = rp - std::data(Rooms); Broke_glass_faces[Num_broke_glass] = facenum; Num_broke_glass++; } diff --git a/Descent3/door.cpp b/Descent3/door.cpp index aef6918e8..58a98c240 100644 --- a/Descent3/door.cpp +++ b/Descent3/door.cpp @@ -128,7 +128,7 @@ // --------------------------------------------------------------------------- // Globals -door Doors[MAX_DOORS]; // door info. +std::array Doors; // door info. int Num_doors = 0; // --------------------------------------------------------------------------- diff --git a/Descent3/door.h b/Descent3/door.h index 90faf1957..b7c0664be 100644 --- a/Descent3/door.h +++ b/Descent3/door.h @@ -97,6 +97,8 @@ #ifndef DOOR_H #define DOOR_H +#include + #ifdef NEWEDITOR /* only include tablefile header (manage stuff for NEWEDITOR) */ #include "..\neweditor\ned_TableFile.h" #include "..\neweditor\ned_Door.h" @@ -142,7 +144,7 @@ typedef struct { // The max number of predefined doors #define MAX_DOORS 60 extern int Num_doors; // number of actual doors in game. -extern door Doors[]; +extern std::array Doors; // Sets all doors to unused void InitDoors(); diff --git a/Descent3/doorway.cpp b/Descent3/doorway.cpp index 023f9ca6d..7202151c6 100644 --- a/Descent3/doorway.cpp +++ b/Descent3/doorway.cpp @@ -378,7 +378,7 @@ void DoorwayDeactivateAll() { room *rp; // Go through all rooms and deactivate doors - for (r = 0, rp = Rooms; r <= Highest_room_index; r++) { + for (r = 0, rp = std::data(Rooms); r <= Highest_room_index; r++) { if (rp->used && (rp->flags & RF_DOOR)) { if (rp->doorway_data->state != DOORWAY_STOPPED) { doorway *dp = rp->doorway_data; @@ -629,7 +629,7 @@ void DoorwayRebuildActiveList() { Num_active_doorways = 0; // Go through all rooms and look for active doors - for (r = 0, rp = Rooms; r <= Highest_room_index; r++) { + for (r = 0, rp = std::data(Rooms); r <= Highest_room_index; r++) { if (rp->used && (rp->flags & RF_DOOR)) { ASSERT(rp->doorway_data != NULL); if (rp->doorway_data->state != DOORWAY_STOPPED) diff --git a/Descent3/fireball.cpp b/Descent3/fireball.cpp index b82aa27a8..ab0381695 100644 --- a/Descent3/fireball.cpp +++ b/Descent3/fireball.cpp @@ -1091,7 +1091,7 @@ void CreateSplintersFromBody(object *obj, float explosion_mag, float lifetime) { dest = center + obj->pos; // Now create splinter with that faces center position - int s_objnum = ObjCreate(OBJ_SPLINTER, pm - Poly_models, obj->roomnum, &dest, NULL); + int s_objnum = ObjCreate(OBJ_SPLINTER, pm - Poly_models.data(), obj->roomnum, &dest, NULL); if (s_objnum < 0) { mprintf(0, "Couldn't create splinter object!\n"); return; diff --git a/Descent3/gamesave.cpp b/Descent3/gamesave.cpp index 7707b4eb2..2a5f663b6 100644 --- a/Descent3/gamesave.cpp +++ b/Descent3/gamesave.cpp @@ -823,16 +823,17 @@ bool SaveGameState(const char *pathname, const char *description) { ////////////////////////////////////////////////////////////////////////////// -#define SAVE_DATA_TABLE(_nitems, _array) \ - do { \ - highest_index = -1; \ - for (i = 0; i < (_nitems); i++) \ - if (_array[i].used) \ - highest_index = i; \ - gs_WriteShort(fp, highest_index + 1); \ - for (i = 0; i <= highest_index; i++) \ - cf_WriteString(fp, _array[i].used ? _array[i].name : ""); \ - } while (0) +template +void save_data_table(CFILE *fp, const std::array& data) { + int16_t highest_index = -1; + for (int16_t i = 0; i < sz; i++) + if (data[i].used) + highest_index = i; + + gs_WriteShort(fp, highest_index + 1); + for (int16_t i = 0; i <= highest_index; i++) + cf_WriteString(fp, data[i].used ? data[i].name : ""); +} // writes out translation tables. void SGSXlateTables(CFILE *fp) { @@ -850,19 +851,19 @@ void SGSXlateTables(CFILE *fp) { cf_WriteString(fp, (Object_info[i].type != OBJ_NONE) ? Object_info[i].name : ""); // write out polymodel list. - SAVE_DATA_TABLE(MAX_POLY_MODELS, Poly_models); + save_data_table(fp, Poly_models); // save out door list - SAVE_DATA_TABLE(MAX_DOORS, Doors); + save_data_table(fp, Doors); // save out ship list - SAVE_DATA_TABLE(MAX_SHIPS, Ships); + save_data_table(fp, Ships); // save out weapons list - SAVE_DATA_TABLE(MAX_WEAPONS, Weapons); + save_data_table(fp, Weapons); // save out textures list - SAVE_DATA_TABLE(MAX_TEXTURES, GameTextures); + save_data_table(fp, GameTextures); // write out bitmap handle list. look at all Objects that are fireballs and // save their handles-names. diff --git a/Descent3/gamesequence.cpp b/Descent3/gamesequence.cpp index 877bb829b..a03b31dfb 100644 --- a/Descent3/gamesequence.cpp +++ b/Descent3/gamesequence.cpp @@ -1743,7 +1743,7 @@ void StartTextureSounds() { room *rp; face *fp; - for (r = 0, rp = Rooms; r <= Highest_room_index; r++, rp++) { + for (r = 0, rp = std::data(Rooms); r <= Highest_room_index; r++, rp++) { if (rp->used) { for (f = 0, fp = rp->faces; f < rp->num_faces; f++, fp++) { int sound = GameTextures[fp->tmap].sound; diff --git a/Descent3/gametexture.cpp b/Descent3/gametexture.cpp index c9961f0cd..7df1517b0 100644 --- a/Descent3/gametexture.cpp +++ b/Descent3/gametexture.cpp @@ -285,7 +285,7 @@ // TODO: MTS: this is only used in this file. int Num_textures = 0; -texture GameTextures[MAX_TEXTURES]; +std::array GameTextures; extern bool Mem_superlow_memory_mode; diff --git a/Descent3/gametexture.h b/Descent3/gametexture.h index 64fc7a76c..eb50dfbfb 100644 --- a/Descent3/gametexture.h +++ b/Descent3/gametexture.h @@ -190,6 +190,7 @@ #ifndef GAMETEXTURE_H #define GAMETEXTURE_H +#include #ifdef NEWEDITOR /* only include tablefile header (manage stuff for NEWEDITOR) */ #include "..\neweditor\ned_TableFile.h" @@ -308,7 +309,7 @@ typedef struct { } texture; -extern texture GameTextures[MAX_TEXTURES]; +extern std::array GameTextures; extern int Num_textures; // Inits the texture system, returning 1 if successful diff --git a/Descent3/multi.cpp b/Descent3/multi.cpp index 093798836..baf993806 100644 --- a/Descent3/multi.cpp +++ b/Descent3/multi.cpp @@ -9132,7 +9132,7 @@ void MultiSendBreakGlass(room *rp, int facenum) { int size_offset; size_offset = START_DATA(MP_BREAK_GLASS, data, &count); - MultiAddUshort(rp - Rooms, data, &count); + MultiAddUshort(rp - std::data(Rooms), data, &count); MultiAddUshort(facenum, data, &count); END_DATA(count, data, size_offset); diff --git a/Descent3/multi_dll_mgr.cpp b/Descent3/multi_dll_mgr.cpp index dcfedc2dd..532c2bd8d 100644 --- a/Descent3/multi_dll_mgr.cpp +++ b/Descent3/multi_dll_mgr.cpp @@ -388,12 +388,12 @@ void GetMultiAPI(multi_api *api) { // make the compiler happy bool (*fp_PlayerIsShipAllowed)(int, int) = PlayerIsShipAllowed; api->objs = (int *)Objects; - api->rooms = (int *)Rooms; + api->rooms = (int *)std::data(Rooms); api->terrain = (int *)Terrain_seg; api->players = (int *)Players; api->netgame = (int *)&Netgame; api->netplayers = (int *)&NetPlayers; - api->ships = (int *)Ships; + api->ships = (int *)Ships.data(); // Fill in function pointers here. The order here must match the order on the // DLL side diff --git a/Descent3/render.cpp b/Descent3/render.cpp index 3674bee08..9aca80e57 100644 --- a/Descent3/render.cpp +++ b/Descent3/render.cpp @@ -1143,7 +1143,7 @@ void BuildRoomList(int start_room_num) { if (Render_all_external_rooms) { int i; room *rp; - for (i = 0, rp = Rooms; i <= Highest_room_index; i++, rp++) { + for (i = 0, rp = std::data(Rooms); i <= Highest_room_index; i++, rp++) { if (rp->used && (rp->flags & RF_EXTERNAL)) { for (int t = 0; t < rp->num_faces; t++) rp->faces[t].flags |= FF_VISIBLE; @@ -1955,7 +1955,7 @@ void RenderFace(room *rp, int facenum) { if (TSearch_on) { if (rend_GetPixel(TSearch_x, TSearch_y) != oldcolor) { TSearch_found_type = TSEARCH_FOUND_MINE; - TSearch_seg = rp - Rooms; + TSearch_seg = rp - std::data(Rooms); TSearch_face = facenum; } } @@ -1966,7 +1966,7 @@ void RenderFace(room *rp, int facenum) { ((fp->flags & FF_CORONA) || FastCoronas) && (fp->flags & FF_LIGHTMAP) && UseHardware && (GameTextures[fp->tmap].flags & TF_LIGHT)) { if (Num_glows_this_frame < MAX_LIGHT_GLOWS && Detail_settings.Coronas_enabled) { - LightGlowsThisFrame[Num_glows_this_frame].roomnum = rp - Rooms; + LightGlowsThisFrame[Num_glows_this_frame].roomnum = rp - std::data(Rooms); LightGlowsThisFrame[Num_glows_this_frame].facenum = facenum; Num_glows_this_frame++; } @@ -2207,7 +2207,7 @@ void SetupRoomFog(room *rp, vector *eye, matrix *orient, int viewer_room) { return; } - if (viewer_room == (rp - Rooms)) { + if (viewer_room == (rp - std::data(Rooms))) { // viewer is in the room vector *vec = eye; Room_fog_plane_check = 1; @@ -2219,7 +2219,7 @@ void SetupRoomFog(room *rp, vector *eye, matrix *orient, int viewer_room) { // find the 'fogroom' number (we should have put it in here if we will render the room) int found_room = -1; for (int i = 0; i < Num_fogged_rooms_this_frame && found_room == -1; i++) { - if (Fog_portal_data[i].roomnum == rp - Rooms) { + if (Fog_portal_data[i].roomnum == rp - std::data(Rooms)) { found_room = i; break; } @@ -2321,7 +2321,7 @@ void RenderRoomUnsorted(room *rp) { face_depth[fn] += World_point_buffer[rp->wpb_index + fp->face_verts[vn]].p3_z; } Postrender_list[Num_postrenders].type = PRT_WALL; - Postrender_list[Num_postrenders].roomnum = rp - Rooms; + Postrender_list[Num_postrenders].roomnum = rp - std::data(Rooms); Postrender_list[Num_postrenders].facenum = fn; Postrender_list[Num_postrenders++].z = face_depth[fn] /= fp->num_verts; ; @@ -2388,12 +2388,12 @@ void ComputeRoomPulseLight(room *rp) { } if (!In_editor_mode) { if (rp->flags & RF_STROBE) { - int val = (Gametime * 10) + (rp - Rooms); + int val = (Gametime * 10) + (rp - std::data(Rooms)); if (val % 2) Room_light_val = 0; } if (rp->flags & RF_FLICKER) { - ps_srand((Gametime * 1000) + (rp - Rooms)); + ps_srand((Gametime * 1000) + (rp - std::data(Rooms))); if (ps_rand() % 2) Room_light_val = 0; } @@ -2575,7 +2575,7 @@ void CheckLightGlowsForRoom(room *rp) { // shoot a ray from the light position to the current vertex if (FastCoronas) { if (rp->flags & RF_EXTERNAL) { - SetGlowStatus(rp - Rooms, LightGlowsThisFrame[i].facenum, ¢er, size, FastCoronas); + SetGlowStatus(rp - std::data(Rooms), LightGlowsThisFrame[i].facenum, ¢er, size, FastCoronas); continue; } vector subvec = Viewer_eye - center; @@ -2584,7 +2584,7 @@ void CheckLightGlowsForRoom(room *rp) { subvec += center; fq.p0 = ¢er; fq.p1 = &subvec; - fq.startroom = rp - Rooms; + fq.startroom = rp - std::data(Rooms); } else { fq.p0 = &Viewer_eye; fq.p1 = ¢er; @@ -2598,7 +2598,7 @@ void CheckLightGlowsForRoom(room *rp) { int fate = fvi_FindIntersection(&fq, &hit_info); if (fate != HIT_NONE) continue; - SetGlowStatus(rp - Rooms, LightGlowsThisFrame[i].facenum, ¢er, size, FastCoronas); + SetGlowStatus(rp - std::data(Rooms), LightGlowsThisFrame[i].facenum, ¢er, size, FastCoronas); } } // Called before a frame starts to render - sets all of our light glows to decreasing @@ -2931,11 +2931,11 @@ void RenderMirroredRoom(room *rp) { RotateRoomPoints(rp, mirror_dest_vecs); // Mark facing faces - int save_frame = Facing_visited[rp - Rooms]; - Facing_visited[rp - Rooms] = 0; + int save_frame = Facing_visited[rp - std::data(Rooms)]; + Facing_visited[rp - std::data(Rooms)] = 0; - MarkFacingFaces(rp - Rooms, mirror_dest_vecs); - Facing_visited[rp - Rooms] = save_frame; + MarkFacingFaces(rp - std::data(Rooms), mirror_dest_vecs); + Facing_visited[rp - std::data(Rooms)] = save_frame; // Render the mirror room rend_SetColorModel(CM_MONO); rend_SetLighting(LS_GOURAUD); @@ -2973,7 +2973,7 @@ void RenderRoom(room *rp) { ComputeRoomPulseLight(rp); // Mark it visible for automap - AutomapVisMap[rp - Rooms] = 1; + AutomapVisMap[rp - std::data(Rooms)] = 1; #ifdef EDITOR if (!UseHardware) { @@ -3353,7 +3353,7 @@ void RenderMirrorRooms() { if (do_mirror_face) // This room has a mirror...render it first { Render_mirror_for_room = true; - Mirror_room = rp - Rooms; + Mirror_room = rp - std::data(Rooms); BuildMirroredRoomList(); for (int t = Num_mirrored_rooms - 1; t >= 0; t--) diff --git a/Descent3/room.cpp b/Descent3/room.cpp index 184619341..04dbd5070 100644 --- a/Descent3/room.cpp +++ b/Descent3/room.cpp @@ -426,8 +426,8 @@ #include "bnode.h" // Global array of rooms -room Rooms[MAX_ROOMS + MAX_PALETTE_ROOMS]; -room_changes Room_changes[MAX_ROOM_CHANGES]; +std::array Rooms; +std::array Room_changes; extern int Cur_selected_room, Cur_selected_face; @@ -593,11 +593,11 @@ void InitRoom(room *rp, int nverts, int nfaces, int nportals) { rp->bn_info.nodes = NULL; #if (defined(EDITOR) || defined(NEWEDITOR)) - Room_multiplier[rp - Rooms] = 1.0; + Room_multiplier[rp - std::data(Rooms)] = 1.0; - Room_ambience_r[rp - Rooms] = 0.0; - Room_ambience_g[rp - Rooms] = 0.0; - Room_ambience_b[rp - Rooms] = 0.0; + Room_ambience_r[rp - std::data(Rooms)] = 0.0; + Room_ambience_g[rp - std::data(Rooms)] = 0.0; + Room_ambience_b[rp - std::data(Rooms)] = 0.0; #endif rp->used = 1; // flag this room as used @@ -710,7 +710,7 @@ void FreeAllRooms() { int rn; room *rp; mprintf(1, "Freeing rooms...Higest_room_index %d\n", Highest_room_index); - for (rn = 0, rp = Rooms; rn <= Highest_room_index; rn++, rp++) { + for (rn = 0, rp = std::data(Rooms); rn <= Highest_room_index; rn++, rp++) { if (rp->used) { // mprintf(2, "rn %d\n", rn); FreeRoom(rp); @@ -1193,7 +1193,7 @@ void CreateRoomObjects() { ObjDelete(objnum); // Now go through all rooms & create objects for external ones - for (r = 0, rp = Rooms; r <= Highest_room_index; r++, rp++) + for (r = 0, rp = std::data(Rooms); r <= Highest_room_index; r++, rp++) if (rp->used && (rp->flags & RF_EXTERNAL)) { vector pos; float rad; diff --git a/Descent3/room.h b/Descent3/room.h index ea5e4541f..c46958af1 100644 --- a/Descent3/room.h +++ b/Descent3/room.h @@ -363,6 +363,8 @@ #ifndef _ROOM_H #define _ROOM_H +#include + #include "pstypes.h" #include "vecmat_external.h" #include "gametexture.h" @@ -400,7 +402,7 @@ typedef struct { // Globals // -extern room Rooms[]; // global sparse array of rooms +extern std::array Rooms; // global sparse array of rooms extern int Highest_room_index; // index of highest-numbered room // @@ -408,7 +410,7 @@ extern int Highest_room_index; // index of highest-numbered room // // Handy macro to convert a room ptr to a room number -#define ROOMNUM(r) (r - Rooms) +#define ROOMNUM(r) (r - Rooms.data()) // See above from RF_MINE_MASK #define MINE_INDEX(x) ((Rooms[x].flags & RFM_MINE) >> 20) diff --git a/Descent3/ship.cpp b/Descent3/ship.cpp index 648c29089..663d099be 100644 --- a/Descent3/ship.cpp +++ b/Descent3/ship.cpp @@ -115,7 +115,7 @@ #define DEFAULT_SHIP_SIZE 4.0 -ship Ships[MAX_SHIPS]; +std::array Ships; int Num_ships = 0; // There are no static ships diff --git a/Descent3/ship.h b/Descent3/ship.h index 9a0dd154e..e94ad678a 100644 --- a/Descent3/ship.h +++ b/Descent3/ship.h @@ -113,6 +113,8 @@ #ifndef SHIP_H #define SHIP_H +#include + #include "pstypes.h" #include "manage.h" #include "object.h" @@ -174,7 +176,7 @@ typedef struct { } ship; extern int Num_ships; -extern ship Ships[MAX_SHIPS]; +extern std::array Ships; extern const char *AllowedShips[]; diff --git a/Descent3/weapon.cpp b/Descent3/weapon.cpp index cb845942d..817698597 100644 --- a/Descent3/weapon.cpp +++ b/Descent3/weapon.cpp @@ -364,7 +364,7 @@ // #include "samirlog.h" #define LOGFILE(_s) -weapon Weapons[MAX_WEAPONS]; +std::array Weapons; int Num_weapons = 0; const char *Static_weapon_names[] = { diff --git a/Descent3/weapon.h b/Descent3/weapon.h index 2a2896b4c..75ecddd45 100644 --- a/Descent3/weapon.h +++ b/Descent3/weapon.h @@ -193,6 +193,8 @@ #ifndef WEAPON_H #define WEAPON_H +#include + #include "pstypes.h" #include "manage.h" #include "object.h" @@ -325,7 +327,7 @@ typedef struct { extern float Primary_ramp_time, Secondary_ramp_time; extern int Num_weapons; -extern weapon Weapons[MAX_WEAPONS]; +extern std::array Weapons; extern const char *Static_weapon_names[]; extern int Static_weapon_names_msg[]; extern int Static_weapon_ckpt_names[][2]; diff --git a/lib/polymodel.h b/lib/polymodel.h index 0203437cd..f51bbb486 100644 --- a/lib/polymodel.h +++ b/lib/polymodel.h @@ -294,6 +294,8 @@ #ifndef POLYMODEL_H #define POLYMODEL_H +#include + #include "manage.h" #include "pstypes.h" #include "vecmat.h" @@ -311,7 +313,7 @@ #define SOF_MONITOR_MASK 0x0ff0 // mask for monitors extern int Num_poly_models; -extern poly_model Poly_models[]; +extern std::array Poly_models; extern int Polymodel_use_effect; extern polymodel_effect Polymodel_effect; @@ -326,7 +328,7 @@ extern lightmap_object *Polylighting_lightmap_object; extern vector Model_eye_position; extern vector Interp_pos_instance_vec; -extern g3Point Robot_points[]; +extern std::array Robot_points; // Flag to draw an outline around the faces extern bool Polymodel_outline_mode; diff --git a/model/newstyle.cpp b/model/newstyle.cpp index 89eded770..d91e88663 100644 --- a/model/newstyle.cpp +++ b/model/newstyle.cpp @@ -309,7 +309,7 @@ inline void RenderSubmodelFace(poly_model *pm, bsp_info *sm, int facenum) { // If there is a texture, set it up if (texp) { - bm_handle = GetTextureBitmap(texp - GameTextures, 0); + bm_handle = GetTextureBitmap(texp - GameTextures.data(), 0); rend_SetTextureType(TT_LINEAR); if (Polymodel_light_type == POLYMODEL_LIGHTING_GOURAUD) @@ -323,7 +323,7 @@ inline void RenderSubmodelFace(poly_model *pm, bsp_info *sm, int facenum) { // Setup custom color if there is one if (Polymodel_use_effect && (Polymodel_effect.type & PEF_CUSTOM_COLOR) && - (texp - GameTextures) == Multicolor_texture) { + (texp - GameTextures.data()) == Multicolor_texture) { int r, g, b; rend_SetLighting(LS_FLAT_GOURAUD); diff --git a/model/polymodel.cpp b/model/polymodel.cpp index 799eadab1..6001e90f0 100644 --- a/model/polymodel.cpp +++ b/model/polymodel.cpp @@ -598,6 +598,7 @@ * $NoKeywords: $ */ + #include "objinfo.h" #include "polymodel.h" #include "pserror.h" @@ -619,12 +620,12 @@ #include int Num_poly_models = 0; -poly_model Poly_models[MAX_POLY_MODELS]; +std::array Poly_models; -g3Point Robot_points[MAX_POLYGON_VECS]; +std::array Robot_points; vector Interp_pos_instance_vec = {0, 0, 0}; -vector Instance_vec_stack[MAX_SUBOBJECTS]; +std::array Instance_vec_stack; int Instance_vec_cnt = 0; #ifdef _DEBUG @@ -2055,7 +2056,7 @@ int ReadNewModelFile(int polynum, CFILE *infile) { if (pm->n_models > MAX_SUBOBJECTS) { mprintf(0, "This model has more than the max number of subobjects! (%d)\n", MAX_SUBOBJECTS); Int3(); - FreePolyModel(pm - Poly_models); + FreePolyModel(pm - Poly_models.data()); return 0; } diff --git a/physics/Collide.cpp b/physics/Collide.cpp index 65fcb345d..e683f4fd4 100644 --- a/physics/Collide.cpp +++ b/physics/Collide.cpp @@ -1067,7 +1067,7 @@ void DoWallEffects(object *weapon, int surface_tmap) { } else if (texp->flags & TF_RUBBLE) { if ((ps_rand() % 4) == 0) { int num_rubble = (ps_rand() % 3) + 1; - int bm_handle = GetTextureBitmap(texp - GameTextures, 0); + int bm_handle = GetTextureBitmap(texp - GameTextures.data(), 0); uint16_t *data = bm_data(bm_handle, 0); uint16_t color = data[(bm_w(bm_handle, 0) * (bm_h(bm_handle, 0) / 2)) + (bm_w(bm_handle, 0) / 2)]; diff --git a/scripts/AIGame.cpp b/scripts/AIGame.cpp index 712d7940a..988a71f18 100644 --- a/scripts/AIGame.cpp +++ b/scripts/AIGame.cpp @@ -18,6 +18,7 @@ // AIGame.cpp // +#include #include #include #include @@ -1634,7 +1635,8 @@ typedef struct { int name_idx; } tThiefItems; -static tThiefItems ThiefableItems[] = { +static const std::array ThiefableItems = { + tThiefItems {0, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_LASERS}, // Laser {1, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_VAUSS}, // Vauss {2, THIEFABLEITEM_PRIMARY, 0.70f, 0.50f, 0.70f, TXT_WEAP_MICROWAVE}, // Microwave @@ -1665,7 +1667,7 @@ static tThiefItems ThiefableItems[] = { {6, THIEFABLEITEM_ACCESSORY, 1.00f, 0.60f, 1.00f, TXT_WEAP_RAPIDFIRE}, // RapidFire {7, THIEFABLEITEM_ACCESSORY, 1.00f, 0.60f, 1.00f, TXT_WEAP_QUADLASERS}, // Quads }; -static int numThiefableItems = sizeof(ThiefableItems) / sizeof(tThiefItems); +const int numThiefableItems = std::size(ThiefableItems); typedef struct { uint16_t id; diff --git a/scripts/LEVEL15.cpp b/scripts/LEVEL15.cpp index e3b67ecab..c2b2f1582 100644 --- a/scripts/LEVEL15.cpp +++ b/scripts/LEVEL15.cpp @@ -22,6 +22,8 @@ // Filename: Level15.cpp // Version: 3 ///////////////////////////////////////////////////////////////////// + +#include #include #include #include @@ -837,12 +839,13 @@ const char *GetMessage(const char *name); #define MatCenStateD (*((int *)(&User_vars[3]))) #define MatCenStateE (*((int *)(&User_vars[4]))) -typedef struct { +struct tMyHandle { const char *name; int handle; -} tMyHandle; +}; -tMyHandle MyObjects[] = { +std::array MyObjects = { + tMyHandle {"MatCen1Peg", -1}, {"MatCen2Peg", -1}, {"MatCen3Peg", -1}, {"MatCen4Peg", -1}, {"MatCen5Peg", -1}, {"MatCenSwitchA", -1}, {"MatCenSwitchB", -1}, {"MatCenSwitchC", -1}, {"MatCenSwitchD", -1}, {"MatCenSwitchE", -1}, {"MatCenSwitchF", -1}, {"MatCenSwitchG", -1}, @@ -850,20 +853,29 @@ tMyHandle MyObjects[] = { {"MatCen4Spewer", -1}, {"MatCen5Spewer", -1}, }; -tMyHandle MyMatcens[] = {{"MatCen5", -1}, {"MatCen4", -1}, {"MatCen2", -1}, {"MatCen3", -1}, {"MatCen1", -1}}; +std::array MyMatcens = { + tMyHandle + {"MatCen5", -1}, + {"MatCen4", -1}, + {"MatCen2", -1}, + {"MatCen3", -1}, + {"MatCen1", -1}}; -tMyHandle MyRooms[] = {{"MagicMatCenArmory", -1}}; +std::array MyRooms = {{"MagicMatCenArmory", -1}}; typedef struct { const char *name; const char *mem; } tMyMessage; -tMyMessage MyMessages[] = {{"MagicMatCenSwitches", NULL}, {"MatCenSwitchDOn", NULL}, {"MatCenSwitchDOff", NULL}, - {"MatCenSwitchGOn", NULL}, {"MatCenSwitchGOff", NULL}, {"MatCenSwitchCOn", NULL}, - {"MatCenSwitchCOff", NULL}, {"MatCenSwitchEOn", NULL}, {"MatCenSwitchEOff", NULL}, - {"MatCenSwitchBOn", NULL}, {"MatCenSwitchBOff", NULL}, {"MatCenSwitchFOn", NULL}, - {"MatCenSwitchFOff", NULL}, {"MatCenSwitchAOn", NULL}, {"MatCenSwitchAOff", NULL}}; +std::array MyMessages = { + tMyMessage + {"MagicMatCenSwitches", NULL}, {"MatCenSwitchDOn", NULL}, {"MatCenSwitchDOff", NULL}, + {"MatCenSwitchGOn", NULL}, {"MatCenSwitchGOff", NULL}, {"MatCenSwitchCOn", NULL}, + {"MatCenSwitchCOff", NULL}, {"MatCenSwitchEOn", NULL}, {"MatCenSwitchEOff", NULL}, + {"MatCenSwitchBOn", NULL}, {"MatCenSwitchBOff", NULL}, {"MatCenSwitchFOn", NULL}, + {"MatCenSwitchFOff", NULL}, {"MatCenSwitchAOn", NULL}, {"MatCenSwitchAOff", NULL} + }; int GetMyMatCen(int id) { if (MyMatcens[id].handle == -1)