Skip to content

Commit

Permalink
Adding Worldmap classes (not yet enabled)
Browse files Browse the repository at this point in the history
  • Loading branch information
myst6re committed Feb 26, 2024
1 parent c5f671f commit ee6d4af
Show file tree
Hide file tree
Showing 59 changed files with 4,125 additions and 89 deletions.
28 changes: 27 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ if(NOT PRERELEASE_STRING)
set(PRERELEASE_STRING "")
endif()

project("Deling" VERSION 2.0.0 LANGUAGES CXX
project("Deling" VERSION 1.0.0 LANGUAGES CXX
DESCRIPTION "Final Fantasy VIII field archive editor"
HOMEPAGE_URL "https://github.com/myst6re/deling"
)
Expand Down Expand Up @@ -170,6 +170,26 @@ set(PROJECT_SOURCES
"src/FsPreviewWidget.h"
"src/FsWidget.cpp"
"src/FsWidget.h"
"src/game/worldmap/Map.cpp"
"src/game/worldmap/Map.h"
"src/game/worldmap/MapBlock.cpp"
"src/game/worldmap/MapBlock.h"
"src/game/worldmap/MapPoly.cpp"
"src/game/worldmap/MapPoly.h"
"src/game/worldmap/MapSegment.cpp"
"src/game/worldmap/MapSegment.h"
"src/game/worldmap/ObjFile.cpp"
"src/game/worldmap/ObjFile.h"
"src/game/worldmap/TexlFile.cpp"
"src/game/worldmap/TexlFile.h"
"src/game/worldmap/WmArchive.cpp"
"src/game/worldmap/WmArchive.h"
"src/game/worldmap/WmEncounter.cpp"
"src/game/worldmap/WmEncounter.h"
"src/game/worldmap/WmsetFile.cpp"
"src/game/worldmap/WmsetFile.h"
"src/game/worldmap/WmxFile.cpp"
"src/game/worldmap/WmxFile.h"
"src/GZIP.cpp"
"src/GZIP.h"
"src/HexLineEdit.cpp"
Expand Down Expand Up @@ -201,6 +221,8 @@ set(PROJECT_SOURCES
"src/OrientationWidget.h"
"src/PlainTextEdit.cpp"
"src/PlainTextEdit.h"
"src/Poly.cpp"
"src/Poly.h"
"src/PreviewWidget.cpp"
"src/PreviewWidget.h"
"src/ProgressWidget.cpp"
Expand Down Expand Up @@ -263,6 +285,10 @@ set(PROJECT_SOURCES
"src/widgets/TdwWidget2.h"
"src/widgets/WalkmeshWidget.cpp"
"src/widgets/WalkmeshWidget.h"
"src/widgets/WorldmapGLWidget.cpp"
"src/widgets/WorldmapGLWidget.h"
"src/widgets/WorldmapWidget.cpp"
"src/widgets/WorldmapWidget.h"
)

if(APPLE)
Expand Down
Binary file removed src/.DS_Store
Binary file not shown.
5 changes: 5 additions & 0 deletions src/FF8DiscArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,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 Down
1 change: 1 addition & 0 deletions src/FF8DiscArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class FF8DiscArchive : public IsoArchive
const FF8DiscFile &fieldBinFile();
// QList<FF8DiscFile> worldmapDirectory();
// FF8DiscFile worldmapFile(int id);
const FF8DiscFile &worldBinFile();
const QList<FF8DiscFile> &fieldDirectory();
int fieldCount();
const FF8DiscFile &fieldFile(int id);
Expand Down
4 changes: 2 additions & 2 deletions src/FieldArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ QMap<int, int> FieldArchive::searchAllOpcodeTypes() const
return ret;
}

QList<Vertex_s> FieldArchive::searchAllSavePoints() const
QList<Vertex> FieldArchive::searchAllSavePoints() const
{
QList<Vertex_s> ret;
QList<Vertex> ret;

for (Field *field: fields) {
if (field->hasJsmFile()) {
Expand Down
4 changes: 2 additions & 2 deletions src/FieldArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

#include <QtCore>
#include "files/JsmFile.h"
#include "files/CaFile.h"
#include "Poly.h"

class Field;
struct ArchiveObserver;
Expand Down Expand Up @@ -63,7 +63,7 @@ class FieldArchive
QMap<Field *, QList<int> > searchAllBattles() const;
QMultiMap<int, Field *> searchAllMoments() const;
QMap<int, int> searchAllOpcodeTypes() const;
QList<Vertex_s> searchAllSavePoints() const;
QList<Vertex> searchAllSavePoints() const;
QStringList fieldList() const;
const QStringList &mapList() const;
void setMapList(const QStringList &mapList);
Expand Down
8 changes: 5 additions & 3 deletions src/FsArchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,9 +293,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 @@ -947,7 +949,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
6 changes: 3 additions & 3 deletions src/FsArchive.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,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 @@ -143,7 +144,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
123 changes: 123 additions & 0 deletions src/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.swapItemsAt(2, 3);
_normals.swapItemsAt(2, 3);

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

if(!texCoords.isEmpty()) {
_texCoords.swapItemsAt(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.swapItemsAt(2, 3);
_normals.swapItemsAt(2, 3);

if(!texCoords.isEmpty()) {
_texCoords.swapItemsAt(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)
{
}
102 changes: 102 additions & 0 deletions src/Poly.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/****************************************************************************
** Deling Final Fantasy VIII Field Editor
** Copyright (C) 2009-2024 Arzel Jérôme <myst6re@gmail.com>
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#pragma once

#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 size_t 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>());
};
6 changes: 3 additions & 3 deletions src/VertexWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,16 @@ VertexWidget::VertexWidget(QWidget *parent) :
connect(z, SIGNAL(valueChanged(int)), SLOT(emitValuesChanged()));
}

Vertex_s VertexWidget::values() const
Vertex VertexWidget::values() const
{
Vertex_s v;
Vertex v;
v.x = x->value();
v.y = y->value();
v.z = z->value();
return v;
}

void VertexWidget::setValues(const Vertex_s &v)
void VertexWidget::setValues(const Vertex &v)
{
dontEmit = true;
x->setValue(v.x);
Expand Down
Loading

0 comments on commit ee6d4af

Please sign in to comment.