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

Convert min/max macros to std::min/max #23

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ IF (WIN32)

SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /SAFESEH:NO /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBC")
SET(CMAKE_MODULE_LINKER_FLAGS "/SAFESEH:NO /SUBSYSTEM:WINDOWS /NODEFAULTLIB:LIBC")
ADD_DEFINITIONS (-DIS_WINDOWS -D_CRT_SECURE_NO_WARNINGS -DMONO -DWIN32 -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE)
ADD_DEFINITIONS (-DIS_WINDOWS -D_CRT_SECURE_NO_WARNINGS -DMONO -DWIN32 -D_CRT_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -DNOMINMAX)

SET(PLATFORM_INCLUDES "lib/win/directx" "lib/win")

Expand Down
6 changes: 4 additions & 2 deletions Descent3/Game2DLL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#include "ObjScript.h"
#include "args.h"

#include <algorithm>

void SelectNextCameraView(int window);
#define NUM_CAMERA_VIEWS 3
extern int Camera_view_mode[NUM_CAMERA_VIEWS];
Expand Down Expand Up @@ -820,14 +822,14 @@ bool GetDLLNumTeamInfo(char *name, int *mint, int *maxt) {
*maxt = 1;
return false;
}
*maxt = (dllo.max_teams == 0 || dllo.max_teams == 1 || dllo.max_teams < 0) ? 1 : min(dllo.max_teams, 4);
*maxt = (dllo.max_teams == 0 || dllo.max_teams == 1 || dllo.max_teams < 0) ? 1 : std::min(dllo.max_teams, 4);
if ((*maxt) == 1) {
*mint = 1;
} else {
*mint = 2;
}
if (dllo.flags & DOF_MINTEAMS && dllo.min_teams >= 0) {
*mint = (dllo.min_teams == 0 || dllo.min_teams == 1) ? 1 : min(*maxt, dllo.min_teams);
*mint = (dllo.min_teams == 0 || dllo.min_teams == 1) ? 1 : std::min(*maxt, dllo.min_teams);
}
return ((*maxt) == 1) ? false : true;
}
3 changes: 2 additions & 1 deletion Descent3/LoadLevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1226,6 +1226,7 @@
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <algorithm>

#include "LoadLevel.h"

Expand Down Expand Up @@ -3894,7 +3895,7 @@ int LoadLevel(char *filename, void (*cb_fn)(const char *, int, int)) {
ubyte buf[1000];
int n = chunk_size, r;
while (n) {
r = cf_ReadBytes(buf, min(n, sizeof(buf)), ifile);
r = cf_ReadBytes(buf, std::min(n, sizeof(buf)), ifile);
cf_WriteBytes(buf, r, ofile);
n -= r;
}
Expand Down
4 changes: 3 additions & 1 deletion Descent3/PilotPicsAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
#include "PilotPicsAPI.h"
#include "mem.h"

#include <algorithm>

#define PILOTPIC_DATABASE_HOG "PPics.Hog"
#define PILOTPIC_DATABASE_INDEX "PPics.idx"

Expand Down Expand Up @@ -386,7 +388,7 @@ bool PPic_GetPilot(ushort pilot_id, char *pilot_name, int buffersize) {
cfseek(PilotPic_database_index_handle, oldoffset, SEEK_SET);
return false;
}
int toread = min(name_size, buffersize - 1);
int toread = std::min<int>(name_size, buffersize - 1);
cf_ReadBytes((ubyte *)pilot_name, toread, PilotPic_database_index_handle);
pilot_name[toread] = '\0';

Expand Down
16 changes: 9 additions & 7 deletions Descent3/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,8 @@
#include "Macros.h"
#endif

#include <algorithm>

player Players[MAX_PLAYERS];
int Player_num;
extern bool IsCheater;
Expand Down Expand Up @@ -1449,7 +1451,7 @@ void InitPlayerNewLevel(int slot) {
ship *ship = &Ships[player->ship_index];
for (int i = 0; i < MAX_PLAYER_WEAPONS; i++) {
if ((i >= SECONDARY_INDEX) || ship->static_wb[i].ammo_usage)
player->weapon_ammo[i] = min(ship->max_ammo[i], player->weapon_ammo[i]);
player->weapon_ammo[i] = std::min<float>(ship->max_ammo[i], player->weapon_ammo[i]);
}

#ifdef E3_DEMO
Expand Down Expand Up @@ -2933,7 +2935,7 @@ void PlayerSpewInventory(object *obj, bool spew_energy_and_shield, bool spew_non
id = Ships[playp->ship_index].spew_powerup[playp->weapon[PW_SECONDARY].index];
if (id != -1) {
ASSERT(Object_info[id].type == OBJ_POWERUP);
int count = __min(playp->weapon_ammo[playp->weapon[PW_SECONDARY].index], MAX_SECONDARY_SPEW);
int count = std::min<int>(playp->weapon_ammo[playp->weapon[PW_SECONDARY].index], MAX_SECONDARY_SPEW);
for (int t = 0; t < count; t++)
PlayerSpewObject(obj, OBJ_POWERUP, id, 2, NULL);
}
Expand All @@ -2954,7 +2956,7 @@ void PlayerSpewInventory(object *obj, bool spew_energy_and_shield, bool spew_non
object *objp = &Objects[objnum];
ASSERT(objp->control_type == CT_POWERUP);
if (Game_mode & GM_MULTI)
objp->ctype.powerup_info.count = max(objp->ctype.powerup_info.count / 4, playp->weapon_ammo[w]);
objp->ctype.powerup_info.count = std::max<int>(objp->ctype.powerup_info.count / 4, playp->weapon_ammo[w]);
else
objp->ctype.powerup_info.count = playp->weapon_ammo[w];
}
Expand All @@ -2978,7 +2980,7 @@ void PlayerSpewInventory(object *obj, bool spew_energy_and_shield, bool spew_non
if (objnum != -1)
Objects[objnum].ctype.powerup_info.count = playp->weapon_ammo[w];
} else {
int count = __min(playp->weapon_ammo[w], MAX_SECONDARY_SPEW);
int count = std::min<int>(playp->weapon_ammo[w], MAX_SECONDARY_SPEW);
for (int t = 0; t < count; t++)
PlayerSpewObject(obj, OBJ_POWERUP, id, 0, NULL);
}
Expand Down Expand Up @@ -3055,7 +3057,7 @@ void PlayerSpewInventory(object *obj, bool spew_energy_and_shield, bool spew_non
for (i = 0; i < count && !done; i++) {
if (count < 2 || (ps_rand() % 2)) {
int limit = playp->counter_measures.GetPosCount();
limit = min(2, limit);
limit = std::min(2, limit);
for (int t = 0; t < limit; t++) {
playp->counter_measures.GetAuxPosTypeID(type, id);
playp->counter_measures.GetPosInfo(inven_flags, object_flags);
Expand Down Expand Up @@ -3724,8 +3726,8 @@ void DoEnergyToShields(int pnum) {
return;
}

amount = min(Frametime * CONVERTER_RATE, Players[pnum].energy - INITIAL_ENERGY);
amount = min(amount, (MAX_SHIELDS - Objects[Players[pnum].objnum].shields) * CONVERTER_SCALE);
amount = std::min(Frametime * CONVERTER_RATE, Players[pnum].energy - INITIAL_ENERGY);
amount = std::min(amount, (MAX_SHIELDS - Objects[Players[pnum].objnum].shields) * CONVERTER_SCALE);

Players[pnum].energy -= amount;

Expand Down
10 changes: 4 additions & 6 deletions Descent3/TelComCargo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
#include "weapon.h"
#include "hlsoundlib.h"

#include <algorithm>

#define TCBACK_BUTTON_X 500
#define TCBACK_BUTTON_Y 350
#define TCFORW_BUTTON_X 532
Expand All @@ -99,10 +101,6 @@
#define LID_COUNTERMEASURES 4
#define LID_INVENTORY 5

#ifdef __LINUX__
#define max(a, b) ((a > b) ? a : b)
#endif

typedef struct {
ubyte type;
char *name;
Expand Down Expand Up @@ -142,7 +140,7 @@ int TCCargoCreateLine(int id, int y, char *title, int type) {
grtext_SetFont(SM_FONT);

float shields = Player_object->shields;
shields = max(shields, 0);
shields = std::max<float>(shields, 0);
int perc = (int)((shields / INITIAL_SHIELDS) * 100.0f);
grtext_Printf(TITLE_X, y, title);
grtext_Printf(VALUE_X, y, "%d%c", perc, '%');
Expand All @@ -154,7 +152,7 @@ int TCCargoCreateLine(int id, int y, char *title, int type) {
grtext_SetFont(SM_FONT);

float energy = Players[Player_num].energy;
energy = max(energy, 0);
energy = std::max<float>(energy, 0);
int perc = (int)((energy / INITIAL_ENERGY) * 100.0f);
grtext_Printf(TITLE_X, y, title);
grtext_Printf(VALUE_X, y, "%d%c", perc, '%');
Expand Down
14 changes: 8 additions & 6 deletions Descent3/TelComGoals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@
#include "Macros.h"
#include "hlsoundlib.h"

#include <algorithm>

#define TITLE_X 30 + TGminx
#define VALUE_X 400 + TGminx
int TGminx, TGmaxx, TGminy, TGmaxy;
Expand Down Expand Up @@ -287,13 +289,13 @@ void TCGoalsRenderCallback(void) {
float alpha_amount;
while (alpha_change > 0) {
if (active_alpha_in) {
alpha_amount = min(ACTIVE_ALPHA_MAX - active_alpha, alpha_change);
alpha_amount = std::min(ACTIVE_ALPHA_MAX - active_alpha, alpha_change);
active_alpha += alpha_amount;

if (active_alpha > (ACTIVE_ALPHA_MAX - 1.0f))
active_alpha_in = false;
} else {
alpha_amount = min(alpha_change, active_alpha - ACTIVE_ALPHA_MIN);
alpha_amount = std::min(alpha_change, active_alpha - ACTIVE_ALPHA_MIN);
active_alpha -= alpha_amount;

if (active_alpha < (ACTIVE_ALPHA_MIN + 1.0f))
Expand Down Expand Up @@ -570,18 +572,18 @@ void TCGoalsRenderCallback(void) {
// adjust box
if (TG_TT_curr.w > TG_TT_dest.w) {
// shrinking
TG_TT_curr.w -= min(TG_TT_curr.w - TG_TT_dest.w, (int)(TOOLTIP_SPEED * last_frametime));
TG_TT_curr.w -= std::min(TG_TT_curr.w - TG_TT_dest.w, (int)(TOOLTIP_SPEED * last_frametime));
} else {
// enlarging
TG_TT_curr.w += min(TG_TT_dest.w - TG_TT_curr.w, (int)(TOOLTIP_SPEED * last_frametime));
TG_TT_curr.w += std::min(TG_TT_dest.w - TG_TT_curr.w, (int)(TOOLTIP_SPEED * last_frametime));
}

if (TG_TT_curr.h > TG_TT_dest.h) {
// shrinking
TG_TT_curr.h -= min(TG_TT_curr.h - TG_TT_dest.h, (int)(TOOLTIP_SPEED * last_frametime));
TG_TT_curr.h -= std::min(TG_TT_curr.h - TG_TT_dest.h, (int)(TOOLTIP_SPEED * last_frametime));
} else {
// enlarging
TG_TT_curr.h += min(TG_TT_dest.h - TG_TT_curr.h, (int)(TOOLTIP_SPEED * last_frametime));
TG_TT_curr.h += std::min(TG_TT_dest.h - TG_TT_curr.h, (int)(TOOLTIP_SPEED * last_frametime));
}

// rend_SetAlphaType (AT_CONSTANT_TEXTURE);
Expand Down
6 changes: 4 additions & 2 deletions Descent3/WeaponFire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,8 @@
#include "BOA.h"
#include "vibeinterface.h"

#include <algorithm>

bool AreObjectsAttached(const object *obj1, const object *obj2) {
const bool f_o1_a = (obj1->flags & OF_ATTACHED) != 0;
const bool f_o2_a = (obj2->flags & OF_ATTACHED) != 0;
Expand Down Expand Up @@ -1664,7 +1666,7 @@ void WeaponDoFrame(object *obj) {
float extras = (mag * 4) + .5;
int int_extras = extras + 1;

int_extras = min(int_extras, 2);
int_extras = std::min(int_extras, 2);

delta_vec /= int_extras;
delta_time /= int_extras;
Expand Down Expand Up @@ -2340,7 +2342,7 @@ void DoSprayEffect(object *obj, otype_wb_info *static_wb, ubyte wb_index) {

int extras = fextras;

extras = min(extras, 8);
extras = std::min(extras, 8);

for (int t = 0; t < extras; t++) {

Expand Down
14 changes: 8 additions & 6 deletions Descent3/cockpit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,14 @@
#include "hlsoundlib.h"
#include "soundload.h"
#include "sounds.h"
#ifdef __LINUX__
#define min(a, b) ((a < b) ? a : b) // make Linux happy about min()
#elif defined(MACINTOSH)
#if defined(MACINTOSH)
#include "Macros.h"
#endif

#include <string.h>

#include <algorithm>

#define COCKPIT_ANIM_TIME 2.0f
#define COCKPIT_DORMANT_FRAME 0.0
#define COCKPIT_START_FRAME 3.0
Expand Down Expand Up @@ -480,9 +482,9 @@ void RenderCockpit() {
light_scalar_b *= .8f;

if (player_obj->effect_info) {
light_scalar_r = min(1.0, light_scalar_r + (player_obj->effect_info->dynamic_red));
light_scalar_g = min(1.0, light_scalar_g + (player_obj->effect_info->dynamic_green));
light_scalar_b = min(1.0, light_scalar_b + (player_obj->effect_info->dynamic_blue));
light_scalar_r = std::min(1.0f, light_scalar_r + (player_obj->effect_info->dynamic_red));
light_scalar_g = std::min(1.0f, light_scalar_g + (player_obj->effect_info->dynamic_green));
light_scalar_b = std::min(1.0f, light_scalar_b + (player_obj->effect_info->dynamic_blue));
}
if (Players[player_obj->id].flags & PLAYER_FLAGS_HEADLIGHT) {
light_scalar_r = 1.0;
Expand Down
8 changes: 5 additions & 3 deletions Descent3/damage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,8 @@
#include "psrand.h"
#include "vibeinterface.h"

#include <algorithm>

// Shake variables
static matrix Old_player_orient;
float Shake_magnitude = 0.0;
Expand All @@ -594,7 +596,7 @@ void SetNapalmDamageEffect(object *obj, object *killer, int weapon_id) {
else
obj->effect_info->damage_time += (MAX_NAPALM_DAMAGE_TIME / 1.5f);

obj->effect_info->damage_time = min(MAX_NAPALM_DAMAGE_TIME, obj->effect_info->damage_time);
obj->effect_info->damage_time = std::min(MAX_NAPALM_DAMAGE_TIME, obj->effect_info->damage_time);

if (obj->type == OBJ_PLAYER)
obj->effect_info->damage_per_second = Weapons[weapon_id].player_damage;
Expand Down Expand Up @@ -983,7 +985,7 @@ void GenerateDefaultDeath(object *obj, int *death_flags, float *delay_time) {
float extra_time = obj->rtype.pobj_info.anim_time *
(obj->rtype.pobj_info.anim_end_frame - obj->rtype.pobj_info.anim_frame) /
(obj->rtype.pobj_info.anim_end_frame - obj->rtype.pobj_info.anim_start_frame);
extra_time = min(extra_time, 3.0); // limit extra time to 3 seconds
extra_time = std::min<float>(extra_time, 3.0); // limit extra time to 3 seconds
*delay_time = Object_info[obj->id].anim[obj->ai_info->movement_type].elem[AS_DEATH].spc + 0.25 + extra_time;
// Walkers last a little longer
if (obj->movement_type == MT_WALKING)
Expand Down Expand Up @@ -1134,7 +1136,7 @@ float GetDeathAnimTime(object *objp) {
float extra_time = objp->rtype.pobj_info.anim_time *
(objp->rtype.pobj_info.anim_end_frame - objp->rtype.pobj_info.anim_frame) /
(objp->rtype.pobj_info.anim_end_frame - objp->rtype.pobj_info.anim_start_frame);
extra_time = min(extra_time, 3.0); // limit extra time to 3 seconds
extra_time = std::min<float>(extra_time, 3.0); // limit extra time to 3 seconds
mprintf((0, "extra_time = %2f\n", extra_time));

death_time = Object_info[objp->id].anim[objp->ai_info->movement_type].elem[AS_DEATH].spc + 0.25 + extra_time;
Expand Down
17 changes: 9 additions & 8 deletions Descent3/fireball.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,12 @@
#include <stdlib.h>
#include <string.h>
#include "psrand.h"
#ifdef __LINUX__
#define min(a, b) ((a < b) ? a : b)
#elif defined(MACINTOSH)
#if defined(MACINTOSH)
#include "Macros.h"
#endif

#include <algorithm>

// If an objects size is bigger than this, we create size/threshold extra explosions
#define EXTRA_EXPLOSION_THRESHOLD 15
fireball Fireballs[NUM_FIREBALLS] = {
Expand Down Expand Up @@ -748,7 +749,7 @@ void DrawFireballObject(object *obj) {
if (norm_time < .5) // Ramp up quickly
{
float temp_norm = norm_time / .2;
temp_norm = min(1.0, temp_norm);
temp_norm = std::min(1.0f, temp_norm);
size *= temp_norm;
} else // ramp down slowly
{
Expand Down Expand Up @@ -958,7 +959,7 @@ void CreateExtraFireballs(object *obj, float size_scale) {
if (obj->type == OBJ_BUILDING && OBJECT_OUTSIDE(obj))
extras += 4;
// Cap at 12
extras = min(12, extras);
extras = std::min(12, extras);
// mprintf ((0,"Creating %d extra explosions\n",extras));
CreateRandomSparks(extras, &obj->pos, obj->roomnum);
for (i = 0; i < extras; i++) {
Expand Down Expand Up @@ -1040,7 +1041,7 @@ void CreateSplintersFromBody(object *obj, float explosion_mag, float lifetime) {
num_splinters++;
}
} else {
int limit = min(sm->num_faces, MAX_SPLINTERS_PER_OBJECT);
int limit = std::min(sm->num_faces, MAX_SPLINTERS_PER_OBJECT);
for (i = 0; i < limit; i++) {
facenums[i] = ps_rand() % sm->num_faces;
num_splinters++;
Expand All @@ -1050,7 +1051,7 @@ void CreateSplintersFromBody(object *obj, float explosion_mag, float lifetime) {
for (i = 0; i < num_splinters; i++) {
int facenum = facenums[i];
vector dest, center;
int num_verts = min(sm->faces[facenum].nverts, MAX_VERTS_PER_SPLINTER);
int num_verts = std::min<float>(sm->faces[facenum].nverts, MAX_VERTS_PER_SPLINTER);

vm_MakeZero(&dest);
vm_MakeZero(&center);
Expand Down Expand Up @@ -1429,7 +1430,7 @@ void DoDyingFrame(object *objp) {
// If sparking death, do sparks
if (death_flags & DF_DELAY_SPARKS) {
float dying_norm = objp->ctype.dying_info.delay_time / ELECTRICAL_DEATH_TIME;
dying_norm = min(dying_norm, 1.0);
dying_norm = std::min<float>(dying_norm, 1.0);
// Do deform stuff
objp->effect_info->type_flags |= EF_DEFORM;
objp->effect_info->deform_time = 1.0;
Expand Down
Loading
Loading