Просмотр исходного кода

#54 refactor the code a little, use correct file paths for each platform, only load xml data once, share code with qgearsapplication and hide render window by default for installer app.

Paul 11 лет назад
Родитель
Сommit
44d1005d93

+ 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;
             }
         };
     }

+ 20 - 39
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"
@@ -27,58 +29,29 @@
 #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
 {
-    try
-    {
-        m_root = std::make_unique<Ogre::Root>("plugins_d.cfg", "", "installer.log");
-
-        if (!m_root->showConfigDialog())
-        {
-            //        return false;
-        }
-        m_render_window = m_root->initialise(true, "testing");
-
-
-        Ogre::ArchiveManager::getSingleton().addArchiveFactory(new QGears::LGPArchiveFactory());
-
-        mResourceManagers.emplace_back(std::make_shared<QGears::CameraMatrixFileManager>());
-        mResourceManagers.emplace_back(std::make_shared<QGears::PaletteFileManager>());
-        mResourceManagers.emplace_back(std::make_shared<QGears::WalkmeshFileManager>());
-        mResourceManagers.emplace_back(std::make_shared<QGears::FF7::ModelListFileManager>());
-        mResourceManagers.emplace_back(std::make_shared<QGears::HRCFileManager>());
-        mResourceManagers.emplace_back(std::make_shared<QGears::RSDFileManager>());
-        mResourceManagers.emplace_back(std::make_shared<QGears::AFileManager>());
-        mResourceManagers.emplace_back(std::make_shared<QGears::PFileManager>());
-        mResourceManagers.emplace_back(std::make_shared<QGears::LZSFLevelFileManager>());
-        mResourceManagers.emplace_back(std::make_shared<QGears::BackgroundFileManager>());
-        mResourceManagers.emplace_back(std::make_shared<QGears::Background2DFileManager>());
-
-        QGears::TexCodec::install();
-        QGears::TexCodec::initialise();
-    }
-    catch (const Ogre::Exception& ex)
-    {
-        std::cout << ex.what() << std::endl;
-    }
+    mApp.initOgre(true);
 }
 
 FF7DataInstaller::~FF7DataInstaller()
 {
-    mResourceManagers.clear();
-    QGears::TexCodec::shutdown();
-    QGears::TexCodec::uninstall();
+
 }
 
 void FF7DataInstaller::Convert(std::string inputDir, std::string outputDir, const std::vector<std::string>& files)
 {
     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);
         }
     }
@@ -128,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());
 

+ 2 - 5
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,9 +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;
-
-    Ogre::RenderWindow* m_render_window = nullptr; // Not owned
+    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>