1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

[animRewrite] * Code clean-up, Bug-Fixing

This commit is contained in:
beegee1 2012-04-21 17:41:47 +00:00
parent 807eca8bee
commit b1c99f447e
8 changed files with 55 additions and 57 deletions

View File

@ -7,27 +7,27 @@
#include "UIFramework/AnimationClasses.h"
IImage * CResourceHandler::getImage(const ResourceIdentifier & identifier, size_t frame, size_t group)
IImage * CResourceHandler::getImage(const std::string & name, size_t frame, size_t group)
{
ResourceLocator loc = CGI->filesystemh->getResourceLocator(identifier);
ResourceLocator loc = CGI->filesystemh->getResourceLocator(ResourceIdentifier(name, EResType::ANIMATION));
return loadImage(loc, frame, group);
}
IImage * CResourceHandler::getImage(const ResourceIdentifier & identifier)
IImage * CResourceHandler::getImage(const std::string & name)
{
ResourceLocator loc = CGI->filesystemh->getResourceLocator(identifier);
ResourceLocator loc = CGI->filesystemh->getResourceLocator(ResourceIdentifier(name, EResType::GRAPHICS));
return loadImage(loc);
}
CSDLImage * CResourceHandler::getSurface(const ResourceIdentifier & identifier)
CSDLImage * CResourceHandler::getSurface(const std::string & name)
{
ResourceLocator loc = CGI->filesystemh->getResourceLocator(identifier);
ResourceLocator loc = CGI->filesystemh->getResourceLocator(ResourceIdentifier(name, EResType::GRAPHICS));
return dynamic_cast<CSDLImage *>(loadImage(loc, -1, -1, true));
}
CSDLImage * CResourceHandler::getSurface(const ResourceIdentifier & identifier, size_t frame, size_t group)
CSDLImage * CResourceHandler::getSurface(const std::string & name, size_t frame, size_t group)
{
ResourceLocator loc = CGI->filesystemh->getResourceLocator(identifier);
ResourceLocator loc = CGI->filesystemh->getResourceLocator(ResourceIdentifier(name, EResType::ANIMATION));
return dynamic_cast<CSDLImage *>(loadImage(loc, frame, group, true));
}
@ -36,6 +36,10 @@ IImage * CResourceHandler::loadImage(const ResourceLocator & loc, size_t frame /
// Load data stream
CMemoryStream * data = CGI->filesystemh->getResource(loc);
// Return NULL if the resource couldn't been loaded.
if (!data)
return NULL;
// Get file info
CFileInfo locInfo(loc.resourceName);
@ -65,15 +69,15 @@ IImage * CResourceHandler::loadImage(const ResourceLocator & loc, size_t frame /
}
}
CAnimationHolder * CResourceHandler::getAnimation(const ResourceIdentifier & identifier)
CAnimationHolder * CResourceHandler::getAnimation(const std::string & name)
{
ResourceLocator loc = CGI->filesystemh->getResourceLocator(identifier);
ResourceLocator loc = CGI->filesystemh->getResourceLocator(ResourceIdentifier(name, EResType::ANIMATION));
return new CAnimationHolder(loadAnimation(loc));
}
CAnimationHolder * CResourceHandler::getAnimation(const ResourceIdentifier & identifier, size_t group)
CAnimationHolder * CResourceHandler::getAnimation(const std::string & name, size_t group)
{
ResourceLocator loc = CGI->filesystemh->getResourceLocator(identifier);
ResourceLocator loc = CGI->filesystemh->getResourceLocator(ResourceIdentifier(name, EResType::ANIMATION));
return new CAnimationHolder(loadAnimation(loc, group));
}
@ -81,6 +85,10 @@ IAnimation * CResourceHandler::loadAnimation(const ResourceLocator & loc, size_t
{
CMemoryStream * data = CGI->filesystemh->getResource(loc);
// Return NULL if the resource couldn't been loaded.
if (!data)
return NULL;
// get file info of the locator
CFileInfo locInfo(loc.resourceName);

View File

@ -26,18 +26,18 @@ class CResourceHandler
public:
// Loads an image.
IImage * getImage(const ResourceIdentifier & identifier);
IImage * getImage(const std::string & name);
// Loads a frame/sprite.
IImage * getImage(const ResourceIdentifier & identifier, size_t frame, size_t group);
IImage * getImage(const std::string & name, size_t frame, size_t group);
CSDLImage * getSurface(const ResourceIdentifier & identifier);
CSDLImage * getSurface(const std::string & name);
CSDLImage * getSurface(const ResourceIdentifier & identifier, size_t frame, size_t group);
CSDLImage * getSurface(const std::string & name, size_t frame, size_t group);
// Loads complete animation(all groups).
CAnimationHolder * getAnimation(const ResourceIdentifier & identifier);
CAnimationHolder * getAnimation(const std::string & name);
// Loads a group of an animation.
CAnimationHolder * getAnimation(const ResourceIdentifier & identifier, size_t group);
CAnimationHolder * getAnimation(const std::string & name, size_t group);
};

View File

@ -136,7 +136,8 @@ void CImageBasedAnimation::recolorToPlayer(int player)
});
}
CCompAnimation::CCompAnimation(const CDefFile * defFile, size_t group /*= -1*/)
CCompAnimation::CCompAnimation(const CDefFile * defFile, size_t group /*= -1*/) : glowType(EGlowAnimationType::NONE),
glowIntensity(0), alpha(255), rotateFlipType(ERotateFlipType::NONE)
{
constructImageBasedAnimation<CCompImage>(defFile, group);
}
@ -155,11 +156,11 @@ void CCompAnimation::applyTransformations(IImage * img) const
void CCompAnimation::setGlowAnimation(EGlowAnimationType::EGlowAnimationType glowType, ui8 intensity)
{
this->glowIntensity = alpha;
this->glowIntensity = intensity;
this->glowType = glowType;
}
void CCompAnimation::setAlpha(float alpha)
void CCompAnimation::setAlpha(ui8 alpha)
{
this->alpha = alpha;
}
@ -473,7 +474,7 @@ void CAnimationHolder::setGlowAnimation(EGlowAnimationType::EGlowAnimationType g
this->glowType = glowType;
}
void CAnimationHolder::setAlpha(float alpha)
void CAnimationHolder::setAlpha(ui8 alpha)
{
anim->setAlpha(alpha);
}

View File

@ -77,7 +77,7 @@ class CCompAnimation : public CImageBasedAnimation
{
EGlowAnimationType::EGlowAnimationType glowType;
ui8 glowIntensity;
float alpha;
ui8 alpha;
ERotateFlipType::ERotateFlipType rotateFlipType;
public:
@ -86,7 +86,7 @@ public:
void applyTransformations(IImage * img) const;
void setGlowAnimation(EGlowAnimationType::EGlowAnimationType glowType, ui8 intensity);
void setAlpha(float alpha);
void setAlpha(ui8 alpha);
void rotateFlip(ERotateFlipType::ERotateFlipType type);
};
@ -153,6 +153,6 @@ public:
void recolorToPlayer(int player);
void setGlowAnimation(EGlowAnimationType::EGlowAnimationType glowType);
void setAlpha(float alpha);
void setAlpha(ui8 alpha);
void rotateFlip(ERotateFlipType::ERotateFlipType type);
};

View File

@ -410,10 +410,11 @@ void CSDLImage::recolorToPlayer(int player)
void CSDLImage::rotateFlip(ERotateFlipType::ERotateFlipType rotateType)
{
//TODO SDL_Ext method names have to be changed. hFlip to vFlip.
if(rotateType == ERotateFlipType::ROTATENONE_FLIPX)
surf = CSDL_Ext::hFlip(surf, true);
else if (rotateType == ERotateFlipType::ROTATENONE_FLIPY)
surf = CSDL_Ext::rotate01(surf, true);
else if (rotateType == ERotateFlipType::ROTATENONE_FLIPY)
surf = CSDL_Ext::hFlip(surf, true);
}
CCompImage::CCompImageLoader::CCompImageLoader(CCompImage * Img) : image(Img), position(NULL), entry(NULL),
@ -598,7 +599,7 @@ CCompImage::CCompImageLoader::~CCompImageLoader()
}
CCompImage::CCompImage(const CDefFile * defFile, size_t frame, size_t group)
: surf(NULL), length(0), line(NULL), palette(NULL), glowPalette(NULL), alpha(0), rotateFlipType(ERotateFlipType::NONE)
: surf(NULL), length(0), line(NULL), palette(NULL), glowPalette(NULL), alpha(255), rotateFlipType(ERotateFlipType::NONE)
{
CCompImageLoader loader(this);
defFile->loadFrame(frame, group, loader);

View File

@ -592,15 +592,17 @@ EResType::EResType CFileSystemHandler::convertFileExtToResType(const std::string
return it->second;
}
CMemoryStream * CFileSystemHandler::getResource(const ResourceIdentifier & identifier, bool fromBegin /*=false */, bool unpackResource /*=false */)
CMemoryStream * CFileSystemHandler::getResource(const ResourceIdentifier & identifier, bool unpackResource /*=false */)
{
ResourceLocator loc = getResourceLocator(identifier, fromBegin);
ResourceLocator loc = getResourceLocator(identifier);
return getResource(loc, unpackResource);
}
CMemoryStream * CFileSystemHandler::getResource(const ResourceLocator & locator, bool unpackResource /*= false*/)
{
CMemoryStream * rslt = NULL;
if (locator.isEmpty())
return rslt;
// load it
mutex->lock();
@ -613,7 +615,7 @@ CMemoryStream * CFileSystemHandler::getResource(const ResourceLocator & locator,
return rslt;
}
ResourceLocator CFileSystemHandler::getResourceLocator(const ResourceIdentifier & identifier, bool fromBegin /*= false*/)
ResourceLocator CFileSystemHandler::getResourceLocator(const ResourceIdentifier & identifier)
{
// check if resource is registered
if(resources.find(identifier) == resources.end())
@ -627,21 +629,19 @@ ResourceLocator CFileSystemHandler::getResourceLocator(const ResourceIdentifier
// and get the latest inserted resource with fromBegin=false
std::list<ResourceLocator> locators = resources.at(identifier);
ResourceLocator loc;
if (!fromBegin)
return locators.back();
else
return locators.front();
return locators.front();
}
std::string CFileSystemHandler::getResourceAsString(const ResourceIdentifier & identifier, bool fromBegin /*=false */)
std::string CFileSystemHandler::getResourceAsString(const ResourceIdentifier & identifier)
{
CMemoryStream * memStream = getResource(identifier, fromBegin);
CMemoryStream * memStream = getResource(identifier);
return memStream->getDataAsString();
}
CMemoryStream * CFileSystemHandler::getUnpackedResource(const ResourceIdentifier & identifier, bool fromBegin /*=false */)
CMemoryStream * CFileSystemHandler::getUnpackedResource(const ResourceIdentifier & identifier)
{
return getResource(identifier, fromBegin, true);
return getResource(identifier, true);
}
//It is possible to use uncompress function from zlib but we need to know decompressed size (not present in compressed data)

View File

@ -229,19 +229,19 @@ public:
// Get a resource as a flat, binary stream(shared) with the given identifier and a flag, whether to load
// resource from LOD/first loaded or last inserted resource
CMemoryStream * getResource(const ResourceIdentifier & identifier, bool fromBegin = false, bool unpackResource = false);
CMemoryStream * getResource(const ResourceIdentifier & identifier, bool unpackResource = false);
CMemoryStream * getResource(const ResourceLocator & locator, bool unpackResource = false);
ResourceLocator getResourceLocator(const ResourceIdentifier & identifier, bool fromBegin = false);
ResourceLocator getResourceLocator(const ResourceIdentifier & identifier);
// Get a resource as a string(not shared, can be easily altered) with the given identifier and a flag,
// whether to load resource from LOD/first loaded or last inserted resource
std::string getResourceAsString(const ResourceIdentifier & identifier, bool fromBegin = false);
std::string getResourceAsString(const ResourceIdentifier & identifier);
// Gets a resource unpacked with the given identifier and a flag,
// whether to load resource from LOD/first loaded or last inserted resource
CMemoryStream * getUnpackedResource(const ResourceIdentifier & identifier, bool fromBegin = false);
CMemoryStream * getUnpackedResource(const ResourceIdentifier & identifier);
void writeMemoryStreamToFile(CMemoryStream * memStream, const std::string & destFile) const;

View File

@ -93,17 +93,5 @@ struct DLL_LINKAGE ResourceLocator
ResourceLocator(IResourceLoader * Loader, const std::string & ResourceName)
: loader(Loader), resourceName(ResourceName) { };
/*inline bool operator==(ResourceLocator const & other) const
{
return loader == other.loader && resourceName == other.resourceName;
}
inline friend std::size_t hash_value(ResourceLocator const & p)
{
std::size_t seed = 0;
boost::hash_combine(seed, p.loader);
boost::hash_combine(seed, p.resourceName);
return seed;
}*/
};
bool isEmpty() const { return loader == NULL || resourceName == ""; }
};