mirror of
https://github.com/vcmi/vcmi.git
synced 2025-07-15 01:24:45 +02:00
- sound player uses new FS
This commit is contained in:
@ -106,9 +106,6 @@ void CSoundHandler::init()
|
|||||||
if (initialized)
|
if (initialized)
|
||||||
{
|
{
|
||||||
// Load sounds
|
// Load sounds
|
||||||
sndh.add_file(std::string(GameConstants::DATA_DIR + "/Data/Heroes3.snd"));
|
|
||||||
sndh.add_file(std::string(GameConstants::DATA_DIR + "/Data/Heroes3-cd2.snd"), false);
|
|
||||||
sndh.add_file(std::string(GameConstants::DATA_DIR + "/Data/H3ab_ahd.snd"));
|
|
||||||
Mix_ChannelFinished(soundFinishedCallbackC);
|
Mix_ChannelFinished(soundFinishedCallbackC);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -140,12 +137,9 @@ Mix_Chunk *CSoundHandler::GetSoundChunk(soundBase::soundID soundID)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
// Load and insert
|
// Load and insert
|
||||||
int size;
|
auto data = CResourceHandler::get()->loadData(ResourceID(std::string("SOUNDS/") + it->second, EResType::SOUND));
|
||||||
const char *data = sndh.extract(it->second, size);
|
|
||||||
if (!data)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
SDL_RWops *ops = SDL_RWFromConstMem(data, size);
|
SDL_RWops *ops = SDL_RWFromMem(data.first.release(), data.second);
|
||||||
Mix_Chunk *chunk;
|
Mix_Chunk *chunk;
|
||||||
chunk = Mix_LoadWAV_RW(ops, 1); // will free ops
|
chunk = Mix_LoadWAV_RW(ops, 1); // will free ops
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
#include "CConfigHandler.h"
|
#include "CConfigHandler.h"
|
||||||
#include "CSoundBase.h"
|
#include "CSoundBase.h"
|
||||||
#include "../lib/CCreatureHandler.h"
|
#include "../lib/CCreatureHandler.h"
|
||||||
#include "CSndHandler.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CMusicHandler.h, part of VCMI engine
|
* CMusicHandler.h, part of VCMI engine
|
||||||
@ -63,7 +62,6 @@ public:
|
|||||||
class CSoundHandler: public CAudioBase
|
class CSoundHandler: public CAudioBase
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CSndHandler sndh;
|
|
||||||
soundBase::soundID getSoundID(const std::string &fileName);
|
soundBase::soundID getSoundID(const std::string &fileName);
|
||||||
//update volume on configuration change
|
//update volume on configuration change
|
||||||
SettingsListener listener;
|
SettingsListener listener;
|
||||||
|
@ -89,31 +89,6 @@ void CMediaHandler::extract(std::string srcfile, std::string dstfile, bool caseS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
// unused and not sure what it's supposed to do
|
|
||||||
MemberFile CMediaHandler::getFile(std::string name)
|
|
||||||
{
|
|
||||||
MemberFile ret;
|
|
||||||
std::transform(name.begin(),name.end(),name.begin(),tolower);
|
|
||||||
for (size_t i=0;i<entries.size();++i)
|
|
||||||
{
|
|
||||||
if (entries[i].name==name)
|
|
||||||
{
|
|
||||||
std::string por = entries[i].name;
|
|
||||||
std::transform(por.begin(),por.end(),por.begin(),tolower);
|
|
||||||
if (por==name)
|
|
||||||
{
|
|
||||||
ret.length=entries[i].size;
|
|
||||||
file.seekg(entries[i].offset,std::ios_base::beg);
|
|
||||||
ret.ifs=&file;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
const char * CMediaHandler::extract (int index, int & size)
|
const char * CMediaHandler::extract (int index, int & size)
|
||||||
{
|
{
|
||||||
Entry &entry = entries[index];
|
Entry &entry = entries[index];
|
||||||
@ -139,36 +114,6 @@ const char * CMediaHandler::extract (std::string srcName, int &size)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSndHandler::add_file(std::string fname, bool important /*= true*/)
|
|
||||||
{
|
|
||||||
boost::iostreams::mapped_file_source *mfile = NULL;
|
|
||||||
try
|
|
||||||
{
|
|
||||||
mfile = CMediaHandler::add_file(fname, important);
|
|
||||||
}
|
|
||||||
catch(...)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *data = mfile->data();
|
|
||||||
ui32 numFiles = SDL_SwapLE32(*(Uint32 *)&data[0]);
|
|
||||||
struct soundEntry *se = (struct soundEntry *)&data[4];
|
|
||||||
|
|
||||||
for (ui32 i=0; i<numFiles; i++, se++)
|
|
||||||
{
|
|
||||||
Entry entry;
|
|
||||||
|
|
||||||
entry.name = se->filename;
|
|
||||||
entry.offset = SDL_SwapLE32(se->offset);
|
|
||||||
entry.size = SDL_SwapLE32(se->size);
|
|
||||||
entry.data = mfile->data() + entry.offset;
|
|
||||||
|
|
||||||
entries.push_back(entry);
|
|
||||||
fimap[entry.name] = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CVidHandler::add_file(std::string fname)
|
void CVidHandler::add_file(std::string fname)
|
||||||
{
|
{
|
||||||
boost::iostreams::mapped_file_source *mfile = NULL;
|
boost::iostreams::mapped_file_source *mfile = NULL;
|
||||||
|
@ -28,14 +28,6 @@ struct MemberFile
|
|||||||
int length;
|
int length;
|
||||||
};
|
};
|
||||||
|
|
||||||
// sound entry structure in catalog
|
|
||||||
struct soundEntry
|
|
||||||
{
|
|
||||||
char filename[40];
|
|
||||||
Uint32 offset; /* little endian */
|
|
||||||
Uint32 size; /* little endian */
|
|
||||||
};
|
|
||||||
|
|
||||||
// video entry structure in catalog
|
// video entry structure in catalog
|
||||||
struct videoEntry
|
struct videoEntry
|
||||||
{
|
{
|
||||||
@ -64,16 +56,9 @@ public:
|
|||||||
void extract(std::string srcfile, std::string dstfile, bool caseSens=true); //saves selected file
|
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
|
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
|
void extract(int index, std::string dstfile); //saves selected file
|
||||||
MemberFile getFile(std::string name);//nie testowane - sprawdzic
|
|
||||||
const char * extract (int index, int & size); //return selecte file - NIE TESTOWANE
|
const char * extract (int index, int & size); //return selecte file - NIE TESTOWANE
|
||||||
};
|
};
|
||||||
|
|
||||||
class CSndHandler: public CMediaHandler
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
void add_file(std::string fname, bool important = true); //if not important, then we don't print warning when the file is missing
|
|
||||||
};
|
|
||||||
|
|
||||||
class CVidHandler: public CMediaHandler
|
class CVidHandler: public CMediaHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -124,7 +124,8 @@ void CLodArchiveLoader::initVIDArchive(CFileInputStream & fileStream)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
VideoEntryBlock nextVidEntry = vidEntries[i + 1];
|
VideoEntryBlock nextVidEntry = vidEntries[i + 1];
|
||||||
entry.size = SDL_SwapLE32(nextVidEntry.offset) - entry.offset;
|
entry.realSize = SDL_SwapLE32(nextVidEntry.offset) - entry.offset;
|
||||||
|
entry.size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
entries[entry.name] = entry;
|
entries[entry.name] = entry;
|
||||||
@ -160,10 +161,15 @@ void CLodArchiveLoader::initSNDArchive(CFileInputStream & fileStream)
|
|||||||
SoundEntryBlock sndEntry = sndEntries[i];
|
SoundEntryBlock sndEntry = sndEntries[i];
|
||||||
ArchiveEntry entry;
|
ArchiveEntry entry;
|
||||||
|
|
||||||
entry.name = sndEntry.filename;
|
//for some reason entries in snd have format NAME\0WAV\0\0\0....
|
||||||
entry.offset = SDL_SwapLE32(sndEntry.offset);
|
//we need to replace first \0 with dot and trim line
|
||||||
entry.size = SDL_SwapLE32(sndEntry.size);
|
entry.name = std::string(sndEntry.filename, 40);
|
||||||
|
entry.name[entry.name.find_first_of('\0')] = '.';
|
||||||
|
entry.name.resize(entry.name.find_first_of('\0'));
|
||||||
|
|
||||||
|
entry.offset = SDL_SwapLE32(sndEntry.offset);
|
||||||
|
entry.realSize = SDL_SwapLE32(sndEntry.size);
|
||||||
|
entry.size = 0;
|
||||||
entries[entry.name] = entry;
|
entries[entry.name] = entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,7 +374,6 @@ void CResourceHandler::loadFileSystem(const std::string fsConfigURI)
|
|||||||
|
|
||||||
void CResourceHandler::loadModsFilesystems()
|
void CResourceHandler::loadModsFilesystems()
|
||||||
{
|
{
|
||||||
|
|
||||||
auto iterator = initialLoader->getIterator([](const ResourceID & ident) -> bool
|
auto iterator = initialLoader->getIterator([](const ResourceID & ident) -> bool
|
||||||
{
|
{
|
||||||
std::string name = ident.getName();
|
std::string name = ident.getName();
|
||||||
|
Reference in New Issue
Block a user