Explorar o código

Merge pull request #55 from paulsapps/master

Installer app can now convert 1 field model of PC data on Windows
paulsapps %!s(int64=11) %!d(string=hai) anos
pai
achega
0ca0e9fcd2

+ 6 - 2
QGearsMain/include/common/QGearsApplication.h

@@ -27,9 +27,14 @@ namespace QGears
     class Application : public Ogre::Singleton<Application>
     {
     public:
+        Application(Ogre::String pluginsFileName, Ogre::String resourcesFile, Ogre::String logFileName)
+            : m_plugins_filename(pluginsFileName), m_resources_filename(resourcesFile), m_log_filename(logFileName)
+        {
+
+        }
         Application( int argc, char *argv[] );
         virtual ~Application();
-        bool                initOgre( void );
+        bool                initOgre( bool hideWindow = false );
         Ogre::Root*         getRoot( void );
         Ogre::RenderWindow* getRenderWindow( void );
         const String&       getResourcesFilename( void );
@@ -46,7 +51,6 @@ namespace QGears
     private:
         typedef std::vector<std::shared_ptr<Ogre::ResourceManager>> ResourceManagerVector;
 
-        Application();
 
         static const char*      CLI_SECTION_GENERIC;
         static const char*      CLI_HELP;

+ 19 - 5
QGearsMain/src/common/QGearsApplication.cpp

@@ -72,7 +72,7 @@ namespace QGears
 
     //--------------------------------------------------------------------------
     bool
-    Application::initOgre()
+    Application::initOgre(bool hideWindow)
     {
         if( m_initialized )
         {
@@ -81,9 +81,12 @@ namespace QGears
 
         m_initialized = true;
 
-        if( !processCommandLine( m_argc, m_argv ) )
+        if (m_argc && m_argv)
         {
-            return false;
+            if (!processCommandLine(m_argc, m_argv))
+            {
+                return false;
+            }
         }
 
         m_root = std::make_unique<Ogre::Root>( m_plugins_filename, m_config_filename, m_log_filename );
@@ -98,11 +101,22 @@ namespace QGears
         // Show the configuration dialog and initialise the system
         // You can skip this and use root.restoreConfig() to load configuration
         // settings if you were sure there are valid ones saved in ogre.cfg
-        if( !m_root->restoreConfig() && !m_root->showConfigDialog() )
+        if(/* !m_root->restoreConfig() &&*/ !m_root->showConfigDialog() )
         {
             return false;
         }
-        m_render_window = m_root->initialise( true, getWindowTitle() );
+
+        if (hideWindow)
+        {
+            Ogre::NameValuePairList list;
+            list.emplace("hidden", "true");
+            m_root->initialise(false, getWindowTitle());
+            m_render_window = m_root->createRenderWindow(getWindowTitle(), 1, 1, false, &list);
+        }
+        else
+        {
+            m_render_window = m_root->initialise(true, getWindowTitle());
+        }
 
         registerArchiveFactories();
         loadResourcesConfig();

+ 7 - 3
SupportedGames/FinalFantasy7/include/common/FF7NameLookup.h

@@ -126,14 +126,18 @@ namespace QGears
 
             static const String& animation(const String &key)
             {
-                static FF7FiledModelsAndAnimationMetadata data("field_models_and_animation_metadata.xml");
-                return data.Animation(key);
+                return Data().Animation(key);
             }
 
             static const String& model(const String &key)
+            {
+                return Data().Model(key);
+            }
+
+            static FF7FiledModelsAndAnimationMetadata& Data()
             {
                 static FF7FiledModelsAndAnimationMetadata data("field_models_and_animation_metadata.xml");
-                return data.Model(key);
+                return data;
             }
         };
     }

+ 21 - 11
utilities/installer/src/ff7DataInstaller.cpp

@@ -7,6 +7,8 @@
 #include <OgreMeshSerializer.h>
 #include <OgreSkeletonSerializer.h>
 #include <OgreMeshManager.h>
+#include <OgreRenderWindow.h>
+#include <OgreHardwarePixelBuffer.h>
 
 #include "QGearsGameState.h"
 #include "data/QGearsAFileManager.h"
@@ -24,16 +26,16 @@
 #include "data/QGearsLGPArchiveFactory.h"
 #include "common/QGearsStringUtil.h"
 #include "common/FF7NameLookup.h"
+#include "data/QGearsTexCodec.h"
 
 FF7DataInstaller::FF7DataInstaller()
+#ifdef _DEBUG
+    : mApp("plugins_d.cfg", "resources_d.cfg", "install_d.log")
+#else
+    : mApp("plugins.cfg", "resources.cfg", "install.log")
+#endif
 {
-    m_root = std::make_unique<Ogre::Root>("", "", "installer.log");
-    Ogre::ArchiveManager::getSingleton().addArchiveFactory(new QGears::LGPArchiveFactory());
-
-    mResourceManagers.emplace_back(std::make_shared<QGears::HRCFileManager>());
-    mResourceManagers.emplace_back(std::make_shared<QGears::LZSFLevelFileManager>());
-    mResourceManagers.emplace_back(std::make_shared<QGears::AFileManager>());
-    mResourceManagers.emplace_back(std::make_shared<QGears::RSDFileManager>());
+    mApp.initOgre(true);
 }
 
 FF7DataInstaller::~FF7DataInstaller()
@@ -45,12 +47,11 @@ void FF7DataInstaller::Convert(std::string inputDir, std::string outputDir, cons
 {
     for (const auto& file : files)
     {
+        // TODO: Comparison will be incorrect on some platforms
         if (file == "field\\char.lgp")
         {
             auto fullPath = inputDir + file;
-         //   m_root->addResourceLocation(inputDir, "FileSystem", "FFVII");
-            m_root->addResourceLocation(fullPath, "LGP", "FFVII");
-
+            mApp.getRoot()->addResourceLocation(fullPath, "LGP", "FFVII");
             ConvertFieldModels(fullPath, outputDir);
         }
     }
@@ -100,7 +101,15 @@ void FF7DataInstaller::ConvertFieldModels(std::string archive, std::string outDi
 
     auto meshName = QGears::FF7::NameLookup::model("adda.hrc") + ".mesh";
 
-    // TODO: Crashes as technique index out of bounds in the material
+    /*
+    TODO:
+      To figure out what .a files relate to which .hrc files, we need to enumerate every field
+      and check its model loader data. These are always Idle, Walk, Run and then field specific
+      ordering.
+      Model loader is section 3 of the field file.
+
+    */
+
     Ogre::MeshPtr mesh(Ogre::MeshManager::getSingleton().load(meshName, "FFVII"));
     Ogre::SkeletonPtr skeleton(mesh->getSkeleton());
 
@@ -108,3 +117,4 @@ void FF7DataInstaller::ConvertFieldModels(std::string archive, std::string outDi
     exportMesh(outDir, mesh);
 
 }
+

+ 2 - 3
utilities/installer/src/ff7DataInstaller.h

@@ -3,7 +3,7 @@
 #include <string>
 #include <vector>
 #include "common/make_unique.h"
-#include <OgreRoot.h>
+#include "common/QGearsApplication.h"
 
 class FF7DataInstaller
 {
@@ -14,7 +14,6 @@ public:
 
 private:
     void ConvertFieldModels(std::string archive, std::string outDir);
-    std::unique_ptr<Ogre::Root> m_root;
 
-    std::vector<std::shared_ptr<Ogre::ResourceManager>> mResourceManagers;
+    QGears::Application mApp;
 };

+ 26 - 13
utilities/installer/src/mainwindow.cpp

@@ -1,6 +1,7 @@
 #include "mainwindow.h"
 #include "ui_mainwindow.h"
 #include "ff7DataInstaller.h"
+#include <QDir>
 
 MainWindow::MainWindow(QWidget *parent) :
     QMainWindow(parent),
@@ -8,11 +9,16 @@ MainWindow::MainWindow(QWidget *parent) :
 {
     ui->setupUi(this);
     /*
-     set any options here
-     */
+    * set any options here
+    */
+
+    // Default output to "home" dir
+    ui->lineOutput->setText(QDir::toNativeSeparators(QDir::homePath() + "/qgears"));
+
 #ifdef _DEBUG
-    ui->lineInput->setText("C:\\Games\\FF7\\data\\");
-    ui->lineOutput->setText("C:\\Users\\paul\\Desktop\\q-gears\\output\\_data\\");
+    // Hard coded prebaked paths for debugging to save time
+    ui->lineInput->setText("C:\\Games\\FF7\\data");
+    ui->lineOutput->setText("C:\\Users\\paul\\Desktop\\q-gears\\output\\_data");
 #endif
 }
 
@@ -49,17 +55,24 @@ void MainWindow::on_btnGO_clicked()
     {
         QMessageBox::information(this,tr("Converting Data"),tr("Attempt to convert with \n Input: %1 \n Output: %2").arg(ui->lineInput->text(),ui->lineOutput->text()));
 
-        FF7DataInstaller conversion;
-        std::vector<std::string> vec;
+        QString input = QDir::fromNativeSeparators(ui->lineInput->text());
+        if (!input.endsWith("/"))
+        {
+            input += "/";
+        }
+
+        QString output = QDir::fromNativeSeparators(ui->lineOutput->text());
+        if (!output.endsWith("/"))
+        {
+            output += "/";
+        }
 
         // TODO: Enumerate files or find some better way to do this :)
-        vec.push_back("field\\char.lgp");
+        std::vector<std::string> vec;
+        vec.push_back(QDir::toNativeSeparators("field/char.lgp").toStdString());
+        vec.push_back(QDir::toNativeSeparators("field/flevel.lgp").toStdString());
 
-        // TODO: Debug build using release qt dlls so toStdString mixes heaps and crashes
-        auto qinput = ui->lineInput->text();
-        std::wstring input = reinterpret_cast<wchar_t*>(qinput.data());
-        auto qoutput = ui->lineOutput->text();
-        std::wstring output = reinterpret_cast<wchar_t*>(qoutput.data());
-        conversion.Convert(std::string(input.begin(), input.end()), std::string(output.begin(), output.end()), vec);
+        FF7DataInstaller conversion;
+        conversion.Convert(QDir::toNativeSeparators(input).toStdString(), QDir::toNativeSeparators(output).toStdString(), vec);
     }
 }

+ 1 - 1
utilities/installer/src/mainwindow.ui

@@ -72,7 +72,7 @@
     <item>
      <widget class="QPushButton" name="btnGO">
       <property name="text">
-       <string>PushButton</string>
+       <string>Install data</string>
       </property>
      </widget>
     </item>