mirror of
https://github.com/vcmi/vcmi.git
synced 2025-08-13 19:54:17 +02:00
Working version of image caching
This commit is contained in:
@@ -34,8 +34,8 @@ public:
|
||||
/// returns true if chosen coordinates exist on map
|
||||
virtual bool isInMap(const int3 & coordinates) const = 0;
|
||||
|
||||
// /// returns true if selected tile has animation and should not be cached
|
||||
// virtual bool tileAnimated(const int3 & coordinates) const = 0;
|
||||
/// returns true if selected tile has animation and should not be cached
|
||||
virtual bool tileAnimated(const int3 & coordinates) const = 0;
|
||||
|
||||
/// returns tile by selected coordinates. Coordinates MUST be valid
|
||||
virtual const TerrainTile & getMapTile(const int3 & coordinates) const = 0;
|
||||
|
@@ -396,8 +396,10 @@ std::shared_ptr<CAnimation> MapRendererObjects::getBaseAnimation(const CGObjectI
|
||||
|
||||
std::shared_ptr<CAnimation> MapRendererObjects::getAnimation(const std::string & filename, bool generateMovementGroups)
|
||||
{
|
||||
if(animations.count(filename))
|
||||
return animations[filename];
|
||||
auto it = animations.find(filename);
|
||||
|
||||
if(it != animations.end())
|
||||
return it->second;
|
||||
|
||||
auto ret = std::make_shared<CAnimation>(filename);
|
||||
animations[filename] = ret;
|
||||
|
@@ -69,7 +69,7 @@ public:
|
||||
|
||||
class MapRendererObjects
|
||||
{
|
||||
std::map<std::string, std::shared_ptr<CAnimation>> animations;
|
||||
std::unordered_map<std::string, std::shared_ptr<CAnimation>> animations;
|
||||
|
||||
std::shared_ptr<CAnimation> getBaseAnimation(const CGObjectInstance * obj);
|
||||
std::shared_ptr<CAnimation> getFlagAnimation(const CGObjectInstance * obj);
|
||||
|
@@ -16,15 +16,8 @@
|
||||
#include "../CGameInfo.h"
|
||||
#include "../CPlayerInterface.h"
|
||||
#include "../adventureMap/CAdvMapInt.h"
|
||||
//#include "../gui/CGuiHandler.h"
|
||||
//#include "../render/CAnimation.h"
|
||||
//#include "../render/Canvas.h"
|
||||
//#include "../render/IImage.h"
|
||||
//#include "../renderSDL/SDL_Extensions.h"
|
||||
//
|
||||
#include "../../CCallback.h"
|
||||
|
||||
#include "../../lib/CConfigHandler.h"
|
||||
#include "../../lib/mapObjects/CGHeroInstance.h"
|
||||
#include "../../lib/mapping/CMap.h"
|
||||
|
||||
@@ -66,9 +59,9 @@ const CGObjectInstance * MapRendererContext::getObject(ObjectInstanceID objectID
|
||||
|
||||
bool MapRendererContext::isVisible(const int3 & coordinates) const
|
||||
{
|
||||
if (showAllTerrain)
|
||||
if (settingsSessionSpectate || showAllTerrain)
|
||||
return LOCPLINT->cb->isInTheMap(coordinates);
|
||||
return LOCPLINT->cb->isVisible(coordinates) || settings["session"]["spectate"].Bool();
|
||||
return LOCPLINT->cb->isVisible(coordinates);
|
||||
}
|
||||
|
||||
const CGPath * MapRendererContext::currentPath() const
|
||||
@@ -90,7 +83,7 @@ size_t MapRendererContext::objectImageIndex(ObjectInstanceID objectID, size_t gr
|
||||
if(groupSize == 0)
|
||||
return 0;
|
||||
|
||||
if (!settings["adventure"]["objectAnimation"].Bool())
|
||||
if (!settingsAdventureObjectAnimation)
|
||||
return 0;
|
||||
|
||||
// H3 timing for adventure map objects animation is 180 ms
|
||||
@@ -109,7 +102,7 @@ size_t MapRendererContext::objectImageIndex(ObjectInstanceID objectID, size_t gr
|
||||
|
||||
size_t MapRendererContext::terrainImageIndex(size_t groupSize) const
|
||||
{
|
||||
if (!settings["adventure"]["terrainAnimation"].Bool())
|
||||
if (!settingsAdventureTerrainAnimation)
|
||||
return 0;
|
||||
|
||||
size_t baseFrameTime = 180;
|
||||
@@ -118,10 +111,33 @@ size_t MapRendererContext::terrainImageIndex(size_t groupSize) const
|
||||
return frameIndex;
|
||||
}
|
||||
|
||||
//Point MapRendererContext::getTileSize() const
|
||||
//{
|
||||
// return Point(32, 32);
|
||||
//}
|
||||
bool MapRendererContext::tileAnimated(const int3 & coordinates) const
|
||||
{
|
||||
if(movementAnimation)
|
||||
{
|
||||
auto objects = getObjects(coordinates);
|
||||
|
||||
if(vstd::contains(objects, movementAnimation->target))
|
||||
return true;
|
||||
}
|
||||
|
||||
if(fadeInAnimation)
|
||||
{
|
||||
auto objects = getObjects(coordinates);
|
||||
|
||||
if(vstd::contains(objects, fadeInAnimation->target))
|
||||
return true;
|
||||
}
|
||||
|
||||
if(fadeOutAnimation)
|
||||
{
|
||||
auto objects = getObjects(coordinates);
|
||||
|
||||
if(vstd::contains(objects, fadeOutAnimation->target))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MapRendererContext::showOverlay() const
|
||||
{
|
||||
@@ -130,17 +146,21 @@ bool MapRendererContext::showOverlay() const
|
||||
|
||||
bool MapRendererContext::showGrid() const
|
||||
{
|
||||
<<<<<<< HEAD
|
||||
return settings["gameTweaks"]["showGrid"].Bool();
|
||||
=======
|
||||
return settingsSessionShowGrid;
|
||||
>>>>>>> 9a847b520 (Working version of image caching)
|
||||
}
|
||||
|
||||
bool MapRendererContext::showVisitable() const
|
||||
{
|
||||
return settings["session"]["showVisitable"].Bool();
|
||||
return settingsSessionShowVisitable;
|
||||
}
|
||||
|
||||
bool MapRendererContext::showBlockable() const
|
||||
{
|
||||
return settings["session"]["showBlockable"].Bool();
|
||||
return settingsSessionShowBlockable;
|
||||
}
|
||||
|
||||
MapRendererContext::MapRendererContext()
|
||||
|
@@ -76,7 +76,6 @@ class MapRendererContext : public IMapRendererContext
|
||||
|
||||
boost::multi_array<MapObjectsList, 3> objects;
|
||||
|
||||
//Point tileSize = Point(32, 32);
|
||||
uint32_t animationTime = 0;
|
||||
|
||||
boost::optional<HeroAnimationState> movementAnimation;
|
||||
@@ -89,6 +88,12 @@ class MapRendererContext : public IMapRendererContext
|
||||
|
||||
bool worldViewModeActive = false;
|
||||
bool showAllTerrain = false;
|
||||
bool settingsSessionSpectate = false;
|
||||
bool settingsAdventureObjectAnimation = true;
|
||||
bool settingsAdventureTerrainAnimation = true;
|
||||
bool settingsSessionShowGrid = false;
|
||||
bool settingsSessionShowVisitable = false;
|
||||
bool settingsSessionShowBlockable = false;
|
||||
|
||||
size_t selectOverlayImageForObject(const ObjectPosInfo & objectID) const;
|
||||
|
||||
@@ -102,6 +107,7 @@ public:
|
||||
int3 getMapSize() const final;
|
||||
bool isInMap(const int3 & coordinates) const final;
|
||||
bool isVisible(const int3 & coordinates) const override;
|
||||
bool tileAnimated(const int3 & coordinates) const override;
|
||||
|
||||
const TerrainTile & getMapTile(const int3 & coordinates) const override;
|
||||
const MapObjectsList & getObjects(const int3 & coordinates) const override;
|
||||
@@ -114,7 +120,6 @@ public:
|
||||
size_t objectImageIndex(ObjectInstanceID objectID, size_t groupSize) const override;
|
||||
size_t terrainImageIndex(size_t groupSize) const override;
|
||||
size_t overlayImageIndex(const int3 & coordinates) const override;
|
||||
// Point getTileSize() const override;
|
||||
|
||||
bool showOverlay() const override;
|
||||
bool showGrid() const override;
|
||||
|
@@ -130,11 +130,11 @@ void MapViewCache::render(const std::shared_ptr<const IMapRendererContext> & con
|
||||
{
|
||||
int cacheX = (terrainChecksum.shape()[0] + x) % terrainChecksum.shape()[0];
|
||||
int cacheY = (terrainChecksum.shape()[1] + y) % terrainChecksum.shape()[1];
|
||||
int3 tile(x, y, model->getLevel());
|
||||
|
||||
if (lazyUpdate && tilesUpToDate[cacheX][cacheY])
|
||||
if(lazyUpdate && tilesUpToDate[cacheX][cacheY] && !context->tileAnimated(tile))
|
||||
continue;
|
||||
|
||||
int3 tile(x, y, model->getLevel());
|
||||
Canvas source = getTile(tile);
|
||||
Rect targetRect = model->getTargetTileArea(tile);
|
||||
target.draw(source, targetRect.topLeft());
|
||||
|
@@ -115,8 +115,14 @@ void MapViewController::update(uint32_t timeDelta)
|
||||
}
|
||||
|
||||
context->animationTime += timeDelta;
|
||||
//context->tileSize = Point(32,32); //model->getSingleTileSize();
|
||||
context->worldViewModeActive = model->getSingleTileSize() != Point(32,32);
|
||||
|
||||
context->settingsSessionSpectate = settings["session"]["spectate"].Bool();
|
||||
context->settingsAdventureObjectAnimation = settings["adventure"]["objectAnimation"].Bool();
|
||||
context->settingsAdventureTerrainAnimation = settings["adventure"]["terrainAnimation"].Bool();
|
||||
context->settingsSessionShowGrid = settings["gameTweaks"]["showGrid"].Bool();
|
||||
context->settingsSessionShowVisitable = settings["session"]["showVisitable"].Bool();
|
||||
context->settingsSessionShowBlockable = settings["session"]["showBlockable"].Bool();
|
||||
}
|
||||
|
||||
void MapViewController::onObjectFadeIn(const CGObjectInstance * obj)
|
||||
|
Reference in New Issue
Block a user