Преглед на файлове

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 години
родител
ревизия
3cf303f1c7
променени са 2 файла, в които са добавени 7 реда и са изтрити 6 реда
  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/CGHeroInstance.h"
 #include "../../lib/mapObjects/CObjectClassesHandler.h"
 #include "../../lib/mapObjects/CObjectClassesHandler.h"
 #include "../../lib/mapping/CMap.h"
 #include "../../lib/mapping/CMap.h"
+#include "../../lib/Color.h"
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CConfigHandler.h"
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/CStopWatch.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)
 			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 &&
 				if (realPos.y >= info->drawBounds.y &&
 					realPos.y < info->drawBounds.y + info->drawBounds.h)
 					realPos.y < info->drawBounds.y + info->drawBounds.h)
 					for(int i = 0; i < tileSize; i++)
 					for(int i = 0; i < tileSize; i++)
 						if (realPos.x + i >= info->drawBounds.x &&
 						if (realPos.x + i >= info->drawBounds.x &&
 							realPos.x + i < info->drawBounds.x + info->drawBounds.w)
 							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 &&
 				if (realPos.x >= info->drawBounds.x &&
 					realPos.x < info->drawBounds.x + info->drawBounds.w)
 					realPos.x < info->drawBounds.x + info->drawBounds.w)
 					for(int i = 0; i < tileSize; i++)
 					for(int i = 0; i < tileSize; i++)
 						if (realPos.y + i >= info->drawBounds.y &&
 						if (realPos.y + i >= info->drawBounds.y &&
 							realPos.y + i < info->drawBounds.y + info->drawBounds.h)
 							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;
 	uint8_t a;
 
 
 	//constructors
 	//constructors
-	ColorRGBA()
+	constexpr ColorRGBA()
 		:r(0)
 		:r(0)
 		,g(0)
 		,g(0)
 		,b(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)
 		: r(r)
 		, g(g)
 		, g(g)
 		, b(b)
 		, b(b)
 		, a(a)
 		, 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)
 		: r(r)
 		, g(g)
 		, g(g)
 		, b(b)
 		, b(b)