From 8c6648f47ed205618e3093229441e83fcaf77ad1 Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Sun, 8 Dec 2013 13:19:22 +0100 Subject: [PATCH] Use std algorithm functions --- src/filesystem.cpp | 5 +++-- src/graphics.cpp | 12 +++--------- src/table.cpp | 11 ++++++----- src/tilemap.cpp | 5 +++-- src/util.h | 12 ------------ 5 files changed, 15 insertions(+), 30 deletions(-) diff --git a/src/filesystem.cpp b/src/filesystem.cpp index b75a88b..5c01ae7 100644 --- a/src/filesystem.cpp +++ b/src/filesystem.cpp @@ -34,6 +34,7 @@ #include #include +#include #include @@ -160,7 +161,7 @@ RGSS_ioRead(PHYSFS_Io *self, void *buffer, PHYSFS_uint64 len) PHYSFS_Io *io = entry->io; - uint64_t toRead = min(entry->data.size - entry->currentOffset, len); + uint64_t toRead = std::min(entry->data.size - entry->currentOffset, len); uint64_t offs = entry->currentOffset; io->seek(io, entry->data.offset + offs); @@ -188,7 +189,7 @@ RGSS_ioRead(PHYSFS_Io *self, void *buffer, PHYSFS_uint64 len) if (preAlign == 4) preAlign = 0; else - preAlign = min(preAlign, len); + preAlign = std::min(preAlign, len); uint8_t postAlign = (len > preAlign) ? (offs + len) % 4 : 0; diff --git a/src/graphics.cpp b/src/graphics.cpp index c5dec1d..7a395fb 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -39,11 +39,12 @@ #include #include +#include struct PingPong { TEXFBO rt[2]; - unsigned srcInd, dstInd; + uint8_t srcInd, dstInd; int screenW, screenH; PingPong(int screenW, int screenH) @@ -91,7 +92,7 @@ struct PingPong void swapRender() { - swapIndices(); + std::swap(srcInd, dstInd); /* Discard dest buffer */ TEX::bind(rt[dstInd].tex); @@ -118,13 +119,6 @@ private: FBO::bind(rt[srcInd].fbo, FBO::Read); FBO::bind(rt[dstInd].fbo, FBO::Draw); } - - void swapIndices() - { - unsigned tmp = srcInd; - srcInd = dstInd; - dstInd = tmp; - } }; class ScreenScene : public Scene diff --git a/src/table.cpp b/src/table.cpp index 32d1b72..77f0217 100644 --- a/src/table.cpp +++ b/src/table.cpp @@ -23,6 +23,7 @@ #include #include +#include #include "serial-util.h" #include "exception.h" @@ -77,9 +78,9 @@ void Table::resize(int x, int y, int z) { int16_t *newData = static_cast(calloc(x * y * z, sizeof(int16_t))); - for (int i = 0; i < min(x, m_x); ++i) - for (int j = 0; j < min(y, m_y); ++j) - for (int k = 0; k < min(z, m_z); k++) + for (int i = 0; i < std::min(x, m_x); ++i) + for (int j = 0; j < std::min(y, m_y); ++j) + for (int k = 0; k < std::min(z, m_z); k++) { int index = x*y*k + x*j + i; newData[index] = at(i, j, k); @@ -118,8 +119,8 @@ void Table::resize(int x, int y) { int16_t *newData = static_cast(calloc(x * y, sizeof(int16_t))); - for (int i = 0; i < min(x, m_x); ++i) - for (int j = 0; j < min(y, m_y); ++j) + for (int i = 0; i < std::min(x, m_x); ++i) + for (int j = 0; j < std::min(y, m_y); ++j) { int index = x*j + i; newData[index] = at(i, j); diff --git a/src/tilemap.cpp b/src/tilemap.cpp index 50fb826..63f25f5 100644 --- a/src/tilemap.cpp +++ b/src/tilemap.cpp @@ -38,6 +38,7 @@ #include #include +#include #include @@ -638,8 +639,8 @@ struct TilemapPrivate /* Blit autotiles */ Q_FOREACH (uint8_t i, atlas.usableATs) { - int blitW = min(autotiles[i]->width(), atAreaW); - int blitH = min(autotiles[i]->height(), atAreaH); + int blitW = std::min(autotiles[i]->width(), atAreaW); + int blitH = std::min(autotiles[i]->height(), atAreaH); FBO::bind(autotiles[i]->getGLTypes().fbo, FBO::Read); FBO::blit(0, 0, 0, i*autotileH, blitW, blitH); diff --git a/src/util.h b/src/util.h index 76844ad..52da65e 100644 --- a/src/util.h +++ b/src/util.h @@ -46,18 +46,6 @@ static inline T clamp(T value, T min, T max) return value; } -template -static inline T min(T value1, T value2) -{ - return (value1 < value2) ? value1 : value2; -} - -template -static inline T max(T value1, T value2) -{ - return (value1 > value2) ? value1 : value2; -} - static inline int findNextPow2(int start) {