mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
code review
This commit is contained in:
@@ -542,8 +542,8 @@ void CSDL_Ext::putPixelWithoutRefreshIfInSurf(SDL_Surface *ekran, const int & x,
|
||||
CSDL_Ext::putPixelWithoutRefresh(ekran, x, y, R, G, B, A);
|
||||
}
|
||||
|
||||
template<int bpp>
|
||||
void loopOverPixel(SDL_Surface * surf, const Rect & rect, std::function<void(int &r, int &g, int &b)> func)
|
||||
template<typename Functor>
|
||||
void loopOverPixel(SDL_Surface * surf, const Rect & rect, Functor functor)
|
||||
{
|
||||
uint8_t * pixels = static_cast<uint8_t*>(surf->pixels);
|
||||
|
||||
@@ -556,24 +556,23 @@ void loopOverPixel(SDL_Surface * surf, const Rect & rect, std::function<void(int
|
||||
|
||||
for (uint8_t * pixel = pixel_from; pixel < pixel_dest; pixel += surf->format->BytesPerPixel)
|
||||
{
|
||||
int r = Channels::px<bpp>::r.get(pixel);
|
||||
int g = Channels::px<bpp>::g.get(pixel);
|
||||
int b = Channels::px<bpp>::b.get(pixel);
|
||||
int r = Channels::px<4>::r.get(pixel);
|
||||
int g = Channels::px<4>::g.get(pixel);
|
||||
int b = Channels::px<4>::b.get(pixel);
|
||||
|
||||
func(r, g, b);
|
||||
functor(r, g, b);
|
||||
|
||||
Channels::px<bpp>::r.set(pixel, r);
|
||||
Channels::px<bpp>::g.set(pixel, g);
|
||||
Channels::px<bpp>::b.set(pixel, b);
|
||||
Channels::px<4>::r.set(pixel, r);
|
||||
Channels::px<4>::g.set(pixel, g);
|
||||
Channels::px<4>::b.set(pixel, b);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
template<int bpp>
|
||||
void CSDL_Ext::convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect )
|
||||
void CSDL_Ext::convertToGrayscale(SDL_Surface * surf, const Rect & rect )
|
||||
{
|
||||
loopOverPixel<bpp>(surf, rect, [](int &r, int &g, int &b){
|
||||
loopOverPixel(surf, rect, [](int &r, int &g, int &b){
|
||||
int gray = static_cast<int>(0.299 * r + 0.587 * g + 0.114 * b);
|
||||
r = gray;
|
||||
g = gray;
|
||||
@@ -581,19 +580,9 @@ void CSDL_Ext::convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect )
|
||||
});
|
||||
}
|
||||
|
||||
void CSDL_Ext::convertToGrayscale( SDL_Surface * surf, const Rect & rect )
|
||||
void CSDL_Ext::convertToH2Scheme(SDL_Surface * surf, const Rect & rect )
|
||||
{
|
||||
switch(surf->format->BytesPerPixel)
|
||||
{
|
||||
case 3: convertToGrayscaleBpp<3>(surf, rect); break;
|
||||
case 4: convertToGrayscaleBpp<4>(surf, rect); break;
|
||||
}
|
||||
}
|
||||
|
||||
template<int bpp>
|
||||
void CSDL_Ext::convertToH2SchemeBpp(SDL_Surface * surf, const Rect & rect )
|
||||
{
|
||||
loopOverPixel<bpp>(surf, rect, [](int &r, int &g, int &b){
|
||||
loopOverPixel(surf, rect, [](int &r, int &g, int &b){
|
||||
double gray = 0.3 * r + 0.59 * g + 0.11 * b;
|
||||
double factor = 2.0;
|
||||
|
||||
@@ -608,15 +597,6 @@ void CSDL_Ext::convertToH2SchemeBpp(SDL_Surface * surf, const Rect & rect )
|
||||
});
|
||||
}
|
||||
|
||||
void CSDL_Ext::convertToH2Scheme( SDL_Surface * surf, const Rect & rect )
|
||||
{
|
||||
switch(surf->format->BytesPerPixel)
|
||||
{
|
||||
case 3: convertToH2SchemeBpp<3>(surf, rect); break;
|
||||
case 4: convertToH2SchemeBpp<4>(surf, rect); break;
|
||||
}
|
||||
}
|
||||
|
||||
void CSDL_Ext::blitSurface(SDL_Surface * src, const Rect & srcRectInput, SDL_Surface * dst, const Point & dstPoint)
|
||||
{
|
||||
SDL_Rect srcRect = CSDL_Ext::toSDL(srcRectInput);
|
||||
|
||||
@@ -67,12 +67,7 @@ SDL_Color toSDL(const ColorRGBA & color);
|
||||
SDL_Surface * newSurface(const Point & dimensions, SDL_Surface * mod); //creates new surface, with flags/format same as in surface given
|
||||
SDL_Surface * newSurface(const Point & dimensions); //creates new surface, with flags/format same as in screen surface
|
||||
|
||||
template<int bpp>
|
||||
void convertToGrayscaleBpp(SDL_Surface * surf, const Rect & rect);
|
||||
void convertToGrayscale(SDL_Surface * surf, const Rect & rect);
|
||||
|
||||
template<int bpp>
|
||||
void convertToH2SchemeBpp(SDL_Surface * surf, const Rect & rect);
|
||||
void convertToH2Scheme(SDL_Surface * surf, const Rect & rect);
|
||||
|
||||
void setColorKey(SDL_Surface * surface, SDL_Color color);
|
||||
|
||||
@@ -123,12 +123,10 @@ struct DLL_LINKAGE PlayerCheated : public CPackForClient
|
||||
template <typename Handler> void serialize(Handler & h)
|
||||
{
|
||||
h & player;
|
||||
if (h.version >= Handler::Version::COLOR_FILTER)
|
||||
h & localOnlyCheat;
|
||||
h & localOnlyCheat;
|
||||
h & losingCheatCode;
|
||||
h & winningCheatCode;
|
||||
if (h.version >= Handler::Version::COLOR_FILTER)
|
||||
h & colorScheme;
|
||||
h & colorScheme;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -42,9 +42,8 @@ enum class ESerializationVersion : int32_t
|
||||
REWARDABLE_EXTENSIONS, // new functionality for rewardable objects
|
||||
FLAGGABLE_BONUS_SYSTEM_NODE, // flaggable objects now contain bonus system node
|
||||
RANDOMIZATION_REWORK, // random rolls logic has been moved to server
|
||||
COLOR_FILTER, // color filter cheat
|
||||
|
||||
CURRENT = COLOR_FILTER,
|
||||
CURRENT = RANDOMIZATION_REWORK,
|
||||
};
|
||||
|
||||
static_assert(ESerializationVersion::MINIMAL <= ESerializationVersion::CURRENT, "Invalid serialization version definition!");
|
||||
|
||||
Reference in New Issue
Block a user