-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
KadVenku
committed
Mar 26, 2018
0 parents
commit c1cad5d
Showing
60 changed files
with
21,069 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
Asset Loader subsystem | ||
Loads various types of assets by name. The core function is LoadFile which | ||
loads any file in the virtual FS. It first looks through the physical search | ||
paths for the file, before searching the file index constructed from the | ||
MegaFiles listed in MegaFiles.xml. The latter is read during Initialization(). | ||
The Asset manager also keeps track of changed files, and notifies the resource | ||
that was loaded from it when this has happened so it can reload itself. | ||
*/ | ||
#include "Assets/Assets.h" | ||
#include "Assets/FileIndex.h" | ||
#include <algorithm> | ||
#include <map> | ||
#include <list> | ||
using namespace std; | ||
|
||
namespace Assets | ||
{ | ||
// Base paths for various asset types. | ||
// Note: They must end with a path delimiter! | ||
static const char* BASE_PATH_CINEMATICS = "Data\\Art\\Cinematics\\"; | ||
static const char* BASE_PATH_MAPS = "Data\\Art\\Maps\\"; | ||
static const char* BASE_PATH_ANIMATIONS = "Data\\Art\\Models\\"; | ||
static const char* BASE_PATH_MODELS = "Data\\Art\\Models\\"; | ||
static const char* BASE_PATH_PARTICLES = "Data\\Art\\Models\\"; | ||
static const char* BASE_PATH_TEXTURES = "Data\\Art\\Textures\\"; | ||
static const char* BASE_PATH_SHADERS = "Data\\Art\\Shaders\\"; | ||
static const char* BASE_PATH_SFX = "Data\\Audio\\SFX\\"; | ||
static const char* BASE_PATH_MUSIC = "Data\\Audio\\Music\\"; | ||
static const char* BASE_PATH_SPEECH = "Data\\Audio\\Speech\\English\\"; | ||
static const char* BASE_PATH_SCRIPTS = "Data\\Scripts\\"; | ||
static const char* BASE_PATH_XML = "Data\\XML\\"; | ||
|
||
ptr<File> LoadXML(const std::string& filename) | ||
{ | ||
static const char* const extensions[] = {"xml", NULL}; | ||
return LoadFile(BASE_PATH_XML + filename, extensions); | ||
} | ||
|
||
ptr<File> LoadTexture(const std::string& filename) | ||
{ | ||
static const char* const extensions[] = {"tga", "dds", NULL}; | ||
return LoadFile(BASE_PATH_TEXTURES + filename, extensions); | ||
} | ||
|
||
ptr<File> LoadAnimation(const std::string& filename) | ||
{ | ||
static const char* const extensions[] = {"ala", NULL}; | ||
return LoadFile(BASE_PATH_ANIMATIONS + filename, extensions); | ||
} | ||
|
||
ptr<File> LoadModelParticle(const std::string& filename) | ||
{ | ||
static const char* const extensions[] = {"alo", NULL}; | ||
return LoadFile(BASE_PATH_MODELS + filename, extensions); | ||
} | ||
|
||
ptr<File> LoadShader(const std::string& filename) | ||
{ | ||
static const char* const extensions[] = {"fx", "fxo"}; | ||
return LoadFile(BASE_PATH_SHADERS + filename, extensions); | ||
} | ||
|
||
ptr<File> LoadMap(const std::string& filename) | ||
{ | ||
static const char* const extensions[] = {"ted", NULL}; | ||
return LoadFile(BASE_PATH_MAPS + filename, extensions); | ||
} | ||
|
||
ptr<File> LoadSFX(const std::string& filename) | ||
{ | ||
static const char* const extensions[] = {"wav", NULL}; | ||
return LoadFile(BASE_PATH_SFX + filename, extensions); | ||
} | ||
|
||
ptr<File> LoadMusic(const std::string& filename) | ||
{ | ||
static const char* const extensions[] = {"mp3", NULL}; | ||
return LoadFile(BASE_PATH_MUSIC + filename, extensions); | ||
} | ||
|
||
ptr<File> LoadSpeech(const std::string& filename) | ||
{ | ||
ptr<File> f; | ||
static const char* const extensions[] = {"mp3", NULL}; | ||
if ((f = LoadFile(BASE_PATH_SPEECH + filename, extensions)) == NULL) | ||
{ | ||
static const char* const extensions[] = {"wav", NULL}; | ||
f = LoadFile(BASE_PATH_SFX + filename, extensions); | ||
} | ||
return f; | ||
} | ||
|
||
ptr<File> LoadScript(const std::string& filename) | ||
{ | ||
static const char* const extensions[] = {"lua", NULL}; | ||
return LoadFile(BASE_PATH_SCRIPTS + filename, extensions); | ||
} | ||
|
||
ptr<File> LoadCinematic(const std::string& filename) | ||
{ | ||
static const char* const extensions[] = {"tec", NULL}; | ||
return LoadFile(BASE_PATH_CINEMATICS + filename, extensions); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef ASSETS_ASSETS_H | ||
#define ASSETS_ASSETS_H | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "Assets/Files.h" | ||
#include "Assets/XML.h" | ||
#include "Assets/MTD.h" | ||
#include "Assets/Models.h" | ||
#include "Assets/Maps.h" | ||
#include "Assets/ParticleSystem.h" | ||
#include "Assets/StringList.h" | ||
|
||
namespace Assets | ||
{ | ||
// Initialize Assets subsystem with this list of search paths. | ||
void Initialize(const std::wstring& mod_path, const std::wstring& main_path, const std::wstring& old_path); | ||
void Uninitialize(); | ||
|
||
// | ||
// Enumerate assets. | ||
// | ||
// Use the filter to enumerate assets in the search paths and MegaFile index. | ||
// The filter accepts ? and * as wildcards. e.g.: "Data\\Art\\Models\\EV_*.ALO" | ||
// | ||
// Returns NULL when no files have been found. Otherwise, GetFileName() and | ||
// GetFileSize() can be used until Next() returns false. | ||
// | ||
class IEnumerator : public Object | ||
{ | ||
public: | ||
virtual bool Next() = 0; | ||
virtual const std::string& GetFileName() const = 0; | ||
virtual size_t GetFileSize() const = 0; | ||
}; | ||
|
||
ptr<IEnumerator> Enumerate(const std::string& filter); | ||
|
||
// | ||
// The following functions load various asset types. | ||
// If they fail for I/O reasons (e.g., file not found, read error, bad file), | ||
// they return NULL. Other exceptions are passed through. | ||
// | ||
ptr<File> LoadFile(const std::string& filename); | ||
ptr<File> LoadTexture(const std::string& filename); | ||
ptr<File> LoadAnimation(const std::string& filename); | ||
ptr<File> LoadModelParticle(const std::string& filename); | ||
ptr<File> LoadMap(const std::string& filename); | ||
ptr<File> LoadShader(const std::string& filename); | ||
ptr<File> LoadXML(const std::string& filename); | ||
ptr<File> LoadSFX(const std::string& filename); | ||
ptr<File> LoadMusic(const std::string& filename); | ||
ptr<File> LoadSpeech(const std::string& filename); | ||
ptr<File> LoadScript(const std::string& filename); | ||
ptr<File> LoadCinematic(const std::string& filename); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
#include "Assets/ChunkFile.h" | ||
#include "General/Exceptions.h" | ||
#include "General/ExactTypes.h" | ||
#include <cassert> | ||
#include <vector> | ||
using namespace std; | ||
|
||
namespace Assets { | ||
|
||
#pragma pack(1) | ||
struct CHUNKHDR | ||
{ | ||
uint32_t type; | ||
uint32_t size; | ||
}; | ||
|
||
struct MINICHUNKHDR | ||
{ | ||
uint8_t type; | ||
uint8_t size; | ||
}; | ||
#pragma pack() | ||
|
||
ChunkType ChunkReader::nextMini() | ||
{ | ||
assert(m_curDepth >= 0); | ||
assert(m_size >= 0); | ||
|
||
if (m_miniSize >= 0) | ||
{ | ||
// We're in a mini chunk, so skip it | ||
skip(); | ||
} | ||
|
||
if (m_file.GetPosition() == m_offsets[m_curDepth]) | ||
{ | ||
// We're at the end of the current chunk, move up one | ||
m_curDepth--; | ||
m_size = -1; | ||
m_position = 0; | ||
return -1; | ||
} | ||
|
||
MINICHUNKHDR hdr; | ||
if (m_file.Read((void*)&hdr, sizeof(MINICHUNKHDR)) != sizeof(MINICHUNKHDR)) | ||
{ | ||
throw ReadException(); | ||
} | ||
|
||
m_miniSize = letohl(hdr.size); | ||
m_miniOffset = m_file.GetPosition() + m_miniSize; | ||
m_position = 0; | ||
|
||
return letohl(hdr.type); | ||
} | ||
|
||
ChunkType ChunkReader::next() | ||
{ | ||
assert(m_curDepth >= 0); | ||
|
||
if (m_size >= 0) | ||
{ | ||
// We're in a data chunk, so skip it | ||
m_file.SetPosition(m_offsets[m_curDepth--]); | ||
} | ||
|
||
if (m_file.GetPosition() == m_offsets[m_curDepth]) | ||
{ | ||
// We're at the end of the current chunk, move up one | ||
m_curDepth--; | ||
m_size = -1; | ||
m_position = 0; | ||
return -1; | ||
} | ||
|
||
CHUNKHDR hdr; | ||
if (m_file.Read((void*)&hdr, sizeof(CHUNKHDR)) != sizeof(CHUNKHDR)) | ||
{ | ||
throw ReadException(); | ||
} | ||
|
||
unsigned long size = letohl(hdr.size); | ||
m_offsets[ ++m_curDepth ] = m_file.GetPosition() + (size & 0x7FFFFFFF); | ||
m_size = (~size & 0x80000000) ? size : -1; | ||
m_miniSize = -1; | ||
m_position = 0; | ||
|
||
return letohl(hdr.type); | ||
} | ||
|
||
void ChunkReader::skip() | ||
{ | ||
if (m_miniSize >= 0) | ||
{ | ||
m_file.SetPosition(m_miniOffset); | ||
} | ||
else | ||
{ | ||
m_file.SetPosition(m_offsets[m_curDepth--]); | ||
m_size = -1; | ||
m_position = 0; | ||
} | ||
} | ||
|
||
size_t ChunkReader::size() | ||
{ | ||
return (m_miniSize >= 0) ? m_miniSize : m_size; | ||
} | ||
|
||
string ChunkReader::readString() | ||
{ | ||
vector<char> data(size() / sizeof(char)); | ||
read(&data[0], size()); | ||
return &data[0]; | ||
} | ||
|
||
wstring ChunkReader::readWideString() | ||
{ | ||
vector<wchar_t> data(size() / sizeof(wchar_t)); | ||
read(&data[0], size()); | ||
return &data[0]; | ||
} | ||
|
||
unsigned char ChunkReader::readByte() | ||
{ | ||
uint8_t value; | ||
read(&value, sizeof(value)); | ||
return value; | ||
} | ||
|
||
unsigned short ChunkReader::readShort() | ||
{ | ||
uint16_t value; | ||
read(&value, sizeof(value)); | ||
return letohs(value); | ||
} | ||
|
||
unsigned long ChunkReader::readInteger() | ||
{ | ||
uint32_t value; | ||
read(&value, sizeof(value)); | ||
return letohl(value); | ||
} | ||
|
||
size_t ChunkReader::read(void* buffer, size_t size, bool check) | ||
{ | ||
if (m_size >= 0) | ||
{ | ||
size_t s = m_file.Read(buffer, min(m_position + (long)size, (long)this->size()) - m_position); | ||
m_position += (long)s; | ||
if (check && s != size) | ||
{ | ||
throw ReadException(); | ||
} | ||
return size; | ||
} | ||
throw ReadException(); | ||
} | ||
|
||
ChunkReader::ChunkReader(File& file) | ||
: m_file(file) | ||
{ | ||
m_offsets[0] = (unsigned long)m_file.GetSize(); | ||
m_curDepth = 0; | ||
m_size = -1; | ||
m_miniSize = -1; | ||
m_file.AddRef(); | ||
m_file.SetPosition(0); | ||
} | ||
|
||
ChunkReader::~ChunkReader() | ||
{ | ||
m_file.Release(); | ||
} | ||
|
||
} |
Oops, something went wrong.