Replace min/max macro

See #17
This commit is contained in:
Alexander Batalov 2022-05-28 14:45:48 +03:00
parent 17dc61b782
commit 14ce3994ce
15 changed files with 67 additions and 42 deletions

View File

@ -22,6 +22,8 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
// 0x41ADE0
const int _defam[AUTOMAP_MAP_COUNT][ELEVATION_COUNT] = {
{ -1, -1, -1 },
@ -1070,7 +1072,7 @@ int _copy_file_data(File* stream1, File* stream2, int length)
// NOTE: Original code is slightly different, but does the same thing.
while (length != 0) {
int chunkLength = min(length, 0xFFFF);
int chunkLength = std::min(length, 0xFFFF);
if (fileRead(buffer, chunkLength, 1, stream1) != 1) {
break;

View File

@ -2,6 +2,7 @@
#define AUTORUN_H
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
extern HANDLE gInterplayGenericAutorunMutex;

View File

@ -5,6 +5,8 @@
#include <string.h>
#include <math.h>
#include <algorithm>
// 0x50F930
char _aColor_cNoError[] = "color.c: No errors\n";
@ -552,7 +554,7 @@ void colorSetBrightness(double value)
for (int i = 0; i < 64; i++) {
double value = pow(i, gBrightness);
_currentGammaTable[i] = (unsigned char)min(max(value, 0.0), 63.0);
_currentGammaTable[i] = (unsigned char)std::clamp(value, 0.0, 63.0);
}
_setSystemPalette(_systemCmap);

View File

@ -16,6 +16,8 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
// 0x5108C8
const int gDialogBoxBackgroundFrmIds[DIALOG_TYPE_COUNT] = {
218, // MEDIALOG.FRM - Medium generic dialog box
@ -107,7 +109,7 @@ int showDialogBox(const char* title, const char** body, int bodyLength, int x, i
int linesCount = 0;
for (int index = 0; index < bodyLength; index++) {
// NOTE: Calls [fontGetStringWidth] twice because of [max] macro.
maximumLineWidth = max(fontGetStringWidth(body[index]), maximumLineWidth);
maximumLineWidth = std::max(fontGetStringWidth(body[index]), maximumLineWidth);
linesCount++;
}

View File

@ -3,6 +3,7 @@
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#else
#include <dirent.h>

View File

@ -6,6 +6,7 @@
#include "sound.h"
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
typedef enum WeaponSoundEffect {

View File

@ -38,6 +38,8 @@
#include <assert.h>
#include <stdio.h>
#include <algorithm>
#define INVENTORY_LARGE_SLOT_WIDTH 90
#define INVENTORY_LARGE_SLOT_HEIGHT 61
@ -1381,7 +1383,7 @@ void _display_body(int fid, int inventoryWindowType)
unsigned char* frameData = artGetFrameData(art, frame, rotation);
int framePitch = artGetWidth(art, frame, rotation);
int frameWidth = min(framePitch, INVENTORY_BODY_VIEW_WIDTH);
int frameWidth = std::min(framePitch, INVENTORY_BODY_VIEW_WIDTH);
int frameHeight = artGetHeight(art, frame, rotation);
if (frameHeight > INVENTORY_BODY_VIEW_HEIGHT) {
@ -3633,7 +3635,7 @@ int inventoryOpenLooting(Object* a1, Object* a2)
if (!isCaughtStealing) {
if (stealingXp > 0) {
if (!objectIsPartyMember(a2)) {
stealingXp = min(300 - skillGetValue(a1, SKILL_STEAL), stealingXp);
stealingXp = std::min(300 - skillGetValue(a1, SKILL_STEAL), stealingXp);
debugPrint("\n[[[%d]]]", 300 - skillGetValue(a1, SKILL_STEAL));
// You gain %d experience points for successfully using your Steal skill.

View File

@ -45,6 +45,8 @@
#include <stdio.h>
#include <time.h>
#include <algorithm>
#define LS_WINDOW_WIDTH 640
#define LS_WINDOW_HEIGHT 480
@ -2389,7 +2391,7 @@ int _copy_file(const char* a1, const char* a2)
}
while (length != 0) {
chunk_length = min(length, 0xFFFF);
chunk_length = std::min(length, 0xFFFF);
if (fileRead(buf, chunk_length, 1, stream1) != 1) {
break;

View File

@ -25,6 +25,8 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define PREFERENCES_WINDOW_WIDTH 640
#define PREFERENCES_WINDOW_HEIGHT 480
@ -919,32 +921,32 @@ void preferencesSetDefaults(bool a1)
// 0x4931F8
void _JustUpdate_()
{
gPreferencesGameDifficulty1 = min(max(gPreferencesGameDifficulty1, 0), 2);
gPreferencesCombatDifficulty1 = min(max(gPreferencesCombatDifficulty1, 0), 2);
gPreferencesViolenceLevel1 = min(max(gPreferencesViolenceLevel1, 0), 3);
gPreferencesTargetHighlight1 = min(max(gPreferencesTargetHighlight1, 0), 2);
gPreferencesCombatMessages1 = min(max(gPreferencesCombatMessages1, 0), 1);
gPreferencesCombatLooks1 = min(max(gPreferencesCombatLooks1, 0), 1);
gPreferencesCombatTaunts1 = min(max(gPreferencesCombatTaunts1, 0), 1);
gPreferencesLanguageFilter1 = min(max(gPreferencesLanguageFilter1, 0), 1);
gPreferencesRunning1 = min(max(gPreferencesRunning1, 0), 1);
gPreferencesSubtitles1 = min(max(gPreferencesSubtitles1, 0), 1);
gPreferencesItemHighlight1 = min(max(gPreferencesItemHighlight1, 0), 1);
gPreferencesCombatSpeed1 = min(max(gPreferencesCombatSpeed1, 0), 50);
gPreferencesPlayerSpeedup1 = min(max(gPreferencesPlayerSpeedup1, 0), 1);
gPreferencesTextBaseDelay1 = min(max(gPreferencesTextBaseDelay1, 1.0), 6.0);
gPreferencesMasterVolume1 = min(max(gPreferencesMasterVolume1, 0), VOLUME_MAX);
gPreferencesMusicVolume1 = min(max(gPreferencesMusicVolume1, 0), VOLUME_MAX);
gPreferencesSoundEffectsVolume1 = min(max(gPreferencesSoundEffectsVolume1, 0), VOLUME_MAX);
gPreferencesSpeechVolume1 = min(max(gPreferencesSpeechVolume1, 0), VOLUME_MAX);
gPreferencesBrightness1 = min(max(gPreferencesBrightness1, 1.0), 1.17999267578125);
gPreferencesMouseSensitivity1 = min(max(gPreferencesMouseSensitivity1, 1.0), 2.5);
gPreferencesGameDifficulty1 = std::clamp(gPreferencesGameDifficulty1, 0, 2);
gPreferencesCombatDifficulty1 = std::clamp(gPreferencesCombatDifficulty1, 0, 2);
gPreferencesViolenceLevel1 = std::clamp(gPreferencesViolenceLevel1, 0, 3);
gPreferencesTargetHighlight1 = std::clamp(gPreferencesTargetHighlight1, 0, 2);
gPreferencesCombatMessages1 = std::clamp(gPreferencesCombatMessages1, 0, 1);
gPreferencesCombatLooks1 = std::clamp(gPreferencesCombatLooks1, 0, 1);
gPreferencesCombatTaunts1 = std::clamp(gPreferencesCombatTaunts1, 0, 1);
gPreferencesLanguageFilter1 = std::clamp(gPreferencesLanguageFilter1, 0, 1);
gPreferencesRunning1 = std::clamp(gPreferencesRunning1, 0, 1);
gPreferencesSubtitles1 = std::clamp(gPreferencesSubtitles1, 0, 1);
gPreferencesItemHighlight1 = std::clamp(gPreferencesItemHighlight1, 0, 1);
gPreferencesCombatSpeed1 = std::clamp(gPreferencesCombatSpeed1, 0, 50);
gPreferencesPlayerSpeedup1 = std::clamp(gPreferencesPlayerSpeedup1, 0, 1);
gPreferencesTextBaseDelay1 = std::clamp(gPreferencesTextBaseDelay1, 6.0, 10.0);
gPreferencesMasterVolume1 = std::clamp(gPreferencesMasterVolume1, 0, VOLUME_MAX);
gPreferencesMusicVolume1 = std::clamp(gPreferencesMusicVolume1, 0, VOLUME_MAX);
gPreferencesSoundEffectsVolume1 = std::clamp(gPreferencesSoundEffectsVolume1, 0, VOLUME_MAX);
gPreferencesSpeechVolume1 = std::clamp(gPreferencesSpeechVolume1, 0, VOLUME_MAX);
gPreferencesBrightness1 = std::clamp(gPreferencesBrightness1, 1.0, 1.17999267578125);
gPreferencesMouseSensitivity1 = std::clamp(gPreferencesMouseSensitivity1, 1.0, 2.5);
textObjectsSetBaseDelay(gPreferencesTextBaseDelay1);
gameMouseLoadItemHighlight();
double textLineDelay = (gPreferencesTextBaseDelay1 + (-1.0)) * 0.2 * 2.0;
textLineDelay = min(max(textLineDelay, 0.0), 2.0);
textLineDelay = std::clamp(textLineDelay, 0.0, 2.0);
textObjectsSetLineDelay(textLineDelay);
aiMessageListReloadIfNeeded();
@ -1065,7 +1067,7 @@ void _UpdateThing(int index)
case PREF_COMBAT_SPEED:
if (1) {
double value = *meta->valuePtr;
value = min(max(value, 0.0), 50.0);
value = std::clamp(value, 0.0, 50.0);
int x = (int)((value - meta->minValue) * 219.0 / (meta->maxValue - meta->minValue) + 384.0);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640);
@ -1073,13 +1075,13 @@ void _UpdateThing(int index)
break;
case PREF_TEXT_BASE_DELAY:
if (1) {
gPreferencesTextBaseDelay1 = min(max(gPreferencesTextBaseDelay1, 1.0), 6.0);
gPreferencesTextBaseDelay1 = std::clamp(gPreferencesTextBaseDelay1, 1.0, 6.0);
int x = (int)((6.0 - gPreferencesTextBaseDelay1) * 43.8 + 384.0);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640);
double value = (gPreferencesTextBaseDelay1 - 1.0) * 0.2 * 2.0;
value = min(max(value, 0.0), 2.0);
value = std::clamp(value, 0.0, 2.0);
textObjectsSetBaseDelay(gPreferencesTextBaseDelay1);
textObjectsSetLineDelay(value);
@ -1091,7 +1093,7 @@ void _UpdateThing(int index)
case PREF_SPEECH_VOLUME:
if (1) {
double value = *meta->valuePtr;
value = min(max(value, meta->minValue), meta->maxValue);
value = std::clamp(value, meta->minValue, meta->maxValue);
int x = (int)((value - meta->minValue) * 219.0 / (meta->maxValue - meta->minValue) + 384.0);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640);
@ -1114,7 +1116,7 @@ void _UpdateThing(int index)
break;
case PREF_BRIGHTNESS:
if (1) {
gPreferencesBrightness1 = min(max(gPreferencesBrightness1, 1.0), 1.17999267578125);
gPreferencesBrightness1 = std::clamp(gPreferencesBrightness1, 1.0, 1.17999267578125);
int x = (int)((gPreferencesBrightness1 - meta->minValue) * (219.0 / (meta->maxValue - meta->minValue)) + 384.0);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640);
@ -1124,7 +1126,7 @@ void _UpdateThing(int index)
break;
case PREF_MOUSE_SENSITIVIY:
if (1) {
gPreferencesMouseSensitivity1 = min(max(gPreferencesMouseSensitivity1, 1.0), 2.5);
gPreferencesMouseSensitivity1 = std::clamp(gPreferencesMouseSensitivity1, 1.0, 2.5);
int x = (int)((gPreferencesMouseSensitivity1 - meta->minValue) * (219.0 / (meta->maxValue - meta->minValue)) + 384.0);
blitBufferToBufferTrans(gPreferencesWindowFrmData[PREFERENCES_WINDOW_FRM_KNOB_OFF], 21, 12, 21, gPreferencesWindowBuffer + 640 * meta->knobY + x, 640);

View File

@ -9,6 +9,8 @@
#include <mmsystem.h>
#include <stdlib.h>
#include <algorithm>
// 0x51D478
STRUCT_51D478* _fadeHead = NULL;
@ -1069,7 +1071,7 @@ int _soundVolumeHMItoDirectSound(int volume)
if (volume != 0) {
normalizedVolume = -1000.0 * log2(32767.0 / volume);
normalizedVolume = max(min(normalizedVolume, 0.0), -10000.0);
normalizedVolume = std::clamp(normalizedVolume, -10000.0, 0.0);
} else {
normalizedVolume = -10000.0;
}

View File

@ -21,6 +21,8 @@
#include <stdio.h>
#include <algorithm>
// 0x51D53C
StatDescription gStatDescriptions[STAT_COUNT] = {
{ NULL, NULL, 0, PRIMARY_STAT_MIN, PRIMARY_STAT_MAX, 5 },
@ -345,7 +347,7 @@ int critterGetStat(Object* critter, int stat)
}
}
value = min(max(value, gStatDescriptions[stat].minimumValue), gStatDescriptions[stat].maximumValue);
value = std::clamp(value, gStatDescriptions[stat].minimumValue, gStatDescriptions[stat].maximumValue);
} else {
switch (stat) {
case STAT_CURRENT_HIT_POINTS:
@ -546,10 +548,10 @@ void critterUpdateDerivedStats(Object* critter)
data->baseStats[STAT_MAXIMUM_HIT_POINTS] = critterGetBaseStatWithTraitModifier(critter, STAT_STRENGTH) + critterGetBaseStatWithTraitModifier(critter, STAT_ENDURANCE) * 2 + 15;
data->baseStats[STAT_MAXIMUM_ACTION_POINTS] = agility / 2 + 5;
data->baseStats[STAT_ARMOR_CLASS] = agility;
data->baseStats[STAT_MELEE_DAMAGE] = max(strength - 5, 1);
data->baseStats[STAT_MELEE_DAMAGE] = std::max(strength - 5, 1);
data->baseStats[STAT_CARRY_WEIGHT] = 25 * strength + 25;
data->baseStats[STAT_SEQUENCE] = 2 * perception;
data->baseStats[STAT_HEALING_RATE] = max(endurance / 3, 1);
data->baseStats[STAT_HEALING_RATE] = std::max(endurance / 3, 1);
data->baseStats[STAT_CRITICAL_CHANCE] = luck;
data->baseStats[STAT_BETTER_CRITICALS] = 0;
data->baseStats[STAT_RADIATION_RESISTANCE] = 2 * endurance;

View File

@ -2,6 +2,7 @@
#define WIN32_H
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#include <mmreg.h>

View File

@ -12,6 +12,8 @@
#include <SDL.h>
#include <algorithm>
// 0x50FA30
char _path_patches[] = "";
@ -781,10 +783,10 @@ void _GNW_win_refresh(Window* window, Rect* rect, unsigned char* a3)
v26->next = NULL;
v26->rect.left = max(window->rect.left, rect->left);
v26->rect.top = max(window->rect.top, rect->top);
v26->rect.right = min(window->rect.right, rect->right);
v26->rect.bottom = min(window->rect.bottom, rect->bottom);
v26->rect.left = std::max(window->rect.left, rect->left);
v26->rect.top = std::max(window->rect.top, rect->top);
v26->rect.right = std::min(window->rect.right, rect->right);
v26->rect.bottom = std::min(window->rect.bottom, rect->bottom);
if (v26->rect.right >= v26->rect.left && v26->rect.bottom >= v26->rect.top) {
if (a3) {

View File

@ -6,6 +6,7 @@
#include <stddef.h>
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
#include <windows.h>
#define MAX_WINDOW_COUNT (50)

View File

@ -8,6 +8,8 @@
#include <stdio.h>
#include <string.h>
#include <algorithm>
// 0x51E414
int _wd = -1;
@ -210,7 +212,7 @@ int _calc_max_field_chars_wcursor(int a1, int a2)
internal_free(str);
return max(len1, len2) + 1;
return std::max(len1, len2) + 1;
}
// 0x4DD3EC