Skip to content

Commit

Permalink
QDENGINE: Rewrite qdTextDB::load
Browse files Browse the repository at this point in the history
Signed-off-by: kunxl-gg <tiwari.25@iitj.ac.in>
  • Loading branch information
kunxl-gg committed Jun 14, 2024
1 parent 95be8a5 commit bd0faa3
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 51 deletions.
7 changes: 4 additions & 3 deletions core/qdcore/qd_game_dispatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
*/

/* ---------------------------- INCLUDE SECTION ----------------------------- */

#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include "common/file.h"
#include "qdengine/core/qd_precomp.h"
#include "qdengine/core/parser/xml_parser.h"

Expand Down Expand Up @@ -477,8 +478,8 @@ void qdGameDispatcher::load_script(const xml::tag *p) {
#endif

if (!texts_database_.empty()) {
XZipStream fh;
if (qdFileManager::instance().open_file(fh, texts_database_.c_str(), false))
Common::SeekableReadStream *fh;
if (qdFileManager::instance().open_file(&fh, texts_database_.c_str(), false))
qdTextDB::instance().load(fh);
} else
qdTextDB::instance().clear();
Expand Down
85 changes: 37 additions & 48 deletions core/qdcore/qd_textdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

/* ---------------------------- INCLUDE SECTION ----------------------------- */

#define FORBIDDEN_SYMBOL_ALLOW_ALL
#include "common/file.h"
#include "qdengine/core/qd_precomp.h"
#include "qdengine/core/qdcore/qd_textdb.h"

Expand Down Expand Up @@ -86,75 +88,62 @@ bool qdTextDB::load(const char *file_name, const char *comments_file_name, bool
}

bool qdTextDB::load(XStream &fh, const char *comments_file_name, bool clear_old_texts) {
if (clear_old_texts) clear();

int text_cnt;
fh > text_cnt;
warning("STUB: qdTextDB::load(%s)", comments_file_name);

std::string id_str(1024, 0);
std::string txt_str(1024, 0);
std::string snd_str(1024, 0);
for (int i = 0; i < text_cnt; i++) {
int id_length;
fh > id_length;
return true;
}

id_str.resize(id_length);
fh.read(&*id_str.begin(), id_length);
bool qdTextDB::load(Common::SeekableReadStream *fh, const char *commentsFileName, bool clearOldTexts) {
if (clearOldTexts) {
clear();
}

int txt_length;
fh > txt_length;
int32 textCount = fh->readUint32LE();
Common::String idStr("", 1024);
Common::String txtStr("", 1024);
Common::String sndStr("", 1024);

txt_str.resize(txt_length);
fh.read(&*txt_str.begin(), txt_length);
for (int i = 0; i < textCount; i++) {
int32 idLength = fh->readUint32LE();
int txtlength = fh->readUint32LE();
int sndLength = fh->readUint32LE();

int snd_length;
fh > snd_length;
fh->read(&idStr, idLength);
fh->read(&txtStr, txtlength);
fh->read(&sndStr, sndLength);

snd_str.resize(snd_length);
fh.read(&*snd_str.begin(), snd_length);
texts_.insert(qdTextMap::value_type(idStr.c_str(), qdText(txtStr.c_str(), sndStr.c_str())));

texts_.insert(qdTextMap::value_type(id_str.c_str(), qdText(txt_str.c_str(), snd_str.c_str())));
}

fh.close();
delete fh;

#ifndef _FINAL_VERSION_
if (comments_file_name) {
XStream fh1;
if (!fh1.open(comments_file_name, XS_IN))
if (commentsFileName) {
Common::File fh1;
if (!fh1.open(commentsFileName)) {
return true;
}

fh1 > text_cnt;
for (int i = 0; i < text_cnt; i++) {
int id_length;
fh1 > id_length;

id_str.resize(id_length);
fh1.read(&*id_str.begin(), id_length);

int txt_length;
fh1 > txt_length;

txt_str.resize(txt_length);
fh1.read(&*txt_str.begin(), txt_length);
textCount = fh1.readUint32LE();
for (int i = 0; i < textCount; i++) {

int snd_length;
fh1 > snd_length;
int32 idLength = fh1.readUint32LE();
int txtLength = fh1.readUint32LE();
int sndLength = fh1.readUint32LE();

snd_str.resize(snd_length);
fh1.read(&*snd_str.begin(), snd_length);
fh1.read(&idStr, idLength);
fh1.read(&txtStr, txtLength);
fh1.read(&sndStr, sndLength);

qdTextMap::iterator it = texts_.find(id_str.c_str());
qdTextMap::iterator it = texts_.find(idStr.c_str());
if (it != texts_.end())
it->second.comment_ = txt_str.c_str();
it->second.comment_ = txtStr.c_str();
}
}
#endif

return true;
}

bool qdTextDB::load(XZipStream &fh, const char *comments_file_name, bool clear_old_texts) {
warning("STUB: qdTextDB::load(%s)", comments_file_name);
if (clear_old_texts) clear();

int text_cnt;
Expand Down
4 changes: 4 additions & 0 deletions core/qdcore/qd_textdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#ifndef __QD_TEXTDB_H__
#define __QD_TEXTDB_H__

namespace Common {
class SeekableReadStream;
}

namespace QDEngine {

Expand Down Expand Up @@ -56,6 +59,7 @@ class qdTextDB {
bool load(const char *file_name, const char *comments_file_name = NULL, bool clear_old_texts = true);
bool load(XStream &fh, const char *comments_file_name = NULL, bool clear_old_texts = true);
bool load(XZipStream &fh, const char *comments_file_name = NULL, bool clear_old_texts = true);
bool load(Common::SeekableReadStream *fh, const char *comments_file_name = NULL, bool clear_old_texts = true);

typedef std::list<std::string> IdList;
void getIdList(const char *mask, IdList &idList) const;
Expand Down

0 comments on commit bd0faa3

Please sign in to comment.