Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/worldmap #29

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
32 changes: 29 additions & 3 deletions Deling.pro
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ HEADERS += MainWindow.h \
BackgroundExporter.h \
EncounterExporter.h \
PreviewWidget.h \
game/worldmap/TexlFile.h \
game/worldmap/WmArchive.h \
game/worldmap/WmEncounter.h \
QLZ4.h \
ScriptExporter.h \
SearchAll.h \
Expand Down Expand Up @@ -111,12 +114,24 @@ HEADERS += MainWindow.h \
ArchiveObserverProgressDialog.h \
ArchiveObservers.h \
ProgressWidget.h \
JsmExpression.h
JsmExpression.h \
game/worldmap/WmxFile.h \
game/worldmap/Map.h \
game/worldmap/MapSegment.h \
game/worldmap/MapBlock.h \
Poly.h \
widgets/WorldmapWidget.h \
widgets/WorldmapGLWidget.h \
game/worldmap/MapPoly.h \
game/worldmap/WmsetFile.h

SOURCES += MainWindow.cpp \
BackgroundExporter.cpp \
EncounterExporter.cpp \
PreviewWidget.cpp \
game/worldmap/TexlFile.cpp \
game/worldmap/WmArchive.cpp \
game/worldmap/WmEncounter.cpp \
QLZ4.cpp \
ScriptExporter.cpp \
SearchAll.cpp \
Expand Down Expand Up @@ -204,7 +219,16 @@ SOURCES += MainWindow.cpp \
ArchiveObserverProgressDialog.cpp \
ArchiveObservers.cpp \
ProgressWidget.cpp \
JsmExpression.cpp
JsmExpression.cpp \
game/worldmap/WmxFile.cpp \
game/worldmap/Map.cpp \
game/worldmap/MapSegment.cpp \
game/worldmap/MapBlock.cpp \
Poly.cpp \
widgets/WorldmapWidget.cpp \
widgets/WorldmapGLWidget.cpp \
game/worldmap/MapPoly.cpp \
game/worldmap/WmsetFile.cpp

TRANSLATIONS += deling_en.ts \
deling_ja.ts \
Expand Down Expand Up @@ -269,7 +293,9 @@ OTHER_FILES += Deling.rc \
appveyor.yml \
fonts/sysfnt.txt \
fonts/sysfnt_demo_jp.txt \
fonts/sysfnt_jp.txt
fonts/sysfnt_jp.txt \
shaders/vertex.glsl \
shaders/fragment.glsl
DISTFILES += Deling.desktop

# call lrelease to make the qm files.
Expand Down
2 changes: 2 additions & 0 deletions Deling.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,7 @@
<file>fonts/sysfnt.tdw</file>
<file>fonts/sysfnt.txt</file>
<file>fonts/sysfnt_jp.txt</file>
<file>shaders/vertex.glsl</file>
<file>shaders/fragment.glsl</file>
</qresource>
</RCC>
6 changes: 6 additions & 0 deletions FF8DiscArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ const FF8DiscFile &FF8DiscArchive::fieldBinFile()
return rootFile(2);
}

const FF8DiscFile &FF8DiscArchive::worldBinFile()
{
return rootFile(26);
}

const QList<FF8DiscFile> &FF8DiscArchive::fieldDirectory()
{
if(!fieldFiles.isEmpty() || 2 >= rootCount()) return fieldFiles;
Expand All @@ -258,6 +263,7 @@ const QList<FF8DiscFile> &FF8DiscArchive::fieldDirectory()
// // nbSectorsLzs != nbSectors
// if((lzsSize + 4)/SECTOR_SIZE_DATA + (int)(lzsSize%SECTOR_SIZE_DATA != 0) != fieldbinFile.getSize()/SECTOR_SIZE_DATA + (int)(fieldbinFile.getSize()%SECTOR_SIZE_DATA != 0))
// return fieldFiles;
qDebug() << fieldbinFile.getPos();

const QByteArray fieldBin = !isDemo() ? fileLZS(fieldbinFile, false) : file(fieldbinFile);
if(fieldBin.isEmpty())
Expand Down
1 change: 1 addition & 0 deletions FF8DiscArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class FF8DiscArchive : public IsoArchive
const FF8DiscFile &rootFile(int id);
const FF8DiscFile &sysFntTdwFile();
const FF8DiscFile &fieldBinFile();
const FF8DiscFile &worldBinFile();
// QList<FF8DiscFile> worldmapDirectory();
// FF8DiscFile worldmapFile(int id);
const QList<FF8DiscFile> &fieldDirectory();
Expand Down
12 changes: 5 additions & 7 deletions FsArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,11 @@ FsArchive::FsArchive(const QByteArray &fl_data, const QByteArray &fi_data)
}

FsArchive::FsArchive(const QString &path)
: fromFile(true), _isOpen(false)
: fromFile(false), _isOpen(false)
{
load(path);
if (!path.isEmpty()) {
open(path);
}
}

FsArchive::~FsArchive()
Expand Down Expand Up @@ -942,7 +944,7 @@ bool FsArchive::load(const QByteArray &fl_data, const QByteArray &fi_data)
return true;
}

bool FsArchive::load(const QString &path)
bool FsArchive::open(const QString &path)
{
if(_isOpen) return false;

Expand Down Expand Up @@ -1266,19 +1268,16 @@ bool FsArchive::verify()
qWarning() << "FsArchive::verify io error" << fs.errorString();
return false;
}

if(size > 4478885) {
qWarning() << "FsArchive::verify strange size" << size;
}

if(guessPos != info->position()) {
qWarning() << "FsArchive::verify ko" << info->position() << guessPos << size << info->uncompressedSize() << quint32(info->compression());
} else {
qWarning() << "FsArchive::verify ok" << info->position() << guessPos << size << info->uncompressedSize() << quint32(info->compression());
}
guessPos += size;
}

return true;
}

Expand Down Expand Up @@ -1368,7 +1367,6 @@ bool FsArchive::repair(FsArchive *other)
}
if(guessPos != info->position()) {
info->setPosition(guessPos);

changePositions(info, guessPos - info->position());
}
guessPos += size;
Expand Down
4 changes: 2 additions & 2 deletions FsArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ class FsArchive

// FsArchive();
FsArchive(const QByteArray &fl_data, const QByteArray &fi_data);
explicit FsArchive(const QString &path);
explicit FsArchive(const QString &path = QString());
virtual ~FsArchive();

bool open(const QString &path);
void addFile(const QString &path, FiCompression compression);
FsHeader *getFile(const QString &path) const;
void fileToTheEnd(const QString &path, QByteArray &fs_data);
Expand Down Expand Up @@ -145,7 +146,6 @@ class FsArchive
static QStringList listDirsRec(QDir *sourceDir);

bool load(const QByteArray &fl_data, const QByteArray &fi_data);
bool load(const QString &path);

static bool searchData(const QMultiMap<quint32, FsHeader *> &headers,
QFile *fs, const QByteArray &data, quint32 &pos);
Expand Down
2 changes: 1 addition & 1 deletion MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ void MainWindow::exportCurrent()
QString selectedFilter;
path = QFileDialog::getSaveFileName(this, tr("Exporter"), path, filter.join(";;"), &selectedFilter);
if(path.isNull()) return;

int type = typeList.at(filter.indexOf(selectedFilter));

switch(type) {
Expand Down
123 changes: 123 additions & 0 deletions Poly.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#include "Poly.h"

Poly::Poly(int count, const QList<Vertex> &vertices,
const QList<Vertex> &normals, const QList<QRgb> &colors,
const QList<TexCoord> &texCoords) :
_count(count), _normals(normals)
{
setVertices(vertices, colors, texCoords);
}

Poly::Poly(int count, const QList<Vertex> &vertices,
const QList<Vertex> &normals, const QRgb &color,
const QList<TexCoord> &texCoords) :
_count(count), _normals(normals)
{
setVertices(vertices, color, texCoords);
}

void Poly::setVertices(const QList<Vertex> &vertices, const QList<QRgb> &colors,
const QList<TexCoord> &texCoords)
{
_vertices = vertices;
_colors = colors;
_texCoords = texCoords;
}

void Poly::setVertices(const QList<Vertex> &vertices, const QRgb &color,
const QList<TexCoord> &texCoords)
{
_vertices = vertices;
_colors.clear();
_colors.append(color);
_texCoords = texCoords;
}

const Vertex &Poly::vertex(quint8 id) const
{
return _vertices.at(id);
}

const Vertex &Poly::normal(quint8 id) const
{
return _normals.at(id);
}

const QRgb &Poly::color() const
{
return _colors.first();
}

QRgb Poly::color(quint8 id) const
{
return _colors.value(id, _colors.first());
}

const TexCoord &Poly::texCoord(quint8 id) const
{
return _texCoords.at(id);
}

void Poly::setTexCoord(quint8 id, const TexCoord &texCoord)
{
_texCoords.replace(id, texCoord);
}

bool Poly::isMonochrome() const
{
return _colors.size() == 1;
}

bool Poly::hasTexture() const
{
return !_texCoords.isEmpty();
}

QuadPoly::QuadPoly(const QList<Vertex> &vertices,
const QList<Vertex> &normals, const QList<QRgb> &colors,
const QList<TexCoord> &texCoords) :
Poly(4, vertices, normals, colors, texCoords)
{
// swapping the two last vertices for right OpenGL quad order

_vertices.swap(2, 3);
_normals.swap(2, 3);

if(colors.size() == 4) {
_colors.swap(2, 3);
}

if(!texCoords.isEmpty()) {
_texCoords.swap(2, 3);
}
}

QuadPoly::QuadPoly(const QList<Vertex> &vertices,
const QList<Vertex> &normals, const QRgb &color,
const QList<TexCoord> &texCoords) :
Poly(4, vertices, normals, color, texCoords)
{
// swapping the two last vertices for right OpenGL quad order

_vertices.swap(2, 3);
_normals.swap(2, 3);

if(!texCoords.isEmpty()) {
_texCoords.swap(2, 3);
}
}

TrianglePoly::TrianglePoly(const QList<Vertex> &vertices,
const QList<Vertex> &normals,
const QList<QRgb> &colors,
const QList<TexCoord> &texCoords) :
Poly(3, vertices, normals, colors, texCoords)
{
}

TrianglePoly::TrianglePoly(const QList<Vertex> &vertices,
const QList<Vertex> &normals, const QRgb &color,
const QList<TexCoord> &texCoords) :
Poly(3, vertices, normals, color, texCoords)
{
}
88 changes: 88 additions & 0 deletions Poly.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#ifndef POLY_H
#define POLY_H

#include <QtCore>
#include <QRgb>

struct Vertex {
qint16 x, y, z;
};

inline bool operator==(const Vertex &v1, const Vertex &v2)
{
return v1.x == v2.x && v1.y == v2.y && v1.z == v2.z;
}

inline uint qHash(const Vertex &key, uint seed)
{
return qHash(quint64(key.x | (key.y << 16)) | (quint64(key.z) << 32), seed);
}

struct TexCoord {
quint8 x, y;
};

class Poly
{
public:
Poly(int count, const QList<Vertex> &vertices, const QList<Vertex> &normals,
const QList<QRgb> &colors,
const QList<TexCoord> &texCoords=QList<TexCoord>());
Poly(int count, const QList<Vertex> &vertices, const QList<Vertex> &normals,
const QRgb &color,
const QList<TexCoord> &texCoords=QList<TexCoord>());
virtual ~Poly() {}
void setVertices(const QList<Vertex> &vertices, const QList<QRgb> &colors,
const QList<TexCoord> &texCoords=QList<TexCoord>());
void setVertices(const QList<Vertex> &vertices, const QRgb &color,
const QList<TexCoord> &texCoords=QList<TexCoord>());
inline int count() const {
return _count;
}
const Vertex &vertex(quint8 id) const;
const Vertex &normal(quint8 id) const;
inline const QList<Vertex> &vertices() const {
return _vertices;
}
inline const QList<Vertex> &normals() const {
return _normals;
}
const QRgb &color() const;
QRgb color(quint8 id) const;
const TexCoord &texCoord(quint8 id) const;
void setTexCoord(quint8 id, const TexCoord &texCoord);
inline const QList<TexCoord> &texCoords() const {
return _texCoords;
}
bool isMonochrome() const;
bool hasTexture() const;
protected:
int _count;
QList<Vertex> _vertices, _normals;
QList<QRgb> _colors;
QList<TexCoord> _texCoords;
};

class QuadPoly : public Poly
{
public:
QuadPoly(const QList<Vertex> &vertices, const QList<Vertex> &normals,
const QList<QRgb> &colors,
const QList<TexCoord> &texCoords=QList<TexCoord>());
QuadPoly(const QList<Vertex> &vertices, const QList<Vertex> &normals,
const QRgb &color,
const QList<TexCoord> &texCoords=QList<TexCoord>());
};

class TrianglePoly : public Poly
{
public:
TrianglePoly(const QList<Vertex> &vertices, const QList<Vertex> &normals,
const QList<QRgb> &colors,
const QList<TexCoord> &texCoords=QList<TexCoord>());
TrianglePoly(const QList<Vertex> &vertices, const QList<Vertex> &normals,
const QRgb &color,
const QList<TexCoord> &texCoords=QList<TexCoord>());
};

#endif // POLY_H
Loading