Skip to content

Commit

Permalink
More of the same
Browse files Browse the repository at this point in the history
  • Loading branch information
GravisZro committed Jun 1, 2024
1 parent 910710e commit a46f0f0
Show file tree
Hide file tree
Showing 27 changed files with 157 additions and 156 deletions.
2 changes: 1 addition & 1 deletion Descent3/AIMain.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
#define AI_SOUND_SHORT_DIST 60.0f

extern int AI_NumRendered;
extern int AI_RenderedList[MAX_OBJECTS];
extern std::array<int, MAX_OBJECTS> AI_RenderedList;

extern int AI_NumHostileAlert; // A rough number of alert/hostile robots
// that have seen the player recently
Expand Down
2 changes: 1 addition & 1 deletion Descent3/AImain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, MAX_OBJECTS> AI_RenderedList;

int AI_NumHostileAlert = 0;

Expand Down
6 changes: 3 additions & 3 deletions Descent3/Game2DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions Descent3/LoadLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t, MAX_OBJECTS> already_listed;
already_listed.fill(0);

for (i = 0; i <= Highest_room_index; i++) {
room *rp = &Rooms[i];
Expand Down Expand Up @@ -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<uint8_t, MAX_OBJECTS> already_loaded;
already_loaded.fill(0);

// Get the number of handles in the file
n = cf_ReadInt(ifile);
Expand Down
4 changes: 2 additions & 2 deletions Descent3/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1135,15 +1135,15 @@

#include <algorithm>

player Players[MAX_PLAYERS];
std::array<player, MAX_PLAYERS> Players;
int Player_num;

int Num_teams = 0;
int Team_game = 0;
int Default_ship_permission = 0x01;
float HudNameTan = -1;

team Teams[MAX_TEAMS];
std::array<team, MAX_TEAMS> Teams;

static int Highest_player_start = 0;

Expand Down
9 changes: 3 additions & 6 deletions Descent3/demofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t, MAX_OBJECTS> Demo_obj_map;
static std::array<bool, MAX_OBJECTS> Demo_turretchanged;
bool Demo_looping = false;
bool Demo_paused = false;
bool Demo_do_one_frame = false;
Expand All @@ -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<float, MAX_COOP_TURRETS> turret_holder;

extern gs_tables *gs_Xlates;

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Descent3/fireball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Descent3/gamecinematics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t, MAX_OBJECTS> Demo_obj_map;

struct {
// some important, pre-computed times
Expand Down
2 changes: 1 addition & 1 deletion Descent3/gamesave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ void SGSVisEffects(CFILE *fp) {
}

extern int Physics_NumLinked;
extern int PhysicsLinkList[MAX_OBJECTS];
extern std::array<int, MAX_OBJECTS> PhysicsLinkList;
extern char MarkerMessages[MAX_PLAYERS * 2][MAX_MARKER_MESSAGE_LENGTH];
extern int Marker_message;
void InsureSaveGame(CFILE *fp) { cf_WriteInt(fp, 0xF00D4B0B); }
Expand Down
2 changes: 1 addition & 1 deletion Descent3/loadstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ int LGSPlayers(CFILE *fp) {
}

extern int Physics_NumLinked;
extern int PhysicsLinkList[MAX_OBJECTS];
extern std::array<int, MAX_OBJECTS> PhysicsLinkList;

int inreadobj = 0;

Expand Down
4 changes: 2 additions & 2 deletions Descent3/mission_download.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
101 changes: 49 additions & 52 deletions Descent3/multi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -1713,7 +1712,7 @@ void MultiProcessShipChecksum(MD5 *md5, int ship_index);

#include <algorithm>

player_pos_suppress Player_pos_fix[MAX_PLAYERS];
std::array<player_pos_suppress, MAX_PLAYERS> Player_pos_fix;

// Define this if you want to have secondaries be sent as reliable packets
//(not recommended - talk to Jason)
Expand All @@ -1724,81 +1723,82 @@ 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<uint16_t, MAX_OBJECTS> Local_object_list;
std::array<uint16_t, MAX_OBJECTS> Server_object_list;
std::array<uint16_t, MAX_SPEW_EFFECTS> Server_spew_list;

#ifndef RELEASE
int Multi_packet_tracking[255];
#endif

// 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<uint16_t, MAX_OBJECTS> 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<uint16_t, MAX_BROKE_GLASS> 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<uint32_t, MAX_OBJECT_IDS> Multi_generic_match_table;
std::array<uint32_t, MAX_WEAPONS> Multi_weapon_match_table;
std::array<uint8_t, MAX_RECEIVE_SIZE> Multi_receive_buffer;

uint8_t Multi_send_buffer[MAX_NET_PLAYERS][MAX_GAME_DATA_SIZE];
int Multi_send_size[MAX_NET_PLAYERS];
std::array<std::array<uint8_t, MAX_GAME_DATA_SIZE>, MAX_NET_PLAYERS> Multi_send_buffer;
std::array<int, MAX_NET_PLAYERS> 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, MAX_NET_PLAYERS> Player_fire_packet;
std::array<std::array<float, MAX_NET_PLAYERS>, 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<std::array<uint8_t, MAX_GAME_DATA_SIZE>, MAX_NET_PLAYERS> Multi_reliable_send_buffer;
std::array<int, MAX_NET_PLAYERS> Multi_reliable_send_size;
std::array<float, MAX_NET_PLAYERS> Multi_reliable_last_send_time;
std::array<uint8_t, MAX_NET_PLAYERS> Multi_reliable_sent_position;
std::array<uint8_t, MAX_NET_PLAYERS> Multi_reliable_urgent;

// For keeping track of buildings that have changed
uint8_t Multi_building_states[MAX_OBJECTS];
std::array<uint8_t, MAX_OBJECTS> 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, MAX_RESPAWNS> Powerup_respawn;
std::array<powerup_timer, MAX_RESPAWNS> Powerup_timer;

// For keeping track of damage and shields
int Multi_additional_damage_type[MAX_PLAYERS];
float Multi_additional_damage[MAX_PLAYERS];
std::array<int, MAX_PLAYERS> Multi_additional_damage_type;
std::array<float, MAX_PLAYERS> 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<float, MAX_SHIELD_REQUEST_TYPES> Multi_additional_shields;

int Num_powerup_respawn = 0;
int Num_powerup_timer = 0;

// For level sequencing
int Multi_next_level = -1;

netplayer NetPlayers[MAX_NET_PLAYERS];
std::array<netplayer, MAX_NET_PLAYERS> NetPlayers;
netgame_info Netgame;

int Num_network_games_known = 0;
network_game Network_games[MAX_NETWORK_GAMES];
std::array<network_game, MAX_NETWORK_GAMES> Network_games;

int Game_is_master_tracker_game = 0;

char Tracker_id[TRACKER_ID_LEN];
std::array<char, TRACKER_ID_LEN> Tracker_id;

vmt_descent3_struct MTPilotinfo[MAX_NET_PLAYERS];
std::array<vmt_descent3_struct, MAX_NET_PLAYERS> MTPilotinfo;

int16_t Multi_kills[MAX_NET_PLAYERS];
int16_t Multi_deaths[MAX_NET_PLAYERS];
std::array<int16_t, MAX_NET_PLAYERS> Multi_kills;
std::array<int16_t, MAX_NET_PLAYERS> Multi_deaths;

int Got_new_game_time = 0;

#define MAX_COOP_TURRETS 400
float turret_holder[MAX_COOP_TURRETS];
std::array<float, MAX_COOP_TURRETS> turret_holder;

#define DATA_CHUNK_SIZE 450

Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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++) {
Expand Down
Loading

0 comments on commit a46f0f0

Please sign in to comment.