2
0
Laserlicht 10 сар өмнө
parent
commit
6795c9afb6

+ 16 - 10
client/mapView/MapRenderer.cpp

@@ -121,15 +121,25 @@ void MapTileStorage::load(size_t index, const AnimationPath & filename, EImageBl
 		terrainAnimations[3]->horizontalFlip();
 }
 
-std::shared_ptr<IImage> MapTileStorage::find(size_t fileIndex, size_t rotationIndex, size_t imageIndex)
+std::shared_ptr<IImage> MapTileStorage::find(size_t fileIndex, size_t rotationIndex, size_t imageIndex, size_t groupIndex)
 {
 	const auto & animation = animations[fileIndex][rotationIndex];
 	if (animation)
-		return animation->getImage(imageIndex); // ask for group
+		return animation->getImage(imageIndex, groupIndex); // ask for group
 	else
 		return nullptr;
 }
 
+int MapTileStorage::groupCount(size_t fileIndex, size_t rotationIndex, size_t imageIndex)
+{
+	const auto & animation = animations[fileIndex][rotationIndex];
+	if (animation)
+		for(int i = 0; true; i++)
+			if(!animation->getImage(imageIndex, i, false))
+				return i;
+	return 1;
+}
+
 MapRendererTerrain::MapRendererTerrain()
 	: storage(VLC->terrainTypeHandler->objects.size())
 {
@@ -147,7 +157,8 @@ void MapRendererTerrain::renderTile(IMapRendererContext & context, Canvas & targ
 	int32_t imageIndex = mapTile.terView;
 	int32_t rotationIndex = mapTile.extTileFlags % 4;
 
-	const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex);
+	int groupCount = storage.groupCount(terrainIndex, rotationIndex, imageIndex);
+	const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex, groupCount > 1 ? context.terrainImageIndex(groupCount) : 0);
 
 	assert(image);
 	if (!image)
@@ -156,9 +167,6 @@ void MapRendererTerrain::renderTile(IMapRendererContext & context, Canvas & targ
 		return;
 	}
 
-	for( auto const & element : mapTile.getTerrain()->paletteAnimation)
-		image->shiftPalette(element.start, element.length, context.terrainImageIndex(element.length));
-
 	target.draw(image, Point(0, 0));
 }
 
@@ -191,10 +199,8 @@ void MapRendererRiver::renderTile(IMapRendererContext & context, Canvas & target
 	int32_t imageIndex = mapTile.riverDir;
 	int32_t rotationIndex = (mapTile.extTileFlags >> 2) % 4;
 
-	const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex);
-
-	for( auto const & element : mapTile.getRiver()->paletteAnimation)
-		image->shiftPalette(element.start, element.length, context.terrainImageIndex(element.length));
+	int groupCount = storage.groupCount(terrainIndex, rotationIndex, imageIndex);
+	const auto & image = storage.find(terrainIndex, rotationIndex, imageIndex, groupCount > 1 ? context.terrainImageIndex(groupCount) : 0);
 
 	target.draw(image, Point(0, 0));
 }

+ 2 - 1
client/mapView/MapRenderer.h

@@ -33,7 +33,8 @@ class MapTileStorage
 public:
 	explicit MapTileStorage(size_t capacity);
 	void load(size_t index, const AnimationPath & filename, EImageBlitMode blitMode);
-	std::shared_ptr<IImage> find(size_t fileIndex, size_t rotationIndex, size_t imageIndex);
+	std::shared_ptr<IImage> find(size_t fileIndex, size_t rotationIndex, size_t imageIndex, size_t groupIndex = 0);
+	int groupCount(size_t fileIndex, size_t rotationIndex, size_t imageIndex);
 };
 
 class MapRendererTerrain

+ 1 - 0
client/render/AssetGenerator.cpp

@@ -409,6 +409,7 @@ void AssetGenerator::createPaletteShiftedSprites()
 						img->shiftPalette(tmp.start, tmp.length, l % tmp.length);
 					}
 				}
+				
 				Canvas canvas = Canvas(Point(32, 32), CanvasScalingPolicy::IGNORE);
 				canvas.draw(img, Point((32 - img->dimensions().x) / 2, (32 - img->dimensions().y) / 2));
 				std::shared_ptr<IImage> image = GH.renderHandler().createImage(canvas.getInternalSurface());

+ 4 - 3
client/render/CAnimation.cpp

@@ -18,11 +18,12 @@
 #include "../../lib/filesystem/Filesystem.h"
 #include "../../lib/json/JsonUtils.h"
 
-bool CAnimation::loadFrame(size_t frame, size_t group)
+bool CAnimation::loadFrame(size_t frame, size_t group, bool verbose)
 {
 	if(size(group) <= frame)
 	{
-		printError(frame, group, "LoadFrame");
+		if(verbose)
+			printError(frame, group, "LoadFrame");
 		return false;
 	}
 
@@ -119,7 +120,7 @@ void CAnimation::duplicateImage(const size_t sourceGroup, const size_t sourceFra
 
 std::shared_ptr<IImage> CAnimation::getImage(size_t frame, size_t group, bool verbose)
 {
-	if (!loadFrame(frame, group))
+	if (!loadFrame(frame, group, verbose))
 		return nullptr;
 	return getImageImpl(frame, group, verbose);
 }

+ 1 - 1
client/render/CAnimation.h

@@ -41,7 +41,7 @@ private:
 	PlayerColor player = PlayerColor::CANNOT_DETERMINE;
 
 	//loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
-	bool loadFrame(size_t frame, size_t group);
+	bool loadFrame(size_t frame, size_t group, bool verbose = true);
 
 	//unloadFrame, returns true if image has been unloaded ( either deleted or decreased refCount)
 	bool unloadFrame(size_t frame, size_t group);