mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
try to use CAnimation for Hero path
This commit is contained in:
parent
8505a909e1
commit
3dddbcf2e8
@ -154,7 +154,7 @@ void init()
|
|||||||
logGlobal->infoStream()<<"Screen handler: "<<pomtime.getDiff();
|
logGlobal->infoStream()<<"Screen handler: "<<pomtime.getDiff();
|
||||||
pomtime.getDiff();
|
pomtime.getDiff();
|
||||||
|
|
||||||
graphics->loadHeroAnims();
|
graphics->load();
|
||||||
logGlobal->infoStream()<<"\tMain graphics: "<<pomtime.getDiff();
|
logGlobal->infoStream()<<"\tMain graphics: "<<pomtime.getDiff();
|
||||||
logGlobal->infoStream()<<"Initializing game graphics: "<<tmh.getDiff();
|
logGlobal->infoStream()<<"Initializing game graphics: "<<tmh.getDiff();
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include "../lib/filesystem/CBinaryReader.h"
|
#include "../lib/filesystem/CBinaryReader.h"
|
||||||
#include "CDefHandler.h"
|
#include "CDefHandler.h"
|
||||||
#include "gui/SDL_Extensions.h"
|
#include "gui/SDL_Extensions.h"
|
||||||
|
#include "gui/CAnimation.h"
|
||||||
#include <SDL_ttf.h>
|
#include <SDL_ttf.h>
|
||||||
#include "../lib/CThreadHelper.h"
|
#include "../lib/CThreadHelper.h"
|
||||||
#include "CGameInfo.h"
|
#include "CGameInfo.h"
|
||||||
@ -145,7 +146,6 @@ Graphics::Graphics()
|
|||||||
tasks += std::bind(&Graphics::loadErmuToPicture,this);
|
tasks += std::bind(&Graphics::loadErmuToPicture,this);
|
||||||
tasks += std::bind(&Graphics::initializeImageLists,this);
|
tasks += std::bind(&Graphics::initializeImageLists,this);
|
||||||
tasks += GET_DEF_ESS(resources32,"RESOURCE.DEF");
|
tasks += GET_DEF_ESS(resources32,"RESOURCE.DEF");
|
||||||
tasks += GET_DEF_ESS(heroMoveArrows,"ADAG.DEF");
|
|
||||||
|
|
||||||
CThreadHelper th(&tasks,std::max((ui32)1,boost::thread::hardware_concurrency()));
|
CThreadHelper th(&tasks,std::max((ui32)1,boost::thread::hardware_concurrency()));
|
||||||
th.run();
|
th.run();
|
||||||
@ -157,13 +157,17 @@ Graphics::Graphics()
|
|||||||
loadErmuToPicture();
|
loadErmuToPicture();
|
||||||
initializeImageLists();
|
initializeImageLists();
|
||||||
resources32 = CDefHandler::giveDefEss("RESOURCE.DEF");
|
resources32 = CDefHandler::giveDefEss("RESOURCE.DEF");
|
||||||
heroMoveArrows = CDefHandler::giveDefEss("ADAG.DEF");
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for(auto & elem : heroMoveArrows->ourImages)
|
//(!) do not load any CAnimation here
|
||||||
{
|
}
|
||||||
CSDL_Ext::alphaTransform(elem.bitmap);
|
|
||||||
}
|
void Graphics::load()
|
||||||
|
{
|
||||||
|
heroMoveArrows = std::make_shared<CAnimation>("ADAG");
|
||||||
|
heroMoveArrows->preload();
|
||||||
|
|
||||||
|
loadHeroAnims();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Graphics::loadHeroAnims()
|
void Graphics::loadHeroAnims()
|
||||||
|
@ -38,20 +38,31 @@ class Graphics
|
|||||||
{
|
{
|
||||||
void addImageListEntry(size_t index, std::string listName, std::string imageName);
|
void addImageListEntry(size_t index, std::string listName, std::string imageName);
|
||||||
|
|
||||||
|
void initializeBattleGraphics();
|
||||||
|
void loadPaletteAndColors();
|
||||||
|
void loadHeroFlags();
|
||||||
|
void loadHeroFlagsDetail(std::pair<std::vector<CDefEssential *> Graphics::*, std::vector<const char *> > &pr, bool mode);
|
||||||
|
void loadHeroAnims();
|
||||||
|
CDefEssential * loadHeroAnim(const std::string &name, const std::vector<std::pair<int,int> > &rotations);
|
||||||
|
void loadErmuToPicture();
|
||||||
|
|
||||||
|
void loadFonts();
|
||||||
|
void initializeImageLists();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//Fonts
|
//Fonts
|
||||||
static const int FONTS_NUMBER = 9;
|
static const int FONTS_NUMBER = 9;
|
||||||
IFont * fonts[FONTS_NUMBER];
|
IFont * fonts[FONTS_NUMBER];
|
||||||
|
|
||||||
//various graphics
|
//various graphics
|
||||||
SDL_Color * playerColors; //array [8]
|
SDL_Color * playerColors; //array [8]
|
||||||
SDL_Color * neutralColor;
|
SDL_Color * neutralColor;
|
||||||
SDL_Color * playerColorPalette; //palette to make interface colors good - array of size [256]
|
SDL_Color * playerColorPalette; //palette to make interface colors good - array of size [256]
|
||||||
SDL_Color * neutralColorPalette;
|
SDL_Color * neutralColorPalette;
|
||||||
|
|
||||||
std::vector<CDefEssential *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,
|
std::vector<CDefEssential *> flags1, flags2, flags3, flags4; //flags blitted on heroes when ,
|
||||||
CDefEssential * resources32; //resources 32x32
|
CDefEssential * resources32; //resources 32x32
|
||||||
CDefEssential * heroMoveArrows;
|
std::shared_ptr<CAnimation> heroMoveArrows;
|
||||||
std::map<std::string, CDefEssential *> heroAnims; // [hero class def name] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
|
std::map<std::string, CDefEssential *> heroAnims; // [hero class def name] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
|
||||||
std::vector<CDefEssential *> boatAnims; // [boat type: 0 - 3] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
|
std::vector<CDefEssential *> boatAnims; // [boat type: 0 - 3] //added group 10: up - left, 11 - left and 12 - left down // 13 - up-left standing; 14 - left standing; 15 - left down standing
|
||||||
CDefHandler * FoWfullHide; //for Fog of War
|
CDefHandler * FoWfullHide; //for Fog of War
|
||||||
@ -68,18 +79,11 @@ public:
|
|||||||
std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type
|
std::vector< std::vector< std::string > > battleBacks; //battleBacks[terType] - vector of possible names for certain terrain type
|
||||||
std::map< int, std::vector < std::string > > battleACToDef; //maps AC format to vector of appropriate def names
|
std::map< int, std::vector < std::string > > battleACToDef; //maps AC format to vector of appropriate def names
|
||||||
//functions
|
//functions
|
||||||
Graphics();
|
Graphics();
|
||||||
void initializeBattleGraphics();
|
|
||||||
void loadPaletteAndColors();
|
|
||||||
void loadHeroFlags();
|
|
||||||
void loadHeroFlagsDetail(std::pair<std::vector<CDefEssential *> Graphics::*, std::vector<const char *> > &pr, bool mode);
|
|
||||||
void loadHeroAnims();
|
|
||||||
CDefEssential * loadHeroAnim(const std::string &name, const std::vector<std::pair<int,int> > &rotations);
|
|
||||||
void loadErmuToPicture();
|
|
||||||
void blueToPlayersAdv(SDL_Surface * sur, PlayerColor player); //replaces blue interface colour with a color of player
|
|
||||||
|
|
||||||
void loadFonts();
|
void load();
|
||||||
void initializeImageLists();
|
|
||||||
|
void blueToPlayersAdv(SDL_Surface * sur, PlayerColor player); //replaces blue interface colour with a color of player
|
||||||
};
|
};
|
||||||
|
|
||||||
extern Graphics * graphics;
|
extern Graphics * graphics;
|
||||||
|
@ -635,6 +635,7 @@ void SDLImage::draw(SDL_Surface *where, int posX, int posY, Rect *src, ui8 rotat
|
|||||||
{
|
{
|
||||||
if (!surf)
|
if (!surf)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Rect sourceRect(margins.x, margins.y, surf->w, surf->h);
|
Rect sourceRect(margins.x, margins.y, surf->w, surf->h);
|
||||||
//TODO: rotation and scaling
|
//TODO: rotation and scaling
|
||||||
if (src)
|
if (src)
|
||||||
@ -1056,7 +1057,8 @@ void CAnimation::printError(size_t frame, size_t group, std::string type) const
|
|||||||
|
|
||||||
CAnimation::CAnimation(std::string Name, bool Compressed):
|
CAnimation::CAnimation(std::string Name, bool Compressed):
|
||||||
name(Name),
|
name(Name),
|
||||||
compressed(Compressed)
|
compressed(Compressed),
|
||||||
|
preloaded(false)
|
||||||
{
|
{
|
||||||
size_t dotPos = name.find_last_of('.');
|
size_t dotPos = name.find_last_of('.');
|
||||||
if ( dotPos!=-1 )
|
if ( dotPos!=-1 )
|
||||||
@ -1069,14 +1071,18 @@ CAnimation::CAnimation(std::string Name, bool Compressed):
|
|||||||
|
|
||||||
CAnimation::CAnimation():
|
CAnimation::CAnimation():
|
||||||
name(""),
|
name(""),
|
||||||
compressed(false)
|
compressed(false),
|
||||||
|
preloaded(false)
|
||||||
{
|
{
|
||||||
init(nullptr);
|
init(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
CAnimation::~CAnimation()
|
CAnimation::~CAnimation()
|
||||||
{
|
{
|
||||||
if (!images.empty())
|
if(preloaded)
|
||||||
|
unload();
|
||||||
|
|
||||||
|
if(!images.empty())
|
||||||
{
|
{
|
||||||
logGlobal->warnStream()<<"Warning: not all frames were unloaded from "<<name;
|
logGlobal->warnStream()<<"Warning: not all frames were unloaded from "<<name;
|
||||||
for (auto & elem : images)
|
for (auto & elem : images)
|
||||||
@ -1126,6 +1132,12 @@ void CAnimation::unload()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CAnimation::preload()
|
||||||
|
{
|
||||||
|
preloaded = true;
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
void CAnimation::loadGroup(size_t group)
|
void CAnimation::loadGroup(size_t group)
|
||||||
{
|
{
|
||||||
CDefFile * file = getFile();
|
CDefFile * file = getFile();
|
||||||
|
@ -169,6 +169,8 @@ private:
|
|||||||
//if true all frames will be stored in compressed (RLE) state
|
//if true all frames will be stored in compressed (RLE) state
|
||||||
const bool compressed;
|
const bool compressed;
|
||||||
|
|
||||||
|
bool preloaded;
|
||||||
|
|
||||||
//loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
|
//loader, will be called by load(), require opened def file for loading from it. Returns true if image is loaded
|
||||||
bool loadFrame(CDefFile * file, size_t frame, size_t group);
|
bool loadFrame(CDefFile * file, size_t frame, size_t group);
|
||||||
|
|
||||||
@ -204,6 +206,7 @@ public:
|
|||||||
//all available frames
|
//all available frames
|
||||||
void load ();
|
void load ();
|
||||||
void unload();
|
void unload();
|
||||||
|
void preload();
|
||||||
|
|
||||||
//all frames from group
|
//all frames from group
|
||||||
void loadGroup (size_t group);
|
void loadGroup (size_t group);
|
||||||
|
@ -778,8 +778,8 @@ void CMapHandler::CMapPuzzleViewBlitter::drawObjects(SDL_Surface * targetSurf, c
|
|||||||
// grail X mark
|
// grail X mark
|
||||||
if(pos.x == info->grailPos.x && pos.y == info->grailPos.y)
|
if(pos.x == info->grailPos.x && pos.y == info->grailPos.y)
|
||||||
{
|
{
|
||||||
Rect destRect(realTileRect);
|
const IImage * mark = graphics->heroMoveArrows->getImage(0);
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(graphics->heroMoveArrows->ourImages[0].bitmap, nullptr, targetSurf, &destRect);
|
mark->draw(targetSurf,realTileRect.x,realTileRect.y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,13 +227,14 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to)
|
|||||||
pn+=25;
|
pn+=25;
|
||||||
if (pn>=0)
|
if (pn>=0)
|
||||||
{
|
{
|
||||||
CDefEssential * arrows = graphics->heroMoveArrows;
|
const IImage * arrow = graphics->heroMoveArrows->getImage(pn);
|
||||||
|
|
||||||
int x = 32*(curPos.x-adventureInt->position.x)+CGI->mh->offsetX + pos.x,
|
int x = 32*(curPos.x-adventureInt->position.x)+CGI->mh->offsetX + pos.x,
|
||||||
y = 32*(curPos.y-adventureInt->position.y)+CGI->mh->offsetY + pos.y;
|
y = 32*(curPos.y-adventureInt->position.y)+CGI->mh->offsetY + pos.y;
|
||||||
if (x< -32 || y< -32 || x>pos.w || y>pos.h)
|
if (x< -32 || y< -32 || x>pos.w || y>pos.h)
|
||||||
continue;
|
continue;
|
||||||
int hvx = (x+arrows->ourImages[pn].bitmap->w)-(pos.x+pos.w),
|
int hvx = (x + arrow->width()) - (pos.x + pos.w),
|
||||||
hvy = (y+arrows->ourImages[pn].bitmap->h)-(pos.y+pos.h);
|
hvy = (y + arrow->height()) - (pos.y + pos.h);
|
||||||
|
|
||||||
SDL_Rect prevClip;
|
SDL_Rect prevClip;
|
||||||
SDL_GetClipRect(to, &prevClip);
|
SDL_GetClipRect(to, &prevClip);
|
||||||
@ -243,52 +244,44 @@ void CTerrainRect::showPath(const SDL_Rect * extRect, SDL_Surface * to)
|
|||||||
{
|
{
|
||||||
if (hvx<0 && hvy<0)
|
if (hvx<0 && hvy<0)
|
||||||
{
|
{
|
||||||
Rect dstRect = genRect(32, 32, x + moveX, y + moveY);
|
arrow->draw(to, x + moveX, y + moveY);
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, nullptr, to, &dstRect);
|
|
||||||
}
|
}
|
||||||
else if(hvx<0)
|
else if(hvx<0)
|
||||||
{
|
{
|
||||||
Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0);
|
Rect srcRect = genRect(arrow->height() - hvy, arrow->width(), 0, 0);
|
||||||
Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x + moveX, y + moveY);
|
arrow->draw(to, x + moveX, y + moveY, &srcRect);
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
|
|
||||||
}
|
}
|
||||||
else if (hvy<0)
|
else if (hvy<0)
|
||||||
{
|
{
|
||||||
Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0);
|
Rect srcRect = genRect(arrow->height(), arrow->width() - hvx, 0, 0);
|
||||||
Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY);
|
arrow->draw(to, x + moveX, y + moveY, &srcRect);
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0);
|
Rect srcRect = genRect(arrow->height() - hvy, arrow->width() - hvx, 0, 0);
|
||||||
Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x + moveX, y + moveY);
|
arrow->draw(to, x + moveX, y + moveY, &srcRect);
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else //standard version
|
else //standard version
|
||||||
{
|
{
|
||||||
if (hvx<0 && hvy<0)
|
if (hvx<0 && hvy<0)
|
||||||
{
|
{
|
||||||
Rect dstRect = genRect(32, 32, x, y);
|
arrow->draw(to, x, y);
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, nullptr, to, &dstRect);
|
|
||||||
}
|
}
|
||||||
else if(hvx<0)
|
else if(hvx<0)
|
||||||
{
|
{
|
||||||
Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, 0, 0);
|
Rect srcRect = genRect(arrow->height() - hvy, arrow->width(), 0, 0);
|
||||||
Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w, x, y);
|
arrow->draw(to, x, y, &srcRect);
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
|
|
||||||
}
|
}
|
||||||
else if (hvy<0)
|
else if (hvy<0)
|
||||||
{
|
{
|
||||||
Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, 0, 0);
|
Rect srcRect = genRect(arrow->height(), arrow->width() - hvx, 0, 0);
|
||||||
Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h, arrows->ourImages[pn].bitmap->w-hvx, x, y);
|
arrow->draw(to, x, y, &srcRect);
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Rect srcRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, 0, 0);
|
Rect srcRect = genRect(arrow->height() - hvy, arrow->width() - hvx, 0, 0);
|
||||||
Rect dstRect = genRect(arrows->ourImages[pn].bitmap->h-hvy, arrows->ourImages[pn].bitmap->w-hvx, x, y);
|
arrow->draw(to, x, y, &srcRect);
|
||||||
CSDL_Ext::blit8bppAlphaTo24bpp(arrows->ourImages[pn].bitmap, &srcRect, to, &dstRect);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_SetClipRect(to, &prevClip);
|
SDL_SetClipRect(to, &prevClip);
|
||||||
|
Loading…
Reference in New Issue
Block a user