1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-15 06:52:34 +02:00

clang-format files in rwviewer

This commit is contained in:
Daniel Evans 2016-09-09 21:13:21 +01:00
parent 8a19f9b5d0
commit d1c33af268
15 changed files with 692 additions and 760 deletions

View File

@ -1,35 +1,32 @@
#include "AnimationListModel.hpp" #include "AnimationListModel.hpp"
QVariant AnimationListModel::data(const QModelIndex& index, int role) const QVariant AnimationListModel::data(const QModelIndex& index, int role) const {
{ if (role == Qt::DisplayRole) {
if(role == Qt::DisplayRole) { if (index.row() >= 0 && (unsigned)index.row() < animations.size()) {
if(index.row() >= 0 && (unsigned) index.row() < animations.size()) { auto& f = animations.at(index.row());
auto& f = animations.at(index.row()); if (index.column() == 0) {
if(index.column() == 0) { return QString(f.first.c_str());
return QString(f.first.c_str()); }
} }
} }
} return QVariant::Invalid;
return QVariant::Invalid;
} }
QVariant AnimationListModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant AnimationListModel::headerData(int section,
{ Qt::Orientation orientation,
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) { int role) const {
if(section == 0) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
return "Name"; if (section == 0) {
} return "Name";
} }
return QVariant::Invalid; }
return QVariant::Invalid;
} }
int AnimationListModel::rowCount(const QModelIndex& parent) const int AnimationListModel::rowCount(const QModelIndex& parent) const {
{ return animations.size();
return animations.size();
} }
int AnimationListModel::columnCount(const QModelIndex& parent) const int AnimationListModel::columnCount(const QModelIndex& parent) const {
{ return 1;
return 1;
} }

View File

@ -1,4 +1,4 @@
#pragma once #pragma once
#ifndef _ANIMATIONLISTMODEL_HPP_ #ifndef _ANIMATIONLISTMODEL_HPP_
#define _ANIMATIONLISTMODEL_HPP_ #define _ANIMATIONLISTMODEL_HPP_
#include <QAbstractItemModel> #include <QAbstractItemModel>
@ -6,27 +6,29 @@
typedef std::vector<std::pair<std::string, Animation*>> AnimationList; typedef std::vector<std::pair<std::string, Animation*>> AnimationList;
class AnimationListModel : public QAbstractListModel class AnimationListModel : public QAbstractListModel {
{ Q_OBJECT
Q_OBJECT
AnimationList animations;
AnimationList animations;
public: public:
AnimationListModel(const AnimationList& anims, QObject* parent = 0)
AnimationListModel(const AnimationList& anims, QObject* parent = 0) : QAbstractListModel(parent), animations(anims) {
: QAbstractListModel(parent), animations(anims) }
{}
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
const AnimationList& getAnimations() const { return animations; } int role = Qt::DisplayRole) const;
const AnimationList& getAnimations() const {
return animations;
}
}; };
#endif #endif

View File

@ -2,47 +2,45 @@
#include <QVBoxLayout> #include <QVBoxLayout>
AnimationListWidget::AnimationListWidget(QWidget* parent, Qt::WindowFlags flags) AnimationListWidget::AnimationListWidget(QWidget* parent, Qt::WindowFlags flags)
: QDockWidget(parent, flags), filter(nullptr), model(nullptr) : QDockWidget(parent, flags), filter(nullptr), model(nullptr) {
{ setWindowTitle("Animations");
setWindowTitle("Animations"); QVBoxLayout* layout = new QVBoxLayout();
QVBoxLayout* layout = new QVBoxLayout(); QWidget* intermediate = new QWidget();
QWidget* intermediate = new QWidget();
searchbox = new QLineEdit(); searchbox = new QLineEdit();
searchbox->setPlaceholderText("Search"); searchbox->setPlaceholderText("Search");
table = new QListView(); table = new QListView();
layout->addWidget(searchbox); layout->addWidget(searchbox);
layout->addWidget(table); layout->addWidget(table);
intermediate->setLayout(layout); intermediate->setLayout(layout);
setWidget(intermediate); setWidget(intermediate);
filter = new QSortFilterProxyModel; filter = new QSortFilterProxyModel;
table->setModel(filter); table->setModel(filter);
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedIndexChanged(QModelIndex))); connect(table->selectionModel(),
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString))); SIGNAL(currentChanged(QModelIndex, QModelIndex)),
SLOT(selectedIndexChanged(QModelIndex)));
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
} }
void AnimationListWidget::setAnimations(const AnimationList& archive) void AnimationListWidget::setAnimations(const AnimationList& archive) {
{ auto m = new AnimationListModel(archive);
auto m = new AnimationListModel(archive); filter->setSourceModel(m);
filter->setSourceModel(m); if (model) {
if(model) { delete model;
delete model; }
} model = m;
model = m;
} }
void AnimationListWidget::selectedIndexChanged(const QModelIndex& current) void AnimationListWidget::selectedIndexChanged(const QModelIndex& current) {
{ auto mts = filter->mapToSource(current);
auto mts = filter->mapToSource(current); if (mts.row() >= 0 && (unsigned)mts.row() < model->getAnimations().size()) {
if(mts.row() >= 0 && (unsigned) mts.row() < model->getAnimations().size()) { auto& f = model->getAnimations().at(mts.row());
auto& f = model->getAnimations().at(mts.row()); emit selectedAnimationChanged(f.second);
emit selectedAnimationChanged(f.second); }
}
} }
void AnimationListWidget::setFilter(const QString &f) void AnimationListWidget::setFilter(const QString& f) {
{ filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
} }

View File

@ -2,34 +2,32 @@
#ifndef _ANIMATIONLISTWIDGET_HPP_ #ifndef _ANIMATIONLISTWIDGET_HPP_
#define _ANIMATIONLISTWIDGET_HPP_ #define _ANIMATIONLISTWIDGET_HPP_
#include <QDockWidget> #include <QDockWidget>
#include <QListView>
#include <QLineEdit> #include <QLineEdit>
#include <QListView>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include "AnimationListModel.hpp" #include "AnimationListModel.hpp"
class AnimationListWidget : public QDockWidget class AnimationListWidget : public QDockWidget {
{ Q_OBJECT
Q_OBJECT
QSortFilterProxyModel* filter;
AnimationListModel* model;
QListView* table;
QLineEdit* searchbox;
QSortFilterProxyModel* filter;
AnimationListModel* model;
QListView* table;
QLineEdit* searchbox;
public: public:
AnimationListWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
AnimationListWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0); void setAnimations(const AnimationList& anims);
void setAnimations(const AnimationList& anims);
signals: signals:
void selectedAnimationChanged(Animation* anim); void selectedAnimationChanged(Animation* anim);
public slots: public slots:
void selectedIndexChanged(const QModelIndex& current); void selectedIndexChanged(const QModelIndex& current);
void setFilter(const QString& f); void setFilter(const QString& f);
}; };
#endif #endif

View File

@ -1,41 +1,38 @@
#include "IMGArchiveModel.hpp" #include "IMGArchiveModel.hpp"
QVariant IMGArchiveModel::data(const QModelIndex& index, int role) const QVariant IMGArchiveModel::data(const QModelIndex& index, int role) const {
{ if (role == Qt::DisplayRole) {
if(role == Qt::DisplayRole) { if (index.row() >= 0 &&
if(index.row() >= 0 && (unsigned) index.row() < archive.getAssetCount()) { (unsigned)index.row() < archive.getAssetCount()) {
auto& f = archive.getAssetInfoByIndex(index.row()); auto& f = archive.getAssetInfoByIndex(index.row());
if(index.column() == 0) { if (index.column() == 0) {
return QString(f.name); return QString(f.name);
} }
if(index.column() == 1) { if (index.column() == 1) {
return f.size; return f.size;
} }
} }
} }
return QVariant::Invalid; return QVariant::Invalid;
} }
QVariant IMGArchiveModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant IMGArchiveModel::headerData(int section, Qt::Orientation orientation,
{ int role) const {
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
if(section == 0) { if (section == 0) {
return "Name"; return "Name";
} }
if(section == 1) { if (section == 1) {
return "Size"; return "Size";
} }
} }
return QVariant::Invalid; return QVariant::Invalid;
} }
int IMGArchiveModel::rowCount(const QModelIndex& parent) const int IMGArchiveModel::rowCount(const QModelIndex& parent) const {
{ return archive.getAssetCount();
return archive.getAssetCount();
} }
int IMGArchiveModel::columnCount(const QModelIndex& parent) const int IMGArchiveModel::columnCount(const QModelIndex& parent) const {
{ return 2;
return 2;
} }

View File

@ -1,30 +1,32 @@
#pragma once #pragma once
#ifndef _IMGARCHIVEMODEL_HPP_ #ifndef _IMGARCHIVEMODEL_HPP_
#define _IMGARCHIVEMODEL_HPP_ #define _IMGARCHIVEMODEL_HPP_
#include <QAbstractItemModel> #include <QAbstractItemModel>
#include <loaders/LoaderIMG.hpp> #include <loaders/LoaderIMG.hpp>
class IMGArchiveModel : public QAbstractListModel class IMGArchiveModel : public QAbstractListModel {
{ Q_OBJECT
Q_OBJECT
LoaderIMG archive;
LoaderIMG archive;
public: public:
IMGArchiveModel(const LoaderIMG& archive, QObject* parent = 0) IMGArchiveModel(const LoaderIMG& archive, QObject* parent = 0)
: QAbstractListModel(parent), archive(archive) : QAbstractListModel(parent), archive(archive) {
{} }
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation,
const LoaderIMG& getArchive() const { return archive; } int role = Qt::DisplayRole) const;
const LoaderIMG& getArchive() const {
return archive;
}
}; };
#endif #endif

View File

@ -1,60 +1,55 @@
#include "ItemListModel.hpp" #include "ItemListModel.hpp"
#include <engine/GameData.hpp> #include <engine/GameData.hpp>
qint16 ItemListModel::getIDOf(unsigned int row) const qint16 ItemListModel::getIDOf(unsigned int row) const {
{ if (row < world()->data->objectTypes.size()) {
if( row < world()->data->objectTypes.size() ) return row;
{ }
return row;
}
return -1; return -1;
} }
ItemListModel::ItemListModel(GameWorld *world, QObject *parent) : ItemListModel::ItemListModel(GameWorld *world, QObject *parent)
QAbstractTableModel(parent), _world( world ) : QAbstractTableModel(parent), _world(world) {
{
} }
int ItemListModel::rowCount(const QModelIndex &parent) const int ItemListModel::rowCount(const QModelIndex &parent) const {
{ return _world->data->objectTypes.size();
return _world->data->objectTypes.size();
} }
int ItemListModel::columnCount(const QModelIndex &parent) const int ItemListModel::columnCount(const QModelIndex &parent) const {
{ return 2;
return 2;
} }
QVariant ItemListModel::data(const QModelIndex &index, int role) const QVariant ItemListModel::data(const QModelIndex &index, int role) const {
{ if (role == Qt::DisplayRole) {
if ( role == Qt::DisplayRole ) { qint16 id = getIDOf(index.row());
qint16 id = getIDOf(index.row()); if (id == -1) return QVariant::Invalid;
if( id == -1 ) return QVariant::Invalid; if (index.column() == 0) {
if( index.column() == 0 ) { return id;
return id; } else if (index.column() == 1) {
} return QString::fromStdString("TODO");
else if ( index.column() == 1 ) { }
return QString::fromStdString("TODO"); }
} return QVariant::Invalid;
}
return QVariant::Invalid;
} }
QVariant ItemListModel::headerData(int section, Qt::Orientation orientation, int role) const QVariant ItemListModel::headerData(int section, Qt::Orientation orientation,
{ int role) const {
if(role == Qt::DisplayRole && orientation == Qt::Horizontal) { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
if(section == 0) { if (section == 0) {
return "ID"; return "ID";
} }
if(section == 1) { if (section == 1) {
return "Model"; return "Model";
} }
} }
return QVariant::Invalid; return QVariant::Invalid;
} }
QModelIndex ItemListModel::index(int row, int column, const QModelIndex &parent) const QModelIndex ItemListModel::index(int row, int column,
{ const QModelIndex &parent) const {
return hasIndex(row, column, parent) ? createIndex(row, column, getIDOf(row)) : QModelIndex(); return hasIndex(row, column, parent)
? createIndex(row, column, getIDOf(row))
: QModelIndex();
} }

View File

@ -5,28 +5,31 @@
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
class ItemListModel : public QAbstractTableModel class ItemListModel : public QAbstractTableModel {
{ Q_OBJECT
Q_OBJECT
GameWorld* _world; GameWorld* _world;
public: public:
explicit ItemListModel(GameWorld* _world, QObject *parent = 0); explicit ItemListModel(GameWorld* _world, QObject* parent = 0);
GameWorld* world() const { return _world; } GameWorld* world() const {
return _world;
}
qint16 getIDOf(unsigned int row ) const; qint16 getIDOf(unsigned int row) const;
virtual int rowCount(const QModelIndex& parent = QModelIndex()) const; virtual int rowCount(const QModelIndex& parent = QModelIndex()) const;
virtual int columnCount(const QModelIndex& parent = QModelIndex()) const; virtual int columnCount(const QModelIndex& parent = QModelIndex()) const;
virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const; virtual QVariant data(const QModelIndex& index,
int role = Qt::DisplayRole) const;
virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; virtual QVariant headerData(int section, Qt::Orientation orientation,
int role = Qt::DisplayRole) const;
QModelIndex index(int row, int column, const QModelIndex &parent) const; QModelIndex index(int row, int column, const QModelIndex& parent) const;
}; };
#endif // ITEMLISTMODEL_HPP #endif // ITEMLISTMODEL_HPP

View File

@ -1,47 +1,45 @@
#include "ItemListWidget.hpp" #include "ItemListWidget.hpp"
#include <QVBoxLayout>
#include <QHeaderView> #include <QHeaderView>
#include <QVBoxLayout>
ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags) ItemListWidget::ItemListWidget(QWidget* parent, Qt::WindowFlags flags)
: QDockWidget(parent, flags), filter(nullptr), model(nullptr) : QDockWidget(parent, flags), filter(nullptr), model(nullptr) {
{ setWindowTitle("Items");
setWindowTitle("Items"); QVBoxLayout* layout = new QVBoxLayout();
QVBoxLayout* layout = new QVBoxLayout(); QWidget* intermediate = new QWidget();
QWidget* intermediate = new QWidget();
searchbox = new QLineEdit(); searchbox = new QLineEdit();
searchbox->setPlaceholderText("Search"); searchbox->setPlaceholderText("Search");
table = new QTableView(); table = new QTableView();
layout->addWidget(searchbox); layout->addWidget(searchbox);
layout->addWidget(table); layout->addWidget(table);
table->setSelectionBehavior(QAbstractItemView::SelectRows); table->setSelectionBehavior(QAbstractItemView::SelectRows);
intermediate->setLayout(layout); intermediate->setLayout(layout);
setWidget(intermediate); setWidget(intermediate);
filter = new QSortFilterProxyModel; filter = new QSortFilterProxyModel;
table->setModel(filter); table->setModel(filter);
filter->setFilterKeyColumn(-1); // Search all columns filter->setFilterKeyColumn(-1); // Search all columns
connect(table->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), SLOT(selectedIndexChanged(QModelIndex))); connect(table->selectionModel(),
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString))); SIGNAL(currentChanged(QModelIndex, QModelIndex)),
SLOT(selectedIndexChanged(QModelIndex)));
connect(searchbox, SIGNAL(textChanged(QString)), SLOT(setFilter(QString)));
} }
void ItemListWidget::worldLoaded(GameWorld *world) void ItemListWidget::worldLoaded(GameWorld* world) {
{ if (model) delete model;
if ( model ) delete model; model = new ItemListModel(world, this);
model = new ItemListModel( world, this ); filter->setSourceModel(model);
filter->setSourceModel( model );
} }
void ItemListWidget::selectedIndexChanged(const QModelIndex& current) void ItemListWidget::selectedIndexChanged(const QModelIndex& current) {
{ auto mts = filter->mapToSource(current);
auto mts = filter->mapToSource(current); if (mts.isValid()) {
if( mts.isValid() ) { emit selectedItemChanged(model->getIDOf(mts.row()));
emit selectedItemChanged( model->getIDOf(mts.row()) ); }
}
} }
void ItemListWidget::setFilter(const QString &f) void ItemListWidget::setFilter(const QString& f) {
{ filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
filter->setFilterRegExp(QRegExp(f, Qt::CaseInsensitive));
} }

View File

@ -2,33 +2,32 @@
#ifndef _ITEMLISTWIDGET_HPP_ #ifndef _ITEMLISTWIDGET_HPP_
#define _ITEMLISTWIDGET_HPP_ #define _ITEMLISTWIDGET_HPP_
#include <QDockWidget> #include <QDockWidget>
#include <QTableView>
#include <QLineEdit> #include <QLineEdit>
#include <QSortFilterProxyModel> #include <QSortFilterProxyModel>
#include <QTableView>
#include "ItemListModel.hpp" #include "ItemListModel.hpp"
class ItemListWidget : public QDockWidget class ItemListWidget : public QDockWidget {
{ Q_OBJECT
Q_OBJECT
QSortFilterProxyModel* filter;
ItemListModel* model;
QTableView* table;
QLineEdit* searchbox;
QSortFilterProxyModel* filter;
ItemListModel* model;
QTableView* table;
QLineEdit* searchbox;
public: public:
ItemListWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0); ItemListWidget(QWidget* parent = 0, Qt::WindowFlags flags = 0);
signals: signals:
void selectedItemChanged(const qint16 id); void selectedItemChanged(const qint16 id);
public slots: public slots:
void worldLoaded(GameWorld* world); void worldLoaded(GameWorld* world);
void selectedIndexChanged(const QModelIndex& current); void selectedIndexChanged(const QModelIndex& current);
void setFilter(const QString& f); void setFilter(const QString& f);
}; };
#endif #endif

View File

@ -1,239 +1,214 @@
#include "ViewerWidget.hpp" #include "ViewerWidget.hpp"
#include <QFileDialog>
#include <QMouseEvent>
#include <algorithm>
#include <data/Model.hpp> #include <data/Model.hpp>
#include <data/Skeleton.hpp>
#include <engine/Animator.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <objects/GameObject.hpp>
#include <render/GameRenderer.hpp> #include <render/GameRenderer.hpp>
#include <render/OpenGLRenderer.hpp> #include <render/OpenGLRenderer.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <QMouseEvent>
#include <objects/GameObject.hpp>
#include <engine/Animator.hpp>
#include <data/Skeleton.hpp>
#include <QFileDialog>
#include <algorithm>
#include <objects/InstanceObject.hpp>
#include <objects/CharacterObject.hpp> #include <objects/CharacterObject.hpp>
#include <objects/InstanceObject.hpp>
#include <objects/VehicleObject.hpp> #include <objects/VehicleObject.hpp>
ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent,
ViewerWidget::ViewerWidget(QGLFormat g, QWidget* parent, const QGLWidget* shareWidget, Qt::WindowFlags f) const QGLWidget* shareWidget, Qt::WindowFlags f)
: QGLWidget(g, parent, shareWidget, f) : QGLWidget(g, parent, shareWidget, f)
, gworld(nullptr) , gworld(nullptr)
, activeModel(nullptr) , activeModel(nullptr)
, selectedFrame(nullptr) , selectedFrame(nullptr)
, dummyObject(nullptr) , dummyObject(nullptr)
, currentObjectID(0) , currentObjectID(0)
, _lastModel(nullptr) , _lastModel(nullptr)
, canimation(nullptr) , canimation(nullptr)
, viewDistance(1.f) , viewDistance(1.f)
, dragging(false) , dragging(false)
, moveFast(false) , moveFast(false)
, _frameWidgetDraw(nullptr) , _frameWidgetDraw(nullptr)
, _frameWidgetGeom(nullptr) , _frameWidgetGeom(nullptr) {
{ setFocusPolicy(Qt::StrongFocus);
setFocusPolicy(Qt::StrongFocus);
} }
struct WidgetVertex { struct WidgetVertex {
float x, y, z; float x, y, z;
static const AttributeList vertex_attributes() { static const AttributeList vertex_attributes() {
return { return {{ATRS_Position, 3, sizeof(WidgetVertex), 0ul}};
{ATRS_Position, 3, sizeof(WidgetVertex), 0ul} }
};
}
}; };
std::vector<WidgetVertex> widgetVerts = { std::vector<WidgetVertex> widgetVerts = {{-.5f, 0.f, 0.f}, {.5f, 0.f, 0.f},
{-.5f, 0.f, 0.f}, {0.f, -.5f, 0.f}, {0.f, .5f, 0.f},
{ .5f, 0.f, 0.f}, {0.f, 0.f, -.5f}, {0.f, 0.f, .5f}};
{ 0.f,-.5f, 0.f},
{ 0.f, .5f, 0.f},
{ 0.f, 0.f,-.5f},
{ 0.f, 0.f, .5f}
};
void ViewerWidget::initializeGL() void ViewerWidget::initializeGL() {
{ QGLWidget::initializeGL();
QGLWidget::initializeGL(); timer.setInterval(25);
timer.setInterval(25); connect(&timer, SIGNAL(timeout()), SLOT(updateGL()));
connect(&timer, SIGNAL(timeout()), SLOT(updateGL())); timer.start();
timer.start();
_frameWidgetDraw = new DrawBuffer; _frameWidgetDraw = new DrawBuffer;
_frameWidgetDraw->setFaceType(GL_LINES); _frameWidgetDraw->setFaceType(GL_LINES);
_frameWidgetGeom = new GeometryBuffer; _frameWidgetGeom = new GeometryBuffer;
_frameWidgetGeom->uploadVertices(widgetVerts); _frameWidgetGeom->uploadVertices(widgetVerts);
_frameWidgetDraw->addGeometry(_frameWidgetGeom); _frameWidgetDraw->addGeometry(_frameWidgetGeom);
glGenTextures(1, &whiteTex); glGenTextures(1, &whiteTex);
glBindTexture(GL_TEXTURE_2D, whiteTex); glBindTexture(GL_TEXTURE_2D, whiteTex);
GLuint tex = 0xFFFFFFFF; GLuint tex = 0xFFFFFFFF;
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, &tex); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); &tex);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
} }
void ViewerWidget::resizeGL(int w, int h) void ViewerWidget::resizeGL(int w, int h) {
{ QGLWidget::resizeGL(w, h);
QGLWidget::resizeGL(w, h); glViewport(0, 0, w, h);
glViewport(0, 0, w, h);
} }
void ViewerWidget::paintGL() void ViewerWidget::paintGL() {
{ glClearColor(0.3f, 0.3f, 0.3f, 1.f);
glClearColor(0.3f, 0.3f, 0.3f, 1.f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, width(), height());
if( world() == nullptr ) return;
auto& r = *renderer; glViewport(0, 0, width(), height());
r.setViewport(width(), height()); if (world() == nullptr) return;
if(dummyObject && dummyObject->animator && dummyObject->skeleton) { auto& r = *renderer;
dummyObject->animator->tick(1.f/60.f);
dummyObject->skeleton->interpolate(1.f);
}
gworld->_work->update();
r.getRenderer()->invalidate(); r.setViewport(width(), height());
glEnable(GL_DEPTH_TEST); if (dummyObject && dummyObject->animator && dummyObject->skeleton) {
dummyObject->animator->tick(1.f / 60.f);
dummyObject->skeleton->interpolate(1.f);
}
glm::mat4 m(1.f); gworld->_work->update();
r.getRenderer()->useProgram(r.worldProg); r.getRenderer()->invalidate();
ViewCamera vc; glEnable(GL_DEPTH_TEST);
float viewFov = glm::radians(45.f); glm::mat4 m(1.f);
vc.frustum.far = 500.f; r.getRenderer()->useProgram(r.worldProg);
vc.frustum.near = 0.1f;
vc.frustum.fov = viewFov;
vc.frustum.aspectRatio = width()/(height()*1.f);
Model* model = activeModel; ViewCamera vc;
if( model != _lastModel ) {
_lastModel = model;
emit modelChanged(_lastModel);
}
glm::vec3 eye(sin(viewAngles.x) * cos(viewAngles.y), cos(viewAngles.x) * cos(viewAngles.y), sin(viewAngles.y)); float viewFov = glm::radians(45.f);
if( model ) vc.frustum.far = 500.f;
{ vc.frustum.near = 0.1f;
glm::mat4 proj = vc.frustum.projection(); vc.frustum.fov = viewFov;
glm::mat4 view = glm::lookAt(eye * viewDistance, glm::vec3(0.f, 0.f, 0.f), glm::vec3(0.f, 0.f, 1.f)); vc.frustum.aspectRatio = width() / (height() * 1.f);
r.getRenderer()->setSceneParameters({ proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f), glm::vec4(0.f), 90.f, vc.frustum.far }); Model* model = activeModel;
if (model != _lastModel) {
_lastModel = model;
emit modelChanged(_lastModel);
}
r.getRenderer()->invalidate(); glm::vec3 eye(sin(viewAngles.x) * cos(viewAngles.y),
cos(viewAngles.x) * cos(viewAngles.y), sin(viewAngles.y));
r.setupRender(); if (model) {
glm::mat4 proj = vc.frustum.projection();
glm::mat4 view =
glm::lookAt(eye * viewDistance, glm::vec3(0.f, 0.f, 0.f),
glm::vec3(0.f, 0.f, 1.f));
r.renderModel(model, m, dummyObject); r.getRenderer()->setSceneParameters(
{proj, view, glm::vec4(0.15f), glm::vec4(0.7f), glm::vec4(1.f),
glm::vec4(0.f), 90.f, vc.frustum.far});
drawFrameWidget(model->frames[model->rootFrameIdx]); r.getRenderer()->invalidate();
r.renderPostProcess();
} r.setupRender();
else if (world()->allObjects.size() > 0)
{ r.renderModel(model, m, dummyObject);
vc.frustum.fov = glm::radians(90.f);
vc.frustum.far = 1000.f; drawFrameWidget(model->frames[model->rootFrameIdx]);
vc.position = viewPosition; r.renderPostProcess();
vc.rotation = glm::angleAxis(glm::half_pi<float>() + viewAngles.x, glm::vec3(0.f, 0.f, 1.f)) } else if (world()->allObjects.size() > 0) {
* glm::angleAxis(viewAngles.y, glm::vec3(0.f, 1.f, 0.f)); vc.frustum.fov = glm::radians(90.f);
r.renderWorld(world(), vc, 0.f); vc.frustum.far = 1000.f;
} vc.position = viewPosition;
vc.rotation = glm::angleAxis(glm::half_pi<float>() + viewAngles.x,
glm::vec3(0.f, 0.f, 1.f)) *
glm::angleAxis(viewAngles.y, glm::vec3(0.f, 1.f, 0.f));
r.renderWorld(world(), vc, 0.f);
}
} }
void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m) void ViewerWidget::drawFrameWidget(ModelFrame* f, const glm::mat4& m) {
{ auto thisM = m * f->getTransform();
auto thisM = m * f->getTransform(); if (f->getGeometries().size() == 0) {
if(f->getGeometries().size() == 0) Renderer::DrawParameters dp;
{ dp.count = _frameWidgetGeom->getCount();
Renderer::DrawParameters dp; dp.start = 0;
dp.count = _frameWidgetGeom->getCount(); dp.ambient = 1.f;
dp.start = 0; dp.diffuse = 1.f;
dp.ambient = 1.f; if (f == selectedFrame) {
dp.diffuse = 1.f; dp.colour = {255, 255, 0, 255};
if( f == selectedFrame ) // Sorry!
{ glLineWidth(10.f);
dp.colour = {255, 255, 0, 255}; } else {
// Sorry! dp.colour = {255, 255, 255, 255};
glLineWidth(10.f); glLineWidth(1.f);
} }
else dp.textures = {whiteTex};
{ renderer->getRenderer()->drawArrays(thisM, _frameWidgetDraw, dp);
dp.colour = {255, 255, 255, 255}; }
glLineWidth(1.f);
} for (auto c : f->getChildren()) {
dp.textures = { whiteTex }; drawFrameWidget(c, thisM);
renderer->getRenderer()->drawArrays(thisM, _frameWidgetDraw, dp); }
}
for(auto c : f->getChildren()) {
drawFrameWidget(c, thisM);
}
} }
GameWorld* ViewerWidget::world() GameWorld* ViewerWidget::world() {
{ return gworld;
return gworld;
} }
void ViewerWidget::showObject(qint16 item) void ViewerWidget::showObject(qint16 item) {
{ currentObjectID = item;
currentObjectID = item;
if( dummyObject ) gworld->destroyObject( dummyObject ); if (dummyObject) gworld->destroyObject(dummyObject);
auto def = world()->data->objectTypes[item]; auto def = world()->data->objectTypes[item];
if( def ) if (def) {
{ if (def->class_type == ObjectData::class_id) {
if(def->class_type == ObjectData::class_id) dummyObject = gworld->createInstance(item, {});
{ } else if (def->class_type == CharacterData::class_id) {
dummyObject = gworld->createInstance(item, {}); dummyObject = gworld->createPedestrian(item, {});
} } else if (def->class_type == VehicleData::class_id) {
else if(def->class_type == CharacterData::class_id) dummyObject = gworld->createVehicle(item, {});
{ }
dummyObject = gworld->createPedestrian(item, {}); RW_CHECK(dummyObject != nullptr, "Dummy Object is null");
} if (dummyObject != nullptr) {
else if(def->class_type == VehicleData::class_id) activeModel = dummyObject->model->resource;
{ }
dummyObject = gworld->createVehicle(item, {}); }
}
RW_CHECK(dummyObject != nullptr, "Dummy Object is null");
if (dummyObject != nullptr) {
activeModel = dummyObject->model->resource;
}
}
} }
void ViewerWidget::showModel(Model* model) void ViewerWidget::showModel(Model* model) {
{ if (dummyObject) gworld->destroyObject(dummyObject);
if( dummyObject ) gworld->destroyObject( dummyObject ); dummyObject = nullptr;
dummyObject = nullptr; activeModel = model;
activeModel = model;
} }
void ViewerWidget::selectFrame(ModelFrame* frame) void ViewerWidget::selectFrame(ModelFrame* frame) {
{ selectedFrame = frame;
selectedFrame = frame;
} }
void ViewerWidget::exportModel() void ViewerWidget::exportModel() {
{ QString toSv = QFileDialog::getSaveFileName(
QString toSv = QFileDialog::getSaveFileName(this, this, "Export Model", QDir::homePath(), "Model (*.DFF)");
"Export Model",
QDir::homePath(),
"Model (*.DFF)");
if( toSv.size() == 0 ) return; if (toSv.size() == 0) return;
#if 0 #if 0
auto it = world()->objectTypes.find(currentObjectID); auto it = world()->objectTypes.find(currentObjectID);
@ -252,77 +227,60 @@ void ViewerWidget::exportModel()
#endif #endif
} }
void ViewerWidget::dataLoaded(GameWorld *world) void ViewerWidget::dataLoaded(GameWorld* world) {
{ gworld = world;
gworld = world;
} }
void ViewerWidget::setRenderer(GameRenderer *render) void ViewerWidget::setRenderer(GameRenderer* render) {
{ renderer = render;
renderer = render;
} }
void ViewerWidget::keyPressEvent(QKeyEvent* e) void ViewerWidget::keyPressEvent(QKeyEvent* e) {
{ if (e->key() == Qt::Key_Shift) moveFast = true;
if (e->key() == Qt::Key_Shift)
moveFast = true;
glm::vec3 movement; glm::vec3 movement;
if (e->key() == Qt::Key_W) if (e->key() == Qt::Key_W) movement.y += moveFast ? 10.f : 1.f;
movement.y += moveFast ? 10.f : 1.f; if (e->key() == Qt::Key_S) movement.y -= moveFast ? 10.f : 1.f;
if (e->key() == Qt::Key_S) if (e->key() == Qt::Key_A) movement.x -= moveFast ? 10.f : 1.f;
movement.y -= moveFast ? 10.f : 1.f; if (e->key() == Qt::Key_D) movement.x += moveFast ? 10.f : 1.f;
if (e->key() == Qt::Key_A)
movement.x -= moveFast ? 10.f : 1.f;
if (e->key() == Qt::Key_D)
movement.x += moveFast? 10.f : 1.f;
if (movement.length() > 0.f) if (movement.length() > 0.f) {
{ movement = (glm::angleAxis(viewAngles.x, glm::vec3(0.f, 0.f, 1.f)) *
movement = (glm::angleAxis(viewAngles.x, glm::vec3(0.f, 0.f, 1.f)) glm::angleAxis(viewAngles.y, glm::vec3(-1.f, 0.f, 0.f))) *
* glm::angleAxis(viewAngles.y, glm::vec3(-1.f, 0.f, 0.f))) * movement; movement;
viewPosition += movement; viewPosition += movement;
} }
} }
void ViewerWidget::keyReleaseEvent(QKeyEvent* e) void ViewerWidget::keyReleaseEvent(QKeyEvent* e) {
{ if (e->key() == Qt::Key_Shift) moveFast = false;
if (e->key() == Qt::Key_Shift)
moveFast = false;
} }
Model* ViewerWidget::currentModel() const Model* ViewerWidget::currentModel() const {
{ return activeModel;
return activeModel;
} }
GameObject* ViewerWidget::currentObject() const GameObject* ViewerWidget::currentObject() const {
{ return dummyObject;
return dummyObject;
} }
void ViewerWidget::mousePressEvent(QMouseEvent* e) void ViewerWidget::mousePressEvent(QMouseEvent* e) {
{ dragging = true;
dragging = true; dstart = e->localPos();
dstart = e->localPos(); dastart = viewAngles;
dastart = viewAngles;
} }
void ViewerWidget::mouseReleaseEvent(QMouseEvent*) void ViewerWidget::mouseReleaseEvent(QMouseEvent*) {
{ dragging = false;
dragging = false;
} }
void ViewerWidget::mouseMoveEvent(QMouseEvent* e) void ViewerWidget::mouseMoveEvent(QMouseEvent* e) {
{ if (dragging) {
if(dragging) { auto d = e->localPos() - dstart;
auto d = e->localPos() - dstart; viewAngles = dastart + glm::vec2(d.x(), d.y()) * 0.01f;
viewAngles = dastart + glm::vec2(d.x(), d.y()) * 0.01f; }
}
} }
void ViewerWidget::wheelEvent(QWheelEvent* e) void ViewerWidget::wheelEvent(QWheelEvent* e) {
{ viewDistance = qMax(viewDistance - e->angleDelta().y() / 240.f, 0.5f);
viewDistance = qMax(viewDistance - e->angleDelta().y() / 240.f, 0.5f);
} }

View File

@ -1,14 +1,14 @@
#pragma once #pragma once
#ifndef _VIEWERWIDGET_HPP_ #ifndef _VIEWERWIDGET_HPP_
#define _VIEWERWIDGET_HPP_ #define _VIEWERWIDGET_HPP_
#include <QTimer>
#include <data/Model.hpp>
#include <engine/GameData.hpp> #include <engine/GameData.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include <QTimer>
#include <loaders/LoaderIFP.hpp>
#include <gl/DrawBuffer.hpp> #include <gl/DrawBuffer.hpp>
#include <gl/GeometryBuffer.hpp> #include <gl/GeometryBuffer.hpp>
#include <data/Model.hpp>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <loaders/LoaderIFP.hpp>
// Prevent Qt from conflicting with glLoadGen // Prevent Qt from conflicting with glLoadGen
#define GL_ARB_debug_output #define GL_ARB_debug_output
@ -17,80 +17,79 @@
class GameRenderer; class GameRenderer;
class Model; class Model;
class ViewerWidget : public QGLWidget class ViewerWidget : public QGLWidget {
{ Q_OBJECT
Q_OBJECT
GameRenderer* renderer; GameRenderer* renderer;
QString currentFile; QString currentFile;
QTimer timer; QTimer timer;
GameWorld* gworld; GameWorld* gworld;
Model* activeModel; Model* activeModel;
ModelFrame* selectedFrame; ModelFrame* selectedFrame;
GameObject* dummyObject; GameObject* dummyObject;
quint16 currentObjectID; quint16 currentObjectID;
Model* _lastModel; Model* _lastModel;
Animation* canimation; Animation* canimation;
float viewDistance; float viewDistance;
glm::vec2 viewAngles; glm::vec2 viewAngles;
glm::vec3 viewPosition; glm::vec3 viewPosition;
bool dragging; bool dragging;
QPointF dstart; QPointF dstart;
glm::vec2 dastart; glm::vec2 dastart;
bool moveFast; bool moveFast;
DrawBuffer* _frameWidgetDraw; DrawBuffer* _frameWidgetDraw;
GeometryBuffer* _frameWidgetGeom; GeometryBuffer* _frameWidgetGeom;
GLuint whiteTex; GLuint whiteTex;
void drawFrameWidget(ModelFrame* f, const glm::mat4& = glm::mat4(1.f));
void drawFrameWidget(ModelFrame* f, const glm::mat4& = glm::mat4(1.f));
public: public:
ViewerWidget(QGLFormat g, QWidget* parent = 0,
const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0);
ViewerWidget(QGLFormat g, QWidget* parent = 0, const QGLWidget* shareWidget = 0, Qt::WindowFlags f = 0); virtual void initializeGL();
virtual void initializeGL(); virtual void resizeGL(int w, int h);
virtual void resizeGL(int w, int h);
virtual void paintGL();
Model *currentModel() const; virtual void paintGL();
GameObject* currentObject() const;
GameWorld* world(); Model* currentModel() const;
GameObject* currentObject() const;
GameWorld* world();
public slots: public slots:
void showObject(qint16 item); void showObject(qint16 item);
void showModel(Model* model); void showModel(Model* model);
void selectFrame(ModelFrame* frame); void selectFrame(ModelFrame* frame);
void exportModel(); void exportModel();
void dataLoaded(GameWorld* world); void dataLoaded(GameWorld* world);
void setRenderer(GameRenderer* renderer); void setRenderer(GameRenderer* renderer);
signals: signals:
void fileOpened(const QString& file); void fileOpened(const QString& file);
void modelChanged(Model* model); void modelChanged(Model* model);
protected: protected:
void keyPressEvent(QKeyEvent*) override;
void keyPressEvent(QKeyEvent*) override; void keyReleaseEvent(QKeyEvent*) override;
void keyReleaseEvent(QKeyEvent*) override; void mousePressEvent(QMouseEvent*) override;
void mousePressEvent(QMouseEvent*) override; void mouseReleaseEvent(QMouseEvent*) override;
void mouseReleaseEvent(QMouseEvent*) override; void mouseMoveEvent(QMouseEvent*) override;
void mouseMoveEvent(QMouseEvent*) override; void wheelEvent(QWheelEvent*) override;
void wheelEvent(QWheelEvent*) override;
}; };
#endif #endif

View File

@ -1,230 +1,224 @@
#include "ViewerWindow.hpp" #include "ViewerWindow.hpp"
#include "views/ObjectViewer.hpp"
#include "views/ModelViewer.hpp"
#include "views/WorldViewer.hpp"
#include <ViewerWidget.hpp> #include <ViewerWidget.hpp>
#include "views/ModelViewer.hpp"
#include "views/ObjectViewer.hpp"
#include "views/WorldViewer.hpp"
#include <engine/GameState.hpp> #include <engine/GameState.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include <render/GameRenderer.hpp> #include <render/GameRenderer.hpp>
#include <QMenuBar>
#include <QFileDialog>
#include <QApplication> #include <QApplication>
#include <QSettings>
#include <QPushButton>
#include <QSignalMapper>
#include <QDebug> #include <QDebug>
#include <fstream> #include <QFileDialog>
#include <QMenuBar>
#include <QOffscreenSurface> #include <QOffscreenSurface>
#include <QPushButton>
#include <QSettings>
#include <QSignalMapper>
#include <fstream>
static int MaxRecentGames = 5; static int MaxRecentGames = 5;
ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags) ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags)
: QMainWindow(parent, flags) : QMainWindow(parent, flags)
, gameData(nullptr) , gameData(nullptr)
, gameWorld(nullptr) , gameWorld(nullptr)
, renderer(nullptr) , renderer(nullptr) {
{ setMinimumSize(640, 480);
setMinimumSize(640, 480);
QMenuBar* mb = this->menuBar(); QMenuBar* mb = this->menuBar();
QMenu* file = mb->addMenu("&File"); QMenu* file = mb->addMenu("&File");
file->addAction("Open &Game", this, SLOT(loadGame())); file->addAction("Open &Game", this, SLOT(loadGame()));
file->addSeparator(); file->addSeparator();
for(int i = 0; i < MaxRecentGames; ++i) { for (int i = 0; i < MaxRecentGames; ++i) {
QAction* r = file->addAction(""); QAction* r = file->addAction("");
recentGames.append(r); recentGames.append(r);
connect(r, SIGNAL(triggered()), SLOT(openRecent())); connect(r, SIGNAL(triggered()), SLOT(openRecent()));
} }
recentSep = file->addSeparator(); recentSep = file->addSeparator();
auto ex = file->addAction("E&xit"); auto ex = file->addAction("E&xit");
ex->setShortcut(QKeySequence::Quit); ex->setShortcut(QKeySequence::Quit);
connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows())); connect(ex, SIGNAL(triggered()), QApplication::instance(),
SLOT(closeAllWindows()));
//----------------------- View Mode setup //----------------------- View Mode setup
QGLFormat glFormat; QGLFormat glFormat;
glFormat.setVersion( 3, 3 ); glFormat.setVersion(3, 3);
glFormat.setProfile( QGLFormat::CoreProfile ); glFormat.setProfile(QGLFormat::CoreProfile);
viewerWidget = new ViewerWidget(glFormat); viewerWidget = new ViewerWidget(glFormat);
viewerWidget->context()->makeCurrent(); viewerWidget->context()->makeCurrent();
connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget, SLOT(dataLoaded(GameWorld*))); connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget,
SLOT(dataLoaded(GameWorld*)));
//------------- Object Viewer //------------- Object Viewer
m_views[ViewMode::Object] = new ObjectViewer(viewerWidget); m_views[ViewMode::Object] = new ObjectViewer(viewerWidget);
m_viewNames[ViewMode::Object] = "Objects"; m_viewNames[ViewMode::Object] = "Objects";
//------------- Model Viewer //------------- Model Viewer
m_views[ViewMode::Model] = new ModelViewer(viewerWidget); m_views[ViewMode::Model] = new ModelViewer(viewerWidget);
m_viewNames[ViewMode::Model] = "Model"; m_viewNames[ViewMode::Model] = "Model";
//------------- World Viewer //------------- World Viewer
m_views[ViewMode::World] = new WorldViewer(viewerWidget); m_views[ViewMode::World] = new WorldViewer(viewerWidget);
m_viewNames[ViewMode::World] = "World"; m_viewNames[ViewMode::World] = "World";
//------------- display mode switching //------------- display mode switching
viewSwitcher = new QStackedWidget; viewSwitcher = new QStackedWidget;
auto signalMapper = new QSignalMapper(this); auto signalMapper = new QSignalMapper(this);
auto switchPanel = new QVBoxLayout(); auto switchPanel = new QVBoxLayout();
int i = 0; int i = 0;
for(auto viewer : m_views) { for (auto viewer : m_views) {
viewSwitcher->addWidget(viewer); viewSwitcher->addWidget(viewer);
connect(this, SIGNAL(loadedData(GameWorld*)), viewer, SLOT(showData(GameWorld*))); connect(this, SIGNAL(loadedData(GameWorld*)), viewer,
SLOT(showData(GameWorld*)));
auto viewerButton = new QPushButton(m_viewNames[i].c_str()); auto viewerButton = new QPushButton(m_viewNames[i].c_str());
signalMapper->setMapping(m_views[i], i); signalMapper->setMapping(m_views[i], i);
signalMapper->setMapping(viewerButton, i); signalMapper->setMapping(viewerButton, i);
connect(viewerButton, SIGNAL(clicked()), signalMapper, SLOT(map())); connect(viewerButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
switchPanel->addWidget(viewerButton); switchPanel->addWidget(viewerButton);
i++; i++;
} }
// Map world viewer loading placements to switch to the world viewer // Map world viewer loading placements to switch to the world viewer
connect(m_views[ViewMode::World], SIGNAL(placementsLoaded(QString)), signalMapper, SLOT(map())); connect(m_views[ViewMode::World], SIGNAL(placementsLoaded(QString)),
signalMapper, SLOT(map()));
switchView(ViewMode::Object); switchView(ViewMode::Object);
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), this, SLOT(showObjectModel(uint16_t))); connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), this,
connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)), m_views[ViewMode::Model], SLOT(showObject(uint16_t))); SLOT(showObjectModel(uint16_t)));
connect(this, SIGNAL(loadAnimations(QString)), m_views[ViewMode::Model], SLOT(loadAnimations(QString))); connect(m_views[ViewMode::Object], SIGNAL(showObjectModel(uint16_t)),
m_views[ViewMode::Model], SLOT(showObject(uint16_t)));
connect(this, SIGNAL(loadAnimations(QString)), m_views[ViewMode::Model],
SLOT(loadAnimations(QString)));
connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(switchView(int))); connect(signalMapper, SIGNAL(mapped(int)), this, SLOT(switchView(int)));
connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher, SLOT(setCurrentIndex(int))); connect(signalMapper, SIGNAL(mapped(int)), viewSwitcher,
SLOT(setCurrentIndex(int)));
switchPanel->addStretch(); switchPanel->addStretch();
auto mainlayout = new QHBoxLayout(); auto mainlayout = new QHBoxLayout();
mainlayout->addLayout(switchPanel); mainlayout->addLayout(switchPanel);
mainlayout->addWidget(viewSwitcher); mainlayout->addWidget(viewSwitcher);
auto mainwidget = new QWidget(); auto mainwidget = new QWidget();
mainwidget->setLayout(mainlayout); mainwidget->setLayout(mainlayout);
QMenu* data = mb->addMenu("&Data"); QMenu* data = mb->addMenu("&Data");
//data->addAction("Export &Model", objectViewer, SLOT(exportModel())); // data->addAction("Export &Model", objectViewer, SLOT(exportModel()));
QMenu* anim = mb->addMenu("&Animation"); QMenu* anim = mb->addMenu("&Animation");
anim->addAction("Load &Animations", this, SLOT(openAnimations())); anim->addAction("Load &Animations", this, SLOT(openAnimations()));
QMenu* map = mb->addMenu("&Map"); QMenu* map = mb->addMenu("&Map");
map->addAction("Load IPL", m_views[ViewMode::World], SLOT(loadPlacements())); map->addAction("Load IPL", m_views[ViewMode::World],
SLOT(loadPlacements()));
this->setCentralWidget(mainwidget); this->setCentralWidget(mainwidget);
updateRecentGames(); updateRecentGames();
} }
void ViewerWindow::showEvent(QShowEvent*) void ViewerWindow::showEvent(QShowEvent*) {
{ static bool first = true;
static bool first = true; if (first) {
if(first) { QSettings settings("OpenRW", "rwviewer");
QSettings settings("OpenRW", "rwviewer"); restoreGeometry(settings.value("window/geometry").toByteArray());
restoreGeometry(settings.value("window/geometry").toByteArray()); restoreState(settings.value("window/windowState").toByteArray());
restoreState(settings.value("window/windowState").toByteArray()); first = false;
first = false; }
}
} }
void ViewerWindow::closeEvent(QCloseEvent* event) void ViewerWindow::closeEvent(QCloseEvent* event) {
{ QSettings settings("OpenRW", "rwviewer");
QSettings settings("OpenRW", "rwviewer"); settings.setValue("window/geometry", saveGeometry());
settings.setValue("window/geometry", saveGeometry()); settings.setValue("window/windowState", saveState());
settings.setValue("window/windowState", saveState()); QMainWindow::closeEvent(event);
QMainWindow::closeEvent(event);
} }
void ViewerWindow::openAnimations() void ViewerWindow::openAnimations() {
{ QFileDialog dialog(this, "Open Animations", QDir::homePath(),
QFileDialog dialog(this, "Open Animations", QDir::homePath(), "IFP Animations (*.ifp)"); "IFP Animations (*.ifp)");
if(dialog.exec()) { if (dialog.exec()) {
loadAnimations(dialog.selectedFiles()[0]); loadAnimations(dialog.selectedFiles()[0]);
} }
} }
void ViewerWindow::loadGame() void ViewerWindow::loadGame() {
{ QString dir = QFileDialog::getExistingDirectory(
QString dir = QFileDialog::getExistingDirectory( this, tr("Open Directory"), QDir::homePath(),
this, tr("Open Directory"), QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
QDir::homePath(),
QFileDialog::ShowDirsOnly
| QFileDialog::DontResolveSymlinks);
if( dir.size() > 0 ) loadGame( dir ); if (dir.size() > 0) loadGame(dir);
} }
void ViewerWindow::loadGame(const QString &path) void ViewerWindow::loadGame(const QString& path) {
{ QDir gameDir(path);
QDir gameDir( path );
if( gameDir.exists() && path.size() > 0 ) { if (gameDir.exists() && path.size() > 0) {
gameData = new GameData( &engineLog, &work, gameDir.absolutePath().toStdString() ); gameData = new GameData(&engineLog, &work,
gameWorld = new GameWorld( &engineLog, &work, gameData ); gameDir.absolutePath().toStdString());
renderer = new GameRenderer(&engineLog, gameData ); gameWorld = new GameWorld(&engineLog, &work, gameData);
gameWorld->state = new GameState; renderer = new GameRenderer(&engineLog, gameData);
viewerWidget->setRenderer(renderer); gameWorld->state = new GameState;
viewerWidget->setRenderer(renderer);
gameWorld->data->load(); gameWorld->data->load();
loadedData(gameWorld); loadedData(gameWorld);
} }
QSettings settings("OpenRW", "rwviewer"); QSettings settings("OpenRW", "rwviewer");
QStringList recent = settings.value("recentGames").toStringList(); QStringList recent = settings.value("recentGames").toStringList();
recent.removeAll( path ); recent.removeAll(path);
recent.prepend( path ); recent.prepend(path);
while(recent.size() > MaxRecentGames) recent.removeLast(); while (recent.size() > MaxRecentGames) recent.removeLast();
settings.setValue("recentGames", recent); settings.setValue("recentGames", recent);
updateRecentGames(); updateRecentGames();
} }
void ViewerWindow::openRecent() void ViewerWindow::openRecent() {
{ QAction* r = qobject_cast<QAction*>(sender());
QAction* r = qobject_cast< QAction* >(sender()); if (r) {
if(r) { loadGame(r->data().toString());
loadGame( r->data().toString() ); }
}
} }
void ViewerWindow::switchView(int mode) void ViewerWindow::switchView(int mode) {
{ if (mode < int(m_views.size())) {
if( mode < int(m_views.size()) ) m_views[mode]->setViewerWidget(viewerWidget);
{ } else {
m_views[mode]->setViewerWidget( viewerWidget ); RW_ERROR("Unhandled view mode" << mode);
} }
else
{
RW_ERROR("Unhandled view mode" << mode);
}
} }
void ViewerWindow::showObjectModel(uint16_t) void ViewerWindow::showObjectModel(uint16_t) {
{ // Switch to the model viewer
// Switch to the model viewer switchView(ViewMode::Model);
switchView(ViewMode::Model); viewSwitcher->setCurrentIndex(
viewSwitcher->setCurrentIndex( viewSwitcher->indexOf(m_views[ViewMode::Model]) ); viewSwitcher->indexOf(m_views[ViewMode::Model]));
} }
void ViewerWindow::updateRecentGames() void ViewerWindow::updateRecentGames() {
{ QSettings settings("OpenRW", "rwviewer");
QSettings settings("OpenRW", "rwviewer"); QStringList recent = settings.value("recentGames").toStringList();
QStringList recent = settings.value("recentGames").toStringList();
for (int i = 0; i < MaxRecentGames; ++i) {
for(int i = 0; i < MaxRecentGames; ++i) { if (i < recent.size()) {
if(i < recent.size()) { QString fnm(QFileInfo(recent[i]).fileName());
QString fnm(QFileInfo(recent[i]).fileName()); recentGames[i]->setText(tr("&%1 - %2").arg(i).arg(fnm));
recentGames[i]->setText(tr("&%1 - %2").arg(i).arg(fnm)); recentGames[i]->setData(recent[i]);
recentGames[i]->setData(recent[i]); recentGames[i]->setVisible(true);
recentGames[i]->setVisible(true); } else {
} recentGames[i]->setVisible(false);
else { }
recentGames[i]->setVisible(false); }
}
} recentSep->setVisible(recent.size() > 0);
recentSep->setVisible(recent.size() > 0);
} }

View File

@ -1,9 +1,9 @@
#pragma once #pragma once
#ifndef _VIEWERWINDOW_HPP_ #ifndef _VIEWERWINDOW_HPP_
#define _VIEWERWINDOW_HPP_ #define _VIEWERWINDOW_HPP_
#include <core/Logger.hpp>
#include <engine/GameData.hpp> #include <engine/GameData.hpp>
#include <engine/GameWorld.hpp> #include <engine/GameWorld.hpp>
#include <core/Logger.hpp>
#include <QMainWindow> #include <QMainWindow>
#include <QStackedWidget> #include <QStackedWidget>
@ -16,74 +16,67 @@ class ViewerInterface;
class GameRenderer; class GameRenderer;
class QGLContext; class QGLContext;
class ViewerWindow : public QMainWindow class ViewerWindow : public QMainWindow {
{ Q_OBJECT
Q_OBJECT
enum ViewMode { enum ViewMode { Object = 0, Model = 1, World = 2, _Count };
Object = 0,
Model = 1,
World = 2,
_Count
};
Logger engineLog; Logger engineLog;
WorkContext work; WorkContext work;
GameData* gameData; GameData* gameData;
GameWorld* gameWorld; GameWorld* gameWorld;
GameRenderer* renderer; GameRenderer* renderer;
GameState* state; GameState* state;
/** Contains the OGL context */ /** Contains the OGL context */
ViewerWidget* viewerWidget; ViewerWidget* viewerWidget;
std::array<ViewerInterface*, ViewMode::_Count> m_views; std::array<ViewerInterface*, ViewMode::_Count> m_views;
std::array<std::string, ViewMode::_Count> m_viewNames; std::array<std::string, ViewMode::_Count> m_viewNames;
QStackedWidget* viewSwitcher; QStackedWidget* viewSwitcher;
QGLContext* context;
QGLContext* context;
public: public:
ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0);
ViewerWindow(QWidget* parent = 0, Qt::WindowFlags flags = 0); /**
* @brief openGame Loads a game's dat file.
* @param datFile
*/
void openGame(const QString& datFile);
/** virtual void showEvent(QShowEvent*);
* @brief openGame Loads a game's dat file.
* @param datFile
*/
void openGame(const QString& datFile);
virtual void showEvent(QShowEvent*); virtual void closeEvent(QCloseEvent*);
virtual void closeEvent(QCloseEvent*);
public slots: public slots:
void openAnimations(); void openAnimations();
void loadGame(); void loadGame();
void loadGame( const QString& path ); void loadGame(const QString& path);
signals: signals:
void loadedData(GameWorld* world); void loadedData(GameWorld* world);
void loadAnimations(const QString& file); void loadAnimations(const QString& file);
private slots: private slots:
void openRecent(); void openRecent();
void switchView(int mode); void switchView(int mode);
void showObjectModel(uint16_t object); void showObjectModel(uint16_t object);
private: private:
QList<QAction*> recentGames;
QList<QAction*> recentGames; QAction* recentSep;
QAction* recentSep; void updateRecentGames();
void updateRecentGames();
}; };
#endif #endif

View File

@ -2,12 +2,11 @@
#include <QStyleFactory> #include <QStyleFactory>
#include "ViewerWindow.hpp" #include "ViewerWindow.hpp"
int main(int argc, char *argv[]) int main(int argc, char *argv[]) {
{ QApplication app(argc, argv);
QApplication app(argc, argv);
ViewerWindow viewer;
ViewerWindow viewer; viewer.show();
viewer.show();
return app.exec();
return app.exec();
} }