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

Merge pull request #107 from paulsapps/installer

Update SUDM to get data to write out entity_model and entity_scripts
paulsapps 11 лет назад
Родитель
Сommit
0a01bc769a
2 измененных файлов с 65 добавлено и 24 удалено
  1. 1 1
      dependencies/SUDM
  2. 64 23
      utilities/q-gears-launcher/src/ff7DataInstaller.cpp

+ 1 - 1
dependencies/SUDM

@@ -1 +1 @@
-Subproject commit 2ae28f1d9f5ef236eeadcbd77aaa7ec1722a6b14
+Subproject commit fbc361f0e436b34e17541a48ff632e5cb08f4050

+ 64 - 23
utilities/q-gears-launcher/src/ff7DataInstaller.cpp

@@ -137,18 +137,36 @@ void FF7DataInstaller::ConvertFieldModels(std::string archive, std::string outDi
 class FF7FieldScriptFormatter : public SUDM::IScriptFormatter
 {
 public:
-    virtual bool ExcludeFunction(const std::string& ) override
+    // Renames a variable, return empty string for generated name
+    virtual std::string VarName(unsigned int bank, unsigned int addr) override
     {
-        // Include everything for now
-        return false;
+        return "";
     }
 
+    // Renames an entity
+    virtual std::string EntityName(const std::string& entity) override
+    {
+        return entity;
+    }
+
+    // Renames an animation, return empty string for generated name
+    virtual std::string AnimationName(int id) override
+    {
+        return "";
+    }
+
+    // Renames a function in an entity
+    virtual std::string FunctionName(const std::string& entity, const std::string& funcName) override
+    {
+        return funcName;
+    }
 
-    virtual std::string RenameIdentifer(const std::string& name) override
+    // Sets the header comment for a function in an entity
+    virtual std::string FunctionComment(const std::string& entity, const std::string& funcName) override
     {
-        // Don't rename anything for now
-        return name;
+        return "";
     }
+
 };
 
 const int kInactiveGateWayId = 32767;
@@ -184,9 +202,11 @@ static size_t FieldId(const std::string& name, const std::vector<std::string>& f
 
 static void FF7PcFieldToQGearsField(QGears::FLevelFilePtr& field, const std::string& outDir, const std::vector<std::string>& fieldIdToNameLookup, const FieldSpawnPointsMap& spawnMap)
 {
-    // Save out the tiles as a PNG image
-    
 
+    // TODO: Insert triggers into LUA script
+  
+
+    SUDM::FF7::Field::DecompiledScript decompiled;
     try
     {
         // Get the raw script bytes
@@ -194,11 +214,11 @@ static void FF7PcFieldToQGearsField(QGears::FLevelFilePtr& field, const std::str
 
         // Decompile to LUA
         FF7FieldScriptFormatter formatter;
-        std::string luaScript = SUDM::FF7::Field::Decompile(field->getName(), rawFieldData, formatter);
+        decompiled = SUDM::FF7::Field::Decompile(field->getName(), rawFieldData, formatter);
         std::ofstream scriptFile(outDir + "/" + field->getName() + ".lua");
         if (scriptFile.is_open())
         {
-            scriptFile << luaScript;
+            scriptFile << decompiled.luaScript;
         }
         else
         {
@@ -210,10 +230,7 @@ static void FF7PcFieldToQGearsField(QGears::FLevelFilePtr& field, const std::str
         std::cerr << "InternalDecompilerError: " << ex.what() << std::endl;
     }
 
-    // TODO: Insert triggers into LUA script
-    //const QGears::ModelListFilePtr& models = field->getModelList();
-    //const QGears::ModelListFile::ModelDescription& desc = models->getModels().at(0);
-    
+
     const QGears::TriggersFilePtr& triggers = field->getTriggers();
 
     // Write out the map file which links all the other files together for a given field
@@ -236,21 +253,45 @@ static void FF7PcFieldToQGearsField(QGears::FLevelFilePtr& field, const std::str
         xmlWalkmesh->SetAttribute("file_name", field->getName() + "_wm.xml");
         element->LinkEndChild(xmlWalkmesh.release());
 
-
+        // Angle player moves when "up" is pressed
         std::unique_ptr<TiXmlElement> xmlMovementRotation(new TiXmlElement("movement_rotation"));
         xmlMovementRotation->SetAttribute("degree", std::to_string(triggers->MovementRotation()));
         element->LinkEndChild(xmlMovementRotation.release());
 
-        // TODO: entity_script - name
-        
-        // TODO: entity_model - name, file_name,  position, direction
-        // We set char 1 position to be position of first entity_point so player is spawned in sane
-        // position if map is manually loaded via console.
-        // None player chars set their first position in the init scripts. We know its a entity_model
-        // because it uses PC opcode in init script.
+        const QGears::ModelListFilePtr& models = field->getModelList();
+        for (const auto& it : decompiled.entities)
+        {
+            const int charId = it.second;
+            if (charId != -1)
+            {
+                const QGears::ModelListFile::ModelDescription& desc = models->getModels().at(charId);
+
+                std::unique_ptr<TiXmlElement> xmlEntityScript(new TiXmlElement("entity_model"));
+                xmlEntityScript->SetAttribute("name", it.first);
+
+                // TODO: Add to list of HRC's to convert, obtain name of target converted .mesh file
+                xmlEntityScript->SetAttribute("file_name", desc.hrc_name);
 
-        // entity_manager:get_entity("cl") is done via CHAR opcode
+                // TODO: entity_model - name, file_name,  position, direction
+                // We set char 1 position to be position of first entity_point so player is spawned in sane
+                // position if map is manually loaded via console.
+                // None player chars set their first position in the init scripts. We know its a entity_model
+                // because it uses PC opcode in init script.
+                // entity_manager:get_entity("cl") is done via CHAR opcode
+                xmlEntityScript->SetAttribute("position", "0 0 0");
 
+                xmlEntityScript->SetAttribute("direction", "0");
+
+                element->LinkEndChild(xmlEntityScript.release());
+
+            }
+            else
+            {
+                std::unique_ptr<TiXmlElement> xmlEntityScript(new TiXmlElement("entity_script"));
+                xmlEntityScript->SetAttribute("name", it.first);
+                element->LinkEndChild(xmlEntityScript.release());
+            }
+        }
 
         // TODO: Get these scales from the field game data,  1024 for md1_1 and 512 for md1_2, DAT CFG has them as 2 and 1?
         const float downscaler_next = 128.0f; //  * MapIdToScale( map_id );