浏览代码

Separated timer updates from rendering in adventure map and town screen

Ivan Savenko 2 年之前
父节点
当前提交
fa496628f2

+ 8 - 5
client/mapView/MapView.cpp

@@ -55,6 +55,8 @@ BasicMapView::BasicMapView(const Point & offset, const Point & dimensions)
 	pos += offset;
 	pos.w = dimensions.x;
 	pos.h = dimensions.y;
+
+	addUsedEvents(TIME);
 }
 
 void BasicMapView::render(Canvas & target, bool fullUpdate)
@@ -64,21 +66,22 @@ void BasicMapView::render(Canvas & target, bool fullUpdate)
 	tilesCache->render(controller->getContext(), targetClipped, fullUpdate);
 }
 
-void BasicMapView::show(SDL_Surface * to)
+void BasicMapView::tick(uint32_t msPassed)
 {
-	controller->updateBefore(GH.getFrameDeltaMilliseconds());
+	controller->tick(msPassed);
+}
 
+void BasicMapView::show(SDL_Surface * to)
+{
 	Canvas target(to);
 	CSDL_Ext::CClipRectGuard guard(to, pos);
 	render(target, false);
 
-	controller->updateAfter(GH.getFrameDeltaMilliseconds());
+	controller->afterRender();
 }
 
 void BasicMapView::showAll(SDL_Surface * to)
 {
-	controller->updateBefore(0);
-
 	Canvas target(to);
 	CSDL_Ext::CClipRectGuard guard(to, pos);
 	render(target, true);

+ 1 - 0
client/mapView/MapView.h

@@ -37,6 +37,7 @@ public:
 	BasicMapView(const Point & offset, const Point & dimensions);
 	~BasicMapView() override;
 
+	void tick(uint32_t msPassed) override;
 	void show(SDL_Surface * to) override;
 	void showAll(SDL_Surface * to) override;
 };

+ 2 - 2
client/mapView/MapViewController.cpp

@@ -89,7 +89,7 @@ std::shared_ptr<IMapRendererContext> MapViewController::getContext() const
 	return context;
 }
 
-void MapViewController::updateBefore(uint32_t timeDelta)
+void MapViewController::tick(uint32_t timeDelta)
 {
 	// confirmed to match H3 for
 	// - hero embarking on boat (500 ms)
@@ -158,7 +158,7 @@ void MapViewController::updateBefore(uint32_t timeDelta)
 	}
 }
 
-void MapViewController::updateAfter(uint32_t timeDelta)
+void MapViewController::afterRender()
 {
 	if(movementContext)
 	{

+ 2 - 2
client/mapView/MapViewController.h

@@ -83,8 +83,8 @@ public:
 	void setViewCenter(const int3 & position);
 	void setViewCenter(const Point & position, int level);
 	void setTileSize(const Point & tileSize);
-	void updateBefore(uint32_t timeDelta);
-	void updateAfter(uint32_t timeDelta);
+	void tick(uint32_t timePassed);
+	void afterRender();
 
 	void activateAdventureContext(uint32_t animationTime);
 	void activateAdventureContext();

+ 6 - 1
client/widgets/Images.cpp

@@ -320,6 +320,8 @@ CShowableAnim::CShowableAnim(int x, int y, std::string name, ui8 Flags, ui32 fra
 	pos.h = anim->getImage(0, group)->height();
 	pos.x+= x;
 	pos.y+= y;
+
+	addUsedEvents(TIME);
 }
 
 CShowableAnim::~CShowableAnim()
@@ -391,11 +393,14 @@ void CShowableAnim::show(SDL_Surface * to)
 	if ( flags & BASE )// && frame != first) // FIXME: results in graphical glytch in Fortress, upgraded hydra's dwelling
 		blitImage(first, group, to);
 	blitImage(frame, group, to);
+}
 
+void CShowableAnim::tick(uint32_t msPassed)
+{
 	if ((flags & PLAY_ONCE) && frame + 1 == last)
 		return;
 
-	frameTimePassed += GH.getFrameDeltaMilliseconds();
+	frameTimePassed += msPassed;
 
 	if(frameTimePassed >= frameTimeTotal)
 	{

+ 1 - 0
client/widgets/Images.h

@@ -190,6 +190,7 @@ public:
 	//show current frame and increase counter
 	void show(SDL_Surface * to) override;
 	void showAll(SDL_Surface * to) override;
+	void tick(uint32_t msPassed) override;
 };
 
 /// Creature-dependend animations like attacking, moving,...

+ 6 - 3
client/windows/CCastleInterface.cpp

@@ -68,7 +68,7 @@ CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town
 	  area(nullptr),
 	  stateTimeCounter(BUILD_ANIMATION_FINISHED_TIMEPOINT)
 {
-	addUsedEvents(LCLICK | RCLICK | HOVER);
+	addUsedEvents(LCLICK | RCLICK | HOVER | TIME);
 	pos.x += str->pos.x;
 	pos.y += str->pos.y;
 
@@ -203,9 +203,12 @@ void CBuildingRect::show(SDL_Surface * to)
 
 		border->draw(to, pos.x, pos.y);
 	}
+}
 
-	if(stateTimeCounter < BUILD_ANIMATION_FINISHED_TIMEPOINT)
-		stateTimeCounter += GH.getFrameDeltaMilliseconds();
+void CBuildingRect::tick(uint32_t msPassed)
+{
+	CShowableAnim::tick(msPassed);
+	stateTimeCounter += msPassed;
 }
 
 void CBuildingRect::showAll(SDL_Surface * to)

+ 1 - 0
client/windows/CCastleInterface.h

@@ -69,6 +69,7 @@ public:
 	void clickLeft(tribool down, bool previousState) override;
 	void clickRight(tribool down, bool previousState) override;
 	void mouseMoved (const Point & cursorPosition) override;
+	void tick(uint32_t msPassed) override;
 	void show(SDL_Surface * to) override;
 	void showAll(SDL_Surface * to) override;
 };