2011-12-14 00:23:17 +03:00
|
|
|
#include "StdInc.h"
|
2008-08-04 12:05:52 +03:00
|
|
|
#include "SDL.h"
|
|
|
|
#include "CDefHandler.h"
|
2011-12-14 00:23:17 +03:00
|
|
|
|
2013-07-28 17:49:50 +03:00
|
|
|
#include "../lib/filesystem/Filesystem.h"
|
2009-05-09 19:18:27 +03:00
|
|
|
#include "../lib/VCMI_Lib.h"
|
2010-12-20 23:22:53 +02:00
|
|
|
#include "CBitmapHandler.h"
|
2014-05-23 13:51:38 +03:00
|
|
|
#include "gui/SDL_Extensions.h"
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CDefHandler.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-10-31 00:53:41 +03:00
|
|
|
#ifdef unused
|
2009-05-24 01:57:39 +03:00
|
|
|
static long long pow(long long a, int b)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
|
|
|
if (!b) return 1;
|
|
|
|
long c = a;
|
|
|
|
while (--b)
|
|
|
|
a*=c;
|
|
|
|
return a;
|
|
|
|
}
|
2010-10-31 00:53:41 +03:00
|
|
|
#endif
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
CDefHandler::CDefHandler()
|
|
|
|
{
|
|
|
|
notFreeImgs = false;
|
|
|
|
}
|
|
|
|
CDefHandler::~CDefHandler()
|
|
|
|
{
|
|
|
|
if (notFreeImgs)
|
|
|
|
return;
|
2013-06-29 16:05:48 +03:00
|
|
|
for (auto & elem : ourImages)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
if (elem.bitmap)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
SDL_FreeSurface(elem.bitmap);
|
|
|
|
elem.bitmap=nullptr;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CDefEssential::~CDefEssential()
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : ourImages)
|
|
|
|
SDL_FreeSurface(elem.bitmap);
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
void CDefHandler::openFromMemory(ui8 *table, const std::string & name)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
SDL_Color palette[256];
|
2009-10-14 15:44:44 +03:00
|
|
|
SDefEntry &de = * reinterpret_cast<SDefEntry *>(table);
|
2011-12-14 00:23:17 +03:00
|
|
|
ui8 *p;
|
2009-10-11 21:26:36 +03:00
|
|
|
|
|
|
|
defName = name;
|
2013-02-05 22:56:28 +03:00
|
|
|
DEFType = read_le_u32(&de.DEFType);
|
|
|
|
width = read_le_u32(&de.width);
|
|
|
|
height = read_le_u32(&de.height);
|
|
|
|
ui32 totalBlocks = read_le_u32(&de.totalBlocks);
|
2009-10-11 21:26:36 +03:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
for (ui32 it=0;it<256;it++)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2013-07-06 19:10:20 +03:00
|
|
|
palette[it].r = de.palette[it].R;
|
|
|
|
palette[it].g = de.palette[it].G;
|
|
|
|
palette[it].b = de.palette[it].B;
|
2014-05-23 13:51:38 +03:00
|
|
|
CSDL_Ext::colorSetAlpha(palette[it],SDL_ALPHA_OPAQUE);
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
2009-10-11 21:26:36 +03:00
|
|
|
|
2009-10-16 17:56:57 +03:00
|
|
|
// The SDefEntryBlock starts just after the SDefEntry
|
2011-12-14 00:23:17 +03:00
|
|
|
p = reinterpret_cast<ui8 *>(&de);
|
2009-10-16 17:56:57 +03:00
|
|
|
p += sizeof(de);
|
|
|
|
|
2009-10-25 16:36:11 +02:00
|
|
|
int totalEntries=0;
|
2011-12-14 00:23:17 +03:00
|
|
|
for (ui32 z=0; z<totalBlocks; z++)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2009-10-14 15:44:44 +03:00
|
|
|
SDefEntryBlock &block = * reinterpret_cast<SDefEntryBlock *>(p);
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 totalInBlock;
|
2009-10-11 21:26:36 +03:00
|
|
|
|
2011-10-08 04:23:46 +03:00
|
|
|
totalInBlock = read_le_u32(&block.totalInBlock);
|
2009-10-11 21:26:36 +03:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
for (ui32 j=SEntries.size(); j<totalEntries+totalInBlock; j++)
|
2008-08-04 12:05:52 +03:00
|
|
|
SEntries.push_back(SEntry());
|
2009-10-11 21:26:36 +03:00
|
|
|
|
|
|
|
p = block.data;
|
2011-12-14 00:23:17 +03:00
|
|
|
for (ui32 j=0; j<totalInBlock; j++)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2009-08-19 08:00:59 +03:00
|
|
|
char Buffer[13];
|
2009-10-11 21:26:36 +03:00
|
|
|
memcpy(Buffer, p, 12);
|
2009-08-19 08:00:59 +03:00
|
|
|
Buffer[12] = 0;
|
2008-08-04 12:05:52 +03:00
|
|
|
SEntries[totalEntries+j].name=Buffer;
|
2009-10-11 21:26:36 +03:00
|
|
|
p += 13;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
2011-12-14 00:23:17 +03:00
|
|
|
for (ui32 j=0; j<totalInBlock; j++)
|
2012-02-16 20:10:58 +03:00
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
SEntries[totalEntries+j].offset = read_le_u32(p);
|
2010-02-11 07:25:17 +02:00
|
|
|
p += 4;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
//totalEntries+=totalInBlock;
|
2011-12-14 00:23:17 +03:00
|
|
|
for(ui32 hh=0; hh<totalInBlock; ++hh)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
|
|
|
SEntries[totalEntries].group = z;
|
|
|
|
++totalEntries;
|
|
|
|
}
|
|
|
|
}
|
2009-10-11 21:26:36 +03:00
|
|
|
|
2013-06-29 16:05:48 +03:00
|
|
|
for(auto & elem : SEntries)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
elem.name = elem.name.substr(0, elem.name.find('.')+4);
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
2011-12-14 00:23:17 +03:00
|
|
|
//RWEntries = new ui32[height];
|
|
|
|
for(ui32 i=0; i < SEntries.size(); ++i)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
|
|
|
Cimage nimg;
|
2008-11-11 17:17:58 +02:00
|
|
|
nimg.bitmap = getSprite(i, table, palette);
|
2008-08-04 12:05:52 +03:00
|
|
|
nimg.imName = SEntries[i].name;
|
|
|
|
nimg.groupNumber = SEntries[i].group;
|
|
|
|
ourImages.push_back(nimg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
void CDefHandler::expand(ui8 N,ui8 & BL, ui8 & BR)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
|
|
|
BL = (N & 0xE0) >> 5;
|
|
|
|
BR = N & 0x1F;
|
|
|
|
}
|
|
|
|
|
2013-07-06 19:10:20 +03:00
|
|
|
SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const SDL_Color * palette) const
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2013-06-26 14:18:27 +03:00
|
|
|
SDL_Surface * ret=nullptr;
|
2008-08-04 12:05:52 +03:00
|
|
|
|
2012-02-16 20:10:58 +03:00
|
|
|
ui32 BaseOffset,
|
2010-02-21 20:07:24 +02:00
|
|
|
SpriteWidth, SpriteHeight, //format of sprite
|
|
|
|
TotalRowLength, // length of read segment
|
2009-10-11 21:26:36 +03:00
|
|
|
add, FullHeight,FullWidth,
|
2012-02-16 20:10:58 +03:00
|
|
|
RowAdd,
|
2009-10-11 21:26:36 +03:00
|
|
|
defType2;
|
|
|
|
int LeftMargin, RightMargin, TopMargin, BottomMargin;
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
|
2012-02-16 20:10:58 +03:00
|
|
|
ui8 SegmentType;
|
2008-08-04 12:05:52 +03:00
|
|
|
|
2009-10-14 15:44:44 +03:00
|
|
|
BaseOffset = SEntries[SIndex].offset;
|
2009-10-25 16:36:11 +02:00
|
|
|
SSpriteDef sd = * reinterpret_cast<const SSpriteDef *>(FDef + BaseOffset);
|
2009-10-11 21:26:36 +03:00
|
|
|
|
2013-02-05 22:56:28 +03:00
|
|
|
defType2 = read_le_u32(&sd.defType2);
|
|
|
|
FullWidth = read_le_u32(&sd.FullWidth);
|
|
|
|
FullHeight = read_le_u32(&sd.FullHeight);
|
|
|
|
SpriteWidth = read_le_u32(&sd.SpriteWidth);
|
|
|
|
SpriteHeight = read_le_u32(&sd.SpriteHeight);
|
|
|
|
LeftMargin = read_le_u32(&sd.LeftMargin);
|
|
|
|
TopMargin = read_le_u32(&sd.TopMargin);
|
2008-08-04 12:05:52 +03:00
|
|
|
RightMargin = FullWidth - SpriteWidth - LeftMargin;
|
|
|
|
BottomMargin = FullHeight - SpriteHeight - TopMargin;
|
|
|
|
|
|
|
|
//if(LeftMargin + RightMargin < 0)
|
|
|
|
// SpriteWidth += LeftMargin + RightMargin; //ugly construction... TODO: check how to do it nicer
|
|
|
|
if(LeftMargin<0)
|
|
|
|
SpriteWidth+=LeftMargin;
|
|
|
|
if(RightMargin<0)
|
|
|
|
SpriteWidth+=RightMargin;
|
2012-02-16 20:10:58 +03:00
|
|
|
|
2009-05-23 07:22:21 +03:00
|
|
|
// Note: this looks bogus because we allocate only FullWidth, not FullWidth+add
|
2008-08-04 12:05:52 +03:00
|
|
|
add = 4 - FullWidth%4;
|
|
|
|
if (add==4)
|
|
|
|
add=0;
|
|
|
|
|
|
|
|
ret = SDL_CreateRGBSurface(SDL_SWSURFACE, FullWidth, FullHeight, 8, 0, 0, 0, 0);
|
2014-05-21 21:43:44 +03:00
|
|
|
|
|
|
|
if(nullptr == ret)
|
|
|
|
{
|
|
|
|
logGlobal->errorStream() << __FUNCTION__ <<": Unable to create surface";
|
|
|
|
logGlobal->errorStream() << FullWidth << "X" << FullHeight;
|
|
|
|
logGlobal->errorStream() << SDL_GetError();
|
|
|
|
throw std::runtime_error("Unable to create surface");
|
|
|
|
}
|
2008-08-04 12:05:52 +03:00
|
|
|
|
2009-10-14 15:44:44 +03:00
|
|
|
BaseOffset += sizeof(SSpriteDef);
|
2009-10-11 21:26:36 +03:00
|
|
|
int BaseOffsetor = BaseOffset;
|
2008-08-04 12:05:52 +03:00
|
|
|
|
2014-05-21 21:43:44 +03:00
|
|
|
if(SDL_SetPaletteColors(ret->format->palette,palette,0,256) != 0)
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Unable to set palette");
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
2014-05-21 21:43:44 +03:00
|
|
|
|
2009-05-23 07:22:21 +03:00
|
|
|
int ftcp=0;
|
|
|
|
|
|
|
|
// If there's a margin anywhere, just blank out the whole surface.
|
|
|
|
if (TopMargin > 0 || BottomMargin > 0 || LeftMargin > 0 || RightMargin > 0) {
|
2009-10-25 16:36:11 +02:00
|
|
|
memset( reinterpret_cast<char*>(ret->pixels), 0, FullHeight*FullWidth);
|
2009-05-23 07:22:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Skip top margin
|
|
|
|
if (TopMargin > 0)
|
|
|
|
ftcp += TopMargin*(FullWidth+add);
|
|
|
|
|
2009-05-24 17:32:36 +03:00
|
|
|
switch(defType2)
|
|
|
|
{
|
2009-05-23 07:22:21 +03:00
|
|
|
case 0:
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
for (ui32 i=0;i<SpriteHeight;i++)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
|
|
|
if (LeftMargin>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += LeftMargin;
|
|
|
|
|
2009-10-25 16:36:11 +02:00
|
|
|
memcpy(reinterpret_cast<char*>(ret->pixels)+ftcp, &FDef[BaseOffset], SpriteWidth);
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += SpriteWidth;
|
|
|
|
BaseOffset += SpriteWidth;
|
2012-02-16 20:10:58 +03:00
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
if (RightMargin>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += RightMargin;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
}
|
2009-05-23 07:22:21 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
const ui32 * RWEntriesLoc = reinterpret_cast<const ui32 *>(FDef+BaseOffset);
|
2008-11-12 20:59:33 +02:00
|
|
|
BaseOffset += sizeof(int) * SpriteHeight;
|
2011-12-14 00:23:17 +03:00
|
|
|
for (ui32 i=0;i<SpriteHeight;i++)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
BaseOffset=BaseOffsetor + read_le_u32(RWEntriesLoc + i);
|
2008-08-04 12:05:52 +03:00
|
|
|
if (LeftMargin>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += LeftMargin;
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
TotalRowLength=0;
|
|
|
|
do
|
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
ui32 SegmentLength;
|
2009-05-23 07:22:21 +03:00
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
SegmentType=FDef[BaseOffset++];
|
2009-05-23 07:22:21 +03:00
|
|
|
SegmentLength=FDef[BaseOffset++] + 1;
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
if (SegmentType==0xFF)
|
|
|
|
{
|
2010-07-15 19:21:53 +03:00
|
|
|
memcpy(reinterpret_cast<char*>(ret->pixels)+ftcp, FDef + BaseOffset, SegmentLength);
|
2009-05-23 07:22:21 +03:00
|
|
|
BaseOffset+=SegmentLength;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-25 16:36:11 +02:00
|
|
|
memset(reinterpret_cast<char*>(ret->pixels)+ftcp, SegmentType, SegmentLength);
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
2010-07-15 19:21:53 +03:00
|
|
|
ftcp += SegmentLength;
|
|
|
|
TotalRowLength += SegmentLength;
|
2008-08-04 12:05:52 +03:00
|
|
|
}while(TotalRowLength<SpriteWidth);
|
2009-05-23 07:22:21 +03:00
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
RowAdd=SpriteWidth-TotalRowLength;
|
2009-05-23 07:22:21 +03:00
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
if (RightMargin>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += RightMargin;
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
if (add>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += add+RowAdd;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
}
|
2009-05-23 07:22:21 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
BaseOffset = BaseOffsetor + read_le_u16(FDef + BaseOffsetor);
|
2010-02-11 07:25:17 +02:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
for (ui32 i=0;i<SpriteHeight;i++)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
|
|
|
//BaseOffset = BaseOffsetor+RWEntries[i];
|
|
|
|
if (LeftMargin>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += LeftMargin;
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
TotalRowLength=0;
|
2009-05-23 07:22:21 +03:00
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
do
|
|
|
|
{
|
|
|
|
SegmentType=FDef[BaseOffset++];
|
2011-12-14 00:23:17 +03:00
|
|
|
ui8 code = SegmentType / 32;
|
|
|
|
ui8 value = (SegmentType & 31) + 1;
|
2008-08-04 12:05:52 +03:00
|
|
|
if(code==7)
|
|
|
|
{
|
2009-10-25 16:36:11 +02:00
|
|
|
memcpy(reinterpret_cast<char*>(ret->pixels)+ftcp, &FDef[BaseOffset], value);
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += value;
|
|
|
|
BaseOffset += value;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2009-10-25 16:36:11 +02:00
|
|
|
memset(reinterpret_cast<char*>(ret->pixels)+ftcp, code, value);
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += value;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
TotalRowLength+=value;
|
|
|
|
} while(TotalRowLength<SpriteWidth);
|
2009-05-23 07:22:21 +03:00
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
if (RightMargin>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += RightMargin;
|
|
|
|
|
2009-05-24 17:32:36 +03:00
|
|
|
RowAdd=SpriteWidth-TotalRowLength;
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
if (add>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += add+RowAdd;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
}
|
2009-05-23 07:22:21 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2011-12-14 00:23:17 +03:00
|
|
|
for (ui32 i=0;i<SpriteHeight;i++)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2011-10-08 04:23:46 +03:00
|
|
|
BaseOffset = BaseOffsetor + read_le_u16(FDef + BaseOffsetor+i*2*(SpriteWidth/32));
|
2008-08-04 12:05:52 +03:00
|
|
|
if (LeftMargin>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += LeftMargin;
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
TotalRowLength=0;
|
2009-05-23 07:22:21 +03:00
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
do
|
|
|
|
{
|
|
|
|
SegmentType=FDef[BaseOffset++];
|
2011-12-14 00:23:17 +03:00
|
|
|
ui8 code = SegmentType / 32;
|
|
|
|
ui8 value = (SegmentType & 31) + 1;
|
2010-04-04 11:47:00 +03:00
|
|
|
|
2011-12-14 00:23:17 +03:00
|
|
|
int len = std::min<ui32>(value, SpriteWidth - TotalRowLength) - std::max(0, -LeftMargin);
|
|
|
|
vstd::amax(len, 0);
|
2010-04-04 11:47:00 +03:00
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
if(code==7)
|
|
|
|
{
|
2010-04-04 11:47:00 +03:00
|
|
|
memcpy((ui8*)ret->pixels + ftcp, FDef + BaseOffset, len);
|
|
|
|
ftcp += len;
|
|
|
|
BaseOffset += len;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-04-04 11:47:00 +03:00
|
|
|
memset((ui8*)ret->pixels + ftcp, code, len);
|
|
|
|
ftcp += len;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
TotalRowLength+=( LeftMargin>=0 ? value : value+LeftMargin );
|
|
|
|
}while(TotalRowLength<SpriteWidth);
|
2009-05-23 07:22:21 +03:00
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
if (RightMargin>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += RightMargin;
|
|
|
|
|
2009-05-24 17:32:36 +03:00
|
|
|
RowAdd=SpriteWidth-TotalRowLength;
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
if (add>0)
|
2009-05-23 07:22:21 +03:00
|
|
|
ftcp += add+RowAdd;
|
2008-08-04 12:05:52 +03:00
|
|
|
}
|
|
|
|
}
|
2009-05-23 07:22:21 +03:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-04-22 10:32:45 +03:00
|
|
|
throw std::runtime_error("Unknown sprite format.");
|
2009-05-23 07:22:21 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
SDL_Color ttcol = ret->format->palette->colors[0];
|
2014-05-21 19:04:34 +03:00
|
|
|
Uint32 keycol = SDL_MapRGBA(ret->format, ttcol.r, ttcol.b, ttcol.g, ttcol.a);
|
|
|
|
SDL_SetColorKey(ret, SDL_TRUE, keycol);
|
|
|
|
|
2008-08-04 12:05:52 +03:00
|
|
|
return ret;
|
2012-09-15 22:16:16 +03:00
|
|
|
}
|
2008-08-04 12:05:52 +03:00
|
|
|
|
|
|
|
CDefEssential * CDefHandler::essentialize()
|
|
|
|
{
|
2013-06-29 16:05:48 +03:00
|
|
|
auto ret = new CDefEssential;
|
2008-08-04 12:05:52 +03:00
|
|
|
ret->ourImages = ourImages;
|
|
|
|
notFreeImgs = true;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-02-21 20:07:24 +02:00
|
|
|
CDefHandler * CDefHandler::giveDef(const std::string & defName)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
2013-07-28 17:49:50 +03:00
|
|
|
ResourceID resID(std::string("SPRITES/") + defName, EResType::ANIMATION);
|
|
|
|
|
2013-07-30 18:02:55 +03:00
|
|
|
auto data = CResourceHandler::get()->load(resID)->readAll().first;
|
2008-09-24 19:25:14 +03:00
|
|
|
if(!data)
|
2012-04-22 10:32:45 +03:00
|
|
|
throw std::runtime_error("bad def name!");
|
2013-06-29 16:05:48 +03:00
|
|
|
auto nh = new CDefHandler();
|
2013-07-30 18:02:55 +03:00
|
|
|
nh->openFromMemory(data.get(), defName);
|
2008-08-04 12:05:52 +03:00
|
|
|
return nh;
|
|
|
|
}
|
2010-02-21 20:07:24 +02:00
|
|
|
CDefEssential * CDefHandler::giveDefEss(const std::string & defName)
|
2008-08-04 12:05:52 +03:00
|
|
|
{
|
|
|
|
CDefEssential * ret;
|
2009-05-09 19:18:27 +03:00
|
|
|
CDefHandler * temp = giveDef(defName);
|
2008-08-04 12:05:52 +03:00
|
|
|
ret = temp->essentialize();
|
|
|
|
delete temp;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|