Use std algorithm functions

This commit is contained in:
Jonas Kulla 2013-12-08 13:19:22 +01:00
parent ef12e96158
commit 8c6648f47e
5 changed files with 15 additions and 30 deletions

View File

@ -34,6 +34,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <algorithm>
#include <QDebug> #include <QDebug>
@ -160,7 +161,7 @@ RGSS_ioRead(PHYSFS_Io *self, void *buffer, PHYSFS_uint64 len)
PHYSFS_Io *io = entry->io; PHYSFS_Io *io = entry->io;
uint64_t toRead = min<uint64_t>(entry->data.size - entry->currentOffset, len); uint64_t toRead = std::min<uint64_t>(entry->data.size - entry->currentOffset, len);
uint64_t offs = entry->currentOffset; uint64_t offs = entry->currentOffset;
io->seek(io, entry->data.offset + offs); io->seek(io, entry->data.offset + offs);
@ -188,7 +189,7 @@ RGSS_ioRead(PHYSFS_Io *self, void *buffer, PHYSFS_uint64 len)
if (preAlign == 4) if (preAlign == 4)
preAlign = 0; preAlign = 0;
else else
preAlign = min<uint64_t>(preAlign, len); preAlign = std::min<uint64_t>(preAlign, len);
uint8_t postAlign = (len > preAlign) ? (offs + len) % 4 : 0; uint8_t postAlign = (len > preAlign) ? (offs + len) % 4 : 0;

View File

@ -39,11 +39,12 @@
#include <SDL_timer.h> #include <SDL_timer.h>
#include <time.h> #include <time.h>
#include <algorithm>
struct PingPong struct PingPong
{ {
TEXFBO rt[2]; TEXFBO rt[2];
unsigned srcInd, dstInd; uint8_t srcInd, dstInd;
int screenW, screenH; int screenW, screenH;
PingPong(int screenW, int screenH) PingPong(int screenW, int screenH)
@ -91,7 +92,7 @@ struct PingPong
void swapRender() void swapRender()
{ {
swapIndices(); std::swap(srcInd, dstInd);
/* Discard dest buffer */ /* Discard dest buffer */
TEX::bind(rt[dstInd].tex); TEX::bind(rt[dstInd].tex);
@ -118,13 +119,6 @@ private:
FBO::bind(rt[srcInd].fbo, FBO::Read); FBO::bind(rt[srcInd].fbo, FBO::Read);
FBO::bind(rt[dstInd].fbo, FBO::Draw); FBO::bind(rt[dstInd].fbo, FBO::Draw);
} }
void swapIndices()
{
unsigned tmp = srcInd;
srcInd = dstInd;
dstInd = tmp;
}
}; };
class ScreenScene : public Scene class ScreenScene : public Scene

View File

@ -23,6 +23,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <algorithm>
#include "serial-util.h" #include "serial-util.h"
#include "exception.h" #include "exception.h"
@ -77,9 +78,9 @@ void Table::resize(int x, int y, int z)
{ {
int16_t *newData = static_cast<int16_t*>(calloc(x * y * z, sizeof(int16_t))); int16_t *newData = static_cast<int16_t*>(calloc(x * y * z, sizeof(int16_t)));
for (int i = 0; i < min(x, m_x); ++i) for (int i = 0; i < std::min(x, m_x); ++i)
for (int j = 0; j < min(y, m_y); ++j) for (int j = 0; j < std::min(y, m_y); ++j)
for (int k = 0; k < min(z, m_z); k++) for (int k = 0; k < std::min(z, m_z); k++)
{ {
int index = x*y*k + x*j + i; int index = x*y*k + x*j + i;
newData[index] = at(i, j, k); newData[index] = at(i, j, k);
@ -118,8 +119,8 @@ void Table::resize(int x, int y)
{ {
int16_t *newData = static_cast<int16_t*>(calloc(x * y, sizeof(int16_t))); int16_t *newData = static_cast<int16_t*>(calloc(x * y, sizeof(int16_t)));
for (int i = 0; i < min(x, m_x); ++i) for (int i = 0; i < std::min(x, m_x); ++i)
for (int j = 0; j < min(y, m_y); ++j) for (int j = 0; j < std::min(y, m_y); ++j)
{ {
int index = x*j + i; int index = x*j + i;
newData[index] = at(i, j); newData[index] = at(i, j);

View File

@ -38,6 +38,7 @@
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
#include <algorithm>
#include <QVector> #include <QVector>
@ -638,8 +639,8 @@ struct TilemapPrivate
/* Blit autotiles */ /* Blit autotiles */
Q_FOREACH (uint8_t i, atlas.usableATs) Q_FOREACH (uint8_t i, atlas.usableATs)
{ {
int blitW = min(autotiles[i]->width(), atAreaW); int blitW = std::min(autotiles[i]->width(), atAreaW);
int blitH = min(autotiles[i]->height(), atAreaH); int blitH = std::min(autotiles[i]->height(), atAreaH);
FBO::bind(autotiles[i]->getGLTypes().fbo, FBO::Read); FBO::bind(autotiles[i]->getGLTypes().fbo, FBO::Read);
FBO::blit(0, 0, 0, i*autotileH, blitW, blitH); FBO::blit(0, 0, 0, i*autotileH, blitW, blitH);

View File

@ -46,18 +46,6 @@ static inline T clamp(T value, T min, T max)
return value; return value;
} }
template<typename T>
static inline T min(T value1, T value2)
{
return (value1 < value2) ? value1 : value2;
}
template<typename T>
static inline T max(T value1, T value2)
{
return (value1 > value2) ? value1 : value2;
}
static inline int static inline int
findNextPow2(int start) findNextPow2(int start)
{ {