Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Actually compile with proper optimizations in a release build. #6336

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
12 changes: 11 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

CMAKE_MINIMUM_REQUIRED(VERSION 3.4)
CMAKE_MINIMUM_REQUIRED(VERSION 3.9)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)

# Make sure the source and binary directory are not the sample
Expand Down Expand Up @@ -129,6 +129,8 @@ OPTION(FSO_BUILD_WITH_VULKAN "Enable compilation of the Vulkan renderer" OFF)

OPTION(FSO_BUILD_WITH_OPENXR_DEBUG "Enables debug option for OpenXR" OFF)

OPTION(FSO_USE_LTO "Build using LTO (only for release builds)" ON)

MARK_AS_ADVANCED(FORCE FSO_CMAKE_DEBUG)
MARK_AS_ADVANCED(FORCE FSO_BUILD_INCLUDED_LIBS)
MARK_AS_ADVANCED(FORCE FSO_USE_OPENALSOFT)
Expand Down Expand Up @@ -164,6 +166,14 @@ endif()

include(clang-tidy)

include(CheckIPOSupported)
check_ipo_supported(RESULT LTO_AVAILABLE)
if (CMAKE_BUILD_TYPE STREQUAL "Release" AND FSO_USE_LTO AND LTO_AVAILABLE)
set(CMAKE_POLICY_DEFAULT_CMP0069 NEW)
message("Enabled LTO")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif (CMAKE_BUILD_TYPE STREQUAL "Release" AND FSO_USE_LTO AND LTO_AVAILABLE)

# This includes source code for some tools, either used in the build or also for something else
ADD_SUBDIRECTORY(tools)

Expand Down
2 changes: 1 addition & 1 deletion cmake/toolchain-apple-clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-char-subscripts")

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcolor-diagnostics")

set(CMAKE_CXX_FLAGS_RELEASE "-O2 -Wno-unused-variable -Wno-unused-parameter")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wno-unused-variable -Wno-unused-parameter")

set(CMAKE_CXX_FLAGS_DEBUG "-Og -g -Wshadow")
6 changes: 3 additions & 3 deletions cmake/toolchain-clang.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,16 @@ endif()
string(REGEX MATCH "-O[a-zA-Z|0-9]+" CXX_OPT_FLAG ${CXX_BASE_FLAGS})
string(REGEX MATCH "-O[a-zA-Z|0-9]+" C_OPT_FLAG ${C_BASE_FLAGS})

# If no user-set opt flag, set -O2 and -Og
# If no user-set opt flag, set -O3 and -Og
if ("${CXX_OPT_FLAG}" STREQUAL "")
set(CXX_OPT_FLAG_RELEASE "-O2")
set(CXX_OPT_FLAG_RELEASE "-O3")
set(CXX_OPT_FLAG_DEBUG "-Og")
else()
set(CXX_OPT_FLAG_RELEASE "${CXX_OPT_FLAG}")
set(CXX_OPT_FLAG_DEBUG "${CXX_OPT_FLAG}")
endif()
if ("${C_OPT_FLAG}" STREQUAL "")
set(C_OPT_FLAG_RELEASE "-O2")
set(C_OPT_FLAG_RELEASE "-O3")
set(C_OPT_FLAG_DEBUG "-Og")
else()
set(C_OPT_FLAG_RELEASE "${C_OPT_FLAG}")
Expand Down
6 changes: 3 additions & 3 deletions cmake/toolchain-gcc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ endif()
string(REGEX MATCH "-O[a-zA-Z|0-9]+" CXX_OPT_FLAG ${CXX_BASE_FLAGS})
string(REGEX MATCH "-O[a-zA-Z|0-9]+" C_OPT_FLAG ${C_BASE_FLAGS})

# If no user-set opt flag, set -O2 and -Og
# If no user-set opt flag, set -O3 and -Og
if ("${CXX_OPT_FLAG}" STREQUAL "")
set(CXX_OPT_FLAG_RELEASE "-O2")
set(CXX_OPT_FLAG_RELEASE "-O3")
set(CXX_OPT_FLAG_DEBUG "-Og")
else()
set(CXX_OPT_FLAG_RELEASE "${CXX_OPT_FLAG}")
set(CXX_OPT_FLAG_DEBUG "${CXX_OPT_FLAG}")
endif()
if ("${C_OPT_FLAG}" STREQUAL "")
set(C_OPT_FLAG_RELEASE "-O2")
set(C_OPT_FLAG_RELEASE "-O3")
set(C_OPT_FLAG_DEBUG "-Og")
else()
set(C_OPT_FLAG_RELEASE "${C_OPT_FLAG}")
Expand Down
40 changes: 20 additions & 20 deletions code/menuui/playermenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,45 +79,45 @@ const char *Player_select_background_mask_bitmap[GR_NUM_RESOLUTIONS] = {
#define PLAYER_SELECT_MAIN_HALL_OVERLAY NOX("MainHall1") // main hall help overlay

// convenient struct for handling all button controls
struct barracks_buttons {
struct player_select_buttons {
const char *filename;
int x, y, xt, yt;
int hotspot;
UI_BUTTON button; // because we have a class inside this struct, we need the constructor below..

barracks_buttons(const char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
player_select_buttons(const char *name, int x1, int y1, int xt1, int yt1, int h) : filename(name), x(x1), y(y1), xt(xt1), yt(yt1), hotspot(h) {}
};

static barracks_buttons Player_select_buttons[GR_NUM_RESOLUTIONS][NUM_PLAYER_SELECT_BUTTONS] = {
static player_select_buttons Player_select_buttons[GR_NUM_RESOLUTIONS][NUM_PLAYER_SELECT_BUTTONS] = {
{ // GR_640
// create, clone and delete (respectively)
barracks_buttons("CPB_00", 114, 205, 117, 240, 0),
barracks_buttons("CPB_01", 172, 205, 175, 240, 1),
barracks_buttons("CPB_02", 226, 205, 229, 240, 2),
player_select_buttons("CPB_00", 114, 205, 117, 240, 0),
player_select_buttons("CPB_01", 172, 205, 175, 240, 1),
player_select_buttons("CPB_02", 226, 205, 229, 240, 2),

// scroll up, scroll down, and accept (respectively)
barracks_buttons("CPB_03", 429, 213, -1, -1, 3),
barracks_buttons("CPB_04", 456, 213, -1, -1, 4),
barracks_buttons("CPB_05", 481, 207, 484, 246, 5),
player_select_buttons("CPB_03", 429, 213, -1, -1, 3),
player_select_buttons("CPB_04", 456, 213, -1, -1, 4),
player_select_buttons("CPB_05", 481, 207, 484, 246, 5),

// single player select and multiplayer select, respectively
barracks_buttons("CPB_06", 428, 82, 430, 108, 6),
barracks_buttons("CPB_07", 477, 82, 481, 108, 7)
player_select_buttons("CPB_06", 428, 82, 430, 108, 6),
player_select_buttons("CPB_07", 477, 82, 481, 108, 7)
},
{ // GR_1024
// create, clone and delete (respectively)
barracks_buttons("2_CPB_00", 182, 328, 199, 384, 0),
barracks_buttons("2_CPB_01", 275, 328, 292, 384, 1),
barracks_buttons("2_CPB_02", 361, 328, 379, 384, 2),
player_select_buttons("2_CPB_00", 182, 328, 199, 384, 0),
player_select_buttons("2_CPB_01", 275, 328, 292, 384, 1),
player_select_buttons("2_CPB_02", 361, 328, 379, 384, 2),

// scroll up, scroll down, and accept (respectively)
barracks_buttons("2_CPB_03", 686, 341, -1, -1, 3),
barracks_buttons("2_CPB_04", 729, 341, -1, -1, 4),
barracks_buttons("2_CPB_05", 770, 332, 787, 394, 5),
player_select_buttons("2_CPB_03", 686, 341, -1, -1, 3),
player_select_buttons("2_CPB_04", 729, 341, -1, -1, 4),
player_select_buttons("2_CPB_05", 770, 332, 787, 394, 5),

// single player select and multiplayer select, respectively
barracks_buttons("2_CPB_06", 685, 132, 700, 173, 6),
barracks_buttons("2_CPB_07", 764, 132, 782, 173, 7)
player_select_buttons("2_CPB_06", 685, 132, 700, 173, 6),
player_select_buttons("2_CPB_07", 764, 132, 782, 173, 7)
}
};

Expand Down Expand Up @@ -294,7 +294,7 @@ void player_select_set_controls(int gray)
void player_select_init()
{
int i;
barracks_buttons *b;
player_select_buttons *b;
UI_WINDOW *w;

// start a looping ambient sound
Expand Down
4 changes: 2 additions & 2 deletions code/model/modelread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1700,7 +1700,7 @@ modelread_status read_model_file_no_subsys(polymodel * pm, const char* filename,
Warning(LOCATION, "Model <%s> has a radius <= 0.1f\n", filename);
}

pm->submodel = new bsp_info[pm->n_models];
pm->submodel = new bsp_info[MAX(1,pm->n_models)];

//Assert(pm->n_models <= MAX_SUBMODELS);

Expand Down Expand Up @@ -5379,7 +5379,7 @@ int model_create_bsp_collision_tree()
return (int)i;
}

bsp_collision_tree tree;
bsp_collision_tree tree{};

tree.used = true;
Bsp_collision_tree_list.push_back(tree);
Expand Down
3 changes: 2 additions & 1 deletion code/model/modelreplace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,12 @@ int reallocate_and_copy_array(T*& array, int& size, size_t to_add) {
//Make sure to keep old data
T* oldArray = array;

Assertion(size >= 0, "Tried to realloc an array of negative size %d!", size);
int size_before = size;

//Realloc new submodel array of proper size
size += static_cast<int>(to_add);
array = new T[size];
array = new T[MAX(0,size)];

//Copy over old data. Pointers in the struct can still point to old members, we will just delete the outer bsp_info array
for (int i = 0; i < size_before; i++)
Expand Down
5 changes: 2 additions & 3 deletions code/network/gtrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,8 @@ void IdleGameTracker()
//End New 7-9-98

//Check for incoming

FD_ZERO(&read_fds); // NOLINT
FD_SET(Psnet_socket, &read_fds);
FD_SET_SAFE(Psnet_socket, &read_fds);

if(SELECT(static_cast<int>(Psnet_socket+1),&read_fds,nullptr,nullptr,&timeout, PSNET_TYPE_GAME_TRACKER))
{
Expand Down Expand Up @@ -657,7 +656,7 @@ void StartTrackerGame(void *buffer)
//A new function
void RequestGameCountWithFilter(void *filter)
{
game_packet_header GameCountReq;
game_packet_header GameCountReq{};
ubyte packet_data[sizeof(game_packet_header)];
int packet_length = 0;

Expand Down
12 changes: 6 additions & 6 deletions code/network/psnet2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ int psnet_send(net_addr *who_to_addr, void *data, int len, int np_index) // NOLI
}

FD_ZERO(&wfds);
FD_SET(Psnet_socket, &wfds);
FD_SET_SAFE(Psnet_socket, &wfds);

timeout.tv_sec = 0;
timeout.tv_usec = 0;
Expand All @@ -829,7 +829,7 @@ int psnet_send(net_addr *who_to_addr, void *data, int len, int np_index) // NOLI
}

// if the write file descriptor is not set, then bail!
if ( !FD_ISSET(Psnet_socket, &wfds) ) {
if ( !FD_ISSET_SAFE(Psnet_socket, &wfds) ) {
return 0;
}

Expand Down Expand Up @@ -2005,14 +2005,14 @@ void psnet_rel_connect_to_server(PSNET_SOCKET *socket, net_addr *server_addr)
timeout.tv_usec = 0;

FD_ZERO(&read_fds);
FD_SET(Psnet_socket, &read_fds);
FD_SET_SAFE(Psnet_socket, &read_fds);

if ( SELECT(static_cast<int>(Psnet_socket+1), &read_fds, nullptr, nullptr, &timeout, PSNET_TYPE_RELIABLE) == SOCKET_ERROR ) {
break;
}

// if the file descriptor is not set, then bail!
if ( !FD_ISSET(Psnet_socket, &read_fds) ) {
if ( !FD_ISSET_SAFE(Psnet_socket, &read_fds) ) {
break;
}

Expand Down Expand Up @@ -2050,14 +2050,14 @@ void psnet_rel_connect_to_server(PSNET_SOCKET *socket, net_addr *server_addr)
timeout.tv_usec = 0;

FD_ZERO(&read_fds);
FD_SET(Psnet_socket, &read_fds);
FD_SET_SAFE(Psnet_socket, &read_fds);

if ( SELECT(static_cast<int>(Psnet_socket+1), &read_fds, nullptr, nullptr, &timeout, PSNET_TYPE_RELIABLE) == SOCKET_ERROR ) {
break;
}

// if the file descriptor is not set, then bail!
if ( !FD_ISSET(Psnet_socket, &read_fds) ) {
if ( !FD_ISSET_SAFE(Psnet_socket, &read_fds) ) {
continue;
}

Expand Down
3 changes: 3 additions & 0 deletions code/network/psnet2.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ extern unsigned int Serverconn;
#define PSNET_IP_MODE_V6 (1<<1)
#define PSNET_IP_MODE_DUAL (PSNET_IP_MODE_V4|PSNET_IP_MODE_V6)

#define FD_SET_SAFE(bit, set) FD_SET((bit < 0 || bit >= FD_SETSIZE ? 0 : bit), set)
#define FD_ISSET_SAFE(bit, set) FD_ISSET((bit < 0 || bit >= FD_SETSIZE ? 0 : bit), set)

// -------------------------------------------------------------------------------------------------------
// PSNET 2 TOP LAYER FUNCTIONS - these functions simply buffer and store packets based upon type (see PSNET_TYPE_* defines)
//
Expand Down
4 changes: 2 additions & 2 deletions code/network/ptrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ int GetFSPilotData(vmt_stats_struct *fs_pilot, const char *pilot_name, const cha
// Send an ACK to the server
void AckServer(unsigned int sig)
{
udp_packet_header ack_pack;
udp_packet_header ack_pack{};
ubyte packet_data[sizeof(udp_packet_header)];
int packet_length = 0;

Expand Down Expand Up @@ -623,7 +623,7 @@ void PollPTrackNet()
timeout.tv_usec=0;

FD_ZERO(&read_fds); // NOLINT
FD_SET(Psnet_socket, &read_fds);
FD_SET_SAFE(Psnet_socket, &read_fds);

if(SELECT(static_cast<int>(Psnet_socket+1), &read_fds,nullptr,nullptr,&timeout, PSNET_TYPE_USER_TRACKER)){
int bytesin;
Expand Down
12 changes: 6 additions & 6 deletions code/network/valid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ int ValidateUser(validate_id_request *valid_id, char *trackerid)
timeout.tv_usec=0;

FD_ZERO(&read_fds); // NOLINT
FD_SET(Psnet_socket, &read_fds);
FD_SET_SAFE(Psnet_socket, &read_fds);

while(SELECT(static_cast<int>(Psnet_socket+1),&read_fds,nullptr,nullptr,&timeout, PSNET_TYPE_VALIDATION))
{
Expand Down Expand Up @@ -357,7 +357,7 @@ void ValidIdle()
timeout.tv_usec=0;

FD_ZERO(&read_fds); // NOLINT
FD_SET(Psnet_socket, &read_fds);
FD_SET_SAFE(Psnet_socket, &read_fds);

if(SELECT(static_cast<int>(Psnet_socket+1),&read_fds,nullptr,nullptr,&timeout, PSNET_TYPE_VALIDATION)){
int bytesin;
Expand Down Expand Up @@ -385,7 +385,7 @@ void ValidIdle()
}

FD_ZERO(&read_fds); // NOLINT
FD_SET(Psnet_socket, &read_fds);
FD_SET_SAFE(Psnet_socket, &read_fds);

//Check to make sure the packets ok
if ( (bytesin > 0) && (bytesin == inpacket.len) ) {
Expand Down Expand Up @@ -614,7 +614,7 @@ int ValidateMission(vmt_validate_mission_req_struct *valid_msn)
udp_packet_header inpacket;

FD_ZERO(&read_fds); // NOLINT
FD_SET(Psnet_socket, &read_fds);
FD_SET_SAFE(Psnet_socket, &read_fds);

addrsize = sizeof(fromaddr);
RECVFROM(Psnet_socket, reinterpret_cast<char *>(&inpacket), sizeof(udp_packet_header), 0,
Expand Down Expand Up @@ -700,7 +700,7 @@ int ValidateSquadWar(squad_war_request *sw_req, squad_war_response *sw_resp)
udp_packet_header inpacket;

FD_ZERO(&read_fds); // NOLINT
FD_SET(Psnet_socket, &read_fds);
FD_SET_SAFE(Psnet_socket, &read_fds);

addrsize = sizeof(fromaddr);
RECVFROM(Psnet_socket, reinterpret_cast<char *>(&inpacket), sizeof(udp_packet_header), 0,
Expand Down Expand Up @@ -794,7 +794,7 @@ int ValidateData(const vmt_valid_data_req_struct *vreq)
udp_packet_header inpacket;

FD_ZERO(&read_fds); // NOLINT
FD_SET(Psnet_socket, &read_fds);
FD_SET_SAFE(Psnet_socket, &read_fds);

addrsize = sizeof(fromaddr);
RECVFROM(Psnet_socket, reinterpret_cast<char *>(&inpacket), sizeof(udp_packet_header), 0,
Expand Down
Loading
Loading