1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

further refactoring-related changes

This commit is contained in:
Zyx-2000 2016-01-29 15:16:14 +01:00
parent c3e8c8bc1c
commit 3a1a8e3d47
10 changed files with 79 additions and 93 deletions

View File

@ -70,12 +70,11 @@
<Add option="-Wno-unused-parameter" />
<Add option="-Wno-overloaded-virtual" />
<Add option="-fpermissive" />
<Add option="-isystem $(#boost.include)" />
<Add option="-DBOOST_THREAD_USE_LIB" />
<Add option="-DBOOST_SYSTEM_NO_DEPRECATED" />
<Add option="-D_WIN32_WINNT=0x0501" />
<Add option="-D_WIN32" />
<Add directory="$(#boost.include)" />
<Add directory="../include" />
<Add directory="../client" />
<Add directory="$(#ffmpeg.include)" />
<Add directory="$(#sdl2.include)" />

View File

@ -75,29 +75,26 @@ class CFileCache
static const int cacheSize = 50; //Max number of cached files
struct FileData
{
ResourceID name;
size_t size;
ui8 * data;
ResourceID name;
size_t size;
std::unique_ptr<ui8[]> data;
ui8 * getCopy()
std::unique_ptr<ui8[]> getCopy()
{
auto ret = new ui8[size];
std::copy(data, data + size, ret);
auto ret = std::unique_ptr<ui8[]>(new ui8[size]);
std::copy(data.get(), data.get() + size, ret.get());
return ret;
}
FileData():
size(0),
data(nullptr)
FileData(ResourceID name_, size_t size_, std::unique_ptr<ui8[]> data_):
name{std::move(name_)},
size{size_},
data{std::move(data_)}
{}
~FileData()
{
delete [] data;
}
};
std::list<FileData> cache;
std::deque<FileData> cache;
public:
ui8 * getCachedFile(ResourceID && rid)
std::unique_ptr<ui8[]> getCachedFile(ResourceID rid)
{
for(auto & file : cache)
{
@ -107,12 +104,10 @@ public:
// Still here? Cache miss
if (cache.size() > cacheSize)
cache.pop_front();
cache.push_back(FileData());
auto data = CResourceHandler::get()->load(rid)->readAll();
cache.back().name = ResourceID(rid);
cache.back().size = data.second;
cache.back().data = data.first.release();
cache.emplace_back(std::move(rid), data.second, std::move(data.first));
return cache.back().getCopy();
}
@ -142,15 +137,15 @@ CDefFile::CDefFile(std::string Name):
};
data = animationCache.getCachedFile(ResourceID(std::string("SPRITES/") + Name, EResType::ANIMATION));
palette = new SDL_Color[256];
palette = std::unique_ptr<SDL_Color[]>(new SDL_Color[256]);
int it = 0;
ui32 type = read_le_u32(data + it);
ui32 type = read_le_u32(data.get() + it);
it+=4;
//int width = read_le_u32(data + it); it+=4;//not used
//int height = read_le_u32(data + it); it+=4;
it+=8;
ui32 totalBlocks = read_le_u32(data + it);
ui32 totalBlocks = read_le_u32(data.get() + it);
it+=4;
for (ui32 i= 0; i<256; i++)
@ -161,15 +156,15 @@ CDefFile::CDefFile(std::string Name):
palette[i].a = SDL_ALPHA_OPAQUE;
}
if (type == 71 || type == 64)//Buttons/buildings don't have shadows\semi-transparency
memset(palette, 0, sizeof(SDL_Color)*2);
memset(palette.get(), 0, sizeof(SDL_Color)*2);
else
memcpy(palette, H3Palette, sizeof(SDL_Color)*8);//initialize shadow\selection colors
memcpy(palette.get(), H3Palette, sizeof(SDL_Color)*8);//initialize shadow\selection colors
for (ui32 i=0; i<totalBlocks; i++)
{
size_t blockID = read_le_u32(data + it);
size_t blockID = read_le_u32(data.get() + it);
it+=4;
size_t totalEntries = read_le_u32(data + it);
size_t totalEntries = read_le_u32(data.get() + it);
it+=12;
//8 unknown bytes - skipping
@ -178,7 +173,7 @@ CDefFile::CDefFile(std::string Name):
for (ui32 j=0; j<totalEntries; j++)
{
size_t currOffset = read_le_u32(data + it);
size_t currOffset = read_le_u32(data.get() + it);
offset[blockID].push_back(currOffset);
it += 4;
}
@ -192,7 +187,7 @@ void CDefFile::loadFrame(size_t frame, size_t group, ImageLoader &loader) const
it = offset.find(group);
assert (it != offset.end());
const ui8 * FDef = data+it->second[frame];
const ui8 * FDef = data.get()+it->second[frame];
const SSpriteDef sd = * reinterpret_cast<const SSpriteDef *>(FDef);
SSpriteDef sprite;
@ -210,7 +205,7 @@ void CDefFile::loadFrame(size_t frame, size_t group, ImageLoader &loader) const
loader.init(Point(sprite.width, sprite.height),
Point(sprite.leftMargin, sprite.topMargin),
Point(sprite.fullWidth, sprite.fullHeight), palette);
Point(sprite.fullWidth, sprite.fullHeight), palette.get());
switch (sprite.format)
{
@ -321,11 +316,7 @@ void CDefFile::loadFrame(size_t frame, size_t group, ImageLoader &loader) const
}
};
CDefFile::~CDefFile()
{
delete[] data;
delete[] palette;
}
CDefFile::~CDefFile() = default;
const std::map<size_t, size_t > CDefFile::getEntries() const
{

View File

@ -39,8 +39,8 @@ private:
//offset[group][frame] - offset of frame data in file
std::map<size_t, std::vector <size_t> > offset;
ui8 * data;
SDL_Color * palette;
std::unique_ptr<ui8[]> data;
std::unique_ptr<SDL_Color[]> palette;
public:
CDefFile(std::string Name);

View File

@ -9,17 +9,18 @@
<Target title="Debug Win32">
<Option output="../VCMI_launcher" prefix_auto="1" extension_auto="1" />
<Option working_dir="../" />
<Option object_output=".objs/debug" />
<Option object_output="../obj/Launcher/Debug" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
<Add option="-Og" />
</Compiler>
</Target>
<Target title="Release Win32">
<Option output="../VCMI_launcher" prefix_auto="1" extension_auto="1" />
<Option working_dir="../" />
<Option object_output=".objs/release" />
<Option object_output="../obj/Launcher/Release" />
<Option type="0" />
<Option compiler="gcc" />
<Compiler>
@ -36,11 +37,10 @@
<Add option="-Wextra" />
<Add option="-Wall" />
<Add option="-std=gnu++11" />
<Add option="-isystem $(#boost.include)" />
<Add option="-DBOOST_SYSTEM_NO_DEPRECATED" />
<Add option="-D_WIN32" />
<Add directory="." />
<Add directory="../include" />
<Add directory="$(#boost.include)" />
<Add directory="$(#qt.include)" />
<Add directory="$(#qt.include)/QtGui" />
<Add directory="$(#qt.include)/QtCore" />

View File

@ -19,7 +19,6 @@
<Compiler>
<Add option="-g" />
<Add option="-Og" />
<Add directory="$(#zlib.include)" />
</Compiler>
<Linker>
<Add option="-lws2_32" />
@ -33,9 +32,6 @@
<Add option="-lboost_date_time$(#boost.libsuffix)" />
<Add option="-liconv" />
<Add option="-ldbghelp" />
<Add directory="$(#sdl2.lib)" />
<Add directory="$(#boost.lib32)" />
<Add directory="$(#zlib.lib)" />
</Linker>
</Target>
<Target title="Release-win32">
@ -48,7 +44,6 @@
<Compiler>
<Add option="-fomit-frame-pointer" />
<Add option="-O2" />
<Add directory="$(#zlib.include)" />
</Compiler>
<Linker>
<Add option="-s" />
@ -62,9 +57,6 @@
<Add option="-lboost_locale$(#boost.libsuffix)" />
<Add option="-lboost_date_time$(#boost.libsuffix)" />
<Add option="-liconv" />
<Add directory="$(#sdl2.lib)" />
<Add directory="$(#boost.lib32)" />
<Add directory="$(#zlib.lib)" />
</Linker>
</Target>
<Target title="Debug-win64">
@ -110,18 +102,21 @@
<Add option="-Wno-unused-parameter" />
<Add option="-Wno-overloaded-virtual" />
<Add option="-Wno-unused-local-typedefs" />
<Add option="-isystem $(#boost.include)" />
<Add option="-DVCMI_DLL" />
<Add option="-DBOOST_THREAD_USE_LIB" />
<Add option="-DBOOST_SYSTEM_NO_DEPRECATED" />
<Add option="-D_WIN32_WINNT=0x0501" />
<Add option="-D_WIN32" />
<Add directory="$(#boost.include)" />
<Add directory="../include" />
<Add directory="../lib" />
<Add directory="." />
<Add directory="$(#sdl2.include)" />
<Add directory="$(#zlib.include)" />
</Compiler>
<Linker>
<Add directory="../" />
<Add directory="$(#sdl2.lib)" />
<Add directory="$(#boost.lib32)" />
<Add directory="$(#zlib.lib)" />
</Linker>
<Unit filename="AI_Base.h" />
<Unit filename="BattleAction.cpp" />

View File

@ -8,7 +8,8 @@ CMappedFileLoader::CMappedFileLoader(const std::string & mountPoint, const JsonN
{
for(auto entry : config.Struct())
{
fileList[ResourceID(mountPoint + entry.first)] = ResourceID(mountPoint + entry.second.String());
//fileList[ResourceID(mountPoint + entry.first)] = ResourceID(mountPoint + entry.second.String());
fileList.emplace(ResourceID(mountPoint + entry.first), ResourceID(mountPoint + entry.second.String()));
}
}

View File

@ -46,10 +46,12 @@ static inline std::string readName(std::string name)
return name;
}
#if 0
ResourceID::ResourceID()
:type(EResType::OTHER)
{
}
#endif
ResourceID::ResourceID(std::string name_)
:type{readType(name_)},
@ -62,7 +64,7 @@ ResourceID::ResourceID(std::string name_, EResType::Type type_)
name{readName(std::move(name_))}
{
}
#if 0
std::string ResourceID::getName() const
{
return name;
@ -72,7 +74,7 @@ EResType::Type ResourceID::getType() const
{
return type;
}
#if 0
void ResourceID::setName(std::string name)
{
// setName shouldn't be used if type is UNDEFINED

View File

@ -70,7 +70,7 @@ public:
/**
* Default c-tor.
*/
ResourceID();
//ResourceID();
/**
* Ctor. Can be used to create identifier for resource loading using one parameter
@ -98,8 +98,8 @@ public:
return name == other.name && type == other.type;
}
std::string getName() const;
EResType::Type getType() const;
std::string getName() const {return name;}
EResType::Type getType() const {return type;}
//void setName(std::string name);
//void setType(EResType::Type type);

View File

@ -15,9 +15,8 @@
<Option compiler="gcc" />
<Option use_console_runner="0" />
<Compiler>
<Add option="-g" />
<Add option="-Og" />
<Add option="-ggdb" />
<Add directory="$(#zlib.include)" />
</Compiler>
<Linker>
<Add directory="$(#boost.lib32)" />
@ -34,7 +33,6 @@
<Compiler>
<Add option="-fomit-frame-pointer" />
<Add option="-O2" />
<Add directory="$(#zlib.include)" />
</Compiler>
<Linker>
<Add option="-s" />
@ -69,13 +67,13 @@
<Add option="-Wno-sign-compare" />
<Add option="-Wno-unused-parameter" />
<Add option="-Wno-overloaded-virtual" />
<Add option="-isystem $(#boost.include)" />
<Add option="-D_WIN32_WINNT=0x0501" />
<Add option="-DBOOST_THREAD_USE_LIB" />
<Add option="-DBOOST_SYSTEM_NO_DEPRECATED" />
<Add option="-D_WIN32" />
<Add directory="$(#boost.include)" />
<Add directory="../include" />
<Add directory="$(#sdl2.include)" />
<Add directory="$(#zlib.include)" />
</Compiler>
<Linker>
<Add option="-lole32" />

View File

@ -6,8 +6,8 @@
<Depends filename="lib/minizip/minizip.cbp" />
</Project>
<Project filename="client/VCMI_client.cbp">
<Depends filename="server/VCMI_server.cbp" />
<Depends filename="lib/VCMI_lib.cbp" />
<Depends filename="server/VCMI_server.cbp" />
</Project>
<Project filename="server/VCMI_server.cbp">
<Depends filename="lib/VCMI_lib.cbp" />
@ -27,13 +27,13 @@
<Depends filename="lib/VCMI_lib.cbp" />
</Project>
<Project filename="test/Test.cbp">
<Depends filename="server/VCMI_server.cbp" />
<Depends filename="AI/EmptyAI/EmptyAI.cbp" />
<Depends filename="AI/VCAI/VCAI.cbp" />
<Depends filename="AI/StupidAI/StupidAI.cbp" />
<Depends filename="AI/BattleAI/BattleAI.cbp" />
<Depends filename="lib/VCMI_lib.cbp" />
<Depends filename="client/VCMI_client.cbp" />
<Depends filename="server/VCMI_server.cbp" />
<Depends filename="AI/VCAI/VCAI.cbp" />
</Project>
<Project filename="scripting/erm/ERM.cbp">
<Depends filename="lib/VCMI_lib.cbp" />