1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-21 21:17:49 +02:00

- removed no longer used CSndHandler. Transition to new fs is finished

- moved TownHandler::requirements to CBuilding class
This commit is contained in:
Ivan Savenko 2012-08-09 10:32:50 +00:00
parent 08bcfd1285
commit 7e778045b8
14 changed files with 30 additions and 270 deletions

View File

@ -34,7 +34,6 @@ set(client_SRCS
CMusicHandler.cpp
CPlayerInterface.cpp
CPreGame.cpp
CSndHandler.cpp
CSpellWindow.cpp
CVideoHandler.cpp
CQuestLog.cpp

View File

@ -2,7 +2,6 @@
#include <boost/bimap.hpp>
#include <SDL_mixer.h>
#include "CSndHandler.h"
#include "CMusicHandler.h"
#include "../lib/CCreatureHandler.h"
#include "../lib/CSpellHandler.h"

View File

@ -1,159 +0,0 @@
#include "StdInc.h"
#include <boost/iostreams/device/mapped_file.hpp>
#include <SDL_endian.h>
#include "CSndHandler.h"
/*
* CSndHandler.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
*
*/
/* Media file are kept in container files. We map these files in
* memory, parse them and create an index of them to easily retrieve
* the data+size of the objects. */
CMediaHandler::~CMediaHandler()
{
std::vector<boost::iostreams::mapped_file_source *>::iterator it;
entries.clear();
fimap.clear();
for (it=mfiles.begin() ; it < mfiles.end(); it++ ) {
(*it)->close();
delete *it;
}
}
boost::iostreams::mapped_file_source *CMediaHandler::add_file(std::string fname, bool important /*= true*/)
{
boost::iostreams::mapped_file_source *mfile;
try //c-tor of mapped_file_source throws exception on failure
{
mfile = new boost::iostreams::mapped_file_source(fname);
if (!mfile->is_open()) //just in case
throw std::runtime_error("Cannot open " + fname + ": !mfile->is_open()");
}
catch(std::exception &e)
{
if(important)
tlog1 << "Cannot open " << fname << ": " << e.what() << std::endl;
throw;
}
mfiles.push_back(mfile);
return mfile;
}
void CMediaHandler::extract(int index, std::string dstfile) //saves selected file
{
std::ofstream out(dstfile.c_str(),std::ios_base::binary);
Entry &entry = entries[index];
out.write(entry.data, entry.size);
out.close();
}
void CMediaHandler::extract(std::string srcfile, std::string dstfile, bool caseSens) //saves selected file
{
srcfile.erase(srcfile.find_last_of('.'));
if (caseSens)
{
for (size_t i=0;i<entries.size();++i)
{
if (entries[i].name==srcfile)
extract(i,dstfile);
}
}
else
{
std::transform(srcfile.begin(),srcfile.end(),srcfile.begin(),tolower);
for (size_t i=0;i<entries.size();++i)
{
if (entries[i].name==srcfile)
{
std::string por = entries[i].name;
std::transform(por.begin(),por.end(),por.begin(),tolower);
if (por==srcfile)
extract(i,dstfile);
}
}
}
}
const char * CMediaHandler::extract (int index, int & size)
{
Entry &entry = entries[index];
size = entry.size;
return entry.data;
}
const char * CMediaHandler::extract (std::string srcName, int &size)
{
int index;
size_t dotPos = srcName.find_last_of('.');
if (dotPos != std::string::npos)
srcName.erase(dotPos);
std::map<std::string, int>::iterator fit;
if ((fit = fimap.find(srcName)) != fimap.end())
{
index = fit->second;
return this->extract(index, size);
}
size = 0;
return NULL;
}
void CVidHandler::add_file(std::string fname)
{
boost::iostreams::mapped_file_source *mfile = NULL;
try
{
mfile = CMediaHandler::add_file(fname);
}
catch(...)
{
return;
}
if(mfile->size() < 48)
{
tlog1 << fname << " doesn't contain needed data!\n";
return;
}
const ui8 *data = (const ui8 *)mfile->data();
ui32 numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]);
struct videoEntry *ve = (struct videoEntry *)&data[4];
for (ui32 i=0; i<numFiles; i++, ve++)
{
Entry entry;
entry.name = ve->filename;
entry.offset = SDL_SwapLE32(ve->offset);
entry.name.erase(entry.name.find_last_of('.'));
// There is no size, so check where the next file is
if (i == numFiles - 1) {
entry.size = mfile->size() - entry.offset;
} else {
struct videoEntry *ve_next = ve+1;
entry.size = SDL_SwapLE32(ve_next->offset) - entry.offset;
}
entry.data = mfile->data() + entry.offset;
entries.push_back(entry);
fimap[entry.name] = i;
}
}

View File

@ -1,66 +0,0 @@
#pragma once
#include <iosfwd>
#include <SDL_stdinc.h>
/*
* CSndHandler.h, 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
*
*/
namespace boost
{
namespace iostreams
{
class mapped_file_source;
}
}
struct MemberFile
{
std::ifstream * ifs;
int length;
};
// video entry structure in catalog
struct videoEntry
{
char filename[40];
Uint32 offset; /* little endian */
};
class CMediaHandler
{
protected:
struct Entry
{
std::string name;
ui32 size;
ui32 offset;
const char *data;
};
std::vector<boost::iostreams::mapped_file_source *> mfiles;
boost::iostreams::mapped_file_source *add_file(std::string fname, bool important = true); //if not important, then we don't print warning when the file is missing
public:
std::vector<Entry> entries;
std::map<std::string, int> fimap; // map of file and index
~CMediaHandler(); //d-tor
void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file
const char * extract (std::string srcfile, int & size); //return selecte file data, NULL if file doesn't exist
void extract(int index, std::string dstfile); //saves selected file
const char * extract (int index, int & size); //return selecte file - NIE TESTOWANE
};
class CVidHandler: public CMediaHandler
{
public:
void add_file(std::string fname);
};

View File

@ -1,6 +1,5 @@
#include "StdInc.h"
#include <SDL.h>
#include "CSndHandler.h"
#include "CVideoHandler.h"
#include "UIFramework/CGuiHandler.h"

View File

@ -1,8 +1,5 @@
#pragma once
#include "CSndHandler.h"
struct SDL_Surface;
@ -227,7 +224,6 @@ public:
#else
#include "CSndHandler.h"
#include <SDL.h>
#include <SDL_video.h>
#if SDL_VERSION_ATLEAST(1,3,0)

View File

@ -75,8 +75,6 @@ vcmiclient_SOURCES = \
CPlayerInterface.h \
CPreGame.cpp \
CPreGame.h \
CSndHandler.cpp \
CSndHandler.h \
CSoundBase.h \
CSpellWindow.cpp \
CSpellWindow.h \

View File

@ -86,7 +86,7 @@ am_vcmiclient_OBJECTS = vcmiclient-CCallback.$(OBJEXT) \
vcmiclient-Client.$(OBJEXT) vcmiclient-CMessage.$(OBJEXT) \
vcmiclient-CMT.$(OBJEXT) vcmiclient-CMusicHandler.$(OBJEXT) \
vcmiclient-CPlayerInterface.$(OBJEXT) \
vcmiclient-CPreGame.$(OBJEXT) vcmiclient-CSndHandler.$(OBJEXT) \
vcmiclient-CPreGame.$(OBJEXT) \
vcmiclient-CSpellWindow.$(OBJEXT) \
vcmiclient-CVideoHandler.$(OBJEXT) \
vcmiclient-CQuestLog.$(OBJEXT) vcmiclient-Graphics.$(OBJEXT) \
@ -380,8 +380,6 @@ vcmiclient_SOURCES = \
CPlayerInterface.h \
CPreGame.cpp \
CPreGame.h \
CSndHandler.cpp \
CSndHandler.h \
CSoundBase.h \
CSpellWindow.cpp \
CSpellWindow.h \
@ -513,7 +511,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CPlayerInterface.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CPreGame.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CQuestLog.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CSndHandler.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CSpellWindow.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-CVideoHandler.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vcmiclient-Client.Po@am__quote@
@ -937,20 +934,6 @@ vcmiclient-CPreGame.obj: CPreGame.cpp
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CPreGame.obj `if test -f 'CPreGame.cpp'; then $(CYGPATH_W) 'CPreGame.cpp'; else $(CYGPATH_W) '$(srcdir)/CPreGame.cpp'; fi`
vcmiclient-CSndHandler.o: CSndHandler.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CSndHandler.o -MD -MP -MF $(DEPDIR)/vcmiclient-CSndHandler.Tpo -c -o vcmiclient-CSndHandler.o `test -f 'CSndHandler.cpp' || echo '$(srcdir)/'`CSndHandler.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CSndHandler.Tpo $(DEPDIR)/vcmiclient-CSndHandler.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='CSndHandler.cpp' object='vcmiclient-CSndHandler.o' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CSndHandler.o `test -f 'CSndHandler.cpp' || echo '$(srcdir)/'`CSndHandler.cpp
vcmiclient-CSndHandler.obj: CSndHandler.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CSndHandler.obj -MD -MP -MF $(DEPDIR)/vcmiclient-CSndHandler.Tpo -c -o vcmiclient-CSndHandler.obj `if test -f 'CSndHandler.cpp'; then $(CYGPATH_W) 'CSndHandler.cpp'; else $(CYGPATH_W) '$(srcdir)/CSndHandler.cpp'; fi`
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CSndHandler.Tpo $(DEPDIR)/vcmiclient-CSndHandler.Po
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ $(AM_V_CXX)source='CSndHandler.cpp' object='vcmiclient-CSndHandler.obj' libtool=no @AMDEPBACKSLASH@
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(AM_V_CXX@am__nodep@)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -c -o vcmiclient-CSndHandler.obj `if test -f 'CSndHandler.cpp'; then $(CYGPATH_W) 'CSndHandler.cpp'; else $(CYGPATH_W) '$(srcdir)/CSndHandler.cpp'; fi`
vcmiclient-CSpellWindow.o: CSpellWindow.cpp
@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(vcmiclient_CXXFLAGS) $(CXXFLAGS) -MT vcmiclient-CSpellWindow.o -MD -MP -MF $(DEPDIR)/vcmiclient-CSpellWindow.Tpo -c -o vcmiclient-CSpellWindow.o `test -f 'CSpellWindow.cpp' || echo '$(srcdir)/'`CSpellWindow.cpp
@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/vcmiclient-CSpellWindow.Tpo $(DEPDIR)/vcmiclient-CSpellWindow.Po

View File

@ -42,7 +42,7 @@
],
"CONFIG/":
[
{"type" : "dir", "path" : "GLOBAL/Config",} // separate to avoid overwriting global resources
{"type" : "dir", "path" : "GLOBAL/Config",}, // separate to avoid overwriting global resources
{"type" : "dir", "path" : "LOCAL/Config", "writeable": true}
],
"MAPS/":

View File

@ -124,9 +124,30 @@ void CBuildingHandler::loadBuildings()
}
row_num ++;
}
assert (row_num == 5);
}
// Buildings dependencies. Which building depend on which other building.
const JsonNode buildingsConf(ResourceID("config/buildings.json"));
// Iterate for each city type
int townID = 0;
BOOST_FOREACH(const JsonNode &town_node, buildingsConf["town_type"].Vector())
{
BOOST_FOREACH(const JsonNode &node, town_node["building_requirements"].Vector())
{
int id = node["id"].Float();
CBuilding * build = buildings[townID][id];
if (build)
{
BOOST_FOREACH(const JsonNode &building, node["requires"].Vector())
{
build->requirements.insert(building.Float());
}
}
}
townID++;
}
}
CBuildingHandler::~CBuildingHandler()

View File

@ -22,13 +22,14 @@ public:
TResources resources;
std::string name;
std::string description;
std::set<int> requirements; //set of required buildings
const std::string &Name() const;
const std::string &Description() const;
template <typename Handler> void serialize(Handler &h, const int version)
{
h & tid & bid & resources & name & description;
h & tid & bid & resources & name & description & requirements;
}
CBuilding(int TID = -1, int BID = -1);
};

View File

@ -110,16 +110,6 @@ void CTownHandler::loadStructures()
level ++;
}
// Buildings dependencies. Which building depend on which other building.
requirements.resize(GameConstants::F_NUMBER);
BOOST_FOREACH(const JsonNode &node, town_node["building_requirements"].Vector()) {
std::set<int> &requires = requirements[townID][node["id"].Float()];
BOOST_FOREACH(const JsonNode &building, node["requires"].Vector()) {
requires.insert(building.Float());
}
}
// Misc.
towns[townID].mageLevel = town_node["mage_guild"].Float();
towns[townID].primaryRes = town_node["primary_resource"].Float();

View File

@ -64,7 +64,6 @@ class DLL_LINKAGE CTownHandler
public:
std::vector<CTown> towns;
std::vector<std::map<int, Structure*> > structures; // <town ID, <structure ID, structure>>
std::vector<std::map<int,std::set<int> > > requirements; //requirements[town_id][structure_id] -> set of required buildings
CTownHandler(); //c-tor
~CTownHandler(); //d-tor
@ -72,7 +71,7 @@ public:
template <typename Handler> void serialize(Handler &h, const int version)
{
h & towns & requirements;
h & towns;
if(!h.saving)
loadStructures();
}

View File

@ -1014,7 +1014,7 @@ std::set<int> CGameInfoCallback::getBuildingRequiments( const CGTownInstance *t,
std::set<int> used;
used.insert(ID);
std::set<int> reqs = VLC->townh->requirements[t->subID][ID];
std::set<int> reqs = VLC->buildh->buildings[t->subID][ID]->requirements;
while(true)
{
@ -1025,8 +1025,8 @@ std::set<int> CGameInfoCallback::getBuildingRequiments( const CGTownInstance *t,
{
used.insert(*i);
for(
std::set<int>::iterator j=VLC->townh->requirements[t->subID][*i].begin();
j!=VLC->townh->requirements[t->subID][*i].end();
std::set<int>::iterator j=VLC->buildh->buildings[t->subID][*i]->requirements.begin();
j!= VLC->buildh->buildings[t->subID][*i]->requirements.end();
j++)
{
reqs.insert(*j);//creating full list of requirements