Explorar el Código

Merge pull request #95 from paulsapps/installer

Persist console history and write UV's in installer
paulsapps hace 11 años
padre
commit
e848a61aa1

+ 6 - 2
QGearsMain/include/core/Console.h

@@ -40,6 +40,10 @@ public:
     virtual void messageLogged( const Ogre::String& message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool& skipThisMessage );
     virtual void messageLogged( const Ogre::String& message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool& skipThisMessage );
 
 
 private:
 private:
+    void LoadHistory();
+    void SaveHistory();
+    void AddToHistory(const Ogre::String& history);
+
     int                           m_ConsoleWidth;
     int                           m_ConsoleWidth;
     int                           m_ConsoleHeight;
     int                           m_ConsoleHeight;
     unsigned int                  m_LineWidth;
     unsigned int                  m_LineWidth;
@@ -63,8 +67,8 @@ private:
     float                         m_CursorBlinkTime;
     float                         m_CursorBlinkTime;
 
 
     std::list< Ogre::String >     m_History;
     std::list< Ogre::String >     m_History;
-    int                           m_HistoryLine;
-    unsigned int                  m_HistorySize;
+    int                           m_HistoryLineCycleIndex;
+    unsigned int                  m_MaxHistorySize;
 
 
     Ogre::StringVector            m_AutoCompletition;
     Ogre::StringVector            m_AutoCompletition;
     unsigned int                  m_AutoCompletitionLine;
     unsigned int                  m_AutoCompletitionLine;

+ 49 - 15
QGearsMain/src/core/Console.cpp

@@ -27,8 +27,8 @@ Console::Console():
     m_CursorPosition(0),
     m_CursorPosition(0),
     m_CursorBlinkTime(0),
     m_CursorBlinkTime(0),
 
 
-    m_HistoryLine(-1),
-    m_HistorySize(32),
+    m_HistoryLineCycleIndex(-1),
+    m_MaxHistorySize(32),
 
 
     m_AutoCompletitionLine(0)
     m_AutoCompletitionLine(0)
 {
 {
@@ -51,17 +51,56 @@ Console::Console():
 
 
     LOG_TRIVIAL("Created console width " + Ogre::StringConverter::toString(m_ConsoleWidth) + ", height " + Ogre::StringConverter::toString(m_ConsoleHeight));
     LOG_TRIVIAL("Created console width " + Ogre::StringConverter::toString(m_ConsoleWidth) + ", height " + Ogre::StringConverter::toString(m_ConsoleHeight));
 
 
-    // add as frame and log listner
+    // add as frame and log listener
     Ogre::LogManager::getSingleton().getDefaultLog()->addListener(this);
     Ogre::LogManager::getSingleton().getDefaultLog()->addListener(this);
+
+    LoadHistory();
 }
 }
 
 
 
 
 Console::~Console()
 Console::~Console()
 {
 {
-    // remove as listner
+    // remove as listener
     Ogre::LogManager::getSingleton().getDefaultLog()->removeListener(this);
     Ogre::LogManager::getSingleton().getDefaultLog()->removeListener(this);
+    SaveHistory();
 }
 }
 
 
+void Console::LoadHistory()
+{
+    LOG_TRIVIAL("Loading console_history.txt ...");
+
+    std::ifstream file("console_history.txt");
+    std::string historyLine;
+    while (std::getline(file, historyLine))
+    {
+        AddToHistory(historyLine);
+    }
+    std::reverse(m_History.begin(), m_History.end());
+}
+
+void Console::SaveHistory()
+{
+    std::ofstream file("console_history.txt");
+    if (!file.is_open())
+    {
+        LOG_ERROR("Failed to open console_history.txt for writing");
+        return;
+    }
+    for (auto& historyLine : m_History)
+    {
+        file << historyLine << "\r\n";
+    }
+}
+
+void Console::AddToHistory(const Ogre::String& history)
+{
+    if (m_History.size() >= m_MaxHistorySize)
+    {
+        m_History.pop_back();
+    }
+    m_History.push_front(history);
+    m_HistoryLineCycleIndex = -1;
+}
 
 
 void
 void
 Console::Input(const QGears::Event& event)
 Console::Input(const QGears::Event& event)
@@ -120,18 +159,18 @@ Console::Input(const QGears::Event& event)
     // history up
     // history up
     else if ((event.type == QGears::ET_KEY_PRESS || event.type == QGears::ET_KEY_REPEAT) && event.param1 == OIS::KC_UP)
     else if ((event.type == QGears::ET_KEY_PRESS || event.type == QGears::ET_KEY_REPEAT) && event.param1 == OIS::KC_UP)
     {
     {
-        if(m_HistoryLine < (int)m_History.size() - 1)
+        if(m_HistoryLineCycleIndex < (int)m_History.size() - 1)
         {
         {
-            ++m_HistoryLine;
+            ++m_HistoryLineCycleIndex;
             SetInputLineFromHistory();
             SetInputLineFromHistory();
         }
         }
     }
     }
     // history down
     // history down
     else if ((event.type == QGears::ET_KEY_PRESS || event.type == QGears::ET_KEY_REPEAT) && event.param1 == OIS::KC_DOWN)
     else if ((event.type == QGears::ET_KEY_PRESS || event.type == QGears::ET_KEY_REPEAT) && event.param1 == OIS::KC_DOWN)
     {
     {
-        if(m_HistoryLine > 0)
+        if(m_HistoryLineCycleIndex > 0)
         {
         {
-            --m_HistoryLine;
+            --m_HistoryLineCycleIndex;
             SetInputLineFromHistory();
             SetInputLineFromHistory();
         }
         }
     }
     }
@@ -736,12 +775,7 @@ Console::ResetAutoCompletion()
 void
 void
 Console::AddInputToHistory()
 Console::AddInputToHistory()
 {
 {
-    if(m_History.size() >= m_HistorySize)
-    {
-        m_History.pop_back();
-    }
-    m_History.push_front(m_InputLine);
-    m_HistoryLine = -1;
+    AddToHistory(m_InputLine);
 }
 }
 
 
 
 
@@ -753,7 +787,7 @@ Console::SetInputLineFromHistory()
     std::list<Ogre::String>::iterator i = m_History.begin();
     std::list<Ogre::String>::iterator i = m_History.begin();
     for(int count = 0; i != m_History.end(); ++i, ++count)
     for(int count = 0; i != m_History.end(); ++i, ++count)
     {
     {
-        if(count == m_HistoryLine)
+        if(count == m_HistoryLineCycleIndex)
         {
         {
             m_InputLine = (*i);
             m_InputLine = (*i);
             m_CursorPosition = m_InputLine.size();
             m_CursorPosition = m_InputLine.size();

+ 18 - 5
utilities/q-gears-launcher/src/ff7DataInstaller.cpp

@@ -192,16 +192,29 @@ static void FF7PcFieldToQGearsField(QGears::FLevelFilePtr& field, const std::str
                 for (QGears::BackgroundFile::SpriteData& sprite : layer.sprites)
                 for (QGears::BackgroundFile::SpriteData& sprite : layer.sprites)
                 {
                 {
                     std::unique_ptr<TiXmlElement> xmlElement(new TiXmlElement("tile"));
                     std::unique_ptr<TiXmlElement> xmlElement(new TiXmlElement("tile"));
+
+                    // Not sure why it needs to be * 3
                     xmlElement->SetAttribute("destination", Ogre::StringConverter::toString(sprite.dst.x * 3) + " " + Ogre::StringConverter::toString(sprite.dst.y * 3));
                     xmlElement->SetAttribute("destination", Ogre::StringConverter::toString(sprite.dst.x * 3) + " " + Ogre::StringConverter::toString(sprite.dst.y * 3));
 
 
-                    // Where to get UVs??
-                    //sprite.dst.x; layer.width
-                    //sprite.dst.y;
+                    // Each tile is added to a big texture atlas with hard coded size of 1024x1024
+                    const float u0 = static_cast<float>(sprite.dst.x) / 1024.0f;
+                    const float v0 = static_cast<float>(sprite.dst.y) / 1024.0f;
+
+                    const float u1 = static_cast<float>(sprite.dst.x+sprite.width) / 1024.0f;
+                    const float v1 = static_cast<float>(sprite.dst.y+sprite.height) / 1024.0f;
+
+                    xmlElement->SetAttribute("uv", 
+                        Ogre::StringConverter::toString(u0) + " " + Ogre::StringConverter::toString(v0) + " " +
+                        Ogre::StringConverter::toString(u1) + " " + Ogre::StringConverter::toString(v1)
+                        );
 
 
-                    // sprite.depth;
+                    // TODO: Needs converting somehow
+                    xmlElement->SetAttribute("depth", "999"/* Ogre::StringConverter::toString(sprite.depth)*/);
 
 
-                    // Where to get blend mode??
 
 
+                    // TODO: Convert properly
+                    xmlElement->SetAttribute("blending", "alpha" /* Ogre::StringConverter::toString(sprite.blending)*/);
+                    
                     element->LinkEndChild(xmlElement.release());
                     element->LinkEndChild(xmlElement.release());
                 }
                 }