AGS: Replaced Math/std Min/Max with ScummVM macros

Inspired by 6dee5ee6f271c600e30879d892295ea6069e8cc9
This commit is contained in:
Paul Gilbert 2022-05-05 20:47:43 -07:00
parent 84a3925442
commit b1649597d7
33 changed files with 93 additions and 93 deletions

View File

@ -174,8 +174,8 @@ int _display_main(int xx, int yy, int wii, const char *text, int disp_type, int
if (disp_type < DISPLAYTEXT_NORMALOVERLAY)
remove_screen_overlay(_GP(play).text_overlay_on); // remove any previous blocking texts
const int bmp_width = std::max(2, wii);
const int bmp_height = std::max(2, disp.fulltxtheight + extraHeight);
const int bmp_width = MAX(2, wii);
const int bmp_height = MAX(2, disp.fulltxtheight + extraHeight);
Bitmap *text_window_ds = BitmapHelper::CreateTransparentBitmap(
bmp_width, bmp_height, _GP(game).GetColorDepth());

View File

@ -299,8 +299,8 @@ AGS_INLINE void ctx_data_to_game_coord(int &x, int &y, bool hires_ctx) {
AGS_INLINE void ctx_data_to_game_size(int &w, int &h, bool hires_ctx) {
if (hires_ctx && !_GP(game).IsLegacyHiRes()) {
w = Math::Max(1, (w / HIRES_COORD_MULTIPLIER));
h = Math::Max(1, (h / HIRES_COORD_MULTIPLIER));
w = MAX(1, (w / HIRES_COORD_MULTIPLIER));
h = MAX(1, (h / HIRES_COORD_MULTIPLIER));
} else if (!hires_ctx && _GP(game).IsLegacyHiRes()) {
w *= HIRES_COORD_MULTIPLIER;
h *= HIRES_COORD_MULTIPLIER;
@ -309,7 +309,7 @@ AGS_INLINE void ctx_data_to_game_size(int &w, int &h, bool hires_ctx) {
AGS_INLINE int ctx_data_to_game_size(int size, bool hires_ctx) {
if (hires_ctx && !_GP(game).IsLegacyHiRes())
return Math::Max(1, (size / HIRES_COORD_MULTIPLIER));
return MAX(1, (size / HIRES_COORD_MULTIPLIER));
if (!hires_ctx && _GP(game).IsLegacyHiRes())
return size * HIRES_COORD_MULTIPLIER;
return size;
@ -319,7 +319,7 @@ AGS_INLINE int game_to_ctx_data_size(int size, bool hires_ctx) {
if (hires_ctx && !_GP(game).IsLegacyHiRes())
return size * HIRES_COORD_MULTIPLIER;
else if (!hires_ctx && _GP(game).IsLegacyHiRes())
return Math::Max(1, (size / HIRES_COORD_MULTIPLIER));
return MAX(1, (size / HIRES_COORD_MULTIPLIER));
return size;
}

View File

@ -466,7 +466,7 @@ static int ags_pf_ungetc(int /*c*/, void * /*userdata*/) {
static long ags_pf_fread(void *p, long n, void *userdata) {
AGS_PACKFILE_OBJ *obj = (AGS_PACKFILE_OBJ *)userdata;
if (obj->remains > 0) {
size_t read = Math::Min(obj->remains, (size_t)n);
size_t read = MIN(obj->remains, (size_t)n);
obj->remains -= read;
return obj->stream->Read(p, read);
}

View File

@ -303,7 +303,7 @@ void InventoryScreen::Draw(Bitmap *ds) {
wputblock(ds, barxp + 1 + ((i - top_item) % 4) * widest + widest / 2 - spof->GetWidth() / 2,
bartop + 1 + ((i - top_item) / 4) * highest + highest / 2 - spof->GetHeight() / 2, spof, 1);
}
#define BUTTONWID Math::Max(1, _GP(game).SpriteInfos[btn_select_sprite].Width)
#define BUTTONWID MAX(1, _GP(game).SpriteInfos[btn_select_sprite].Width)
// Draw select, look and OK buttons
wputblock(ds, 2, buttonyp + get_fixed_pixel_size(2), _GP(spriteset)[btn_look_sprite], 1);
wputblock(ds, 3 + BUTTONWID, buttonyp + get_fixed_pixel_size(2), _GP(spriteset)[btn_select_sprite], 1);

View File

@ -356,10 +356,10 @@ Point get_overlay_position(const ScreenOverlay &over) {
Point screenpt = view->RoomToScreen(
data_to_game_coord(_GP(game).chars[charid].x),
data_to_game_coord(_GP(game).chars[charid].get_effective_y()) - height).first;
int tdxp = std::max(0, screenpt.X - over.pic->GetWidth() / 2);
int tdxp = MAX(0, screenpt.X - over.pic->GetWidth() / 2);
int tdyp = screenpt.Y - get_fixed_pixel_size(5);
tdyp -= over.pic->GetHeight();
tdyp = std::max(5, tdyp);
tdyp = MAX(5, tdyp);
if ((tdxp + over.pic->GetWidth()) >= ui_view.GetWidth())
tdxp = (ui_view.GetWidth() - over.pic->GetWidth()) - 1;

View File

@ -96,7 +96,7 @@ static int find_route_jps(int fromx, int fromy, int destx, int desty) {
_G(num_navpoints) = 0;
// new behavior: cut path if too complex rather than abort with error message
int count = std::min<int>((int)cpath.size(), MAXNAVPOINTS);
int count = MIN<int>((int)cpath.size(), MAXNAVPOINTS);
for (int i = 0; i < count; i++) {
int x, y;

View File

@ -114,7 +114,7 @@ const char *String_Substring(const char *thisString, int index, int length) {
size_t strlen = ustrlen(thisString);
if ((index < 0) || ((size_t)index > strlen))
quit("!String.Substring: invalid index");
size_t sublen = std::min((size_t)length, strlen - index);
size_t sublen = MIN((size_t)length, strlen - index);
size_t start = uoffset(thisString, index);
size_t end = uoffset(thisString + start, sublen) + start;
size_t copysz = end - start;

View File

@ -104,7 +104,7 @@ bool walkbehinds_cropout(Bitmap *sprit, int sprx, int spry, int basel, int zoom)
bool pixels_changed = false;
// pass along the sprite's pixels, but skip those that lie outside the mask
for (int x = std::max(0, 0 - sprx);
for (int x = MAX(0, 0 - sprx);
(x < sprit->GetWidth()) && (x + sprx < _GP(thisroom).WalkBehindMask->GetWidth()); ++x) {
// select the WB column at this x
const auto &wbcol = walkBehindCols[x + sprx];
@ -116,7 +116,7 @@ bool walkbehinds_cropout(Bitmap *sprit, int sprx, int spry, int basel, int zoom)
// ensure we only check within the valid areas (between Y1 and Y2)
// we assume that Y1 and Y2 are always within the mask
for (int y = std::max(0, wbcol.Y1 - spry);
for (int y = MAX(0, wbcol.Y1 - spry);
(y < sprit->GetHeight()) && (y + spry < wbcol.Y2); ++y) {
const int wb = _GP(thisroom).WalkBehindMask->GetScanLine(y + spry)[x + sprx];
if (wb < 1) continue; // "no area"
@ -167,10 +167,10 @@ void walkbehinds_recalc() {
}
wbcol.Y2 = y + 1; // +1 to allow bottom line of screen to work (CHECKME??)
// resize the bounding rect
walkBehindAABB[wb].Left = std::min(col, walkBehindAABB[wb].Left);
walkBehindAABB[wb].Top = std::min(y, walkBehindAABB[wb].Top);
walkBehindAABB[wb].Right = std::max(col, walkBehindAABB[wb].Right);
walkBehindAABB[wb].Bottom = std::max(y, walkBehindAABB[wb].Bottom);
walkBehindAABB[wb].Left = MIN(col, walkBehindAABB[wb].Left);
walkBehindAABB[wb].Top = MIN(y, walkBehindAABB[wb].Top);
walkBehindAABB[wb].Right = MAX(col, walkBehindAABB[wb].Right);
walkBehindAABB[wb].Bottom = MAX(y, walkBehindAABB[wb].Bottom);
}
}
}

View File

@ -160,7 +160,7 @@ float Mouse::GetSpeedUnit() {
}
void Mouse::SetSpeed(float speed) {
SpeedVal = Math::Max(0.f, speed);
SpeedVal = MAX(0.f, speed);
Speed = SpeedUnit * SpeedVal;
}

View File

@ -446,7 +446,7 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
RemapLegacySoundNums(_GP(game), _GP(views), _G(loaded_game_file_version));
// restore these to the ones retrieved from the save game
const size_t dynsurf_num = Math::Min((uint)MAX_DYNAMIC_SURFACES, r_data.DynamicSurfaces.size());
const size_t dynsurf_num = MIN((uint)MAX_DYNAMIC_SURFACES, r_data.DynamicSurfaces.size());
for (size_t i = 0; i < dynsurf_num; ++i) {
_G(dynamicallyCreatedSurfaces)[i] = r_data.DynamicSurfaces[i];
}
@ -463,13 +463,13 @@ HSaveError DoAfterRestore(const PreservedParams &pp, const RestoredData &r_data)
// read the global data into the newly created script
if (r_data.GlobalScript.Data.get())
memcpy(_G(gameinst)->globaldata, r_data.GlobalScript.Data.get(),
Math::Min((size_t)_G(gameinst)->globaldatasize, r_data.GlobalScript.Len));
MIN((size_t)_G(gameinst)->globaldatasize, r_data.GlobalScript.Len));
// restore the script module data
for (size_t i = 0; i < _G(numScriptModules); ++i) {
if (r_data.ScriptModules[i].Data.get())
memcpy(_GP(moduleInst)[i]->globaldata, r_data.ScriptModules[i].Data.get(),
Math::Min((size_t)_GP(moduleInst)[i]->globaldatasize, r_data.ScriptModules[i].Len));
MIN((size_t)_GP(moduleInst)[i]->globaldatasize, r_data.ScriptModules[i].Len));
}
setup_player_character(_GP(game).playercharacter);

View File

@ -199,9 +199,9 @@ void ScummVMRendererGraphicsDriver::SetGamma(int newGamma) {
uint16 gamma_blue[256];
for (int i = 0; i < 256; i++) {
gamma_red[i] = std::min(((int)_defaultGammaRed[i] * newGamma) / 100, 0xffff);
gamma_green[i] = std::min(((int)_defaultGammaGreen[i] * newGamma) / 100, 0xffff);
gamma_blue[i] = std::min(((int)_defaultGammaBlue[i] * newGamma) / 100, 0xffff);
gamma_red[i] = MIN(((int)_defaultGammaRed[i] * newGamma) / 100, 0xffff);
gamma_green[i] = MIN(((int)_defaultGammaGreen[i] * newGamma) / 100, 0xffff);
gamma_blue[i] = MIN(((int)_defaultGammaBlue[i] * newGamma) / 100, 0xffff);
}
SDL_SetWindowGammaRamp(sys_get_window(), gamma_red, gamma_green, gamma_blue);

View File

@ -228,7 +228,7 @@ void engine_post_gfxmode_mouse_setup(const Size &init_desktop) {
if (_GP(usetup).mouse_speed_def == kMouseSpeed_CurrentDisplay) {
Size cur_desktop;
if (sys_get_desktop_resolution(cur_desktop.Width, cur_desktop.Height) == 0)
_GP(mouse).SetSpeedUnit(Math::Max((float)cur_desktop.Width / (float)init_desktop.Width,
_GP(mouse).SetSpeedUnit(MAX((float)cur_desktop.Width / (float)init_desktop.Width,
(float)cur_desktop.Height / (float)init_desktop.Height));
}

View File

@ -169,8 +169,8 @@ Size get_game_frame_from_screen_size(const Size &game_size, const Size screen_si
if (scale > 0)
fp_scale = convert_scaling_to_fp(scale);
else
fp_scale = Math::Max<int32_t>(kUnit,
Math::Min((screen_size.Width / game_size.Width) << kShift,
fp_scale = MAX<int32_t>(kUnit,
MIN((screen_size.Width / game_size.Width) << kShift,
(screen_size.Height / game_size.Height) << kShift));
Size frame_size = Size(
(game_size.Width * fp_scale) >> kShift,
@ -222,8 +222,8 @@ bool try_init_compatible_mode(const DisplayMode &dm) {
// Windowed mode
if (dm.IsWindowed()) {
// If windowed mode, make the resolution stay in the generally supported limits
dm_compat.Width = Math::Min(dm_compat.Width, device_size.Width);
dm_compat.Height = Math::Min(dm_compat.Height, device_size.Height);
dm_compat.Width = MIN(dm_compat.Width, device_size.Width);
dm_compat.Height = MIN(dm_compat.Height, device_size.Height);
}
// Fullscreen mode
else {

View File

@ -258,7 +258,7 @@ void AGSPlatformDriver::Delay(int millis) {
break;
}
auto duration = std::min<std::chrono::milliseconds>(delayUntil - now,
auto duration = MIN<std::chrono::milliseconds>(delayUntil - now,
_G(MaximumDelayBetweenPolling));
std::this_thread::sleep_for(duration);
now = AGS_Clock::now(); // update now

View File

@ -335,7 +335,7 @@ int ccInstance::CallScriptFunction(const char *funcname, int32_t numargs, const
// Prepare instance for run
flags &= ~INSTF_ABORTED;
// Allow to pass less parameters if script callback has less declared args
numargs = std::min(numargs, export_args);
numargs = MIN(numargs, export_args);
// object pointer needs to start zeroed
registers[SREG_OP].SetDynamicObject(nullptr, nullptr);
registers[SREG_SP].SetStackPtr(&stack[0]);

View File

@ -223,7 +223,7 @@ const char *ScriptSprintf(char *buffer, size_t buf_length, const char *format,
arg_idx++;
if (snprintf_res >= 0) {
// snprintf returns maximal number of characters, so limit it with buffer size
out_ptr += Math::Min<ptrdiff_t>(snprintf_res, avail_outbuf);
out_ptr += MIN<ptrdiff_t>(snprintf_res, avail_outbuf);
continue;
}
// -- pass further to invalid format case
@ -231,7 +231,7 @@ const char *ScriptSprintf(char *buffer, size_t buf_length, const char *format,
// If format was not valid, or there are no available
// parameters, just copy stored format buffer as it is
size_t copy_len = Math::Min(Math::Min<ptrdiff_t>(fmt_bufptr - fmtbuf, fmtbuf_size - 1), avail_outbuf);
size_t copy_len = MIN(MIN<ptrdiff_t>(fmt_bufptr - fmtbuf, fmtbuf_size - 1), avail_outbuf);
memcpy(out_ptr, fmtbuf, copy_len);
out_ptr += copy_len;
}

View File

@ -122,7 +122,7 @@ void GameSetupStruct::read_font_infos(Shared::Stream *in, GameDataVersion data_v
for (int i = 0; i < numfonts; ++i) {
fonts[i].YOffset = in->ReadInt32();
if (data_ver >= kGameVersion_341_2)
fonts[i].LineSpacing = Math::Max<int32_t>(0, in->ReadInt32());
fonts[i].LineSpacing = MAX<int32_t>(0, in->ReadInt32());
}
} else {
for (int i = 0; i < numfonts; ++i) {
@ -130,7 +130,7 @@ void GameSetupStruct::read_font_infos(Shared::Stream *in, GameDataVersion data_v
fonts[i].Size = in->ReadInt32();
fonts[i].Outline = in->ReadInt32();
fonts[i].YOffset = in->ReadInt32();
fonts[i].LineSpacing = Math::Max<int32_t>(0, in->ReadInt32());
fonts[i].LineSpacing = MAX<int32_t>(0, in->ReadInt32());
AdjustFontInfoUsingFlags(fonts[i], flags);
}
}

View File

@ -325,7 +325,7 @@ static inline void ReadSprHeader(SpriteDatHeader &hdr, Stream *in,
HError SpriteFile::RebuildSpriteIndex(Stream *in, sprkey_t topmost,
std::vector<Size> &metrics) {
topmost = std::min(topmost, (sprkey_t)_spriteData.size() - 1);
topmost = MIN(topmost, (sprkey_t)_spriteData.size() - 1);
for (sprkey_t i = 0; !in->EOS() && (i <= topmost); ++i) {
_spriteData[i].Offset = in->GetPosition();
SpriteDatHeader hdr;

View File

@ -110,7 +110,7 @@ void decrypt_text(char *toenc, size_t buf_sz) {
void read_string_decrypt(Stream *in, char *buf, size_t buf_sz) {
size_t len = in->ReadInt32();
size_t slen = std::min(buf_sz - 1, len);
size_t slen = MIN(buf_sz - 1, len);
in->Read(buf, slen);
if (len > slen)
in->Seek(len - slen);

View File

@ -164,7 +164,7 @@ int get_text_width_outlined(const char *text, size_t font_number) {
return self_width + 2 * _GP(fonts)[font_number].Info.AutoOutlineThickness;
}
int outline_width = _GP(fonts)[outline].Renderer->GetTextWidth(text, outline);
return std::max(self_width, outline_width);
return MAX(self_width, outline_width);
}
int get_font_outline(size_t font_number) {
@ -209,7 +209,7 @@ int get_font_height_outlined(size_t fontNumber) {
return self_height + 2 * _GP(fonts)[fontNumber].Info.AutoOutlineThickness;
}
int outline_height = _GP(fonts)[outline].Metrics.CompatHeight;
return std::max(self_height, outline_height);
return MAX(self_height, outline_height);
}
int get_font_surface_height(size_t fontNumber) {
@ -449,8 +449,8 @@ void alloc_font_outline_buffers(size_t font_number,
(f.TextStencil.GetWidth() < text_width) || (f.TextStencil.GetHeight() < text_height)) {
int sw = f.TextStencil.IsNull() ? 0 : f.TextStencil.GetWidth();
int sh = f.TextStencil.IsNull() ? 0 : f.TextStencil.GetHeight();
sw = std::max(text_width, sw);
sh = std::max(text_height, sh);
sw = MAX(text_width, sw);
sh = MAX(text_height, sh);
f.TextStencil.Create(sw, sh, color_depth);
f.OutlineStencil.Create(sw, sh + thick, color_depth);
f.TextStencilSub.CreateSubBitmap(&f.TextStencil, RectWH(Size(text_width, text_height)));

View File

@ -227,7 +227,7 @@ Interaction &Interaction::operator =(const Interaction &ni) {
void Interaction::CopyTimesRun(const Interaction &inter) {
assert(Events.size() == inter.Events.size());
size_t count = Math::Min(Events.size(), inter.Events.size());
size_t count = MIN(Events.size(), inter.Events.size());
for (size_t i = 0; i < count; ++i) {
Events[i].TimesRun = inter.Events[i].TimesRun;
}

View File

@ -356,7 +356,7 @@ void ReadDialogs(DialogTopic *&dialog,
break;
}
newlen = Math::Min(newlen, sizeof(buffer) - 1);
newlen = MIN(newlen, sizeof(buffer) - 1);
in->Read(buffer, newlen);
decrypt_text(buffer, newlen);
buffer[newlen] = 0;

View File

@ -77,7 +77,7 @@ Rect GUILabel::CalcGraphicRect(bool clipped) {
++i, at_y += linespacing) {
Line lpos = GUI::CalcTextPositionHor(_GP(Lines)[i].GetCStr(), Font, 0, 0 + Width - 1, at_y,
(FrameAlignment)TextAlignment);
max_line.X2 = std::max(max_line.X2, lpos.X2);
max_line.X2 = MAX(max_line.X2, lpos.X2);
}
return SumRects(rc, RectWH(0, 0, max_line.X2 - max_line.X1 + 1, at_y - linespacing + get_font_surface_height(Font)));
}

View File

@ -104,7 +104,7 @@ Rect GUIListBox::CalcGraphicRect(bool clipped) {
PrepareTextToDraw(Items[item_index]);
Line lpos = GUI::CalcTextPositionHor(_textToDraw.GetCStr(), Font, 1 + pixel_size, right_hand_edge, at_y + 1,
(FrameAlignment)TextAlignment);
max_line.X2 = std::max(max_line.X2, lpos.X2);
max_line.X2 = MAX(max_line.X2, lpos.X2);
}
return SumRects(rc, RectWH(0, 0, max_line.X2 - max_line.X1 + 1, Height));
}

View File

@ -69,10 +69,10 @@ Rect GUISlider::CalcGraphicRect(bool clipped) {
Rect bar = _cachedBar;
Rect handle = _cachedHandle;
return Rect(
std::min(std::min(logical.Left, bar.Left), handle.Left),
std::min(std::min(logical.Top, bar.Top), handle.Top),
std::max(std::max(logical.Right, bar.Right), handle.Right),
std::max(std::max(logical.Bottom, bar.Bottom), handle.Bottom)
MIN(MIN(logical.Left, bar.Left), handle.Left),
MIN(MIN(logical.Top, bar.Top), handle.Top),
MAX(MAX(logical.Right, bar.Right), handle.Right),
MAX(MAX(logical.Bottom, bar.Bottom), handle.Bottom)
);
}
@ -136,7 +136,7 @@ void GUISlider::UpdateMetrics() {
_cachedBar = bar;
_cachedHandle = handle;
_handleRange = std::max(1, handle_range);
_handleRange = MAX(1, handle_range);
}
void GUISlider::Draw(Bitmap *ds, int x, int y) {

View File

@ -210,7 +210,7 @@ void AlignedStream::ReadPadding(size_t next_type) {
_block += next_type - pad;
}
_maxAlignment = Math::Max(_maxAlignment, next_type);
_maxAlignment = MAX(_maxAlignment, next_type);
// Data is evenly aligned now
if (_block % LargestPossibleType == 0) {
_block = 0;
@ -233,7 +233,7 @@ void AlignedStream::WritePadding(size_t next_type) {
_block += next_type - pad;
}
_maxAlignment = Math::Max(_maxAlignment, next_type);
_maxAlignment = MAX(_maxAlignment, next_type);
// Data is evenly aligned now
if (_block % LargestPossibleType == 0) {
_block = 0;

View File

@ -85,7 +85,7 @@ size_t BufferedStream::Read(void *toBuffer, size_t toSize) {
soff_t bufferOffset = _position - _bufferPosition;
assert(bufferOffset >= 0);
size_t bytesLeft = _buffer.size() - (size_t)bufferOffset;
size_t chunkSize = std::min<size_t>(bytesLeft, toSize);
size_t chunkSize = MIN<size_t>(bytesLeft, toSize);
memcpy(to, _buffer.data() + bufferOffset, chunkSize);
@ -133,7 +133,7 @@ bool BufferedStream::Seek(soff_t offset, StreamSeek origin) {
}
// clamp
_position = std::min(std::max(want_pos, (soff_t)_start), _end);
_position = MIN(MAX(want_pos, (soff_t)_start), _end);
return _position == want_pos;
}
@ -141,9 +141,9 @@ BufferedSectionStream::BufferedSectionStream(const String &file_name, soff_t sta
FileOpenMode open_mode, FileWorkMode work_mode, DataEndianess stream_endianess)
: BufferedStream(file_name, open_mode, work_mode, stream_endianess) {
assert(start_pos <= end_pos);
start_pos = std::min(start_pos, end_pos);
_start = std::min(start_pos, _end);
_end = std::min(end_pos, _end);
start_pos = MIN(start_pos, end_pos);
_start = MIN(start_pos, _end);
_end = MIN(end_pos, _end);
Seek(0, kSeekBegin);
}

View File

@ -38,13 +38,13 @@ bool IsRectInsideRect(const Rect &place, const Rect &item) {
float DistanceBetween(const Rect &r1, const Rect &r2) {
// https://gamedev.stackexchange.com/a/154040
Rect rect_outer(
std::min(r1.Left, r2.Left),
std::min(r1.Top, r2.Top),
std::max(r1.Right, r2.Right),
std::max(r1.Bottom, r2.Bottom)
MIN(r1.Left, r2.Left),
MIN(r1.Top, r2.Top),
MAX(r1.Right, r2.Right),
MAX(r1.Bottom, r2.Bottom)
);
int inner_width = std::max(0, rect_outer.GetWidth() - r1.GetWidth() - r2.GetWidth());
int inner_height = std::max(0, rect_outer.GetHeight() - r1.GetHeight() - r2.GetHeight());
int inner_width = MAX(0, rect_outer.GetWidth() - r1.GetWidth() - r2.GetWidth());
int inner_height = MAX(0, rect_outer.GetHeight() - r1.GetHeight() - r2.GetHeight());
return static_cast<float>(std::sqrt((inner_width ^ 2) + (inner_height ^ 2)));
}
@ -121,13 +121,13 @@ Rect PlaceInRect(const Rect &place, const Rect &item, const RectPlacement &place
}
Rect SumRects(const Rect &r1, const Rect &r2) { // NOTE: remember that in AGS Y axis is pointed downwards (top < bottom)
return Rect(std::min(r1.Left, r2.Left), std::min(r1.Top, r2.Top),
std::max(r1.Right, r2.Right), std::max(r1.Bottom, r2.Bottom));
return Rect(MIN(r1.Left, r2.Left), MIN(r1.Top, r2.Top),
MAX(r1.Right, r2.Right), MAX(r1.Bottom, r2.Bottom));
}
Rect IntersectRects(const Rect &r1, const Rect &r2) { // NOTE: the result may be empty (negative) rect if there's no intersection
return Rect(std::max(r1.Left, r2.Left), std::max(r1.Top, r2.Top),
std::min(r1.Right, r2.Right), std::min(r1.Bottom, r2.Bottom));
return Rect(MAX(r1.Left, r2.Left), MAX(r1.Top, r2.Top),
MIN(r1.Right, r2.Right), MIN(r1.Bottom, r2.Bottom));
}
} // namespace AGS3

View File

@ -222,7 +222,7 @@ inline void BlockCopy(uint8_t *dst, const size_t dst_pitch, const size_t dst_off
const uint8_t *src, const size_t src_pitch, const size_t src_offset,
const size_t height) {
for (size_t y = 0; y < height; ++y, src += src_pitch, dst += dst_pitch)
memcpy(dst + dst_offset, src + src_offset, Math::Min(dst_pitch - dst_offset, src_pitch - src_offset));
memcpy(dst + dst_offset, src + src_offset, MIN(dst_pitch - dst_offset, src_pitch - src_offset));
}
} // namespace Memory

View File

@ -92,7 +92,7 @@ size_t MemoryStream::Read(void *buffer, size_t size) {
}
assert(_len > _pos);
size_t remain = _len - _pos;
size_t read_sz = std::min(remain, size);
size_t read_sz = MIN(remain, size);
memcpy(buffer, _cbuf + _pos, read_sz);
_pos += read_sz;
return read_sz;
@ -117,8 +117,8 @@ bool MemoryStream::Seek(soff_t offset, StreamSeek origin) {
default:
return false;
}
_pos = static_cast<size_t>(std::max<soff_t>(0, pos));
_pos = static_cast<size_t>(std::min<soff_t>(_len, pos)); // clamp to EOS
_pos = static_cast<size_t>(MAX<soff_t>(0, pos));
_pos = static_cast<size_t>(MIN<soff_t>(_len, pos)); // clamp to EOS
return true;
}
@ -126,7 +126,7 @@ size_t MemoryStream::Write(const void *buffer, size_t size) {
if (_pos >= _buf_sz) {
return 0;
}
size = std::min(size, _buf_sz - _pos);
size = MIN(size, _buf_sz - _pos);
memcpy(_buf + _pos, buffer, size);
_pos += size;
_len += size;

View File

@ -144,7 +144,7 @@ void String::Write(Stream *out) const {
void String::WriteCount(Stream *out, size_t count) const {
if (out) {
size_t str_out_len = Math::Min(count - 1, _len);
size_t str_out_len = MIN(count - 1, _len);
if (str_out_len > 0)
out->Write(_cstr, str_out_len);
size_t null_out_len = count - str_out_len;
@ -173,27 +173,27 @@ int String::CompareLeftNoCase(const char *cstr, size_t count) const {
int String::CompareMid(const char *cstr, size_t from, size_t count) const {
cstr = cstr ? cstr : "";
from = Math::Min(from, _len);
from = MIN(from, _len);
return strncmp(_cstr + from, cstr, count != NoIndex ? count : strlen(cstr));
}
int String::CompareMidNoCase(const char *cstr, size_t from, size_t count) const {
cstr = cstr ? cstr : "";
from = Math::Min(from, _len);
from = MIN(from, _len);
return ags_strnicmp(_cstr + from, cstr, count != NoIndex ? count : strlen(cstr));
}
int String::CompareRight(const char *cstr, size_t count) const {
cstr = cstr ? cstr : "";
count = count != NoIndex ? count : strlen(cstr);
size_t off = Math::Min(_len, count);
size_t off = MIN(_len, count);
return strncmp(_cstr + _len - off, cstr, count);
}
int String::CompareRightNoCase(const char *cstr, size_t count) const {
cstr = cstr ? cstr : "";
count = count != NoIndex ? count : strlen(cstr);
size_t off = Math::Min(_len, count);
size_t off = MIN(_len, count);
return ags_strnicmp(_cstr + _len - off, cstr, count);
}
@ -210,7 +210,7 @@ size_t String::FindCharReverse(char c, size_t from) const {
return NoIndex;
}
from = Math::Min(from, _len - 1);
from = MIN(from, _len - 1);
const char *seek_ptr = _cstr + from;
while (seek_ptr >= _cstr) {
if (*seek_ptr == c) {
@ -327,7 +327,7 @@ String String::Upper() const {
}
String String::Left(size_t count) const {
count = Math::Min(count, _len);
count = MIN(count, _len);
return count == _len ? *this : String(_cstr, count);
}
@ -337,7 +337,7 @@ String String::Mid(size_t from, size_t count) const {
}
String String::Right(size_t count) const {
count = Math::Min(count, _len);
count = MIN(count, _len);
return count == _len ? *this : String(_cstr + _len - count, count);
}
@ -400,7 +400,7 @@ void String::Reserve(size_t max_length) {
if (max_length > _bufHead->Capacity) {
// grow by 50%
size_t grow_length = _bufHead->Capacity + (_bufHead->Capacity / 2);
Copy(Math::Max(max_length, grow_length));
Copy(MAX(max_length, grow_length));
}
} else {
Create(max_length);
@ -469,7 +469,7 @@ void String::AppendFmtv(const char *fcstr, va_list argptr) {
void String::ClipLeft(size_t count) {
if ((_len != 0) && (count > 0)) {
count = Math::Min(count, _len);
count = MIN(count, _len);
BecomeUnique();
_len -= count;
_cstr += count;
@ -478,7 +478,7 @@ void String::ClipLeft(size_t count) {
void String::ClipMid(size_t from, size_t count) {
if (from < _len) {
count = Math::Min(count, _len - from);
count = MIN(count, _len - from);
if (count > 0) {
BecomeUnique();
if (!from) {
@ -498,7 +498,7 @@ void String::ClipMid(size_t from, size_t count) {
void String::ClipRight(size_t count) {
if (_len > 0 && count > 0) {
count = Math::Min(count, _len);
count = MIN(count, _len);
BecomeUnique();
_len -= count;
_cstr[_len] = 0;
@ -745,7 +745,7 @@ void String::SetAt(size_t index, char c) {
void String::SetString(const char *cstr, size_t length) {
if (cstr) {
length = Math::Min(length, strlen(cstr));
length = MIN(length, strlen(cstr));
if (length > 0) {
ReserveAndShift(false, Math::Surplus(length, _len));
memcpy(_cstr, cstr, length);
@ -820,7 +820,7 @@ void String::TrimRight(char c) {
void String::TruncateToLeft(size_t count) {
if (_len != 0) {
count = Math::Min(count, _len);
count = MIN(count, _len);
if (count < _len) {
BecomeUnique();
_len = count;
@ -843,7 +843,7 @@ void String::TruncateToMid(size_t from, size_t count) {
void String::TruncateToRight(size_t count) {
if (_len != 0) {
count = Math::Min(count, _len);
count = MIN(count, _len);
if (count < _len) {
BecomeUnique();
_cstr += _len - count;
@ -939,7 +939,7 @@ void String::Copy(size_t max_length, size_t offset) {
char *new_data = new char[sizeof(String::BufHeader) + max_length + 1];
// remember, that _cstr may point to any address in buffer
char *cstr_head = new_data + sizeof(String::BufHeader) + offset;
size_t copy_length = Math::Min(_len, max_length);
size_t copy_length = MIN(_len, max_length);
memcpy(cstr_head, _cstr, copy_length);
Free();
_buf = new_data;
@ -974,7 +974,7 @@ void String::ReserveAndShift(bool left, size_t more_length) {
if (_bufHead->Capacity < total_length) { // not enough capacity - reallocate buffer
// grow by 50% or at least to total_size
size_t grow_length = _bufHead->Capacity + (_bufHead->Capacity >> 1);
Copy(Math::Max(total_length, grow_length), left ? more_length : 0u);
Copy(MAX(total_length, grow_length), left ? more_length : 0u);
} else if (_bufHead->RefCount > 1) { // is a shared string - clone buffer
Copy(total_length, left ? more_length : 0u);
} else {

View File

@ -130,7 +130,7 @@ void StrUtil::ReadString(char *cstr, Stream *in, size_t buf_limit) {
return;
}
len = Math::Min(len, buf_limit - 1);
len = MIN(len, buf_limit - 1);
if (len > 0)
in->Read(cstr, len);
cstr[len] = 0;

View File

@ -85,10 +85,10 @@ String TextStreamReader::ReadLine() {
if (c < chars_read_last && *seek_ptr == '\n') {
line_break_position = seek_ptr - char_buffer;
if (str_len < max_chars) {
append_length = Math::Min(line_break_position, max_chars - str_len);
append_length = MIN(line_break_position, max_chars - str_len);
}
} else {
append_length = Math::Min(chars_read_last, max_chars - str_len);
append_length = MIN(chars_read_last, max_chars - str_len);
}
if (append_length > 0) {