Bläddra i källkod

vcmi/client: make ColorRGBA constexpr

1. Replace overflowing int3 to ColorRGBA, which is more semantically
   correct
2. Make ColorRGBA constexpr, to make sure than hardcoded colors can
   be initialized in compile time
Konstantin 2 år sedan
förälder
incheckning
3cf303f1c7
2 ändrade filer med 7 tillägg och 6 borttagningar
  1. 4 3
      client/adventureMap/mapHandler.cpp
  2. 3 3
      lib/Color.h

+ 4 - 3
client/adventureMap/mapHandler.cpp

@@ -23,6 +23,7 @@
 #include "../../lib/mapObjects/CGHeroInstance.h"
 #include "../../lib/mapObjects/CObjectClassesHandler.h"
 #include "../../lib/mapping/CMap.h"
+#include "../../lib/Color.h"
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/CStopWatch.h"
@@ -925,21 +926,21 @@ void CMapHandler::CMapBlitter::blit(SDL_Surface * targetSurf, const MapDrawingIn
 		{
 			for (realPos.y = initPos.y, pos.y = topTile.y; pos.y < topTile.y + tileCount.y; pos.y++, realPos.y += tileSize)
 			{
-				const int3 color(0x555555, 0x555555, 0x555555);
+				constexpr ColorRGBA color(0x55, 0x55, 0x55);
 
 				if (realPos.y >= info->drawBounds.y &&
 					realPos.y < info->drawBounds.y + info->drawBounds.h)
 					for(int i = 0; i < tileSize; i++)
 						if (realPos.x + i >= info->drawBounds.x &&
 							realPos.x + i < info->drawBounds.x + info->drawBounds.w)
-							CSDL_Ext::putPixelWithoutRefresh(targetSurf, realPos.x + i, realPos.y, color.x, color.y, color.z);
+							CSDL_Ext::putPixelWithoutRefresh(targetSurf, realPos.x + i, realPos.y, color.r, color.g, color.b);
 
 				if (realPos.x >= info->drawBounds.x &&
 					realPos.x < info->drawBounds.x + info->drawBounds.w)
 					for(int i = 0; i < tileSize; i++)
 						if (realPos.y + i >= info->drawBounds.y &&
 							realPos.y + i < info->drawBounds.y + info->drawBounds.h)
-							CSDL_Ext::putPixelWithoutRefresh(targetSurf, realPos.x, realPos.y + i, color.x, color.y, color.z);
+							CSDL_Ext::putPixelWithoutRefresh(targetSurf, realPos.x, realPos.y + i, color.r, color.g, color.b);
 			}
 		}
 	}

+ 3 - 3
lib/Color.h

@@ -27,7 +27,7 @@ public:
 	uint8_t a;
 
 	//constructors
-	ColorRGBA()
+	constexpr ColorRGBA()
 		:r(0)
 		,g(0)
 		,b(0)
@@ -35,14 +35,14 @@ public:
 	{
 	}
 
-	ColorRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
+	constexpr ColorRGBA(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
 		: r(r)
 		, g(g)
 		, b(b)
 		, a(a)
 	{}
 
-	ColorRGBA(uint8_t r, uint8_t g, uint8_t b)
+	constexpr ColorRGBA(uint8_t r, uint8_t g, uint8_t b)
 		: r(r)
 		, g(g)
 		, b(b)