summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-05-08 22:47:30 +0300
committerAndrei Karas <akaras@inbox.ru>2014-05-08 22:47:30 +0300
commit64aabf79b5a10bdf8192bb1048804a3e36730905 (patch)
treeab7f8a82228acd617ec178f04d7ca6bb09f727de /src
parent3f9d0c023f3d84de0c68dbf9f7c29aa1b0abb9c9 (diff)
downloadmanaverse-64aabf79b5a10bdf8192bb1048804a3e36730905.tar.gz
manaverse-64aabf79b5a10bdf8192bb1048804a3e36730905.tar.bz2
manaverse-64aabf79b5a10bdf8192bb1048804a3e36730905.tar.xz
manaverse-64aabf79b5a10bdf8192bb1048804a3e36730905.zip
Fix code style in resources.
Diffstat (limited to 'src')
-rw-r--r--src/resources/action.cpp5
-rw-r--r--src/resources/action.h6
-rw-r--r--src/resources/dye.cpp30
-rw-r--r--src/resources/dye.h2
-rw-r--r--src/resources/imagewriter.cpp5
-rw-r--r--src/resources/mapreader.cpp6
-rw-r--r--src/resources/resourcemanager.cpp6
-rw-r--r--src/resources/sdlimagehelper.cpp8
8 files changed, 41 insertions, 27 deletions
diff --git a/src/resources/action.cpp b/src/resources/action.cpp
index 7deced3d5..cbcf4f72b 100644
--- a/src/resources/action.cpp
+++ b/src/resources/action.cpp
@@ -23,7 +23,6 @@
#include "resources/action.h"
#include "resources/animation.h"
-#include "resources/spritedef.h"
#include "utils/dtor.h"
@@ -40,7 +39,7 @@ Action::~Action()
delete_all(mAnimations);
}
-const Animation *Action::getAnimation(int direction) const noexcept
+const Animation *Action::getAnimation(SpriteDirection direction) const noexcept
{
Animations::const_iterator i = mAnimations.find(direction);
@@ -66,7 +65,7 @@ const Animation *Action::getAnimation(int direction) const noexcept
return (i == mAnimations.end()) ? nullptr : i->second;
}
-void Action::setAnimation(const int direction,
+void Action::setAnimation(const SpriteDirection direction,
Animation *const animation) noexcept
{
mAnimations[direction] = animation;
diff --git a/src/resources/action.h b/src/resources/action.h
index 92fadfc89..64d8b40d8 100644
--- a/src/resources/action.h
+++ b/src/resources/action.h
@@ -23,6 +23,8 @@
#ifndef RESOURCES_ACTION_H
#define RESOURCES_ACTION_H
+#include "resources/spritedef.h"
+
#include <map>
#include "localconsts.h"
@@ -41,10 +43,10 @@ class Action final
~Action();
- void setAnimation(const int direction,
+ void setAnimation(const SpriteDirection direction,
Animation *const animation) noexcept;
- const Animation *getAnimation(int direction) const
+ const Animation *getAnimation(SpriteDirection direction) const
noexcept A_WARN_UNUSED;
unsigned getNumber() const noexcept A_WARN_UNUSED
diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp
index 2baa2d12b..ce15c5b2d 100644
--- a/src/resources/dye.cpp
+++ b/src/resources/dye.cpp
@@ -36,10 +36,10 @@
#include "debug.h"
DyePalette::DyePalette(const std::string &description,
- const int8_t blockSize) :
+ const uint8_t blockSize) :
mColors()
{
- const size_t size = static_cast<int>(description.length());
+ const size_t size = static_cast<size_t>(description.length());
if (size == 0)
return;
@@ -53,7 +53,7 @@ DyePalette::DyePalette(const std::string &description,
DyeColor color(0, 0, 0, 0);
- for (int i = 0, colorIdx = 0; i < blockSize && colorIdx < 4;
+ for (size_t i = 0, colorIdx = 0; i < blockSize && colorIdx < 4;
i += 2, colorIdx ++)
{
color.value[colorIdx] = static_cast<unsigned char>((
@@ -209,7 +209,9 @@ void DyePalette::replaceSColor(uint32_t *restrict pixels,
if (sz % 2)
-- it_end;
- for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++pixels)
+ for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ pixels != p_end;
+ ++pixels)
{
uint8_t *const p = reinterpret_cast<uint8_t *>(pixels);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
@@ -266,7 +268,9 @@ void DyePalette::replaceAColor(uint32_t *restrict pixels,
if (sz % 2)
-- it_end;
- for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++pixels)
+ for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ pixels != p_end;
+ ++pixels)
{
uint8_t *const p = reinterpret_cast<uint8_t *>(pixels);
const unsigned int data = *pixels;
@@ -310,7 +314,9 @@ void DyePalette::replaceSOGLColor(uint32_t *restrict pixels,
if (sz % 2)
-- it_end;
- for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++pixels)
+ for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ pixels != p_end;
+ ++pixels)
{
uint8_t *const p = reinterpret_cast<uint8_t *>(pixels);
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
@@ -360,7 +366,9 @@ void DyePalette::replaceAOGLColor(uint32_t *restrict pixels,
if (sz % 2)
-- it_end;
- for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++pixels)
+ for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ pixels != p_end;
+ ++pixels)
{
uint8_t *const p = reinterpret_cast<uint8_t *>(pixels);
const unsigned int data = *pixels;
@@ -509,7 +517,9 @@ int Dye::getType() const
void Dye::normalDye(uint32_t *restrict pixels, const int bufSize) const
{
- for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++ pixels)
+ for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ pixels != p_end;
+ ++ pixels)
{
const uint32_t p = *pixels;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
@@ -562,7 +572,9 @@ void Dye::normalDye(uint32_t *restrict pixels, const int bufSize) const
void Dye::normalOGLDye(uint32_t *restrict pixels, const int bufSize) const
{
- for (uint32_t *p_end = pixels + bufSize; pixels != p_end; ++ pixels)
+ for (uint32_t *p_end = pixels + static_cast<size_t>(bufSize);
+ pixels != p_end;
+ ++ pixels)
{
const uint32_t p = *pixels;
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
diff --git a/src/resources/dye.h b/src/resources/dye.h
index b6003624b..80da36506 100644
--- a/src/resources/dye.h
+++ b/src/resources/dye.h
@@ -45,7 +45,7 @@ class DyePalette final
* The string is either a file name or a sequence of hexadecimal RGB
* values separated by ',' and starting with '#'.
*/
- DyePalette(const std::string &pallete, const int8_t blockSize);
+ DyePalette(const std::string &pallete, const uint8_t blockSize);
A_DELETE_COPY(DyePalette)
diff --git a/src/resources/imagewriter.cpp b/src/resources/imagewriter.cpp
index 65e3a7dbe..9ff87c758 100644
--- a/src/resources/imagewriter.cpp
+++ b/src/resources/imagewriter.cpp
@@ -84,7 +84,8 @@ bool ImageWriter::writePNG(SDL_Surface *const surface,
png_set_packing(png_ptr);
- png_bytep *const row_pointers = new png_bytep[surface->h];
+ png_bytep *const row_pointers
+ = new png_bytep[static_cast<size_t>(surface->h)];
/*
if (!row_pointers)
{
@@ -97,7 +98,7 @@ bool ImageWriter::writePNG(SDL_Surface *const surface,
for (int i = 0; i < surface->h; i++)
{
row_pointers[i] = static_cast<png_bytep>(static_cast<uint8_t *>(
- surface->pixels)) + i * surface->pitch;
+ surface->pixels) + static_cast<size_t>(i * surface->pitch));
}
png_write_image(png_ptr, row_pointers);
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp
index e4c3e6f73..075891764 100644
--- a/src/resources/mapreader.cpp
+++ b/src/resources/mapreader.cpp
@@ -147,7 +147,7 @@ int inflateMemory(unsigned char *restrict const in,
return Z_MEM_ERROR;
}
- strm.next_out = out + bufferSize;
+ strm.next_out = out + static_cast<size_t>(bufferSize);
strm.avail_out = bufferSize;
bufferSize *= 2;
}
@@ -576,8 +576,8 @@ bool MapReader::readBase64Layer(const XmlNodePtrConst childNode,
if (!dataChild)
return true;
- const int len = static_cast<int>(strlen(
- reinterpret_cast<const char*>(dataChild->content)) + 1);
+ const size_t len = strlen(
+ reinterpret_cast<const char*>(dataChild->content)) + 1;
unsigned char *charData = new unsigned char[len + 1];
xmlChar *const xmlChars = xmlNodeGetContent(dataChild);
const char *charStart = reinterpret_cast<const char*>(xmlChars);
diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp
index 876d7b751..8ed5d52f1 100644
--- a/src/resources/resourcemanager.cpp
+++ b/src/resources/resourcemanager.cpp
@@ -215,7 +215,7 @@ bool ResourceManager::cleanOrphans(const bool always)
timeval tv;
gettimeofday(&tv, nullptr);
// Delete orphaned resources after 30 seconds.
- time_t oldest = tv.tv_sec;
+ time_t oldest = static_cast<time_t>(tv.tv_sec);
const time_t threshold = oldest - 30;
if (mOrphanedResources.empty() || (!always && mOldestOrphan >= threshold))
@@ -841,7 +841,7 @@ void ResourceManager::release(Resource *const res)
timeval tv;
gettimeofday(&tv, nullptr);
- const time_t timestamp = tv.tv_sec;
+ const time_t timestamp = static_cast<time_t>(tv.tv_sec);
res->mTimeStamp = timestamp;
if (mOrphanedResources.empty())
@@ -999,7 +999,7 @@ bool ResourceManager::copyFile(const std::string &restrict src,
}
const int fileSize = static_cast<const int>(PHYSFS_fileLength(srcFile));
- char *buf = new char[fileSize];
+ char *buf = new char[static_cast<size_t>(fileSize)];
PHYSFS_read(srcFile, buf, 1, fileSize);
PHYSFS_write(dstFile, buf, 1, fileSize);
diff --git a/src/resources/sdlimagehelper.cpp b/src/resources/sdlimagehelper.cpp
index 7b9aeda5e..0858a9908 100644
--- a/src/resources/sdlimagehelper.cpp
+++ b/src/resources/sdlimagehelper.cpp
@@ -118,7 +118,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage,
return nullptr;
bool hasAlpha = false;
- const int sz = tmpImage->w * tmpImage->h;
+ const size_t sz = tmpImage->w * tmpImage->h;
// The alpha channel to be filled with alpha values
uint8_t *alphaChannel = new uint8_t[sz];
@@ -126,7 +126,7 @@ Image *SDLImageHelper::createTextSurface(SDL_Surface *const tmpImage,
const SDL_PixelFormat *const fmt = tmpImage->format;
if (fmt->Amask)
{
- for (int i = 0; i < sz; ++ i)
+ for (size_t i = 0; i < sz; ++ i)
{
uint32_t c = (static_cast<uint32_t*>(tmpImage->pixels))[i];
@@ -202,7 +202,7 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const
converted = true;
}
- const int sz = tmpImage->w * tmpImage->h;
+ const size_t sz = tmpImage->w * tmpImage->h;
// The alpha channel to be filled with alpha values
uint8_t *alphaChannel = new uint8_t[sz];
@@ -217,7 +217,7 @@ Image *SDLImageHelper::_SDLload(SDL_Surface *tmpImage) const
const uint8_t ashift = fmt->Ashift;
const uint8_t aloss = fmt->Aloss;
const uint32_t *pixels = static_cast<uint32_t*>(tmpImage->pixels);
- for (int i = 0; i < sz; ++ i)
+ for (size_t i = 0; i < sz; ++ i)
{
const unsigned v = (pixels[i] & amask) >> ashift;
const uint8_t a = static_cast<const uint8_t>((v << aloss)