From a46f0f0c0d4c7793d3990404ff90ac3afc5d551d Mon Sep 17 00:00:00 2001 From: GravisZro Date: Sat, 1 Jun 2024 17:05:13 -0400 Subject: [PATCH] More of the same --- Descent3/AIMain.h | 2 +- Descent3/AImain.cpp | 2 +- Descent3/Game2DLL.cpp | 6 +- Descent3/LoadLevel.cpp | 8 +-- Descent3/Player.cpp | 4 +- Descent3/demofile.cpp | 9 +-- Descent3/fireball.cpp | 2 +- Descent3/gamecinematics.cpp | 2 +- Descent3/gamesave.cpp | 2 +- Descent3/loadstate.cpp | 2 +- Descent3/mission_download.cpp | 4 +- Descent3/multi.cpp | 101 +++++++++++++++++----------------- Descent3/multi.h | 57 +++++++++---------- Descent3/multi_client.cpp | 2 +- Descent3/multi_connect.cpp | 20 +++---- Descent3/multi_dll_mgr.cpp | 8 +-- Descent3/multi_server.cpp | 6 +- Descent3/player.h | 6 +- Descent3/room.h | 2 +- lib/PHYSICS.H | 2 +- lib/demofile.h | 5 +- lib/networking.h | 3 +- model/newstyle.cpp | 4 +- model/polymodel.cpp | 2 +- networking/networking.cpp | 48 ++++++++-------- physics/Collide.cpp | 2 +- physics/physics.cpp | 2 +- 27 files changed, 157 insertions(+), 156 deletions(-) diff --git a/Descent3/AIMain.h b/Descent3/AIMain.h index 819ba56ab..75820cbbc 100644 --- a/Descent3/AIMain.h +++ b/Descent3/AIMain.h @@ -157,7 +157,7 @@ #define AI_SOUND_SHORT_DIST 60.0f extern int AI_NumRendered; -extern int AI_RenderedList[MAX_OBJECTS]; +extern std::array AI_RenderedList; extern int AI_NumHostileAlert; // A rough number of alert/hostile robots // that have seen the player recently diff --git a/Descent3/AImain.cpp b/Descent3/AImain.cpp index 6f780df99..b662657b3 100644 --- a/Descent3/AImain.cpp +++ b/Descent3/AImain.cpp @@ -1625,7 +1625,7 @@ const char *const Ai_movement_subtype_walking_strings[MAX_AI_INIT_MOVEMENT_SUBTY #define AI_MAX_MELEE_RANGE 5.0f int AI_NumRendered; -int AI_RenderedList[MAX_OBJECTS]; +std::array AI_RenderedList; int AI_NumHostileAlert = 0; diff --git a/Descent3/Game2DLL.cpp b/Descent3/Game2DLL.cpp index 0ab76380d..676f77850 100644 --- a/Descent3/Game2DLL.cpp +++ b/Descent3/Game2DLL.cpp @@ -139,7 +139,7 @@ void GetGameAPI(game_api *api) { api->objs = (int *)Objects; api->rooms = (int *)std::data(Rooms); api->terrain = (int *)Terrain_seg; - api->players = (int *)Players; + api->players = (int *)std::data(Players); api->netgame = (int *)&Netgame; api->netplayers = (int *)&NetPlayers; api->ships = (int *)&Ships; @@ -534,8 +534,8 @@ void GetGameAPI(game_api *api) { api->vp[8] = (int *)&Game_interface_mode; api->vp[9] = (int *)LocalD3Dir; api->vp[10] = (int *)&Game_is_master_tracker_game; - api->vp[11] = (int *)Local_object_list; - api->vp[12] = (int *)Server_object_list; + api->vp[11] = (int *)std::data(Local_object_list); + api->vp[12] = (int *)std::data(Server_object_list); api->vp[13] = (int *)&Dedicated_server; api->vp[14] = (int *)Player_colors; api->vp[15] = (int *)&Hud_aspect_x; diff --git a/Descent3/LoadLevel.cpp b/Descent3/LoadLevel.cpp index 51289a4ee..641da955f 100644 --- a/Descent3/LoadLevel.cpp +++ b/Descent3/LoadLevel.cpp @@ -3492,8 +3492,8 @@ void ReadPlayerStarts(CFILE *infile, int fileversion) { void VerifyObjectList() { int i; - uint8_t already_listed[MAX_OBJECTS]; - memset(already_listed, 0, MAX_OBJECTS); + std::array already_listed; + already_listed.fill(0); for (i = 0; i <= Highest_room_index; i++) { room *rp = &Rooms[i]; @@ -3790,8 +3790,8 @@ int LoadLevel(char *filename, void (*cb_fn)(const char *, int, int)) { } else if (ISCHUNK(CHUNK_OBJECT_HANDLES)) { // Read in any non-zero handles for deleted objects int handle, objnum; - uint8_t already_loaded[MAX_OBJECTS]; - memset(already_loaded, 0, MAX_OBJECTS); + std::array already_loaded; + already_loaded.fill(0); // Get the number of handles in the file n = cf_ReadInt(ifile); diff --git a/Descent3/Player.cpp b/Descent3/Player.cpp index 000b683ee..1e8187837 100644 --- a/Descent3/Player.cpp +++ b/Descent3/Player.cpp @@ -1135,7 +1135,7 @@ #include -player Players[MAX_PLAYERS]; +std::array Players; int Player_num; int Num_teams = 0; @@ -1143,7 +1143,7 @@ int Team_game = 0; int Default_ship_permission = 0x01; float HudNameTan = -1; -team Teams[MAX_TEAMS]; +std::array Teams; static int Highest_player_start = 0; diff --git a/Descent3/demofile.cpp b/Descent3/demofile.cpp index 34bf37d20..23c79106b 100644 --- a/Descent3/demofile.cpp +++ b/Descent3/demofile.cpp @@ -309,8 +309,8 @@ static float Demo_last_pinfo; float Demo_frame_ofs; static int Demo_auto_idx = 0; uint32_t Demo_flags = 0; -uint16_t Demo_obj_map[MAX_OBJECTS]; -static bool Demo_turretchanged[MAX_OBJECTS]; +std::array Demo_obj_map; +static std::array Demo_turretchanged; bool Demo_looping = false; bool Demo_paused = false; bool Demo_do_one_frame = false; @@ -321,7 +321,7 @@ bool Demo_make_movie = false; #define DEMO_PINFO_UPDATE .1 #define MAX_COOP_TURRETS 400 -extern float turret_holder[MAX_COOP_TURRETS]; +extern std::array turret_holder; extern gs_tables *gs_Xlates; @@ -544,9 +544,6 @@ void DemoWriteObjCreate(uint8_t type, uint16_t id, int roomnum, vector *pos, con } } -#define MAX_COOP_TURRETS 400 -extern float turret_holder[MAX_COOP_TURRETS]; - void DemoWriteTurretChanged(uint16_t objnum) { Demo_turretchanged[objnum] = true; } void DemoReadTurretChanged(void) { diff --git a/Descent3/fireball.cpp b/Descent3/fireball.cpp index ab0381695..4d362ab4c 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.data(), obj->roomnum, &dest, NULL); + int s_objnum = ObjCreate(OBJ_SPLINTER, pm - std::data(Poly_models), obj->roomnum, &dest, NULL); if (s_objnum < 0) { mprintf(0, "Couldn't create splinter object!\n"); return; diff --git a/Descent3/gamecinematics.cpp b/Descent3/gamecinematics.cpp index fd723ba2e..384aa8cd2 100644 --- a/Descent3/gamecinematics.cpp +++ b/Descent3/gamecinematics.cpp @@ -223,7 +223,7 @@ extern int DoAI; extern bool Game_being_played_from_quick_play; #endif #endif -extern uint16_t Demo_obj_map[MAX_OBJECTS]; +extern std::array Demo_obj_map; struct { // some important, pre-computed times diff --git a/Descent3/gamesave.cpp b/Descent3/gamesave.cpp index c29248c87..7b5f94245 100644 --- a/Descent3/gamesave.cpp +++ b/Descent3/gamesave.cpp @@ -999,7 +999,7 @@ void SGSVisEffects(CFILE *fp) { } extern int Physics_NumLinked; -extern int PhysicsLinkList[MAX_OBJECTS]; +extern std::array PhysicsLinkList; extern char MarkerMessages[MAX_PLAYERS * 2][MAX_MARKER_MESSAGE_LENGTH]; extern int Marker_message; void InsureSaveGame(CFILE *fp) { cf_WriteInt(fp, 0xF00D4B0B); } diff --git a/Descent3/loadstate.cpp b/Descent3/loadstate.cpp index 9100d47f9..5d2e3d838 100644 --- a/Descent3/loadstate.cpp +++ b/Descent3/loadstate.cpp @@ -815,7 +815,7 @@ int LGSPlayers(CFILE *fp) { } extern int Physics_NumLinked; -extern int PhysicsLinkList[MAX_OBJECTS]; +extern std::array PhysicsLinkList; int inreadobj = 0; diff --git a/Descent3/mission_download.cpp b/Descent3/mission_download.cpp index 0e8b6ab03..081bfb2b9 100644 --- a/Descent3/mission_download.cpp +++ b/Descent3/mission_download.cpp @@ -173,8 +173,8 @@ msn_urls *msn_GetURL(network_address *net_addr) { start_time = timer_GetTime(); while ((timer_GetTime() - start_time < URL_ASK_POLL_TIME) && Got_url == -1) { int packsize; - while (((packsize = nw_Receive(Multi_receive_buffer, &from_addr)) > 0) && Got_url == -1) { - MultiProcessBigData(Multi_receive_buffer, packsize, &from_addr); + while (((packsize = nw_Receive(std::data(Multi_receive_buffer), &from_addr)) > 0) && Got_url == -1) { + MultiProcessBigData(std::data(Multi_receive_buffer), packsize, &from_addr); } } } diff --git a/Descent3/multi.cpp b/Descent3/multi.cpp index baf993806..429d34483 100644 --- a/Descent3/multi.cpp +++ b/Descent3/multi.cpp @@ -1691,7 +1691,6 @@ #include "weather.h" #include "doorway.h" #include "object_lighting.h" -#include "spew.h" #include "PHYSICS.H" #include "SmallViews.h" #include "demofile.h" @@ -1713,7 +1712,7 @@ void MultiProcessShipChecksum(MD5 *md5, int ship_index); #include -player_pos_suppress Player_pos_fix[MAX_PLAYERS]; +std::array Player_pos_fix; // Define this if you want to have secondaries be sent as reliable packets //(not recommended - talk to Jason) @@ -1724,9 +1723,9 @@ bool Multi_no_stats_saved = false; uint32_t Netgame_curr_handle = 1; -uint16_t Local_object_list[MAX_OBJECTS]; -uint16_t Server_object_list[MAX_OBJECTS]; -uint16_t Server_spew_list[MAX_SPEW_EFFECTS]; +std::array Local_object_list; +std::array Server_object_list; +std::array Server_spew_list; #ifndef RELEASE int Multi_packet_tracking[255]; @@ -1734,45 +1733,46 @@ int Multi_packet_tracking[255]; // This is for clearing lightmapped objects on the client/server int Num_client_lm_objects, Num_server_lm_objects; -uint16_t Client_lightmap_list[MAX_OBJECTS], Server_lightmap_list[MAX_OBJECTS]; + +std::array Client_lightmap_list, Server_lightmap_list; // This is for breakable glass -uint16_t Broke_glass_rooms[MAX_BROKE_GLASS], Broke_glass_faces[MAX_BROKE_GLASS]; +std::array Broke_glass_rooms, Broke_glass_faces; int Num_broke_glass = 0; // This is for getting out a menu if in multiplayer bool Multi_bail_ui_menu = false; -uint32_t Multi_generic_match_table[MAX_OBJECT_IDS]; -uint32_t Multi_weapon_match_table[MAX_WEAPONS]; -uint8_t Multi_receive_buffer[MAX_RECEIVE_SIZE]; +std::array Multi_generic_match_table; +std::array Multi_weapon_match_table; +std::array Multi_receive_buffer; -uint8_t Multi_send_buffer[MAX_NET_PLAYERS][MAX_GAME_DATA_SIZE]; -int Multi_send_size[MAX_NET_PLAYERS]; +std::array, MAX_NET_PLAYERS> Multi_send_buffer; +std::array Multi_send_size; -player_fire_packet Player_fire_packet[MAX_NET_PLAYERS]; -float Multi_last_sent_time[MAX_NET_PLAYERS][MAX_NET_PLAYERS]; +std::array Player_fire_packet; +std::array, MAX_NET_PLAYERS> Multi_last_sent_time; -uint8_t Multi_reliable_send_buffer[MAX_NET_PLAYERS][MAX_GAME_DATA_SIZE]; -int Multi_reliable_send_size[MAX_NET_PLAYERS]; -float Multi_reliable_last_send_time[MAX_NET_PLAYERS]; -uint8_t Multi_reliable_sent_position[MAX_NET_PLAYERS]; -uint8_t Multi_reliable_urgent[MAX_NET_PLAYERS]; +std::array, MAX_NET_PLAYERS> Multi_reliable_send_buffer; +std::array Multi_reliable_send_size; +std::array Multi_reliable_last_send_time; +std::array Multi_reliable_sent_position; +std::array Multi_reliable_urgent; // For keeping track of buildings that have changed -uint8_t Multi_building_states[MAX_OBJECTS]; +std::array Multi_building_states; uint16_t Multi_num_buildings_changed = 0; // For keeping track of powerup respawn points -powerup_respawn Powerup_respawn[MAX_RESPAWNS]; -powerup_timer Powerup_timer[MAX_RESPAWNS]; +std::array Powerup_respawn; +std::array Powerup_timer; // For keeping track of damage and shields -int Multi_additional_damage_type[MAX_PLAYERS]; -float Multi_additional_damage[MAX_PLAYERS]; +std::array Multi_additional_damage_type; +std::array Multi_additional_damage; int Multi_requested_damage_type = PD_NONE; float Multi_requested_damage_amount = 0; -float Multi_additional_shields[MAX_SHIELD_REQUEST_TYPES]; +std::array Multi_additional_shields; int Num_powerup_respawn = 0; int Num_powerup_timer = 0; @@ -1780,25 +1780,25 @@ int Num_powerup_timer = 0; // For level sequencing int Multi_next_level = -1; -netplayer NetPlayers[MAX_NET_PLAYERS]; +std::array NetPlayers; netgame_info Netgame; int Num_network_games_known = 0; -network_game Network_games[MAX_NETWORK_GAMES]; +std::array Network_games; int Game_is_master_tracker_game = 0; -char Tracker_id[TRACKER_ID_LEN]; +std::array Tracker_id; -vmt_descent3_struct MTPilotinfo[MAX_NET_PLAYERS]; +std::array MTPilotinfo; -int16_t Multi_kills[MAX_NET_PLAYERS]; -int16_t Multi_deaths[MAX_NET_PLAYERS]; +std::array Multi_kills; +std::array Multi_deaths; int Got_new_game_time = 0; #define MAX_COOP_TURRETS 400 -float turret_holder[MAX_COOP_TURRETS]; +std::array turret_holder; #define DATA_CHUNK_SIZE 450 @@ -2152,21 +2152,17 @@ void MultiAnnounceEffect(object *obj, float size, float time) { // the data to process_big_data void MultiProcessIncoming() { int size, i; - uint8_t *data; network_address from_addr; - data = &(Multi_receive_buffer[0]); - // get the other net players data - while ((size = nw_Receive(data, &from_addr)) > 0) { - MultiProcessBigData(data, size, &from_addr); + while ((size = nw_Receive(std::data(Multi_receive_buffer), &from_addr)) > 0) { + MultiProcessBigData(std::data(Multi_receive_buffer), size, &from_addr); if (ServerTimeout) { LastPacketReceived = timer_GetTime(); } } // end while // read reliable sockets for data - data = &(Multi_receive_buffer[0]); if (Netgame.local_role == LR_SERVER) { for (i = 0; i < MAX_NET_PLAYERS; i++) { if (Player_num == i) @@ -2175,16 +2171,18 @@ void MultiProcessIncoming() { if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].reliable_socket != INVALID_SOCKET) && (NetPlayers[i].reliable_socket != 0)) { - while ((size = nw_ReceiveReliable(NetPlayers[i].reliable_socket, data, MAX_RECEIVE_SIZE)) > 0) { - MultiProcessBigData(data, size, &NetPlayers[i].addr); + while (size = nw_ReceiveReliable(NetPlayers[i].reliable_socket, std::data(Multi_receive_buffer), std::size(Multi_receive_buffer)), + size > 0) { + MultiProcessBigData(std::data(Multi_receive_buffer), size, &NetPlayers[i].addr); } } } } else { // if I'm not the master of the game, read reliable data from my connection with the server if ((NetPlayers[Player_num].reliable_socket != INVALID_SOCKET) && (NetPlayers[Player_num].reliable_socket != 0)) { - while ((size = nw_ReceiveReliable(NetPlayers[Player_num].reliable_socket, data, MAX_RECEIVE_SIZE)) > 0) { - MultiProcessBigData(data, size, &Netgame.server_address); + while (size = nw_ReceiveReliable(NetPlayers[Player_num].reliable_socket, std::data(Multi_receive_buffer), std::size(Multi_receive_buffer)), + size > 0) { + MultiProcessBigData(std::data(Multi_receive_buffer), size, &Netgame.server_address); } } } @@ -6437,13 +6435,12 @@ bool MultiStartNewLevel(int level) { #endif - memset(Player_pos_fix, 0, sizeof(Player_pos_fix)); - - memset(Multi_building_states, 0, MAX_OBJECTS); + Player_pos_fix.fill({0, 0.0f, 0, false}); + Multi_building_states.fill(0); Multi_num_buildings_changed = 0; - memset(Multi_additional_damage, 0, MAX_PLAYERS * 4); - memset(Multi_additional_shields, 0, MAX_SHIELD_REQUEST_TYPES * 4); + Multi_additional_damage.fill(0.0f); + Multi_additional_shields.fill(0.0f); Multi_requested_damage_amount = 0; for (i = 0; i < MAX_OBJECTS; i++) { @@ -6523,7 +6520,7 @@ void MultiSendFullPacket(int slot, int flags) { return; MULTI_ASSERT_NOMESSAGE(NetPlayers[slot].flags & NPF_CONNECTED); - nw_Send(&NetPlayers[slot].addr, Multi_send_buffer[slot], Multi_send_size[slot], flags); + nw_Send(&NetPlayers[slot].addr, std::data(Multi_send_buffer[slot]), Multi_send_size[slot], flags); Multi_send_size[slot] = 0; } @@ -6537,7 +6534,7 @@ void MultiSendFullReliablePacket(int slot, int flags) { // We're sending to the server if (slot == SERVER_PLAYER) { // mprintf(0,"Sending full packet of size %d to slot%d!\n",Multi_cur_send_size,slot); - nw_SendReliable(NetPlayers[Player_num].reliable_socket, Multi_reliable_send_buffer[Player_num], + nw_SendReliable(NetPlayers[Player_num].reliable_socket, std::data(Multi_reliable_send_buffer[Player_num]), Multi_reliable_send_size[Player_num], false); Multi_reliable_send_size[Player_num] = 0; Multi_reliable_sent_position[Player_num] = 0; @@ -6546,7 +6543,7 @@ void MultiSendFullReliablePacket(int slot, int flags) { } else // We are the server and we're sending to "slot" { MULTI_ASSERT_NOMESSAGE(NetPlayers[slot].flags & NPF_CONNECTED); - nw_SendReliable(NetPlayers[slot].reliable_socket, Multi_reliable_send_buffer[slot], Multi_reliable_send_size[slot], + nw_SendReliable(NetPlayers[slot].reliable_socket, std::data(Multi_reliable_send_buffer[slot]), Multi_reliable_send_size[slot], true); Multi_reliable_send_size[slot] = 0; Multi_reliable_sent_position[slot] = 0; @@ -6650,8 +6647,8 @@ void MultiBuildMatchTables() { mprintf(0, "Building match tables for multiplayer.\n"); - memset(Multi_generic_match_table, 0, MAX_OBJECT_IDS * sizeof(int)); - memset(Multi_weapon_match_table, 0, MAX_WEAPONS * sizeof(int)); + Multi_generic_match_table.fill(0); + Multi_weapon_match_table.fill(0); // Build generic tables for (i = 0; i < MAX_OBJECT_IDS; i++) { diff --git a/Descent3/multi.h b/Descent3/multi.h index 0297013f6..ee2e84857 100644 --- a/Descent3/multi.h +++ b/Descent3/multi.h @@ -492,11 +492,14 @@ #ifndef MULTI_H #define MULTI_H +#include + #include "pstypes.h" #include "vecmat_external.h" #include "object_external_struct.h" #include "object_external.h" #include "player_external.h" +#include "spew.h" #if defined(__LINUX__) #include "linux_fix.h" @@ -670,9 +673,9 @@ struct player_fire_packet { extern netgame_info Netgame; -extern uint16_t Local_object_list[]; -extern uint16_t Server_object_list[]; -extern uint16_t Server_spew_list[]; +extern std::array Local_object_list; +extern std::array Server_object_list; +extern std::array Server_spew_list; #define MAX_RECEIVE_SIZE 4096 #define MAX_NETWORK_GAMES 100 @@ -708,7 +711,7 @@ static inline void MultiMatrixMakeEndianFriendly(multi_orientation *mmat) { } // For firing players -extern player_fire_packet Player_fire_packet[MAX_NET_PLAYERS]; +extern std::array Player_fire_packet; // For powerup respawning #define MAX_RESPAWNS 300 @@ -733,11 +736,11 @@ struct powerup_timer { float respawn_time; }; -extern powerup_timer Powerup_timer[]; -extern powerup_respawn Powerup_respawn[]; -extern network_game Network_games[]; -extern netplayer NetPlayers[MAX_NET_PLAYERS]; -extern uint8_t Multi_receive_buffer[MAX_RECEIVE_SIZE]; +extern std::array Powerup_timer; +extern std::array Powerup_respawn; +extern std::array Network_games; +extern std::array NetPlayers; +extern std::array Multi_receive_buffer; extern int Ok_to_join; extern int Num_powerup_respawn; extern int Num_powerup_timer; @@ -748,31 +751,31 @@ extern bool Got_heartbeat; // This is for breakable glass #define MAX_BROKE_GLASS 100 -extern uint16_t Broke_glass_rooms[], Broke_glass_faces[]; +extern std::array Broke_glass_rooms, Broke_glass_faces; extern int Num_broke_glass; // For keeping track of damage and shields -extern float Multi_additional_damage[]; +extern std::array Multi_additional_damage; extern int Multi_requested_damage_type; extern float Multi_requested_damage_amount; -extern float Multi_additional_shields[]; - -extern uint8_t Multi_send_buffer[MAX_NET_PLAYERS][MAX_GAME_DATA_SIZE]; -extern int Multi_send_size[MAX_NET_PLAYERS]; -extern float Multi_last_sent_time[MAX_NET_PLAYERS][MAX_NET_PLAYERS]; -extern int Multi_additional_damage_type[MAX_NET_PLAYERS]; - -extern uint8_t Multi_reliable_urgent[MAX_NET_PLAYERS]; -extern uint8_t Multi_reliable_send_buffer[MAX_NET_PLAYERS][MAX_GAME_DATA_SIZE]; -extern int Multi_reliable_send_size[MAX_NET_PLAYERS]; -extern float Multi_reliable_last_send_time[MAX_NET_PLAYERS]; -extern uint8_t Multi_reliable_sent_position[MAX_NET_PLAYERS]; +extern std::array Multi_additional_shields; + +extern std::array, MAX_NET_PLAYERS> Multi_send_buffer; +extern std::array Multi_send_size; +extern std::array, MAX_NET_PLAYERS> Multi_last_sent_time; +extern std::array Multi_additional_damage_type; + +extern std::array Multi_reliable_urgent; +extern std::array, MAX_NET_PLAYERS> Multi_reliable_send_buffer; +extern std::array Multi_reliable_send_size; +extern std::array Multi_reliable_last_send_time; +extern std::array Multi_reliable_sent_position; extern uint32_t Multi_visible_players[]; extern int Got_level_info; extern int Got_new_game_time; // For keeping track of buildings that have changed -extern uint8_t Multi_building_states[]; +extern std::array Multi_building_states; extern uint16_t Multi_num_buildings_changed; extern bool Multi_logo_state; @@ -784,9 +787,7 @@ extern int Num_network_games_known; extern int Game_is_master_tracker_game; #define TRACKER_ID_LEN 10 // Don't change this! -extern char Tracker_id[TRACKER_ID_LEN]; - -extern uint16_t Turrett_position_counter[MAX_OBJECTS]; +extern std::array Tracker_id; #define LOGIN_LEN 33 #define REAL_NAME_LEN 66 @@ -824,7 +825,7 @@ struct vmt_descent3_struct { #pragma pack() #endif -extern vmt_descent3_struct MTPilotinfo[MAX_NET_PLAYERS]; +extern std::array MTPilotinfo; // Display a menu based on what the server just told us about void MultiDoGuidebotMenuData(uint8_t *data); diff --git a/Descent3/multi_client.cpp b/Descent3/multi_client.cpp index 4e83b9753..db3b1b1ed 100644 --- a/Descent3/multi_client.cpp +++ b/Descent3/multi_client.cpp @@ -186,7 +186,7 @@ void MultiSendMyInfo() { if (Game_is_master_tracker_game) { MultiAddUint(MASTER_TRACKER_SIG, data, &count); - strcpy(Players[Player_num].tracker_id, Tracker_id); + strcpy(Players[Player_num].tracker_id, std::data(Tracker_id)); len = strlen(Players[Player_num].tracker_id) + 1; MultiAddByte(len, data, &count); memcpy(&data[count], Players[Player_num].tracker_id, len); diff --git a/Descent3/multi_connect.cpp b/Descent3/multi_connect.cpp index da11a1b72..2ad81e944 100644 --- a/Descent3/multi_connect.cpp +++ b/Descent3/multi_connect.cpp @@ -313,8 +313,8 @@ int AskToJoin(network_address *addr) { start_time = timer_GetTime(); while ((timer_GetTime() - start_time < ASK_POLL_TIME) && Ok_to_join == -1) { int packsize; - while (((packsize = nw_Receive(Multi_receive_buffer, &from_addr)) > 0) && Ok_to_join == -1) { - MultiProcessBigData(Multi_receive_buffer, packsize, &from_addr); + while (((packsize = nw_Receive(std::data(Multi_receive_buffer), &from_addr)) > 0) && Ok_to_join == -1) { + MultiProcessBigData(std::data(Multi_receive_buffer), packsize, &from_addr); } } } @@ -598,7 +598,7 @@ void MultiSendConnectionAccepted(int slotnum, SOCKET sock, network_address *addr int MultiPollForLevelInfo() { float start_time, ask_time, initial_start_time; int connected = 0; - uint8_t data[MAX_RECEIVE_SIZE]; + std::array data; network_address from_addr; ShowProgressScreen(TXT_MLTWAITSERVER); @@ -622,11 +622,11 @@ int MultiPollForLevelInfo() { } int size; - while ((size = nw_ReceiveReliable(NetPlayers[Player_num].reliable_socket, data, MAX_RECEIVE_SIZE)) > 0) { - MultiProcessBigData(data, size, &Netgame.server_address); + while ((size = nw_ReceiveReliable(NetPlayers[Player_num].reliable_socket, std::data(data), MAX_RECEIVE_SIZE)) > 0) { + MultiProcessBigData(std::data(data), size, &Netgame.server_address); } - while ((size = nw_Receive(data, &from_addr)) > 0) { + while ((size = nw_Receive(std::data(data), &from_addr)) > 0) { if (data[0] == MP_HEARTBEAT) { mprintf(0, "Got a heart beat from the server.\n"); Got_heartbeat = true; @@ -924,8 +924,8 @@ int SearchForLocalGamesTCP(uint32_t ask, uint16_t port) { } int packsize; - while (((packsize = nw_Receive(Multi_receive_buffer, &from_addr)) > 0)) { - MultiProcessBigData(Multi_receive_buffer, packsize, &from_addr); + while (((packsize = nw_Receive(std::data(Multi_receive_buffer), &from_addr)) > 0)) { + MultiProcessBigData(std::data(Multi_receive_buffer), packsize, &from_addr); } return Num_network_games_known; } @@ -953,8 +953,8 @@ int SearchForGamesPXO(uint32_t ask, uint16_t port) { } int packsize; - while (((packsize = nw_Receive(Multi_receive_buffer, &from_addr)) > 0)) { - MultiProcessBigData(Multi_receive_buffer, packsize, &from_addr); + while (((packsize = nw_Receive(std::data(Multi_receive_buffer), &from_addr)) > 0)) { + MultiProcessBigData(std::data(Multi_receive_buffer), packsize, &from_addr); } return Num_network_games_known; } diff --git a/Descent3/multi_dll_mgr.cpp b/Descent3/multi_dll_mgr.cpp index c820dfaa4..b85fbccd7 100644 --- a/Descent3/multi_dll_mgr.cpp +++ b/Descent3/multi_dll_mgr.cpp @@ -390,10 +390,10 @@ void GetMultiAPI(multi_api *api) { api->objs = (int *)Objects; api->rooms = (int *)std::data(Rooms); api->terrain = (int *)Terrain_seg; - api->players = (int *)Players; + api->players = (int *)std::data(Players); api->netgame = (int *)&Netgame; api->netplayers = (int *)&NetPlayers; - api->ships = (int *)Ships.data(); + api->ships = (int *)std::data(Ships); // Fill in function pointers here. The order here must match the order on the // DLL side @@ -522,13 +522,13 @@ void GetMultiAPI(multi_api *api) { // Variable pointers api->vp[0] = (int *)&Player_num; - api->vp[1] = (int *)Tracker_id; + api->vp[1] = (int *)std::data(Tracker_id); api->vp[2] = (int *)&Game_is_master_tracker_game; api->vp[3] = (int *)&Game_mode; api->vp[4] = (int *)NULL; // Current_pilot; no longer a struct api->vp[5] = (int *)Base_directory; api->vp[6] = (int *)&MultiDLLGameStarting; - api->vp[7] = (int *)MTPilotinfo; + api->vp[7] = (int *)std::data(MTPilotinfo); api->vp[8] = (int *)&Num_network_games_known; api->vp[9] = (int *)&Network_games; api->vp[10] = (int *)&NewUIWindow_alpha; diff --git a/Descent3/multi_server.cpp b/Descent3/multi_server.cpp index bff570d00..66f32967a 100644 --- a/Descent3/multi_server.cpp +++ b/Descent3/multi_server.cpp @@ -1857,14 +1857,12 @@ void MultiSendToAllExcept(int except, uint8_t *data, int size, int seq_threshold // Flushes all receive sockets so that there is no data coming from them void MultiFlushAllIncomingBuffers() { - uint8_t *data; network_address from_addr; int size; - data = &(Multi_receive_buffer[0]); // get all incoming data and throw it away - while ((size = nw_Receive(data, &from_addr)) > 0) + while ((size = nw_Receive(std::data(Multi_receive_buffer), &from_addr)) > 0) ; if (Netgame.local_role == LR_SERVER) { @@ -1875,7 +1873,7 @@ void MultiFlushAllIncomingBuffers() { if ((NetPlayers[i].flags & NPF_CONNECTED) && (NetPlayers[i].reliable_socket != INVALID_SOCKET) && (NetPlayers[i].reliable_socket != 0)) { - while ((size = nw_ReceiveReliable(NetPlayers[i].reliable_socket, data, MAX_RECEIVE_SIZE)) > 0) + while ((size = nw_ReceiveReliable(NetPlayers[i].reliable_socket, std::data(Multi_receive_buffer), std::size(Multi_receive_buffer))) > 0) ; } } diff --git a/Descent3/player.h b/Descent3/player.h index 0841e0486..c55bae28b 100644 --- a/Descent3/player.h +++ b/Descent3/player.h @@ -409,7 +409,7 @@ struct player_pos_suppress { #define PLAYER_POS_HACK_TIME 10 -extern player_pos_suppress Player_pos_fix[MAX_PLAYERS]; +extern std::array Player_pos_fix; struct team { char name[CALLSIGN_LEN + 1]; @@ -423,8 +423,8 @@ extern int Default_ship_permission; extern object *Player_object; extern int Num_teams, Team_game; -extern player Players[]; -extern team Teams[]; +extern std::array Players; +extern std::array Teams; extern float HudNameTan; extern int Current_waypoint; diff --git a/Descent3/room.h b/Descent3/room.h index 930665cd1..98f163450 100644 --- a/Descent3/room.h +++ b/Descent3/room.h @@ -410,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.data()) +#define ROOMNUM(r) (r - std::data(Rooms)) // See above from RF_MINE_MASK #define MINE_INDEX(x) ((Rooms[x].flags & RFM_MINE) >> 20) diff --git a/lib/PHYSICS.H b/lib/PHYSICS.H index 0aa6a8381..34eeb1c9c 100644 --- a/lib/PHYSICS.H +++ b/lib/PHYSICS.H @@ -92,7 +92,7 @@ void PhysicsDoSimLinear(const object &obj, const vector &pos, const vector &forc vector &movementVec, vector &movementPos, float simTime, int count); extern int Physics_NumLinked; -extern int PhysicsLinkList[MAX_OBJECTS]; +extern std::array PhysicsLinkList; // Simulate a physics object for this frame void do_physics_sim(object *obj); diff --git a/lib/demofile.h b/lib/demofile.h index 3991735ba..3fb3ac2d7 100644 --- a/lib/demofile.h +++ b/lib/demofile.h @@ -107,6 +107,9 @@ #define _DEMO_FILE_HEADER_ #include +#include + +#include "object_external_struct.h" extern char Demo_fname[_MAX_PATH * 2]; @@ -117,7 +120,7 @@ extern bool Demo_restart; extern bool Demo_auto_play; extern bool Demo_make_movie; extern float Demo_frame_ofs; -extern uint16_t Demo_obj_map[MAX_OBJECTS]; +extern std::array Demo_obj_map; #define DF_NONE 0 #define DF_RECORDING 1 #define DF_PLAYBACK 2 diff --git a/lib/networking.h b/lib/networking.h index 1b33bf1c3..485f3935a 100644 --- a/lib/networking.h +++ b/lib/networking.h @@ -158,6 +158,7 @@ #include "pstypes.h" #include +#include #if defined(WIN32) // Windows includes @@ -403,7 +404,7 @@ void nw_FreePacket(int id); // nw_Recieve will call the above function to read data out of the socket. It will then determine // which of the buffers we should use and pass to the routine which called us -int nw_Receive(void *data, network_address *from_addr); +int nw_Receive(uint8_t* data, network_address *from_addr); // nw_SendReliable sends the given data through the given reliable socket. int nw_SendReliable(uint32_t socketid, uint8_t *data, int length, bool urgent = false); diff --git a/model/newstyle.cpp b/model/newstyle.cpp index d91e88663..b1aa8192f 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.data(), 0); + bm_handle = GetTextureBitmap(texp - std::data(GameTextures), 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.data()) == Multicolor_texture) { + (texp - std::data(GameTextures)) == Multicolor_texture) { int r, g, b; rend_SetLighting(LS_FLAT_GOURAUD); diff --git a/model/polymodel.cpp b/model/polymodel.cpp index 6001e90f0..ba1f9ef71 100644 --- a/model/polymodel.cpp +++ b/model/polymodel.cpp @@ -2056,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.data()); + FreePolyModel(pm - std::data(Poly_models)); return 0; } diff --git a/networking/networking.cpp b/networking/networking.cpp index e3d1ef109..e46c6234f 100644 --- a/networking/networking.cpp +++ b/networking/networking.cpp @@ -284,6 +284,8 @@ * */ +#include + #ifdef WIN32 #include #include @@ -460,19 +462,18 @@ struct reliable_header { uint16_t seq; // sequence packet 0-65535 used for ACKing also uint16_t data_len; // length of data float send_time; // Time the packet was sent, if an ACK the time the packet being ACK'd was sent. - uint8_t data[NETBUFFERSIZE]; // Packet data + std::array data; // Packet data }; #define RELIABLE_PACKET_HEADER_ONLY_SIZE (sizeof(reliable_header) - NETBUFFERSIZE) #define MAX_PING_HISTORY 10 struct reliable_net_sendbuffer { - uint8_t buffer[NETBUFFERSIZE]; - + std::array buffer; }; struct reliable_net_rcvbuffer { - uint8_t buffer[NETBUFFERSIZE]; + std::array buffer; }; static SOCKET Reliable_UDP_socket = INVALID_SOCKET; @@ -490,9 +491,9 @@ static uint32_t serverconn = 0xFFFFFFFF; struct reliable_socket { - float timesent[MAXNETBUFFERS]; - int16_t send_len[MAXNETBUFFERS]; - int16_t recv_len[MAXNETBUFFERS]; + std::array timesent; + std::array send_len; + std::array recv_len; float last_packet_received; // For a given connection, this is the last packet we received float last_packet_sent; float pings[MAX_PING_HISTORY]; @@ -504,20 +505,20 @@ struct reliable_socket { uint16_t status; // Status of this connection uint16_t oursequence; // This is the next sequence number the application is expecting uint16_t theirsequence; // This is the next sequence number the peer is expecting - uint16_t rsequence[MAXNETBUFFERS]; // This is the sequence number of the given packet + std::array rsequence; // This is the sequence number of the given packet uint8_t ping_pos; network_address net_addr; // A D3 network address structure network_protocol connection_type; // IPX, IP, modem, etc. - reliable_net_rcvbuffer *rbuffers[MAXNETBUFFERS]; + std::array rbuffers; SOCKADDR addr; // SOCKADDR of our peer - reliable_net_sendbuffer *sbuffers[MAXNETBUFFERS]; // This is an array of pointers for quick sorting + std::array sbuffers; // This is an array of pointers for quick sorting uint16_t ssequence[MAXNETBUFFERS]; // This is the sequence number of the given packet uint8_t send_urgent; }; -static reliable_socket reliable_sockets[MAXRELIABLESOCKETS]; +static std::array reliable_sockets; //******************************* #ifdef __LINUX__ #include @@ -939,7 +940,7 @@ void nw_FreePacket(int id) { // nw_Recieve will call the above function to read data out of the socket. It will then determine // which of the buffers we should use and pass to the routine which called us -int nw_Receive(void *data, network_address *from_addr) { +int nw_Receive(uint8_t* data, network_address *from_addr) { // call the routine to read data out of the socket (which stuffs it into the packet buffers) if (Use_DirectPlay) { @@ -954,7 +955,7 @@ int nw_Receive(void *data, network_address *from_addr) { int buffer_size; // try and get a free buffer and return its size - if (nw_psnet_buffer_get_next((uint8_t *)data, &buffer_size, from_addr)) { + if (nw_psnet_buffer_get_next(data, &buffer_size, from_addr)) { return buffer_size; } return 0; @@ -999,7 +1000,7 @@ int nw_ReceiveReliable(SOCKET socketid, uint8_t *buffer, int max_len) { for (i = 0; i < MAXNETBUFFERS; i++) { if ((rsocket->rsequence[i] == rsocket->oursequence) && (rsocket->rbuffers[i])) { - memcpy(buffer, rsocket->rbuffers[i]->buffer, rsocket->recv_len[i]); + memcpy(buffer, std::data(rsocket->rbuffers[i]->buffer), rsocket->recv_len[i]); mem_free(rsocket->rbuffers[i]); rsocket->rbuffers[i] = NULL; rsocket->rsequence[i] = 0; @@ -1009,6 +1010,8 @@ int nw_ReceiveReliable(SOCKET socketid, uint8_t *buffer, int max_len) { rsocket->oursequence); */ rsocket->oursequence++; + + assert(rsocket->recv_len[i] <= max_len); return rsocket->recv_len[i]; } } @@ -1138,7 +1141,7 @@ int nw_SendReliable(uint32_t socketid, uint8_t *data, int length, bool urgent) { network_address send_address; memset(&send_address, 0, sizeof(network_address)); - memcpy(send_header.data, rsocket->sbuffers[pnum], rsocket->send_len[pnum]); + memcpy(std::data(send_header.data), rsocket->sbuffers[pnum], rsocket->send_len[pnum]); send_header.data_len = INTEL_SHORT(rsocket->send_len[pnum]); send_header.type = RNT_DATA; send_header.send_time = INTEL_FLOAT(timer_GetTime()); @@ -1166,7 +1169,8 @@ int nw_SendReliable(uint32_t socketid, uint8_t *data, int length, bool urgent) { // tack this data on the end of the previous packet // mprintf(0,"Appending to delayed packet...\n"); ASSERT(rsocket->sbuffers[pnum]); - memcpy(rsocket->sbuffers[pnum]->buffer + rsocket->send_len[pnum], data, length); + assert(rsocket->send_len[pnum] + length <= NETBUFFERSIZE); + memcpy(&rsocket->sbuffers[pnum]->buffer.at(rsocket->send_len[pnum]), data, length); // int msize = mem_size(rsocket->sbuffers[pnum]); rsocket->send_len[pnum] += length; return length; @@ -1182,7 +1186,7 @@ int nw_SendReliable(uint32_t socketid, uint8_t *data, int length, bool urgent) { rsocket->send_len[i] = length; rsocket->sbuffers[i] = (reliable_net_sendbuffer *)mem_malloc(sizeof(reliable_net_sendbuffer)); - memcpy(rsocket->sbuffers[i]->buffer, data, length); + memcpy(std::data(rsocket->sbuffers[i]->buffer), data, length); send_header.seq = INTEL_SHORT(rsocket->theirsequence); rsocket->ssequence[i] = rsocket->theirsequence; @@ -1507,7 +1511,7 @@ void nw_WorkReliable(uint8_t *data, int len, network_address *naddr) { else rsocket->recv_len[i] = INTEL_SHORT(rcv_buff.data_len); rsocket->rbuffers[i] = (reliable_net_rcvbuffer *)mem_malloc(sizeof(reliable_net_rcvbuffer)); - memcpy(rsocket->rbuffers[i]->buffer, rcv_buff.data, rsocket->recv_len[i]); + memcpy(std::data(rsocket->rbuffers[i]->buffer), std::data(rcv_buff.data), rsocket->recv_len[i]); rsocket->rsequence[i] = INTEL_SHORT(rcv_buff.seq); // mprintf(0,"Adding packet to receive buffer in nw_ReceiveReliable().\n"); break; @@ -2460,7 +2464,7 @@ int nw_DoReceiveCallbacks(void) { socklen_t read_len, from_len; network_address from_addr; - uint8_t packet_data[1500]; + std::array packet_data; nw_ReliableResend(); @@ -2488,7 +2492,7 @@ int nw_DoReceiveCallbacks(void) { #endif // get data off the socket and process from_len = sizeof(SOCKADDR_IN); - read_len = recvfrom(TCP_socket, (char *)packet_data, 1500, 0, (SOCKADDR *)&ip_addr, &from_len); + read_len = recvfrom(TCP_socket, reinterpret_cast(std::data(packet_data)), std::size(packet_data), 0, (SOCKADDR *)&ip_addr, &from_len); if (read_len == SOCKET_ERROR) { int x = WSAGetLastError(); @@ -2518,7 +2522,7 @@ int nw_DoReceiveCallbacks(void) { NetStatistics.tcp_total_bytes_rec += rlen; } - Netcallbacks[packet_id](packet_data + 1, rlen, &from_addr); + Netcallbacks[packet_id](std::data(packet_data) + 1, rlen, &from_addr); } } @@ -2584,7 +2588,7 @@ void nw_ReliableResend(void) { // mprintf(0,"Resending reliable packet in nw_WorkReliable().\n"); send_header.send_time = INTEL_FLOAT(timer_GetTime()); send_header.seq = INTEL_SHORT(rsocket->ssequence[i]); - memcpy(send_header.data, rsocket->sbuffers[i]->buffer, rsocket->send_len[i]); + memcpy(std::data(send_header.data), std::data(rsocket->sbuffers[i]->buffer), rsocket->send_len[i]); send_header.data_len = INTEL_SHORT(rsocket->send_len[i]); send_header.type = RNT_DATA; diff --git a/physics/Collide.cpp b/physics/Collide.cpp index 91ebd687c..2cb47c504 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.data(), 0); + int bm_handle = GetTextureBitmap(texp - std::data(GameTextures), 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/physics/physics.cpp b/physics/physics.cpp index 15fb84ee7..c1aefe57e 100644 --- a/physics/physics.cpp +++ b/physics/physics.cpp @@ -83,7 +83,7 @@ int Physics_player_verbose = 0; int Physics_cheat_flag = 0; extern char BounceCheat; -int PhysicsLinkList[MAX_OBJECTS]; +std::array PhysicsLinkList; int Physics_NumLinked = 0; // Current strength of gravity