Paul 11 лет назад
Родитель
Сommit
88037e9939

+ 2 - 0
QGearsMain/CMakeLists.txt

@@ -149,6 +149,7 @@ include/data/worldmap/MapFile.h
   include/data/QGearsTexCodec.h
   include/data/QGearsTexFile.h
   include/data/QGearsTriggersFile.h
+  include/data/QGearsMapListFile.h
 )
 
 set(SOURCE_FILES_DATA
@@ -198,6 +199,7 @@ set(SOURCE_FILES_DATA
   src/data/QGearsTexCodec.cpp
   src/data/QGearsTexFile.cpp
   src/data/QGearsTriggersFile.cpp
+  src/data/QGearsMapListFile.cpp
 )
 
 set(SOURCE_FILES

+ 61 - 0
QGearsMain/include/data/QGearsMapListFile.h

@@ -0,0 +1,61 @@
+#pragma once
+
+#include <OgreResourceManager.h>
+#include "QGearsPrerequisites.h"
+#include "common/QGearsResource.h"
+#include "QGearsSerializer.h"
+
+namespace QGears
+{
+    class MapListFileManager :
+        public Ogre::ResourceManager,
+        public Ogre::Singleton<MapListFileManager>
+    {
+    public:
+        MapListFileManager();
+        virtual ~MapListFileManager();
+        static MapListFileManager& getSingleton();
+        static MapListFileManager* getSingletonPtr();
+    protected:
+        virtual Ogre::Resource *createImpl(
+            const Ogre::String &name,
+            Ogre::ResourceHandle handle,
+            const Ogre::String& group,
+            bool isManual,
+            Ogre::ManualResourceLoader* loader,
+            const Ogre::NameValuePairList* createParams) override;
+    };
+
+    class MapListFile : public Resource
+    {
+    public:
+        MapListFile(Ogre::ResourceManager* creator,
+            const String &name,
+            Ogre::ResourceHandle handle,
+            const String& group,
+            bool isManual = false,
+            Ogre::ManualResourceLoader* loader = nullptr);
+        virtual ~MapListFile();
+        static const String RESOURCE_TYPE;
+        const std::vector<std::string> GetMapList() const
+        {
+            return mMapList;
+        }
+    protected:
+        virtual void loadImpl(void) override;
+        virtual void unloadImpl(void) override;
+        virtual size_t calculateSize(void) const override;
+    private:
+        friend class MapListFileSerializer;
+        std::vector<std::string> mMapList;
+    };
+
+    class MapListFileSerializer : public Serializer
+    {
+    public:
+        MapListFileSerializer() = default;
+        void importMapListFile(Ogre::DataStreamPtr &stream, MapListFile& dest);
+    };
+
+    typedef Ogre::SharedPtr<MapListFile> MapListFilePtr;
+}

+ 2 - 0
QGearsMain/src/common/QGearsApplication.cpp

@@ -36,6 +36,7 @@ GNU General Public License for more details.
 #include "data/FF7ModelListFileManager.h"
 #include "data/QGearsLGPArchiveFactory.h"
 #include "data/QGearsTriggersFile.h"
+#include "data/QGearsMapListFile.h"
 #include "common/make_unique.h"
 #include "qgears_version.h"
 
@@ -281,6 +282,7 @@ namespace QGears
         m_resource_managers.emplace_back( std::make_shared<QGears::BackgroundFileManager>() );
         m_resource_managers.emplace_back( std::make_shared<QGears::Background2DFileManager>() );
         m_resource_managers.emplace_back(std::make_shared<QGears::TriggersFileManager>());
+        m_resource_managers.emplace_back(std::make_shared<QGears::MapListFileManager>());
     }
 
     //--------------------------------------------------------------------------

+ 102 - 0
QGearsMain/src/data/QGearsMapListFile.cpp

@@ -0,0 +1,102 @@
+#include "data/QGearsMapListFile.h"
+
+template<> QGears::MapListFileManager *Ogre::Singleton<QGears::MapListFileManager>::msSingleton = nullptr;
+
+namespace QGears
+{
+    const int kMapNameMaxSize = 32;
+
+    MapListFileManager::MapListFileManager()
+    {
+        mResourceType = MapListFile::RESOURCE_TYPE;
+
+        // low, because it will likely reference other resources
+        mLoadOrder = 30.0f;
+
+        // this is how we register the ResourceManager with OGRE
+        Ogre::ResourceGroupManager::getSingleton()._registerResourceManager(mResourceType, this);
+    }
+
+    MapListFileManager::~MapListFileManager()
+    {
+        Ogre::ResourceGroupManager::getSingleton()._unregisterResourceManager(mResourceType);
+    }
+
+    /*static*/ MapListFileManager& MapListFileManager::getSingleton()
+    {
+        assert(msSingleton);
+        return(*msSingleton);
+    }
+
+    /*static*/ MapListFileManager* MapListFileManager::getSingletonPtr()
+    {
+        return msSingleton;
+    }
+
+    // ===========================================================================
+
+    MapListFile::MapListFile(Ogre::ResourceManager* creator,
+        const String &name,
+        Ogre::ResourceHandle handle,
+        const String& group,
+        bool isManual,
+        Ogre::ManualResourceLoader* loader)
+        : Resource(creator, name, handle, group, isManual, loader)
+    {
+    }
+
+    MapListFile::~MapListFile()
+    {
+        unload();
+    }
+
+    void MapListFile::loadImpl(void)
+    {
+        MapListFileSerializer serializer;
+        Ogre::DataStreamPtr stream(openResource());
+        serializer.importMapListFile(stream, *this);
+    }
+
+    void MapListFile::unloadImpl(void)
+    {
+        mMapList.clear();
+    }
+
+    size_t MapListFile::calculateSize(void) const
+    {
+        return mMapList.size() * kMapNameMaxSize;
+    }
+
+    /*static*/ const String MapListFile::RESOURCE_TYPE("FF7FieldPCMapList");
+
+    Ogre::Resource* MapListFileManager::createImpl(
+        const Ogre::String &name,
+        Ogre::ResourceHandle handle,
+        const Ogre::String& group,
+        bool isManual,
+        Ogre::ManualResourceLoader* loader,
+        const Ogre::NameValuePairList* createParams)
+    {
+        return new MapListFile(this, name, handle, group, isManual, loader);
+    }
+
+    // ===========================================================================
+
+    void MapListFileSerializer::importMapListFile(Ogre::DataStreamPtr &stream, MapListFile& dest)
+    {
+        uint16 numMaps = 0;
+        readShort(stream, numMaps);
+        for (auto i = 0u; i < numMaps; i++)
+        {
+            // +1 to ensure nullptr termination
+            std::array<char, kMapNameMaxSize + 1> tmpBuffer = {};
+            readChars(stream, tmpBuffer.data(), tmpBuffer.size() - 1);
+            std::string tmp = tmpBuffer.data();
+            if (!tmp.empty())
+            {
+                dest.mMapList.emplace_back(tmp);
+            }
+        }
+    }
+
+}

+ 13 - 0
utilities/q-gears-launcher/src/ff7DataInstaller.cpp

@@ -27,6 +27,7 @@
 #include "common/QGearsStringUtil.h"
 #include "common/FF7NameLookup.h"
 #include "data/QGearsTexCodec.h"
+#include "data/QGearsMapListFile.h"
 #include "decompiler/sudm.h"
 #include <memory>
 
@@ -261,6 +262,11 @@ static void FF7PcFieldToQGearsField(QGears::FLevelFilePtr& field, const std::str
                     // spawn at position and rotation in gateway.fieldID.
                     // However I think this adds limit of one entrance from gateway.fieldID to this field as there can only be
                     // one Spawn_FieldName entity_point.
+                    // cosin1 field has 2 links to cos_btm
+                    // for fix we put in gateway name, so script calls:
+                    // load_field_map_request( "ffvii_nrthmk", "Spawn_md1_2_Gateway1" )
+                    // Instead of:
+                    // load_field_map_request( "ffvii_nrthmk", "Spawn_md1_2" )
                     xmlEntityPoint->SetAttribute("position",
                         Ogre::StringConverter::toString(
                         Ogre::Vector3(gateway.destination.x, gateway.destination.y, gateway.destination.z) / downscaler_next));
@@ -404,6 +410,13 @@ void FF7DataInstaller::ConvertFields(std::string archive, std::string outDir)
 {
     // Everything in here is a field
     Ogre::StringVectorPtr resources = mApp.ResMgr()->listResourceNames("FFVIIFields", "*");
+
+    QGears::MapListFilePtr mapList = QGears::MapListFileManager::getSingleton().load("maplist", "FFVIIFields").staticCast<QGears::MapListFile>();
+    for (const auto& fieldName : mapList->GetMapList())
+    {
+        std::cout << fieldName << std::endl;
+    }
+
     for (auto& resourceName : *resources)
     {
         if (!QGears::StringUtil::endsWith(resourceName, ".tex")