Ver Fonte

Fade-in fixes;
Added more map object fading cases (teleports/(dis)embarking)

Fay há 10 anos atrás
pai
commit
447c4603a2

+ 2 - 2
client/NetPacksClient.cpp

@@ -367,7 +367,7 @@ void TryMoveHero::applyFirstCl( CClient *cl )
 	}
 
 	if(result == TELEPORTATION  ||  result == EMBARK  ||  result == DISEMBARK  ||  !humanKnows)
-		CGI->mh->removeObject(h);
+		CGI->mh->removeObject(h, result == EMBARK && humanKnows);
 
 
 	if(result == DISEMBARK)
@@ -381,7 +381,7 @@ void TryMoveHero::applyCl( CClient *cl )
 
 	if(result == TELEPORTATION  ||  result == EMBARK  ||  result == DISEMBARK)
 	{
-		CGI->mh->printObject(h);
+		CGI->mh->printObject(h, result == DISEMBARK);
 	}
 
 	if(result == EMBARK)

+ 19 - 46
client/mapHandler.cpp

@@ -814,20 +814,20 @@ void CMapHandler::CMapBlitter::drawObjects(SDL_Surface * targetSurf, const Terra
 	{
 		if (object.fadeAnimKey >= 0)
 		{
-			// this object is currently fading, so skip normal drawing
 			// TODO fading heroes/boats will not be drawn correctly this way
 			
 			auto fadeIter = parent->fadeAnims.find(object.fadeAnimKey);
 			if (fadeIter != parent->fadeAnims.end())
 			{
+				// this object is currently fading, so skip normal drawing
 				Rect r1(object.rect);
 				r1.w = tileSize;
 				r1.h = tileSize;
 				Rect r2(realTileRect);
 				CFadeAnimation * fade = (*fadeIter).second.second;
 				fade->draw(targetSurf, &r1, &r2);
+				continue;
 			}
-			continue;
 		}
 		
 		const CGObjectInstance * obj = object.obj;
@@ -1175,58 +1175,31 @@ bool CMapHandler::updateObjectsFade()
 		CFadeAnimation * anim = (*iter).second.second;
 		
 		anim->update();
+		
 		if (anim->isFading())
 			++iter;
-		else
+		else // fade finished
 		{
-			auto &objs = ttiles[pos.x][pos.y][pos.z].objects;
-			for (auto objIter = objs.begin(); objIter != objs.end(); ++objIter)
+			
+			if (anim->fadingMode == CFadeAnimation::EMode::OUT)
 			{
-				if ((*objIter).fadeAnimKey == (*iter).first)
+				auto &objs = ttiles[pos.x][pos.y][pos.z].objects;
+				for (auto objIter = objs.begin(); objIter != objs.end(); ++objIter)
 				{
-					objs.erase(objIter);
-					break;
+					if ((*objIter).fadeAnimKey == (*iter).first)
+					{						
+						if (anim->fadingMode == CFadeAnimation::EMode::OUT)
+							objs.erase(objIter); // if this was fadeout, remove the object from the map
+						else
+							(*objIter).fadeAnimKey = -1; // for fadein, just remove its connection to the finished fade
+						break;
+					}
 				}
 			}
 			iter = fadeAnims.erase(iter);
 		}
 	}
-	// TODO caching fading objects indices for optimization?
-//	for (size_t i=0; i<map->width; i++)
-//	{
-//		for (size_t j=0; j<map->height; j++)
-//		{
-//			for (size_t k=0; k<(map->twoLevel ? 2 : 1); k++)
-//			{
-//				for(size_t x=0; x < ttiles[i][j][k].objects.size(); )
-//				{
-//					auto &obj = ttiles[i][j][k].objects[x];
-					
-//					if (obj.fadeAnimKey >= 0)
-//					{
-//						auto fadeAnimIter = fadeAnims.find(obj.fadeAnimKey);
-//						if (fadeAnimIter == fadeAnims.end())
-//						{
-//							obj.fadeAnimKey = -1;
-//							++x;
-//							continue;
-//						}
-						
-//						obj.fadeAnim->update();
-//						if (obj.fadeAnim->isFading())
-//						{
-//							anyObjectsStillFading = true;
-//							++x;
-//						}
-//						else if (obj.fadeAnim->fadingMode == CFadeAnimation::EMode::OUT)
-//							ttiles[i][j][k].objects.erase(ttiles[i][j][k].objects.begin() + x);
-//					}
-//					else
-//						++x;
-//				}
-//			}
-//		}
-//	}
+	
 	return !fadeAnims.empty();
 }
 
@@ -1316,9 +1289,9 @@ bool CMapHandler::hideObject(const CGObjectInstance *obj, bool fadeout /* = fals
 	}
 	return true;
 }
-bool CMapHandler::removeObject(CGObjectInstance *obj)
+bool CMapHandler::removeObject(CGObjectInstance *obj, bool fadeout /* = false */)
 {
-	hideObject(obj);
+	hideObject(obj, fadeout);
 	return true;
 }
 

+ 1 - 1
client/mapHandler.h

@@ -351,7 +351,7 @@ public:
 	CGObjectInstance * createObject(int id, int subid, int3 pos, int owner=254); //creates a new object with a certain id and subid
 	bool printObject(const CGObjectInstance * obj, bool fadein = false); //puts appropriate things to ttiles, so obj will be visible on map
 	bool hideObject(const CGObjectInstance * obj, bool fadeout = false); //removes appropriate things from ttiles, so obj will be no longer visible on map (but still will exist)
-	bool removeObject(CGObjectInstance * obj); //removes object from each place in VCMI (I hope)
+	bool removeObject(CGObjectInstance * obj, bool fadeout = false); //removes object from each place in VCMI (I hope)
 	void init();
 	void calculateBlockedPos();
 	void initObjectRects();

+ 2 - 11
client/windows/CAdvmapInterface.cpp

@@ -320,15 +320,7 @@ void CTerrainRect::showAnim(SDL_Surface * to)
 	if (fadeAnim->isFading())
 		show(to);
 	else if (lastRedrawStatus == EMapAnimRedrawStatus::REDRAW_REQUESTED)
-	{
-		MapDrawingInfo info(adventureInt->position, &LOCPLINT->cb->getVisibilityMap(), &pos);
-		info.otherheroAnim = true;
-		info.anim = adventureInt->anim;
-		info.heroAnim = adventureInt->heroAnim;
-		if (ADVOPT.smoothMove)
-			info.movement = int3(moveX, moveY, 0);
-		lastRedrawStatus = CGI->mh->drawTerrainRectNew(to, &info, true);
-	}		
+		show(to); // currently the same; maybe we should pass some flag to map handler so it redraws ONLY tiles that need redraw instead of full
 }
 
 int3 CTerrainRect::whichTileIsIt(const int & x, const int & y)
@@ -988,9 +980,8 @@ void CAdvMapInt::centerOn(int3 on, bool fadeIfZChanged /* = false */)
 {
 	bool switchedLevels = on.z != position.z;
 	
-	if (switchedLevels && fadeIfZChanged)
+	if (fadeIfZChanged)
 	{
-		logGlobal->warnStream() << "START FADING";
 		terrain.fadeFromCurrentView();
 	}