Jelajahi Sumber

More code formatting and documentation. Added history document.

Iñigo Valentin 4 tahun lalu
induk
melakukan
6222d70b92
100 mengubah file dengan 16302 tambahan dan 5320 penghapusan
  1. 1 1
      .gitignore
  2. 6 6
      PlugIns/Data/src/QGearsDataPlugin.cpp
  3. 2 2
      QGearsMain/CMakeLists.txt
  4. 3 3
      QGearsMain/include/common/QGearsApplication.h
  5. 24 9
      QGearsMain/include/core/Assert.h
  6. 275 62
      QGearsMain/include/core/AudioManager.h
  7. 641 146
      QGearsMain/include/core/Background2D.h
  8. 201 52
      QGearsMain/include/core/Background2DAnimation.h
  9. 186 49
      QGearsMain/include/core/CameraManager.h
  10. 29 22
      QGearsMain/include/core/CameraManagerCommands.h
  11. 117 32
      QGearsMain/include/core/ConfigCmd.h
  12. 96 21
      QGearsMain/include/core/ConfigCmdManager.h
  13. 361 308
      QGearsMain/include/core/ConfigCmdManagerCommands.h
  14. 32 9
      QGearsMain/include/core/ConfigFile.h
  15. 173 45
      QGearsMain/include/core/ConfigVar.h
  16. 52 14
      QGearsMain/include/core/ConfigVarManager.h
  17. 266 65
      QGearsMain/include/core/Console.h
  18. 384 84
      QGearsMain/include/core/DebugDraw.h
  19. 350 76
      QGearsMain/include/core/DialogsManager.h
  20. 1277 252
      QGearsMain/include/core/Entity.h
  21. 47 16
      QGearsMain/include/core/EntityCollision.h
  22. 47 16
      QGearsMain/include/core/EntityDirection.h
  23. 468 121
      QGearsMain/include/core/EntityManager.h
  24. 92 22
      QGearsMain/include/core/EntityModel.h
  25. 93 21
      QGearsMain/include/core/EntityPoint.h
  26. 135 37
      QGearsMain/include/core/EntityTrigger.h
  27. 115 25
      QGearsMain/include/core/Event.h
  28. 152 0
      QGearsMain/include/core/GameFrameListener.h
  29. 0 42
      QGearsMain/include/core/GameFrameListner.h
  30. 232 61
      QGearsMain/include/core/InputManager.h
  31. 97 62
      QGearsMain/include/core/InputManagerCommands.h
  32. 105 12
      QGearsMain/include/core/Logger.h
  33. 74 17
      QGearsMain/include/core/Module.h
  34. 417 85
      QGearsMain/include/core/ScriptManager.h
  35. 438 150
      QGearsMain/include/core/ScriptManagerBinds.h
  36. 50 27
      QGearsMain/include/core/ScriptManagerCommands.h
  37. 156 39
      QGearsMain/include/core/TextManager.h
  38. 44 23
      QGearsMain/include/core/TextManagerCommands.h
  39. 104 21
      QGearsMain/include/core/Timer.h
  40. 270 65
      QGearsMain/include/core/UiAnimation.h
  41. 183 39
      QGearsMain/include/core/UiFont.h
  42. 145 30
      QGearsMain/include/core/UiManager.h
  43. 126 29
      QGearsMain/include/core/UiSprite.h
  44. 452 138
      QGearsMain/include/core/UiTextArea.h
  45. 813 154
      QGearsMain/include/core/UiWidget.h
  46. 234 40
      QGearsMain/include/core/Utilites.h
  47. 149 35
      QGearsMain/include/core/Walkmesh.h
  48. 39 14
      QGearsMain/include/core/XmlBackground2DFile.h
  49. 186 24
      QGearsMain/include/core/XmlFile.h
  50. 39 15
      QGearsMain/include/core/XmlFontFile.h
  51. 39 15
      QGearsMain/include/core/XmlFontsFile.h
  52. 48 16
      QGearsMain/include/core/XmlMapFile.h
  53. 51 17
      QGearsMain/include/core/XmlMapsFile.h
  54. 39 15
      QGearsMain/include/core/XmlMusicsFile.h
  55. 41 15
      QGearsMain/include/core/XmlPrototypesFile.h
  56. 50 16
      QGearsMain/include/core/XmlScreenFile.h
  57. 39 15
      QGearsMain/include/core/XmlScreensFile.h
  58. 39 15
      QGearsMain/include/core/XmlScriptsFile.h
  59. 39 15
      QGearsMain/include/core/XmlTextFile.h
  60. 44 12
      QGearsMain/include/core/XmlTextsFile.h
  61. 39 16
      QGearsMain/include/core/XmlWalkmeshFile.h
  62. 154 61
      QGearsMain/include/data/QGearsAFile.h
  63. 67 33
      QGearsMain/include/data/QGearsAFileManager.h
  64. 108 56
      QGearsMain/include/data/QGearsAFileSerializer.h
  65. 401 130
      QGearsMain/include/data/QGearsBackgroundFile.h
  66. 68 43
      QGearsMain/include/data/QGearsBackgroundFileManager.h
  67. 257 96
      QGearsMain/include/data/QGearsBackgroundFileSerializer.h
  68. 47 39
      QGearsMain/include/data/QGearsBackgroundTextureLoader.h
  69. 189 72
      QGearsMain/include/data/QGearsCameraMatrixFile.h
  70. 69 43
      QGearsMain/include/data/QGearsCameraMatrixFileManager.h
  71. 70 47
      QGearsMain/include/data/QGearsCameraMatrixFileSerializer.h
  72. 56 44
      QGearsMain/include/data/QGearsFLevelBackground2DLoader.h
  73. 290 94
      QGearsMain/include/data/QGearsFLevelFile.h
  74. 65 43
      QGearsMain/include/data/QGearsFLevelFileManager.h
  75. 240 86
      QGearsMain/include/data/QGearsFLevelFileSerializer.h
  76. 47 39
      QGearsMain/include/data/QGearsFLevelTextureLoader.h
  77. 211 79
      QGearsMain/include/data/QGearsHRCFile.h
  78. 77 43
      QGearsMain/include/data/QGearsHRCFileManager.h
  79. 125 65
      QGearsMain/include/data/QGearsHRCFileSerializer.h
  80. 59 41
      QGearsMain/include/data/QGearsHRCMeshLoader.h
  81. 59 43
      QGearsMain/include/data/QGearsHRCSkeletonLoader.h
  82. 205 69
      QGearsMain/include/data/QGearsLGPArchive.h
  83. 58 44
      QGearsMain/include/data/QGearsLGPArchiveFactory.h
  84. 90 62
      QGearsMain/include/data/QGearsLGPArchiveSerializer.h
  85. 212 104
      QGearsMain/include/data/QGearsLZSDataStream.h
  86. 67 42
      QGearsMain/include/data/QGearsLZSFLevelFile.h
  87. 68 43
      QGearsMain/include/data/QGearsLZSFLevelFileManager.h
  88. 172 45
      QGearsMain/include/data/QGearsMapListFile.h
  89. 450 141
      QGearsMain/include/data/QGearsPFile.h
  90. 68 44
      QGearsMain/include/data/QGearsPFileManager.h
  91. 218 83
      QGearsMain/include/data/QGearsPFileSerializer.h
  92. 108 58
      QGearsMain/include/data/QGearsPaletteFile.h
  93. 68 44
      QGearsMain/include/data/QGearsPaletteFileManager.h
  94. 180 84
      QGearsMain/include/data/QGearsPaletteFileSerializer.h
  95. 189 68
      QGearsMain/include/data/QGearsRSDFile.h
  96. 76 44
      QGearsMain/include/data/QGearsRSDFileManager.h
  97. 106 53
      QGearsMain/include/data/QGearsRSDFileSerializer.h
  98. 213 68
      QGearsMain/include/data/QGearsSerializer.h
  99. 153 65
      QGearsMain/include/data/QGearsTexCodec.h
  100. 496 157
      QGearsMain/include/data/QGearsTexFile.h

+ 1 - 1
.gitignore

@@ -17,4 +17,4 @@ output/share
 output/include
 output/lib
 CMakeLists.txt.user
-
+doc/FFVII/RAW/

+ 6 - 6
PlugIns/Data/src/QGearsDataPlugin.cpp

@@ -32,25 +32,25 @@ using Ogre::String;
 namespace QGears {
     const String DataPlugin::ms_plugin_name( "Plugin for Various FFVII File Formats" );
 
-    //---------------------------------------------------------------------
+
     DataPlugin::DataPlugin()
     {
     }
 
-    //---------------------------------------------------------------------
+
     const String& DataPlugin::getName() const
     {
         return ms_plugin_name;
     }
 
-    //---------------------------------------------------------------------
+
     void DataPlugin::install()
     {
         //install called - create stuff here
         TexCodec::install();
     }
 
-    //---------------------------------------------------------------------
+
     void DataPlugin::initialise()
     {
         //intialise called - register stuff here
@@ -62,7 +62,7 @@ namespace QGears {
         //background_manager  = new BackgroundFileManager();
     }
 
-    //---------------------------------------------------------------------
+
     void DataPlugin::shutdown()
     {
         //shutdown called - unregister stuff here
@@ -74,7 +74,7 @@ namespace QGears {
         //delete background_manager;
     }
 
-    //---------------------------------------------------------------------
+
     void DataPlugin::uninstall()
     {
         //uninstall called - delete stuff here

+ 2 - 2
QGearsMain/CMakeLists.txt

@@ -69,7 +69,7 @@ set(HEADER_FILES
   include/core/EntityPoint.h
   include/core/EntityTrigger.h
   include/core/Event.h
-  include/core/GameFrameListner.h
+  include/core/GameFrameListener.h
   include/core/InputManager.h
   include/core/InputManagerCommands.h
   include/core/Logger.h
@@ -250,7 +250,7 @@ set(SOURCE_FILES
   src/core/EntityModel.cpp
   src/core/EntityPoint.cpp
   src/core/EntityTrigger.cpp
-  src/core/GameFrameListner.cpp
+  src/core/GameFrameListener.cpp
   src/core/InputManager.cpp
   src/core/ScriptManager.cpp
   src/core/Timer.cpp

+ 3 - 3
QGearsMain/include/common/QGearsApplication.h

@@ -20,11 +20,11 @@
 #include <memory>
 #include "TypeDefine.h"
 
-/**
- * The V-Gears main applicacion
- */
 namespace QGears{
 
+    /**
+     * The V-Gears main applicacion
+     */
     class Application : public Ogre::Singleton<Application>{
 
         public:

+ 24 - 9
QGearsMain/include/core/Assert.h

@@ -1,12 +1,27 @@
-#ifndef ASSERT_H
-#define ASSERT_H
-
-#include <cassert>
-
-
-
-#define QGEARS_ASSERT( exp, text ) assert( exp && text )
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
+#pragma once
 
+#include <cassert>
 
-#endif // ASSERT_H
+/**
+ * Assertion check.
+ *
+ * @param exp[in] Expression to evaluate.
+ * @param text[in] Error message to be displayed when the expression is not
+ * true.
+ */
+#define QGEARS_ASSERT(exp, text) assert(exp && text)

+ 275 - 62
QGearsMain/include/core/AudioManager.h

@@ -1,5 +1,19 @@
-#ifndef AUDIO_MANAGER_H
-#define AUDIO_MANAGER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreSingleton.h>
 #include <boost/thread.hpp>
@@ -14,86 +28,285 @@
     #include <AL/alc.h>
 #endif
 
+/**
+ * The audio manager.
+ *
+ * It handles all music and sounds in the application.
+ */
+class AudioManager : public Ogre::Singleton<AudioManager>{
 
+    public:
 
-class AudioManager : public Ogre::Singleton< AudioManager >
-{
-public:
-    AudioManager();
-    virtual ~AudioManager();
+        /**
+         * Constructor.
+         */
+        AudioManager();
 
-    // boost uses this
-    void operator()();
+        /**
+         * Destructor
+         */
+        virtual ~AudioManager();
 
-    void Update();
-    void MusicPause();
-    void MusicPlay( const Ogre::String& name );
-    void MusicStop();
+        /**
+         * Used by boost libraries.
+         */
+        void operator()();
 
-    struct Music
-    {
-        Ogre::String name;
-        Ogre::String file;
-        float        loop;
-    };
-    void AddMusic( const AudioManager::Music& music );
-    AudioManager::Music* GetMusic( const Ogre::String& name );
+        /**
+         * Updates the music player.
+         */
+        void Update();
 
-private:
-    const bool Init();
-    const char* ALError();
-    const char* ALCError( const ALCdevice* device );
+        /**
+         * Pauses currently playing music.
+         *
+         * @todo How to resume it?
+         */
+        void MusicPause();
 
-    class Player
-    {
-    public:
-        Player( boost::recursive_mutex* mutex );
-        ~Player();
+        /**
+         * Plays a music track.
+         *
+         * @param name[in] Name of the track to play.
+         */
+        void MusicPlay(const Ogre::String& name);
 
-        void Pause();
-        void Play( const Ogre::String& file );
-        void Stop();
+        /**
+         * Stops the currently playing music.
+         *
+         * Playback can't be resumed.
+         */
+        void MusicStop();
 
-        void SetLoop( const float loop );
+        /**
+         * Music structure.
+         *
+         * Defines a music track.
+         */
+        struct Music{
 
-        void Update();
-        float GetPosition();
+            /**
+             * The name of the track.
+             */
+            Ogre::String name;
+
+            /**
+             * Track filename
+             */
+            Ogre::String file;
+
+            /**
+             * Music loop location for continous playback.
+             *
+             * @todo How is a loop done with only one value? shouldn't it be
+             * start and end of loop?
+             */
+            float        loop;
+        };
+
+        /**
+         * Adds a music track to the audio manager.
+         *
+         * @param music[in] The track to add.
+         */
+        void AddMusic(const AudioManager::Music& music);
+
+        /**
+         * Retrieves a muisc track by name.
+         *
+         * @param name[in] The track name
+         * @return The music track, or nullptr if there is no track by that
+         * name.
+         */
+        AudioManager::Music* GetMusic(const Ogre::String& name);
 
     private:
-        boost::recursive_mutex* m_UpdateMutex;
-        float                   m_Loop;
-        OggVorbis_File          m_VorbisFile;
-        vorbis_info*            m_VorbisInfo;
-        int                     m_VorbisSection;
-        bool                    m_StreamFinished;
-        ALuint                  m_Source;
 
-        ALsizei FillBuffer();
-    };
+        /**
+         * Initializes the audio manager.
+         *
+         * @todo Verify this comment.
+         */
+        const bool Init();
 
+        /**
+         * Handles errors
+         *
+         * @return nullptr
+         * @todo Implement and get error info.
+         */
+        const char* ALError();
 
+        /**
+         * Handles errors
+         *
+         * @return nullptr
+         * @todo Implement and get error info.
+         */
+        const char* ALCError( const ALCdevice* device );
 
-private:
-    bool                   m_Initialized;
+        /**
+         * An audio player
+         */
+        class Player{
 
-    ALCdevice*             m_ALDevice;
-    ALCcontext*            m_ALContext;
-    char*                  m_Buffer;
+            public:
+                /**
+                 * Constructor.
+                 *
+                 * @param mutex[in] Mutex to handle concurrent updates.
+                 */
+                Player(boost::recursive_mutex* mutex);
 
-    boost::recursive_mutex m_UpdateMutex;
-    boost::thread*         m_UpdateThread;
-    bool                   m_ThreadContinue;
+                /**
+                 * Destructor.
+                 */
+                ~Player();
 
-    AudioManager::Player             m_Music;
-    std::list< AudioManager::Music > m_MusicList;
+                /**
+                 * Pauses the player.
+                 */
+                void Pause();
 
-    // allocate for every new player two 96Kb buffer chunks
-    // every chunk would buffer ~0.5 seconds of 44100Hz stereo 16-bit data
-    // in that case we can sleep updating buffers for 250ms
-    static ALsizei m_ChannelBufferSize;
-    static int m_ChannelBufferNumber;
-};
+                /**
+                 * Plays an audio file.
+                 *
+                 * @param file[in] Path to the file to play
+                 */
+                void Play(const Ogre::String& file);
+
+                /**
+                 * Stops the audio player.
+                 */
+                void Stop();
+
+                /**
+                 * Sets the loop for the current track.
+                 *
+                 * @param loop[in] Loop point
+                 */
+                void SetLoop(const float loop);
+
+                /**
+                 * Updates the audio player.
+                 *
+                 * @param Understand and document.
+                 */
+                void Update();
+
+                /**
+                 * Get the playing position of the current track.
+                 *
+                 * @return Playing position.
+                 * @todo Is this in seconds?
+                 */
+                float GetPosition();
+
+            private:
+
+                /**
+                 * Mutex to handle concurrent update on the player.
+                 */
+                boost::recursive_mutex* update_mutex_;
+
+                /**
+                 * Loop point for the current track.
+                 */
+                float loop_;
 
+                /**
+                 * File played or to play.
+                 */
+                OggVorbis_File vorbis_file_;
 
+                /**
+                 * Info about the track.
+                 */
+                vorbis_info* vorbis_info_;
 
-#endif // AUDIO_MANAGER_H
+                /**
+                 * Section of the track.
+                 */
+                int vorbis_section_;
+
+                /**
+                 * Indicates if the stream is finished.
+                 */
+                bool stream_finished_;
+
+                /**
+                 * Audio source.
+                 */
+                ALuint source_;
+
+                /**
+                 * Fills the audio buffer.
+                 *
+                 * @return Size of the data added to the buffer.
+                 */
+                ALsizei FillBuffer();
+        };
+
+    private:
+
+        /**
+         * Indicatesif the audio manager has been initialized.
+         */
+        bool initialized_;
+
+        /**
+         * Audio output device.
+         */
+        ALCdevice* al_device_;
+
+        /**
+         * Audio context.
+         */
+        ALCcontext* al_context_;
+
+        /**
+         * Audio buffer.
+         */
+        char* buffer_;
+
+        /**
+         * Mutex to handle concurrent operations.
+         */
+        boost::recursive_mutex update_mutex_;
+
+        /**
+         * Thread to handle consurrent operations.
+         */
+        boost::thread* update_thread_;
+
+        /**
+         * Flag to indicate if the playback must continue.
+         */
+        bool thread_continue_;
+
+        /**
+         * Music player
+         */
+        AudioManager::Player music_;
+
+        /**
+         * List of music.
+         */
+        std::list<AudioManager::Music> music_list_;
+
+        /**
+         * Size of a channel buffer.
+         *
+         * 96Kb are allocated for each channel. ~0.5 seconds of 44100Hz stereo
+         * 16-bit data can be allocated in each channel. This way, 250ms can
+         * pass between buffer updates.
+         */
+        static ALsizei channel_buffer_size_;
+
+        /**
+         * Number of buffers.
+         *
+         * 2 channels.
+         */
+        static int channel_buffer_number_;
+};

+ 641 - 146
QGearsMain/include/core/Background2D.h

@@ -1,158 +1,653 @@
-#ifndef BACKGROUND_2D_H
-#define BACKGROUND_2D_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreHardwareVertexBuffer.h>
 #include <OgreRenderQueueListener.h>
 #include <OgreRoot.h>
-
 #include "map/QGearsBackground2DFile.h"
-
 #include "Background2DAnimation.h"
 #include "Entity.h"
 #include "ScriptManager.h"
 
-
-class Background2D : public Ogre::RenderQueueListener
-{
-public:
-
-    typedef QGears::Blending  Blending;
-
-    enum ScrollType
-    {
-        NONE,
-        LINEAR,
-        SMOOTH
-    };
-
-    Background2D();
-    virtual ~Background2D();
-
-    void InputDebug(const QGears::Event& event);
-    void Update();
-    void UpdateDebug();
-    void OnResize();
-
-    void Clear();
-
-    void ScriptAutoScrollToEntity( Entity* entity );
-    Entity* GetAutoScrollEntity() const;
-    void ScriptScrollToPosition( const float x, const float y, const ScrollType type, const float seconds );
-    int ScriptScrollSync();
-    void UnsetScroll();
-    const Ogre::Vector2& GetScrollPositionStart() const;
-    const Ogre::Vector2& GetScrollPositionEnd() const;
-    ScrollType GetScrollType() const;
-    float GetScrollSeconds() const;
-    void SetScrollCurrentSeconds( const float seconds );
-    float GetScrollCurrentSeconds() const;
-
-    // Scroll position in screen coordinates
-    void SetScreenScroll( const Ogre::Vector2& position );
-    const Ogre::Vector2 GetScreenScroll() const;
-    // scroll in game internal screen coordinates
-    void SetScroll( const Ogre::Vector2& position );
-    const Ogre::Vector2& GetScroll() const;
-
-
-    void SetImage( const Ogre::String& image );
-
-    void SetRange( const int min_x, const int min_y, const int max_x, const int max_y );
-    void SetRange( const Ogre::Vector4& range );
-
-    void AddTile( const int x, const int y, const int width, const int height, const float depth, const float u1, const float v1, const float u2, const float v2, const Blending blending );
-    void AddTile( const Ogre::Vector2& destination, const int width, const int height, const float depth, const Ogre::Vector4& uv, const Blending blending );
-    void AddTile( const QGears::Tile& tile );
-
-    void UpdateTileUV( const unsigned int tile_id, const float u1, const float v1, const float u2, const float v2 );
-
-    void AddAnimation( Background2DAnimation* animation );
-    void PlayAnimation( const Ogre::String& animation, const Background2DAnimation::State state );
-    void ScriptPlayAnimationLooped( const char* name );
-    void ScriptPlayAnimationOnce( const char* name );
-    int ScriptAnimationSync( const char* name );
-
-    void renderQueueEnded( Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation );
-
-    struct Tile
-    {
-        int x;
-        int y;
-        int width;
-        int height;
-        size_t start_vertex_index;
-        Blending blending;
-    };
-    typedef std::vector< Tile > TileList;
-
-    virtual void load( const QGears::Background2DFilePtr &background );
-
-protected:
-    virtual void load( const QGears::Background2DFile::TileList &tiles );
-    virtual void load( const size_t tile_index, const QGears::AnimationMap &animations );
-    virtual void applyScroll( void );
-    virtual void calculateScreenScale( void );
-    virtual void virtualScreenToWorldSpace( Ogre::Vector2 &pos ) const;
-
-    enum
-    {
-        TILE_VERTEX_COUNT = 6
-       ,TILE_VERTEX_INDEX_SIZE = TILE_VERTEX_COUNT + 3
-    };
-
-private:
-    void CreateVertexBuffers();
-    void DestroyVertexBuffers();
-
-private:
-    Ogre::SceneManager*                   m_SceneManager;
-    Ogre::RenderSystem*                   m_RenderSystem;
-
-    TileList                              m_Tiles;
-
-    // alpha blended
-    Ogre::RenderOperation                 m_AlphaRenderOp;
-    Ogre::HardwareVertexBufferSharedPtr   m_AlphaVertexBuffer;
-    unsigned int                          m_AlphaMaxVertexCount;
-    Ogre::MaterialPtr                     m_AlphaMaterial;
-
-    // add blended
-    Ogre::RenderOperation                 m_AddRenderOp;
-    Ogre::HardwareVertexBufferSharedPtr   m_AddVertexBuffer;
-    unsigned int                          m_AddMaxVertexCount;
-    Ogre::MaterialPtr                     m_AddMaterial;
-
-    // subtract blended
-    Ogre::RenderOperation                 m_SubtractRenderOp;
-    Ogre::HardwareVertexBufferSharedPtr   m_SubtractVertexBuffer;
-    unsigned int                          m_SubtractMaxVertexCount;
-    Ogre::MaterialPtr                     m_SubtractMaterial;
-
-    Entity*                               m_ScrollEntity;
-    Ogre::Vector2                         m_ScrollPositionStart;
-    Ogre::Vector2                         m_ScrollPositionEnd;
-    ScrollType                            m_ScrollType;
-    float                                 m_ScrollSeconds;
-    float                                 m_ScrollCurrentSeconds;
-    std::vector< ScriptId >               m_ScrollSync;
-    Ogre::Vector2                         m_Position;
-    Ogre::Vector2                         m_PositionReal;
-
-    Ogre::Real                            m_screen_scale;
-    Ogre::Vector2                         m_screen_proportion;
-    Ogre::Vector2                         m_virtual_screen_size;
-    Ogre::AxisAlignedBox                  m_range;
-
-    struct AnimationPlayed
-    {
-        Ogre::String                 name;
-        std::vector< ScriptId >      sync;
-        Background2DAnimation::State state;
-    };
-    std::vector< AnimationPlayed >        m_AnimationPlayed;
-    std::vector< Background2DAnimation* > m_Animations;
+/**
+ * A field background
+ */
+class Background2D : public Ogre::RenderQueueListener{
+
+    public:
+
+        typedef QGears::Blending  Blending;
+
+        /**
+         * How to scroll the background.
+         */
+        enum ScrollType{
+
+            /**
+             * Don't scroll the background.
+             */
+            NONE,
+
+            /**
+             * Linearly scroll.
+             *
+             * May seem unnatural in scripted sequences, but it's OK for
+             * character tracking.
+             */
+            LINEAR,
+            /**
+             * Smooth (soft in, soft out) scroll.
+             *
+             * Best for scripted sequences.
+             */
+            SMOOTH
+        };
+
+        /**
+         * Constructor.
+         */
+        Background2D();
+
+        /**
+         * Destructor
+         */
+        virtual ~Background2D();
+
+        /**
+         * @todo Understand and document.
+         * @param event[in] Event.
+         */
+        void InputDebug(const QGears::Event& event);
+
+        /**
+         * Run each frame.
+         *
+         * Updates animations and changes in the background.
+         */
+        void Update();
+
+        /**
+         * Debug inormation about changes in the background.
+         */
+        void UpdateDebug();
+
+        /**
+         * Called on window resize.
+         *
+         * Resizes the background, keeping the ratio.
+         */
+        void OnResize();
+
+        /**
+         * Removes the background and it's animations.
+         */
+        void Clear();
+
+        /**
+         * Flags the background to automatically scroll to an entity position.
+         *
+         * @param entity The entity to track.
+         */
+        void ScriptAutoScrollToEntity(Entity* entity);
+
+        /**
+         * Retrieves the entity currently being tracked for autoscroll.
+         *
+         * @return The entity currently being tracked, or nullptr if the
+         * background is not currently scrolling to any entity.
+         */
+        Entity* GetAutoScrollEntity() const;
+
+        /**
+         * Scrolls the background to a position.
+         *
+         * @param x[in] X coordinate to scroll to.
+         * @param y[in] Y coordinate to scroll to.
+         * @param type[in] Scroll type.
+         * @param seconds[in] Duration of the scroll.
+         */
+        void ScriptScrollToPosition(
+          const float x, const float y,
+          const ScrollType type, const float seconds
+        );
+
+        /**
+         * Waits for the scroll to complete.
+         *
+         * @return -1.
+         */
+        int ScriptScrollSync();
+
+        /**
+         * Stops the current scrolling.
+         */
+        void UnsetScroll();
+
+        /**
+         * Retrieves the initial position of the current scroll action.
+         *
+         * @return The initial position of the current scroll action.
+         */
+        const Ogre::Vector2& GetScrollPositionStart() const;
+
+        /**
+         * Retrieves the final position of the current scroll action.
+         *
+         * @return The final position of the current scroll action.
+         */
+        const Ogre::Vector2& GetScrollPositionEnd() const;
+
+        /**
+         * Retrieves the type of the current scroll action.
+         *
+         * @return The type of the current scroll action.
+         */
+        ScrollType GetScrollType() const;
+
+        /**
+         * Retrieves the total duration the current scroll action.
+         *
+         * @return Duration of the current scroll action.
+         */
+        float GetScrollSeconds() const;
+
+        /**
+         * Sets the time taken by the current scroll action.
+         *
+         * It represents the time the current scroll action has been going on
+         * for.
+         *
+         * @param seconds[in] Time taken by the current scroll action.
+         */
+        void SetScrollCurrentSeconds(const float seconds);
+
+        /**
+         * Retrieves the time taken by the current scroll action.
+         *
+         * It represents the time the current scroll action has been going on
+         * for.
+         *
+         * @return Time taken by the current scroll action.
+         */
+        float GetScrollCurrentSeconds() const;
+
+        /**
+         * Scroll position in screen coordinates.
+         *
+         * @param position[in] Position to set the scroll.
+         */
+        void SetScreenScroll(const Ogre::Vector2& position);
+
+        /**
+         * Retrieves the scroll position in screen coordinates.
+         *
+         * @return Screen coordinates of the scroll.
+         */
+        const Ogre::Vector2 GetScreenScroll() const;
+
+        /**
+         * Sets the scroll in game internal screen coordinates.
+         *
+         * @param position[in] Position to set the scroll.
+         */
+        void SetScroll(const Ogre::Vector2& position);
+
+        /**
+         * Retrieves the scroll position in game internal screen coordinates.
+         *
+         * @return Screen coordinates of the scroll.
+         */
+        const Ogre::Vector2& GetScroll() const;
+
+        /**
+         * Sets the background image.
+         *
+         * @param image[in] Image name.
+         */
+        void SetImage( const Ogre::String& image );
+
+        /**
+         * Set the background scrolling range.
+         *
+         * The range is applied in game internal screen coordinates.
+         *
+         * @param min_x[in] Min scrollabe x coordinate.
+         * @param min_y[in] Min scrollabe y coordinate.
+         * @param max_x[in] Max scrollabe x coordinate.
+         * @param max_y[in] Max scrollabe y coordinate.
+         */
+        void SetRange(
+          const int min_x, const int min_y, const int max_x, const int max_y
+        );
+
+        /**
+         * Set the background scrolling range.
+         *
+         * The range is applied in game internal screen coordinates.
+         *
+         * @param range[in] Range bounds vector.
+         */
+        void SetRange(const Ogre::Vector4& range);
+
+        /**
+         * Adds a tile to the background
+         *
+         * @param x[in] X coordinate for the tile.
+         * @param y[in] Y coordinate for the tile.
+         * @param width[in] Tile width.
+         * @param height[in] Tile height.
+         * @param depth[in] Depth of the tile.
+         * @param u1[in]
+         * @param v1[in]
+         * @param u2[in]
+         * @param v2[in]
+         * @param blending[in] Blending mode for the tile
+         * @todo Depth is z-index??
+         * @todo What are v1, v2, u1 and u2?
+         */
+        void AddTile(
+          const int x, const int y, const int width, const int height,
+          const float depth, const float u1, const float v1,
+          const float u2, const float v2, const Blending blending
+        );
+
+        /**
+         * Adds a tile to the background
+         *
+         * @param destination[in] Coordinates for the tile.
+         * @param width[in] Tile width.
+         * @param height[in] Tile height.
+         * @param depth[in] Depth of the tile.
+         * @param uv[in]
+         * @param blending[in] Blending mode for the tile
+         * @todo Depth is z-index??
+         * @todo What is uv?
+         */
+        void AddTile(
+          const Ogre::Vector2& destination, const int width, const int height,
+          const float depth, const Ogre::Vector4& uv, const Blending blending
+        );
+
+        /**
+         * Adds a tile to the background
+         *
+         * @param tile[in] The tile to add.
+         */
+        void AddTile(const QGears::Tile& tile);
+
+        /**
+         * Updates the UV vector of a tile
+         *
+         * @param tile_id[in] ID of the tile to update.
+         * @param u1[in]
+         * @param v1[in]
+         * @param u2[in]
+         * @param v2[in]
+         * @todo What are v1, v2, u1 and u2?
+         */
+        void UpdateTileUV(
+          const unsigned int tile_id,
+          const float u1, const float v1, const float u2, const float v2
+        );
+
+        /**
+         * Adds an animation to the background.
+         *
+         * @param animation[in] Animation to add.
+         */
+        void AddAnimation(Background2DAnimation* animation);
+
+        /**
+         * Plays an animation.
+         *
+         * @param animation[in] The animation to play.
+         * @param state[in] Animation state.
+         */
+        void PlayAnimation(
+          const Ogre::String& animation, const Background2DAnimation::State state
+        );
+
+        /**
+         * Plays an animation in a loop.
+         *
+         * The animation is played asynchronously.
+         *
+         * @param name[in] Animation name.
+         */
+        void ScriptPlayAnimationLooped(const char* name);
+
+        /**
+         * Plays an animation once, then stops.
+         *
+         * The animation is played asynchronously.
+         *
+         * @param name[in] Animation name.
+         */
+        void ScriptPlayAnimationOnce(const char* name);
+
+        /**
+         * Plays an animation once, then stops.
+         *
+         * The animation is played synchronously, and the thread is locked
+         * until it ends.
+         *
+         * @param name[in] Animation name.
+         */
+        int ScriptAnimationSync(const char* name);
+
+        /**
+         * Ends the render queue.
+         *
+         * @param queueGroupId[in] The group id of the queue to end.
+         * @param invocation[in]
+         * @param repeatThisInvocation[in]
+         * @todo Understand and document.
+         */
+        void renderQueueEnded(
+          Ogre::uint8 queueGroupId, const Ogre::String& invocation,
+          bool& repeatThisInvocation
+        ) override;
+
+        /**
+         * Represents a tile.
+         */
+        struct Tile{
+
+            /**
+             * Tile X coordinate.
+             */
+            int x;
+
+            /**
+             * Tile Y coordinate.
+             */
+            int y;
+
+            /**
+             * Tile width.
+             */
+            int width;
+
+            /**
+             * Tile height.
+             */
+            int height;
+
+            /**
+             * @todo
+             */
+            size_t start_vertex_index;
+
+            /**
+             * Tile blending mode.
+             */
+            Blending blending;
+        };
+
+        typedef std::vector<Tile> TileList;
+
+        /**
+         * Loads a background.
+         *
+         * @param background[in] The background to load.
+         */
+        virtual void load(const QGears::Background2DFilePtr &background);
+
+    protected:
+
+        /**
+         * Loads a tile list to the background.
+         *
+         * @param tiles[in] The list of tiles to load.
+         */
+        virtual void load(const QGears::Background2DFile::TileList &tiles);
+
+        /**
+         * Loads an animation list to the background.
+         *
+         * @param tiles_index[in]
+         * @param animations[in] List of animations to load.
+         */
+        virtual void load(
+          const size_t tile_index, const QGears::AnimationMap &animations
+        );
+
+        /**
+         * Apply the camera position to match the current scroll.
+         */
+        virtual void applyScroll(void);
+
+        /**
+         * Calculates the screen scale.
+         *
+         * The scale is calculated as the proportion between the viewport and
+         * the virtual screen.
+         */
+        virtual void calculateScreenScale(void);
+
+
+        /**
+         * Sets the virtual screen to world space.
+         *
+         * @param pos[in]
+         * @todo Understand and document.
+         */
+        virtual void virtualScreenToWorldSpace(Ogre::Vector2 &pos) const;
+
+        /**
+         * Tile vertex properties.
+         */
+        enum{
+
+            /**
+             * Tile vertex count.
+             *
+             * @todo Understand and document.
+             */
+            TILE_VERTEX_COUNT = 6,
+
+            /**
+             * Tile vertex index size.
+             */
+            TILE_VERTEX_INDEX_SIZE = TILE_VERTEX_COUNT + 3
+        };
+
+    private:
+
+        /**
+         * Creates all vertex buffers.
+         */
+        void CreateVertexBuffers();
+
+        /**
+         * Destroys all vertex buffers.
+         */
+        void DestroyVertexBuffers();
+
+        /**
+         * The scene manager.
+         */
+        Ogre::SceneManager* scene_manager_;
+
+        /**
+         * The render system.
+         */
+        Ogre::RenderSystem* render_system_;
+
+        /**
+         * The list of tiles in the background.
+         */
+        TileList tiles_;
+
+        /**
+         * Alpha blending render operation.
+         */
+        Ogre::RenderOperation alpha_render_op_;
+
+        /**
+         * Alpha blending vertex buffer.
+         */
+        Ogre::HardwareVertexBufferSharedPtr alpha_vertex_buffer_;
+
+        /**
+         * Alpha blending max vertex count.
+         */
+        unsigned int alpha_max_vertex_count_;
+
+        /**
+         * Alpha blending material.
+         */
+        Ogre::MaterialPtr alpha_material_;
+
+        /**
+         * Add blending render operation.
+         */
+        Ogre::RenderOperation add_render_op_;
+
+        /**
+         * Add blending vertex buffer.
+         */
+        Ogre::HardwareVertexBufferSharedPtr add_vertex_buffer_;
+
+        /**
+         * Add blending max vertex count.
+         */
+        unsigned int add_max_vertex_count_;
+
+        /**
+         * Add blending material.
+         */
+        Ogre::MaterialPtr add_material;
+
+        /**
+         * Substract blending render operation.
+         */
+        Ogre::RenderOperation subtract_render_op_;
+
+        /**
+         * Substract blending vertex buffer.
+         */
+        Ogre::HardwareVertexBufferSharedPtr subtract_vertex_buffer_;
+
+        /**
+         * Substract blending max vertex count.
+         */
+        unsigned int subtract_max_vertex_count_;
+
+        /**
+         * Substract blending material.
+         */
+        Ogre::MaterialPtr subtract_material_;
+
+        /**
+         * The entity to keep track of with the scroll.
+         */
+        Entity* scroll_entity_;
+
+        /**
+         * Starting position of the current scroll action.
+         */
+        Ogre::Vector2 scroll_position_start_;
+
+        /**
+         * Final position of the current scroll action.
+         */
+        Ogre::Vector2 scroll_position_end_;
+
+        /**
+         * Type of the current scroll action.
+         */
+        ScrollType scroll_type_;
+
+        /**
+         * Total duration of the current scroll action, in seconds
+         */
+        float scroll_seconds_;
+
+        /**
+         * Secund the currens scroll action has taken so far.
+         */
+        float scroll_current_seconds_;
+
+        /**
+         * @todo Document.
+         */
+        std::vector<ScriptId> scroll_sync_;
+
+        /**
+         * The current scroll position, virtual screen size.
+         */
+        Ogre::Vector2 position_;
+
+        /**
+         * The current scroll position, viewport size.
+         */
+        Ogre::Vector2 position_real_;
+
+        /**
+         * The scale of the screen
+         */
+        Ogre::Real screen_scale_;
+
+        /**
+         * Screen aspect ration.
+         */
+        Ogre::Vector2 screen_proportion_;
+
+        /**
+         * The size of the virtual screen.
+         */
+        Ogre::Vector2 virtual_screen_size_;
+
+        /**
+         * @todo Document.
+         */
+        Ogre::AxisAlignedBox range_;
+
+        /**
+         * State of an animation.
+         */
+        struct AnimationPlayed{
+
+            /**
+             * Animation name.
+             */
+            Ogre::String name;
+
+            /**
+             * @todo Document
+             */
+            std::vector<ScriptId> sync;
+
+            /**
+             * Animation state.
+             */
+            Background2DAnimation::State state;
+        };
+
+        /**
+         * @todo Document.
+         */
+        std::vector<AnimationPlayed> animation_played_;
+
+        /**
+         * List of animations.
+         */
+        std::vector<Background2DAnimation*> animations_;
 };
 
 
-
-#endif // BACKGROUND_2D_H

+ 201 - 52
QGearsMain/include/core/Background2DAnimation.h

@@ -1,62 +1,211 @@
-#ifndef BACKGROUND_2D_ANIMATION_H
-#define BACKGROUND_2D_ANIMATION_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreString.h>
 #include <Ogre.h>
 #include <vector>
-
 #include "map/QGearsTile.h"
 
 class Background2D;
 
-
-
-class Background2DAnimation
-{
-public:
-    Background2DAnimation( const Ogre::String& name, Background2D* background, const int tile_index );
-    virtual ~Background2DAnimation();
-
-    enum State
-    {
-        ONCE,
-        LOOPED
-    };
-
-    void  AddTime( const float time );
-
-    const Ogre::String& GetName() const;
-
-    void  SetTime( const float time );
-    float GetTime() const;
-    void  SetLength( const float time );
-    float GetLength() const;
-
-    virtual void AddUVKeyFrame( const QGears::KeyFrame key_frame );
-    virtual void AddUVKeyFrame( const float time, const Ogre::Vector4& uv );
-    virtual void AddUVKeyFrame( const float time, const float u1, const float v1, const float u2, const float v2 );
-
-private:
-    Background2DAnimation();
-
-    Ogre::String  m_Name;
-    Background2D* m_Background;
-    int           m_TileIndex;
-
-    float         m_Time;
-    float         m_Length;
-
-    struct Background2DKeyFrameUV
-    {
-        float time;
-        float u1;
-        float v1;
-        float u2;
-        float v2;
-    };
-    std::vector< Background2DKeyFrameUV > m_UV;
+/**
+ * An animation in the background of a field.
+ */
+class Background2DAnimation{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param name[in] The animation name.
+         * @param background[in] The background to animate.
+         * @param tile_index[in] The tile the animation applies to.
+         */
+        Background2DAnimation(
+          const Ogre::String& name, Background2D* background,
+          const int tile_index
+        );
+
+        /**
+         * Destructor.
+         */
+        virtual ~Background2DAnimation();
+
+        /**
+         * Repetition status of the animation.
+         */
+        enum State{
+
+            /**
+             * The animation must be played once.
+             */
+            ONCE,
+
+            /**
+             * The animation must loop indefinitely.
+             */
+            LOOPED
+        };
+
+        /**
+         * Adds time, so the animation state is changed according to it.
+         *
+         * @param time[in] The time passed
+         * @todo time is in seconds?
+         */
+        void AddTime(const float time);
+
+        /**
+         * Retrieves the animation name.
+         *
+         * @return The animation name.
+         */
+        const Ogre::String& GetName() const;
+
+        /**
+         * Sets the time the animation has been running.
+         *
+         * @param time[in] The time the animation has been running.
+         * @todo time is in seconds?
+         */
+        void  SetTime( const float time );
+
+        /**
+         * Retrieves the time the animation has been running.
+         *
+         * @return The time the animation has been running.
+         * @todo time is in seconds?
+         */
+        float GetTime() const;
+
+        /**
+         * Sets the duration of the animation.
+         *
+         * @param time[in] The duration of the animation.
+         * @todo time is in seconds?
+         */
+        void  SetLength(const float time);
+
+        /**
+         * Retrieves the duration of the animation.
+         *
+         * @return The duration of the animation.
+         * @todo time is in seconds?
+         */
+        float GetLength() const;
+
+        /**
+         * Adds a keyframe to the animation.
+         *
+         * @param key_frame[in] The keyframe to add.
+         */
+        virtual void AddUVKeyFrame(const QGears::KeyFrame key_frame);
+
+        /**
+         * Adds a keyframe to the animation.
+         *
+         * @param time[in] Time to add the keyframe at.
+         * @param uv[in] Animation vector.
+         * @todo time is in seconds?
+         */
+        virtual void AddUVKeyFrame(const float time, const Ogre::Vector4& uv);
+
+        /**
+         * Adds a keyframe to the animation.
+         *
+         * @param time[in] Time to add the keyframe at.
+         * @param u1[in] Animation vector component.
+         * @param v1[in] Animation vector component.
+         * @param u2[in] Animation vector component.
+         * @param v2[in] Animation vector component.
+         * @todo time is in seconds?
+         */
+        virtual void AddUVKeyFrame(
+          const float time,
+          const float u1, const float v1, const float u2, const float v2
+        );
+
+    private:
+
+        /**
+         * Constructor.
+         */
+        Background2DAnimation();
+
+        /**
+         * The animation name.
+         */
+        Ogre::String name_;
+
+        /**
+         * The background the animation belongs to.
+         */
+        Background2D* background_;
+
+        /**
+         * The index of the tile tha animation applies to.
+         */
+        int tile_index_;
+
+        /**
+         * The animation current time.
+         */
+        float time_;
+
+        /**
+         * The duration of the animation.
+         */
+        float length_;
+
+        /**
+         * A keyframe.
+         */
+        struct Background2DKeyFrameUV{
+
+            /**
+             * Keyframe time.
+             */
+            float time;
+
+            /**
+             * Keyframe vector component.
+             */
+            float u1;
+
+            /**
+             * Keyframe vector component.
+             */
+            float v1;
+
+            /**
+             * Keyframe vector component.
+             */
+            float u2;
+
+            /**
+             * Keyframe vector component.
+             */
+            float v2;
+        };
+
+        /**
+         * Keyframe list.
+         */
+        std::vector<Background2DKeyFrameUV> uv_;
 };
 
-
-
-#endif // BACKGROUND_2D_ANIMATION_H

+ 186 - 49
QGearsMain/include/core/CameraManager.h

@@ -1,56 +1,193 @@
-#ifndef CAMERA_MANAGER_H
-#define CAMERA_MANAGER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreCamera.h>
 #include <OgreSingleton.h>
-
 #include "Event.h"
 
-
-
-class CameraManager : public Ogre::Singleton< CameraManager >
-{
-public:
-    CameraManager();
-    virtual ~CameraManager();
-
-    void Input(const QGears::Event& event , Ogre::Real timeSinceLastFrame);
-    void Update();
-    void OnResize();
-
-    // camera free related
-    void SetCameraFree( const bool enable );
-
-    // camera 2D related
-    void Set2DCamera( const Ogre::Vector3 position, const Ogre::Quaternion orientation, const Ogre::Radian fov );
-    void Set2DScroll( const Ogre::Vector2& position );
-    const Ogre::Vector2& Get2DScroll() const;
-
-    const Ogre::Vector3 ProjectPointToScreen( const Ogre::Vector3& point );
-
-    Ogre::Camera*   GetCurrentCamera();
-    Ogre::Viewport* getViewport();
-
-    void EnableWireFrame(bool);
-private:
-
-    void InitCommands();
-
-private:
-    Ogre::Camera   *m_Camera;
-    Ogre::Viewport *m_Viewport;
-
-    // camera free related
-    bool m_CameraFree;
-    bool m_CameraFreeRotate;
-
-    // camera 2D related
-    Ogre::Vector3 m_2DPosition;
-    Ogre::Quaternion m_2DOrientation;
-    Ogre::Radian m_2DFOV;
-    Ogre::Vector2 m_2DScroll;
+/**
+ * The camera manager.
+ */
+class CameraManager : public Ogre::Singleton<CameraManager>{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * Initializes the camera with default parameters attached to the root scene
+         * manager.
+         */
+        CameraManager();
+
+        /**
+         * Destructor.
+         */
+        virtual ~CameraManager();
+
+        /**
+         * Handles camera actions.
+         *
+         * Handles the scene manager camera actions based on events.
+         *
+         * @param event[in] Event that triggers the camera action.
+         * @param time_since_last_frame[in] For speed calculation.
+         */
+        void Input(
+          const QGears::Event& event , Ogre::Real time_since_last_frame
+        );
+
+        /**
+         * Triggered when updated.
+         *
+         * Unused.
+         */
+        void Update();
+
+        /**
+         * Trigered when the viewport is resized.
+         *
+         * Resets the aspect ratio.
+         */
+        void OnResize();
+
+        /**
+         * Enables or disables the free camera.
+         *
+         * A free camera moves depending on player input, not according to a
+         * script. For example, a camera following the PC is a free camera.
+         *
+         * @param enable[in] True to enable free camera, false to disable it.
+         */
+        void SetCameraFree(const bool enable);
+
+        /**
+         * Sets the camera properties.
+         *
+         * @param position[in] Camera coordinates.
+         * @param orientation[in] Camera rotation, in quaternion format.
+         * @param fov[in] Field of view, in radians.
+         */
+        void Set2DCamera(
+          const Ogre::Vector3 position, const Ogre::Quaternion orientation,
+          const Ogre::Radian fov
+        );
+
+        /**
+         * Sets the camera scroll.
+         *
+         * Moves the camera to the desired position. If the camera is in free
+         * mode, it sets the position, but it won't actually move the camera.
+         *
+         * @param position[in] Position to scroll the camera to.
+         */
+        void Set2DScroll(const Ogre::Vector2& position);
+
+        /**
+         * Retrieves the camera position.
+         *
+         * @return The camera current position, relative to absolute origin.
+         */
+        const Ogre::Vector2& Get2DScroll() const;
+
+        /**
+         * Calculates the position of a point in screen.
+         *
+         * The calculation is done using A map position and the camera scroll.
+         *
+         * @param point[in] Position of the map to be translated to screen
+         * position.
+         * @return Position of POINT in screen coordinates.
+         */
+        const Ogre::Vector3 ProjectPointToScreen(const Ogre::Vector3& point);
+
+        /**
+         * Retrieves the camera.
+         *
+         * @return The current camera.
+         */
+        Ogre::Camera* GetCurrentCamera();
+
+        /**
+         * Retrieves the viewport.
+         *
+         * @return The camera viewport.
+         */
+        Ogre::Viewport* getViewport();
+
+        /**
+         * Enables or disables the camera wireframe.
+         *
+         * In wireframe mode, faces will not be rendered, only edges
+         *
+         * @param enable[in] True to enable wireframe mode, false to disable.
+         */
+        void EnableWireFrame(bool enable);
+
+    private:
+
+        /**
+         * Initializes the camera parameters.
+         *
+         * Must be called on construction.
+         */
+        void InitCommands();
+
+        /**
+         * The camera.
+         */
+        Ogre::Camera *camera_;
+
+        /**
+         * The viewport.
+         */
+        Ogre::Viewport *viewport_;
+
+        /**
+         * Flag to indicate a free camera.
+         *
+         * A free camera moves depending on player input, not according to a
+         * script. For example, a camera following the PC is a free camera.
+         */
+        bool camera_free_;
+
+        /**
+         * Flag to indicate the free camera has rotated.
+         */
+        bool camera_free_rotate_;
+
+        /**
+         * Camera position.
+         */
+        Ogre::Vector3 d2_position_;
+
+        /**
+         * Camera orientation.
+         */
+        Ogre::Quaternion d2_orientation_;
+
+        /**
+         * The field of view.
+         */
+        Ogre::Radian d2_fov_;
+
+        /**
+         * The camera scroll.
+         */
+        Ogre::Vector2 d2_scroll_;
 };
 
-
-
-#endif // CAMERA_MANAGER_H

+ 29 - 22
QGearsMain/include/core/CameraManagerCommands.h

@@ -1,36 +1,43 @@
-#include <OgreStringConverter.h>
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
+#include <OgreStringConverter.h>
 #include "CameraManager.h"
 #include "ConfigCmdManager.h"
 #include "Console.h"
 
-
-
-void
-CommandCameraFree( const Ogre::StringVector& params )
-{
-    if( params.size() < 1 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /camera_free <enable>" );
+void CommandCameraFree(const Ogre::StringVector& params){
+    if (params.size() < 1){
+        Console::getSingleton().AddTextToOutput("Usage: /camera_free <enable>");
         return;
     }
-
-    CameraManager::getSingleton().SetCameraFree( Ogre::StringConverter::parseBool( params[ 1 ] ) );
+    CameraManager::getSingleton().SetCameraFree(
+      Ogre::StringConverter::parseBool(params[1])
+    );
 }
 
-
-
-void
-CommandCameraFreeCompletition( Ogre::StringVector& complete_params )
-{
+void CommandCameraFreeCompletition( Ogre::StringVector& complete_params ){
     complete_params.push_back( "true" );
     complete_params.push_back( "false" );
 }
 
-
-
-void
-CameraManager::InitCommands()
-{
-    ConfigCmdManager::getSingleton().AddCommand( "camera_free", "Enable or disable free camera", "", CommandCameraFree, CommandCameraFreeCompletition );
+void CameraManager::InitCommands(){
+    ConfigCmdManager::getSingleton().AddCommand(
+      "camera_free", "Enable or disable free camera", "",
+      CommandCameraFree, CommandCameraFreeCompletition
+    );
 }

+ 117 - 32
QGearsMain/include/core/ConfigCmd.h

@@ -1,45 +1,130 @@
-#ifndef CONFIG_CMD_H
-#define CONFIG_CMD_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreString.h>
 #include <OgreStringVector.h>
 
-
-
 class ConfigCmdManager;
 
-typedef void ( *ConfigCmdHandler )( const Ogre::StringVector& params );
-typedef void ( *ConfigCmdCompletion )( Ogre::StringVector& complete_params );
-
+typedef void (*ConfigCmdHandler)(const Ogre::StringVector& params);
 
+typedef void (*ConfigCmdCompletion)(Ogre::StringVector& complete_params);
 
-class ConfigCmd
-{
-    friend class ConfigCmdManager;
-
-public:
-    const Ogre::String&     GetName() const;
-    const Ogre::String&     GetDescription() const;
-    const Ogre::String&     GetParamsDescription() const;
 
-    ConfigCmdHandler        GetHandler() const;
-    ConfigCmdCompletion     GetCompletion() const;
+/**
+ * A configuration command.
+ */
+class ConfigCmd{
 
+    friend class ConfigCmdManager;
 
-    // ConfigCmd could be created only by ConfigCmdManager
-    ConfigCmd(const Ogre::String& name, const Ogre::String& description, const Ogre::String& params_description, ConfigCmdHandler handler, ConfigCmdCompletion completion);
-private:
-    // forbid copy
-    ConfigCmd(const ConfigCmd& rhs) = delete;
-    ConfigCmd& operator =(const ConfigCmd& rhs) = delete;
-
-    Ogre::String            m_Name;
-    Ogre::String            m_Description;
-    Ogre::String            m_ParamsDescription;
-    ConfigCmdHandler        m_Handler;
-    ConfigCmdCompletion     m_Completion;
+    public:
+
+        /**
+         * Constructor.
+         *
+         * It should only be created only by ConfigCmdManager.
+         *
+         * @param name[in] Command name.
+         * @param description[in] Command description.
+         * @param params_description[in] Command parameters description.
+         * @param handler[in] Command handler.
+         * @param completion[in] Command completion.
+         */
+        ConfigCmd(
+          const Ogre::String& name, const Ogre::String& description,
+          const Ogre::String& params_description, ConfigCmdHandler handler,
+          ConfigCmdCompletion completion
+        );
+
+        /**
+         * Retrieves the command name.
+         *
+         * @return The command name.
+         */
+        const Ogre::String& GetName() const;
+
+        /**
+         * Retrieves the command description.
+         *
+         * @return The command description.
+         */
+        const Ogre::String& GetDescription() const;
+
+        /**
+         * Retrieves the command parameter description.
+         *
+         * @return The command parameter description.
+         */
+        const Ogre::String& GetParamsDescription() const;
+
+        /**
+         * Retrieves the command parameter description.
+         *
+         * @return The command parameter description.
+         */
+        ConfigCmdHandler GetHandler() const;
+
+        /**
+         * Checks the command completion
+         *
+         * @return The command completion.
+         */
+        ConfigCmdCompletion GetCompletion() const;
+
+    private:
+
+        /**
+         * Forbidden copy constructor.
+         *
+         * @param rhs[in] Command to not copy.
+         */
+        ConfigCmd(const ConfigCmd& rhs) = delete;
+
+        /**
+         * Forbidden copy constructor.
+         *
+         * @param rhs[in] Command to not copy.
+         */
+        ConfigCmd& operator =(const ConfigCmd& rhs) = delete;
+
+        /**
+         * The command name.
+         */
+        Ogre::String name_;
+
+        /**
+         * The command description.
+         */
+        Ogre::String description_;
+
+        /**
+         * The command parameters description.
+         */
+        Ogre::String params_description_;
+
+        /**
+         * The command handler.
+         */
+        ConfigCmdHandler handler_;
+
+        /**
+         * The command completion.
+         */
+        ConfigCmdCompletion completion_;
 };
 
-
-
-#endif // CONFIG_CMD_H

+ 96 - 21
QGearsMain/include/core/ConfigCmdManager.h

@@ -1,38 +1,113 @@
-#ifndef CONFIG_CMD_MANAGER_H
-#define CONFIG_CMD_MANAGER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreSingleton.h>
 #include <vector>
 #include <memory>
 #include "ConfigCmd.h"
 
+/**
+ * A manager for configuration commands.
+ */
+class ConfigCmdManager : public Ogre::Singleton<ConfigCmdManager>{
 
+    public:
 
-class ConfigCmdManager : public Ogre::Singleton< ConfigCmdManager >
-{
-public:
-    ConfigCmdManager();
-    ~ConfigCmdManager();
+        /**
+         * Constructor.
+         */
+        ConfigCmdManager();
 
-    void AddCommand( const Ogre::String& name, const Ogre::String& description, const Ogre::String& params_description, ConfigCmdHandler handler, ConfigCmdCompletion completion );
+        /**
+         * Destructor.
+         */
+        ~ConfigCmdManager();
 
-    void ExecuteString( const Ogre::String& cmd_string );
+        /**
+         * Adds a command to the manager.
+         *
+         * @param name[in] Command name.
+         * @param description[in] Command description.
+         * @param params_description[in] Command parameters description.
+         * @param handler[in] Command handler.
+         * @param completion[in] Command completion.
+         */
+        void AddCommand(
+          const Ogre::String& name, const Ogre::String& description,
+          const Ogre::String& params_description, ConfigCmdHandler handler,
+          ConfigCmdCompletion completion
+        );
 
-    // return command with specified name
-    ConfigCmd* Find( const Ogre::String& name ) const;
-    int GetConfigCmdNumber();
-    ConfigCmd* GetConfigCmd( unsigned int i ) const;
+        /**
+         * Executes a command.
+         *
+         * @param cmd_string[in] The command, in string format.
+         */
+        void ExecuteString( const Ogre::String& cmd_string );
 
-private:
-    // forbid copy
-    ConfigCmdManager( const ConfigCmdManager& rhs ) = delete;
-    ConfigCmdManager operator =( const ConfigCmdManager& rhs ) = delete;
+        /**
+         * Finds a command by name.
+         *
+         * @param name[in] Name of the command.
+         * @return The command by the name, or nullptr if there is none.
+         */
+        ConfigCmd* Find(const Ogre::String& name) const;
 
-    void InitCmd();
+        /**
+         * Counts the commands in the manager.
+         *
+         * @return The total number of commands
+         */
+        int GetConfigCmdNumber();
 
-    std::vector< std::unique_ptr<ConfigCmd> > m_Commands;
-};
+        /**
+         * Retrieves a command by index.
+         *
+         * A command index is the position at which it was added to the
+         * manager.
+         */
+        ConfigCmd* GetConfigCmd(unsigned int i) const;
+
+    private:
 
+        /**
+         * Forbidden copy constructor.
+         *
+         * @param rhs[in] Manager to not copy.
+         */
+        ConfigCmdManager(const ConfigCmdManager& rhs) = delete;
 
+        /**
+         * Forbidden copy constructor.
+         *
+         * @param rhs[in] Manager to not copy.
+         */
+        ConfigCmdManager operator =(const ConfigCmdManager& rhs) = delete;
+
+        /**
+         * Initializes the command.
+         *
+         * Must be called from the constructor.
+         */
+        void InitCmd();
+
+        /**
+         * List of command in the manager.
+         */
+        std::vector<std::unique_ptr<ConfigCmd>> commands_;
+};
 
-#endif // CONFIG_CMD_MANAGER_H

+ 361 - 308
QGearsMain/include/core/ConfigCmdManagerCommands.h

@@ -1,7 +1,23 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
+
 #include <OgreRenderWindow.h>
 #include <OgreRoot.h>
 #include <OgreStringConverter.h>
-
 #include "Console.h"
 #include "ConfigCmdManager.h"
 #include "ConfigVarManager.h"
@@ -9,431 +25,468 @@
 #include "Logger.h"
 #include "XmlMapFile.h"
 #include "XmlMapsFile.h"
-
 #include "QGearsGameState.h"
 #include "common/QGearsApplication.h"
 
-
-void
-CmdQuit( const Ogre::StringVector& params )
-{
+/**
+ * Command to quit the application.
+ *
+ * @param params[in] Command parameters. Ignored.
+ */
+void CmdQuit(const Ogre::StringVector& params){
     QGears::g_ApplicationState = QGears::G_EXIT;
 }
 
-
-
-void
-CmdEcho( const Ogre::StringVector& params )
-{
-    if( params.size() < 1 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /echo <string to output>" );
+/**
+ * Command to print to console.
+ *
+ * @param params[in] Command parameters. All of them will be concatenated and
+ * printed. If none are supplied, a command usage text will be printed instead.
+ */
+void CmdEcho(const Ogre::StringVector& params){
+    if (params.size() < 1){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /echo <string to output>"
+        );
         return;
     }
-
     Ogre::String text = "";
-
-    for( size_t i = 1; i < params.size(); ++i )
-    {
-        if( i != 1 )
-        {
-            text += " ";
-        }
-        text += params[ i ];
+    for (size_t i = 1; i < params.size(); ++ i){
+        if (i != 1)text += " ";
+        text += params[i];
     }
-
-    Console::getSingleton().AddTextToOutput( text + "\n" );
+    Console::getSingleton().AddTextToOutput(text + "\n");
 }
 
-
-
-void
-CmdConfigVarList( const Ogre::StringVector& params )
-{
-    if( params.size() > 2 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /config_var_list [search string]" );
+/**
+ * Searches variables in the variable list and prints them.
+ *
+ * @param params[in] Command parameters. The first one is the command name. If
+ * no more are passed, all variables will be printed. If another parameter is
+ * passed, the variables with that name (if any) will be printed. If more than
+ * two parameter are passed, a command usage string will be printed instead.
+ */
+void CmdConfigVarList(const Ogre::StringVector& params){
+    if (params.size() > 2){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /config_var_list [search string]"
+       );
         return;
     }
 
     int number = 0;
     int num_vars = ConfigVarManager::getSingleton().GetConfigVarNumber();
-    for( int i = 0; i < num_vars; ++i )
-    {
-        ConfigVar* var = ConfigVarManager::getSingleton().GetConfigVar( i );
+    for (int i = 0; i < num_vars; ++ i){
+        ConfigVar* var = ConfigVarManager::getSingleton().GetConfigVar(i);
         Ogre::String name = var->GetName();
 
-        if( params.size() > 1 )
-        {
-            int found = name.find( params[ 1 ] );
-            if( found == 0 )
-            {
-                Console::getSingleton().AddTextToOutput( var->GetName() + " = \"" + var->GetS() + "\"" );
+        if (params.size() > 1){
+            int found = name.find(params[1]);
+            if (found == 0){
+                Console::getSingleton().AddTextToOutput(
+                  var->GetName() + " = \"" + var->GetS() + "\""
+               );
                 ++number;
             }
         }
-        else
-        {
-            Console::getSingleton().AddTextToOutput( var->GetName() + " = \"" + var->GetS() + "\"" );
+        else{
+            Console::getSingleton().AddTextToOutput(
+              var->GetName() + " = \"" + var->GetS() + "\""
+           );
             ++number;
         }
     }
-
-    Console::getSingleton().AddTextToOutput( Ogre::StringConverter::toString(number) + " config variables.\n" );
+    Console::getSingleton().AddTextToOutput(
+      Ogre::StringConverter::toString(number) + " config variables.\n"
+   );
 }
 
-
-
-void
-CmdConfigCmdList( const Ogre::StringVector& params )
-{
-    if( params.size() > 2 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /config_cmd_list [search string]" );
+/**
+ * Searches the command list and prints the comands.
+ *
+ * @param params[in] Command parameters. The first one is the command name. If
+ * no more is passed, all commands will be printed. If another parameter is
+ * passed, the command with that name (if any) will be printed. If more than
+ * two parameter are passed, a command usage string will be printed instead.
+ */
+void CmdConfigCmdList(const Ogre::StringVector& params){
+    if (params.size() > 2){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /config_cmd_list [search string]"
+       );
         return;
     }
-
     int number = 0;
     int num_cmds = ConfigCmdManager::getSingleton().GetConfigCmdNumber();
-    for( int i = 0; i < num_cmds; ++i )
-    {
-        ConfigCmd* cmd = ConfigCmdManager::getSingleton().GetConfigCmd( i );
+    for (int i = 0; i < num_cmds; ++ i){
+        ConfigCmd* cmd = ConfigCmdManager::getSingleton().GetConfigCmd(i);
         Ogre::String name = cmd->GetName();
-
-        if( params.size() > 1 )
-        {
-            int found = name.find( params[ 1 ] );
-
-            if( found == 0 )
-            {
-                Console::getSingleton().AddTextToOutput( cmd->GetName() );
+        if (params.size() > 1){
+            int found = name.find(params[1]);
+            if (found == 0){
+                Console::getSingleton().AddTextToOutput(cmd->GetName());
                 ++number;
             }
         }
-        else
-        {
-            Console::getSingleton().AddTextToOutput( cmd->GetName() );
+        else{
+            Console::getSingleton().AddTextToOutput(cmd->GetName());
             ++number;
         }
     }
-
-    Console::getSingleton().AddTextToOutput( Ogre::StringConverter::toString( number ) + " config commands.\n" );
+    Console::getSingleton().AddTextToOutput(
+      Ogre::StringConverter::toString(number) + " config commands.\n"
+   );
 }
 
-
-
-// set cvar value
-void
-CmdSetConfigVar( const Ogre::StringVector& params )
+/**
+ * Sets the value of a configuration value.
+ *
+ * @param params[in] Command parameters. The first one is the command name. The
+ * second one is a variable name. The third one is optional and is a value for
+ * the variable. If a value is supplied, the variable will be given that value.
+ * If not, the variable will be reset to it's default value. If there is no
+ * variable by that name, nothing will be done. In any case, a feddback will be
+ * printed to console. If less than two or more than three parameters are
+ * passed, a usage text wil be printed and nothing will be done.
+ */
+void CmdSetConfigVar(const Ogre::StringVector& params)
 {
-    if( params.size() < 2 || params.size() > 3 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /set <config variable> [value]" );
+    if (params.size() < 2 || params.size() > 3){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /set <config variable> [value]"
+       );
         return;
     }
-
-    Ogre::String name = params[ 1 ];
-
-    ConfigVar* cvar = ConfigVarManager::getSingleton().Find( name );
-    if( cvar == NULL )
-    {
-        LOG_ERROR( "Config variable \"" + name + "\" not found." );
+    Ogre::String name = params[1];
+    ConfigVar* cvar = ConfigVarManager::getSingleton().Find(name);
+    if (cvar == NULL){
+        LOG_ERROR("Config variable \"" + name + "\" not found.");
         return;
     }
-
-    if( params.size() == 3 )
-    {
-        cvar->SetS( params[ 2 ] );
-
+    if (params.size() == 3){
+        cvar->SetS(params[2]);
         Console* console = Console::getSingletonPtr();
-        if( console != NULL )
-        {
-            LOG_TRIVIAL( params[ 1 ] + " changed to \"" + params[ 2 ] + "\"." );
-        }
+        if (console != NULL)
+            LOG_TRIVIAL(params[1] + " changed to \"" + params[2] + "\".");
     }
-    else
-    {
-        // reset to default
-        cvar->SetS( cvar->GetDefaultValue() );
-        LOG_TRIVIAL( params[ 1 ] + " changed to default \"" + cvar->GetDefaultValue() + "\"." );
+    else{
+        // Reset to default
+        cvar->SetS(cvar->GetDefaultValue());
+        LOG_TRIVIAL(
+          params[1] + " changed to default \""
+          + cvar->GetDefaultValue() + "\"."
+       );
     }
 }
 
-
-
-// toggle cvar value
-void
-CmdToggleConfigVar( const Ogre::StringVector& params )
-{
-    if( params.size() < 4 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /toggle <config variable> [value1] [value2] ..." );
+/**
+ * Changes the value of a configuration value conditionally.
+ *
+ * @param params[in] Command parameters. The first one is the command name. The
+ * next ones are possible values for the variables. If the value of the
+ * variable is the current one, the next one will be assigned. Once the value
+ * is changed once, no more steps will be taken and the function will return.
+ * If the last provided value is the current value of the variable, it will not
+ * be changed.
+ */
+void CmdToggleConfigVar(const Ogre::StringVector& params){
+    if (params.size() < 4){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /toggle <config variable> [value1] [value2] ...");
         return;
     }
-
-    Ogre::String name = params[ 1 ];
-
-    ConfigVar* cvar = ConfigVarManager::getSingleton().Find( name );
-    if( cvar == NULL )
-    {
-        LOG_ERROR( "Config variable \"" + name + "\" not found." );
+    Ogre::String name = params[1];
+    ConfigVar* cvar = ConfigVarManager::getSingleton().Find(name);
+    if (cvar == NULL){
+        LOG_ERROR("Config variable \"" + name + "\" not found.");
         return;
     }
 
-    // sequentially trigger values
+    // Sequentially trigger values
     int number_of_values = params.size() - 2;
     Ogre::String value = cvar->GetS();
     int i = 0;
-
-    for( ; i < number_of_values; ++i )
-    {
-        if( value == params[ i + 2 ] )
-        {
-            ++i;
+    for (; i < number_of_values; ++ i){
+        if (value == params[i + 2]){
+            ++ i;
             break;
         }
     }
-
-    if( i == number_of_values )
-    {
-        i = 0;
-    }
-
-    cvar->SetS( params[ i + 2 ] );
+    if (i == number_of_values) i = 0;
+    cvar->SetS(params[i + 2]);
 }
 
-
-
-// increment cvar value
-void
-CmdIncrementConfigVar( const Ogre::StringVector& params )
-{
-    if( params.size() != 5 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /increment <cvar name> [value min] [value max] [step]" );
+/**
+ * Increments the value of a configuration variable.
+ *
+ * @param params[in] Command parameters. Exactly five must be provided. The
+ * first one is the command name. The second one is the variable to increment.
+ * The third one is the minimum value the variable will take. The fourth one is
+ * the maximum value the variable will take. The fifth value is the increment
+ * to apply to the variable. The variable in the second parameter will be
+ * incremented by the value in the fith one, but it will be capped between the
+ * third and fourth one. If there are more or less than five parameters, a
+ * usage text will be printed and nothing will be done.
+ */
+void CmdIncrementConfigVar(const Ogre::StringVector& params){
+    if (params.size() != 5){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /increment <cvar name> [value min] [value max] [step]"
+       );
         return;
     }
-
-    Ogre::String name = params[ 1 ];
-
-    ConfigVar* cvar = ConfigVarManager::getSingleton().Find( name );
-    if( cvar == NULL )
-    {
-        LOG_ERROR( "Config variable \"" + name + "\" not found." );
+    Ogre::String name = params[1];
+    ConfigVar* cvar = ConfigVarManager::getSingleton().Find(name);
+    if (cvar == NULL){
+        LOG_ERROR("Config variable \"" + name + "\" not found.");
         return;
     }
-
-    float start_value = Ogre::StringConverter::parseReal( params[ 2 ] );
-    float end_value = Ogre::StringConverter::parseReal( params[ 3 ] );
-    float step = Ogre::StringConverter::parseReal( params[ 4 ] );
+    float start_value = Ogre::StringConverter::parseReal(params[2]);
+    float end_value = Ogre::StringConverter::parseReal(params[3]);
+    float step = Ogre::StringConverter::parseReal(params[4]);
 
     float new_value = cvar->GetF() + step;
-    if( new_value > end_value )
-    {
-        new_value = end_value;
-    }
-    else if( new_value < start_value )
-    {
-        new_value = start_value;
-    }
-
-    cvar->SetF( new_value );
+    if (new_value > end_value) new_value = end_value;
+    else if (new_value < start_value) new_value = start_value;
+    cvar->SetF(new_value);
 }
 
-
-
-void
-CmdSetLogLevel( const Ogre::StringVector& params )
-{
-    if( params.size() != 2 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /log_level <level: 1 - only errors, 2 - errors and warnings, 3 - all>" );
+/**
+ * Configures the log level.
+ *
+ * @param params[in] Command parameters. Exactly two must be provided. The
+ * first one is the command name. The second one is the log level. Accepted
+ * values are 1 (only errors), 2 (errors and warnings) and 3 (all). If there
+ * are more or less than five parameters, a usage text will be printed and
+ * nothing will be done.
+ */
+void CmdSetLogLevel(const Ogre::StringVector& params){
+    if (params.size() != 2){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /log_level "
+          "<level: 1 - only errors, 2 - errors and warnings, 3 - all>"
+        );
         return;
     }
 
-    int value = Ogre::StringConverter::parseInt( params[ 1 ] );
-    if( value > 0 && value < 4 )
-    {
-        Ogre::LogManager::getSingletonPtr()->getDefaultLog()->setLogDetail( ( Ogre::LoggingLevel )value );
-
-        switch( value )
-        {
-            case 1: Console::getSingleton().AddTextToOutput( "Logger level changed to \"only errors\".\n" ); break;
-            case 2: Console::getSingleton().AddTextToOutput( "Logger level changed to \"errors and warnings\".\n" ); break;
-            case 3: Console::getSingleton().AddTextToOutput( "Logger level changed to \"all\".\n" ); break;
+    int value = Ogre::StringConverter::parseInt(params[1]);
+    if (value > 0 && value < 4){
+        Ogre::LogManager::getSingletonPtr()->getDefaultLog()->setLogDetail(
+          (Ogre::LoggingLevel) value
+        );
+        switch(value){
+            case 1:
+                Console::getSingleton().AddTextToOutput(
+                  "Logger level changed to \"only errors\".\n"
+                );
+                break;
+            case 2:
+                Console::getSingleton().AddTextToOutput(
+                  "Logger level changed to \"errors and warnings\".\n"
+                );
+                break;
+            case 3:
+                Console::getSingleton().AddTextToOutput(
+                  "Logger level changed to \"all\".\n"
+                );
+                break;
         }
     }
-    else
-    {
-        Console::getSingleton().AddTextToOutput( "Logger level can't be changed. Value \"" + params[ 1 ] + "\" isn't supported.\n" );
+    else{
+        Console::getSingleton().AddTextToOutput(
+          "Logger level can't be changed. Value \""
+          + params[1] + "\" isn't supported.\n"
+        );
     }
 }
 
-
-
-void
-CmdMap( const Ogre::StringVector& params )
-{
-    if( params.size() != 2 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /map [map_id]" );
+/**
+ * Changes the game map.
+ *
+ * @param params[in] Command parameters. Exactly two must be provided. The
+ * first one is the command name. The second one is the map ID. If there
+ * are more or less than five parameters, a usage text will be printed and
+ * nothing will be done.
+ */
+void CmdMap(const Ogre::StringVector& params){
+    if (params.size() != 2){
+        Console::getSingleton().AddTextToOutput("Usage: /map [map_id]");
         return;
     }
-
     EntityManager::getSingleton().Clear();
-
-    XmlMapsFile xml( "./data/maps.xml" );
-    Ogre::String file_name = xml.GetMapFileNameByName( params[ 1 ] );
-
-    XmlMapFile xml_map( "./data/" + file_name );
+    XmlMapsFile xml("./data/maps.xml");
+    Ogre::String file_name = xml.GetMapFileNameByName(params[1]);
+    XmlMapFile xml_map("./data/" + file_name);
     xml_map.LoadMap();
 }
 
-
-
-void
-CmdMapCompletion( Ogre::StringVector& complete_params )
-{
-    XmlMapsFile xml( "./data/maps.xml" );
-    xml.GetMapNames( complete_params );
+/**
+ * Loads a list of map names.
+ *
+ * @param complete_params[in] The map names will be loaded here.
+ */
+void CmdMapCompletion(Ogre::StringVector& complete_params){
+    XmlMapsFile xml("./data/maps.xml");
+    xml.GetMapNames(complete_params);
 }
 
-
-
-void
-CmdResolution( const Ogre::StringVector& params )
-{
-    if( params.size() < 3 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /resolution <width> <height> [full screen]" );
+/**
+ * Sets the resolution and full screen mode.
+ *
+ * @param params[in] Command parameters. Three or four must be provided. The
+ * first one is the command name. The second one is the resolution width. The
+ * third one is the resolution height. The fourth one is optional and can be
+ * used to toggle the full screen. "true", "yes" or 1 will set the game in full
+ * screen mode. Anything else will set it to windowed mode.
+ */
+void CmdResolution(const Ogre::StringVector& params){
+    if (params.size() < 3){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /resolution <width> <height> [full screen]"
+        );
         return;
     }
-
-    Ogre::RenderWindow* window = QGears::Application::getSingleton().getRenderWindow();
-
-    if( params.size() >= 4 )
-    {
-        window->setFullscreen( Ogre::StringConverter::parseBool( params[ 3 ] ), Ogre::StringConverter::parseInt( params[ 1 ] ), Ogre::StringConverter::parseInt( params[ 2 ] ) );
+    Ogre::RenderWindow* window
+      = QGears::Application::getSingleton().getRenderWindow();
+    if (params.size() >= 4){
+        window->setFullscreen(
+          Ogre::StringConverter::parseBool(params[3]),
+          Ogre::StringConverter::parseInt(params[1]),
+          Ogre::StringConverter::parseInt(params[2])
+        );
     }
-    else
-    {
-        window->resize( Ogre::StringConverter::parseInt( params[ 1 ] ), Ogre::StringConverter::parseInt( params[ 2 ] ) );
+    else{
+        window->resize(
+          Ogre::StringConverter::parseInt(params[1]),
+          Ogre::StringConverter::parseInt(params[2])
+        );
     }
 }
 
-
-
-void
-CmdResolutionCompletition( Ogre::StringVector& complete_params )
-{
-    complete_params.push_back( "640 480 0" );
-    complete_params.push_back( "640 480 1" );
-    complete_params.push_back( "800 600 0" );
-    complete_params.push_back( "800 600 1" );
-    complete_params.push_back( "1024 768 0" );
-    complete_params.push_back( "1024 768 1" );
-    complete_params.push_back( "1280 720 0" );
-    complete_params.push_back( "1280 720 1" );
-    complete_params.push_back( "1280 1024 0" );
-    complete_params.push_back( "1280 1024 1" );
+/**
+ * Loads a list of resolution modes.
+ *
+ * A resolution mode is represented by a string with the format "[w] [h] [f]",
+ * where [w] is the resolution width, in pixels, [h] is the resolution height,
+ * in pixels and [f] is the full screen state (0 for windowed mode, 1 for full
+ * screen)
+ *
+ * @param complete_params[in] The resolution modes will be loaded here.
+ */
+void CmdResolutionCompletition(Ogre::StringVector& complete_params){
+    complete_params.push_back("640 480 0");
+    complete_params.push_back("640 480 1");
+    complete_params.push_back("800 600 0");
+    complete_params.push_back("800 600 1");
+    complete_params.push_back("1024 768 0");
+    complete_params.push_back("1024 768 1");
+    complete_params.push_back("1280 720 0");
+    complete_params.push_back("1280 720 1");
+    complete_params.push_back("1280 1024 0");
+    complete_params.push_back("1280 1024 1");
 }
 
-
-
-void
-CmdScreenshot( const Ogre::StringVector& params )
-{
-    Ogre::RenderWindow* window = QGears::Application::getSingleton().getRenderWindow();
-    Ogre::String ret = window->writeContentsToTimestampedFile( "screenshot_", ".tga" );
-    Console::getSingleton().AddTextToOutput( "Screenshot " + ret + " saved." );
+/**
+ * Saves a screenshot of the current game window.
+ *
+ * @param params Command parameters. Unused.
+ */
+void CmdScreenshot(const Ogre::StringVector& params){
+    Ogre::RenderWindow* window
+      = QGears::Application::getSingleton().getRenderWindow();
+    Ogre::String ret
+      = window->writeContentsToTimestampedFile("screenshot_", ".tga");
+    Console::getSingleton().AddTextToOutput("Screenshot " + ret + " saved.");
 }
 
 
 
 /*
-void
-CmdViewer( const Ogre::StringVector& params )
-{
-    if( params.size() == 2 || params.size() > 3 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /viewer [type_of_thing_to_view] [path_to_resource]" );
+void CmdViewer(const Ogre::StringVector& params){
+    if (params.size() == 2 || params.size() > 3){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /viewer [type_of_thing_to_view] [path_to_resource]"
+        );
         return;
     }
-
     ModuleManager::getSingleton().RunViewer();
-
-    if( params.size() == 3 )
-    {
-        ViewerModule* module = ( ViewerModule* )( ModuleManager::getSingleton().GetTopModule() );
-
-        if( params[ 1 ] == "walkmesh" )
-        {
-            module->SetWalkmeshToLoad( params[ 2 ] );
-        }
-        else if( params[ 1 ] == "model" )
-        {
-            module->SetModelToLoad( params[ 2 ] );
-        }
-        else
-        {
-            LOG_ERROR( "Unsupported type \"" + params[ 1 ] + "\" in viewer command." );
+    if (params.size() == 3){
+        ViewerModule* module
+          = (ViewerModule*)(ModuleManager::getSingleton().GetTopModule());
+
+        if (params[1] == "walkmesh") module->SetWalkmeshToLoad(params[2]);
+        else if (params[1] == "model") module->SetModelToLoad(params[2]);
+        else{
+            LOG_ERROR(
+              "Unsupported type \"" + params[1] + "\" in viewer command."
+            );
         }
     }
 }
 
-
-
-void
-CmdViewerCompletion( Ogre::StringVector& complete_params )
-{
+void CmdViewerCompletion(Ogre::StringVector& complete_params){
     // models
-    complete_params.push_back( "model" );
-
-    Ogre::FileInfoListPtr resources = Ogre::ResourceGroupManager::getSingleton().listResourceFileInfo( "Game" );
+    complete_params.push_back("model");
+    Ogre::FileInfoListPtr resources
+      = Ogre::ResourceGroupManager::getSingleton().listResourceFileInfo("Game");
     Ogre::FileInfoList resource_names = *resources;
 
     Ogre::FileInfoList::iterator i = resource_names.begin();
-    for( ; i != resource_names.end(); ++i )
-    {
+    for (; i != resource_names.end(); ++ i){
         Ogre::String name;
         Ogre::String ext;
-        Ogre::StringUtil::splitBaseFilename( i->filename, name, ext );
-        if( ext == "mesh" )
-        {
-            complete_params.push_back( "model " + i->filename );
-        }
+        Ogre::StringUtil::splitBaseFilename(i->filename, name, ext);
+        if (ext == "mesh") complete_params.push_back("model " + i->filename);
     }
 
     // walkmeshes
-    complete_params.push_back( "walkmesh" );
-    XmlMapsFile xml( "./data/game_data/maps.xml" );
+    complete_params.push_back("walkmesh");
+    XmlMapsFile xml("./data/game_data/maps.xml");
     Ogre::StringVector tmp;
-    xml.GetMapNames( tmp );
-    for( int i = 0; i < tmp.size(); ++i )
-    {
-        complete_params.push_back( "walkmesh " + tmp[ i ] );
-    }
+    xml.GetMapNames(tmp);
+    for (int i = 0; i < tmp.size(); ++i)
+        complete_params.push_back("walkmesh " + tmp[i]);
 }
 */
 
-
-void
-ConfigCmdManager::InitCmd()
-{
-    AddCommand( "quit", "Stops application and quit", "", CmdQuit, NULL );
-    AddCommand( "echo", "Print command parameters", "", CmdEcho, NULL );
-    AddCommand( "config_var_list", "List of registered config variables", "[<filter substring>]", CmdConfigVarList, NULL );
-    AddCommand( "config_cmd_list", "List of registered config commands", "[<filter substring>]", CmdConfigCmdList, NULL );
-    AddCommand( "set", "Set cvar value", "<cvar name> [value]", CmdSetConfigVar, NULL );
-    AddCommand( "toggle", "Toggle cvar value", "<cvar name> [value1] [value2] ...", CmdToggleConfigVar, NULL );
-    AddCommand( "increment", "Increment cvar value", "<cvar name> [value min] [value max] [step]", CmdIncrementConfigVar, NULL );
-
-    AddCommand( "set_log_level", "Set log messages level", "", CmdSetLogLevel, NULL );
-
-    AddCommand( "map", "Run game module", "", CmdMap, CmdMapCompletion );
-
-    AddCommand( "resolution", "Change resolution", "", CmdResolution, CmdResolutionCompletition );
-    AddCommand( "screenshot", "Capture current screen content", "", CmdScreenshot, NULL );
-
-    //AddCommand( "viewer", "Run viewer module", "", CmdViewer, CmdViewerCompletion );
+/**
+ * Initializes all available commands.
+ */
+void ConfigCmdManager::InitCmd(){
+    AddCommand("quit", "Stops application and quit", "", CmdQuit, NULL);
+    AddCommand("echo", "Print command parameters", "", CmdEcho, NULL);
+    AddCommand(
+      "config_var_list", "List of registered config variables",
+      "[<filter substring>]", CmdConfigVarList, NULL
+    );
+    AddCommand(
+      "config_cmd_list", "List of registered config commands",
+      "[<filter substring>]", CmdConfigCmdList, NULL
+    );
+    AddCommand(
+      "set", "Set cvar value", "<cvar name> [value]", CmdSetConfigVar, NULL
+    );
+    AddCommand(
+      "toggle", "Toggle cvar value",
+      "<cvar name> [value1] [value2] ...", CmdToggleConfigVar, NULL
+    );
+    AddCommand(
+      "increment",
+      "Increment cvar value", "<cvar name> [value min] [value max] [step]",
+      CmdIncrementConfigVar, NULL
+    );
+    AddCommand(
+      "set_log_level", "Set log messages level", "", CmdSetLogLevel, NULL
+    );
+    AddCommand("map", "Run game module", "", CmdMap, CmdMapCompletion);
+    AddCommand(
+      "resolution", "Change resolution", "",
+      CmdResolution, CmdResolutionCompletition
+    );
+    AddCommand(
+      "screenshot", "Capture current screen content", "", CmdScreenshot, NULL
+    );
+    //AddCommand(
+    //  "viewer", "Run viewer module", "", CmdViewer, CmdViewerCompletion
+    //);
 }

+ 32 - 9
QGearsMain/include/core/ConfigFile.h

@@ -1,16 +1,39 @@
-#ifndef CONFIG_FILE_H
-#define CONFIG_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreString.h>
 
+/**
+ * A configuration file.
+ */
+class ConfigFile{
 
+    public:
 
-class ConfigFile
-{
-public:
-    void            Execute(const Ogre::String& name);
+        /**
+         * Executes a configuration file.
+         *
+         * The configuration file must be populated with commands, as described
+         * in {@see ConfigCmdManagerCommands.h}
+         *
+         * Executing a file will sequentially execute all the commands in it.
+         *
+         * @param name[in] Configuration file path.
+         */
+        void Execute(const Ogre::String& name);
 };
 
-
-
-#endif // CONFIG_FILE_H

+ 173 - 45
QGearsMain/include/core/ConfigVar.h

@@ -1,54 +1,182 @@
-#ifndef CONFIG_VAR_H
-#define CONFIG_VAR_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreString.h>
 
-
-
 class ConfigVarManager;
 
-
-
-class ConfigVar
-{
+/**
+ * A configuration variable
+ */
+class ConfigVar{
     friend class ConfigVarManager;
 
-public:
-                        ConfigVar(const Ogre::String& name, const Ogre::String& description, const Ogre::String& default_value);
-
-    int                 GetI() const;
-    float               GetF() const;
-    bool                GetB() const;
-    Ogre::String        GetS() const;
-
-    void                SetI(int value);
-    void                SetF(float value);
-    void                SetB(bool value);
-    void                SetS(const Ogre::String& value);
-
-    const Ogre::String& GetName() const;
-    const Ogre::String& GetDescription() const;
-    const Ogre::String& GetDefaultValue() const;
-
-    void                UpdateVariables();
-
-private:
-    // forbid copy
-    ConfigVar(const ConfigVar&) = delete;
-    ConfigVar&operator=(const ConfigVar&) = delete;
-
-    Ogre::String    m_Name;
-    Ogre::String    m_Description;
-    Ogre::String    m_DefaultValue;
-    int             m_ValueI;
-    float           m_ValueF;
-    bool            m_ValueB;
-    Ogre::String    m_ValueS;
-
-    ConfigVar*          m_Previous;
-    static ConfigVar*   m_StaticConfigVarList;
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param name[in] The variable name.
+         * @param description[in] A human-friendly description for the
+         * variable.
+         * @param default_value[in] The default value for the variable.
+         */
+        ConfigVar(
+          const Ogre::String& name, const Ogre::String& description,
+          const Ogre::String& default_value
+        );
+
+        /**
+         * Retrieves the value of the variable in integer form.
+         *
+         * @return The variable value.
+         */
+        int GetI() const;
+
+        /**
+         * Retrieves the value of the variable in float form.
+         *
+         * @return The variable value.
+         */
+        float GetF() const;
+
+        /**
+         * Retrieves the value of the variable in boolean form.
+         *
+         * @return The variable value.
+         */
+        bool GetB() const;
+
+        /**
+         * Retrieves the value of the variable in string form.
+         *
+         * @return The variable value.
+         */
+        Ogre::String GetS() const;
+
+        /**
+         * Sets the integer value of the variable.
+         *
+         * @param value[in] The variable value.
+         */
+        void SetI(int value);
+
+        /**
+         * Sets the float value of the variable.
+         *
+         * @param value[in] The variable value.
+         */
+        void SetF(float value);
+
+        /**
+         * Sets the boolean value of the variable.
+         *
+         * @param value[in] The variable value.
+         */
+        void SetB(bool value);
+
+        /**
+         * Sets the string value of the variable.
+         *
+         * @param value[in] The variable value.
+         */
+        void SetS(const Ogre::String& value);
+
+        /**
+         * Retrieves the variable name.
+         *
+         * @return The variable name.
+         */
+        const Ogre::String& GetName() const;
+
+        /**
+         * Retrieves the variable description.
+         *
+         * @return The variable description.
+         */
+        const Ogre::String& GetDescription() const;
+
+        /**
+         * Retrieves the variable default value.
+         *
+         * @return The variable default value.
+         */
+        const Ogre::String& GetDefaultValue() const;
+
+        /**
+         * Updates the integer and float values from the string value.
+         */
+        void UpdateVariables();
+
+    private:
+
+        /**
+         * Forbidden copy constructor.
+         */
+        ConfigVar(const ConfigVar&) = delete;
+
+        /**
+         * Forbidden copy constructor.
+         */
+        ConfigVar&operator=(const ConfigVar&) = delete;
+
+        /**
+         * The variable name.
+         */
+        Ogre::String    name_;
+
+        /**
+         * The variable description.
+         */
+        Ogre::String    description_;
+
+        /**
+         * The variable default value.
+         */
+        Ogre::String    default_value_;
+
+        /**
+         * Variable value, integer format.
+         */
+        int             value_i_;
+
+        /**
+         * Variable value, float format.
+         */
+        float           value_f_;
+
+        /**
+         * Variable value, integer format.
+         */
+        bool            value_b_;
+
+        /**
+         * Variable value, string format.
+         */
+        Ogre::String    value_s_;
+
+        /**
+         * @todo Understand and document.
+         */
+        ConfigVar*          previous_;
+
+        /**
+         * @todo Understand and document.
+         */
+        static ConfigVar*   static_config_var_list_;
 };
 
-
-
-#endif // CONFIG_VAR_H

+ 52 - 14
QGearsMain/include/core/ConfigVarManager.h

@@ -1,26 +1,64 @@
-#ifndef CONFIG_VAR_MANAGER_H
-#define CONFIG_VAR_MANAGER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreSingleton.h>
 #include <vector>
-
 #include "ConfigVar.h"
 
+/**
+ * Configuration variable manager.
+ */
+class ConfigVarManager : public Ogre::Singleton<ConfigVarManager>{
 
+    public:
 
-class ConfigVarManager : public Ogre::Singleton< ConfigVarManager >
-{
-public:
-    ConfigVarManager();
+        /**
+         * Constructor.
+         */
+        ConfigVarManager();
 
-    ConfigVar*   Find( const Ogre::String& name ) const;
-    unsigned int GetConfigVarNumber() const;
-    ConfigVar*   GetConfigVar( const unsigned int i ) const;
+        /**
+         * Finds a variable by name.
+         *
+         * @param name[in] Name of the variable to retrieve.
+         * @return The variable by the specified name, nullptr if there is no
+         * one by that name.
+         */
+        ConfigVar* Find(const Ogre::String& name) const;
 
-private:
-    std::vector< ConfigVar* > m_ConfigVars;
-};
+        /**
+         * Counts the configuration variables.
+         *
+         * @return The number of defined configuration variables.
+         */
+        unsigned int GetConfigVarNumber() const;
 
+        /**
+         * Retrieves a configuration variable by index.
+         *
+         * @param i[in] Index of the configuration variable.
+         * @return Variable at the specified index.
+         */
+        ConfigVar* GetConfigVar(const unsigned int i) const;
 
+    private:
 
-#endif // CONFIG_VAR_MANAGER_H
+        /**
+         * List of configuration variables.
+         */
+        std::vector<ConfigVar*> config_vars_;
+};

+ 266 - 65
QGearsMain/include/core/Console.h

@@ -1,5 +1,19 @@
-#ifndef CONSOLE_H
-#define CONSOLE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreColourValue.h>
 #include <OgreLog.h>
@@ -8,73 +22,260 @@
 #include <OIS/OIS.h>
 #include <list>
 #include <vector>
-
 #include "Event.h"
 
+/**
+ * The game console.
+ */
+class Console : public Ogre::Singleton<Console>, public Ogre::LogListener{
 
+    public:
 
-class Console : public Ogre::Singleton< Console >, public Ogre::LogListener
-{
-public:
-    Console();
-    ~Console();
-
-    void Input(const QGears::Event& event);
-    void Update();
-    void UpdateDraw();
-    void UpdateNotification();
-    void OnResize();
-
-    void SetToVisible();
-    void SetToHide();
-    bool IsVisible() const;
-
-    void AddTextToOutput( const Ogre::String& text, const Ogre::ColourValue& colour = Ogre::ColourValue::White );
-    void ExecuteCommand( const Ogre::String& command );
-    void ExecuteScript();
-    void CompleteInput();
-    void ResetAutoCompletion();
-    void AddInputToHistory();
-    void SetInputLineFromHistory();
-
-    virtual void messageLogged( const Ogre::String& message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool& skipThisMessage );
-
-private:
-    void LoadHistory();
-    void SaveHistory();
-    void AddToHistory(const Ogre::String& history);
-    char TranslateNumpad(const QGears::Event& event);
-
-    int                           m_ConsoleWidth;
-    int                           m_ConsoleHeight;
-    unsigned int                  m_LineWidth;
-    int                           m_LetterWidth;
-
-    bool                          m_ToVisible;
-    bool                          m_Visible;
-    float                         m_Height;
-
-    struct OutputLine
-    {
-        Ogre::String text;
-        Ogre::ColourValue colour;
-        float time;
-    };
-    std::list< OutputLine >       m_OutputLine;
-    unsigned int                  m_MaxOutputLine; // max number of lines in output list
-    unsigned int                  m_DisplayLine;   // bottom of console displays this line
-    Ogre::String                  m_InputLine;
-    unsigned int                  m_CursorPosition;
-    float                         m_CursorBlinkTime;
-
-    std::list< Ogre::String >     m_History;
-    int                           m_HistoryLineCycleIndex;
-    unsigned int                  m_MaxHistorySize;
-
-    Ogre::StringVector            m_AutoCompletition;
-    unsigned int                  m_AutoCompletitionLine;
-};
+        /**
+         * Constructor.
+         */
+        Console();
+
+        /**
+         * Destructor.
+         */
+        ~Console();
+
+        /**
+         * Processes an input event.
+         *
+         * @param event[in] Event to process.
+         */
+        void Input(const QGears::Event& event);
+
+        /**
+         * Updates the console.
+         */
+        void Update();
+
+        /**
+         * Redraws the console.
+         */
+        void UpdateDraw();
+
+        /**
+         * Notifies the console to update itself.
+         */
+        void UpdateNotification();
+
+        /**
+         * Processes a console resizing event.
+         */
+        void OnResize();
+
+        /**
+         * Shows the console.
+         */
+        void SetToVisible();
+
+        /**
+         * Hides the console.
+         */
+        void SetToHide();
+
+        /**
+         * Checks if the console is currently visible.
+         *
+         * @return TRue if the console is visible, false otherwise.
+         */
+        bool IsVisible() const;
+
+        /**
+         * Writes text to the console.
+         *
+         * @param text[in] Text to write.
+         * @param color[in] Color for the text. Default is white.
+         */
+        void AddTextToOutput(
+          const Ogre::String& text,
+          const Ogre::ColourValue& colour = Ogre::ColourValue::White
+       );
+
+        /**
+         * Executes a command in the console
+         *
+         * @param command[in] Command to execute.
+         */
+        void ExecuteCommand(const Ogre::String& command);
+
+        /**
+         * @todo Understand and document.
+         */
+        void ExecuteScript();
+
+        /**
+         * Autocompletes the current input.
+         */
+        void CompleteInput();
+
+        /**
+         * Clears the autocompletion list.
+         */
+        void ResetAutoCompletion();
+
+        /**
+         * Adds a console input to the console history.
+         */
+        void AddInputToHistory();
+
+        /**
+         * Sets a line from the history as the current input.
+         */
+        void SetInputLineFromHistory();
+
+        /**
+         * Logs a message to the console.
+         *
+         * @param message[in] The message to log.
+         * @param lml[in] Log level for the message.
+         * @param maskDebug Indicates if the mesage is beinng printed to the
+         * console or not.
+         * @param logName[in] Name of the log.
+         * @param skipThisMessage[in] If true, the message will not be logged.
+         */
+        virtual void messageLogged(
+          const Ogre::String& message, Ogre::LogMessageLevel lml,
+          bool maskDebug, const Ogre::String &logName, bool& skipThisMessage
+        );
+
+    private:
+
+        /**
+         * Loads the console input history.
+         */
+        void LoadHistory();
+
+        /**
+         * Saves the console input history.
+         */
+        void SaveHistory();
 
+        /**
+         * Adds a string to the console input history.
+         */
+        void AddToHistory(const Ogre::String& history);
 
+        /**
+         * Translates numpad key events to regular number events.
+         *
+         * @param event[in] Event to translate.
+         */
+        char TranslateNumpad(const QGears::Event& event);
+
+        /**
+         * The console width.
+         */
+        int console_width_;
+
+        /**
+         * The console height.
+         */
+        int console_height_;
+
+        /**
+         * The width of each line in the console.
+         */
+        unsigned int line_width_;
+
+        /**
+         * The width of each letter in the console.
+         */
+        int letter_width_;
+
+        /**
+         * Indicates if the console is being made visible.
+         */
+        bool to_visible_;
+
+        /**
+         * Indicates if the console is currently visible.
+         */
+        bool visible_;
+
+        /**
+         * Line height of the console.
+         */
+        float height_;
+
+        /**
+         * An ouptut line of the console.
+         */
+        struct OutputLine{
+
+            /**
+             * Text in the line.
+             */
+            Ogre::String text;
+
+            /**
+             * Color for the text in the line.
+             */
+            Ogre::ColourValue colour;
+
+            /**
+             * Time at which it was printed.
+             */
+            float time;
+        };
+
+        /**
+         * Listof lines in the console.
+         */
+        std::list<OutputLine> output_line_;
+
+        /**
+         * Max number of lines in output list.
+         */
+        unsigned int max_output_line_;
+
+        /**
+         * The bottom line of the console, the active one.
+         */
+        unsigned int display_line_;
+
+        /**
+         * Currently typed text.
+         */
+        Ogre::String input_line_;
+
+        /**
+         * Position of the cursor in the active line.
+         */
+        unsigned int cursor_position_;
+
+        /**
+         * Cursor blink frequency, in seconds.
+         */
+        float cursor_blink_time_;
+
+        /**
+         * The console input history.
+         */
+        std::list<Ogre::String> history_;
+
+        /**
+         * Currently selected line of the input history.
+         */
+        int history_line_cycle_index_;
+
+        /**
+         * Maximum number of inputs to save to the history.
+         */
+        unsigned int max_history_size_;
+
+        /**
+         * List of strings available for autocompletion.
+         */
+        Ogre::StringVector auto_completition_;
+
+        /**
+         * Index of the currently displayed autocompletion option.
+         */
+        unsigned int auto_completition_line_;
+};
 
-#endif // CONSOLE_H

+ 384 - 84
QGearsMain/include/core/DebugDraw.h

@@ -1,5 +1,19 @@
-#ifndef DEBUG_DRAW_H
-#define DEBUG_DRAW_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreHardwareVertexBuffer.h>
 #include <OgreRenderQueueListener.h>
@@ -7,92 +21,378 @@
 #include <OgreSingleton.h>
 #include <OgreFont.h>
 
-
-class DebugDraw : public Ogre::RenderQueueListener, public Ogre::Singleton< DebugDraw >
+class DebugDraw :
+  public Ogre::RenderQueueListener, public Ogre::Singleton<DebugDraw>
 {
-public:
-    DebugDraw();
-    virtual ~DebugDraw();
-
-    void SetColour( const Ogre::ColourValue& colour );
-    void SetScreenSpace( const bool screen_space );
-    void SetZ( const float z );
-    void SetFadeDistance( const float fade_s, const float fade_e );
-
-    enum TextAlignment
-    {
-        LEFT,
-        RIGHT,
-        CENTER
-    };
-    void SetTextAlignment( TextAlignment alignment );
-
-    void Line( const float x1, const float y1, const float x2, const float y2 );
-    void Line3d( const Ogre::Vector3& point1, const Ogre::Vector3& point2 );
-    void Triangle3d( const Ogre::Vector3& point1, const Ogre::Vector3& point2, const Ogre::Vector3& point3 );
-    void Quad( const float x1, const float y1, const float x2, const float y2, const float x3, const float y3, const float x4, const float y4 );
-    void Text( const float x1, const float y1, const Ogre::String& text );
-    void Text( const Ogre::Vector3& point, const float x, const float y, const Ogre::String& text );
-
-    void renderQueueEnded( Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation );
-
-private:
-    void CreateLineVertexBuffer();
-    void DestroyLineVertexBuffer();
-    void CreateLine3dVertexBuffer();
-    void DestroyLine3dVertexBuffer();
-    void CreateTriangle3dVertexBuffer();
-    void DestroyTriangle3dVertexBuffer();
-    void CreateQuadVertexBuffer();
-    void DestroyQuadVertexBuffer();
-    void CreateTextVertexBuffer();
-    void DestroyTextVertexBuffer();
-
-private:
-    Ogre::SceneManager* m_SceneManager;
-    Ogre::RenderSystem* m_RenderSystem;
-
-    // line
-    Ogre::RenderOperation               m_LineRenderOp;
-    Ogre::HardwareVertexBufferSharedPtr m_LineVertexBuffer;
-    unsigned int                        m_LineMaxVertexCount;
-
-    // line3d
-    Ogre::RenderOperation               m_Line3dRenderOp;
-    Ogre::HardwareVertexBufferSharedPtr m_Line3dVertexBuffer;
-    unsigned int                        m_Line3dMaxVertexCount;
-
-    // triangle3d
-    Ogre::RenderOperation               m_Triangle3dRenderOp;
-    Ogre::HardwareVertexBufferSharedPtr m_Triangle3dVertexBuffer;
-    unsigned int                        m_Triangle3dMaxVertexCount;
-
-    // quad
-    Ogre::RenderOperation               m_QuadRenderOp;
-    Ogre::HardwareVertexBufferSharedPtr m_QuadVertexBuffer;
-    unsigned int                        m_QuadMaxVertexCount;
-
-    // text
-    Ogre::RenderOperation               m_TextRenderOp;
-    Ogre::HardwareVertexBufferSharedPtr m_TextVertexBuffer;
-    unsigned int                        m_TextMaxVertexCount;
-    Ogre::FontPtr                       m_Font;
-    int                                 m_FontHeight;
-    TextAlignment                       m_TextAlignment;
-
-    Ogre::MaterialPtr                   m_Material;
-    Ogre::MaterialPtr                   m_Material3d;
-    Ogre::ColourValue                   m_Colour;
-    bool                                m_ScreenSpace;
-    float                               m_Z;
-    float                               m_FadeStartSquare; // text start fading from this distance
-    float                               m_FadeEndSquare; // text fully faded from this distance
-};
+    public:
 
+        /**
+         * Constructor.
+         */
+        DebugDraw();
 
+        /**
+         * Destructor.
+         */
+        virtual ~DebugDraw();
 
-#define DEBUG_DRAW DebugDraw::getSingleton()
+        /**
+         * Sets the colour of the element to draw.
+         *
+         * @param colour[in] The color to apply.
+         */
+        void SetColour(const Ogre::ColourValue& colour);
+
+        /**
+         * Sets the screen space.
+         *
+         * @param screen_space[in] The screen space.
+         * @todo Understand and document properly.
+         */
+        void SetScreenSpace(const bool screen_space);
+
+        /**
+         * Set the Z coordinate.
+         *
+         * @param z[in] The Z coordinate.
+         */
+        void SetZ(const float z);
+
+        /**
+         * Sets the fade distance for text.
+         *
+         * @param fade_s[in] The text starts fading at this distance.
+         * @param fade_e[in] The text has faded completely at this distance.
+         */
+        void SetFadeDistance(const float fade_s, const float fade_e);
+
+        /**
+         * Text alignment modes.
+         */
+        enum TextAlignment{
+
+            /**
+             * Left aligned text.
+             */
+            LEFT,
+
+            /**
+             * Right aligned text.
+             */
+            RIGHT,
+
+            /**
+             * Center aligned text.
+             */
+            CENTER
+        };
+        void SetTextAlignment(TextAlignment alignment);
+
+        /**
+         * Draws a line in 2D space.
+         *
+         * If the debug vertex limit has been reached or if it would be
+         * exceeded by drawing the line, a warning message will be printed and
+         * nothing will be done.
+         *
+         * @param x1[in] X coordinate of the starting point.
+         * @param y1[in] Y coordinate of the starting point.
+         * @param x2[in] X coordinate of the ending point.
+         * @param y2[in] Y coordinate of the ending point.
+         */
+        void Line(
+          const float x1, const float y1, const float x2, const float y2
+        );
+
+        /**
+         * Draws a line in 3D space.
+         *
+         * If the debug vertex limit has been reached or if it would be
+         * exceeded by drawing the line, a warning message will be printed and
+         * nothing will be done.
+         *
+         * @param point1[in] Starting point.
+         * @param point2[in] Ending point.
+         */
+        void Line3d(const Ogre::Vector3& point1, const Ogre::Vector3& point2);
+
+        /**
+         * Draws a triangle in 3D space.
+         *
+         * If the debug vertex limit has been reached or if it would be
+         * exceeded by drawing the triangle, a warning message will be printed
+         * and nothing will be done.
+         *
+         * @param point1[in] A triangle vertex point.
+         * @param point2[in] A triangle vertex point.
+         * @param point3[in] A triangle vertex point.
+         */
+        void Triangle3d(
+          const Ogre::Vector3& point1, const Ogre::Vector3& point2,
+          const Ogre::Vector3& point3
+        );
+
+        /**
+         * Draws a quad in 2D space.
+         *
+         * If the debug vertex limit has been reached or if it would be
+         * exceeded by drawing the quad, a warning message will be printed and
+         * nothing will be done.
+         *
+         * @param x1[in] X coordinate of the first point.
+         * @param y1[in] Y coordinate of the first point.
+         * @param x2[in] X coordinate of the second point.
+         * @param y2[in] Y coordinate of the second point.
+         * @param x3[in] X coordinate of the third point.
+         * @param y3[in] Y coordinate of the third point.
+         * @param x4[in] X coordinate of the fourth point.
+         * @param y4[in] Y coordinate of the fourth point.
+         */
+        void Quad(
+          const float x1, const float y1, const float x2, const float y2,
+          const float x3, const float y3, const float x4, const float y4
+        );
+
+        /**
+         * Writes debug text on the game screen.
+         *
+         * The text won't be warped automatically. If the maximum number of
+         * debug letters has been written, or if it would be exceeded by
+         * writing, a warning message will be printed to console and nothing
+         * will be done.
+         *
+         * @param x[in] Left position of the text in the screen.
+         * @param y[in] Left position of the text in the screen.
+         * @param text[in] The text to write.
+         */
+        void Text(const float x, const float y, const Ogre::String& text);
+
+        /**
+         * Writes debug text on the game screen.
+         *
+         * The text will be warped automatically. If the maximum number of
+         * debug letters has been written, or if it would be exceeded by
+         * writing, a warning message will be printed to console and nothing
+         * will be done.
+         *
+         * @param point[in] Top left point of the screen where the text will be
+         * written.
+         * @param x[in] Text width.
+         * @param y[in] Text height.
+         * @param text[in] The text to write.
+         */
+        void Text(
+          const Ogre::Vector3& point, const float x, const float y,
+          const Ogre::String& text
+        );
+
+        /**
+         * Ends the render queue.
+         *
+         * @param queueGroupId[in] The group id of the queue to end.
+         * @param invocation[in]
+         * @param repeatThisInvocation[in]
+         * @todo Understand and document.
+         */
+        void renderQueueEnded(
+          Ogre::uint8 queueGroupId, const Ogre::String& invocation,
+          bool& repeatThisInvocation
+        );
+
+    private:
+
+        /**
+         * Creates a 2D line vertex buffer (2 vertices).
+         */
+        void CreateLineVertexBuffer();
+
+        /**
+         * Destroys a 2D line vertex buffer (2 vertices).
+         */
+        void DestroyLineVertexBuffer();
+
+        /**
+         * Creates a 3D line vertex buffer (2 vertices).
+         */
+        void CreateLine3dVertexBuffer();
+
+        /**
+         * Destroys a 3D line vertex buffer (2 vertices).
+         */
+        void DestroyLine3dVertexBuffer();
+
+        /**
+         * Creates a 3D triangle vertex buffer (3 vertices).
+         */
+        void CreateTriangle3dVertexBuffer();
+
+        /**
+         * Destroys a 3D triangle vertex buffer (3 vertices).
+         */
+        void DestroyTriangle3dVertexBuffer();
+
+        /**
+         * Creates a quad vertex buffer (4 vertices).
+         */
+        void CreateQuadVertexBuffer();
+
+        /**
+         * Destroys a quad vertex buffer (4 vertices).
+         */
+        void DestroyQuadVertexBuffer();
+
+        /**
+         * Creates a text vertex buffer.
+         */
+        void CreateTextVertexBuffer();
+
+        /**
+         * Destroys a text vertex buffer.
+         */
+        void DestroyTextVertexBuffer();
 
+        /**
+         * The scene manager.
+         */
+        Ogre::SceneManager* scene_manager_;
 
+        /**
+         * The render system.
+         */
+        Ogre::RenderSystem* render_system_;
+
+        /**
+         * A 2D line render operation.
+         */
+        Ogre::RenderOperation line_render_operation_;
+
+        /**
+         * A 2D line vertex buffer (2 vertices).
+         */
+        Ogre::HardwareVertexBufferSharedPtr line_vertex_buffer_;
+
+        /**
+         * Maximum number of vertices for debug 2D lines.
+         */
+        unsigned int line_max_vertex_;
+
+        /**
+         * A 3D line render operation.
+         */
+        Ogre::RenderOperation line_3d_render_operation_;
+
+        /**
+         * A 3D line vertex buffer (2 vertices).
+         */
+        Ogre::HardwareVertexBufferSharedPtr line_3d_vertex_buffer_;
+
+        /**
+         * Maximum number of vertices for debug 3D lines.
+         */
+        unsigned int line_3d_max_vertex_;
+
+        /**
+         * A 3D triangle render operation.
+         */
+        Ogre::RenderOperation triangle_3d_render_operation_;
+
+        /**
+         * A 3D triangle vertex buffer (3 vertices).
+         */
+        Ogre::HardwareVertexBufferSharedPtr triangle_3d_vertex_buffer_;
+
+        /**
+         * Maximum number of vertices for debug 3D triangles.
+         */
+        unsigned int triangle_3d_max_vertex_;
+
+        /**
+         * A quad render operation.
+         */
+        Ogre::RenderOperation quad_render_operation_;
+
+        /**
+         * A quad vertex buffer (4 vertices).
+         */
+        Ogre::HardwareVertexBufferSharedPtr quad_vertex_buffer_;
+
+        /**
+         * Maximum number of vertices for debug quads.
+         */
+        unsigned int quad_max_vertex_;
+
+        /**
+         * A text render operation.
+         */
+        Ogre::RenderOperation text_render_operation_;
+
+        /**
+         * A text vertex buffer.
+         *
+         * @todo Confirm if it's 6 vertices per letter.
+         */
+        Ogre::HardwareVertexBufferSharedPtr text_vertex_buffer_;
+
+        /**
+         * Maximum number of vertices for debug text.
+         *
+         * @todo Confirm if it's 6 vertices per letter.
+         */
+        unsigned int text_max_vertex_;
+
+        /**
+         * Font to use for debug text.
+         */
+        Ogre::FontPtr font_;
+
+        /**
+         * Font height for the debug text.
+         */
+        int font_height_;
+
+        /**
+         * Alignment for debug text.
+         */
+        TextAlignment text_alignment_;
+
+        /**
+         * Material for a 2D object.
+         */
+        Ogre::MaterialPtr material_;
+
+        /**
+         * Material for a 3D object.
+         */
+        Ogre::MaterialPtr material_3d_;
+
+        /**
+         * Color for the debug object or text.
+         */
+        Ogre::ColourValue colour_;
+
+        /**
+         * The screen space.
+         */
+        bool screen_space_;
+
+        /**
+         * Z coordinate for the debug object.
+         */
+        float z_coordinate_;
+
+        /**
+         * For text fading. The text start fading from this distance.
+         */
+        float fade_start_square_;
+
+        /**
+         * For text fading. The text fully fades at this distance.
+         */
+        float fade_end_square_;
+};
+
+/**
+ * Shortcut for a DebugDraw singleton.
+ */
+#define DEBUG_DRAW DebugDraw::getSingleton()
 
-#endif // DEBUG_DRAW_H

+ 350 - 76
QGearsMain/include/core/DialogsManager.h

@@ -1,125 +1,399 @@
-#ifndef DIALOGS_MANAGER_h
-#define DIALOGS_MANAGER_h
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreSingleton.h>
-
 #include "UiManager.h"
 #include "UiTextArea.h"
 
 
+/**
+ * Possible states for messages.
+ */
+enum MessageState{
 
-enum MessageState
-{
+    /**
+     * The message is now closed.
+     */
     MS_CLOSED,
+
+    /**
+     * The message window is shown, but there is no text.
+     */
     MS_SHOW_WINDOW,
+
+    /**
+     * The message window and text are shown.
+     */
     MS_SHOW_TEXT,
+
+    /**
+     * The message window is open.
+     */
     MS_OPENED,
+
+    /**
+     * The message window has been hidden.
+     */
     MS_HIDE_WINDOW
 };
 
+/**
+ * Styles for message boxes.
+ */
+enum MessageStyle{
 
-
-enum MessageStyle
-{
+    /**
+     * Regular message box, solid background.
+     */
     MSL_SOLID,
+
+    /**
+     * Translucent message box.
+     */
     MSL_TRANSPARENT,
+
+    /**
+     * No message box.
+     */
     MSL_NONE
 };
 
-
-
-struct MessageData
-{
+/**
+ * Message data.
+ */
+struct MessageData{
     MessageData():
-        widget( NULL ),
-        window( NULL ),
-        scissor( NULL ),
-        text_area( NULL ),
-        cursor( NULL ),
-
-        state( MS_CLOSED ),
-
-        clickable( true ),
-        show_window( true ),
-        show_cursor( false ),
-        auto_close( false ),
-
-        cursor_percent_y( 0 ),
-        cursor_y( 0 ),
-        cursor_row_selected( 0 ),
-        cursor_row_current( 0 ),
-        cursor_row_first( 0 ),
-        cursor_row_last( 0 )
-    {
-    }
-
+      widget(NULL),
+      window(NULL),
+      scissor(NULL),
+      text_area(NULL),
+      cursor(NULL),
+      state(MS_CLOSED),
+      clickable(true),
+      show_window(true),
+      show_cursor(false),
+      auto_close(false),
+      cursor_percent_y(0),
+      cursor_y(0),
+      cursor_row_selected(0),
+      cursor_row_current(0),
+      cursor_row_first(0),
+      cursor_row_last(0)
+    {}
+
+    /**
+     * The widget where the message is displayed.
+     */
     UiWidget* widget;
+
+    /**
+     * The window where the message is displayed.
+     */
     UiWidget* window;
+
+    /**
+     * @todo Understand and document.
+     */
     UiWidget* scissor;
+
+    /**
+     * The message text area.
+     */
     UiTextArea* text_area;
+
+    /**
+     * The message cursor.
+     */
     UiWidget* cursor;
 
+    /**
+     * The state of the message.
+     */
     MessageState state;
+
+    /**
+     * The message window X coordinate.
+     */
     int x = 0;
+
+    /**
+     * The message window Y coordinate.
+     */
     int y = 0;
+
+    /**
+     * The message width, in pixels.
+     */
     int w = 0;
+
+    /**
+     * The message height, in pixels.
+     */
     int h = 0;
 
-    std::vector< ScriptId > sync;
+    /**
+     * @todo Understand and document.
+     */
+    std::vector<ScriptId> sync;
 
+    /**
+     * Indicates if the text is 'clickable', i.e., if it requieres a keypress
+     * to advance.
+     */
     bool clickable;
+
+    /**
+     * Indicates if the dialog window is shown.
+     */
     bool show_window;
+
+    /**
+     * Indicates if the choice selection cursor must be shown.
+     */
     bool show_cursor;
+
+    /**
+     * Indicates if the dialog must be closed automatically.
+     */
     bool auto_close;
 
+    /**
+     * @todo Understand and document.
+     */
     float cursor_percent_y;
+
+    /**
+     * Y position of the cursor in the message box.
+     */
     float cursor_y;
+
+    /**
+     * Selected choice line.
+     */
     int cursor_row_selected;
+
+    /**
+     * Currently selected choice line.
+     */
     int cursor_row_current;
+
+    /**
+     * First chooseable line.
+     */
     int cursor_row_first;
+
+    /**
+     * Last chooseable line.
+     */
     int cursor_row_last;
 };
 
-
-
-class DialogsManager : public Ogre::Singleton< DialogsManager >
-{
-public:
-    DialogsManager();
-    virtual ~DialogsManager();
-
-    void Initialise();
-    void Input( const QGears::Event& event );
-    void Update();
-    void Clear();
-
-    void OpenDialog(const char* d_name, int x, int y, int w, int h); // aka dialog_open
-    void SetText( const char* d_name, const char* text ); // aka dialog_set_text
-    int Sync( const char* d_name ); // aka dialog_wait_for_close
-    void Hide(const char* d_name); // aka dialog_close
-
-    void SetVariable( const char* d_name, const char* name, const char* value );
-
-    void SetClickable( const char* d_name, const bool clickable );
-    void SetCursor( const char* d_name, const int first_row, const int last_row );
-    int GetCursor( const char* d_name ) const;
-
-private:
-    void ShowMessage( const int id, const int x, const int y, const int width, const int height );
-    void HideMessage( const int id );
-    int GetMessageId( const char* d_name ) const;
-    bool AutoCloseCheck( const unsigned int id );
-
-private:
-    UiWidget* m_LimitArea;
-    std::vector< MessageData* > m_Messages;
-
-    bool m_NextPressed;
-    bool m_NextRepeated;
-    bool m_UpPressed;
-    bool m_DownPressed;
+/**
+ * The dialog manager.
+ */
+class DialogsManager : public Ogre::Singleton<DialogsManager>{
+
+    public:
+
+        /**
+         * Constructor.
+         */
+        DialogsManager();
+
+        /**
+         * Destructor.
+         */
+        virtual ~DialogsManager();
+
+        /**
+         * Initializes the dialog manager.
+         */
+        void Initialise();
+
+        /**
+         * Processes an input event.
+         *
+         * @param event[in] Event to process.
+         */
+        void Input(const QGears::Event& event);
+
+        /**
+         * Updates all the messages in the manager.
+         */
+        void Update();
+
+        /**
+         * Hides every dialog in the manager.
+         */
+        void Clear();
+
+        /**
+         * Opens a dialog.
+         *
+         * Equivalent to dialog_open in the field scripts.
+         *
+         * @param d_name[in] The dialog name. Can be used as ID.
+         * @param x[in] X coordinate for the top left corner of the dialog.
+         * @param y[in] Y coordinate for the top left corner of the dialog.
+         * @param w[in] Width of the dialog, in pixels.
+         * @param h[in] Height of the dialog, in pixels.
+         */
+        void OpenDialog(const char* d_name, int x, int y, int w, int h);
+
+        /**
+         * Sets the text of a dialog.
+         *
+         * Equivalent to dialog_set_text in the field scripts.
+         *
+         * @param d_name[in] Name of the dialog.
+         * @param text[in] Text to set in the dialog.
+         */
+        void SetText(const char* d_name, const char* text);
+
+        /**
+         * Syncs the dialog and makes the script wait until it is closed.
+         *
+         * Equivalent to dialog_wait_for_close in the field scripts.
+         *
+         * @param d_name[in] Name of the dialog.
+         * @return 1 if the dialog doesn't exist, -1 otherwise.
+         */
+        int Sync(const char* d_name);
+
+        /**
+         * Closes and hides a dialog window.
+         *
+         * Equivalent to dialog_close in the field scripts.
+         *
+         * @param dialog_name Name of the dialog to close.
+         */
+        void Hide(const char* d_name);
+
+        /**
+         * Sets a variable in a dialog
+         *
+         * @param d_name[in] Name of the dialog.
+         * @param name[in] Name of the variable.
+         * @param value[in] Value for the variable.
+         */
+        void SetVariable(
+          const char* d_name, const char* name, const char* value
+        );
+
+        /**
+         * Makes the dialog clickable or not.
+         *
+         * A clickable dialog presents a choice for the user that must be
+         * selected with a cursor.
+         *
+         * @param d_name[in] Name of the dialog.
+         * @param clickable[in] True to make the dialog clickable, false to
+         * make it unclickable
+         */
+        void SetClickable(const char* d_name, const bool clickable);
+
+        /**
+         * Sets a choice sursor in the dialog.
+         *
+         * @param d_name[in] Name of the dialog.
+         * @param first_row[in] First selectable line.
+         * @param last_row[in] Last selectable line.
+         */
+        void SetCursor(
+          const char* d_name, const int first_row, const int last_row
+        );
+
+        /**
+         * Gets the cursor position in a dialog.
+         *
+         * @param d_name[in] Dialog name.
+         * @return Position of the cursor in the dialog, including unselectable
+         * lines (0-index). 0 if the dialog doesn't exist.
+         */
+        int GetCursor(const char* d_name) const;
+
+    private:
+
+        /**
+         * Shows a message in a dialog.
+         *
+         * @param id[in] Message id.
+         * @param x[in] X coordinate for the text in the dialog.
+         * @param y[in] Y coordinate for the text in the dialog.
+         * @param width[in] Width of the text, in pixels.
+         * @param height[in] Height of the text, in pixels.
+         * @todo Is this a window-limit-aware version of SetText?
+         */
+        void ShowMessage(
+          const int id, const int x, const int y,
+          const int width, const int height
+        );
+
+        /**
+         * Closes and hides a message.
+         *
+         * @param id[in] ID of the message to close.
+         */
+        void HideMessage(const int id);
+
+        /**
+         * Retrieves a message Id from it's name.
+         *
+         * @param d_name[in] Dialog name.
+         * @return The dialog ID. -1 if there is no dialog by that name.
+         */
+        int GetMessageId(const char* d_name) const;
+
+        /**
+         * Checks if a message is set to close automatically.
+         *
+         * @param id[in] Message ID.
+         * @return True if the message is set to auto close, false otherwise.
+         */
+        bool AutoCloseCheck(const unsigned int id);
+
+        /**
+         * The limit area for message boxes.
+         */
+        UiWidget* limit_area_;
+
+        /**
+         * The list of messages.
+         */
+        std::vector<MessageData*> messages_;
+
+        /**
+         * Indicates if the 'next' button has been pressed.
+         */
+        bool next_pressed_;
+
+        /**
+         * Indicates if the 'next' button is being hold.
+         */
+        bool next_repeated_;
+
+        /**
+         * Indicates if the 'up' button has been pressed.
+         */
+        bool up_pressed_;
+
+        /**
+         * Indicates if the 'down' button has been pressed.
+         */
+        bool down_pressed_;
 };
 
-
-
-#endif // DIALOGS_MANAGER_H

+ 1277 - 252
QGearsMain/include/core/Entity.h

@@ -1,282 +1,1307 @@
-#ifndef ENTITY_H
-#define ENTITY_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreString.h>
+#pragma once
 
+#include <OgreString.h>
 #include "EntityCollision.h"
 #include "EntityDirection.h"
 #include "ScriptManager.h"
 
+/**
+ * Action types.
+ */
+enum ActionType{
 
-
-enum ActionType
-{
+    /**
+     * No action.
+     */
     AT_NONE,
+
+    /**
+     * Linear action.
+     *
+     * It starts and ends at full speed.
+     */
     AT_LINEAR,
+
+    /**
+     * Smooth action.
+     *
+     * The action speed steadily increases when started, and it steadily
+     * decreases before the end.
+     */
     AT_SMOOTH
 };
 
+/**
+ * The direction for an entity turn.
+ */
+enum TurnDirection{
 
-
-enum TurnDirection
-{
+    /**
+     * Turn clockwise.
+     */
     TD_CLOCKWISE,
+
+    /**
+     * Turn anticlockwise.
+     */
     TD_ANTICLOCKWISE,
+
+    /**
+     * Choose direction automatically.
+     *
+     * The direction in which the turn is shorter will be selected.
+     */
     TD_CLOSEST
 };
 
+/**
+ * Linear movement modes.
+ */
+enum LinearMovement{
 
-
-enum LinearMovement
-{
+    /**
+     * Move down.
+     */
     LM_UP_TO_DOWN,
+
+    /**
+     * Move up.
+     */
     LM_DOWN_TO_UP,
+
+    /**
+     * Move right.
+     */
     LM_LEFT_TO_RIGHT,
+
+    /**
+     * Move left.
+     */
     LM_RIGHT_TO_LEFT
 };
 
+/**
+ * Any entity in a field.
+ */
+class Entity{
 
+    public:
 
-class Entity
-{
-public:
-    enum AnimationState
-    {
-        REQUESTED_ANIMATION,
-        AUTO_ANIMATION
-    };
-
-    enum AnimationPlayType
-    {
-        PLAY_DEFAULT,
-        PLAY_ONCE,
-        PLAY_LOOPED
-    };
-
-    enum State
-    {
-        NONE,
-        WALKMESH,
-        LINEAR,
-        JUMP
-    };
-
-                         Entity( const Ogre::String& name, Ogre::SceneNode* node );
-    virtual              ~Entity();
-
-    virtual void         Update();
-    virtual void         UpdateDebug();
-
-    const Ogre::String&  GetName() const;
-
-    void                 SetPosition( const Ogre::Vector3& position );
-    void                 ScriptSetPosition( const float x, const float y, const float z );
-    const Ogre::Vector3  GetPosition() const;
-    void                 ScriptGetPosition() const;
-
-    void                 SetOffset( const Ogre::Vector3& position );
-    const Ogre::Vector3  GetOffset() const;
-
-    void                 SetRotation( const Ogre::Degree& rotation );
-    void                 ScriptSetRotation( const float rotation );
-    Ogre::Degree         GetRotation() const;
-    float                ScriptGetRotation() const;
-
-    virtual void         setScale( const Ogre::Vector3 &scale );
-    virtual void         setRootOrientation( const Ogre::Quaternion &root_orientation );
-
-    // height related
-    float                GetHeight() const;
-
-    // solid related
-    void                 SetSolidRadius( const float radius );
-    float                GetSolidRadius() const;
-    void                 SetSolid( const bool solid );
-    bool                 IsSolid() const;
-
-    // talk related
-    void                 SetTalkRadius( const float radius );
-    float                GetTalkRadius() const;
-    void                 SetTalkable( const bool talkable );
-    bool                 IsTalkable() const;
-
-    // model related
-    virtual void         SetVisible( const bool visible ) = 0;
-    virtual bool         IsVisible() const = 0;
-
-    // different type of movement state related
-    void                 SetState( const State state );
-    State                GetState() const;
-
-    // movement related
-    void                 SetMoveAutoSpeed( const float speed );
-    float                GetMoveAutoSpeed() const;
-    void                 SetMoveWalkSpeed( const float speed );
-    float                GetMoveWalkSpeed() const;
-    void                 SetMoveRunSpeed( const float speed );
-    float                GetMoveRunSpeed() const;
-    void                 SetMovePosition( const Ogre::Vector3& target );
-    const Ogre::Vector3& GetMovePosition() const;
-    float                GetMoveStopDistance() const;
-    void                 SetMoveTriangleId( const int triangle );
-    int                  GetMoveTriangleId() const;
-    void                 SetMoveAutoRotation( const bool rotate );
-    bool                 GetMoveAutoRotation() const;
-    void                 SetMoveAutoAnimation( const bool animate );
-    bool                 GetMoveAutoAnimation() const;
-    const Ogre::String&  GetMoveAnimationWalkName() const;
-    const Ogre::String&  GetMoveAnimationRunName() const;
-    void                 ScriptMoveToPosition( const float x, const float y );
-    void                 ScriptMoveToEntity( Entity* entity );
-    int                  ScriptMoveSync();
-    void                 UnsetMove();
-
-    // linear related
-    void                 ScriptLinearToPosition( const float x, const float y, const float z, const LinearMovement movement, const char* animation );
-    int                  ScriptLinearSync();
-    void                 SetLinear( const Ogre::Vector3& end, const LinearMovement movement, const Ogre::String& animation );
-    void                 UnsetLinear();
-    LinearMovement       GetLinearMovement() const;
-    const Ogre::Vector3& GetLinearStart() const;
-    const Ogre::Vector3& GetLinearEnd() const;
-
-    // jump related
-    void                 ScriptJumpToPosition( const float x, const float y, const float z,const float seconds );
-    int                  ScriptJumpSync();
-    void                 SetJump( const Ogre::Vector3& jump_to, const float seconds );
-    void                 UnsetJump();
-    const Ogre::Vector3& GetJumpStart() const;
-    const Ogre::Vector3& GetJumpEnd() const;
-    float                GetJumpSeconds() const;
-    void                 SetJumpCurrentSeconds( const float seconds );
-    float                GetJumpCurrentSeconds() const;
-
-    // offset related
-    void                 ScriptOffsetToPosition( const float x, const float y, const float z, const ActionType type, const float seconds );
-    int                  ScriptOffsetSync();
-    void                 UnsetOffset();
-    const Ogre::Vector3& GetOffsetPositionStart() const;
-    const Ogre::Vector3& GetOffsetPositionEnd() const;
-    ActionType           GetOffsetType() const;
-    float                GetOffsetSeconds() const;
-    void                 SetOffsetCurrentSeconds( const float seconds );
-    float                GetOffsetCurrentSeconds() const;
-
-    // turn related
-    void                 ScriptTurnToDirection( const float direction, const TurnDirection turn_direction, const ActionType turn_type, const float seconds );
-    void                 ScriptTurnToEntity( Entity* entity, const TurnDirection turn_direction, const float seconds );
-    int                  ScriptTurnSync();
-    void                 SetTurn( const Ogre::Degree& direction_to, Entity* entity, const TurnDirection turn_direction, const ActionType turn_type, const float seconds );
-    void                 UnsetTurn();
-    Ogre::Degree         CalculateTurnAngle( const Ogre::Degree& start, const Ogre::Degree& end ) const;
-    Ogre::Degree         GetTurnDirectionStart() const;
-    Ogre::Degree         GetTurnDirectionEnd() const;
-    ActionType           GetTurnType() const;
-    float                GetTurnSeconds() const;
-    void                 SetTurnCurrentSeconds( const float seconds );
-    float                GetTurnCurrentSeconds() const;
-
-    // animation related
-    void                 ScriptSetAnimationSpeed( const float speed );
-    const Ogre::String&  GetDefaultAnimationName() const;
-    const Ogre::String&  GetCurrentAnimationName() const;
-    AnimationState       GetAnimationState() const;
-    virtual void         PlayAnimation( const Ogre::String& animation, AnimationState state, AnimationPlayType play_type, const float start, const float end ) = 0;
-    virtual void         PlayAnimationContinue( const Ogre::String& animation ) = 0;
-    virtual void         UpdateAnimation( const float delta ) = 0;
-    void                 ScriptPlayAnimation( const char* name );
-    void                 ScriptPlayAnimationStop( const char* name );
-    void                 ScriptPlayAnimation( const char* name, const float start, const float end );
-    void                 ScriptPlayAnimationStop( const char* name, const float start, const float end );
-    void                 ScriptSetDefaultAnimation( const char* animation );
-    int                  ScriptAnimationSync();
-
-private:
-    Entity();
-    Ogre::Degree         GetDirectionToEntity( Entity* entity ) const;
-
-protected:
-    Ogre::String            m_Name;
-
-    Ogre::SceneNode*        m_SceneNode;
-    Ogre::SceneNode*        m_ModelNode;
-    Ogre::SceneNode*        m_model_root_node;
-
-    // height related
-    float                   m_Height;
-
-    Ogre::SceneNode*        m_DirectionNode;
-    EntityDirection*        m_Direction;
-
-    // collision related
-    Ogre::SceneNode*        m_SolidCollisionNode;
-    EntityCollision*        m_SolidCollision;
-    float                   m_SolidRadius;
-    bool                    m_Solid;
-
-    // talk related
-    Ogre::SceneNode*        m_TalkCollisionNode;
-    EntityCollision*        m_TalkCollision;
-    float                   m_TalkRadius;
-    bool                    m_Talkable;
-
-    // move state related
-    State                   m_State;
-    std::vector< ScriptId > m_Sync;
-
-    // move related
-    float                   m_MoveAutoSpeed;
-    float                   m_MoveWalkSpeed;
-    float                   m_MoveRunSpeed;
-    Ogre::Vector3           m_MovePosition;
-    Entity*                 m_MoveEntity;
-    float                   m_MoveStopDistance;
-    int                     m_MoveTriangleId;
-    bool                    m_MoveAutoRotation;
-    bool                    m_MoveAutoAnimation;
-    Ogre::String            m_MoveAnimationWalk;
-    Ogre::String            m_MoveAnimationRun;
-
-    // linear movement related
-    LinearMovement          m_LinearMovement;
-    Ogre::Vector3           m_LinearStart;
-    Ogre::Vector3           m_LinearEnd;
-
-    // jump related
-    Ogre::Vector3           m_JumpStart;
-    Ogre::Vector3           m_JumpEnd;
-    float                   m_JumpSeconds;
-    float                   m_JumpCurrentSeconds;
-
-    // offset related
-    Ogre::Vector3           m_OffsetPositionStart;
-    Ogre::Vector3           m_OffsetPositionEnd;
-    ActionType              m_OffsetType;
-    float                   m_OffsetSeconds;
-    float                   m_OffsetCurrentSeconds;
-    std::vector< ScriptId > m_OffsetSync;
-
-    // turn related
-    TurnDirection           m_TurnDirection;
-    Ogre::Degree            m_TurnDirectionStart;
-    Ogre::Degree            m_TurnDirectionEnd;
-    Entity*                 m_TurnEntity;
-    ActionType              m_TurnType;
-    float                   m_TurnSeconds;
-    float                   m_TurnCurrentSeconds;
-    std::vector< ScriptId > m_TurnSync;
-
-    // animation
-    float                   m_AnimationSpeed;
-    Ogre::String            m_AnimationCurrentName;
-    std::vector< ScriptId > m_AnimationSync;
-    AnimationState          m_AnimationState;
-    AnimationPlayType       m_AnimationPlayType;
-    Ogre::String            m_AnimationDefault;
-    float                   m_AnimationEndTime;
-    bool                    m_AnimationAutoPlay;
-};
+        /**
+         * Entity animation states.
+         */
+        enum AnimationState{
+
+            /**
+             * An animation has been requested.
+             */
+            REQUESTED_ANIMATION,
+
+            /**
+             * An animation is set to play automatically.
+             */
+            AUTO_ANIMATION
+        };
+
+        /**
+         * Types of animations.
+         */
+        enum AnimationPlayType{
+
+            /**
+             * Default animation mode.
+             *
+             * @todo Same as PLAY_ONCE?
+             */
+            PLAY_DEFAULT,
+
+            /**
+             * Play the animation once, then stop.
+             */
+            PLAY_ONCE,
+
+            /**
+             * Play an animation in a continous loop.
+             */
+            PLAY_LOOPED
+        };
+
+        /**
+         * Entity state.
+         */
+        enum State{
+
+            /**
+             * No state.
+             *
+             * The entity has not been placed or it has been removed.
+             */
+            NONE,
+
+            /**
+             * The entity is in the walkmesh.
+             */
+            WALKMESH,
+
+            /**
+             * @todo Understand and document.
+             */
+            LINEAR,
+
+            /**
+             * @todo Understand and document.
+             */
+            JUMP
+        };
+
+        /**
+         * Constructor.
+         *
+         * @param name[in] Entity name.
+         * @param node[in] Scene node to which the entity should be attached.
+         */
+        Entity(const Ogre::String& name, Ogre::SceneNode* node);
+
+        /**
+         * Destructor.
+         */
+        virtual ~Entity();
+
+        /**
+         * Updates the entity status.
+         */
+        virtual void Update();
+
+        /**
+         * Updates the entity status with debug information.
+         */
+        virtual void UpdateDebug();
+
+        /**
+         * Retrieves the entity name.
+         *
+         * @return The entity name.
+         */
+        const Ogre::String& GetName() const;
+
+        /**
+         * Sets the entity position.
+         *
+         * @param position[in] Entity's new position.
+         */
+        void SetPosition(const Ogre::Vector3& position);
+
+        /**
+         * Sets the entity position.
+         *
+         * It also resets the walkmesh triangle to reattach entity to walkmesh
+         * again if needed.
+         *
+         * @param x[in] Entity's new position X coordinate.
+         * @param y[in] Entity's new position Y coordinate.
+         * @param z[in] Entity's new position Z coordinate.
+         */
+        void ScriptSetPosition(const float x, const float y, const float z);
+
+        /**
+         * Retrieves the entity position.
+         *
+         * @return The entity position.
+         */
+        const Ogre::Vector3 GetPosition() const;
+
+        /**
+         * Informs the script manager of the entity position.
+         *
+         * @todo Im not really sure what this actually does.
+         */
+        void ScriptGetPosition() const;
+
+        /**
+         * Sets the entity position.
+         *
+         * @param position[in] The entity new position.
+         * @todo Offset to what?
+         */
+        void SetOffset(const Ogre::Vector3& position);
+
+        /**
+         * Retrieves the entity position.
+         *
+         * @return The entity position.
+         * @todo Offset to what?
+         */
+        const Ogre::Vector3 GetOffset() const;
+
+        /**
+         * Sets the entity rotation.
+         *
+         * @param rotation[in] The entity rotation, in degrees.
+         */
+        void SetRotation(const Ogre::Degree& rotation);
+
+        /**
+         * Sets the entity rotation.
+         *
+         * @param rotation[in] The entity rotation (0-360).
+         */
+        void ScriptSetRotation(const float rotation);
+
+        /**
+         * Retrieves the entity rotation.
+         *
+         * @return The entity rotation, in degrees.
+         */
+        Ogre::Degree GetRotation() const;
+
+        /**
+         * Retrieves the entity rotation.
+         *
+         * @return The entity rotation (0-360).
+         */
+        float ScriptGetRotation() const;
+
+        /**
+         * Sets the entity scale.
+         *
+         * @param scale[in] Three dimensional scale.
+         */
+        virtual void setScale(const Ogre::Vector3 &scale);
+
+        /**
+         * Sets the entity's absolute orientation.
+         *
+         * @param root_orientation[in] The entity's new orientation.
+         */
+        virtual void setRootOrientation(
+          const Ogre::Quaternion &root_orientation
+        );
+
+        /**
+         * Retrieves the entity's height.
+         *
+         * @return The entity's height.
+         */
+        float GetHeight() const;
+
+        /**
+         * Sets the entity's solid radius.
+         *
+         * The solid radius is used to detect collisions.
+         *
+         * @param radius[in] The solid radius.
+         * @todo Is it in pixels?
+         */
+        void SetSolidRadius(const float radius);
+
+        /**
+         * Retrieves the entity's solid radius.
+         *
+         * The solid radius is used to detect collisions.
+         *
+         * @return The solid radius.
+         * @todo Is it in pixels?
+         */
+        float GetSolidRadius() const;
+
+        /**
+         * Makes the entity solid or non-solid.
+         *
+         * Solid entities can produce collisions.
+         *
+         * @param solid[in] True to make the entity solid, false otherwise.
+         */
+        void SetSolid(const bool solid);
+
+        /**
+         * Checks if the entity is solid.
+         *
+         * Solid entities can produce collisions.
+         *
+         * @return True if the entity is solid, false otherwise.
+         */
+        bool IsSolid() const;
+
+        /**
+         * Sets the entity talk radius.
+         *
+         * The talk radius is the maximum distance at which an entity can be
+         * talked to or interacted with.
+         *
+         * @param radius[in] The talk radius.
+         * @todo Is it in pixels?
+         */
+        void SetTalkRadius(const float radius);
+
+        /**
+         * Retrieves the entity talk radius.
+         *
+         * The talk radius is the maximum distance at which an entity can be
+         * talked to or interacted with.
+         *
+         * @return The talk radius.
+         * @todo Is it in pixels?
+         */
+        float GetTalkRadius() const;
+
+        /**
+         * Sets an entity as talkable or non-talkable.
+         *
+         * Talkable units can be talked to or interacted with.
+         *
+         * @param talkable[in] True to make the entity talkable, false to make
+         * it non-talkable.
+         */
+        void SetTalkable(const bool talkable);
+
+        /**
+         * Checks if an entity is talkable or non-talkable.
+         *
+         * Talkable units can be talked to or interacted with.
+         *
+         * @return True if the entity is talkable, false if it's not.
+         */
+        bool IsTalkable() const;
+
+        /**
+         * Makes the entity visible or invisible.
+         *
+         * Invisible entities can't be interacted with.
+         *
+         * @param visible[in] True to make the unit visible, false to make it
+         * invisible.
+         */
+        virtual void SetVisible(const bool visible) = 0;
+
+        /**
+         * Checks if the entity is visible or invisible.
+         *
+         * Invisible entities can't be interacted with.
+         *
+         * @return True if the unit is visible, false if it's invisible.
+         */
+        virtual bool IsVisible() const = 0;
+
+        /**
+         * Sets the entity's state.
+         *
+         * @param state[in] The entity's state.
+         */
+        void SetState(const State state);
+
+        /**
+         * Retrieves the entity's state.
+         *
+         * @return The entity's state.
+         */
+        State GetState() const;
+
+        /**
+         * Sets the entity's automatic movement speed.
+         *
+         * @param speed[in] Automatic movement speed.
+         * @todo Describe where this speed is used, and max and mins or
+         * references.
+         */
+        void SetMoveAutoSpeed(const float speed);
+
+        /**
+         * Retrieves the entity's automatic movement speed.
+         *
+         * @return Automatic movement speed.
+         * @todo Describe where this speed is used, and max and mins or
+         * references.
+         */
+        float GetMoveAutoSpeed() const;
+
+        /**
+         * Sets the entity's walking movement speed.
+         *
+         * @param speed[in] Walking speed.
+         * @todo Describe where this speed is used, and max and mins or
+         * references.
+         */
+        void SetMoveWalkSpeed(const float speed);
+
+        /**
+         * Retrieves the entity's walking speed.
+         *
+         * @return Walking speed.
+         * @todo Describe where this speed is used, and max and mins or
+         * references.
+         */
+        float GetMoveWalkSpeed() const;
+
+        /**
+         * Sets the entity's running movement speed.
+         *
+         * @param speed[in] Running speed.
+         * @todo Describe where this speed is used, and max and mins or
+         * references.
+         */
+        void SetMoveRunSpeed(const float speed);
+
+        /**
+         * Retrieves the entity's running speed.
+         *
+         * @return Running speed.
+         * @todo Describe where this speed is used, and max and mins or
+         * references.
+         */
+        float GetMoveRunSpeed() const;
+
+        /**
+         * Sets the entity's movement destination position.
+         *
+         * @param target[in] The destination position.
+         */
+        void SetMovePosition(const Ogre::Vector3& target);
+
+        /**
+         * Retrieves the entity's movement destination position.
+         *
+         * @return The destination position.
+         */
+        const Ogre::Vector3& GetMovePosition() const;
+
+        /**
+         * Retrieves the distance to destination.
+         *
+         * It's the distance between the entity's current position and it's
+         * current movement destination point.
+         *
+         * @return The distance to destination.
+         * @todo Verify this description. Also, indicate units (pixels?).
+         */
+        float GetMoveStopDistance() const;
+
+        /**
+         * Sets the destination triangle in the walkmesh.
+         *
+         * Sets the units destination to one of the walkmesh triangles. The
+         * movement will stop once the unit enters the triangle.
+         *
+         * @param triangle[in] Destination triangle in the walkmesh.
+         */
+        void SetMoveTriangleId(const int triangle);
+
+        /**
+         * Sets the destination triangle in the walkmesh.
+         *
+         * @return Destination triangle in the walkmesh.
+         */
+        int GetMoveTriangleId() const;
+
+        /**
+         * Enables or disables autorotation while the entity is moving.
+         *
+         * @param rotate[in] If true, the entity will rotate automatically
+         * while moving. If false, the entity will not rotate.
+         */
+        void SetMoveAutoRotation(const bool rotate);
+
+        /**
+         * Checks if the unit can autorotate while it's moving.
+         *
+         * @return If true, the entity will rotate automatically while moving.
+         * If false, the entity will not rotate.
+         */
+        bool GetMoveAutoRotation() const;
+
+        /**
+         * Enables or disables autoanimation while the entity is moving.
+         *
+         * @param animate[in] If true, the entity will animate automatically
+         * while moving. If false, the entity will not animate.
+         */
+        void SetMoveAutoAnimation(const bool animate);
+
+        /**
+         * Checks if the unit can autoanimate while it's moving.
+         *
+         * @return If true, the entity will animate automatically while moving.
+         * If false, the entity will not animate.
+         */
+        bool GetMoveAutoAnimation() const;
+
+        /**
+         * Retrieves the entity's walk animation name.
+         *
+         * @return The walk animation name.
+         */
+        const Ogre::String& GetMoveAnimationWalkName() const;
+
+        /**
+         * Retrieves the entity's run animation name.
+         *
+         * @return The run animation name.
+         */
+        const Ogre::String& GetMoveAnimationRunName() const;
+
+        /**
+         * Makes the unit move to a point in the map.
+         *
+         * @param x[in] X coordinate of the destination point.
+         * @param y[in] Y coordinate of the destination point.
+         */
+        void ScriptMoveToPosition(const float x, const float y);
+
+        /**
+         * Makes the unit move towards another in the map.
+         *
+         * @param entity[in] entity to move towards.
+         */
+        void ScriptMoveToEntity(Entity* entity);
+
+        /**
+         * Adds the entity's movement to the sync queue.
+         *
+         * @return Always -1.
+         * @todo Properly describe this.
+         */
+        int ScriptMoveSync();
+
+        /**
+         * Cancels the entity's current movement.
+         *
+         * It also clears the movement sync queue.
+         */
+        void UnsetMove();
+
+        /**
+         * Linearly moves the entity.
+         *
+         * @param x[in] X coordinate of the destination point.
+         * @param y[in] Y coordinate of the destination point.
+         * @param z[in] Z coordinate of the destination point.
+         * @param movement[in] Movement direction.
+         * @param animation[in] Movement animation.
+         */
+        void ScriptLinearToPosition(
+          const float x, const float y, const float z,
+          const LinearMovement movement, const char* animation
+        );
+
+        /**
+         * Adds the unit linear movement to the sync queue.
+         *
+         * @return Always -1.
+         * @todo Properly describe this.
+         */
+        int ScriptLinearSync();
+
+        /**
+         * Linearly moves the entity.
+         *
+         * @param end[in] Destination point.
+         * @param movement[in] Movement direction.
+         * @param animation[in] Movement animation.
+         */
+        void SetLinear(
+          const Ogre::Vector3& end, const LinearMovement movement,
+          const Ogre::String& animation
+        );
+
+        /**
+         * Cancels the entity's current linear movement.
+         *
+         * It also clears the movement sync queue.
+         */
+        void UnsetLinear();
+
+        /**
+         * Retrieves the entity's current linear movement.
+         *
+         * @return Current linear movement.
+         */
+        LinearMovement GetLinearMovement() const;
+
+        /**
+         * Retrieves the starting point of the current linear movement.
+         *
+         * @return Starting point.
+         */
+        const Ogre::Vector3& GetLinearStart() const;
+
+        /**
+         * Retrieves the ending point of the current linear movement.
+         *
+         * @return Ending point.
+         */
+        const Ogre::Vector3& GetLinearEnd() const;
+
+        /**
+         * Makes the unit jump to a point in the field.
+         *
+         * @param x[in] X coordinate of the jump destination point.
+         * @param y[in] Y coordinate of the jump destination point.
+         * @param z[in] Z coordinate of the jump destination point.
+         * @param seconds[in] Jump duration.
+         */
+        void ScriptJumpToPosition(
+          const float x, const float y, const float z,const float seconds
+        );
+
+        /**
+         * Adds the entity's jump to the sync queue.
+         *
+         * @return Always -1.
+         * @todo Properly describe this.
+         */
+        int ScriptJumpSync();
+
+        /**
+         * Makes the unit jump to a point in the field.
+         *
+         * @param jump_to[in] The jump destination point.
+         * @param seconds[in] Jump duration.
+         */
+        void SetJump(const Ogre::Vector3& jump_to, const float seconds);
+
+        /**
+         * Cancels the entity's current jump.
+         *
+         * It also clears the movement sync queue.
+         */
+        void UnsetJump();
+
+        /**
+         * Retrieves the starting point of the current jump.
+         *
+         * @return Starting point.
+         */
+        const Ogre::Vector3& GetJumpStart() const;
+
+        /**
+         * Retrieves the ending point of the current jump.
+         *
+         * @return Ending point.
+         */
+        const Ogre::Vector3& GetJumpEnd() const;
+
+        /**
+         * Gets the total duration of the jump.
+         *
+         * @param Jump total duration, in seconds.
+         */
+        float GetJumpSeconds() const;
+
+        /**
+         * Sets the current duration of the jump.
+         *
+         * @param Jump current duration, in seconds.
+         */
+        void SetJumpCurrentSeconds(const float seconds);
+
+        /**
+         * Gets the current duration of the jump.
+         *
+         * @param Jump current duration, in seconds.
+         */
+        float GetJumpCurrentSeconds() const;
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param x[in] X coordinate of the destination point.
+         * @param y[in] Y coordinate of the destination point.
+         * @param z[in] Z coordinate of the destination point.
+         * @param type[in] Type of action.
+         * @param seconds[in] Duration of the action, in seconds.
+         */
+        void ScriptOffsetToPosition(
+          const float x, const float y, const float z,
+          const ActionType type, const float seconds
+        );
+
+        /**
+         * @todo Understand and document.
+         *
+         * @return Always -1.
+         */
+        int ScriptOffsetSync();
 
+        /**
+         * @todo Understand and document.
+         */
+        void UnsetOffset();
 
+        /**
+         * @todo Understand and document.
+         *
+         * @return Starting position.
+         */
+        const Ogre::Vector3& GetOffsetPositionStart() const;
+
+        /**
+         * @todo Understand and document.
+         *
+         * @return Ending position.
+         */
+        const Ogre::Vector3& GetOffsetPositionEnd() const;
+
+        /**
+         * @todo Understand and document.
+         *
+         * @return The action type.
+         */
+        ActionType GetOffsetType() const;
+
+        /**
+         * @todo Understand and document.
+         *
+         * @return Action total duration in seconds.
+         */
+        float GetOffsetSeconds() const;
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param seconds[in] Action current duration in seconds.
+         */
+        void SetOffsetCurrentSeconds(const float seconds);
+
+        /**
+         * @todo Understand and document.
+         *
+         * @return Action current duration in seconds.
+         */
+        float GetOffsetCurrentSeconds() const;
+
+        /**
+         * Makes the entity turn to a fixed direction.
+         *
+         * @param direction[in] Final direction to turn the entity's to.
+         * @param turn_direction[in] Direction of the turn.
+         * @param turn_type[in] Turn mode.
+         * @param seconds[in] Total turn duration, in seconds.
+         */
+        void ScriptTurnToDirection(
+          const float direction, const TurnDirection turn_direction,
+          const ActionType turn_type, const float seconds
+        );
+
+        /**
+         * Makes the entity turn towards another entity.
+         *
+         * @param entity[in] Entity to turn to.
+         * @param turn_direction[in] Direction of the turn.
+         * @param turn_type[in] Turn mode.
+         * @param seconds[in] Total turn duration, in seconds.
+         */
+        void ScriptTurnToEntity(
+          Entity* entity, const TurnDirection turn_direction,
+          const float seconds
+        );
+
+        /**
+         * Adds the entity's turn to the sync queue.
+         *
+         * @return Always -1.
+         * @todo Properly describe this.
+         */
+        int ScriptTurnSync();
+
+        /**
+         * Makes the entity turn towards a point or another entity.
+         *
+         * @param direction_to[in] Final direction to turn the entity's to.
+         * @param entity[in] Entity to turn to.
+         * @param turn_direction[in] Direction of the turn.
+         * @param turn_type[in] Turn mode.
+         * @param seconds[in] Total turn duration, in seconds.
+         * @todo What if the point
+         */
+        void SetTurn(const Ogre::Degree& direction_to, Entity* entity, const TurnDirection turn_direction, const ActionType turn_type, const float seconds);
+
+        /**
+         * Cancels the entity's current jump.
+         *
+         * It also clears the movement sync queue.
+         */
+        void UnsetTurn();
+
+        /**
+         * Calculates the turn angle.
+         *
+         * If the turn direction is {@see TD_CLOSEST}, the result is the
+         * smallest angle between the two orientations. Otherwise, is the angle
+         * in the specified turn direction.
+         *
+         * @param start[in] Starting angle.
+         * @param start[in] Ending angle.
+         * @return[in] Calculated turn angle.
+         */
+        Ogre::Degree CalculateTurnAngle(
+          const Ogre::Degree& start, const Ogre::Degree& end
+        ) const;
+
+        /**
+         * Retrieves the turn staring orientation.
+         *
+         * @return The turn starting orientation.
+         */
+        Ogre::Degree GetTurnDirectionStart() const;
+
+        /**
+         * Retrieves the turn ending orientation.
+         *
+         * @return The turn ending orientation.
+         */
+        Ogre::Degree GetTurnDirectionEnd() const;
+
+        /**
+         * Retrieves the turn type.
+         *
+         * @return The turn type.
+         */
+        ActionType GetTurnType() const;
+
+        /**
+         * Retrieves the turn total duration.
+         *
+         * @return The turn total duration, in seconds.
+         */
+        float GetTurnSeconds() const;
+
+        /**
+         * Sets the turn current duration.
+         *
+         * @param seconds[in] The turn current duration, in seconds.
+         */
+        void SetTurnCurrentSeconds(const float seconds);
+
+        /**
+         * Retrieves the turn current duration.
+         *
+         * @return The turn current duration, in seconds.
+         */
+        float GetTurnCurrentSeconds() const;
+
+        /**
+         * Sets the animation speed.
+         *
+         * @param speed[in] The animation speed.
+         * @todo Indicate units, max and mins, or references.
+         */
+        void ScriptSetAnimationSpeed(const float speed);
+
+        /**
+         * Retrieves the entity's default animation name.
+         *
+         * @return The default animation name.
+         */
+        const Ogre::String& GetDefaultAnimationName() const;
+
+        /**
+         * Retrieves the entity's current animation name.
+         *
+         * @return The current animation name.
+         */
+        const Ogre::String& GetCurrentAnimationName() const;
+
+        /**
+         * Retrieves the entity's current animation state.
+         *
+         * @return The current animation state.
+         */
+        AnimationState GetAnimationState() const;
+
+        /**
+         * Plays one of the entity's animations.
+         *
+         * @param animation[in] Name of the animation to play.
+         * @param state[in] The animation initial state.
+         * @param play_type[in] The animation play type, to play it once or in
+         * a loop.
+         * @param start[in] Animation starting point in time, in seconds.
+         * @param start[in] Animation ending point in time, in seconds.
+         */
+        virtual void PlayAnimation(
+          const Ogre::String& animation, AnimationState state,
+          AnimationPlayType play_type, const float start, const float end
+        ) = 0;
+
+        /**
+         * Resumes an animation.
+         *
+         * @param animation[in] Name of the animation to resume.
+         */
+        virtual void PlayAnimationContinue(const Ogre::String& animation) = 0;
+
+        /**
+         * Updates the animation state.
+         *
+         * @param delta[in] @todo.
+         */
+        virtual void UpdateAnimation(const float delta) = 0;
+
+        /**
+         * Plays one of the entity's animations.
+         *
+         * @param name[in] Name of the animation to play.
+         */
+        void ScriptPlayAnimation(const char* name);
+
+        /**
+         * Stops one of the entity's animations.
+         *
+         * @param name[in] Name of the animation to stop.
+         */
+        void ScriptPlayAnimationStop(const char* name);
+
+        /**
+         * Plays one of the entity's animations.
+         *
+         * @param name[in] Name of the animation to play.
+         * @param start[in] Animation starting point in time, in seconds.
+         * @param start[in] Animation ending point in time, in seconds.
+         */
+        void ScriptPlayAnimation(
+          const char* name, const float start, const float end
+        );
+
+        /**
+         * Stops one of the entity's animations.
+         *
+         * @param name[in] Name of the animation to stop.
+         * @param start[in] Animation starting point in time, in seconds.
+         * @param start[in] Animation ending point in time, in seconds.
+         */
+        void ScriptPlayAnimationStop(
+          const char* name, const float start, const float end
+        );
+
+        /**
+         * Sets the default animation of the entity.
+         *
+         * @param animation[in] Name of the default animation.
+         */
+        void ScriptSetDefaultAnimation(const char* animation);
+
+        /**
+         * Adds the entity's animation to the sync queue.
+         *
+         * @return Always -1.
+         * @todo Properly describe this.
+         */
+        int ScriptAnimationSync();
+
+    protected:
+
+        /**
+         * The name of the entity.
+         */
+        Ogre::String name_;
+
+        /**
+         * The scene node the entity is attached to.
+         */
+        Ogre::SceneNode* scene_node_;
+
+        /**
+         * The entity's model.
+         */
+        Ogre::SceneNode* model_node_;
+
+        /**
+         * The entity's root node.
+         */
+        Ogre::SceneNode* model_root_node_;
+
+        /**
+         * The entity's height.
+         */
+        float height_;
+
+        /**
+         * The entity's direction node.
+         */
+        Ogre::SceneNode* direction_node_;
+
+        /**
+         * The entity's direction.
+         */
+        EntityDirection* direction_;
+
+        /**
+         * The entity's collision node.
+         */
+        Ogre::SceneNode* solid_collision_node_;
+
+        /**
+         * The entity's collision.
+         */
+        EntityCollision* solid_collision_;
+
+        /**
+         * The entity's solid radius.
+         */
+        float solid_radius_;
+
+        /**
+         * Indicates it the entity is solid and can handle collisions.
+         */
+        bool solid_;
+
+        /**
+         * The entity's talk collision node.
+         */
+        Ogre::SceneNode* talk_collision_node_;
+
+        /**
+         * The entity's talk collision.
+         */
+        EntityCollision* talk_collision_;
+
+        /**
+         * The radius at which the entity can be interacted with.
+         */
+        float talk_radius_;
+
+        /**
+         * Indicates if the entity can be interacted with.
+         */
+        bool talkable_;
+
+        /**
+         * Entity's movement status.
+         */
+        State state_;
+
+        /**
+         * Entity's movement sync queue.
+         */
+        std::vector<ScriptId> sync_;
+
+        /**
+         * The entity's automatic movement speed.
+         */
+        float move_auto_speed_;
+
+        /**
+         * The entity's walking speed.
+         */
+        float move_walk_speed_;
+
+        /**
+         * The entity's running speed.
+         */
+        float move_run_speed_;
+
+        /**
+         * The entity's movement destination point.
+         */
+        Ogre::Vector3 move_position_;
+
+        /**
+         * The entity's movement destination entity.
+         */
+        Entity* move_entity_;
+
+        /**
+         * Distance between the entity and it's movement destination point.
+         */
+        float move_stop_distance_;
+
+        /**
+         * Entity's movement destination triangle ID.
+         */
+        int move_triangle_id_;
+
+        /**
+         * Indicates if the entity can rotate while moving.
+         */
+        bool move_auto_rotation_;
+
+        /**
+         * Indicates if the entity can animate while moving.
+         */
+        bool move_auto_animation_;
+
+        /**
+         * The name of the entity's walk animation.
+         */
+        Ogre::String move_animation_walk_;
+
+        /**
+         * The name of the entity's run animation.
+         */
+        Ogre::String move_animation_run_;
+
+        /**
+         * The entity's linear movement direction.
+         */
+        LinearMovement linear_movement_;
+
+        /**
+         * The linear movement starting point.
+         */
+        Ogre::Vector3 linear_start_;
+
+        /**
+         * The linear movement ending point.
+         */
+        Ogre::Vector3 linear_end_;
+
+        /**
+         * The jump starting point.
+         */
+        Ogre::Vector3 jump_start_;
+
+        /**
+         * The jump ending point.
+         */
+        Ogre::Vector3 jump_end_;
+
+        /**
+         * Total jump duration.
+         */
+        float jump_seconds_;
+
+        /**
+         * Current jump duration.
+         */
+        float jump_current_seconds_;
+
+        /**
+         * @todo Understand and document.
+         */
+        Ogre::Vector3 offset_position_start_;
+
+        /**
+         * @todo Understand and document.
+         */
+        Ogre::Vector3 offset_position_end_;
+
+        /**
+         * @todo Understand and document.
+         */
+        ActionType offset_type_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float offset_seconds_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float offset_current_seconds_;
+
+        /**
+         * @todo Understand and document.
+         */
+        std::vector<ScriptId> offset_sync_;
+
+        /**
+         * Turn movement direction.
+         */
+        TurnDirection turn_direction_;
+
+        /**
+         * Turn initial orientation.
+         */
+        Ogre::Degree turn_direction_start_;
+
+        /**
+         * Turn final orientation.
+         */
+        Ogre::Degree turn_direction_end_;
+
+        /**
+         * The turn destination entity.
+         */
+        Entity* turn_entity_;
+
+        /**
+         * The turn type.
+         */
+        ActionType turn_type_;
+
+        /**
+         * Total turn duration.
+         */
+        float turn_seconds_;
+
+        /**
+         * Current turn duration.
+         */
+        float turn_current_seconds_;
+
+        /**
+         * Entity's turning sync queue.
+         */
+        std::vector<ScriptId> turn_sync_;
+
+        /**
+         * The animation speed.
+         */
+        float animation_speed_;
+
+        /**
+         * The entity's current animation name.
+         */
+        Ogre::String animation_current_name_;
+
+        /**
+         * Entity's animation sync queue.
+         */
+        std::vector<ScriptId> animation_sync_;
+
+        /**
+         * The entity's current animation state.
+         */
+        AnimationState animation_state_;
+
+        /**
+         * The entity's current animation type.
+         */
+        AnimationPlayType animation_play_type_;
+
+        /**
+         * The name of the entity's default name.
+         */
+        Ogre::String animation_default_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float animation_end_time_;
+
+        /**
+         * Indicates if an automation must be played automatically.
+         */
+        bool animation_auto_play_;
+
+    private:
+
+        /**
+         * Constructor.
+         */
+        Entity();
+
+        /**
+         * Calculates the angular distance to an entity.
+         *
+         * @param entity[in] Entity to calculate the angular distance to.
+         * @return Angular distance to the specified entity.
+         */
+        Ogre::Degree GetDirectionToEntity(Entity* entity) const;
+};
 
-#endif // ENTITY_H

+ 47 - 16
QGearsMain/include/core/EntityCollision.h

@@ -1,21 +1,52 @@
-#ifndef ENTITY_COLLISION_H
-#define ENTITY_COLLISION_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreCamera.h>
 #include <OgreSimpleRenderable.h>
 
-
-
-class EntityCollision : public Ogre::SimpleRenderable
-{
-public:
-    EntityCollision();
-    virtual ~EntityCollision();
-
-    Ogre::Real getSquaredViewDepth( const Ogre::Camera* cam ) const;
-    Ogre::Real getBoundingRadius() const;
+/**
+ * An entity collision
+ */
+class EntityCollision : public Ogre::SimpleRenderable{
+
+    public:
+
+        /**
+         * Constructor.
+         */
+        EntityCollision();
+
+        /**
+         * Destructor.
+         */
+        virtual ~EntityCollision();
+
+        /**
+         * Retrieves the view depth, relative to a camera.
+         *
+         * @param camera[in] The camera
+         * @return The squared view depth (always 0).
+         */
+        Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
+
+        /**
+         * Retrieves the bounding radius.
+         *
+         * @return The bounding radius (always 0).
+         */
+        Ogre::Real getBoundingRadius() const;
 };
-
-
-
-#endif // ENTITY_COLLISION_H

+ 47 - 16
QGearsMain/include/core/EntityDirection.h

@@ -1,21 +1,52 @@
-#ifndef ENTITY_DIRECTION_H
-#define ENTITY_DIRECTION_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreCamera.h>
 #include <OgreSimpleRenderable.h>
 
-
-
-class EntityDirection : public Ogre::SimpleRenderable
-{
-public:
-    EntityDirection();
-    virtual ~EntityDirection();
-
-    Ogre::Real getSquaredViewDepth( const Ogre::Camera* cam ) const;
-    Ogre::Real getBoundingRadius() const;
+/**
+ * An entity direction.
+ */
+class EntityDirection : public Ogre::SimpleRenderable{
+
+    public:
+
+        /**
+         * Constructor.
+         */
+        EntityDirection();
+
+        /**
+         * Destructor.
+         */
+        virtual ~EntityDirection();
+
+        /**
+         * Retrieves the view depth, relative to a camera.
+         *
+         * @param camera[in] The camera
+         * @return The squared view depth (always 0).
+         */
+        Ogre::Real getSquaredViewDepth(const Ogre::Camera* cam) const;
+
+        /**
+         * Retrieves the bounding radius.
+         *
+         * @return The bounding radius (always 0).
+         */
+        Ogre::Real getBoundingRadius() const;
 };
-
-
-
-#endif // ENTITY_DIRECTION_H

+ 468 - 121
QGearsMain/include/core/EntityManager.h

@@ -1,8 +1,21 @@
-#ifndef ENTITY_MANAGER_H
-#define ENTITY_MANAGER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreSingleton.h>
+#pragma once
 
+#include <OgreSingleton.h>
 #include "Background2D.h"
 #include "Entity.h"
 #include "EntityPoint.h"
@@ -10,126 +23,460 @@
 #include "Event.h"
 #include "Walkmesh.h"
 
+/**
+ * The entity manager.
+ */
+class EntityManager : public Ogre::Singleton<EntityManager>{
 
+    public:
+        /**
+         * Constructor.
+         */
+        EntityManager();
 
-class EntityManager : public Ogre::Singleton< EntityManager >
-{
-public:
-    EntityManager();
-    virtual ~EntityManager();
-
-    void Input(const QGears::Event& event);
-    void Update();
-    void UpdateDebug();
-    void OnResize();
-
-    void Clear();
-
-    void ScriptSetPaused( const bool paused );
-
-    Walkmesh* GetWalkmesh();
-    Background2D* GetBackground2D();
-    void AddEntity( const Ogre::String& name, const Ogre::String& file_name, const Ogre::Vector3& position, const Ogre::Degree& direction );
-    void AddEntity( const Ogre::String& name, const Ogre::String& file_name, const Ogre::Vector3& position, const Ogre::Degree& rotation, const Ogre::Vector3& scale, const Ogre::Quaternion& root_orientation );
-    void ScriptAddEntity( const char* name, const char* file_name, const float x, const float y, const float z, const float direction );
-    void AddEntityTrigger( const Ogre::String& name, const Ogre::Vector3& point1, const Ogre::Vector3& point2, const bool enabled );
-    void AddEntityPoint( const Ogre::String& name, const Ogre::Vector3& position, const float rotation );
-    void AddEntityScript( const Ogre::String& name );
-    void ScriptAddEntityScript( const char* name );
-
-    Entity* GetEntity( const Ogre::String& name ) const;
-    Entity* ScriptGetEntity( const char* name ) const;
-    EntityPoint* ScriptGetEntityPoint( const char* name ) const;
-
-    void ScriptSetPlayerEntity( const char* name );
-    void ScriptUnsetPlayerEntity();
-    void ScriptPlayerLock( const bool lock );
-    void SetPlayerMoveRotation( const Ogre::Radian rotation );
-
-    /**
-     * Checks if random battle encounters are active in the field.
-     *
-     * @return True random battles can occur, false otherwise.
-     */
-    bool GetRandomEncounters();
-
-    /**
-     * Enables or disables random encounters in the field.
-     *
-     * @param active[in] True to enable encounters, false to deactivate
-     * them.
-     */
-    void SetRandomEncounters(bool active);
-
-    /**
-     * Get the encounter rate for the field.
-     *
-     * @return The encounter rate, between 0 and 1 (both included).
-     */
-    float GetEncounterRate();
-
-    /**
-     * Sets the battle encounter rate.
-     *
-     * @param rate[in] The encounter rate (max. 1).
-     */
-    void SetEncounterRate(float rate);
-
-    /**
-     * Starts a battle.
-     *
-     * @TODO
-     * @param formation[in] The enemy formation to fight.
-     * @return True if the battle victory conditions are met, false\
-     * otherwise.
-     */
-    //bool StartBattle(unsigned int formation);
-    void StartBattle(unsigned int formation);
-
-private:
-    // movement
-    bool SetEntityOnWalkmesh( Entity* entity );
-    bool PerformWalkmeshMove( Entity* entity, const float speed );
-    bool WalkmeshBorderCross( Entity* entity, Ogre::Vector3& position, const Ogre::Vector2& move_vector );
-    bool CheckSolidCollisions( Entity* entity, Ogre::Vector3& position );
-    void SetEntityDirectionByVector( Entity* entity, const Ogre::Vector2& vector );
-    void CheckTriggers( Entity* entity, Ogre::Vector3& position );
-    void CheckEntityInteract();
-
-    void SetNextOffsetStep( Entity* entity );
-    void SetNextTurnStep( Entity* entity );
-    void SetNextLinearStep( Entity* entity );
-    void SetNextJumpStep( Entity* entity );
-    void SetNextScrollStep();
-
-private:
-    bool                          m_Paused;
-
-    Walkmesh                      m_Walkmesh;
-    Background2D                  m_Background2D;
-
-    Ogre::String                  m_EntityTableName;
-    std::vector< Entity* >        m_Entity;
-    Entity*                       m_PlayerEntity;
-    Ogre::Vector3                 m_PlayerMove;
-    Ogre::Radian                  m_PlayerMoveRotation;
-    bool                          m_PlayerLock;
-    bool                          m_PlayerRun;
-
-    std::vector< EntityTrigger* > m_EntityTriggers;
-    std::vector< EntityPoint* >   m_EntityPoints;
-    std::vector< Ogre::String >   m_EntityScripts;
-
-    Ogre::SceneNode*              m_SceneNode;
-
-    Ogre::Entity*                 m_Grid;
-    Ogre::Entity*                 m_Axis;
-
-    // TODO battle formations
-    bool random_encounters_;
-    float encounter_rate_;
-};
+        /**
+         * Destructor.
+         */
+        virtual ~EntityManager();
+
+        /**
+         * Handles an input event.
+         *
+         * @param event[in] Event to handle.
+         */
+        void Input(const QGears::Event& event);
+
+        /**
+         * Updates the entities in the manager.
+         */
+        void Update();
+
+        /**
+         * Updates the entities in the manager with debug information.
+         *
+         * It's automatically called from {@see Update}.
+         */
+        void UpdateDebug();
+
+        /**
+         * Handles resizing events
+         */
+        void OnResize();
+
+        /**
+         * Clears the entity manager.
+         */
+        void Clear();
+
+        /**
+         * Pauses or resumes an entity scripts.
+         *
+         * @param paused[in] True to pause, false to resume.
+         * @todo Verify the description.
+         */
+        void ScriptSetPaused(const bool paused);
+
+        /**
+         * Retrieves the walkmesh.
+         *
+         * @return The walkmesh.
+         */
+        Walkmesh* GetWalkmesh();
+
+        /**
+         * Retrieves the 2D background.
+         *
+         * @return The 2D background.
+         */
+        Background2D* GetBackground2D();
+
+        /**
+         * Adds an entity to the manager.
+         *
+         * @param name[in] Entity name.
+         * @param file_name[in] Path to the entity model file.
+         * @param position[in] Entity position in the map.
+         * @param direction[in] Entity face direction.
+         */
+        void AddEntity(
+          const Ogre::String& name, const Ogre::String& file_name,
+          const Ogre::Vector3& position, const Ogre::Degree& direction
+        );
+
+        /**
+         * Adds an entity to the manager.
+         *
+         * @param name[in] Entity name.
+         * @param file_name[in] Path to the entity model file.
+         * @param position[in] Entity position in the map.
+         * @param rotation[in] Entity face direction.
+         * @param scale[in] Entity scale.
+         * @param root_orientation[in] Map orientation.
+         */
+        void AddEntity(
+          const Ogre::String& name, const Ogre::String& file_name,
+          const Ogre::Vector3& position, const Ogre::Degree& rotation,
+          const Ogre::Vector3& scale, const Ogre::Quaternion& root_orientation
+        );
+
+        /**
+         * Adds an entity to the manager.
+         *
+         * @param name[in] Entity name.
+         * @param file_name[in] Path to the entity model file.
+         * @param x[in] X coordinate of the entity position in the map.
+         * @param y[in] Y coordinate of the entity position in the map.
+         * @param z[in] Z coordinate of the entity position in the map.
+         * @param direction[in] Entity face direction.
+         */
+        void ScriptAddEntity(
+          const char* name, const char* file_name,
+          const float x, const float y, const float z, const float direction
+        );
+
+        /**
+         * Adds an entity trigger to the manager.
+         *
+         * A trigger is a line that does something when approached or crossed.
+         *
+         * @param name[in] Entity trigger name.
+         * @param point1[in] One point of the trigger line.
+         * @param point2[in] One point of the trigger line.
+         * @param enabled[in] True to enable the trigger, false to leave it
+         * disabled.
+         */
+        void AddEntityTrigger(
+          const Ogre::String& name, const Ogre::Vector3& point1,
+          const Ogre::Vector3& point2, const bool enabled
+        );
+
+        /**
+         * Adds an entity point to the manager.
+         *
+         * @param name[in] Entity point name.
+         * @param position[in] Entity point position.
+         * @param rotation[in] The point orientation.
+         */
+        void AddEntityPoint(
+          const Ogre::String& name, const Ogre::Vector3& position,
+          const float rotation
+        );
+
+        /**
+         * Adds an entity script to the manager.
+         *
+         * @param name[in] Entity script name.
+         */
+        void AddEntityScript(const Ogre::String& name);
+
+        /**
+         * Adds an entity script to the manager.
+         *
+         * @param name[in] Entity script name.
+         */
+        void ScriptAddEntityScript(const char* name);
+
+        /**
+         * Retrieves an entity by name.
+         *
+         * @param name[in] Name of the entity to retrieve.
+         * @return The entity by the specified name, or nullptr if there is no
+         * one.
+         */
+        Entity* GetEntity(const Ogre::String& name) const;
+
+        /**
+         * Retrieves an entity by name.
+         *
+         * @param name[in] Name of the entity to retrieve.
+         * @return The entity by the specified name, or nullptr if there is no
+         * one.
+         */
+        Entity* ScriptGetEntity(const char* name) const;
+
+        /**
+         * Retrieves an entity point by name.
+         *
+         * @param name[in] Name of the entity point to retrieve.
+         * @return The entity point by the specified name, or nullptr if there
+         * is no one.
+         */
+        EntityPoint* ScriptGetEntityPoint(const char* name) const;
+
+        /**
+         * Sets the playable entity.
+         *
+         * If no entities are found by name, no one will be assigned, the
+         * previous playable entity will remain so, and no warning will be
+         * issued.
+         *
+         * @param name[in] Name of the entity to make playable.
+         */
+        void ScriptSetPlayerEntity(const char* name);
+
+        /**
+         * Unsets any playable entities.
+         */
+        void ScriptUnsetPlayerEntity();
+
+        /**
+         * Locks or unlocks player control of the playable entity.
+         *
+         * @param lock[in] True to lock, false to unlock.
+         */
+        void ScriptPlayerLock(const bool lock);
+
+        /**
+         * Sets the baseline rotation for the player controlled entity.
+         *
+         * @param rotation[in] Baseline rotation.
+         * @todo Verify this description.
+         */
+        void SetPlayerMoveRotation(const Ogre::Radian rotation);
+
+        /**
+         * Checks if random battle encounters are active in the field.
+         *
+         * @return True if random battles can occur, false otherwise.
+         */
+        bool GetRandomEncounters();
+
+        /**
+         * Enables or disables random encounters in the field.
+         *
+         * @param active[in] True to enable encounters, false to deactivate
+         * them.
+         */
+        void SetRandomEncounters(bool active);
+
+        /**
+         * Get the encounter rate for the field.
+         *
+         * @return The encounter rate, between 0 and 1 (both included).
+         */
+        float GetEncounterRate();
+
+        /**
+         * Sets the battle encounter rate.
+         *
+         * @param rate[in] The encounter rate (0-1).
+         */
+        void SetEncounterRate(float rate);
+
+        /**
+         * Starts a battle.
+         *
+         * @param formation[in] The enemy formation to fight.
+         * @return True if the battle victory conditions are met, false
+         * otherwise.
+         * @todo Implement
+         */
+        bool StartBattleForResult(unsigned int formation);
 
+        /**
+         * Starts a battle.
+         *
+         * @param formation[in] The enemy formation to fight.
+         * @todo Implement
+         */
+        void StartBattle(unsigned int formation);
 
+    private:
 
-#endif // ENTITY_MANAGER_H
+        /**
+         * Attaches an entity to the walkmesh.
+         *
+         * It sets the triangle from the entity position coordinates.
+         *
+         * @param entity[in] Entity to attach.
+         * @return True if the entity was assigned to a walkmesh triangle,
+         * false if the entity is not in a triangle.
+         */
+        bool SetEntityOnWalkmesh(Entity* entity);
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param entity[in] Entity to move.
+         * @param speed[in] Movement speed.
+         * @return @todo.
+         */
+        bool PerformWalkmeshMove(Entity* entity, const float speed);
+
+        /**
+         * Cheks if the entity is crossing a walkmesh triangle border.
+         *
+         * @param entity[in] Entity to check.
+         * @param position[in] @todo.
+         * @param move_vector[in] @todo.
+         * @return True if the entity is crossing a triangle border, false
+         * otherwise.
+         */
+        bool WalkmeshBorderCross(
+          Entity* entity, Ogre::Vector3& position,
+          const Ogre::Vector2& move_vector
+        );
+
+        /**
+         * Checks for collisions of the entity with other entities.
+         *
+         * @param entity[in] Entity to check for collisions.
+         * @param position[in] Position of the entity.
+         * @return True if the entity is colliding with another, false
+         * otherwise. If the entity is not solid, always false.
+         */
+        bool CheckSolidCollisions(Entity* entity, Ogre::Vector3& position);
+
+        /**
+         * Sets an entity direction
+         *
+         * @param entity[in] Entity whose direction is to be set.
+         * @param vector[in] Direction vector.
+         */
+        void SetEntityDirectionByVector(
+          Entity* entity, const Ogre::Vector2& vector
+        );
+
+        /**
+         * Checks for entity triggers at a specified location.
+         *
+         * @param entity[in] Entity to check for triggers.
+         * @param position[in] Position of the entity trigger.
+         * @return True if the entity is colliding with another, false
+         * otherwise. If the entity is not solid, always false.
+         */
+        void CheckTriggers(Entity* entity, Ogre::Vector3& position);
+
+        /**
+         * Checks if an entity can be interacted.
+         *
+         * It checks if there are entities that can be interacted with from the
+         * players current position and orientation. If there are, the most
+         * appropriate one is selected and, if it has an on_interact script, it
+         * is run.
+         */
+        void CheckEntityInteract();
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param entity[in] @todo.
+         */
+        void SetNextOffsetStep(Entity* entity);
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param entity[in] @todo.
+         */
+        void SetNextTurnStep(Entity* entity);
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param entity[in] @todo.
+         */
+        void SetNextLinearStep(Entity* entity);
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param entity[in] @todo.
+         */
+        void SetNextJumpStep(Entity* entity);
+
+        /**
+         * @todo Understand and document.
+         */
+        void SetNextScrollStep();
+
+        /**
+         * Indicates if the script execution is paused.
+         */
+        bool paused_;
+
+        /**
+         * The map walkmesh.
+         */
+        Walkmesh walkmesh_;
+
+        /**
+         * The map background
+         */
+        Background2D background_2d_;
+
+        /**
+         * The entity table name.
+         */
+        Ogre::String entity_table_name_;
+
+        /**
+         * The list of entities.
+         */
+        std::vector<Entity*> entity_;
+
+        /**
+         * The player controlled entity.
+         */
+        Entity* player_entity_;
+
+        /**
+         * @todo Understand and document.
+         */
+        Ogre::Vector3 player_move_;
+
+        /**
+         * @todo Understand and document.
+         */
+        Ogre::Radian player_move_rotation_;
+
+        /**
+         * Indicates if player control is locked.
+         */
+        bool player_lock_;
+
+        /**
+         * @todo Understand and document.
+         */
+        bool player_run_;
+
+        /**
+         * List of triggers.
+         */
+        std::vector<EntityTrigger*> entity_triggers_;
+
+        /**
+         * List of points.
+         */
+        std::vector<EntityPoint*> entity_points_;
+
+        /**
+         * List of scripts.
+         */
+        std::vector<Ogre::String> entity_scripts_;
+
+        /**
+         * The scene node.
+         */
+        Ogre::SceneNode* scene_node_;
+
+        /**
+         * @todo Understand and document.
+         */
+        Ogre::Entity* grid_;
+
+        /**
+         * @todo Understand and document.
+         */
+        Ogre::Entity* axis_;
+
+        /**
+         * Indicates if random encounters happen in the map.
+         */
+        bool random_encounters_;
+
+        /**
+         * The encounter rate of the map.
+         */
+        float encounter_rate_;
+};

+ 92 - 22
QGearsMain/include/core/EntityModel.h

@@ -1,35 +1,105 @@
-#ifndef ENTITY_MODEL_H
-#define ENTITY_MODEL_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "Entity.h"
 
+/**
+ * A 3D model for an entity.
+ */
+class EntityModel : public Entity{
 
+    public:
 
-class EntityModel : public Entity
-{
-public:
-                        EntityModel( const Ogre::String& name, const Ogre::String file_name, Ogre::SceneNode* node );
-    virtual             ~EntityModel();
+        /**
+         * Constructor.
+         *
+         * @param name[in] Entity name.
+         * @param file_name[in] File with the model data.
+         * @param node[in] Scene node to attach the model to.
+         */
+        EntityModel(
+          const Ogre::String& name, const Ogre::String file_name,
+          Ogre::SceneNode* node
+        );
+        virtual ~EntityModel();
 
-    virtual void        Update();
+        /**
+         * Updates the model status.
+         */
+        virtual void Update();
 
-    // model related
-    virtual void        SetVisible( const bool visible );
-    virtual bool        IsVisible() const;
+        /**
+         * Toggles the model visibility.
+         *
+         * @param visible[in] True to make the model visible, false to turn it
+         * invisible.
+         */
+        virtual void SetVisible(const bool visible);
 
-    // animation related
-    virtual void        PlayAnimation( const Ogre::String& animation, AnimationState state, AnimationPlayType play_type, const float start, const float end );
-    virtual void        PlayAnimationContinue( const Ogre::String& animation );
-    virtual void        UpdateAnimation( const float delta );
+        /**
+         * Checks the model visibility.
+         *
+         * @return True if the model is visible, false if it's invisible.
+         */
+        virtual bool IsVisible() const;
 
-private:
-    EntityModel();
+        /**
+         * Plays an animation of the model.
+         *
+         * @param animation[in] Name of the animation to play.
+         * @param state[in] Initial state of the animation.
+         * @param play_type[in] Play mode, for single or looped playbacks.
+         * @param start[in] Start point in time of the animation, in seconds.
+         * @param end[in] End point in time of the animation, in seconds.
+         */
+        virtual void PlayAnimation(
+          const Ogre::String& animation, AnimationState state,
+          AnimationPlayType play_type, const float start, const float end
+        );
 
-private:
-    Ogre::Entity* m_Model;
-    Ogre::AnimationState* m_AnimationCurrent;
-};
+        /**
+         * Resumes an animation.
+         *
+         * @param animation[in] The name of the animation to resume.
+         */
+        virtual void PlayAnimationContinue(const Ogre::String& animation);
+
+        /**
+         * Updates the animation.
+         *
+         * @param delta[in] Ellapsed time.
+         */
+        virtual void UpdateAnimation(const float delta);
 
+    private:
 
+        /**
+         * Constructor.
+         */
+        EntityModel();
+
+        /**
+         * The model.
+         */
+        Ogre::Entity* model_;
+
+        /**
+         * The current animation state.
+         */
+        Ogre::AnimationState* animation_current_;
+};
 
-#endif // ENTITY_MODEL_H

+ 93 - 21
QGearsMain/include/core/EntityPoint.h

@@ -1,34 +1,106 @@
-#ifndef ENTITY_POINT_H
-#define ENTITY_POINT_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
+#pragma once
 #include <OgreRoot.h>
 
+/**
+ * An entity point.
+ */
+class EntityPoint{
 
+    public:
 
-class EntityPoint
-{
-public:
-    EntityPoint( const Ogre::String& name );
-    virtual ~EntityPoint();
+        /**
+         * Constructor.
+         *
+         * @param name[in] Name of the entity point.
+         */
+        EntityPoint(const Ogre::String& name);
 
-    void UpdateDebug();
+        /**
+         * Destructor.
+         */
+        virtual ~EntityPoint();
 
-    const Ogre::String& GetName() const;
+        /**
+         * Updates the point state with debug information.
+         */
+        void UpdateDebug();
 
-    void SetPosition( const Ogre::Vector3& point );
-    const Ogre::Vector3& GetPosition() const;
-    void ScriptGetPosition() const;
+        /**
+         * Retrieves the entity point name.
+         *
+         * @return The name of the entity point.
+         */
+        const Ogre::String& GetName() const;
 
-    void SetRotation( const float rotation );
-    float GetRotation() const;
-    float ScriptGetRotation() const;
+        /**
+         * Sets the point position.
+         *
+         * @param point[in] The new point position
+         */
+        void SetPosition(const Ogre::Vector3& point);
 
-protected:
-    Ogre::String m_Name;
-    Ogre::Vector3 m_Position;
-    float m_Rotation;
-};
+        /**
+         * Retrieves the point position.
+         *
+         * @return The point position.
+         */
+        const Ogre::Vector3& GetPosition() const;
+
+        /**
+         * Informs the script manager of the point position.
+         */
+        void ScriptGetPosition() const;
+
+        /**
+         * Sets the point orientation.
+         *
+         * @param rotation[in] The new orientation (0-360).
+         */
+        void SetRotation(const float rotation);
+
+        /**
+         * Retrieves the point orientation.
+         *
+         * @return The point orientation.
+         */
+        float GetRotation() const;
 
+        /**
+         * Retrieves the point orientation.
+         *
+         * @return The point orientation.
+         */
+        float ScriptGetRotation() const;
 
+    protected:
 
-#endif // ENTITY_POINT_H
+        /**
+         * The entity point name.
+         */
+        Ogre::String name_;
+
+        /**
+         * The entity point's position.
+         */
+        Ogre::Vector3 position_;
+
+        /**
+         * The entity point's orientation.
+         */
+        float rotation_;
+};

+ 135 - 37
QGearsMain/include/core/EntityTrigger.h

@@ -1,44 +1,142 @@
-#ifndef ENTITY_TRIGGER_H
-#define ENTITY_TRIGGER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreRoot.h>
 
 class Entity;
 
-
-
-class EntityTrigger
-{
-public:
-    EntityTrigger( const Ogre::String& name );
-    virtual ~EntityTrigger();
-
-    void UpdateDebug();
-
-    const Ogre::String& GetName() const;
-
-    void SetEnabled( const bool enabled );
-    bool IsEnabled() const;
-
-    void AddActivator( Entity* activator );
-    void RemoveActivator( Entity* activator );
-    bool IsActivator( Entity* activator );
-
-    void SetPoints( const Ogre::Vector3& point1, const Ogre::Vector3& point2 );
-    const Ogre::Vector3& GetPoint1() const;
-    const Ogre::Vector3& GetPoint2() const;
-
-protected:
-    Ogre::String m_Name;
-
-    bool m_Enabled;
-
-    std::vector< Entity* > m_Activators;
-
-    Ogre::Vector3 m_Point1;
-    Ogre::Vector3 m_Point2;
+/**
+ * An entity trigger.
+ */
+class EntityTrigger{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param name[in] The trigger name.
+         */
+        EntityTrigger(const Ogre::String& name);
+
+        /**
+         * Destructor.
+         */
+        virtual ~EntityTrigger();
+
+        /**
+         * Updates the trigger state with debug information.
+         */
+        void UpdateDebug();
+
+        /**
+         * Retrieves the trigger name.
+         *
+         * @return The trigger name.
+         */
+        const Ogre::String& GetName() const;
+
+        /**
+         * Enables or disables the trigger.
+         *
+         * When disabled, all the activators are removed.
+         *
+         * @param enabled[in] True to enable the trigger, false to disable it.
+         */
+        void SetEnabled(const bool enabled);
+
+        /**
+         * Checks if the trigger is enabled.
+         *
+         * @return True if it's enabled, false otherwise.
+         */
+        bool IsEnabled() const;
+
+        /**
+         * Adds an activator to the trigger.
+         *
+         * @param activator[in] Trigger activator entity.
+         */
+        void AddActivator(Entity* activator);
+
+        /**
+         * Removes an activator from the trigger.
+         *
+         * @param activator[in] Entity to remove as activator.
+         */
+        void RemoveActivator(Entity* activator);
+
+        /**
+         * Checks if an entity is an activator of the trigger.
+         *
+         * @param activator[in] Entity to test as an activator.
+         * @return True if the entity is an activator, false otherwise.
+         */
+        bool IsActivator(Entity* activator);
+
+        /**
+         * Sets the vertices of the line that acts as the trigger.
+         *
+         * @param point1[in] One of the vertices of the line.
+         * @param point2[in] One of the vertices of the line.
+         */
+        void SetPoints(
+          const Ogre::Vector3& point1, const Ogre::Vector3& point2
+        );
+
+        /**
+         * Retrieves the first vertex of the line that acts as trigger.
+         *
+         * @return The first vertex.
+         */
+        const Ogre::Vector3& GetPoint1() const;
+
+        /**
+         * Retrieves the second vertex of the line that acts as trigger.
+         *
+         * @return The second vertex.
+         */
+        const Ogre::Vector3& GetPoint2() const;
+
+    protected:
+
+        /**
+         * The name of the trigger.
+         */
+        Ogre::String name_;
+
+        /**
+         * Indicates if the trigger is enabled or disabled.
+         */
+        bool enabled_;
+
+        /**
+         * List of activators of the trigger.
+         */
+        std::vector<Entity*> activators_;
+
+        /**
+         * One of the vertices of the trigger line.
+         */
+        Ogre::Vector3 point_1_;
+
+        /**
+         * One of the vertices of the trigger line.
+         */
+        Ogre::Vector3 point_2_;
 };
 
-
-
-#endif // ENTITY_TRIGGER_H

+ 115 - 25
QGearsMain/include/core/Event.h

@@ -1,53 +1,143 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
 #pragma once
 
-// add this include because this is only common file between everything that uses Input fucntion
+// Add this include because this is only common file between everything that
+// uses Input function.
 #include <OIS/OIS.h>
 
+namespace QGears{
+
+    /**
+     * Type of event.
+     */
+    enum EventType{
 
-namespace QGears
-{
-    enum EventType
-    {
+        /**
+         * Null event.
+         */
         ET_NULL = 0,
+
+        /**
+         * A key is pressed.
+         */
         ET_KEY_PRESS,
+
+        /**
+         * A key is being held down.
+         */
         ET_KEY_REPEAT,
-		ET_KEY_REPEAT_WAIT,
+
+        /**
+         * @todo Understand and document.
+         */
+        ET_KEY_REPEAT_WAIT,
+
+        /**
+         * @todo Understand and document.
+         */
         ET_KEY_IMPULSE,
+
+        /**
+         * A key is released.
+         */
         ET_KEY_RELEASE,
+
+        /**
+         * A mouse button is pressed.
+         */
         ET_MOUSE_PRESS,
+
+        /**
+         * A mouse button is released.
+         */
         ET_MOUSE_RELEASE,
+
+        /**
+         * The mouse has moved.
+         */
         ET_MOUSE_MOVE,
+
+        /**
+         * The mouse has scrolled.
+         */
         ET_MOUSE_SCROLL
     };
 
 
+    /**
+     * An input event.
+     */
+    struct Event{
 
-    struct Event
-    {
-        Event() :
-            type(ET_NULL),
-            param1(0),
-            param2(0)
-        {
-        };
+        /**
+         * Constructor.
+         *
+         * Sets the type to {@see ET_NULL}, and the parameters to 0.
+         */
+        Event():
+          type(ET_NULL),
+          param1(0),
+          param2(0)
+        {};
 
-        Event(EventType n) :
-            type(n),
-            param1(0),
-            param2(0)
-        {
-        };
+        /**
+         * Constructor.
+         *
+         * Sets the parameters to 0.
+         *
+         * @param n[in] The event type.
+         */
+        Event(EventType n):
+          type(n),
+          param1(0),
+          param2(0)
+        {};
 
+        /**
+         * Constructor.
+         *
+         * @param n[in] The event type.
+         * @param p1[in] First parameter.
+         * @param p1[in] Second parameter.
+         */
         Event(EventType n, float p1, float p2) :
-            type(n),
-            param1(p1),
-            param2(p2)
-        {
-        };
+          type(n),
+          param1(p1),
+          param2(p2)
+        {};
 
+        /**
+         * The type of the event.
+         */
         EventType type;
+
+        /**
+         * First event parameter.
+         */
         float param1;
+
+        /**
+         * Second event parameter.
+         */
         float param2;
+
+        /**
+         * Event ID.
+         */
         Ogre::String event;
     };
 }

+ 152 - 0
QGearsMain/include/core/GameFrameListener.h

@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
+
+#include <OgreFrameListener.h>
+#include <OgreRenderWindow.h>
+#include <OgreWindowEventUtilities.h>
+#include <OIS/OIS.h>
+
+/**
+ * The game frame listener.
+ *
+ * Handles the game window and input events.
+ */
+class GameFrameListener :
+  public Ogre::FrameListener, public Ogre::WindowEventListener,
+  public OIS::KeyListener, public OIS::MouseListener
+{
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param win[in] Render window.
+         */
+        GameFrameListener(Ogre::RenderWindow* win);
+
+        /**
+         * Destructor.
+         */
+        virtual ~GameFrameListener();
+
+        /**
+         * Called when a frame is about to begin rendering.
+         *
+         * This event happens before any render targets have begun updating.
+         *
+         * @return True to go ahead, false to abort rendering and drop out of
+         * the rendering loop.
+         */
+        bool frameStarted(const Ogre::FrameEvent& evt);
+
+        /**
+         * Called just after a frame has been rendered.
+         *
+         * This event happens after all render targets have been fully updated
+         * and the buffers switched.
+         *
+         * @return True to continue with the next frame, false to drop out of
+         * the rendering loop.
+         */
+        bool frameEnded(const Ogre::FrameEvent& evt);
+
+        /**
+         * Event triggered when the window moves.
+         *
+         * @param rw[in] The render window.
+         */
+        virtual void windowMoved(Ogre::RenderWindow *rw);
+
+        /**
+         * Event triggered when the window changes it's size.
+         *
+         * @param rw[in] The render window.
+         */
+        virtual void windowResized(Ogre::RenderWindow *rw);
+
+        /**
+         * Event triggered when the window is closed.
+         *
+         * @param rw[in] The render window.
+         */
+        virtual void windowClosed(Ogre::RenderWindow* rw);
+
+        /**
+         * Event triggered when the window losses or gains the focus.
+         *
+         * @param rw[in] The render window.
+         */
+        virtual void windowFocusChange(Ogre::RenderWindow *rw);
+
+        /**
+         * Triggered when a key is pressed.
+         *
+         * @param e[in] Keyboard event.
+         */
+        bool keyPressed(const OIS::KeyEvent& e);
+
+        /**
+         * Triggered when a key is released.
+         *
+         * @param e[in] Keyboard event.
+         */
+        bool keyReleased(const OIS::KeyEvent& e);
+
+        /**
+         * Triggered when the mouse moves.
+         *
+         * @param e[in] Mouse event.
+         */
+        bool mouseMoved(const OIS::MouseEvent &e);
+
+        /**
+         * Triggered when a mouse button is pressed.
+         *
+         * @param e[in] Mouse event.
+         */
+        bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
+
+        /**
+         * Triggered when a mouse button is released.
+         *
+         * @param e[in] Mouse event.
+         */
+        bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id);
+
+    protected:
+
+        /**
+         * The render window.
+         */
+        Ogre::RenderWindow* window_;
+
+        /**
+         * The input manager.
+         */
+        OIS::InputManager*  input_manager_;
+
+        /**
+         * The keyboard.
+         */
+        OIS::Keyboard*      keyboard_;
+
+        /**
+         * The mouse.
+         */
+        OIS::Mouse*         mouse_;
+};
+

+ 0 - 42
QGearsMain/include/core/GameFrameListner.h

@@ -1,42 +0,0 @@
-#ifndef GAME_FRAME_LISTENER_H
-#define GAME_FRAME_LISTENER_H
-
-#include <OgreFrameListener.h>
-#include <OgreRenderWindow.h>
-#include <OgreWindowEventUtilities.h>
-#include <OIS/OIS.h>
-
-
-
-class GameFrameListener : public Ogre::FrameListener, public Ogre::WindowEventListener, public OIS::KeyListener, public OIS::MouseListener
-{
-public:
-                 GameFrameListener( Ogre::RenderWindow* win );
-    virtual     ~GameFrameListener();
-
-    bool         frameStarted( const Ogre::FrameEvent& evt );
-    bool         frameEnded( const Ogre::FrameEvent& evt );
-
-    virtual void windowMoved( Ogre::RenderWindow *rw );
-    virtual void windowResized( Ogre::RenderWindow *rw );
-    virtual void windowClosed( Ogre::RenderWindow* rw );
-    virtual void windowFocusChange( Ogre::RenderWindow *rw );
-
-    bool         keyPressed( const OIS::KeyEvent& e );
-    bool         keyReleased( const OIS::KeyEvent& e );
-
-    bool         mouseMoved( const OIS::MouseEvent &e );
-    bool         mousePressed( const OIS::MouseEvent &e, OIS::MouseButtonID id );
-    bool         mouseReleased( const OIS::MouseEvent &e, OIS::MouseButtonID id );
-
-protected:
-    Ogre::RenderWindow* m_Window;
-
-    OIS::InputManager*  m_InputManager;
-    OIS::Keyboard*      m_Keyboard;
-    OIS::Mouse*         m_Mouse;
-};
-
-
-
-#endif // GAME_FRAME_LISTENER_H

+ 232 - 61
QGearsMain/include/core/InputManager.h

@@ -1,73 +1,244 @@
-#ifndef INPUT_FILTER_H
-#define INPUT_FILTER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreSingleton.h>
 #include <OgreString.h>
 #include <OIS/OIS.h>
 #include <vector>
-
 #include "Event.h"
 
-
-
-typedef std::vector< QGears::Event > InputEventArray;
-typedef std::vector< int > ButtonList;
+typedef std::vector<QGears::Event> InputEventArray;
+typedef std::vector<int> ButtonList;
 
 class ConfigCmd;
 
-class InputManager : public Ogre::Singleton< InputManager >
-{
-public:
-                        InputManager();
-    virtual             ~InputManager();
-
-    void                ButtonPressed( int button, char text, bool down );
-    void                MousePressed( int button, bool down );
-    void                MouseMoved( int x, int y );
-    void                MouseScrolled( int value );
-    void                Reset();
-    void                Update();
-
-    bool                IsButtonPressed( int button ) const;
-
-    void                GetInputEvents( InputEventArray& input_events );
-
-    // binds
-    void                InitCmd();
-    void                BindCommand( ConfigCmd* cmd, const Ogre::StringVector& params, const ButtonList& buttons );
-    void                BindGameEvent( const Ogre::String& event, const ButtonList& buttons );
-    void                ActivateBinds( const int button );
-    void                AddGameEvents( const int button, const QGears::EventType type );
-
-private:
-    bool                    m_ButtonState[ 256 ];
-    char                    m_ButtonText[ 256 ];
-
-    bool                    m_RepeatFirstWait;
-    float                   m_RepeatTimer;
-
-    InputEventArray         m_EventQueue;
-
-    // binds
-    struct BindInfo
-    {
-        BindInfo():
-            cmd( NULL )
-        {}
-
-        ConfigCmd* cmd;
-        Ogre::StringVector params;
-        ButtonList buttons;
-    };
-    std::vector< BindInfo > m_Binds;
-    struct BindGameEventInfo
-    {
-        Ogre::String event;
-        ButtonList buttons;
-    };
-    std::vector< BindGameEventInfo > m_BindGameEvents;
+/**
+ * The input manager.
+ *
+ * It handles input events and creates {@see Event}s.
+ */
+class InputManager : public Ogre::Singleton<InputManager>{
+
+    public:
+
+        /**
+         * Constructor.
+         */
+        InputManager();
+
+        /**
+         * Destructor.
+         */
+        virtual ~InputManager();
+
+        /**
+         * Triggered when a keyboard button is pressed or released.
+         *
+         * Creates an {@Event}.
+         *
+         * @param button[in] Pressed button ID.
+         * @param text[in] @todo The key code? It gets assigned to parameter 1
+         * of the generated event.
+         * @param down[in] True if the button has been pressed, false if it has
+         * been released. It gets assigned to parameter 2 of the event.
+         */
+        void ButtonPressed(int button, char text, bool down);
+
+        /**
+         * Triggered when a mouse button is pressed or released.
+         *
+         * Creates an {@Event}.
+         *
+         * @param button[in] Pressed button ID.
+         * @param down[in] True if the button has been pressed, false if it has
+         * been released. It gets assigned to parameter 1 of the event.
+         */
+        void MousePressed(int button, bool down);
+
+        /**
+         * Triggered when a mouse moves.
+         *
+         * Creates an {@Event}.
+         *
+         * @param x[in] New mouse's X coordinate. It gets assigned to parameter
+         * 1 of the event.
+         * @param y[in] New mouse's Y coordinate. It gets assigned to parameter
+         * 2 of the event.
+         */
+        void MouseMoved(int x, int y);
+
+        /**
+         * Triggered when a mouse scrolls.
+         *
+         * Creates an {@Event}.
+         *
+         * @param value[in] Number of lines scrolled. Positive for scroll down,
+         * negative for scroll up. It gets assigned to parameter 1 of the
+         * event.
+         */
+        void MouseScrolled(int value);
+
+        /**
+         * Resets all keyboard and mouse events to their default state.
+         *
+         * Keyboard and mouse are considered to not pressed, the mouse movement
+         * and scroll are considered 0.
+         */
+        void Reset();
+
+        /**
+         * Update keyboard and mouse buttons, movements and scroll status.
+         */
+        void Update();
+
+        bool IsButtonPressed(int button) const;
+
+        /**
+         * Retrieves the current input events.
+         *
+         * The input event queue will be empty after calling this function.
+         *
+         * @param input_events[out] The current events will be loaded here.
+         */
+        void GetInputEvents(InputEventArray& input_events);
+
+        /**
+         * Initializes all command bindings.
+         */
+        void InitCmd();
+
+        /**
+         * Binds a command to an input event.
+         *
+         * @param cmd[in] Command to bind.
+         * @param params[in] Command arguments.
+         * @param buttons[in] Buttons to bind to the command.
+         */
+        void BindCommand(
+          ConfigCmd* cmd, const Ogre::StringVector& params,
+          const ButtonList& buttons
+        );
+
+        /**
+         * Binds a game event to an input event.
+         *
+         * @param event[in] The game event to bind.
+         * @param buttons[in] Buttons to bind to the event.
+         */
+        void BindGameEvent(
+          const Ogre::String& event, const ButtonList& buttons
+        );
+
+        /**
+         * Activates all bindings for a button.
+         *
+         * @param button[in] ID of the button.
+         */
+        void ActivateBinds(const int button);
+
+        /**
+         * @tdo Understand and document.
+         *
+         * @param button[in] ID of the button.
+         * @param type[in] Event type.
+         */
+        void AddGameEvents(const int button, const QGears::EventType type);
+
+    private:
+
+        /**
+         * The state of eahc button.
+         */
+        bool button_state_[256];
+
+        /**
+         * The text of each button.
+         *
+         * @todo The text is the keycode?
+         */
+        char button_text_[256];
+
+        /**
+         * Indicates if a key holded down is waiting to repeat events.
+         *
+         * @todo Verify this.
+         */
+        bool repeat_first_wait_;
+
+        /**
+         * The time a key has been pressed.
+         */
+        float repeat_timer_;
+
+        /**
+         * The event queue.
+         */
+        InputEventArray event_queue_;
+
+        /**
+         * A command binding.
+         */
+        struct BindInfo{
+
+            /**
+             * Constructor.
+             */
+            BindInfo(): cmd(NULL){}
+
+            /**
+             * The bind command.
+             */
+            ConfigCmd* cmd;
+
+            /**
+             * The command parameters.
+             */
+            Ogre::StringVector params;
+
+            /**
+             * The buttons bond to the command.
+             */
+            ButtonList buttons;
+        };
+
+        /**
+         * List of command bindings.
+         */
+        std::vector<BindInfo> binds_;
+
+        /**
+         * A game event binding
+         */
+        struct BindGameEventInfo{
+
+            /**
+             * The game event.
+             */
+            Ogre::String event;
+
+            /**
+             * The buttons bond to the command.
+             */
+            ButtonList buttons;
+        };
+
+        /**
+         * List of game event bindings.
+         */
+        std::vector<BindGameEventInfo> bind_game_events_;
 };
 
-
-
-#endif // INPUT_FILTER_H

+ 97 - 62
QGearsMain/include/core/InputManagerCommands.h

@@ -1,92 +1,127 @@
-#include <OgreStringConverter.h>
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
+#include <OgreStringConverter.h>
 #include "Console.h"
 #include "ConfigCmdManager.h"
 #include "ConfigVarManager.h"
 #include "Logger.h"
 #include "Utilites.h"
 
-
-
-bool
-ParseKeys( const Ogre::String& string, ButtonList& key_codes )
-{
-    Ogre::StringVector keys = Ogre::StringUtil::split( string, "+" );
-
-    for( unsigned int i = 0; i < keys.size(); ++i )
-    {
-        key_codes.push_back( StringToKey( keys[ i ] ) );
-    }
+/**
+ * Parses a list of keys to retrieve their keycodes.
+ *
+ * @param string[in] Every character in this string will be processed, and the
+ * correspondant keycodes will be added to 'key_codes'.
+ * @param key_codes[out] Every keycode assigned to a character in 'string' will
+ * be added here, even repeated ones.
+ * @return True if there were no errors, false if at least one of the
+ * characters in 'string' doesn't have an associated keycode. Every case wil be
+ * logged.
+ */
+bool ParseKeys(const Ogre::String& string, ButtonList& key_codes){
+    Ogre::StringVector keys = Ogre::StringUtil::split(string, "+");
+
+    for (unsigned int i = 0; i < keys.size(); ++ i)
+        key_codes.push_back(StringToKey(keys[i]));
 
     bool fail = false;
-    for( unsigned int i = 0; i < key_codes.size(); ++i )
-    {
-        if( key_codes[ i ] == OIS::KC_UNASSIGNED )
-        {
-            LOG_ERROR( "Failed to parse key string \"" + string + "\". Can't recognize key " + Ogre::StringConverter::toString( i ) );
+    for (unsigned int i = 0; i < key_codes.size(); ++ i){
+        if (key_codes[i] == OIS::KC_UNASSIGNED){
+            LOG_ERROR(
+              "Failed to parse key string \"" + string
+              + "\". Can't recognize key " + Ogre::StringConverter::toString(i)
+            );
             fail = true;
         }
     }
-
     return fail;
 }
 
-
-
-void
-CmdBind( const Ogre::StringVector& params )
-{
-    if( params.size() != 3 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /bind <key1>+[key2]+[key3] \"<command line>\"" );
+/**
+ * Binds a key combination to a command.
+ *
+ * @param params[in] Binding parameters. Exactly three are required. The first
+ * one is the binding command name and it's not evaluated here. The second one
+ * must be one or more keycodes. The third one is the command string. If more
+ * or less than three parameter are passed, a usage string will be printed
+ * instead, and nothing will be done.
+ * @todo How are keycodes separated? spaces or '+'?
+ */
+void CmdBind(const Ogre::StringVector& params){
+    if (params.size() != 3){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /bind <key1>+[key2]+[key3] \"<command line>\""
+        );
         return;
     }
-
     ButtonList key_codes;
-
-    if( ParseKeys( params[ 1 ], key_codes ) == false )
-    {
-        Ogre::StringVector params_cmd = StringTokenise( params[ 2 ] );
-
-        // handle command
-        ConfigCmd* cmd = ConfigCmdManager::getSingleton().Find( params_cmd[ 0 ] );
-        if( cmd != NULL )
-        {
-            InputManager::getSingleton().BindCommand( cmd, params_cmd, key_codes );
-            LOG_TRIVIAL( "Bind \"" + params[ 1 ] + "\" to command \"" + params[ 2 ] + "\"." );
+    if (ParseKeys(params[1], key_codes) == false){
+        Ogre::StringVector params_cmd = StringTokenise(params[2]);
+
+        // Handle command
+        ConfigCmd* cmd = ConfigCmdManager::getSingleton().Find(params_cmd[0]);
+        if (cmd != NULL){
+            InputManager::getSingleton().BindCommand(
+              cmd, params_cmd, key_codes
+            );
+            LOG_TRIVIAL(
+              "Bind \"" + params[1] + "\" to command \"" + params[2] + "\"."
+            );
         }
-        else
-        {
-            LOG_ERROR( "Can't find command \"" + params_cmd[ 0 ] + "\" in bind command \"" + params[ 2 ] + "\"." );
+        else{
+            LOG_ERROR(
+              "Can't find command \"" + params_cmd[0]
+              + "\" in bind command \"" + params[2] + "\"."
+            );
         }
     }
 }
 
-
-
-void
-CmdBindGameEvent( const Ogre::StringVector& params )
-{
-    if( params.size() != 3 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /game_bind <key1>+[key2]+[key3] \"<game event>\"" );
+/**
+ * Binds a key combination to a game event.
+ *
+ * @param params[in] Binding parameters. Exactly three are required. The first
+ * one is the binding command name and it's not evaluated here. The second one
+ * must be one or more keycodes. The third one is the game event string. If
+ * more or less than three parameter are passed, a usage string will be printed
+ * instead, and nothing will be done.
+ * @todo How are keycodes separated? spaces or '+'?
+ */
+void CmdBindGameEvent(const Ogre::StringVector& params){
+    if (params.size() != 3){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /game_bind <key1>+[key2]+[key3] \"<game event>\""
+        );
         return;
     }
-
     ButtonList key_codes;
-
-    if( ParseKeys( params[ 1 ], key_codes ) == false )
-    {
-        InputManager::getSingleton().BindGameEvent( params[ 2 ], key_codes );
-        LOG_TRIVIAL( "Bind \"" + params[ 1 ] + "\" to game event \"" + params[ 2 ] + "\"." );
+    if (ParseKeys(params[1], key_codes) == false){
+        InputManager::getSingleton().BindGameEvent(params[2], key_codes);
+        LOG_TRIVIAL(
+          "Bind \"" + params[1] + "\" to game event \"" + params[2] + "\"."
+        );
     }
 }
 
-
-
-void
-InputManager::InitCmd()
-{
-    ConfigCmdManager::getSingleton().AddCommand( "bind", "Bind command to keys", "", CmdBind, NULL );
-    ConfigCmdManager::getSingleton().AddCommand( "bind_game_event", "Bind game event to keys", "", CmdBindGameEvent, NULL );
+// TODO: Move this to InpuManager.cpp?
+void InputManager::InitCmd(){
+    ConfigCmdManager::getSingleton().AddCommand(
+      "bind", "Bind command to keys", "", CmdBind, NULL
+    );
+    ConfigCmdManager::getSingleton().AddCommand(
+      "bind_game_event", "Bind game event to keys", "", CmdBindGameEvent, NULL
+    );
 }

+ 105 - 12
QGearsMain/include/core/Logger.h

@@ -1,23 +1,116 @@
-#ifndef LOGGER_H
-#define LOGGER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreLogManager.h>
 #include <OgreString.h>
 #include <OgreStringConverter.h>
 #include <string>
 
+/**
+ * Prints an error log message.
+ *
+ * @param message[in] Message to print.
+ */
+#define LOG_ERROR(message) Ogre::LogManager::getSingleton().logMessage( \
+  "[ERROR] " + Ogre::String(__FILE__) + " " \
+  + Ogre::StringConverter::toString(__LINE__) + ": " + message, \
+  Ogre::LML_CRITICAL \
+)
+
+/**
+ * Prints  awarning log message.
+ *
+ * @param message[in] Message to print.
+ */
+#define LOG_WARNING(message) Ogre::LogManager::getSingleton().logMessage( \
+  "[WARNING] " + Ogre::String(__FILE__) + " " \
+  + Ogre::StringConverter::toString(__LINE__) + ": " + message, \
+  Ogre::LML_NORMAL \
+)
 
-#define LOG_ERROR( message ) Ogre::LogManager::getSingleton().logMessage( "[ERROR] " + Ogre::String( __FILE__ ) + " " + Ogre::StringConverter::toString( __LINE__ ) + ": " + message, Ogre::LML_CRITICAL )
-#define LOG_WARNING( message ) Ogre::LogManager::getSingleton().logMessage( "[WARNING] " + Ogre::String( __FILE__ ) + " " + Ogre::StringConverter::toString( __LINE__ ) + ": " + message, Ogre::LML_NORMAL )
-#define LOG_TRIVIAL( message ) Ogre::LogManager::getSingleton().logMessage( message, Ogre::LML_TRIVIAL )
-#define LOG_CONSOLE( message) Ogre::LogManager::getSingleton().logMessage( message, Ogre::LML_NORMAL )
+/**
+ * Prints a trivial log message.
+ *
+ * @param message[in] Message to print.
+ */
+#define LOG_TRIVIAL(message) Ogre::LogManager::getSingleton().logMessage( \
+  message, Ogre::LML_TRIVIAL \
+)
 
+/**
+ * Prints a log message to the console with normal priority.
+ *
+ * @param message[in] Message to print.
+ */
+#define LOG_CONSOLE(message) Ogre::LogManager::getSingleton().logMessage( \
+  message, Ogre::LML_NORMAL \
+)
+
+// TODO: Remove microsoft tools and leave only the generic?
 #ifdef _MSC_VER
-#define LOG_DEBUG_EX( message ) Ogre::LogManager::getSingleton().logMessage( "[DEBUG] (" +  __FILE__ + " " + Ogre::StringConverter::toString( __LINE__ ) + ")(" + std::string( __FUNCTION__ ) + "): " + message, Ogre::LML_CRITICAL )
-#define LOG_DEBUG( message ) Ogre::LogManager::getSingleton().logMessage( "[DEBUG] (" + std::string( __FUNCTION__ ) + "): " + message, Ogre::LML_CRITICAL )
+
+/**
+ * Prints an explicit debug message to the log (Microsoft only).
+ *
+ * It includes the filename, line, and function name. The priority is critical
+ *
+ * @param message[in] Message to print.
+ */
+#define LOG_DEBUG_EX(message) Ogre::LogManager::getSingleton().logMessage( \
+  "[DEBUG] (" +  __FILE__ + " " + Ogre::StringConverter::toString(__LINE__) \
+  + ")(" + std::string(__FUNCTION__) + "): " + message, \
+  Ogre::LML_CRITICAL \
+  )
+
+/**
+ * Prints a debug message to the log (Microsoft only).
+ *
+ * It includes the function name. The priority is critical
+ *
+ * @param message[in] Message to print.
+ */
+#define LOG_DEBUG(message) Ogre::LogManager::getSingleton().logMessage(\
+  "[DEBUG] (" + std::string(__FUNCTION__) + "): " + message, \
+  Ogre::LML_CRITICAL \
+)
 #else
-#define LOG_DEBUG_EX( message ) Ogre::LogManager::getSingleton().logMessage( "[DEBUG] (" +  __FILE__ + " " + Ogre::StringConverter::toString( __LINE__ ) + ")(" + std::string( __PRETTY_FUNCTION__ ) + "): " + message, Ogre::LML_CRITICAL )
-#define LOG_DEBUG( message ) Ogre::LogManager::getSingleton().logMessage( "[DEBUG] (" + std::string( __PRETTY_FUNCTION__ ) + "): " + message, Ogre::LML_CRITICAL )
-#endif
 
-#endif // LOGGER_H
+/**
+ * Prints an explicit debug message to the log.
+ *
+ * It includes the filename, line, and function name. The priority is critical
+ *
+ * @param message[in] Message to print.
+ */
+#define LOG_DEBUG_EX(message) Ogre::LogManager::getSingleton().logMessage( \
+  "[DEBUG] (" +  __FILE__ + " " + Ogre::StringConverter::toString(__LINE__) \
+  + ")(" + std::string(__PRETTY_FUNCTION__) + "): " + message, \
+  Ogre::LML_CRITICAL \
+)
+
+/**
+ * Prints a debug message to the log.
+ *
+ * It includes the function name. The priority is critical
+ *
+ * @param message[in] Message to print.
+ */
+#define LOG_DEBUG(message) Ogre::LogManager::getSingleton().logMessage( \
+  "[DEBUG] (" + std::string(__PRETTY_FUNCTION__) + "): " + message, \
+  Ogre::LML_CRITICAL \
+)
+#endif

+ 74 - 17
QGearsMain/include/core/Module.h

@@ -1,37 +1,94 @@
-#ifndef MODULE_H
-#define MODULE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OIS/OIS.h>
 #include "Event.h"
 
+/**
+ * Possible states of a module.
+ */
+enum MODULE_STATE{
 
-
-enum MODULE_STATE
-{
+    /**
+     * The module is starting.
+     */
     MODULE_START,
+
+    /**
+     * The module is running.
+     */
     MODULE_RUN,
+
+    /**
+     * The module has finished running.
+     */
     MODULE_FINISH,
+
+    /**
+     * The module is stopped.
+     */
     MODULE_STOP,
+
+    /**
+     * The module is paused.
+     */
     MODULE_PAUSE
 };
 
+/**
+ * A game module
+ */
+class Module {
 
+    public:
 
-class Module
-{
-public:
-    virtual ~Module(){};
+        /**
+         * Destructor.
+         */
+        virtual ~Module(){}
 
-    virtual void Input(const Event& event) = 0;
-    virtual void Update() = 0;
+        /**
+         * Handles an input event.
+         */
+        virtual void Input(const Event& event) = 0;
 
-    void SetState(const MODULE_STATE state) {m_State = state;};
-    const MODULE_STATE GetState() const {return m_State;};
+        /**
+         * Updates the module state.
+         */
+        virtual void Update() = 0;
 
-private:
-    MODULE_STATE m_State;
-};
+        /**
+         * Sets the module state.
+         *
+         * @param state[in] Module's new state.
+         */
+        void SetState(const MODULE_STATE state){state_ = state;}
 
+        /**
+         * Retrieves the module state.
+         *
+         * @return The module's current state.
+         */
+        const MODULE_STATE GetState() const {return state_;}
 
+    private:
 
-#endif // MODULE_H
+        /**
+         * The current module state.
+         */
+        MODULE_STATE state_;
+};

+ 417 - 85
QGearsMain/include/core/ScriptManager.h

@@ -1,128 +1,460 @@
-#ifndef SCRIPT_MANAGER_H
-#define SCRIPT_MANAGER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreSingleton.h>
 #include <OgreString.h>
-
 #include "Event.h"
 #include "LuaIncludes.h"
 
 class Entity;
 
-struct ScriptId
-{
-    ScriptId(): entity( "" ), function( "" ){}
+/**
+ * Script identifier.
+ */
+struct ScriptId{
+
+    /**
+     * Constructor.
+     */
+    ScriptId(): entity(""), function(""){}
 
+    /**
+     * Entity name.
+     */
     Ogre::String entity;
+
+    /**
+     * Function (script) name.
+     */
     Ogre::String function;
 };
 
-
-
+/**
+ * A script entity.
+ */
 struct ScriptEntity;
 
+/**
+ * A script queue.
+ */
+struct QueueScript{
 
-
-struct QueueScript
-{
+    /**
+     * Constructor.
+     */
     QueueScript():
-        function( "" ),
-        argument1( "" ),
-        argument2( "" ),
-        priority( 0 ),
-        state( NULL ),
-        seconds_to_wait( 0 ),
-        wait( false ),
-        yield( false )
+      function(""),
+      argument1(""),
+      argument2(""),
+      priority(0),
+      state(NULL),
+      seconds_to_wait(0),
+      wait(false),
+      yield(false)
     {}
 
+    /**
+     * Function name.
+     */
     Ogre::String function;
-    Ogre::String argument1;
-    Ogre::String argument2;
-    int priority;
-    lua_State* state;
-    int state_id; // for storing and deleating thread
-    float seconds_to_wait;
-    bool wait;
-    bool yield;
-    ScriptId paused_script_start; // script paused by call of this script.
-    ScriptId paused_script_end; // script paused by call of this script.
-};
-
-
 
-class ScriptManager : public Ogre::Singleton< ScriptManager >
-{
-public:
-    enum Type
-    {
-        SYSTEM,
-        ENTITY,
-        UI,
-        FIELD
-    };
+    /**
+     * First function argument.
+     */
+    Ogre::String argument1;
 
-    ScriptManager();
-    virtual ~ScriptManager();
+    /**
+     * Second function argument.
+     */
+    Ogre::String argument2;
 
-    void Input(const QGears::Event& event);
-    void Update( const Type type );
+    /**
+     * Function priority.
+     */
+    int priority;
 
-    void RunString( const Ogre::String& lua );
-    void RunFile( const Ogre::String& file );
+    /**
+     * Current state.
+     */
+    lua_State* state;
 
-    // binds
-    void InitBinds();
-    void InitCmd();
+    /**
+     * State thread identifier.
+     *
+     * Used to store and delete thread.
+     */
+    int state_id;
 
-    void AddEntity( const Type type, const Ogre::String& entity_name, Entity* entity );
-    void RemoveEntity( const Type type, const Ogre::String& entity_name );
-    void AddEntityScript( const Ogre::String& entity_name, const Ogre::String& function_name, int priority );
-    void RemoveEntityTopScript( ScriptEntity& entity );
+    /**
+     * Seconds to wait for completion.
+     */
+    float seconds_to_wait;
 
-    luabind::object GetTableByEntityName( const ScriptManager::Type type, const Ogre::String& name, lua_State* state ) const;
-    QueueScript* GetScriptByScriptId( const ScriptId& script ) const;
-    ScriptEntity* GetScriptEntityByName( const Type type, const Ogre::String& entity_name ) const;
-    const ScriptId GetCurrentScriptId() const;
-    void ContinueScriptExecution( const ScriptId& script );
+    /**
+     * Indicates if the script completion should be waited for,
+     */
+    bool wait;
 
-    int ScriptWait( const float seconds );
-    void ScriptRequest( const Type type, const char* entity, const char* function, const int priority );
-    int ScriptRequestStartSync( const Type type, const char* entity, const char* function, const int priority );
-    int ScriptRequestEndSync( const Type type, const char* entity, const char* function, const int priority );
-    bool ScriptRequest( ScriptEntity* script_entity, const Ogre::String& function, const int priority, const Ogre::String& argument1, const Ogre::String& argument2, bool start_sync, bool end_sync );
+    /**
+     * @todo Understand and document.
+     */
+    bool yield;
 
-    void AddValueToStack( const float value );
+    /**
+     * The script paused by call of this script
+     */
+    ScriptId paused_script_start;
 
-private:
-    lua_State* m_LuaState;
+    /**
+     * The script paused by call of this script
+     */
+    ScriptId paused_script_end;
+};
 
-    Ogre::String m_SystemTableName;
-    Ogre::String m_EntityTableName;
-    Ogre::String m_UiTableName;
 
-    std::vector< ScriptEntity > m_ScriptEntity;
 
-    ScriptId m_CurrentScriptId;
+class ScriptManager : public Ogre::Singleton<ScriptManager>{
+
+    public:
+
+        /**
+         * Script types.
+         */
+        enum Type{
+
+            /**
+             * System script.
+             *
+             * The script is triggered by a system event.
+             */
+            SYSTEM,
+
+            /**
+             * A field entity script.
+             *
+             * The script belongs to any of the enities on a map.
+             */
+            ENTITY,
+
+            /**
+             * A UI element script.
+             *
+             * The script is triggered by a UI element (menu, cursor...)
+             */
+            UI,
+
+            /**
+             * A field script.
+             *
+             * The script ios triggered by the map itself
+             */
+            FIELD
+        };
+
+        /**
+         * Constructor.
+         */
+        ScriptManager();
+
+        /**
+         * Destructor.
+         */
+        virtual ~ScriptManager();
+
+        /**
+         * Handles an input event.
+         *
+         * @param event[in] The event to handle.
+         */
+        void Input(const QGears::Event& event);
+
+        /**
+         * Updates the state of all scripts of a given type.
+         *
+         * @param type[in] Type of the scripts to update.
+         */
+        void Update(const Type type);
+
+        /**
+         * Runs a lua command string.
+         *
+         * No errors are handled, and nothing is returned
+         *
+         * @param lua[in] Lua string to run.
+         */
+        void RunString(const Ogre::String& lua);
+
+        /**
+         * Runs a lua file.
+         *
+         * No errors are handled, and nothing is returned
+         *
+         * @param file[in] Path to the lua file to run (relative to the
+         * data directory).
+         */
+        void RunFile(const Ogre::String& file);
+
+        /**
+         * Initializes Lua binds.
+         *
+         * It relates the command available in the field maps to C++ functions.
+         */
+        void InitBinds();
+
+        /**
+         * Initializes command bindings
+         */
+        void InitCmd();
+
+        /**
+         * Adds an entity to the manager.
+         *
+         * @param type[in] Type of entity to add.
+         * @param entity_name[in] The entity name.
+         * @param entity[in] The entity to add.
+         */
+        void AddEntity(
+          const Type type, const Ogre::String& entity_name, Entity* entity
+        );
+
+        /**
+         * Deletes an entity from the manager.
+         *
+         * If there is no entity with name ENTITY_NAME and type TYPE, nothing
+         * will be done.
+         *
+         * @param type[in] Type of the entity to remove.
+         * @param entity_name[in] NAme of the entity to remove.
+         */
+        void RemoveEntity(const Type type, const Ogre::String& entity_name);
+
+        /**
+         * Adds an script to an entity.
+         *
+         * @param entity_name[in] Name of the entity to add a script to.
+         * @param function_name[in] Name of the script to add.
+         * @param priority[in] Script priority. Lower numbers have higher
+         * priority.
+         */
+        void AddEntityScript(
+          const Ogre::String& entity_name, const Ogre::String& function_name,
+          int priority
+        );
+
+        /**
+         * Removes the top script of an entity.
+         *
+         * @param entiry[in] Enthity whose first script to remove.
+         */
+        void RemoveEntityTopScript(ScriptEntity& entity);
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param type[in] Type of script.
+         * @param name[in] Script name.
+         * @param state[in] Initial script state.
+         * @return @todo.
+         */
+        luabind::object GetTableByEntityName(
+          const ScriptManager::Type type, const Ogre::String& name,
+          lua_State* state
+        ) const;
+
+        /**
+         * Retrieves a script from it's ID.
+         *
+         * @param script[in] Script ID.
+         * @return The script with the corresponding ID, or nullptr if there is
+         * none
+         */
+        QueueScript* GetScriptByScriptId(const ScriptId& script) const;
+
+        /**
+         * Retrieves a script entity by it's name and type.
+         *
+         * @param type[in] Entity type.
+         * @param entity_name[in] The entity name.
+         * @return The entity by that type and name, or nullptr if there is
+         * no one that matches.
+         */
+        ScriptEntity* GetScriptEntityByName(
+          const Type type, const Ogre::String& entity_name
+        ) const;
+
+        /**
+         * Retrieves the current script ID.
+         *
+         * @return The currently executing script ID.
+         */
+        const ScriptId GetCurrentScriptId() const;
+
+        /**
+         * continues the execution of a script.
+         *
+         * @param script[in] The ID of the script to resume.
+         */
+        void ContinueScriptExecution(const ScriptId& script);
+
+        /**
+         * Makes an script wait.
+         *
+         * @param seconds[in] Number of seconds to wait.
+         * @todo Does it refer to the current script?
+         */
+        int ScriptWait(const float seconds);
+
+        /**
+         * Request an script execution.
+         *
+         * @param type[in] Script type.
+         * @param entity[in] Entity the scripts belong to.
+         * @param function[in] Name of the function of the selected entity to
+         * execute.
+         * @param priority[in] Execution priority.
+         */
+        void ScriptRequest(
+          const Type type, const char* entity,
+          const char* function, const int priority
+        );
+
+        /**
+         * Request a synchronous script execution to start.
+         *
+         * @param type[in] Script type.
+         * @param entity[in] Entity the scripts belong to.
+         * @param function[in] Name of the function of the selected entity to
+         * execute.
+         * @param priority[in] Execution priority.
+         * @return -1 on success, 1 if the entity or the script don't exist.
+         */
+        int ScriptRequestStartSync(
+          const Type type, const char* entity,
+          const char* function, const int priority);
+
+        /**
+         * Request a synchronous script execution to end.
+         *
+         * @param type[in] Script type.
+         * @param entity[in] Entity the scripts belong to.
+         * @param function[in] Name of the function of the selected entity to
+         * execute.
+         * @param priority[in] Execution priority.
+         * @return -1 if the execution stops or if the script was not running,
+         * 1 if the entity or the script don't exist.
+         */
+        int ScriptRequestEndSync(
+          const Type type, const char* entity,
+          const char* function, const int priority
+        );
+
+        /**
+         * Request a script execution.
+         *
+         * @param script_entity[in] Entity the scripts belong to.
+         * @param function[in] Name of the function of the selected entity to
+         * execute.
+         * @param priority[in] Execution priority.
+         * @param argument1[in] First argument for the script.
+         * @param argument2[in] Second argument for the script.
+         * @param start_sync[in] If true, the script will be started
+         * synchronously.
+         * @param end_sync[in] @todo Understand and document.
+         * @return True on success, false on error (i.e. if the entity or the
+         * script don't exist)
+         */
+        bool ScriptRequest(
+          ScriptEntity* script_entity, const Ogre::String& function,
+          const int priority, const Ogre::String& argument1,
+          const Ogre::String& argument2, bool start_sync, bool end_sync
+        );
+
+        /**
+         * Adds a script to the stack.
+         *
+         * @param value[in] ID of the script to add.
+         * @todo Verify this documentation.
+         */
+        void AddValueToStack(const float value);
+
+    private:
+
+        /**
+         * Lua state.
+         */
+        lua_State* lua_state_;
+
+        /**
+         * The system script table name.
+         */
+        Ogre::String system_table_name_;
+
+        /**
+         * The entity script table name.
+         */
+        Ogre::String entity_table_name_;
+
+        /**
+         * The UI script table name.
+         */
+        Ogre::String ui_table_name_;
+
+        /**
+         * The list of script entities.
+         */
+        std::vector<ScriptEntity> script_entity_;
+
+        /**
+         * The current script ID.
+         */
+        ScriptId current_script_id_;
 };
 
+struct ScriptEntity{
 
-
-struct ScriptEntity
-{
+    /**
+     * Constructor.
+     *
+     *By default, the type is {@see ScriptManager::SYSTEM}.
+     */
     ScriptEntity():
-        name( "" ),
-        type( ScriptManager::SYSTEM ),
-        resort( false )
-    {
-    }
+      name(""),
+      type(ScriptManager::SYSTEM),
+      resort(false)
+    {}
 
+    /**
+     * The script name.
+     */
     Ogre::String name;
+
+    /**
+     * The script type.
+     */
     ScriptManager::Type type;
-    std::vector< QueueScript > queue;
-    bool resort;
-};
 
+    /**
+     * The script queue.
+     */
+    std::vector<QueueScript> queue;
 
+    /**
+     * @todo Understand and document.
+     */
+    bool resort;
+};
 
-#endif // SCRIPT_MANAGER_H

+ 438 - 150
QGearsMain/include/core/ScriptManagerBinds.h

@@ -1,19 +1,16 @@
 /*
- * Q-Gears
- * Copyright (C) 2022 Q-Gears Team
+ * Copyright (C) 2022 The V-Gears Team
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * This file is part of V-Gears
  *
- * This program is distributed in the hope that it will be useful,
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <iostream>
@@ -44,7 +41,7 @@ void ScriptPrint(const char* text){
  * Reads the data for the next map, initializes all it's entities, scripts, etc
  * and loads it.
  *
- * @param text The new map name.
+ * @param text[in] The new map name.
  */
 void ScriptMap(const char* text){
     EntityManager::getSingleton().Clear();
@@ -66,67 +63,164 @@ void ScriptConsole(const char* text){
     Console::getSingleton().ExecuteCommand(text);
 }
 
-/**
- * Initializes the lua command binds
- *
- * It relates the command available in the field maps to C++ functions
- */
 void ScriptManager::InitBinds(){
 
     std::cout << "[INIT BINDS] Begin " << std::endl;
 
     // Global functions.
-    luabind::module(m_LuaState)[
+    luabind::module(lua_state_)[
         luabind::def("print", (void(*)(const char*)) &ScriptPrint),
         luabind::def("map", (void(*)(const char*)) &ScriptMap),
         luabind::def("console", (void(*)(const char*)) &ScriptConsole)
     ];
 
-    std::cout << "[INIT BINDS] 1 " << std::endl;
-
     // Individual entity commands.
-    luabind::module(m_LuaState)[
-        luabind::class_< Entity >("Entity")
-          .def("set_position", (void(Entity::*)(const float, const float, const float)) &Entity::ScriptSetPosition)
-          .def("get_position", (void(Entity::*)()) &Entity::ScriptGetPosition) // return 3 values internaly
-          .def("set_rotation", (void(Entity::*)(const float)) &Entity::ScriptSetRotation)
+    luabind::module(lua_state_)[
+        luabind::class_<Entity>("Entity")
+          .def(
+            "set_position",
+            (void(Entity::*)(const float, const float, const float))
+              &Entity::ScriptSetPosition
+          )
+          // Internally returns 3 values:
+          .def("get_position", (void(Entity::*)()) &Entity::ScriptGetPosition)
+          .def(
+            "set_rotation",
+            (void(Entity::*)(const float)) &Entity::ScriptSetRotation
+          )
           .def("get_rotation", (float(Entity::*)()) &Entity::ScriptGetRotation)
-          .def("set_solid_radius", (void(Entity::*)(const float)) &Entity::SetSolidRadius)
+          .def(
+            "set_solid_radius",
+            (void(Entity::*)(const float)) &Entity::SetSolidRadius
+          )
           .def("get_solid_radius", (float(Entity::*)()) &Entity::GetSolidRadius)
           .def("set_solid", (void(Entity::*)(const bool)) &Entity::SetSolid)
           .def("is_solid", (bool(Entity::*)()) &Entity::IsSolid)
-          .def("set_talk_radius", (void(Entity::*)(const float)) &Entity::SetTalkRadius)
+          .def(
+            "set_talk_radius",
+            (void(Entity::*)(const float)) &Entity::SetTalkRadius
+          )
           .def("get_talk_radius", (float(Entity::*)()) &Entity::GetTalkRadius)
-          // Some old test script use this, its just an alias for SetTalkable
-          .def("set_interactable", (void(Entity::*)(const bool)) &Entity::SetTalkable)
-          .def("set_talkable", (void(Entity::*)(const bool)) &Entity::SetTalkable)
+          // Some old test script use this, its just an alias for SetTalkable:
+          .def(
+            "set_interactable",
+            (void(Entity::*)(const bool)) &Entity::SetTalkable
+          )
+          .def(
+            "set_talkable",
+            (void(Entity::*)(const bool)) &Entity::SetTalkable
+          )
           .def("is_talkable", (bool(Entity::*)()) &Entity::IsTalkable)
           .def("set_visible", (void(Entity::*)(const bool)) &Entity::SetVisible)
           .def("is_visible", (bool(Entity::*)()) &Entity::IsVisible)
-          .def("set_move_auto_speed", (void(Entity::*)(const float)) &Entity::SetMoveAutoSpeed)
-          .def("get_move_auto_speed", (float(Entity::*)()) &Entity::GetMoveAutoSpeed)
-          .def("get_move_triangle_id", (int(Entity::*)()) &Entity::GetMoveTriangleId)
-          .def("move_auto_rotation", (void(Entity::*)(const bool)) &Entity::SetMoveAutoRotation)
-          .def("move_auto_animation", (void(Entity::*)(const bool)) &Entity::SetMoveAutoAnimation)
-          .def("move_to_position", (void(Entity::*)(const float, const float)) &Entity::ScriptMoveToPosition)
-          .def("move_to_entity", (void(Entity::*)(Entity*)) &Entity::ScriptMoveToEntity)
-          .def("move_sync", (int(Entity::*)()) &Entity::ScriptMoveSync, luabind::yield)
-          .def("linear_to_position", (void(Entity::*)(const float, const float, const float, const LinearMovement, const char*)) &Entity::ScriptLinearToPosition)
-          .def("linear_sync", (int(Entity::*)()) &Entity::ScriptLinearSync, luabind::yield)
-          .def("jump_to_position", (void(Entity::*)(const float, const float, const float, const float))&Entity::ScriptJumpToPosition)
-          .def("jump_sync", (int(Entity::*)()) &Entity::ScriptJumpSync, luabind::yield)
-          .def("offset_to_position", (void(Entity::*)(const float, const float, const float, const ActionType, const float)) &Entity::ScriptOffsetToPosition)
-          .def("offset_sync", (int(Entity::*)()) &Entity::ScriptOffsetSync, luabind::yield)
-          .def("turn_to_entity", (void(Entity::*)(Entity*, const TurnDirection, const float))&Entity::ScriptTurnToEntity)
-          .def("turn_to_direction", (void(Entity::*)(const float, const TurnDirection, const ActionType, const float))&Entity::ScriptTurnToDirection)
-          .def("turn_sync", (int(Entity::*)()) &Entity::ScriptTurnSync, luabind::yield)
-          .def("set_animation_speed", (void(Entity::*)(const float)) &Entity::ScriptSetAnimationSpeed)
-          .def("play_animation", (void(Entity::*)(const char*)) &Entity::ScriptPlayAnimation)
-          .def("play_animation_stop", (void(Entity::*)(const char*)) &Entity::ScriptPlayAnimationStop)
-          .def("play_animation", (void(Entity::*)(const char*, const float, const float)) &Entity::ScriptPlayAnimation)
-          .def("play_animation_stop", (void(Entity::*)(const char*, const float, const float)) &Entity::ScriptPlayAnimationStop)
-          .def("set_default_animation", (void(Entity::*)(const char*)) &Entity::ScriptSetDefaultAnimation)
-          .def("animation_sync", (int(Entity::*)()) &Entity::ScriptAnimationSync, luabind::yield)
+          .def(
+            "set_move_auto_speed",
+            (void(Entity::*)(const float)) &Entity::SetMoveAutoSpeed
+          )
+          .def(
+            "get_move_auto_speed",
+            (float(Entity::*)()) &Entity::GetMoveAutoSpeed
+          )
+          .def(
+            "get_move_triangle_id",
+            (int(Entity::*)()) &Entity::GetMoveTriangleId
+          )
+          .def(
+            "move_auto_rotation",
+            (void(Entity::*)(const bool)) &Entity::SetMoveAutoRotation
+          )
+          .def(
+            "move_auto_animation",
+            (void(Entity::*)(const bool)) &Entity::SetMoveAutoAnimation
+          )
+          .def(
+            "move_to_position",
+            (void(Entity::*)(const float, const float))
+              &Entity::ScriptMoveToPosition
+            )
+          .def(
+            "move_to_entity",
+            (void(Entity::*)(Entity*)) &Entity::ScriptMoveToEntity
+          )
+          .def(
+            "move_sync",
+            (int(Entity::*)()) &Entity::ScriptMoveSync, luabind::yield
+          )
+          .def(
+            "linear_to_position",
+            (void(Entity::*)(
+              const float, const float, const float,
+              const LinearMovement, const char*
+            )) &Entity::ScriptLinearToPosition)
+          .def(
+            "linear_sync",
+            (int(Entity::*)()) &Entity::ScriptLinearSync, luabind::yield
+          )
+          .def(
+            "jump_to_position",
+            (void(Entity::*)(
+               const float, const float, const float, const float
+             ))&Entity::ScriptJumpToPosition
+           )
+          .def(
+            "jump_sync",
+            (int(Entity::*)()) &Entity::ScriptJumpSync, luabind::yield
+          )
+          .def(
+            "offset_to_position",
+            (void(Entity::*)(
+              const float, const float, const float,
+              const ActionType, const float
+            )) &Entity::ScriptOffsetToPosition
+          )
+          .def(
+            "offset_sync",
+            (int(Entity::*)()) &Entity::ScriptOffsetSync, luabind::yield
+          )
+          .def(
+            "turn_to_entity",
+            (void(Entity::*)(Entity*, const TurnDirection, const float))
+              &Entity::ScriptTurnToEntity
+          )
+          .def(
+            "turn_to_direction",
+            (void(Entity::*)(
+               const float, const TurnDirection, const ActionType, const float
+            )) &Entity::ScriptTurnToDirection)
+          .def(
+            "turn_sync",
+            (int(Entity::*)()) &Entity::ScriptTurnSync, luabind::yield
+          )
+          .def(
+            "set_animation_speed",
+            (void(Entity::*)(const float)) &Entity::ScriptSetAnimationSpeed
+          )
+          .def(
+            "play_animation",
+            (void(Entity::*)(const char*)) &Entity::ScriptPlayAnimation
+          )
+          .def(
+            "play_animation_stop",
+            (void(Entity::*)(const char*)) &Entity::ScriptPlayAnimationStop
+          )
+          .def(
+            "play_animation",
+            (void(Entity::*)(const char*, const float, const float))
+              &Entity::ScriptPlayAnimation
+          )
+          .def(
+            "play_animation_stop",
+            (void(Entity::*)(const char*, const float, const float))
+            &Entity::ScriptPlayAnimationStop
+          )
+          .def(
+            "set_default_animation",
+            (void(Entity::*)(const char*)) &Entity::ScriptSetDefaultAnimation
+          )
+          .def(
+            "animation_sync",
+            (int(Entity::*)()) &Entity::ScriptAnimationSync, luabind::yield
+          )
           .enum_("constants")[
              luabind::value("NONE", AT_NONE),
              luabind::value("LINEAR", AT_LINEAR),
@@ -141,51 +235,133 @@ void ScriptManager::InitBinds(){
            ]
     ];
 
-    std::cout << "[INIT BINDS] 1 " << std::endl;
-
     // Field commands.
     // TODO: Duplicated in group EntityManager, this can probably be deleted
-    luabind::module(m_LuaState)[
-        luabind::class_< EntityManager >("Field")
-          .def("random_encounters_on", (float(EntityManager::*)(bool)) &EntityManager::SetRandomEncounters)
-          .def("start_battle", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
+    luabind::module(lua_state_)[
+        luabind::class_<EntityManager>("Field")
+          .def(
+            "random_encounters_on",
+            (float(EntityManager::*)(bool)) &EntityManager::SetRandomEncounters
+          )
+          .def(
+            "start_battle",
+            (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle
+          )
           // TODO: Run? Set battle flags
-          .def("battle_run", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
+          .def(
+            "battle_run",
+            (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle
+          )
     ];
 
     // Entity individual point commands
-    luabind::module(m_LuaState)[
+    luabind::module(lua_state_)[
         luabind::class_< EntityPoint >("EntityPoint")
-          .def("get_position", (void(EntityPoint::*)()) &EntityPoint::ScriptGetPosition) // return 3 values internaly
-          .def("get_rotation", (float(EntityPoint::*)()) &EntityPoint::ScriptGetRotation)
+          .def( // Internally returns 3 values:
+            "get_position",
+            (void(EntityPoint::*)()) &EntityPoint::ScriptGetPosition
+          )
+          .def(
+            "get_rotation",
+            (float(EntityPoint::*)()) &EntityPoint::ScriptGetRotation
+          )
     ];
 
     // Commands for the entity manager, not related to any particular entity.
-    luabind::module(m_LuaState)[
-        luabind::class_< EntityManager >("EntityManager")
-          .def("set_paused", (void(EntityManager::*)(const bool)) &EntityManager::ScriptSetPaused)
-          .def("add_entity", (void(EntityManager::*)(const char*, const char*, const float, const float, const float, const float)) &EntityManager::ScriptAddEntity)
-          .def("add_entity_script", (void(EntityManager::*)(const char*)) &EntityManager::ScriptAddEntityScript)
-          .def("get_entity", (Entity*(EntityManager::*)(const char*)) &EntityManager::ScriptGetEntity)
-          .def("get_entity_point", (EntityPoint*(EntityManager::*)(const char*)) &EntityManager::ScriptGetEntityPoint)
-          .def("set_player_entity", (void(EntityManager::*)(const char*)) &EntityManager::ScriptSetPlayerEntity)
-          .def("unset_player_entity", (void(EntityManager::*)()) &EntityManager::ScriptUnsetPlayerEntity)
-          .def("player_lock", (void(EntityManager::*)(const bool)) &EntityManager::ScriptPlayerLock)
-          .def("random_encounters_on", (float(EntityManager::*)(bool)) &EntityManager::SetRandomEncounters)
-          .def("start_battle", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
+    luabind::module(lua_state_)[
+        luabind::class_<EntityManager>("EntityManager")
+          .def(
+             "set_paused",
+             (void(EntityManager::*)(const bool))
+               &EntityManager::ScriptSetPaused
+          )
+          .def(
+             "add_entity",
+             (void(EntityManager::*)(
+               const char*, const char*, const float,
+               const float, const float, const float
+             )) &EntityManager::ScriptAddEntity
+          )
+          .def(
+             "add_entity_script",
+             (void(EntityManager::*)(const char*))
+               &EntityManager::ScriptAddEntityScript
+          )
+          .def(
+             "get_entity",
+             (Entity*(EntityManager::*)(const char*))
+             &EntityManager::ScriptGetEntity
+          )
+          .def(
+             "get_entity_point",
+             (EntityPoint*(EntityManager::*)(const char*))
+             &EntityManager::ScriptGetEntityPoint
+          )
+          .def(
+             "set_player_entity",
+             (void(EntityManager::*)(const char*))
+               &EntityManager::ScriptSetPlayerEntity
+          )
+          .def(
+            "unset_player_entity",
+            (void(EntityManager::*)()) &EntityManager::ScriptUnsetPlayerEntity
+          )
+          .def(
+            "player_lock",
+            (void(EntityManager::*)(const bool))
+              &EntityManager::ScriptPlayerLock
+          )
+          .def(
+            "random_encounters_on",
+            (float(EntityManager::*)(bool)) &EntityManager::SetRandomEncounters
+          )
+          .def(
+            "start_battle",
+            (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle
+          )
           // TODO: Run? Set battle flags
-          .def("battle_run", (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle)
+          .def(
+            "battle_run",
+            (void(EntityManager::*)(unsigned int)) &EntityManager::StartBattle
+          )
     ];
 
     // 2D background and camera commands
-    luabind::module(m_LuaState)[
-        luabind::class_< Background2D >("Background2D")
-          .def("autoscroll_to_entity", (void(Background2D::*)(Entity*)) &Background2D::ScriptAutoScrollToEntity)
-          .def("scroll_to_position", (void(Background2D::*)(const float, const float, const Background2D::ScrollType, const float)) &Background2D::ScriptScrollToPosition)
-          .def("scroll_sync", (int(Background2D::*)()) &Background2D::ScriptScrollSync, luabind::yield)
-          .def("play_animation_looped", (void(Background2D::*)(const char*)) &Background2D::ScriptPlayAnimationLooped)
-          .def("play_animation_once", (void(Background2D::*)(const char*)) &Background2D::ScriptPlayAnimationOnce)
-          .def("animation_sync", (int(Background2D::*)(const char*)) &Background2D::ScriptAnimationSync, luabind::yield)
+    luabind::module(lua_state_)[
+        luabind::class_<Background2D>("Background2D")
+          .def(
+            "autoscroll_to_entity",
+            (void(Background2D::*)(Entity*))
+              &Background2D::ScriptAutoScrollToEntity
+          )
+          .def(
+            "scroll_to_position",
+            (void(Background2D::*)(
+              const float, const float,
+              const Background2D::ScrollType, const float
+            )) &Background2D::ScriptScrollToPosition
+          )
+          .def(
+            "scroll_sync",
+            (int(Background2D::*)()) &Background2D::ScriptScrollSync,
+            luabind::yield
+          )
+          .def(
+            "play_animation_looped",
+            (void(Background2D::*)(const char*))
+              &Background2D::ScriptPlayAnimationLooped
+          )
+          .def(
+            "play_animation_once",
+            (void(Background2D::*)(const char*))
+              &Background2D::ScriptPlayAnimationOnce
+          )
+          .def(
+            "animation_sync",
+            (int(Background2D::*)(const char*))
+              &Background2D::ScriptAnimationSync,
+            luabind::yield
+          )
           .enum_("constants")[
             luabind::value("NONE", AT_NONE),
             luabind::value("LINEAR", AT_LINEAR),
@@ -194,23 +370,59 @@ void ScriptManager::InitBinds(){
     ];
 
     // Walkmesh commands
-    luabind::module(m_LuaState)[
-        luabind::class_< Walkmesh >("Walkmesh")
-          .def("lock_walkmesh", (void(Walkmesh ::*)(unsigned int, bool)) &Walkmesh ::LockWalkmesh)
-          .def("is_locked", (bool(Walkmesh ::*)(unsigned int)) &Walkmesh ::IsLocked)
+    luabind::module(lua_state_)[
+        luabind::class_<Walkmesh>("Walkmesh")
+          .def(
+            "lock_walkmesh",
+            (void(Walkmesh ::*)(unsigned int, bool)) &Walkmesh ::LockWalkmesh
+          )
+          .def(
+            "is_locked", (bool(Walkmesh ::*)(unsigned int)) &Walkmesh ::IsLocked
+          )
     ];
 
     // Dialog commands
-    luabind::module(m_LuaState)[
-        luabind::class_< DialogsManager >("Dialog")
-          .def("dialog_open", (void(DialogsManager::*)(const char*, int, int, int, int)) &DialogsManager::OpenDialog)
-          .def("dialog_set_text", (void(DialogsManager::*)(const char*, const char*)) &DialogsManager::SetText)
-          .def("dialog_wait_for_close", (int(DialogsManager::*)(const char*)) &DialogsManager::Sync, luabind::yield)
-          .def("dialog_close", (void(DialogsManager::*)(const char*)) &DialogsManager::Hide)
-          .def("set_variable", (void(DialogsManager::*)(const char*, const char*, const char*)) &DialogsManager::SetVariable)
-          .def("set_clickable", (void(DialogsManager::*)(const char*, const bool)) &DialogsManager::SetClickable)
-          .def("set_cursor", (void(DialogsManager::*)(const char*, const int, const int)) &DialogsManager::SetCursor)
-          .def("get_cursor", (int(DialogsManager::*)(const char*)) &DialogsManager::GetCursor)
+    luabind::module(lua_state_)[
+        luabind::class_<DialogsManager>("Dialog")
+          .def(
+            "dialog_open",
+            (void(DialogsManager::*)(const char*, int, int, int, int))
+              &DialogsManager::OpenDialog
+          )
+          .def(
+            "dialog_set_text",
+            (void(DialogsManager::*)(const char*, const char*))
+              &DialogsManager::SetText
+          )
+          .def(
+            "dialog_wait_for_close",
+            (int(DialogsManager::*)(const char*)) &DialogsManager::Sync,
+            luabind::yield
+          )
+          .def(
+            "dialog_close",
+            (void(DialogsManager::*)(const char*)) &DialogsManager::Hide
+          )
+          .def(
+            "set_variable",
+            (void(DialogsManager::*)(const char*, const char*, const char*))
+              &DialogsManager::SetVariable
+          )
+          .def(
+            "set_clickable",
+            (void(DialogsManager::*)(const char*, const bool))
+              &DialogsManager::SetClickable
+          )
+          .def(
+            "set_cursor",
+            (void(DialogsManager::*)(const char*, const int, const int))
+              &DialogsManager::SetCursor
+          )
+          .def(
+            "get_cursor",
+            (int(DialogsManager::*)(const char*))
+              &DialogsManager::GetCursor
+          )
           .enum_("constants")[
             luabind::value("SOLID", MSL_SOLID),
             luabind::value("TRANSPARENT", MSL_TRANSPARENT),
@@ -219,46 +431,121 @@ void ScriptManager::InitBinds(){
     ];
 
     // UI widget commands
-    luabind::module(m_LuaState)[
-        luabind::class_< UiWidget >("UiWidget")
-          .def("set_visible", (void(UiWidget::*)(const bool)) &UiWidget::SetVisible)
-          .def("is_visible", (bool(UiWidget::*)()) &UiWidget::IsVisible)
-          .def("play_animation", (void(UiWidget::*)(const char*)) &UiWidget::ScriptPlayAnimation)
-          .def("play_animation_stop", (void(UiWidget::*)(const char*)) &UiWidget::ScriptPlayAnimationStop)
-          .def("play_animation", (void(UiWidget::*)(const char*, const float, const float)) &UiWidget::ScriptPlayAnimation)
-          .def("play_animation_stop", (void(UiWidget::*)(const char*, const float, const float)) &UiWidget::ScriptPlayAnimationStop)
-          .def("set_default_animation", (void(UiWidget::*)(const char*)) &UiWidget::ScriptSetDefaultAnimation)
-          .def("animation_sync", (int(UiWidget::*)()) &UiWidget::ScriptAnimationSync, luabind::yield)
-          .def("set_colour", (void(UiWidget::*)(const float, const float, const float)) &UiWidget::SetColour)
-          .def("set_alpha", (void(UiWidget::*)(const float)) &UiWidget::SetAlpha)
-          .def("set_x", (void(UiWidget::*)(const float, const float)) &UiWidget::SetX)
-          .def("set_y", (void(UiWidget::*)(const float, const float)) &UiWidget::SetY)
-          .def("set_z", (void(UiWidget::*)(const float)) &UiWidget::SetZ)
-          .def("set_width", (void(UiWidget::*)(const float, const float)) &UiWidget::SetWidth)
-          .def("set_height", (void(UiWidget::*)(const float, const float)) &UiWidget::SetHeight)
+    luabind::module(lua_state_)[
+        luabind::class_<UiWidget>("UiWidget")
+          .def(
+            "set_visible",
+            (void(UiWidget::*)(const bool)) &UiWidget::SetVisible
+          )
+          .def(
+            "is_visible",
+            (bool(UiWidget::*)()) &UiWidget::IsVisible
+          )
+          .def(
+            "play_animation",
+            (void(UiWidget::*)(const char*)) &UiWidget::ScriptPlayAnimation
+          )
+          .def(
+            "play_animation_stop",
+            (void(UiWidget::*)(const char*)) &UiWidget::ScriptPlayAnimationStop
+          )
+          .def(
+            "play_animation",
+            (void(UiWidget::*)(const char*, const float, const float))
+              &UiWidget::ScriptPlayAnimation
+          )
+          .def(
+            "play_animation_stop",
+            (void(UiWidget::*)(const char*, const float, const float))
+            &UiWidget::ScriptPlayAnimationStop
+          )
+          .def(
+            "set_default_animation",
+            (void(UiWidget::*)(const char*))
+              &UiWidget::ScriptSetDefaultAnimation
+          )
+          .def(
+            "animation_sync",
+            (int(UiWidget::*)()) &UiWidget::ScriptAnimationSync, luabind::yield
+          )
+          .def(
+            "set_colour",
+            (void(UiWidget::*)(const float, const float, const float))
+            &UiWidget::SetColour
+          )
+          .def(
+            "set_alpha",
+            (void(UiWidget::*)(const float)) &UiWidget::SetAlpha
+          )
+          .def(
+            "set_x",
+            (void(UiWidget::*)(const float, const float)) &UiWidget::SetX
+          )
+          .def(
+            "set_y", (void(UiWidget::*)(const float, const float))
+            &UiWidget::SetY
+          )
+          .def(
+            "set_z",
+            (void(UiWidget::*)(const float)) &UiWidget::SetZ
+          )
+          .def(
+            "set_width", (void(UiWidget::*)(const float, const float))
+            &UiWidget::SetWidth
+          )
+          .def(
+            "set_height",
+            (void(UiWidget::*)(const float, const float)) &UiWidget::SetHeight
+          )
     ];
 
     // UI manager commands. Use to get a specific widget.
-    luabind::module(m_LuaState)[
-        luabind::class_< UiManager >("UiManager")
-          .def("get_widget", (UiWidget*(UiManager::*)(const char*)) &UiManager::ScriptGetWidget)
+    luabind::module(lua_state_)[
+        luabind::class_<UiManager>("UiManager")
+          .def(
+            "get_widget",
+            (UiWidget*(UiManager::*)(const char*)) &UiManager::ScriptGetWidget
+          )
     ];
 
     // Timer command. To show a in-game timer.
-    luabind::module(m_LuaState)[
-        luabind::class_< Timer >("Timer")
-          .def("get_game_time_total", (float(Timer::*)()) &Timer::GetGameTimeTotal)
+    luabind::module(lua_state_)[
+        luabind::class_<Timer>("Timer")
+          .def(
+            "get_game_time_total", (float(Timer::*)()) &Timer::GetGameTimeTotal
+          )
           .def("set_timer", (float(Timer::*)(const float)) &Timer::SetGameTimer)
           .def("get_timer", (int(Timer::*)()) &Timer::GetGameTimer)
     ];
 
     // Commands that control script execution
-    luabind::module(m_LuaState)[
-        luabind::class_< ScriptManager >("Script")
-          .def("wait", (int(ScriptManager::*)(const float)) &ScriptManager::ScriptWait, luabind::yield)
-          .def("request", (void(ScriptManager::*)(const ScriptManager::Type, const char*, const char*, const int)) &ScriptManager::ScriptRequest)
-          .def("request_start_sync", (int(ScriptManager::*)(const ScriptManager::Type, const char*, const char*, const int)) &ScriptManager::ScriptRequestStartSync, luabind::yield)
-          .def("request_end_sync", (int(ScriptManager::*)(const ScriptManager::Type, const char*, const char*, const int)) &ScriptManager::ScriptRequestEndSync, luabind::yield)
+    luabind::module(lua_state_)[
+        luabind::class_<ScriptManager>("Script")
+          .def(
+            "wait",
+            (int(ScriptManager::*)(const float)) &ScriptManager::ScriptWait,
+            luabind::yield
+          )
+          .def(
+            "request",
+            (void(ScriptManager::*)(
+              const ScriptManager::Type, const char*, const char*, const int
+            )) &ScriptManager::ScriptRequest
+          )
+          .def(
+            "request_start_sync",
+            (int(ScriptManager::*)(
+              const ScriptManager::Type, const char*, const char*, const int
+            )) &ScriptManager::ScriptRequestStartSync,
+            luabind::yield
+          )
+          .def(
+            "request_end_sync",
+            (int(ScriptManager::*)
+              (const ScriptManager::Type, const char*, const char*, const int))
+                &ScriptManager::ScriptRequestEndSync,
+            luabind::yield
+          )
           .enum_("constants")[
             luabind::value("SYSTEM", ScriptManager::SYSTEM),
             luabind::value("ENTITY", ScriptManager::ENTITY),
@@ -267,32 +554,33 @@ void ScriptManager::InitBinds(){
     ];
 
     // Commnds to initiate modules
-    luabind::module(m_LuaState)[
-        luabind::class_< QGears::WorldMapModule >("world_map_module")
-          .def("init", (void(QGears::WorldMapModule::*)()) &QGears::WorldMapModule::Init)
+    luabind::module(lua_state_)[
+        luabind::class_<QGears::WorldMapModule>("world_map_module")
+          .def(
+            "init",
+            (void(QGears::WorldMapModule::*)()) &QGears::WorldMapModule::Init
+          )
     ];
 
-    std::cout << "[INIT BINDS] REGISTER " << std::endl;
-
     // Register all command handlers
     auto a = boost::ref(*(EntityManager::getSingletonPtr()));
-    std::cout << "[INIT BINDS] REGISTER 0" << std::endl;
-    luabind::globals(m_LuaState);
-    std::cout << "[INIT BINDS] REGISTER 0.5" << std::endl;
-    /*auto b = luabind::globals(m_LuaState)["entity_manager"];
-    if (b == NULL){
-        std::cout << "[INIT BINDS] B NULL" << std::endl;
-    }*/
-    std::cout << "[INIT BINDS] REGISTER 0.6" << std::endl;
-    luabind::globals(m_LuaState)["entity_manager"] = boost::ref(*(EntityManager::getSingletonPtr()));
-    std::cout << "[INIT BINDS] REGISTER 1" << std::endl;
-    luabind::globals(m_LuaState)["background2d"] = boost::ref(*(EntityManager::getSingletonPtr()->GetBackground2D()));
-    luabind::globals(m_LuaState)["walkmesh"] = boost::ref(*(EntityManager::getSingletonPtr()->GetWalkmesh()));
-    luabind::globals(m_LuaState)["dialog"] = boost::ref(*(DialogsManager::getSingletonPtr()));
-    luabind::globals(m_LuaState)["ui_manager"] = boost::ref(*(UiManager::getSingletonPtr()));
-    luabind::globals(m_LuaState)["world_map_module"] = boost::ref(*(QGears::WorldMapModule::getSingletonPtr()));
-    luabind::globals(m_LuaState)["timer"] = boost::ref(*(Timer::getSingletonPtr()));
-    luabind::globals(m_LuaState)["script"] = boost::ref(*this);
+    luabind::globals(lua_state_);
+    //auto b = luabind::globals(lua_state_)["entity_manager"];
+    luabind::globals(lua_state_)["entity_manager"]
+      = boost::ref(*(EntityManager::getSingletonPtr()));
+    luabind::globals(lua_state_)["background2d"]
+      = boost::ref(*(EntityManager::getSingletonPtr()->GetBackground2D()));
+    luabind::globals(lua_state_)["walkmesh"]
+      = boost::ref(*(EntityManager::getSingletonPtr()->GetWalkmesh()));
+    luabind::globals(lua_state_)["dialog"]
+      = boost::ref(*(DialogsManager::getSingletonPtr()));
+    luabind::globals(lua_state_)["ui_manager"]
+      = boost::ref(*(UiManager::getSingletonPtr()));
+    luabind::globals(lua_state_)["world_map_module"]
+      = boost::ref(*(QGears::WorldMapModule::getSingletonPtr()));
+    luabind::globals(lua_state_)["timer"]
+      = boost::ref(*(Timer::getSingletonPtr()));
+    luabind::globals(lua_state_)["script"] = boost::ref(*this);
 
     std::cout << "[INIT BINDS] END " << std::endl;
 

+ 50 - 27
QGearsMain/include/core/ScriptManagerCommands.h

@@ -1,39 +1,62 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
 #include "ConfigCmdManager.h"
 #include "Console.h"
 
-
-
-void
-CmdScriptRunString( const Ogre::StringVector& params )
-{
-    if( params.size() < 2 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /script_run_string <string>" );
+/**
+ * Runs a script string.
+ *
+ * @param params[in] Script parameters. Exactly three are required. The first
+ * one is the command name and it's not evaluated here. The second one must be
+ * the line to execute. If less than three parameter are passed, a usage string
+ * will be printed instead, and nothing will be done.
+ */
+void CmdScriptRunString(const Ogre::StringVector& params){
+    if(params.size() < 2){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /script_run_string <string>"
+        );
         return;
     }
-
-    ScriptManager::getSingleton().RunString( params[ 1 ] );
+    ScriptManager::getSingleton().RunString(params[1]);
 }
 
-
-
-void
-CmdScriptRunFile( const Ogre::StringVector& params )
-{
-    if( params.size() < 2 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /script_run_file <file name>" );
+/**
+ * Runs a script string.
+ *
+ * @param params[in] Script parameters. Exactly three are required. The first
+ * one is the command name and it's not evaluated here. The second one must be
+ * the path to the file to execute. If less than three parameter are passed, a
+ * usage string will be printed instead, and nothing will be done.
+ */
+void CmdScriptRunFile(const Ogre::StringVector& params){
+    if(params.size() < 2){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /script_run_file <file name>"
+        );
         return;
     }
-
-    ScriptManager::getSingleton().RunFile( params[ 1 ] );
+    ScriptManager::getSingleton().RunFile(params[1]);
 }
 
-
-
-void
-ScriptManager::InitCmd()
-{
-    ConfigCmdManager::getSingleton().AddCommand( "script_run_string", "Run script string", "", CmdScriptRunString, NULL );
-    ConfigCmdManager::getSingleton().AddCommand( "script_run_file", "Run script file", "", CmdScriptRunFile, NULL );
+void ScriptManager::InitCmd(){
+    ConfigCmdManager::getSingleton().AddCommand(
+      "script_run_string", "Run script string", "", CmdScriptRunString, NULL
+    );
+    ConfigCmdManager::getSingleton().AddCommand(
+      "script_run_file", "Run script file", "", CmdScriptRunFile, NULL
+    );
 }

+ 156 - 39
QGearsMain/include/core/TextManager.h

@@ -1,49 +1,166 @@
-#ifndef TEXT_MANAGER_H
-#define TEXT_MANAGER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreString.h>
 #include <OgreSingleton.h>
-
 #include <tinyxml.h>
 
+/**
+ * The text manager.
+ */
+class TextManager : public Ogre::Singleton<TextManager>{
 
+    public:
 
-class TextManager : public Ogre::Singleton< TextManager >
-{
-public:
-    TextManager();
-    virtual ~TextManager();
-
-    void InitCmd();
-
-    void SetLanguage( const Ogre::String& language );
-    const Ogre::String& GetLanguage();
-    void AddText( const Ogre::String& name, TiXmlNode* node );
-    void AddDialog( const Ogre::String& name, TiXmlNode* node, const float width, const float height );
-    TiXmlNode* GetText( const Ogre::String& name ) const;
-    TiXmlNode* GetDialog( const Ogre::String& name, float &width, float& height ) const;
-    void UnloadTexts();
-
-private:
-    Ogre::String m_Language;
-
-    struct Text
-    {
-        Ogre::String name;
-        TiXmlNode* node;
-    };
-    std::vector< Text > m_Texts;
-
-    struct Dialog
-    {
-        Ogre::String name;
-        TiXmlNode* node;
-        float width;
-        float height;
-    };
-     std::vector< Dialog > m_Dialogs;
-};
+        /**
+         * Constructor.
+         */
+        TextManager();
+
+        /**
+         * Destructor.
+         */
+        virtual ~TextManager();
+
+        /**
+         * Initializes the commands for the text manager.
+         */
+        void InitCmd();
+
+        /**
+         * Sets the language for texts.
+         *
+         * @param language[in] Language identifier. Must be the name of one of
+         * the folders in the data/text/.
+         */
+        void SetLanguage(const Ogre::String& language);
+
+        /**
+         * Retrieves the currently set language.
+         *
+         * @return The current language.
+         */
+        const Ogre::String& GetLanguage();
+
+        /**
+         * Adds text.
+         *
+         * @param name[in] Text name or identifier.
+         * @param node[in] Text node in an XML file.
+         */
+        void AddText(const Ogre::String& name, TiXmlNode* node);
+
+        /**
+         * Adds a text dialog.
+         *
+         * @param name[in] Text name or identifier.
+         * @param node[in] Text node in an XML file.
+         * @param width[in] Text width.
+         * @param height[in] Text height.
+         */
+        void AddDialog(
+          const Ogre::String& name, TiXmlNode* node,
+          const float width, const float height
+        );
+
+        /**
+         * Retrieves a text by name.
+         *
+         * @param name[in] Text name or identifier.
+         * @return Text node in an XML file, or NULL if there is none.
+         */
+        TiXmlNode* GetText(const Ogre::String& name) const;
+
+        /**
+         * Retrieves a dialog and it's dimensions by name.
+         *
+         * @param name[in] Text name or identifier.
+         * @param width[out] The text width will be saved here. It won't change
+         * if the dialog is not found.
+         * @param height[out] The text height will be saved here. It won't
+         * change if the dialog is not found.
+         * @return Text node in an XML file, or NULL if there is none.
+         */
+        TiXmlNode* GetDialog(
+          const Ogre::String& name, float &width, float& height
+        ) const;
+
+        /**
+         * Deletes all texts in the manager.
+         */
+        void UnloadTexts();
 
+    private:
 
+        /**
+         * The language for the texts.
+         */
+        Ogre::String language_;
+
+        /**
+         * A text.
+         */
+        struct Text{
+
+            /**
+             * Name or identifier of the text.
+             */
+            Ogre::String name;
+
+            /**
+             * Text node in an XML file.
+             */
+            TiXmlNode* node;
+        };
+
+        /**
+         * The list of texts in the manager.
+         */
+        std::vector<Text> texts_;
+
+        /**
+         * A dialog.
+         */
+        struct Dialog{
+
+            /**
+             * Name or identifier of the text.
+             */
+            Ogre::String name;
+
+            /**
+             * Text node in an XML file.
+             */
+            TiXmlNode* node;
+
+            /**
+             * The text width.
+             */
+            float width;
+
+            /**
+             * The text height.
+             */
+            float height;
+        };
+
+        /**
+         * The list of dialogs in the manager.
+         */
+        std::vector<Dialog> dialogs_;
+};
 
-#endif // TEXT_MANAGER_H

+ 44 - 23
QGearsMain/include/core/TextManagerCommands.h

@@ -1,36 +1,57 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
 #include "ConfigCmdManager.h"
 #include "Console.h"
 #include "Logger.h"
 #include "XmlTextsFile.h"
 
-
-
-void
-CmdSetLanguage( const Ogre::StringVector& params )
-{
-    if( params.size() < 2 )
-    {
-        Console::getSingleton().AddTextToOutput( "Usage: /set_language <language>" );
+/**
+ * Sets the language for texts.
+ *
+ * @param params[in] Command parameters. Exactly three are required. The first
+ * one is the command name and it's not evaluated here. The second one must be
+ * the language to set. If less than three parameter are passed, a usage string
+ * will be printed instead, and nothing will be done.
+ */
+void CmdSetLanguage(const Ogre::StringVector& params){
+    if (params.size() < 2){
+        Console::getSingleton().AddTextToOutput(
+          "Usage: /set_language <language>"
+        );
         return;
     }
-
-    TextManager::getSingleton().SetLanguage( params[ 1 ] );
-    LOG_TRIVIAL( "Set game language to \"" + params[ 1 ] + "\"." );
+    TextManager::getSingleton().SetLanguage(params[1]);
+    LOG_TRIVIAL("Set game language to \"" + params[1] + "\".");
 }
 
-
-
-void
-CmdSetLanguageCompletition( Ogre::StringVector& complete_params )
-{
+/**
+ * Loads a list of every available language identifiers.
+ *
+ * To do so, it uses the folders in data/texts.
+ *
+ * @param complete_params[out] The list of languages will be saved here.
+ */
+void CmdSetLanguageCompletition(Ogre::StringVector& complete_params){
     XmlTextsFile texts( "./data/texts.xml" );
-    texts.GetAvailableLanguages( complete_params );
+    texts.GetAvailableLanguages(complete_params);
 }
 
-
-
-void
-TextManager::InitCmd()
-{
-    ConfigCmdManager::getSingleton().AddCommand( "set_language", "Change language of texts and dialogs", "", CmdSetLanguage, CmdSetLanguageCompletition );
+void TextManager::InitCmd(){
+    ConfigCmdManager::getSingleton().AddCommand(
+      "set_language", "Change language of texts and dialogs", "",
+      CmdSetLanguage, CmdSetLanguageCompletition
+    );
 }

+ 104 - 21
QGearsMain/include/core/Timer.h

@@ -1,34 +1,117 @@
-#ifndef TIMER_H
-#define TIMER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreSingleton.h>
 
+/**
+ * The game timer.
+ */
+class Timer : public Ogre::Singleton<Timer>{
+    public:
 
+        /**
+         * Constructor.
+         */
+        Timer();
 
-class Timer : public Ogre::Singleton< Timer >
-{
-public:
-    Timer();
+        /**
+         * Retrieves the total system time.
+         *
+         * @return The total system time.
+         * @todo What is the system time? What's the difference with game time?
+         */
+        float GetSystemTimeTotal();
 
-    float GetSystemTimeTotal();
-    float GetSystemTimeDelta();
-    float GetGameTimeTotal();
-    float GetGameTimeDelta();
+        /**
+         * Retrieves the system time difference.
+         *
+         * @return The system time difference.
+         * @todo What is the system time? What's the difference with game time?
+         */
+        float GetSystemTimeDelta();
 
-    void AddTime( const float time );
+        /**
+         * Retrieves the total game time.
+         *
+         * @return The total game time.
+         * @todo What is the game time? What's the difference with system time?
+         */
+        float GetGameTimeTotal();
 
-    void SetGameTimer( const float timer );
-    int GetGameTimer() const;
+        /**
+         * Retrieves the game time difference.
+         *
+         * @return The game time difference.
+         * @todo What is the game time? What's the difference with system time?
+         */
+        float GetGameTimeDelta();
 
-private:
-    float m_SystemTimeTotal;
-    float m_SystemTimeDelta;
-    float m_GameTimeTotal;
-    float m_GameTimeDelta;
+        /**
+         * Adds time to the time.
+         *
+         * It can also be used to subtract time, but it will never get below 0.
+         *
+         * @param time[in] The time to add?
+         * @todo What are the units? seconds?
+         */
+        void AddTime(const float time);
 
-    float m_GameTimer;
-};
+        /**
+         * Sets the game timer.
+         *
+         * @param timer[in] The new game timer.
+         * @todo Understand and document.
+         */
+        void SetGameTimer(const float timer);
+
+        /**
+         * Retrieves the game timer.
+         *
+         * @return The game timer.
+         * @todo What is this timer? Why is it an int, but the setter accepts
+         * float?
+         */
+        int GetGameTimer() const;
+
+    private:
 
+        /**
+         * The total system time.
+         */
+        float system_time_total_;
 
+        /**
+         * The system time difference.
+         */
+        float system_time_delta_;
+
+        /**
+         * The total game time.
+         */
+        float game_time_total_;
+
+        /**
+         * The game time difference.
+         */
+        float game_time_delta_;
+
+        /**
+         * The game timer.
+         */
+        float game_timer_;
+};
 
-#endif // TIMER_H

+ 270 - 65
QGearsMain/include/core/UiAnimation.h

@@ -1,87 +1,292 @@
-#ifndef UI_ANIMATION_H
-#define UI_ANIMATION_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreString.h>
 #include <Ogre.h>
 #include <vector>
 
-
-
 class UiWidget;
 
+/**
+ * A keyframe value.
+ */
+struct UiKeyFrameFloat{
 
-
-struct UiKeyFrameFloat
-{
+    /**
+     * Keyframe time, in seconds.
+     */
     float time;
+
+    /**
+     * Value for the keyframe.
+     */
     float value;
 };
 
+/**
+ * Coordinate keyframe.
+ */
+struct UiKeyFrameVector2{
 
-
-struct UiKeyFrameVector2
-{
+    /**
+     * Keyframe time, in seconds.
+     */
     float time;
+
+    /**
+     * Position for the keyframe.
+     */
     Ogre::Vector2 value;
 };
 
+/**
+ * An UI element animation.
+ */
+class UiAnimation{
 
+    public:
 
-class UiAnimation
-{
-public:
-    UiAnimation( const Ogre::String& name, UiWidget* widget );
-    virtual ~UiAnimation();
-
-    enum State
-    {
-        DEFAULT,
-        ONCE
-    };
-
-    void AddTime( const float time );
-
-    const Ogre::String& GetName() const;
-
-    void SetTime( const float time );
-    float GetTime() const;
-    void SetLength( const float time );
-    float GetLength() const;
-    void AddScaleKeyFrame( const UiKeyFrameVector2& key_frame );
-    void AddXKeyFrame( const UiKeyFrameVector2& key_frame );
-    void AddYKeyFrame( const UiKeyFrameVector2& key_frame );
-    void AddWidthKeyFrame( const UiKeyFrameVector2& key_frame );
-    void AddHeightKeyFrame( const UiKeyFrameVector2& key_frame );
-    void AddRotationKeyFrame( const UiKeyFrameFloat& key_frame );
-    void AddAlphaKeyFrame( const UiKeyFrameFloat& key_frame );
-    void AddScissorKeyFrame( const UiKeyFrameVector2& x1, const UiKeyFrameVector2& y1, const UiKeyFrameVector2& x2, const UiKeyFrameVector2& y2 );
-
-private:
-    UiAnimation();
-
-    float KeyFrameGetValue( std::vector< UiKeyFrameFloat >& data );
-    Ogre::Vector2 KeyFrameGetValue( std::vector< UiKeyFrameVector2 >& data );
-
-    Ogre::String m_Name;
-    UiWidget*    m_Widget;
-
-    float        m_Time;
-    float        m_Length;
-
-    std::vector< UiKeyFrameVector2 > m_Scale;
-    std::vector< UiKeyFrameVector2 > m_X;
-    std::vector< UiKeyFrameVector2 > m_Y;
-    std::vector< UiKeyFrameVector2 > m_Width;
-    std::vector< UiKeyFrameVector2 > m_Height;
-    std::vector< UiKeyFrameFloat >   m_Rotation;
-    std::vector< UiKeyFrameFloat >   m_Alpha;
-
-    std::vector< UiKeyFrameVector2 > m_ScissorXTop;
-    std::vector< UiKeyFrameVector2 > m_ScissorYLeft;
-    std::vector< UiKeyFrameVector2 > m_ScissorXBottom;
-    std::vector< UiKeyFrameVector2 > m_ScissorYRight;
-};
+        /**
+         * Constructor.
+         *
+         * @param name[in] Animation name.
+         * @param widget[in] Widget to animate.
+         */
+        UiAnimation(const Ogre::String& name, UiWidget* widget);
+
+        /**
+         * Destructor.
+         */
+        virtual ~UiAnimation();
+
+        /**
+         * Animation state.
+         */
+        enum State{
+
+            /**
+             * @todo Understand and document.
+             */
+            DEFAULT,
+
+            /**
+             * Animate only once.
+             */
+            ONCE
+        };
+
+        /**
+         * Adds time to the animation and updates it.
+         *
+         * @param time[in] Time to add, in seconds.
+         */
+        void AddTime(const float time);
+
+        /**
+         * Retrieves the animation name.
+         *
+         * @return The animation name.
+         */
+        const Ogre::String& GetName() const;
+
+        /**
+         * Sets the time of the animation and updates it.
+         *
+         * @param time[i] The time of the animation.
+         */
+        void SetTime(const float time);
+
+        /**
+         * Retrieves the animation current time.
+         *
+         * @return The animation current time.
+         */
+        float GetTime() const;
+
+        /**
+         * Sets the animation length.
+         *
+         * @param time[in] The animation length, in seconds.
+         */
+        void SetLength(const float time);
+
+        /**
+         * Retrieves the animation length.
+         *
+         * @return The animation length, in seconds.
+         */
+        float GetLength() const;
+
+        /**
+         * Adds a scale keyframe to the animation.
+         *
+         * @param key_frame[in] The keyframe to add.
+         */
+        void AddScaleKeyFrame(const UiKeyFrameVector2& key_frame);
+
+        /**
+         * Adds a X position keyframe to the animation.
+         *
+         * @param key_frame[in] The keyframe to add.
+         */
+        void AddXKeyFrame(const UiKeyFrameVector2& key_frame);
+
+        /**
+         * Adds a Y position keyframe to the animation.
+         *
+         * @param key_frame[in] The keyframe to add.
+         */
+        void AddYKeyFrame(const UiKeyFrameVector2& key_frame);
+
+        /**
+         * Adds a width keyframe to the animation.
+         *
+         * @param key_frame[in] The keyframe to add.
+         */
+        void AddWidthKeyFrame(const UiKeyFrameVector2& key_frame);
 
+        /**
+         * Adds a height keyframe to the animation.
+         *
+         * @param key_frame[in] The keyframe to add.
+         */
+        void AddHeightKeyFrame(const UiKeyFrameVector2& key_frame);
 
+        /**
+         * Adds a rotation keyframe to the animation.
+         *
+         * @param key_frame[in] The keyframe to add.
+         */
+        void AddRotationKeyFrame(const UiKeyFrameFloat& key_frame);
 
-#endif // UI_ANIMATION_H
+        /**
+         * Adds an alpha keyframe to the animation.
+         *
+         * @param key_frame[in] The keyframe to add.
+         */
+        void AddAlphaKeyFrame(const UiKeyFrameFloat& key_frame);
+
+        /**
+         * Adds an scissor keyframe to the animation.
+         *
+         * @param x1[in] @todo Understand and document.
+         * @param y1[in] @todo Understand and document.
+         * @param x2[in] @todo Understand and document.
+         * @param y2[in] @todo Understand and document.
+         * @todo What is an scissor keyframe?.
+         */
+        void AddScissorKeyFrame(
+          const UiKeyFrameVector2& x1, const UiKeyFrameVector2& y1,
+          const UiKeyFrameVector2& x2, const UiKeyFrameVector2& y2
+        );
+
+    private:
+
+        /**
+         * Constructor.
+         */
+        UiAnimation();
+
+        /**
+         * Gets the value from a @{see UiKeyFrameFloat}.
+         *
+         * @return The value of the keyframe.
+         */
+        float KeyFrameGetValue(std::vector<UiKeyFrameFloat>& data);
+
+        /**
+         * Gets the value from a @{see UiKeyFrameVector2}.
+         *
+         * @return The value of the keyframe.
+         */
+        Ogre::Vector2 KeyFrameGetValue(std::vector<UiKeyFrameVector2>& data);
+
+        /**
+         * The UI animation name.
+         */
+        Ogre::String name_;
+
+        /**
+         * The UI widget.
+         */
+        UiWidget* widget_;
+
+        /**
+         * The animation's current time.
+         */
+        float time_;
+
+        /**
+         * The animation length.
+         */
+        float length_;
+
+        /**
+         * List of scale keyframes.
+         */
+        std::vector<UiKeyFrameVector2> scale_;
+
+        /**
+         * List of X position keyframes.
+         */
+        std::vector<UiKeyFrameVector2> x_;
+
+        /**
+         * List of Y position keyframes.
+         */
+        std::vector<UiKeyFrameVector2> y_;
+
+        /**
+         * List of width keyframes.
+         */
+        std::vector<UiKeyFrameVector2> width_;
+
+        /**
+         * List of height keyframes.
+         */
+        std::vector<UiKeyFrameVector2> height_;
+
+        /**
+         * List of rotation keyframes.
+         */
+        std::vector<UiKeyFrameFloat> rotation_;
+
+        /**
+         * List of alpha keyframes.
+         */
+        std::vector<UiKeyFrameFloat> alpha_;
+
+        /**
+         * @todo Understand and document.
+         */
+        std::vector<UiKeyFrameVector2> scissor_x_top_;
+
+        /**
+         * @todo Understand and document.
+         */
+        std::vector<UiKeyFrameVector2> scissor_y_left_;
+
+        /**
+         * @todo Understand and document.
+         */
+        std::vector<UiKeyFrameVector2> scissor_x_bottom_;
+
+        /**
+         * @todo Understand and document.
+         */
+        std::vector<UiKeyFrameVector2> scissor_y_right_;
+};

+ 183 - 39
QGearsMain/include/core/UiFont.h

@@ -1,54 +1,198 @@
-#ifndef UI_FONT_H
-#define UI_FONT_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreString.h>
 
+/**
+ * Character data for UI elements.
+ */
+struct UiCharData{
 
-
-struct UiCharData
-{
+    /**
+     * The character code.
+     */
     int char_code;
+
+    /**
+     * The character X position in the font image.
+     */
     int x;
+
+    /**
+     * The character Y position in the font image.
+     */
     int y;
+
+    /**
+     * The character width.
+     */
     int width;
+
+    /**
+     * The character height.
+     */
     int height;
+
+    /**
+     * @todo Understand and document.
+     */
     int pre;
+
+    /**
+     * @todo Understand and document.
+     */
     int post;
 };
 
-
-
-class UiFont
-{
-public:
-    UiFont( const Ogre::String& name, const Ogre::String& language );
-    virtual ~UiFont();
-
-    const Ogre::String& GetName() const;
-    const Ogre::String& GetLanguage() const;
-
-    void SetImage( const Ogre::String& image, const int width, const int height );
-    const Ogre::String& GetImageName() const;
-    int GetImageWidth() const;
-    int GetImageHeight() const;
-
-    void SetHeight( const int height );
-    int GetHeight() const;
-
-    void AddCharData( const UiCharData& data );
-    UiCharData GetCharData( const int char_code ) const;
-
-private:
-    Ogre::String              m_Name;
-    Ogre::String              m_Language;
-
-    Ogre::String              m_ImageName;
-    int                       m_ImageWidth;
-    int                       m_ImageHeight;
-    int                       m_Height;
-    std::vector< UiCharData > m_CharData;
+/**
+ * The UI widgets font.
+ */
+class UiFont{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param name[in] The font name.
+         * @param language[in] The font language.
+         */
+        UiFont(const Ogre::String& name, const Ogre::String& language);
+
+        /**
+         * Destructor.
+         */
+        virtual ~UiFont();
+
+        /**
+         * Retrieves the font name.
+         *
+         * @return The font name.
+         */
+        const Ogre::String& GetName() const;
+
+        /**
+         * Retrieves the font language.
+         *
+         * @return The font language.
+         */
+        const Ogre::String& GetLanguage() const;
+
+        /**
+         * Sets an image for the font.
+         *
+         * The image is a character map.
+         *
+         * @param image[in] Path to the font image, relative to data/fonts.
+         * @param width[in] Image width.
+         * @param height[in] Image height.
+         */
+        void SetImage(
+          const Ogre::String& image, const int width, const int height
+        );
+
+        /**
+         * Retrieves the font image file name.
+         *
+         * @return The font image file name.
+         */
+        const Ogre::String& GetImageName() const;
+
+        /**
+         * Retrieves the font image width.
+         *
+         * @return The font image height.
+         */
+        int GetImageWidth() const;
+
+        /**
+         * Retrieves the font image height.
+         *
+         * @return The font image height.
+         */
+        int GetImageHeight() const;
+
+        /**
+         * Sets the character height for the font.
+         *
+         * @param height[in] Character height.
+         */
+        void SetHeight(const int height);
+
+        /**
+         * Retrieves the character height of the font.
+         *
+         * @return The character height.
+         */
+        int GetHeight() const;
+
+        /**
+         * Adds data for a character.
+         *
+         * @param data[in] The character data to add.
+         */
+        void AddCharData(const UiCharData& data);
+
+        /**
+         * Retrieves character data from a char code.
+         *
+         * @param char_code[in] The code of the character to retrieve data
+         * about.
+         * @return Character data associated to the char code. A default {@see
+         * UiCharData} structure wil be returnd if there is no data for the
+         * char code.
+         */
+        UiCharData GetCharData(const int char_code) const;
+
+    private:
+
+        /**
+         * The font name.
+         */
+        Ogre::String name_;
+
+        /**
+         * The font language.
+         */
+        Ogre::String language_;
+
+        /**
+         * The font image file name.
+         */
+        Ogre::String image_name_;
+
+        /**
+         * The font image file width.
+         */
+        int image_width_;
+
+        /**
+         * The font image file height.
+         */
+        int image_height_;
+
+        /**
+         * The height of the font characters.
+         */
+        int height_;
+
+        /**
+         * List of character data for the font.
+         */
+        std::vector<UiCharData> char_data_;
 };
 
-
-
-#endif // UI_FONT_H

+ 145 - 30
QGearsMain/include/core/UiManager.h

@@ -1,50 +1,165 @@
-#ifndef UI_MANAGER_H
-#define UI_MANAGER_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreRenderQueueListener.h>
 #include <OgreSingleton.h>
 #include <OgreUTFString.h>
 #include <tinyxml.h>
-
 #include "UiFont.h"
 #include "UiWidget.h"
 
+/**
+ * The UI manager.
+ */
+class UiManager
+  : public Ogre::RenderQueueListener, public Ogre::Singleton<UiManager>
+{
 
+    public:
 
-class UiManager : public Ogre::RenderQueueListener, public Ogre::Singleton< UiManager >
-{
-public:
-    UiManager();
-    virtual ~UiManager();
+        /**
+         * Constructor.
+         */
+        UiManager();
 
-    void Initialise();
-    void Update();
-    void OnResize();
+        /**
+         * Destructor.
+         */
+        virtual ~UiManager();
 
+        /**
+         * Initializes the manager.
+         *
+         * Loads all available fonts and screens from fonts.xml and
+         * screens.xml, respectably.
+         */
+        void Initialise();
 
-    void AddFont( UiFont* font );
-    UiFont* GetFont( const Ogre::String& name );
+        /**
+         * Updates the UI elements in the manager.
+         */
+        void Update();
 
-    void AddPrototype( const Ogre::String& name, TiXmlNode* prototype );
-    TiXmlNode* GetPrototype( const Ogre::String& name ) const;
+        /**
+         * Handles resizing events.
+         */
+        void OnResize();
 
-    void AddWidget( UiWidget* widget );
-    UiWidget* GetWidget( const Ogre::String& name );
-    UiWidget* ScriptGetWidget( const char* name );
+        /**
+         * Adds a font to the manager.
+         *
+         * @param font[in] The font to add.
+         */
+        void AddFont(UiFont* font);
 
-    void renderQueueStarted( Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& skipThisInvocation );
+        /**
+         * Retrieves a font by name.
+         *
+         * @param name[in] Name of the font.
+         * @return The font by the specified name, or NULL if there is none.
+         */
+        UiFont* GetFont(const Ogre::String& name);
 
-private:
-    std::vector< UiFont* > m_Fonts;
-    struct UiPrototype
-    {
-        Ogre::String name;
-        TiXmlNode* node;
-    };
-    std::vector< UiPrototype > m_Prototypes;
-    std::vector< UiWidget* > m_Widgets;
-};
+        /**
+         * Adds a prototype to the manager.
+         *
+         * @param name[in] The prototype manager.
+         * @param prototype[in] The prototyme, as an XML node.
+         * @todo What exactly is a prototype here?
+         */
+        void AddPrototype(const Ogre::String& name, TiXmlNode* prototype);
+
+        /**
+         * Retrieves a prototype by name.
+         *
+         * @param name[in] Name of the prototype.
+         * @return The prototype by the specified name, or NULL if there is
+         * none.
+         * @todo What exactly is a prototype here?
+         */
+        TiXmlNode* GetPrototype(const Ogre::String& name) const;
+
+        /**
+         * Adds a UI widget to the manager.
+         *
+         * @param widget[in] The widget to add.
+         */
+        void AddWidget(UiWidget* widget);
+
+        /**
+         * Retrieves a UI widget by name.
+         *
+         * @param name[in] Name of the widget.
+         * @return The widget by the specified name, or NULL if there is none.
+         */
+        UiWidget* GetWidget(const Ogre::String& name);
 
+        /**
+         * Retrieves a UI widget by name.
+         *
+         * @param name[in] Name of the widget.
+         * @return The widget by the specified name, or NULL if there is none.
+         */
+        UiWidget* ScriptGetWidget(const char* name);
 
+        /**
+         * Updates the render queue.
+         *
+         * @param queueGroupId[in] The queue group ID.
+         * @param invocation[in] Unused.
+         * @param skipThisInvocation[in] Unused.
+         */
+        void renderQueueStarted(
+          Ogre::uint8 queueGroupId, const Ogre::String& invocation,
+          bool& skipThisInvocation
+        );
 
-#endif // UI_MANAGER_H
+    private:
+
+        /**
+         * List of fonts in the manager.
+         */
+        std::vector<UiFont*> fonts_;
+
+        /**
+         * A UI prototype.
+         *
+         * @todo What exactly is a prototype here?
+         */
+        struct UiPrototype{
+
+            /**
+             * The prototype node.
+             */
+            Ogre::String name;
+
+            /**
+             * The prototype structure as an XML node.
+             */
+            TiXmlNode* node;
+        };
+
+        /**
+         * List of prototypes.
+         */
+        std::vector<UiPrototype> prototypes_;
+
+        /**
+         * List of widgets.
+         */
+        std::vector<UiWidget*> widgets_;
+};

+ 126 - 29
QGearsMain/include/core/UiSprite.h

@@ -1,45 +1,142 @@
-#ifndef UI_SPRITE_H
-#define UI_SPRITE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreHardwareVertexBuffer.h>
 #include <OgreRenderQueueListener.h>
 #include <OgreRoot.h>
-
 #include "UiWidget.h"
 
+/**
+ * A sprite.
+ */
+class UiSprite : public UiWidget{
 
+    public:
 
-class UiSprite : public UiWidget
-{
-public:
-    UiSprite( const Ogre::String& name );
-    UiSprite( const Ogre::String& name, const Ogre::String& path_name, UiWidget* parent );
-    virtual ~UiSprite();
+        /**
+         * Constructor.
+         *
+         * @param name[in] The sprite name.
+         */
+        UiSprite(const Ogre::String& name);
 
-    void Initialise();
-    virtual void Update();
-    virtual void Render();
-    virtual void UpdateTransformation();
+        /**
+         * Constructor.
+         *
+         * @param name[in] The sprinte name.
+         * @param path_name[in] Path to the sprite file.
+         * @param parent[in] Widget to be set as parent of the sprite.
+         * @todo path_name is relative to data? Filename is needed?
+         */
+        UiSprite(
+          const Ogre::String& name, const Ogre::String& path_name,
+          UiWidget* parent
+        );
 
-    void SetImage( const Ogre::String& image );
-    void SetVertexShader( const Ogre::String& shader );
-    void SetFragmentShader( const Ogre::String& shader );
-    void UpdateGeometry();
+        /**
+         * Destructor.
+         */
+        virtual ~UiSprite();
 
-private:
-    UiSprite();
-    void CreateVertexBuffer();
-    void DestroyVertexBuffer();
+        /**
+         * Loads an initializes the sprite.
+         */
+        void Initialise();
 
-private:
-    Ogre::MaterialPtr                   m_Material;
-    Ogre::SceneManager*                 m_SceneManager;
-    Ogre::RenderSystem*                 m_RenderSystem;
+        /**
+         * Updates the sprite state.
+         */
+        virtual void Update();
 
-    Ogre::RenderOperation               m_RenderOp;
-    Ogre::HardwareVertexBufferSharedPtr m_VertexBuffer;
-};
+        /**
+         * Renders the sprite.
+         */
+        virtual void Render();
+
+        /**
+         * Updates the sprite state.
+         */
+        virtual void UpdateTransformation();
+
+        /**
+         * Sets the sprite image.
+         *
+         * @param image[in] @todo file path or just a name?
+         */
+        void SetImage(const Ogre::String& image);
+
+        /**
+         * Sets the vertex shader for the sprite.
+         *
+         * @param shader[in] The shader to set.
+         */
+        void SetVertexShader(const Ogre::String& shader);
+
+        /**
+         * Sets the fragment shader for the sprite.
+         *
+         * @param shader[in] The shader to set.
+         */
+        void SetFragmentShader(const Ogre::String& shader);
+
+        /**
+         * Recalculates the sprite geometry.
+         */
+        void UpdateGeometry();
 
+    private:
 
+        /**
+         * Constructor.
+         */
+        UiSprite();
 
-#endif // UI_SPRITE_H
+        /**
+         * Creates a vertex buffer for the sprite.
+         */
+        void CreateVertexBuffer();
+
+        /**
+         * Destroys a vertex buffer for the sprite.
+         */
+        void DestroyVertexBuffer();
+
+        /**
+         * The sprite material.
+         */
+        Ogre::MaterialPtr material_;
+
+        /**
+         * The scene manager.
+         */
+        Ogre::SceneManager* scene_manager_;
+
+        /**
+         * The render system.
+         */
+        Ogre::RenderSystem* render_system_;
+
+        /**
+         * The render operation.
+         */
+        Ogre::RenderOperation render_operation_;
+
+        /**
+         * The vertex buffer.
+         */
+        Ogre::HardwareVertexBufferSharedPtr vertex_buffer_;
+};

+ 452 - 138
QGearsMain/include/core/UiTextArea.h

@@ -1,5 +1,19 @@
-#ifndef UI_TEXT_AREA_H
-#define UI_TEXT_AREA_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreHardwareVertexBuffer.h>
 #include <OgreRenderQueueListener.h>
@@ -12,34 +26,62 @@
 
 class UiSprite;
 
-enum TextState
-{
+/**
+ * The textarea state.
+ */
+enum TextState{
+
+    /**
+     * The text is displayed.
+     */
     TS_SHOW_TEXT,
+
+    /**
+     * The text is scrolling.
+     */
     TS_SCROLL_TEXT,
+
+    /**
+     * The text is paused waiting for input.
+     */
     TS_PAUSE_OK,
+
+    /**
+     * The text is paused waiting for time to pass.
+     */
     TS_PAUSE_TIME,
+
+    /**
+     * The textarea is done with.
+     */
     TS_DONE,
+
+    /**
+     * The text is overflowing.
+     */
     TS_OVERFLOW,
+
+    /**
+     * The text is changing pages.
+     */
     TS_NEXT_PAGE,
 };
 
 
 
-struct TextChar
-{
+struct TextChar{
     TextChar():
-        char_code( 0 ),
-        colour( Ogre::ColourValue::White ),
-        skip( false ),
-        variable( "" ),
-        variable_len( 0 ),
-        pause_ok( false ),
-        pause_time( 0.0f ),
-        next_page( false ),
-        sprite( NULL ),
-        sprite_y( 0 )
-    {
-    }
+      char_code(0),
+      colour(Ogre::ColourValue::White),
+      skip(false),
+      variable(""),
+      variable_len(0),
+      pause_ok(false),
+      pause_time(0.0f),
+      next_page(false),
+      sprite(NULL),
+      sprite_y(0)
+    {}
 
     int char_code;
     Ogre::ColourValue colour;
@@ -68,125 +110,397 @@ struct TextVariable
  * It may be any window used to represent text: a diaog window, a menu panel,
  * a choice selection...
  */
-class UiTextArea : public UiWidget
-{
-public:
-
-    /**
-     * Creates a UiTextArea.
-     *
-     * @param name[name] Name for the textarea.
-     */
-    UiTextArea( const Ogre::String& name );
-
-    /**
-     * Creates a UiTextArea.
-     *
-     * @param name[in] Name for the textarea.
-     * @param path_name[in] Path for the widget.
-     * @param parent[in] Poinbter to the widget that will parent the UiTextArea.
-     */
-    UiTextArea( const Ogre::String& name, const Ogre::String& path_name, UiWidget* parent );
-
-    /**
-     * Destroys the UiTextArea.
-     */
-    virtual ~UiTextArea();
-
-    /**
-     * Sets default values for the UiTextArea.
-     *
-     * It's automatically called when the UiTextArea is created.
-     */
-    void Initialise();
-
-    /**
-     * Updates the UiTextArea.
-     */
-    virtual void Update();
-
-    /**
-     * Renders the UiTextArea on the screen.
-     */
-    virtual void Render();
-
-    /**
-     *
-     */
-    virtual void UpdateTransformation();
-
-    void UpdateGeometry();
-
-    void InputPressed();
-    void InputRepeated();
-
-    enum TextAlign
-    {
-        LEFT,
-        RIGHT,
-        CENTER
-    };
-    void SetTextAlign( const TextAlign align );
-    void SetPadding( const float top, const float right, const float bottom, const float left );
-    void SetText( const Ogre::UTFString& text );
-    void SetText( TiXmlNode* text );
-    void TextClear();
-    void RemoveSpritesFromText( const unsigned int end );
-    void SetFont( const Ogre::String& font );
-    const UiFont* GetFont() const;
-    void SetTextPrintSpeed( const float speed );
-    void SetTextScrollTime( const float time );
-    void SetVariable( const Ogre::String& name, const Ogre::UTFString& value );
-    Ogre::UTFString GetVariable( const Ogre::String& name ) const;
-    TextState GetTextState() const;
-    float GetTextLimit() const;
-    unsigned int GetTextSize() const;
-    float GetPauseTime() const;
-
-private:
-    float GetTextWidth() const;
-    void PrepareTextFromNode( TiXmlNode* node, const Ogre::ColourValue& colour );
-    void PrepareTextFromText( const Ogre::UTFString& text, const Ogre::ColourValue& colour );
-
-    UiTextArea();
-    void CreateVertexBuffer();
-    void DestroyVertexBuffer();
-
-private:
-    Ogre::MaterialPtr                   m_Material;
-    Ogre::SceneManager*                 m_SceneManager;
-    Ogre::RenderSystem*                 m_RenderSystem;
-
-    unsigned int                        m_MaxLetters;
-    Ogre::RenderOperation               m_RenderOp;
-    Ogre::HardwareVertexBufferSharedPtr m_VertexBuffer;
-
-    UiFont*                             m_Font;
-    TextAlign                           m_TextAlign;
-
-    std::vector< TextChar >             m_Text;
-    float                               m_TextLimit;
-    float                               m_TextPrintSpeed;
-    float                               m_TextPrintSpeedMod;
-    TextState                           m_TextState;
-    std::vector< TextVariable >         m_TextVariable;
-
-    float                               m_TextScrollTime;
-    float                               m_TextYOffset;
-    float                               m_TextYOffsetTarget;
-    float                               m_PauseTime;
-    unsigned int                        m_NextPageStart;
-
-    bool                                m_NextPressed;
-    bool                                m_NextRepeated;
-
-    float                               m_PaddingTop;
-    float                               m_PaddingRight;
-    float                               m_PaddingBottom;
-    float                               m_PaddingLeft;
-
-    bool                                m_Timer;
-    int                                 m_TimerTime;
+class UiTextArea : public UiWidget{
+
+    public:
+
+        /**
+         * Creates a UiTextArea.
+         *
+         * @param name[in] Name for the textarea.
+         */
+        UiTextArea(const Ogre::String& name);
+
+        /**
+         * Creates a UiTextArea.
+         *
+         * @param name[in] Name for the textarea.
+         * @param path_name[in] Path for the widget.
+         * @param parent[in] Pointer to the widget that will parent the
+         * UiTextArea.
+         */
+        UiTextArea(
+          const Ogre::String& name, const Ogre::String& path_name,
+          UiWidget* parent
+        );
+
+        /**
+         * Destroys the UiTextArea.
+         */
+        virtual ~UiTextArea();
+
+        /**
+         * Sets default values for the UiTextArea.
+         *
+         * It's automatically called when the UiTextArea is created.
+         */
+        void Initialise();
+
+        /**
+         * Updates the UiTextArea.
+         */
+        virtual void Update();
+
+        /**
+         * Renders the UiTextArea on the screen.
+         */
+        virtual void Render();
+
+        /**
+         * Updates the UiTextArea.
+         */
+        virtual void UpdateTransformation();
+
+        /**
+         * Updates the UiTextArea geometry.
+         */
+        void UpdateGeometry();
+
+        /**
+         * Handles a keypress.
+         */
+        void InputPressed();
+
+        /**
+         * Handles a key being hold.
+         */
+        void InputRepeated();
+
+        /**
+         * Text alignment in the text area.
+         */
+        enum TextAlign{
+
+            /**
+             * Left aligned text.
+             */
+            LEFT,
+
+            /**
+             * Right aligned text.
+             */
+            RIGHT,
+
+            /**
+             * Horizontally centered text.
+             */
+            CENTER
+        };
+
+        /**
+         * Sets the text alignment in the text area.
+         *
+         * @param align[in] The text alignment.
+         */
+        void SetTextAlign(const TextAlign align);
+
+        /**
+         * Sets the paddings in the text area.
+         *
+         * @param top[in] Padding from the top, in pixels.
+         * @param right[in] Padding from the right, in pixels.
+         * @param bottom[in] Padding from the bottom, in pixels.
+         * @param left[in] Padding from the left, in pixels.
+         */
+        void SetPadding(
+          const float top, const float right,
+          const float bottom, const float left
+        );
+
+        /**
+         * Sets the text from a string.
+         *
+         * @param text[in] Text to set.
+         */
+        void SetText(const Ogre::UTFString& text);
+
+        /**
+         * Sets the text from an XML node.
+         *
+         * @param text[in] XML node with the text to set.
+         */
+        void SetText(TiXmlNode* text);
+
+        /**
+         * Removes the text from the text area.
+         */
+        void TextClear();
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param end[in] @todo Understand and document.
+         */
+        void RemoveSpritesFromText(const unsigned int end);
+
+        /**
+         * Set the font for the text.
+         *
+         * @param font[in] The font to set.
+         */
+        void SetFont(const Ogre::String& font);
+
+        /**
+         * Retrieves the font.
+         *
+         * @return The font used for the text in the textarea.
+         */
+        const UiFont* GetFont() const;
+
+        /**
+         * Sets the printing speed.
+         *
+         * @param speed[in] The text speed. -1 for instant text.
+         * @todo Explain units or references.
+         */
+        void SetTextPrintSpeed(const float speed);
+
+        /**
+         * Sets the scroll duration.
+         *
+         * @param time[in] Time to scroll a line.
+         * @todo Units or references.
+         */
+        void SetTextScrollTime(const float time);
+
+        /**
+         * Sets a variable in the text.
+         *
+         * @param name[in] Variable name.
+         * @param value[in] Variable value.
+         */
+        void SetVariable(
+          const Ogre::String& name, const Ogre::UTFString& value
+        );
+
+        /**
+         * Gets the value of a variable in the text.
+         *
+         * @param name[in] The variable name.
+         * @return The variable value, in string format, or an empty string if
+         * there is no such variable.
+         */
+        Ogre::UTFString GetVariable(const Ogre::String& name) const;
+
+        /**
+         * Checks the text state.
+         *
+         * @return The text state.
+         */
+        TextState GetTextState() const;
+
+        /**
+         * Gets the text limit.
+         *
+         * @return The text limit.
+         * @todo The limit is the max number of letters per text area? Does it
+         * include multiple pages?
+         */
+        float GetTextLimit() const;
+
+        /**
+         * Gets the text size.
+         *
+         * @return The number of characters in the text.
+         */
+        unsigned int GetTextSize() const;
+
+        /**
+         * Retrieves the pause time of the text.
+         *
+         * @return The time the text must still remain paused, in second.
+         */
+        float GetPauseTime() const;
+
+    private:
+
+        /**
+         * Retrieves the text width.
+         *
+         * @return The text width, in pixels.
+         */
+        float GetTextWidth() const;
+
+        /**
+         * Prepares text from a XML node.
+         *
+         * @param node[in] The XML node to get the text from.
+         * @param colour[in] The text colour.
+         * @todo Does this call setText?
+         */
+        void PrepareTextFromNode(
+          TiXmlNode* node, const Ogre::ColourValue& colour
+        );
+
+        /**
+         * Prepares text from a string.
+         *
+         * @param text[in] The text to prepare.
+         * @param colour[in] The text colour.
+         * @todo Does this call setText?
+         */
+        void PrepareTextFromText(
+          const Ogre::UTFString& text, const Ogre::ColourValue& colour
+        );
+
+        /**
+         * Constructor.
+         */
+        UiTextArea();
+
+        /**
+         * Creates a vertex buffer for the textarea.
+         */
+        void CreateVertexBuffer();
+
+        /**
+         * Destroys a vertex buffer for the textarea.
+         */
+        void DestroyVertexBuffer();
+
+        /**
+         * Material for the text area.
+         */
+        Ogre::MaterialPtr material_;
+
+        /**
+         * The scene manager.
+         */
+        Ogre::SceneManager* scene_manager_;
+
+        /**
+         * The render system.
+         */
+        Ogre::RenderSystem* render_system_;
+
+        /**
+         * Max letter per textarea.
+         */
+        unsigned int max_letters_;
+
+        /**
+         * The render operation.
+         */
+        Ogre::RenderOperation render_operation_;
+
+        /**
+         * The text area vertext buffer.
+         */
+        Ogre::HardwareVertexBufferSharedPtr vertex_buffer_;
+
+        /**
+         * The font for the text.
+         */
+        UiFont* font_;
+
+        /**
+         * The text alignment.
+         */
+        TextAlign text_align_;
+
+        /**
+         * The text.
+         */
+        std::vector<TextChar> text_;
+
+        /**
+         * The text limit.
+         */
+        float text_limit_;
+
+        /**
+         * The text printing speed.
+         */
+        float text_print_speed_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float text_print_speed_mod_;
+
+        /**
+         * The state of the text.
+         */
+        TextState text_state_;
+
+        /**
+         * Variables in the text.
+         */
+        std::vector<TextVariable> text_variable_;
+
+        /**
+         * Time to scroll the text.
+         */
+        float text_scroll_time_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float text_y_offset_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float text_y_offset_target_;
+
+        /**
+         * The time to pause the text.
+         */
+        float pause_time_;
+
+        /**
+         * @todo Understand and document.
+         */
+        unsigned int next_page_start_;
+
+        /**
+         * Indicates if the 'next' button has been pressed.
+         */
+        bool next_pressed_;
+
+        /**
+         * Indicates if the 'next' button is being held down.
+         */
+        bool next_repeated_;
+
+        /**
+         * The top padding.
+         */
+        float padding_top_;
+
+        /**
+         * The right padding.
+         */
+        float padding_right_;
+
+        /**
+         * The bottom padding.
+         */
+        float padding_bottom_;
+
+        /**
+         * The left padding.
+         */
+        float padding_left_;
+
+        /**
+         * @todo Understand and document.
+         */
+        bool timer_;
+
+        /**
+         * @todo Understand and document.
+         */
+        int timer_time_;
 };
 
-#endif // UI_TEXT_AREA_H

+ 813 - 154
QGearsMain/include/core/UiWidget.h

@@ -1,167 +1,826 @@
-#ifndef UI_WIDGET_H
-#define UI_WIDGET_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreColourValue.h>
 #include <OgreString.h>
 #include <Ogre.h>
 #include <vector>
-
 #include "ScriptManager.h"
 #include "UiAnimation.h"
 
+/**
+ * An UI widget.
+ */
+class UiWidget{
 
+    public:
 
-class UiWidget
-{
-public:
-    UiWidget( const Ogre::String& name );
-    UiWidget( const Ogre::String& name, const Ogre::String& path_name, UiWidget* parent );
-    virtual ~UiWidget();
-
-    void Initialise();
-    virtual void Update();
-    void OnResize();
-    virtual void Render();
-
-    void SetVisible( const bool visible );
-    bool IsVisible() const;
-
-    const Ogre::String& GetName() const;
-
-    void AddChild( UiWidget* widget );
-    UiWidget* GetChild( const Ogre::String& name );
-    UiWidget* GetChild( const unsigned int id );
-    unsigned int GetNumberOfChildren();
-    void RemoveAllChildren();
-
-    // animation related
-    void AddAnimation( UiAnimation* animation );
-    const Ogre::String& GetCurrentAnimationName() const;
-    UiAnimation::State GetAnimationState() const;
-    void PlayAnimation( const Ogre::String& animation, UiAnimation::State state, const float start, const float end );
-    void ScriptPlayAnimation( const char* name );
-    void ScriptPlayAnimationStop( const char* name );
-    void ScriptPlayAnimation( const char* name, const float start, const float end );
-    void ScriptPlayAnimationStop( const char* name, const float start, const float end );
-    void ScriptSetDefaultAnimation( const char* animation );
-    int ScriptAnimationSync();
-
-    void SetUpdateTransformation();
-    virtual void UpdateTransformation();
-
-    enum Align
-    {
-        LEFT,
-        RIGHT,
-        CENTER
-    };
-    enum VerticalAlign
-    {
-        TOP,
-        BOTTOM,
-        MIDDLE
-    };
-    void SetAlign( const UiWidget::Align align );
-    void SetVerticalAlign( const UiWidget::VerticalAlign valign );
-
-    float GetFinalZ() const;
-    Ogre::Vector2 GetFinalOrigin() const;
-    Ogre::Vector2 GetFinalTranslate() const;
-    Ogre::Vector2 GetFinalSize() const;
-    Ogre::Vector2 GetFinalScale() const;
-    Ogre::Vector4 GetFinalScissor( bool& scissor ) const;
-    float GetFinalRotation() const;
-
-    void SetOriginX( const float percent, const float x );
-    void SetOriginY( const float percent, const float y );
-    void SetX( const float percent, const float x );
-    void GetX( float& percent, float& x );
-    void SetY( const float percent, const float y );
-    void GetY( float& percent, float& y );
-    void SetZ( const float z );
-    void SetWidth( const float percent, const float width );
-    void GetWidth( float& percent, float& width );
-    void SetHeight( const float percent, const float height );
-    void GetHeight( float& percent, float& height );
-    void SetScale( const Ogre::Vector2& scale );
-    void SetRotation( const float degree );
-    void SetScissorArea( const float percent_x1, const float x1, const float percent_y1, const float y1, const float percent_x2, const float x2, const float percent_y2, const float y2 );
-    void SetGlobalScissor( const bool global );
-    void SetColour( const float r, const float g, const float b );
-    void SetColours( const float r1, const float g1, const float b1, const float r2, const float g2, const float b2, const float r3, const float g3, const float b3, const float r4, const float g4, const float b4 );
-    void SetAlpha( const float a );
-
-private:
-    UiWidget();
-
-protected:
-    Ogre::String             m_Name;
-    Ogre::String             m_PathName;
-
-    UiWidget*                m_Parent;
-    std::vector< UiWidget* > m_Children;
-
-    float                    m_ScreenWidth;
-    float                    m_ScreenHeight;
-
-    bool                     m_Visible;
-    Ogre::ColourValue        m_Colour1;
-    Ogre::ColourValue        m_Colour2;
-    Ogre::ColourValue        m_Colour3;
-    Ogre::ColourValue        m_Colour4;
-
-    Align                    m_Align;
-    VerticalAlign            m_VerticalAlign;
-
-    bool                     m_UpdateTransformation;
-
-    Ogre::Vector2            m_FinalOrigin;
-    Ogre::Vector2            m_FinalTranslate;
-    float                    m_FinalZ;
-    Ogre::Vector2            m_FinalSize;
-    Ogre::Vector2            m_FinalScale;
-    float                    m_FinalRotation;
-
-    float                    m_OriginXPercent;
-    float                    m_OriginX;
-    float                    m_OriginYPercent;
-    float                    m_OriginY;
-    float                    m_XPercent;
-    float                    m_X;
-    float                    m_YPercent;
-    float                    m_Y;
-    float                    m_Z;
-    float                    m_WidthPercent;
-    float                    m_Width;
-    float                    m_HeightPercent;
-    float                    m_Height;
-    Ogre::Vector2            m_Scale;
-    float                    m_Rotation;
-
-    bool                     m_Scissor;
-    bool                     m_LocalScissor;
-    bool                     m_GlobalScissor;
-    int                      m_ScissorTop;
-    float                    m_ScissorXPercentTop;
-    float                    m_ScissorXTop;
-    int                      m_ScissorBottom;
-    float                    m_ScissorXPercentBottom;
-    float                    m_ScissorXBottom;
-    int                      m_ScissorLeft;
-    float                    m_ScissorYPercentLeft;
-    float                    m_ScissorYLeft;
-    int                      m_ScissorRight;
-    float                    m_ScissorYPercentRight;
-    float                    m_ScissorYRight;
-
-    UiAnimation*                m_AnimationCurrent;
-    std::vector< ScriptId >     m_AnimationSync;
-    UiAnimation::State          m_AnimationState;
-    Ogre::String                m_AnimationDefault;
-    float                       m_AnimationEndTime;
-    std::vector< UiAnimation* > m_Animations;
-};
+        /**
+         * Constructor.
+         *
+         * @param name[in] Name for the widget.
+         */
+        UiWidget(const Ogre::String& name);
+
+        /**
+         * Constructor.
+         *
+         * @param name[in] Name for the widget.
+         * @param path_name[in] @todo Understand and document.
+         * @param parent[in] Widget to be made parent of the new one.
+         */
+        UiWidget(
+          const Ogre::String& name, const Ogre::String& path_name,
+          UiWidget* parent
+        );
+
+        /**
+         * Destructor.
+         */
+        virtual ~UiWidget();
+
+        /**
+         * Initializes the widget.
+         *
+         * It sets the widget geometry.
+         */
+        void Initialise();
+
+        /**
+         * Updates the widget status.
+         */
+        virtual void Update();
+
+        /**
+         * Handles resizing events.
+         *
+         * Recalculates the widget geometry and calls OnResize for all the
+         * widget children.
+         */
+        void OnResize();
+
+        /**
+         * Renders the widget and it's children.
+         */
+        virtual void Render();
+
+        /**
+         * Toggles the widget visibility.
+         *
+         * @param vivible[in] True to make the widget visible, false to make it
+         * invisible.
+         */
+        void SetVisible(const bool visible);
+
+        /**
+         * Checks the widget visibility.
+         *
+         * @return True if the widget is visible, false if it is invisible.
+         */
+        bool IsVisible() const;
+
+        /**
+         * Retrieves the widget name.
+         *
+         * @return The widget name.
+         */
+        const Ogre::String& GetName() const;
+
+        /**
+         * Add other widget as the widget's child.
+         *
+         * @param widget[in] Widget to be made children of this one.
+         */
+        void AddChild(UiWidget* widget);
+
+        /**
+         * Retrieves a children by name.
+         *
+         * @param name[in] Name of the children widget to retrieve.
+         * @return The children widget by the specified name. NULL if the
+         * widgets has no direct children by that name.
+         */
+        UiWidget* GetChild(const Ogre::String& name);
+
+        /**
+         * Retrieves a children by ID.
+         *
+         * @param name[in] ID of the children widget to retrieve.
+         * @return The children widget by the specified name. NULL if the
+         * widgets has no direct children by that ID.
+         */
+        UiWidget* GetChild(const unsigned int id);
+
+        /**
+         * Counts the widget's children.
+         *
+         * @return The number of direct children.
+         */
+        unsigned int GetNumberOfChildren();
+
+        /**
+         * Removes all children widgets.
+         */
+        void RemoveAllChildren();
+
+        /**
+         * Adds an animation to the widget.
+         *
+         * @param animation[in] The animation to add.
+         */
+        void AddAnimation(UiAnimation* animation);
+
+        /**
+         * Retrieves the current animation name.
+         *
+         * @return The current animation name. A blankstring if there is no set
+         * default animation.
+         */
+        const Ogre::String& GetCurrentAnimationName() const;
+
+        /**
+         * Retrieves the current animation state.
+         *
+         * @return The current animation state.
+         */
+        UiAnimation::State GetAnimationState() const;
+
+        /**
+         * Plays an animation.
+         *
+         * @param animation[in] Animation to play.
+         * @param state[in] Initial animation state.
+         * @param start[in] Seconds at which to start the animation.
+         * @param start[in] Seconds at which to end the animation. -1 to play
+         * it in full.
+         */
+        void PlayAnimation(
+          const Ogre::String& animation, UiAnimation::State state,
+          const float start, const float end
+        );
+
+        /**
+         * Plays an animation.
+         *
+         * The animation will be played from the start for it's full length.
+         *
+         * @param animation[in] The name of the animation to play.
+         * @todo It uses the parameter UiAnimation::DEFAULT. Whats does it do?
+         * Does it play the animation in a loop, or uses a default value of the
+         * specific animation.
+         */
+        void ScriptPlayAnimation(const char* name);
+
+        /**
+         * Plays an animation.
+         *
+         * The animation will be played from the start for it's full length,
+         * only once.
+         *
+         * @param animation[in] The name of the animation to play.
+         */
+        void ScriptPlayAnimationStop(const char* name);
+
+        /**
+         * @param name[in] Name of the animation to play.
+         * @param start[in] Seconds at which to start the animation.
+         * @param start[in] Seconds at which to end the animation. -1 to play
+         * it in full.
+         * @todo It uses the parameter UiAnimation::DEFAULT. Whats does it do?
+         * Does it play the animation in a loop, or uses a default value of the
+         * specific animation.
+         */
+        void ScriptPlayAnimation(
+          const char* name, const float start, const float end
+        );
+
+        /**
+         * Plays an animation.
+         *
+         * The animation will be played only once.
+         *
+         * @param animation[in] The name of the animation to play.
+         */
+        void ScriptPlayAnimationStop(
+          const char* name, const float start, const float end
+        );
+
+        /**
+         * Sets the default animation for the widget.
+         *
+         * @param animation[in] The name of the default animation.
+         */
+        void ScriptSetDefaultAnimation(const char* animation);
+
+        /**
+         * Synchronizes an animation.
+         *
+         * @return Always -1.
+         * @todo Understand and document better.
+         */
+        int ScriptAnimationSync();
+
+        /**
+         * Marks the widget as transformed.
+         *
+         * It means that it's geometry must be updated in the next pass. It
+         * also marks the direct children as transformed.
+         */
+        void SetUpdateTransformation();
+
+        /**
+         * Recalculates the widget geometry.
+         */
+        virtual void UpdateTransformation();
+
+        /**
+         * Horizontal alignment of the widget.
+         */
+        enum Align{
+
+            /**
+             * Left alignment.
+             */
+            LEFT,
+
+            /**
+             * Right alignment.
+             */
+            RIGHT,
+
+            /**
+             * Centered horizontally.
+             */
+            CENTER
+        };
+
+        /**
+         * Vertical alignment of the widget.
+         */
+        enum VerticalAlign{
+
+            /**
+             * Top alignment.
+             */
+            TOP,
+
+            /**
+             * Bottom alignment.
+             */
+            BOTTOM,
+
+            /**
+             * Centered vertically.
+             */
+            MIDDLE
+        };
+
+        /**
+         * Sets the widget horizontal alignment.
+         *
+         * @poaram align[in] Widget alignment.
+         */
+        void SetAlign(const UiWidget::Align align);
+
+        /**
+         * Sets the widget vertical alignment.
+         *
+         * @poaram align[in] Widget alignment.
+         */
+        void SetVerticalAlign(const UiWidget::VerticalAlign valign);
+
+        /**
+         * Retrieves the final Z-index of the widget after a transformation.
+         *
+         * @return The final Z-index.
+         */
+        float GetFinalZ() const;
+
+        /**
+         * Retrieves the coordinates of the widget after a transformation.
+         *
+         * @return The final coordinater.
+         */
+        Ogre::Vector2 GetFinalOrigin() const;
+
+        /**
+         * Retrieves the final translation of the widget after a
+         * transformation.
+         *
+         * @return The final translation.
+         * @todo What is a translation here? Just a movement?
+         */
+        Ogre::Vector2 GetFinalTranslate() const;
+
+        /**
+         * Retrieves the final size of the widget after a transformation.
+         *
+         * @return The final size.
+         */
+        Ogre::Vector2 GetFinalSize() const;
+
+        /**
+         * Retrieves the final scale of the widget after a transformation.
+         *
+         * @return The final scale.
+         */
+        Ogre::Vector2 GetFinalScale() const;
+
+        /**
+         * Retrieves the final scissor of the widget after a transformation.
+         *
+         * @return The final scissor.
+         * @todo What is a scissor?
+         */
+        Ogre::Vector4 GetFinalScissor(bool& scissor) const;
+        float GetFinalRotation() const;
+
+        /**
+         * Sets the X coordinate origin for the widget.
+         *
+         * @param percent[in] @todo
+         * @param x[in] Origin X coordinate.
+         */
+        void SetOriginX(const float percent, const float x);
+
+        /**
+         * Sets the Y coordinate origin for the widget.
+         *
+         * @param percent[in] @todo
+         * @param y[in] Origin Y coordinate.
+         */
+        void SetOriginY(const float percent, const float y);
+
+        /**
+         * Sets the X coordinate for the widget.
+         *
+         * @param percent[in] @todo
+         * @param x[in] The X coordinate.
+         */
+        void SetX(const float percent, const float x);
+
+        /**
+         * Retrieves the X coordinate for the widget.
+         *
+         * @param percent[out] @todo
+         * @param x[out] The X coordinate will be loaded here.
+         */
+        void GetX(float& percent, float& x);
+
+        /**
+         * Sets the Y coordinate for the widget.
+         *
+         * @param percent[in] @todo
+         * @param y[in] The Y coordinate.
+         */
+        void SetY(const float percent, const float y);
+
+        /**
+         * Retrieves the Y coordinate for the widget.
+         *
+         * @param percent[out] @todo
+         * @param y[out] The Y coordinate will be loaded here.
+         */
+        void GetY(float& percent, float& y);
+
+        /**
+         * Sets the widget Z-index.
+         *
+         * @param z[in] The Z-index.
+         */
+        void SetZ(const float z);
+
+        /**
+         * Sets the width the widget.
+         *
+         * @param percent[in] @todo
+         * @param width[in] The widget width.
+         */
+        void SetWidth(const float percent, const float width);
+
+        /**
+         * Retrieves the width of the widget.
+         *
+         * @param percent[out] @todo
+         * @param width[out] The width will be loaded here.
+         */
+        void GetWidth(float& percent, float& width);
+
+        /**
+         * Sets the height the widget.
+         *
+         * @param percent[in] @todo
+         * @param height[in] The widget height.
+         */
+        void SetHeight(const float percent, const float height);
+
+        /**
+         * Retrieves the height of the widget.
+         *
+         * @param percent[out] @todo
+         * @param height[out] The height will be loaded here.
+         */
+        void GetHeight(float& percent, float& height);
+
+        /**
+         * Sets the widget scale.
+         *
+         * @param scale[in] The new widget scale.
+         */
+        void SetScale(const Ogre::Vector2& scale);
+
+        /**
+         * Sets the widget rotation.
+         *
+         * @param scale[in] The new widget rotation.
+         */
+        void SetRotation(const float degree);
+
+        /**
+         * Sets the widget scissor area.
+         *
+         * @param percent_x1[in] @todo Undersnd and document.
+         * @param x1[in] @todo Undersnd and document.
+         * @param percent_y1[in] @todo Undersnd and document.
+         * @param y1[in] @todo Undersnd and document.
+         * @param percent_x2[in] @todo Undersnd and document.
+         * @param x2[in] @todo Undersnd and document.
+         * @param percent_y2[in] @todo Undersnd and document.
+         * @param y2[in] @todo Undersnd and document.
+         */
+        void SetScissorArea(
+          const float percent_x1, const float x1, const float percent_y1,
+          const float y1, const float percent_x2, const float x2,
+          const float percent_y2, const float y2
+        );
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param global[in] @todo Understand and document.
+         */
+        void SetGlobalScissor(const bool global);
+
+        /**
+         * Sets the widget colour.
+         *
+         * It set the same colour for all corners.
+         *
+         * @param r[in] Colour red component (0-255).
+         * @param g[in] Colour green component (0-255).
+         * @param b[in] Colour blue component (0-255).
+         */
+        void SetColour(const float r, const float g, const float b);
 
+        /**
+         * Sets the widget colour.
+         *
+         * It set the same colours for each corner, and blends it in the
+         * interior.
+         *
+         * @param r1[in] Colour red component for the top-left corner (0-255).
+         * @param g1[in] Colour green component for the top-left corner
+         * (0-255).
+         * @param b1[in] Colour blue component for the top-left corner (0-255).
+         * @param r2[in] Colour red component for the top-right corner (0-255).
+         * @param g2[in] Colour green component for the top-right corner
+         * (0-255).
+         * @param b2[in] Colour blue component for the top-right corner (0-255).
+         * @param r3[in] Colour red component for the bottom-right corner (0-255).
+         * @param g3[in] Colour green component for the bottom-right corner
+         * (0-255).
+         * @param b3[in] Colour blue component for the bottom-right corner
+         * (0-255).
+         * @param r4[in] Colour red component for the bottom-left corner
+         * (0-255).
+         * @param g4[in] Colour green component for the bottom-left corner
+         * (0-255).
+         * @param b4[in] Colour blue component for the bottom-left corner
+         * (0-255).
+         */
+        void SetColours(
+          const float r1, const float g1, const float b1,
+          const float r2, const float g2, const float b2,
+          const float r3, const float g3, const float b3,
+          const float r4, const float g4, const float b4
+        );
 
+        /**
+         * Sets the widget transparency.
+         *
+         * @param a[in] Alpha value (0 opaque, 255 fully transparent).
+         */
+        void SetAlpha(const float a);
+
+    protected:
+
+        /**
+         * The widget name.
+         */
+        Ogre::String name_;
+
+        /**
+         * @todo Understand and document.
+         */
+        Ogre::String path_name_;
+
+        /**
+         * The parent widget.
+         */
+        UiWidget* parent_;
+
+        /**
+         * The list of children widgets.
+         */
+        std::vector<UiWidget*> children_;
+
+        /**
+         * Width, in game screen units.
+         *
+         * @todo Understand and document.
+         */
+        float screen_width_;
+
+        /**
+         * Height, in game screen units.
+         *
+         * @todo Understand and document.
+         */
+        float screen_height_;
+
+        /**
+         * Indicates if the widget is visible.
+         */
+        bool visible_;
+
+        /**
+         * Top-left corner colour.
+         */
+        Ogre::ColourValue colour_1_;
+
+        /**
+         * Top-right corner colour.
+         */
+        Ogre::ColourValue colour_2_;
+
+        /**
+         * Bottom-right corner colour.
+         */
+        Ogre::ColourValue colour_3_;
+
+        /**
+         * Bottom-left corner colour.
+         */
+        Ogre::ColourValue colour_4_;
+
+        /**
+         * The vertical alignment.
+         */
+        Align align_;
+
+        /**
+         * The evrtical alignment.
+         */
+        VerticalAlign vertical_align_;
+
+        /**
+         * Indicates if the widget is marked as transformed.
+         */
+        bool update_transformation_;
+
+        /**
+         * Final origin point after a transformation.
+         */
+        Ogre::Vector2 final_origin_;
+
+        /**
+         * Final translation after a transformation.
+         *
+         * @todo Understand and document.
+         */
+        Ogre::Vector2 final_translate_;
+
+        /**
+         * Final Z-index after a transformation.
+         */
+        float final_z_;
+
+        /**
+         * Final size after a transformation.
+         */
+        Ogre::Vector2 final_size_;
+
+        /**
+         * Final scale after a transformation.
+         */
+        Ogre::Vector2 final_scale_;
+
+        /**
+         * Final rotation after a transformation.
+         */
+        float final_rotation_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float origin_x_percent_;
+
+        /**
+         * The origin X coordinate.
+         */
+        float origin_x_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float origin_y_percent_;
+
+        /**
+         * The origin Y coordinate.
+         */
+        float origin_y_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float x_percent_;
+
+        /**
+         * The widget X coordinate.
+         */
+        float x_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float y_percent_;
+
+        /**
+         * The widget Y coordinate.
+         */
+        float y_;
+
+        /**
+         * The widget Z coordinate.
+         */
+        float z_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float width_percent_;
+
+        /**
+         * The widget width.
+         */
+        float width_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float height_percent_;
+
+        /**
+         * The widget height.
+         */
+        float height_;
+
+        /**
+         * The widget scale.
+         */
+        Ogre::Vector2 scale_;
+
+        /**
+         * The widget rotation.
+         */
+        float rotation_;
+
+        /**
+         * @todo Understand and document.
+         */
+        bool scissor_;
+
+        /**
+         * @todo Understand and document.
+         */
+        bool local_scissor_;
+
+        /**
+         * @todo Understand and document.
+         */
+        bool global_scissor_;
+
+        /**
+         * @todo Understand and document.
+         */
+        int scissor_top_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float scissor_x_percent_top_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float scissor_x_top_;
+
+        /**
+         * @todo Understand and document.
+         */
+        int scissor_bottom_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float scissor_x_percent_bottom_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float scissor_x_bottom_;
+
+        /**
+         * @todo Understand and document.
+         */
+        int scissor_left_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float scissor_y_percent_left_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float scissor_y_left_;
+
+        /**
+         * @todo Understand and document.
+         */
+        int scissor_right_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float scissor_y_percent_right_;
+
+        /**
+         * @todo Understand and document.
+         */
+        float scissor_y_right_;
+
+        /**
+         * The current animation.
+         */
+        UiAnimation* animation_current_;
+
+        /**
+         * The animation stack.
+         *
+         * @todo Understand and document better.
+         */
+        std::vector<ScriptId> animation_sync_;
+
+        /**
+         * The current animation state.
+         */
+        UiAnimation::State animation_state_;
+
+        /**
+         * The name of the default animation.
+         */
+        Ogre::String animation_default_;
+
+        /**
+         * Time for the current animation to end.
+         */
+        float animation_end_time_;
+
+        /**
+         * The list of animations.
+         */
+        std::vector<UiAnimation*> animations_;
+
+    private:
+
+        /**
+         * Constructor.
+         */
+        UiWidget();
+};
 
-#endif // UI_WIDGET_H

+ 234 - 40
QGearsMain/include/core/Utilites.h

@@ -1,5 +1,19 @@
-#ifndef UTILITES_H
-#define UTILITES_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreColourValue.h>
 #include <OgreMatrix4.h>
@@ -8,44 +22,224 @@
 #include <Ogre.h>
 #include <Overlay/OgreUTFString.h>
 #include <OIS/OIS.h>
-
 #include <tinyxml.h>
 
-bool                      GetBool( TiXmlNode* node, const Ogre::String& tag, bool def = false );
-int                       GetInt( TiXmlNode* node, const Ogre::String& tag, int def = 0 );
-float                     GetFloat( TiXmlNode* node, const Ogre::String& tag, float def = 0.0f );
-const Ogre::String        GetString( TiXmlNode* node, const Ogre::String& tag, const Ogre::String& def = "" );
-const Ogre::UTFString     GetUTFString( TiXmlNode* node, const Ogre::String& tag, const Ogre::UTFString& def = "" );
-const Ogre::Vector2       GetVector2( TiXmlNode* node, const Ogre::String& tag, const Ogre::Vector2& def = Ogre::Vector2::ZERO );
-const Ogre::Vector3       GetVector3( TiXmlNode* node, const Ogre::String& tag, const Ogre::Vector3& def = Ogre::Vector3::ZERO );
-const Ogre::Vector4       GetVector4( TiXmlNode* node, const Ogre::String& tag, const Ogre::Vector4& def = Ogre::Vector4::ZERO );
-const Ogre::Matrix4       GetMatrix4( TiXmlNode* node, const Ogre::String& tag, const Ogre::Matrix4& def = Ogre::Matrix4::IDENTITY );
-const Ogre::Quaternion    GetQuaternion( TiXmlNode* node, const Ogre::String& tag, const Ogre::Quaternion& def = Ogre::Quaternion::IDENTITY );
-const Ogre::ColourValue   GetColourValue( TiXmlNode* node, const Ogre::String& tag, const Ogre::ColourValue& def = Ogre::ColourValue::ZERO );
-
-void                      ParsePersent( float& value_percent, float& value, const Ogre::String& string );
-float                     ParseKeyFrameTime( const float length, const Ogre::String& string );
-
-
-
-const Ogre::String
-CreateAutoName( const Ogre::String prefix );
-
-
-
-Ogre::String
-KeyToString( OIS::KeyCode key );
-
-
-
-OIS::KeyCode
-StringToKey( const Ogre::String& str );
-
-
-
-Ogre::StringVector
-StringTokenise( const Ogre::String& str, const Ogre::String& delimiters = "\t\n ", const Ogre::String& delimiters_preserve = "", const Ogre::String& quote = "\"", const Ogre::String& esc = "\\" );
-
-
+// TODO: All the methods defined here that refer to XML files are implemented
+// as methods of XmlFile. Can they be deleted from here?
+
+/**
+ * Retrieves a boolean from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found or it's not a
+ * boolean value.
+ * @return Boolean value of the tag. If it's not found or it's not a boolean,
+ * def is returned.
+ */
+bool GetBool(TiXmlNode* node, const Ogre::String& tag, bool def = false);
+
+/**
+ * Retrieves an integer from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found or it's not a
+ * numeric value.
+ * @return Integer value of the tag. If it's not found or it's not a number,
+ * def is returned.
+ */
+int GetInt(TiXmlNode* node, const Ogre::String& tag, int def = 0);
+
+/**
+ * Retrieves a decimal from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found or it's not a
+ * numeric value.
+ * @return Floating value of the tag. If it's not found or it's not a number,
+ * def is returned.
+ */
+float GetFloat(TiXmlNode* node, const Ogre::String& tag, float def = 0.0f);
+
+/**
+ * Retrieves a string from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found.
+ * @return String value of the tag. If it's not found, def is returned.
+ */
+const Ogre::String GetString(
+  TiXmlNode* node, const Ogre::String& tag, const Ogre::String& def = ""
+);
+
+/**
+ * Retrieves a string from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found.
+ * @return String value of the tag, in UFT8. If not found, def is returned.
+ */
+const Ogre::UTFString GetUTFString(
+  TiXmlNode* node, const Ogre::String& tag, const Ogre::UTFString& def = ""
+);
+
+/**
+ * Retrieves a 2-dimensional vector from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found.
+ * @return Vector in the tag. If it's not found, def is returned.
+ */
+const Ogre::Vector2 GetVector2(
+  TiXmlNode* node, const Ogre::String& tag,
+  const Ogre::Vector2& def = Ogre::Vector2::ZERO
+);
+
+/**
+ * Retrieves a 3-dimensional vector from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found.
+ * @return Vector in the tag. If it's not found, def is returned.
+ */
+const Ogre::Vector3 GetVector3(
+  TiXmlNode* node, const Ogre::String& tag,
+  const Ogre::Vector3& def = Ogre::Vector3::ZERO
+);
+
+/**
+ * Retrieves a 4-dimensional vector from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found.
+ * @return Vector in the tag. If it's not found, def is returned.
+ */
+const Ogre::Vector4 GetVector4(
+  TiXmlNode* node, const Ogre::String& tag,
+  const Ogre::Vector4& def = Ogre::Vector4::ZERO
+);
+
+/**
+ * Retrieves a 4-dimensional matrix from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found.
+ * @return Martix in the tag. If it's not found, def is returned.
+ */
+const Ogre::Matrix4 GetMatrix4(
+  TiXmlNode* node, const Ogre::String& tag,
+  const Ogre::Matrix4& def = Ogre::Matrix4::IDENTITY
+);
+
+/**
+ * Retrieves a quaternion from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found.
+ * @return quaternion in the tag. If it's not found, def is returned.
+ */
+const Ogre::Quaternion GetQuaternion(
+  TiXmlNode* node, const Ogre::String& tag,
+  const Ogre::Quaternion& def = Ogre::Quaternion::IDENTITY
+);
+
+/**
+ * Retrieves a colour from an XMl tag.
+ *
+ * @param node[in] The XML node.
+ * @param tag[in] The name of the tag.
+ * @param def[in] Default value, in case the tag is not found.
+ * @return Colour in the tag. If it's not found, def is returned.
+ */
+const Ogre::ColourValue GetColourValue(
+  TiXmlNode* node, const Ogre::String& tag,
+  const Ogre::ColourValue& def = Ogre::ColourValue::ZERO
+);
+
+/**
+ * Parses percentage strings
+ *
+ * Accepts strings in the formats "A" "A%" "A%B", where A and B are real
+ * values.
+ *
+ * @param value_percent[out] Percent value
+ * @param value[out] String numeric value.
+ * @param string[in] Input string.
+ * @example "80.4%" -> value = 0, percent_value = 80.4
+ * @example "80.4%20.6" -> value = 20.6, percent_value = 80.4
+ * @example "80.4" -> value = 80.4, percent_value = 0
+ *
+ */
+void ParsePercent(
+  float& value_percent, float& value, const Ogre::String& string
+);
+
+/**
+ * Parses a keyframe time string.
+ *
+ * It acceps input string of numeric values and numeric values followed by a
+ * percentage sign
+ *
+ * @param length[in] Keyframe duration, used only for percentages.
+ * @param string[in] Input string
+ * @return Keyframe time.
+ * @example "7.2" -> 7.2
+ * @example "7.2%" -> length * 7.2
+ */
+float ParseKeyFrameTime(const float length, const Ogre::String& string);
+
+/**
+ * Creates a name.
+ *
+ * @prefix[in] Name prefix.
+ * @return PREFIX + "0".
+ * @todo This seems so simple, am I missing something?
+ */
+const Ogre::String CreateAutoName(const Ogre::String prefix);
+
+/**
+ * Obtains a name from a key code.
+ *
+ * @param key[in] Key code.
+ * @return Human readable name assigned to the key code. "UNASSIGNED" if there
+ * is no name for the key code.
+ */
+Ogre::String KeyToString(OIS::KeyCode key);
+
+/**
+ * Obtains a key code from a name.
+ *
+ * @param str[in] Key name.
+ * @return Key code assigned to the name. OIS::KC_UNASSIGNED  if there is no
+ * keycode with the specified name.
+ */
+OIS::KeyCode StringToKey(const Ogre::String& str);
+
+/**
+ * Tokenizes a string.
+ *
+ * @param str[in] Input string.
+ * @param delimiters[in] Token delimiters. They will be stripped from the
+ * string.
+ * @param delimiters_preserve[in] More token delimiters. They will be returned
+ * as individual tokens.
+ * @param quote[in] @todo Understand and document.
+ * @param esc[in] Accepted escape characters. Escaped characters won't be
+ * considered delimiters of any kind.
+ * @return Tokens of the original string.
+ */
+Ogre::StringVector StringTokenise(
+  const Ogre::String& str, const Ogre::String& delimiters = "\t\n ",
+  const Ogre::String& delimiters_preserve = "",
+  const Ogre::String& quote = "\"", const Ogre::String& esc = "\\"
+);
 
-#endif // UTILITES_H

+ 149 - 35
QGearsMain/include/core/Walkmesh.h

@@ -1,60 +1,174 @@
-#ifndef WALKMESH_H
-#define WALKMESH_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <Ogre.h>
 #include <vector>
 
-struct WalkmeshTriangle
-{
+/**
+ * A triangle of a walkmesh.
+ */
+struct WalkmeshTriangle{
+
+    /**
+     * Constructor.
+     */
     WalkmeshTriangle():
-        a( 0, 0, 0 ),
-        b( 0, 0, 0 ),
-        c( 0, 0, 0 ),
-        locked( false )
+      a(0, 0, 0),
+      b(0, 0, 0),
+      c(0, 0, 0),
+      locked(false)
     {
-        access_side[ 0 ] = -1;
-        access_side[ 1 ] = -1;
-        access_side[ 2 ] = -1;
+        access_side[0] = -1;
+        access_side[1] = -1;
+        access_side[2] = -1;
     }
 
+    /**
+     * A side of the triangle.
+     */
     Ogre::Vector3 a;
+
+    /**
+     * A side of the triangle.
+     */
     Ogre::Vector3 b;
+
+    /**
+     * A side of the triangle.
+     */
     Ogre::Vector3 c;
 
-    int           access_side[ 3 ];
-    bool          locked;
+    /**
+     * @todo Understand and document.
+     */
+    int access_side[3];
+
+    /**
+     * Indicates if the triangle is locked (if it's walkable).
+     */
+    bool locked;
 };
 
-namespace QGears
-{
+namespace QGears{
     typedef Ogre::SharedPtr<class WalkmeshFile> WalkmeshFilePtr;
 }
 
-class Walkmesh
-{
-public:
-    Walkmesh();
-    virtual ~Walkmesh();
+class Walkmesh{
 
-    void UpdateDebug();
-    void Clear();
+    public:
 
-    void AddTriangle( const WalkmeshTriangle& triangle );
+        /**
+         * Constructor.
+         */
+        Walkmesh();
 
-    int GetAccessSide( unsigned int triangle_id, unsigned char side ) const;
-    const Ogre::Vector3& GetA( unsigned int triangle_id ) const;
-    const Ogre::Vector3& GetB( unsigned int triangle_id ) const;
-    const Ogre::Vector3& GetC( unsigned int triangle_id ) const;
-    int GetNumberOfTriangles() const;
-    void LockWalkmesh( unsigned int triangle_id, bool lock );
-    bool IsLocked( unsigned int triangle_id ) const;
+        /**
+         * Destructor.
+         */
+        virtual ~Walkmesh();
 
-    virtual void load( const QGears::WalkmeshFilePtr &walkmesh );
+        /**
+         * Updates the walkmesh with debug information.
+         */
+        void UpdateDebug();
 
-private:
-    std::vector< WalkmeshTriangle > m_Triangles;
-};
+        /**
+         * Deletes all the triangles in the walkmesh.
+         */
+        void Clear();
+
+        /**
+         * Adds a triangle to the walkmesh.
+         *
+         * @param triangle[in] Triangle to add.
+         */
+        void AddTriangle(const WalkmeshTriangle& triangle);
+
+        /**
+         * @todo Understand and document.
+         *
+         * @param triangle[in] Triangle.
+         * @param side[in] The side index in the triangle.
+         * @return @todo.
+         */
+        int GetAccessSide(unsigned int triangle_id, unsigned char side) const;
 
+        /**
+         * Retrieves the first side of a triangle.
+         *
+         * @param triangle_id[in] ID of the triangle.
+         * @return The side of the triangle. Ogre::Vector3::ZERO if the
+         * triangle doesn't exist.
+         */
+        const Ogre::Vector3& GetA(unsigned int triangle_id) const;
 
+        /**
+         * Retrieves the second side of a triangle.
+         *
+         * @param triangle_id[in] ID of the triangle.
+         * @return The side of the triangle. Ogre::Vector3::ZERO if the
+         * triangle doesn't exist.
+         */
+        const Ogre::Vector3& GetB(unsigned int triangle_id) const;
+
+        /**
+         * Retrieves the third side of a triangle.
+         *
+         * @param triangle_id[in] ID of the triangle.
+         * @return The side of the triangle. Ogre::Vector3::ZERO if the
+         * triangle doesn't exist.
+         */
+        const Ogre::Vector3& GetC(unsigned int triangle_id) const;
+
+        /**
+         * Counts the triangles in the walkmesh.
+         *
+         * @return The number of triangles in the walkmesh.
+         */
+        int GetNumberOfTriangles() const;
+
+        /**
+         * Locks or unlocks a triangle.
+         *
+         * @param triangle_id[in] ID of the triangle.
+         * @param lock[in] True to lock, false to unlock.
+         */
+        void LockWalkmesh(unsigned int triangle_id, bool lock);
+
+        /**
+         * Checks if a triangle is locked.
+         *
+         * @param triangle_id[in] ID of the trinagle.
+         * @return True if the triangle is locked, false otherwise.
+         */
+        bool IsLocked(unsigned int triangle_id) const;
+
+        /**
+         * Loads a walkmesh from a file.
+         *
+         * @param walkmesh[in] Walkmesh file.
+         */
+        virtual void load(const QGears::WalkmeshFilePtr &walkmesh);
+
+    private:
+
+        /**
+         * The list of triangles.
+         */
+        std::vector<WalkmeshTriangle> triangles_;
+};
 
-#endif // WALKMESH_H

+ 39 - 14
QGearsMain/include/core/XmlBackground2DFile.h

@@ -1,19 +1,44 @@
-#ifndef XML_BACKGROUND_2D_FILE_H
-#define XML_BACKGROUND_2D_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "XmlFile.h"
 
-
-
-class XmlBackground2DFile : public XmlFile
-{
-public:
-    XmlBackground2DFile( const Ogre::String& file );
-    virtual ~XmlBackground2DFile();
-
-    void Load();
+/**
+ * Handles background XML files.
+ */
+class XmlBackground2DFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the file with the background data.
+         */
+        XmlBackground2DFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlBackground2DFile();
+
+        /**
+         * Reads the XML file set on construction and loads the data.
+         */
+        void Load();
 };
 
-
-
-#endif // XML_BACKGROUND_2D_FILE_H

+ 186 - 24
QGearsMain/include/core/XmlFile.h

@@ -1,40 +1,202 @@
-#ifndef XML_FILE_H
-#define XML_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreColourValue.h>
 #include <OgreMatrix4.h>
 #include <OgreString.h>
 #include <Ogre.h>
 #include <Overlay/OgreUTFString.h>
-
 #include <tinyxml.h>
 
+/**
+ * Handles XML files.
+ */
+class XmlFile{
 
 
-class XmlFile
-{
-public:
-    XmlFile( const Ogre::String& file );
-    virtual ~XmlFile();
+    public:
 
-    bool                      GetBool( TiXmlNode* node, const Ogre::String& tag, bool def = false ) const;
-    int                       GetInt( TiXmlNode* node, const Ogre::String& tag, int def = 0 ) const;
-    float                     GetFloat( TiXmlNode* node, const Ogre::String& tag, float def = 0.0f ) const;
-    const Ogre::String        GetString( TiXmlNode* node, const Ogre::String& tag, const Ogre::String& def = "" ) const;
-    const Ogre::UTFString     GetUTFString( TiXmlNode* node, const Ogre::String& tag, const Ogre::UTFString& def = "" ) const;
-    const Ogre::Vector2       GetVector2( TiXmlNode* node, const Ogre::String& tag, const Ogre::Vector2& def = Ogre::Vector2::ZERO ) const;
-    const Ogre::Vector3       GetVector3( TiXmlNode* node, const Ogre::String& tag, const Ogre::Vector3& def = Ogre::Vector3::ZERO  ) const;
-    const Ogre::Vector4       GetVector4( TiXmlNode* node, const Ogre::String& tag, const Ogre::Vector4& def = Ogre::Vector4::ZERO  ) const;
-    const Ogre::Matrix4       GetMatrix4( TiXmlNode* node, const Ogre::String& tag, const Ogre::Matrix4& def = Ogre::Matrix4::IDENTITY ) const;
-    const Ogre::Quaternion    GetQuaternion( TiXmlNode* node, const Ogre::String& tag, const Ogre::Quaternion& def = Ogre::Quaternion::IDENTITY ) const;
-    const Ogre::ColourValue   GetColourValue( TiXmlNode* node, const Ogre::String& tag, const Ogre::ColourValue& def = Ogre::ColourValue::ZERO ) const;
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the XML file.
+         */
+        XmlFile(const Ogre::String& file);
 
-protected:
-    bool m_NormalFile;
+        /**
+         * Destructor.
+         */
+        virtual ~XmlFile();
 
-    TiXmlDocument m_File;
-};
+        /**
+         * Retrieves a boolean from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found or it's
+         * not a boolean value.
+         * @return Boolean value of the tag. If it's not found or it's not a
+         * boolean, def is returned.
+         */
+        bool GetBool(
+          TiXmlNode* node, const Ogre::String& tag, bool def = false
+        ) const;
+
+        /**
+         * Retrieves an integer from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found or it's
+         * not a numeric value.
+         * @return Integer value of the tag. If it's not found or it's not a
+         * number, def is returned.
+         */
+        int GetInt(TiXmlNode* node, const Ogre::String& tag, int def = 0) const;
+
+        /**
+         * Retrieves a defcimal from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found or it's
+         * not a numeric value.
+         * @return Decimal value of the tag. If it's not found or it's not a
+         * number, def is returned.
+         */
+        float GetFloat(
+          TiXmlNode* node, const Ogre::String& tag, float def = 0.0f
+        ) const;
+
+        /**
+         * Retrieves a string from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found.
+         * @return String value of the tag. If it's not found, def is returned.
+         */
+        const Ogre::String GetString(
+          TiXmlNode* node, const Ogre::String& tag, const Ogre::String& def = ""
+        ) const;
+
+        /**
+         * Retrieves a string from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found.
+         * @return String value of the tag, in UFT8. If not found, def is
+         * returned.
+         */
+        const Ogre::UTFString GetUTFString(
+          TiXmlNode* node, const Ogre::String& tag,
+          const Ogre::UTFString& def = ""
+        ) const;
 
+        /**
+         * Retrieves a 2-dimensional vector from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found.
+         * @return Vector in the tag. If it's not found, def is returned.
+         */
+        const Ogre::Vector2 GetVector2(
+          TiXmlNode* node, const Ogre::String& tag,
+          const Ogre::Vector2& def = Ogre::Vector2::ZERO
+        ) const;
 
+        /**
+         * Retrieves a 3-dimensional vector from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found.
+         * @return Vector in the tag. If it's not found, def is returned.
+         */
+        const Ogre::Vector3 GetVector3(
+          TiXmlNode* node, const Ogre::String& tag,
+          const Ogre::Vector3& def = Ogre::Vector3::ZERO
+        ) const;
 
-#endif // XML_FILE_H
+        /**
+         * Retrieves a 4-dimensional vector from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found.
+         * @return Vector in the tag. If it's not found, def is returned.
+         */
+        const Ogre::Vector4 GetVector4(
+          TiXmlNode* node, const Ogre::String& tag,
+          const Ogre::Vector4& def = Ogre::Vector4::ZERO
+        ) const;
+
+        /**
+         * Retrieves a 4-dimensional matrix from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found.
+         * @return The matrix in the tag. If it's not found, def is returned.
+         */
+        const Ogre::Matrix4 GetMatrix4(
+          TiXmlNode* node, const Ogre::String& tag,
+          const Ogre::Matrix4& def = Ogre::Matrix4::IDENTITY
+        ) const;
+
+        /**
+         * Retrieves a quaternion from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found.
+         * @return Quaternion in the tag. If it's not found, def is returned.
+         */
+        const Ogre::Quaternion GetQuaternion(
+          TiXmlNode* node, const Ogre::String& tag,
+          const Ogre::Quaternion& def = Ogre::Quaternion::IDENTITY
+        ) const;
+
+        /**
+         * Retrieves a colour from an XMl tag.
+         *
+         * @param node[in] The XML node.
+         * @param tag[in] The name of the tag.
+         * @param def[in] Default value, in case the tag is not found.
+         * @return Colour in the tag. If it's not found, def is returned.
+         */
+        const Ogre::ColourValue GetColourValue(
+          TiXmlNode* node, const Ogre::String& tag,
+          const Ogre::ColourValue& def = Ogre::ColourValue::ZERO
+        ) const;
+
+    protected:
+
+        /**
+         * Indicates if the file is a normal file.
+         *
+         * @todo As opposed to what?
+         */
+        bool normal_file_;
+
+        /**
+         * The XML file.
+         */
+        TiXmlDocument file_;
+};

+ 39 - 15
QGearsMain/include/core/XmlFontFile.h

@@ -1,20 +1,44 @@
-#ifndef XML_FONT_FILE_H
-#define XML_FONT_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "UiWidget.h"
 #include "XmlFile.h"
 
-
-
-class XmlFontFile : public XmlFile
-{
-public:
-    explicit XmlFontFile( const Ogre::String& file );
-    virtual ~XmlFontFile();
-
-    void LoadFont();
+/**
+ * Handles an XML font file.
+ */
+class XmlFontFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the XMl file with the font data.
+         */
+        explicit XmlFontFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlFontFile();
+
+        /**
+         * Parses the XML file and loads the font data.
+         */
+        void LoadFont();
 };
-
-
-
-#endif // XML_FONT_FILE_H

+ 39 - 15
QGearsMain/include/core/XmlFontsFile.h

@@ -1,19 +1,43 @@
-#ifndef XML_FONTS_FILE_H
-#define XML_FONTS_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "XmlFile.h"
 
-
-
-class XmlFontsFile : public XmlFile
-{
-public:
-    XmlFontsFile( const Ogre::String& file );
-    virtual ~XmlFontsFile();
-
-    void LoadFonts();
+/**
+ * Handles the fonts main file.
+ */
+class XmlFontsFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the XMl file with the font data.
+         */
+        XmlFontsFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlFontsFile();
+
+        /**
+         * Parses the XML file and loads the fonts.
+         */
+        void LoadFonts();
 };
-
-
-
-#endif // XML_FONTS_FILE_H

+ 48 - 16
QGearsMain/include/core/XmlMapFile.h

@@ -1,20 +1,52 @@
-#ifndef XML_MAP_FILE_H
-#define XML_MAP_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "XmlFile.h"
 
-
-
-class XmlMapFile : public XmlFile
-{
-public:
-    explicit XmlMapFile( const Ogre::String& file );
-    virtual ~XmlMapFile();
-
-    void LoadMap();
-    const Ogre::String GetWalkmeshFileName();
+/**
+ * Handles XML map files.
+ */
+class XmlMapFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the XML map file.
+         */
+        explicit XmlMapFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlMapFile();
+
+        /**
+         * Parses the file and loads the map data.
+         */
+        void LoadMap();
+
+        /**
+         * Retrieves the path to the map walkmesh file.
+         *
+         * @return The path to the map walkmesh file. If there is no walkmesh
+         * associated to the map, an error  message will be written to console
+         * and an empty string will be returned.
+         */
+        const Ogre::String GetWalkmeshFileName();
 };
-
-
-
-#endif // XML_MAP_FILE_H

+ 51 - 17
QGearsMain/include/core/XmlMapsFile.h

@@ -1,22 +1,56 @@
-#ifndef XML_MAPS_FILE_H
-#define XML_MAPS_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreStringVector.h>
-
 #include "XmlFile.h"
 
-
-
-class XmlMapsFile : public XmlFile
-{
-public:
-    XmlMapsFile( const Ogre::String& file );
-    virtual ~XmlMapsFile();
-
-    const Ogre::String GetMapFileNameByName( const Ogre::String& name );
-    void GetMapNames( Ogre::StringVector& complete_params );
+/**
+ * Handles the main maps file.
+ */
+class XmlMapsFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the maps file.
+         */
+        XmlMapsFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlMapsFile();
+
+        /**
+         * Retrieves a map file by map name.
+         *
+         * @param name[in] Name of the map to look for.
+         * @return Path to the specified map file, or an empty string if there
+         * is no file for such map.
+         */
+        const Ogre::String GetMapFileNameByName(const Ogre::String& name);
+
+        /**
+         * Retrieves a list of map names.
+         *
+         * @param complete_params[out] The list of map names will be loaded
+         * here.
+         */
+        void GetMapNames(Ogre::StringVector& complete_params);
 };
-
-
-
-#endif // XML_FIELD_FILE_H

+ 39 - 15
QGearsMain/include/core/XmlMusicsFile.h

@@ -1,19 +1,43 @@
-#ifndef XML_MUSICS_FILE_H
-#define XML_MUSICS_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "XmlFile.h"
 
-
-
-class XmlMusicsFile : public XmlFile
-{
-public:
-    XmlMusicsFile( const Ogre::String& file );
-    virtual ~XmlMusicsFile();
-
-    void LoadMusics();
+/**
+ * Handles tha main musics file.
+ */
+class XmlMusicsFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the main musics file.
+         */
+        XmlMusicsFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlMusicsFile();
+
+        /**
+         * Parses the file and loads the musics.
+         */
+        void LoadMusics();
 };
-
-
-
-#endif // XML_MUSICS_FILE_H

+ 41 - 15
QGearsMain/include/core/XmlPrototypesFile.h

@@ -1,19 +1,45 @@
-#ifndef XML_PROTOTYPES_FILE_H
-#define XML_PROTOTYPES_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "XmlFile.h"
 
-
-
-class XmlPrototypesFile : public XmlFile
-{
-public:
-    XmlPrototypesFile( const Ogre::String& file );
-    virtual ~XmlPrototypesFile();
-
-    void LoadPrototypes();
+/**
+ * Handles the main prototypes file.
+ *
+ * @tpdp What are prototypes? What's in the file?
+ */
+class XmlPrototypesFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the main prototypes file.
+         */
+        XmlPrototypesFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlPrototypesFile();
+
+        /**
+         * Parses the file and loads the prototypes.
+         */
+        void LoadPrototypes();
 };
-
-
-
-#endif // XML_PROTOTYPES_FILE_H

+ 50 - 16
QGearsMain/include/core/XmlScreenFile.h

@@ -1,21 +1,55 @@
-#ifndef XML_SCREEN_FILE_H
-#define XML_SCREEN_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "UiWidget.h"
 #include "XmlFile.h"
 
-
-
-class XmlScreenFile : public XmlFile
-{
-public:
-    explicit XmlScreenFile( const Ogre::String& file );
-    virtual ~XmlScreenFile();
-
-    void LoadScreen();
-    void LoadScreenRecursive( TiXmlNode* node, const Ogre::String& base_name, UiWidget* widget );
+/**
+ * Handles a screen file
+ */
+class XmlScreenFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the XMl screen file.
+         */
+        explicit XmlScreenFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlScreenFile();
+
+        /**
+         * Parses the file and loads the screen data.
+         */
+        void LoadScreen();
+
+        /**
+         * Parses a XML node and recursively loads all of it's components.
+         *
+         * @param node[in] Node to parse.
+         * @param base_name[in] Name for the top widget in the XML node.
+         * @param widget[in] Top parent widget.
+         */
+        void LoadScreenRecursive(
+          TiXmlNode* node, const Ogre::String& base_name, UiWidget* widget
+        );
 };
-
-
-
-#endif // XML_SCREEN_FILE_H

+ 39 - 15
QGearsMain/include/core/XmlScreensFile.h

@@ -1,19 +1,43 @@
-#ifndef XML_SCREENS_FILE_H
-#define XML_SCREENS_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "XmlFile.h"
 
-
-
-class XmlScreensFile : public XmlFile
-{
-public:
-    XmlScreensFile( const Ogre::String& file );
-    virtual ~XmlScreensFile();
-
-    void LoadScreens();
+/**
+ * Handles the main screens file.
+ */
+class XmlScreensFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the mian screens file.
+         */
+        XmlScreensFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlScreensFile();
+
+        /**
+         * Parses the file and loads the screens.
+         */
+        void LoadScreens();
 };
-
-
-
-#endif // XML_SCREENS_FILE_H

+ 39 - 15
QGearsMain/include/core/XmlScriptsFile.h

@@ -1,19 +1,43 @@
-#ifndef XML_SCRIPTS_FILE_H
-#define XML_SCRIPTS_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "XmlFile.h"
 
-
-
-class XmlScriptsFile : public XmlFile
-{
-public:
-    XmlScriptsFile( const Ogre::String& file );
-    virtual ~XmlScriptsFile();
-
-    void LoadScripts();
+/**
+ * Handles the main scripts file
+ */
+class XmlScriptsFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the mian scripts file.
+         */
+        XmlScriptsFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlScriptsFile();
+
+        /**
+         * Parses the file and loads the scripts.
+         */
+        void LoadScripts();
 };
-
-
-
-#endif // XML_SCRIPTS_FILE_H

+ 39 - 15
QGearsMain/include/core/XmlTextFile.h

@@ -1,19 +1,43 @@
-#ifndef XML_TEXT_FILE_H
-#define XML_TEXT_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "XmlFile.h"
 
-
-
-class XmlTextFile : public XmlFile
-{
-public:
-    XmlTextFile( const Ogre::String& file );
-    virtual ~XmlTextFile();
-
-    void LoadTexts();
+/**
+ * Handles a text file.
+ */
+class XmlTextFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the text file
+         */
+        XmlTextFile(const Ogre::String& file);
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlTextFile();
+
+        /**
+         * Parses the file and loads the text.
+         */
+        void LoadTexts();
 };
-
-
-
-#endif // XML_TEXT_FILE_H

+ 44 - 12
QGearsMain/include/core/XmlTextsFile.h

@@ -1,19 +1,51 @@
-#ifndef XML_TEXTS_FILE_H
-#define XML_TEXTS_FILE_H
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include "XmlFile.h"
+#pragma once
 
 #include <OgreStringVector.h>
+#include "XmlFile.h"
 
+/**
+ * Handles the main text file/
+ */
+class XmlTextsFile : public XmlFile{
 
-class XmlTextsFile : public XmlFile
-{
-public:
-    XmlTextsFile( const Ogre::String& file );
-    virtual ~XmlTextsFile();
+    public:
 
-    void GetAvailableLanguages( Ogre::StringVector& languages );
-    void LoadTexts();
-};
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the main texts file.
+         */
+        XmlTextsFile(const Ogre::String& file);
 
-#endif // XML_TEXTS_FILE_H
+        /**
+         * Destructor.
+         */
+        virtual ~XmlTextsFile();
+
+        /**
+         * Retrieves a list of all the available text languages.
+         *
+         * @param languages[out] The list of languages will be loaded here.
+         */
+        void GetAvailableLanguages(Ogre::StringVector& languages);
+
+        /**
+         * Parses the file and loads all of it's texts.
+         */
+        void LoadTexts();
+};

+ 39 - 16
QGearsMain/include/core/XmlWalkmeshFile.h

@@ -1,19 +1,42 @@
-#ifndef XML_WALKMESH_FILE_H
-#define XML_WALKMESH_FILE_H
-
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 #include "XmlFile.h"
 
-
-
-class XmlWalkmeshFile : public XmlFile
-{
-public:
-    XmlWalkmeshFile( const Ogre::String& file );
-    virtual ~XmlWalkmeshFile();
-
-    void Load();
+/**
+ * Handles a walkmesh file.
+ */
+class XmlWalkmeshFile : public XmlFile{
+
+    public:
+
+        /**
+         * Constructor.
+         *
+         * @param file[in] Path to the walkmesh file.
+         */
+        XmlWalkmeshFile( const Ogre::String& file );
+
+        /**
+         * Destructor.
+         */
+        virtual ~XmlWalkmeshFile();
+
+        /**
+         * Parses the file and loads the walkmesh data.
+         */
+        void Load();
 };
-
-
-
-#endif // XML_WALKMESH_FILE_H

+ 154 - 61
QGearsMain/include/data/QGearsAFile.h

@@ -1,73 +1,166 @@
 /*
------------------------------------------------------------------------------
-Copyright (c) 15.1.2013 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-This file is part of Q-Gears
-
-Q-Gears is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 2.0 (GPLv2) of the License.
-
-Q-Gears is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsAFile_H__
-#define __QGearsAFile_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreSkeleton.h>
 #include <Ogre.h>
-
 #include "common/TypeDefine.h"
 #include "common/QGearsResource.h"
 
-namespace QGears
-{
-    class AFile : public Resource
-    {
-    public:
-
-        AFile( Ogre::ResourceManager *creator, const String &name
-              ,Ogre::ResourceHandle handle, const String &group
-              ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
-
-        virtual ~AFile();
-
-        static const Ogre::Real FRAME_DURATION;
-        static const String     RESOURCE_TYPE;
-
-        void addTo( Ogre::SkeletonPtr skeleton, const String &name ) const;
-
-        typedef std::vector<Ogre::Vector3>  BoneRotationList;
-
-        struct Frame
-        {
-            Ogre::Vector3       root_rotation;
-            Ogre::Vector3       root_translation;
-            BoneRotationList    bone_rotations;
-        };
-
-        typedef std::vector<Frame>  FrameList;
-        FrameList&  getFrames() { return m_frames; }
-
-        void    setBoneCount( const uint32 bone_count );
-
-    protected:
-        virtual void loadImpl() override final;
-        virtual void unloadImpl() override final;
-        size_t calculateSize() const;
-
-        void    setFrameRotation( Ogre::TransformKeyFrame *key_frame
-                                         ,const Ogre::Vector3 &rotation ) const;
-
-    private:
-        uint32      m_bone_count;
-        FrameList   m_frames;
+namespace QGears{
+
+    /**
+     * Handles A files.
+     *
+     * A files are files with skeleton animation data.
+     */
+    class AFile : public Resource{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param creator[in] Pointer to the ResourceManager that is
+             * creating this resource.
+             * @param name[in] The unique name of the resource.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             */
+            AFile(
+              Ogre::ResourceManager *creator, const String &name,
+              Ogre::ResourceHandle handle, const String &group,
+              bool is_manual = false, Ogre::ManualResourceLoader *loader = NULL
+            );
+
+            /**
+             * Destructor.
+             */
+            virtual ~AFile();
+
+            /**
+             * Duration of a frame.
+             */
+            static const Ogre::Real FRAME_DURATION;
+
+            /**
+             * The type of resource.
+             */
+            static const String RESOURCE_TYPE;
+
+            /**
+             * Adds an animation to an skeleton.
+             *
+             * @parma skeleton[in|out] Skeleton to add the animation to.
+             * @param name[in] Animation name.
+             */
+            void AddTo(Ogre::SkeletonPtr skeleton, const String &name) const;
+
+            typedef std::vector<Ogre::Vector3> BoneRotationList;
+
+            /**
+             * A frame in an animation.
+             */
+            struct Frame{
+
+                /**
+                 * The rotation of the whole skeleton in the frame.
+                 */
+                Ogre::Vector3 root_rotation;
+
+                /**
+                 * The translation of the whole skeleton in the frame.
+                 */
+                Ogre::Vector3 root_translation;
+
+                /**
+                 * The list of individual bone rotations in the frame.
+                 */
+                BoneRotationList bone_rotations;
+            };
+
+            typedef std::vector<Frame> FrameList;
+
+            /**
+             * Retrieves the list of frames in the file.
+             *
+             * @return The list of frames.
+             */
+            FrameList& GetFrames(){return frames_;}
+
+            /**
+             * Sets the number of bones.
+             *
+             * @param bone_count[in] The number of bones.
+             */
+            void SetBoneCount(const uint32 bone_count);
+
+        protected:
+
+            /**
+             * Loads the file.
+             */
+            virtual void loadImpl() override final;
+
+            /**
+             * Unloads the file.
+             */
+            virtual void unloadImpl() override final;
+
+            /**
+             * Calculates the size of the file.
+             *
+             * @return The size of the file.
+             * @todo Units?
+             */
+            size_t CalculateSize() const;
+
+            /**
+             * Sets the rotation for a frame.
+             *
+             * @param key_frame[in] The frame.
+             * @param rotation[in] The rotation for the frame
+             */
+            void SetFrameRotation(
+              Ogre::TransformKeyFrame *key_frame,
+              const Ogre::Vector3 &rotation
+            ) const;
+
+        private:
+
+            /**
+             * The number of bones.
+             */
+            uint32 bone_count_;
+
+            /**
+             * The list of frames.
+             */
+            FrameList frames_;
     };
 
     typedef Ogre::SharedPtr<AFile> AFilePtr;
 }
 
-#endif // __QGearsAFile_H__

+ 67 - 33
QGearsMain/include/data/QGearsAFileManager.h

@@ -1,46 +1,80 @@
 /*
------------------------------------------------------------------------------
-Copyright (c) 15.10.2013 Tobias Peters <tobias.peters@kreativeffekt.at>
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-This file is part of Q-Gears
-
-Q-Gears is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 2.0 (GPLv2) of the License.
-
-Q-Gears is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-GNU General Public License for more details.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsAFileManager_H__
-#define __QGearsAFileManager_H__
+#pragma once
 
 #include <OgreResourceManager.h>
-
 #include "QGearsPrerequisites.h"
-
 #include "QGearsAFile.h"
 
-namespace QGears
-{
-    class _QGearsExport AFileManager : public Ogre::ResourceManager, public Ogre::Singleton<AFileManager>
+namespace QGears{
+
+    /**
+     * A manager for A files.
+     */
+    class _QGearsExport AFileManager :
+      public Ogre::ResourceManager, public Ogre::Singleton<AFileManager>
     {
-    public:
-        AFileManager();
-        virtual ~AFileManager();
 
-        static AFileManager& getSingleton();
-        static AFileManager* getSingletonPtr();
+        public:
+
+            /**
+             * Constructor.
+             */
+            AFileManager();
 
-    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 final;
+            /**
+             * Destructor.
+             */
+            virtual ~AFileManager();
+
+            /**
+             * Retrieves a singleton to the manager.
+             */
+            static AFileManager& GetSingleton();
+
+            /**
+             * Retrieves a pointer to the manager singleton.
+             */
+            static AFileManager* GetSingletonPtr();
+
+        protected:
+
+            /**
+             * Loads the manager.
+             *
+             * @param name[in] The unique name of the manager.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             * @param create_params[in] Unused.
+             */
+            virtual Ogre::Resource *createImpl(
+              const Ogre::String &name, Ogre::ResourceHandle handle,
+              const Ogre::String &group, bool is_manual,
+              Ogre::ManualResourceLoader *loader,
+              const Ogre::NameValuePairList *create_params
+            ) override final;
 
-    private:
     };
 }
-
-#endif // __QGearsAFileManager_H__

+ 108 - 56
QGearsMain/include/data/QGearsAFileSerializer.h

@@ -1,66 +1,118 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-10 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsAFileSerializer_H__
-#define __QGearsAFileSerializer_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "common/TypeDefine.h"
 #include "QGearsAFile.h"
 #include "QGearsSerializer.h"
 
-namespace QGears
-{
-    class AFileSerializer : public Serializer
-    {
-    public:
-                        AFileSerializer();
-        virtual        ~AFileSerializer();
-
-        void    importAFile( Ogre::DataStreamPtr &stream, AFile* pDest );
-
-        struct Header
-        {
-            uint32 version;
-            uint32 frame_count;
-            uint32 bone_count;
-            uint32 rotation_order;
-            uint32 runtime_data[5];
-        };
+namespace QGears{
 
-    protected:
-        virtual void    readFileHeader( Ogre::DataStreamPtr &stream ) final;
-        void    readObject( Ogre::DataStreamPtr &stream, AFile::Frame &pDest );
-        using Serializer::readObject;
+    /**
+     * Handles the serialization of A files.
+     */
+    class AFileSerializer : public Serializer{
 
-        template<typename ValueType>
-        void readVector( Ogre::DataStreamPtr &stream
-                        ,std::vector<ValueType> &pDest, size_t count );
+        public:
 
-    private:
-        Header  m_header;
-    };
-}
+            /**
+             * Constructor.
+             */
+            AFileSerializer();
+
+            /**
+             * Destructor.
+             */
+            virtual ~AFileSerializer();
+
+            /**
+             * Imports an A file.
+             *
+             * @param stream[in] The contents of the A file.
+             * @param dest[out] The A file.
+             */
+            void ImportAFile(Ogre::DataStreamPtr &stream, AFile* dest);
+
+            /**
+             * An A file header.
+             */
+            struct Header{
+
+                /**
+                 * The file type version.
+                 */
+                uint32 version;
+
+                /**
+                 * The frame count.
+                 */
+                uint32 frame_count;
+
+                /**
+                 * The number of bones.
+                 */
+                uint32 bone_count;
+
+                /**
+                 * The axis rotation order.
+                 */
+                uint32 rotation_order;
 
-#endif // __QGearsAFileSerializer_H__
+                /**
+                 * @todo Understand and document.
+                 */
+                uint32 runtime_data[5];
+            };
+
+        protected:
+
+            /**
+             * Reads a file header and sets the instance data.
+             *
+             * @param stream[in] The contents of the A file.
+             */
+            virtual void ReadFileHeader(Ogre::DataStreamPtr &stream) final;
+
+            /**
+             * Reads an object as an A file.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed A file.
+             */
+            void readObject(Ogre::DataStreamPtr &stream, AFile::Frame &dest);
+
+            using Serializer::readObject;
+
+            /**
+             * Reads a stream as a vector.
+             *
+             * @param stream[in] The input stream.
+             * @param dest[out] The vector data will be loaded here.
+             * @param count[in] Data units to copy.
+             */
+            template<typename ValueType> void ReadVector(
+              Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
+              size_t count
+            );
+
+        private:
+
+            /**
+             * The file header.
+             */
+            Header header_;
+        };
+}

+ 401 - 130
QGearsMain/include/data/QGearsBackgroundFile.h

@@ -1,143 +1,414 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-19 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsBackgroundFile_H__
-#define __QGearsBackgroundFile_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
+#pragma once
+
+#include <array>
 #include <OgreResource.h>
 #include <OgreImage.h>
 #include <Ogre.h>
-
 #include "common/TypeDefine.h"
 #include "data/QGearsPaletteFile.h"
 
-#include <array>
+namespace QGears{
+
+    // TODO inherit from QGears Resource.
+
+    /**
+     * A background file representation.
+     */
+    class BackgroundFile : public Ogre::Resource{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param creator[in] Pointer to the ResourceManager that is
+             * creating this resource.
+             * @param name[in] The unique name of the resource.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             */
+            BackgroundFile(
+              Ogre::ResourceManager *creator, const String &name,
+              Ogre::ResourceHandle handle, const String &group,
+              bool is_manual = false, Ogre::ManualResourceLoader *loader = NULL
+            );
+
+            /**
+             * Destructor.
+             */
+            virtual ~BackgroundFile();
+
+            /**
+             * The type of resource.
+             */
+            static const String RESOURCE_TYPE;
+
+            enum {
+
+                /**
+                 * Width of the background page, in pixels.
+                 *
+                 * Same as {@see PAGE_DATAH_EIGHT}.
+                 */
+                PAGE_DATA_WIDTH = 256,
+
+                /**
+                 * Height of the background page, in pixels.
+                 *
+                 * Same as {@see PAGE_DATA_WIDTH}.
+                 */
+                PAGE_DATA_HEIGHT = PAGE_DATA_WIDTH,
+
+                /**
+                 * Size of the background page, in pixels.
+                 *
+                 * Same as {@see PAGE_DATA_WIDTH} * {@see PAGE_DATA_HEIGHT}.
+                 */
+                PAGE_DATA_SIZE = PAGE_DATA_WIDTH * PAGE_DATA_HEIGHT,
+
+                /**
+                 * Width of sprites, in pixels.
+                 *
+                 * Same as {@see SPRITE_HEIGHT}.
+                 */
+                SPRITE_WIDTH = 16,
+
+                /**
+                 * Height of sprites, in pixels.
+                 *
+                 * Same as {@see SPRITE_WIDTH}.
+                 */
+                SPRITE_HEIGHT = SPRITE_WIDTH,
+
+                /**
+                 * Size of sprites, in pixels.
+                 *
+                 * Same as {@see SPRITE_WIDTH} * {@see SPRITE_HEIGHT}.
+                 */
+                SPRITE_PIXEL_COUNT = SPRITE_WIDTH * SPRITE_HEIGHT,
+
+                /**
+                 * Number of layers in a background.
+                 */
+                LAYER_COUNT = 4,
+
+                /**
+                 * Number of palettes in a background.
+                 */
+                PALETTE_ENTRY_COUNT = 20,
+
+                /**
+                 * Number of pages in a background.
+                 *
+                 * @todo What are pages?
+                 */
+                PAGE_COUNT = 42
+            };
+
+            /**
+             * Data for sprites.
+             */
+            struct SpriteData{
+
+                /**
+                 * Pixel destination.
+                 */
+                Pixel dst;
+
+                /**
+                 * Unused data.
+                 */
+                uint16 unknown_04[2];
+
+                /**
+                 * Pixel source.
+                 */
+                Pixel src;
+
+                /**
+                 * Pixel alternate source.
+                 *
+                 * Used for special effects pages, when data_page2 != 0, it
+                 * must be used instead of {@see src}.
+                 */
+                Pixel src2;
+
+                /**
+                 * Sprite width.
+                 */
+                uint16 width;
+
+                /**
+                 * Sprite height.
+                 */
+                uint16 height;
+
+                /**
+                 * Palete page for the sprite
+                 */
+                uint16 palette_page;
+
+                /**
+                 * Sprite depth (Z-index).
+                 */
+                uint16 depth;
+
+                /**
+                 * Animation ID of the sprite.
+                 */
+                uint8 animation_id;
+
+                /**
+                 * Animation frame of the sprite.
+                 */
+                uint8 animation_frame;
+
+                /**
+                 * Indicates if the sprite uses color blending.
+                 */
+                bool has_blending[2];
+
+                /**
+                 * The type of blending used.
+                 */
+                uint16 blending;
+
+                /**
+                 * The page with the sprite data.
+                 */
+                uint16 data_page;
+
+                /**
+                 * Page with alternate sprite data.
+                 *
+                 * Used for special effects pages. When data_page2 != 0, it
+                 * must be used instead of {@see data_page}.
+                 */
+                uint16 data_page2;
+
+                /**
+                 * Color depth.
+                 *
+                 * Do not use. Use texture page depth instead.
+                 */
+                uint16 colour_depth;
 
-namespace QGears
-{
-    // TODO inherit from Qgears Ressource
-    class BackgroundFile : public Ogre::Resource
-    {
-    public:
-
-        BackgroundFile( Ogre::ResourceManager *creator, const String &name
-              ,Ogre::ResourceHandle handle, const String &group
-              ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
-
-        virtual ~BackgroundFile();
-
-        static const String RESOURCE_TYPE;
-
-        enum {
-            PAGE_DATA_WIDTH     = 256
-           ,PAGE_DATA_HEIGHT    = PAGE_DATA_WIDTH
-           ,PAGE_DATA_SIZE      = PAGE_DATA_WIDTH * PAGE_DATA_HEIGHT
-           ,SPRITE_WIDTH        = 16
-           ,SPRITE_HEIGHT       = SPRITE_WIDTH
-           ,SPRITE_PIXEL_COUNT  = SPRITE_WIDTH * SPRITE_HEIGHT
-           ,LAYER_COUNT         = 4
-           ,PALETTE_ENTRY_COUNT = 20
-           ,PAGE_COUNT          = 42
-        };
-
-        struct SpriteData
-        {
-            Pixel dst;
-            uint16 unknown_04[2]; // Unused
-            Pixel src;
-            Pixel src2; // used for special effects pages, when data_page2 != 0, it must be used instead of src
-            uint16 width;
-            uint16 height;
-
-            uint16 palette_page;
-            uint16 depth; // <=> Z
-            uint8  animation_id;
-            uint8  animation_frame;
-            bool   has_blending[2];
-            uint16 blending;
-            uint16 data_page;
-            uint16 data_page2; // used for special effects pages, when data_page2 != 0, it must be used instead of data_page
-            uint16 colour_depth; // Use texture page depth instead
-            Ogre::Vector3 src_big; // For PC use (z = unknown, x = srcX / 16 * 625000, y = srcY / 16 * 625000)
-        };
-
-
-        typedef std::vector<SpriteData> SpriteList;
-        typedef std::vector<SpriteData*> SpritePtrList;
-
-        struct Layer
-        {
-            bool enabled;
-            uint16 width;
-            uint16 height;
-            // uint16 sprite_count only read in serializer
-            uint16 unknown_06; // unused in layer0
-            uint16 unknown_08[3]; // layer 1,2,3
-            uint16 unknown_0E[4]; // layer   2,3
-            SpriteList sprites;
-        };
-
-        typedef PaletteFile::Color Color;
-
-        typedef std::vector<uint8> Buffer;
-        typedef std::vector<Color> Colors;
-
-        struct Page
-        {
-            bool enabled; // only read further if this is > 0
-            uint16 unknown_02;
-            uint16 value_size;
-            // uint8 if value_size == 1, uint16 if value_size == 2
-            //uint8 data[PAGE_DATA_WIDTH][PAGE_DATA_HEIGHT];
-            Buffer data;
-            Colors colors;
-        };
-
-        std::array<Layer, LAYER_COUNT>& getLayers(void) { return m_layers; }
-        std::array<uint8, PALETTE_ENTRY_COUNT>& getPalette(void) { return m_palette; }
-        std::array<Page, PAGE_COUNT>&  getPages(void) { return m_pages; }
-
-        Ogre::Image*        createImage     ( const PaletteFilePtr &palette );
-
-        void addAllSprites( SpritePtrList& sprites ) ;
-
-    protected:
-        virtual void loadImpl();
-        virtual void unloadImpl();
-        virtual size_t calculateSize() const;
-        virtual size_t calculateSize( const Layer &layer ) const;
-        virtual size_t calculateSize( const Page  &page  ) const;
-
-    private:
-        std::array<Layer, LAYER_COUNT> m_layers;
-        std::array<uint8, PALETTE_ENTRY_COUNT> m_palette;
-
-        std::array<Page, PAGE_COUNT> m_pages;
+                /**
+                 * Sprite source.
+                 *
+                 * For PC use only.
+                 * z = unknown, x = srcX / 16 * 625000, y = srcY / 16 * 625000
+                 */
+                Ogre::Vector3 src_big;
+            };
+
+            typedef std::vector<SpriteData> SpriteList;
+
+            typedef std::vector<SpriteData*> SpritePtrList;
+
+            /**
+             * A layer of a background.
+             */
+            struct Layer{
+
+                /**
+                 * Indicates if the layer is used.
+                 */
+                bool enabled;
+
+                /**
+                 * Layer width.
+                 */
+                uint16 width;
+
+                /**
+                 * Layer height.
+                 */
+                uint16 height;
+                /**
+                 * Unknown.
+                 *
+                 * uint16 sprite_count only read in serializer. Unused in layer
+                 * 0.
+                 */
+                uint16 unknown_06;
+
+                /**
+                 * Unknown.
+                 *
+                 * Used in layers 1, 2 and 3
+                 */
+                uint16 unknown_08[3];
+
+                /**
+                 * Unknown.
+                 *
+                 * Used in layers 2 and 3
+                 */
+                uint16 unknown_0E[4];
+
+                /**
+                 * List of sprites in the layer.
+                 */
+                SpriteList sprites;
+            };
+
+            typedef PaletteFile::Color Color;
+
+            typedef std::vector<uint8> Buffer;
+
+            typedef std::vector<Color> Colors;
+
+            /**
+             * A background page/
+             */
+            struct Page{
+
+                /**
+                 * Indicates if the page is used.
+                 */
+                bool enabled;
+
+                /**
+                 * Unknown data.
+                 */
+                uint16 unknown_02;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                uint16 value_size;
+
+                // //uint8 if value_size == 1, uint16 if value_size == 2
+                // uint8 data[PAGE_DATA_WIDTH][PAGE_DATA_HEIGHT];
+
+                /**
+                 * Data buffer.
+                 */
+                Buffer data;
+
+                /**
+                 * Background color list.
+                 */
+                Colors colors;
+            };
+
+            /**
+             * Retrieves the background layers.
+             *
+             * @return The list of layers.
+             */
+            std::array<Layer, LAYER_COUNT>& GetLayers(void) {return layers_;}
+
+            /**
+             * Retrieves the background palette.
+             *
+             * @return The palette.
+             */
+            std::array<uint8, PALETTE_ENTRY_COUNT>& GetPalette(void) {
+                return palette_;
+            }
+
+            /**
+             * Retrieves the background pages.
+             *
+             * @return The background pages.
+             */
+            std::array<Page, PAGE_COUNT>& GetPages(void){return pages_;}
+
+            /**
+             * Creates an image from a palette.
+             *
+             * @param palette[in] The color palette for the image.
+             * @return The image.
+             */
+            Ogre::Image* CreateImage(const PaletteFilePtr &palette);
+
+            /**
+             * Adds all sprites to the background.
+             *
+             * @param sprites[in] The list of sprites to add.
+             */
+            void AddAllSprites(SpritePtrList& sprites) ;
+
+        protected:
+
+            /**
+             * Loads the file.
+             */
+            virtual void loadImpl() override final;
+
+            /**
+             * Unloads the file.
+             */
+            virtual void unloadImpl() override final;
+
+            /**
+             * Calculates the size of the background.
+             *
+             * It includes all layers and pages.
+             *
+             * @return The total size of the background, in bytes.
+             */
+            virtual size_t CalculateSize() const;
+
+            /**
+             * Calculates the size of a background layer.
+             *
+             * @param layer[in] The layer to calculate size from.
+             * @return The total size of the background layer, in bytes.
+             */
+            virtual size_t CalculateSize(const Layer &layer) const;
+
+            /**
+             * Calculates the size of a background page.
+             *
+             * @param page[in] The layer to calculate size from.
+             * @return The total size of the background page, in bytes.
+             */
+            virtual size_t CalculateSize(const Page &page) const;
+
+        private:
+
+            /**
+             * The list of layers.
+             */
+            std::array<Layer, LAYER_COUNT> layers_;
+
+            /**
+             * The color palette.
+             */
+            std::array<uint8, PALETTE_ENTRY_COUNT> palette_;
+
+            /**
+             * The background pages.
+             */
+            std::array<Page, PAGE_COUNT> pages_;
     };
 
     typedef Ogre::SharedPtr<BackgroundFile> BackgroundFilePtr;
 }
-
-#endif // __QGearsBackgroundFile_H__

+ 68 - 43
QGearsMain/include/data/QGearsBackgroundFileManager.h

@@ -1,55 +1,80 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-17 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsBackgroundFileManager_H__
-#define __QGearsBackgroundFileManager_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResourceManager.h>
+#pragma once
 
+#include <OgreResourceManager.h>
 #include "QGearsPrerequisites.h"
-
 #include "QGearsBackgroundFile.h"
 
-namespace QGears
-{
-    class _QGearsExport BackgroundFileManager : public Ogre::ResourceManager, public Ogre::Singleton<BackgroundFileManager>
+namespace QGears{
+
+    /**
+     * A manager for background files.
+     */
+    class _QGearsExport BackgroundFileManager
+      : public Ogre::ResourceManager,
+        public Ogre::Singleton<BackgroundFileManager>
     {
-    public:
-        BackgroundFileManager();
-        virtual ~BackgroundFileManager();
+        public:
+
+            /**
+             * Constructor.
+             */
+            BackgroundFileManager();
 
-        static BackgroundFileManager& getSingleton();
-        static BackgroundFileManager* getSingletonPtr();
+            /**
+             * Destructor.
+             */
+            virtual ~BackgroundFileManager();
 
-    protected:
-        Ogre::Resource *createImpl( const Ogre::String &name, Ogre::ResourceHandle handle
-          , const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader
-          , const Ogre::NameValuePairList *createParams );
+            /**
+             * Retrieves a singleton to the manager.
+             */
+            static BackgroundFileManager& GetSingleton();
+
+            /**
+             * Retrieves a pointer to the manager singleton.
+             */
+            static BackgroundFileManager* GetSingletonPtr();
+
+        protected:
+
+            /**
+             * Loads the manager.
+             *
+             * @param name[in] The unique name of the manager.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             * @param create_params[in] Unused.
+             */
+            Ogre::Resource *createImpl(
+              const Ogre::String &name, Ogre::ResourceHandle handle,
+              const Ogre::String &group, bool is_manual,
+              Ogre::ManualResourceLoader *loader,
+              const Ogre::NameValuePairList *create_params
+            );
 
-    private:
     };
 }
-
-#endif // __QGearsBackgroundFileManager_H__

+ 257 - 96
QGearsMain/include/data/QGearsBackgroundFileSerializer.h

@@ -1,109 +1,270 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-10 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsBackgroundFileSerializer_H__
-#define __QGearsBackgroundFileSerializer_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include "common/TypeDefine.h"
+#pragma once
 
+#include "common/TypeDefine.h"
 #include "data/QGearsBackgroundFile.h"
 #include "data/QGearsSerializer.h"
 
-namespace QGears
-{
-    class BackgroundFileSerializer : public Serializer
-    {
-    public:
-                        BackgroundFileSerializer();
-        virtual        ~BackgroundFileSerializer();
-
-        void    importBackgroundFile( Ogre::DataStreamPtr &stream, BackgroundFile *pDest );
-
-        enum {
-            BIT_MASK_RED    = 0xF800
-           ,BIT_MASK_GREEN  = 0x07C0
-           ,BIT_MASK_BLUE   = 0x001F
-           ,BIT_SIZE        = 0x001F
-           ,BIT_MASK_RGB    = BIT_MASK_BLUE | BIT_MASK_GREEN | BIT_MASK_RED
-           ,SPRITE_DST_MAX      = 1024
-        };
-
-        struct Header
-        {
-            uint16 unused;
-            uint16 sort_sprites_by_palette;
-        };
-
-        typedef BackgroundFile::Layer       Layer;
-        typedef BackgroundFile::SpriteData  SpriteData;
-        typedef BackgroundFile::SpriteList  SpriteList;
-        typedef BackgroundFile::Page        Page;
-        typedef BackgroundFile::Color       Color;
-
-    protected:
-        virtual void 	readFileHeader( Ogre::DataStreamPtr &stream );
-        virtual void    readSectionHeader( Ogre::DataStreamPtr &stream, const String &section_name );
-
-        virtual void    readPallete( Ogre::DataStreamPtr &stream, BackgroundFile *pDest );
-        virtual void    readBackground( Ogre::DataStreamPtr &stream, BackgroundFile *pDest );
-        virtual void    readTexture( Ogre::DataStreamPtr &stream, BackgroundFile *pDest );
-        virtual void    readEnd( Ogre::DataStreamPtr &stream );
-
-        virtual void    readLayer( Ogre::DataStreamPtr &stream, Layer *pDest, size_t layer_index  );
-
-        virtual void    readObject( Ogre::DataStreamPtr &stream, SpriteData &pDest  );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, Color &pDest  );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, Page &pDest  );
-        using Serializer::readObject;
-
-        template<typename ValueType> void
-        readVector( Ogre::DataStreamPtr &stream, std::vector<ValueType> &pDest, size_t count )
-        {
-            pDest.clear();
-            pDest.reserve( count );
-            for( size_t i( count ); i--; )
-            {
-                ValueType in_tmp;
-                readObject( stream, in_tmp );
-                pDest.push_back( in_tmp );
+namespace QGears{
+
+    /**
+     * Handles the serialization of background files.
+     */
+    class BackgroundFileSerializer : public Serializer{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            BackgroundFileSerializer();
+
+            /**
+             * Destructor.
+             */
+            virtual ~BackgroundFileSerializer();
+
+            /**
+             * Imports a background file.
+             *
+             * @param stream[in] The contents of the background file.
+             * @param dest[out] The background file.
+             */
+            void ImportBackgroundFile(
+              Ogre::DataStreamPtr &stream, BackgroundFile *dest
+          );
+
+            enum {
+
+                /**
+                 * Bitmask for red colour.
+                 */
+                BIT_MASK_RED = 0xF800,
+
+                /**
+                 * Bitmask for green colour.
+                 */
+                BIT_MASK_GREEN = 0x07C0,
+
+                /**
+                 * Bitmask for blue colour.
+                 */
+                BIT_MASK_BLUE = 0x001F,
+
+                /**
+                 * @todo Understand and document.
+                 */
+                BIT_SIZE = 0x001F,
+
+                /**
+                 * Bitmask for RGB colour.
+                 */
+                BIT_MASK_RGB = BIT_MASK_BLUE | BIT_MASK_GREEN | BIT_MASK_RED,
+
+                /**
+                 * @todo Understand and document.
+                 */
+                SPRITE_DST_MAX = 1024
+            };
+
+            /**
+             * A background file header.
+             */
+            struct Header{
+
+                /**
+                 * Unused data.
+                 */
+                uint16 unused;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                uint16 sort_sprites_by_palette;
+            };
+
+            typedef BackgroundFile::Layer Layer;
+
+            typedef BackgroundFile::SpriteData SpriteData;
+
+            typedef BackgroundFile::SpriteList SpriteList;
+
+            typedef BackgroundFile::Page Page;
+
+            typedef BackgroundFile::Color Color;
+
+        protected:
+
+            /**
+             * Reads a background file header.
+             *
+             * @param stream[in] The contents of the header.
+             */
+            virtual void ReadFileHeader(Ogre::DataStreamPtr &stream);
+
+            /**
+             * Reads a section of a background file header.
+             *
+             * @param stream[in] The contents of the header.
+             * @param section_name[in] The name of the section to read.
+             */
+            virtual void ReadSectionHeader(
+              Ogre::DataStreamPtr &stream, const String &section_name
+           );
+
+            /**
+             * Reads pallete data from a background file.
+             *
+             * @param stream[in] Input stream.
+             * @param dest[out] The data will be set on this file.
+             */
+            virtual void ReadPallete(
+              Ogre::DataStreamPtr &stream, BackgroundFile *dest
+            );
+
+            /**
+             * Reads background data from a background file.
+             *
+             * @param stream[in] Input stream.
+             * @param dest[out] The data will be set on this file.
+             */
+            virtual void ReadBackground(
+              Ogre::DataStreamPtr &stream, BackgroundFile *dest
+            );
+
+            /**
+             * Reads texture data from a background file.
+             *
+             * @param stream[in] Input stream.
+             * @param dest[out] The data will be set on this file.
+             */
+            virtual void ReadTexture(
+              Ogre::DataStreamPtr &stream, BackgroundFile *dest
+            );
+
+            /**
+             * @todo Understand and document.
+             *
+             * @param stream[in] Input stream.
+             */
+            virtual void ReadEnd(Ogre::DataStreamPtr &stream);
+
+            /**
+             * Reads a layer from a background file.
+             *
+             * @param stream[in] Input stream.
+             * @param dest[out] The layer info will be loaded here.
+             * @param layer_index[in] Index of the layer to read.
+             */
+            virtual void ReadLayer(
+              Ogre::DataStreamPtr &stream, Layer *dest, size_t layer_index
+            );
+
+            /**
+             * Reads an object as a sprite.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed sprite.
+             */
+            virtual void readObject(
+              Ogre::DataStreamPtr &stream, SpriteData &dest
+            );
+
+            /**
+             * Reads an object as colour data.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed colour data.
+             */
+            virtual void readObject(Ogre::DataStreamPtr &stream, Color &dest);
+
+            /**
+             * Reads an object as a background page.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed page.
+             */
+            virtual void readObject(Ogre::DataStreamPtr &stream, Page &dest);
+
+            using Serializer::readObject;
+
+            /**
+             * Reads a stream as a vector.
+             *
+             * @param stream[in] The input stream.
+             * @param dest[out] The vector data will be loaded here.
+             * @param count[in] Data units to copy.
+             */
+            template<typename ValueType> void ReadVector(
+              Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
+              size_t count
+            ){
+                dest.clear();
+                dest.reserve(count);
+                for(size_t i(count); i --;){
+                    ValueType in_tmp;
+                    readObject(stream, in_tmp);
+                    dest.push_back(in_tmp);
+                }
             }
-        }
 
+            /**
+             * Name of the palette section in the file.
+             */
+            static const String SECTION_NAME_PALETTE;
+
+            /**
+             * Name of the back section in the file.
+             */
+            static const String SECTION_NAME_BACK;
 
-        static const String     SECTION_NAME_PALETTE;
-        static const String     SECTION_NAME_BACK;
-        static const String     SECTION_NAME_TEXTURE;
-        static const String     TAG_FILE_END;
-        static const Ogre::Real src_big_SCALE;
+            /**
+             * Name of the texture section in the file.
+             */
+            static const String SECTION_NAME_TEXTURE;
 
-    private:
-        void removeBuggySprites( SpriteList &sprites );
+            /**
+             * End-of-file tag.
+             */
+            static const String TAG_FILE_END;
 
-        Header  m_header;
-        size_t m_layer_index;
+            /**
+             * @todo Understand and document.
+             */
+            static const Ogre::Real SRC_BIG_SCALE;
+
+        private:
+
+            /**
+             * Removes malformed sprites from the map.
+             *
+             * @param[in|out] The list from which to remove malformed sprites.
+             * @todo Why are they malformed?
+             */
+            void RemoveBuggySprites(SpriteList &sprites);
+
+            /**
+             * The file header.
+             */
+            Header  header_;
+
+            /**
+             * @todo Understand and document.
+             */
+            size_t layer_index_;
     };
 }
-
-#endif // __QGearsBackgroundFileSerializer_H__

+ 47 - 39
QGearsMain/include/data/QGearsBackgroundTextureLoader.h

@@ -1,50 +1,58 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-24 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsBackgroundTextureLoader_H__
-#define __QGearsBackgroundTextureLoader_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreResource.h>
 
-namespace QGears
-{
+namespace QGears{
+
     class BackgroundFile;
 
-    class BackgroundTextureLoader : public Ogre::ManualResourceLoader
-    {
-    public:
-        explicit BackgroundTextureLoader( BackgroundFile &background_file );
-        virtual ~BackgroundTextureLoader();
+    /**
+     * Handles background texture loading.
+     */
+    class BackgroundTextureLoader : public Ogre::ManualResourceLoader{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param background_file[in] The background file.
+             */
+            explicit BackgroundTextureLoader(BackgroundFile &background_file);
 
-        virtual void loadResource( Ogre::Resource *resource );
+            /**
+             * Destructor.
+             */
+            virtual ~BackgroundTextureLoader();
 
-    protected:
+            /**
+             * Loads a resource.
+             *
+             * @param resource[in] The resource to load.
+             */
+            virtual void loadResource(Ogre::Resource *resource);
 
-    private:
-        BackgroundFile  &m_background_file;
+
+        private:
+
+            /**
+             * The background file.
+             */
+            BackgroundFile &background_file_;
     };
 }
-
-#endif // __QGearsBackgroundTextureLoader_H__

+ 189 - 72
QGearsMain/include/data/QGearsCameraMatrixFile.h

@@ -1,81 +1,198 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-09-02 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsCameraMatrixFile_H__
-#define __QGearsCameraMatrixFile_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreMatrix3.h>
-
 #include "common/QGearsResource.h"
 
-namespace QGears
-{
-    class CameraMatrixFile : public Resource
-    {
-    public:
-
-        CameraMatrixFile( Ogre::ResourceManager *creator, const String &name
-              ,Ogre::ResourceHandle handle, const String &group
-              ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
-
-        virtual ~CameraMatrixFile();
-
-        static const String RESOURCE_TYPE;
-
-        const Ogre::Matrix3&    getMatrix() const;
-        void                    setMatrix( const Ogre::Matrix3& matrix );
-
-        const Ogre::Vector3&    getPosition() const;
-        void                    setPosition( const Ogre::Vector3& position );
-
-        const Pixel&            getOffset() const;
-        void                    setOffset( const Pixel& offset );
-
-        const size_t&           getCount() const;
-        void                    setCount( const size_t count );
-
-        const Ogre::Real&       getFocalLength() const;
-        void                    setFocalLength( const Ogre::Real );
-
-        Ogre::Quaternion        getOrientation() const;
-        Ogre::Radian            getFov( Ogre::Real width ) const;
-
-    protected:
-        virtual void loadImpl( void );
-        virtual void unloadImpl( void );
-        virtual size_t calculateSize( void ) const;
-
-    private:
-        Ogre::Matrix3   m_matrix;
-        Ogre::Vector3   m_position;
-        Pixel           moffset_;
-        Ogre::Real      m_focal_length;
-        size_t          m_count;
+namespace QGears{
+
+    /**
+     * Handles camera matrix files.
+     */
+    class CameraMatrixFile : public Resource{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param creator[in] Pointer to the ResourceManager that is
+             * creating this resource.
+             * @param name[in] The unique name of the resource.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             */
+            CameraMatrixFile(
+              Ogre::ResourceManager *creator, const String &name,
+              Ogre::ResourceHandle handle, const String &group,
+              bool is_manual = false, Ogre::ManualResourceLoader *loader = NULL
+           );
+
+            /**
+             * Destructor.
+             */
+            virtual ~CameraMatrixFile();
+
+            /**
+             * The type of resource.
+             */
+            static const String RESOURCE_TYPE;
+
+            /**
+             * Retrieves the camera matrix in the file.
+             *
+             * @return The camera matrix.
+             */
+            const Ogre::Matrix3& GetMatrix() const;
+
+            /**
+             * Sets the camera matrix.
+             *
+             * @param matrix[in] The camera matrix.
+             */
+            void SetMatrix(const Ogre::Matrix3& matrix);
+
+            /**
+             * Retrieves the camera position.
+             *
+             * @return The camera position.
+             */
+            const Ogre::Vector3& GetPosition() const;
+
+            /**
+             * Sets the camera position.
+             *
+             * @param position[in] The camera position.
+             */
+            void SetPosition(const Ogre::Vector3& position);
+
+            /**
+             * Retrieves the camera offset.
+             *
+             * @return The camera offset, as a {@see Pixel}.
+             */
+            const Pixel& GetOffset() const;
+
+            /**
+             * Sets the camera offset.
+             *
+             * @param offset[in] The camera offset, as a {@see Pixel}.
+             */
+            void SetOffset(const Pixel& offset);
+
+            /**
+             * Counts the ???
+             *
+             * @return The number of ???
+             * @todo What does this count?
+             */
+            const size_t& GetCount() const;
+
+            /**
+             * Sets the number of ???
+             *
+             * @param count[in] The number of ???
+             * @todo What is this number?
+             */
+            void SetCount(const size_t count);
+
+            /**
+             * Retrieves the focal length.
+             *
+             * @return The focal length.
+             */
+            const Ogre::Real& GetFocalLength() const;
+
+            /**
+             * Sets the focal length.
+             *
+             * @param focal_length[in] The focal length.
+             */
+            void SetFocalLength(const Ogre::Real focal_length);
+
+            /**
+             * Retrieves the camera orientation.
+             *
+             * @return The camera orientation.
+             */
+            Ogre::Quaternion GetOrientation() const;
+
+            /**
+             * Retrieves the camera field of view.
+             *
+             * @return The field of view.
+             */
+            Ogre::Radian GetFov(Ogre::Real width) const;
+
+        protected:
+
+            /**
+             * Loads the file.
+             */
+            virtual void loadImpl(void);
+
+            /**
+             * Unloads the file.
+             */
+            virtual void unloadImpl(void);
+
+            /**
+             * Calculates the file size
+             *
+             * @return Always 0.
+             */
+            virtual size_t CalculateSize(void) const;
+
+        private:
+
+            /**
+             * The camera matrix.
+             */
+            Ogre::Matrix3 matrix_;
+
+            /**
+             * The position of the camera.
+             */
+            Ogre::Vector3 position_;
+
+            /**
+             * The camera offset.
+             */
+            Pixel offset_;
+
+            /**
+             * The focal length.
+             */
+            Ogre::Real focal_length_;
+
+            /**
+             * The number of @todo what?
+             */
+            size_t count_;
     };
 
     typedef Ogre::SharedPtr<CameraMatrixFile> CameraMatrixFilePtr;
 }
-
-#endif // __QGearsCameraMatrixFile_H__

+ 69 - 43
QGearsMain/include/data/QGearsCameraMatrixFileManager.h

@@ -1,55 +1,81 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-09-02 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsCameraMatrixFileManager_H__
-#define __QGearsCameraMatrixFileManager_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResourceManager.h>
+#pragma once
 
+#include <OgreResourceManager.h>
 #include "QGearsPrerequisites.h"
-
 #include "QGearsCameraMatrixFile.h"
 
-namespace QGears
-{
-    class _QGearsExport CameraMatrixFileManager : public Ogre::ResourceManager, public Ogre::Singleton<CameraMatrixFileManager>
+namespace QGears{
+
+    /**
+     * A manager fo camera matrix files.
+     */
+    class _QGearsExport CameraMatrixFileManager :
+      public Ogre::ResourceManager,
+      public Ogre::Singleton<CameraMatrixFileManager>
     {
-    public:
-        CameraMatrixFileManager();
-        virtual ~CameraMatrixFileManager();
 
-        static CameraMatrixFileManager& getSingleton();
-        static CameraMatrixFileManager* getSingletonPtr();
+        public:
+
+            /**
+             * Constructor.
+             */
+            CameraMatrixFileManager();
 
-    protected:
-        Ogre::Resource *createImpl( const Ogre::String &name, Ogre::ResourceHandle handle
-          , const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader
-          , const Ogre::NameValuePairList *createParams );
+            /**
+             * Destructor.
+             */
+            virtual ~CameraMatrixFileManager();
+
+            /**
+             * Retrieves a singleton to the manager.
+             */
+            static CameraMatrixFileManager& GetSingleton();
+
+            /**
+             * Retrieves a pointer to the manager singleton.
+             */
+            static CameraMatrixFileManager* GetSingletonPtr();
+
+        protected:
+
+            /**
+             * Loads the manager.
+             *
+             * @param name[in] The unique name of the manager.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             * @param create_params[in] Unused.
+             */
+            Ogre::Resource *createImpl(
+              const Ogre::String &name, Ogre::ResourceHandle handle,
+              const Ogre::String &group, bool is_manual,
+              Ogre::ManualResourceLoader *loader,
+              const Ogre::NameValuePairList *create_params
+            );
 
-    private:
     };
 }
-
-#endif // __QGearsCameraMatrixFileManager_H__

+ 70 - 47
QGearsMain/include/data/QGearsCameraMatrixFileSerializer.h

@@ -1,59 +1,82 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-09-02 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsCameraMatrixFileSerializer_H__
-#define __QGearsCameraMatrixFileSerializer_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include "common/TypeDefine.h"
+#pragma once
 
+#include "common/TypeDefine.h"
 #include "QGearsCameraMatrixFile.h"
 #include "QGearsSerializer.h"
 
-namespace QGears
-{
-    class CameraMatrixFileSerializer : public Serializer
-    {
-    public:
-                        CameraMatrixFileSerializer();
-        virtual        ~CameraMatrixFileSerializer();
+namespace QGears{
+
+    /**
+     * Handles the serialization of camera matrix files.
+     */
+    class CameraMatrixFileSerializer : public Serializer{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            CameraMatrixFileSerializer();
 
-        enum
-        {
-            CAMERA_MATRIX_ROW_COUNT     = 3
-           ,CAMERA_MATRIX_COL_COUNT     = CAMERA_MATRIX_ROW_COUNT
-           ,CAMERA_MATRIX_ENTRY_COUNT   = CAMERA_MATRIX_ROW_COUNT * CAMERA_MATRIX_COL_COUNT
-           ,TOTAL_DATA_SIZE             = 0x26
-        };
+            /**
+             * Destructor.
+             */
+            virtual ~CameraMatrixFileSerializer();
 
-        virtual void    importCameraMatrixFile( Ogre::DataStreamPtr &stream, CameraMatrixFile* pDest );
+            enum{
 
-    protected:
+                /**
+                 * Rows in a camera matrix.
+                 *
+                 * Same as {@see CAMERA_MATRIX_COL_COUNT}.
+                 */
+                CAMERA_MATRIX_ROW_COUNT = 3,
 
-    private:
-        // http://en.wikipedia.org/wiki/Angle_of_view
+                /**
+                 * Columns in a camera matrix.
+                 *
+                 * Same as {@see CAMERA_MATRIX_ROW_COUNT}.
+                 */
+                CAMERA_MATRIX_COL_COUNT = CAMERA_MATRIX_ROW_COUNT,
+
+                /**
+                 * Elements in a camera matrix.
+                 *
+                 * Same as {@see CAMERA_MATRIX_ROW_COUNT} *
+                 * {@see CAMERA_MATRIX_COL_COUNT}.
+                 */
+                CAMERA_MATRIX_ENTRY_COUNT
+                  = CAMERA_MATRIX_ROW_COUNT * CAMERA_MATRIX_COL_COUNT,
+
+                /**
+                 * Total size of a camera matrix.
+                 */
+                TOTAL_DATA_SIZE = 0x26,
+            };
+
+            /**
+             * Imports an camera matrix file.
+             *
+             * @param stream[in] The contents of the file.
+             * @param dest[out] The formad camera matrix file.
+             */
+            virtual void ImportCameraMatrixFile(
+              Ogre::DataStreamPtr &stream, CameraMatrixFile* dest
+            );
     };
 }
-
-#endif // __QGearsCameraMatrixFileSerializer_H__

+ 56 - 44
QGearsMain/include/data/QGearsFLevelBackground2DLoader.h

@@ -1,57 +1,69 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-29 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsFLevelBackground2DLoader_H__
-#define __QGearsFLevelBackground2DLoader_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResource.h>
+#pragma once
 
+#include <OgreResource.h>
 #include "data/QGearsBackgroundFile.h"
 #include "map/QGearsBackground2DFile.h"
 
-namespace QGears
-{
+namespace QGears{
+
     class FLevelFile;
 
-    class FLevelBackground2DLoader : public Ogre::ManualResourceLoader
-    {
-    public:
-        explicit FLevelBackground2DLoader( FLevelFile& flevel_file );
-        virtual ~FLevelBackground2DLoader();
+    /**
+     * Handles 2D background loading.
+     */
+    class FLevelBackground2DLoader : public Ogre::ManualResourceLoader{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param flevel_file[in] Level file.
+             */
+            explicit FLevelBackground2DLoader(FLevelFile& flevel_file);
+
+            /**
+             * Destructor.
+             */
+            virtual ~FLevelBackground2DLoader();
 
-        virtual void loadResource( Ogre::Resource *resource );
+            /**
+             * Loads a resource.
+             *
+             * @param resource[in] The resource to load.
+             */
+            virtual void loadResource(Ogre::Resource *resource);
 
-    protected:
-        typedef Background2DFile::TileList  TileList;
-        typedef BackgroundFile::Layer       Layer;
-        typedef BackgroundFile::SpriteData  SpriteData;
-        typedef BackgroundFile::SpriteList  SpriteList;
+        protected:
 
-    private:
-        FLevelFile  &m_flevel_file;
+            typedef Background2DFile::TileList TileList;
+
+            typedef BackgroundFile::Layer Layer;
+
+            typedef BackgroundFile::SpriteData SpriteData;
+
+            typedef BackgroundFile::SpriteList SpriteList;
+
+        private:
+
+            /**
+             * The flevel file.
+             */
+            FLevelFile  &flevel_file_;
     };
 }
-
-#endif // __QGearsFLevelBackground2DLoader_H__

+ 290 - 94
QGearsMain/include/data/QGearsFLevelFile.h

@@ -1,119 +1,315 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-24 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsFLevelFile_H__
-#define __QGearsFLevelFile_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreTexture.h>
+#pragma once
 
+#include <OgreTexture.h>
 #include "common/QGearsResource.h"
 #include "common/TypeDefine.h"
 #include "map/QGearsBackground2DFile.h"
 #include "map/QGearsWalkmeshFile.h"
-
 #include "data/FF7ModelListFile.h"
-
 #include "QGearsBackgroundFile.h"
 #include "QGearsCameraMatrixFile.h"
 #include "QGearsPaletteFile.h"
 #include "QGearsHRCFile.h"
 #include "QGearsTriggersFile.h"
 
-namespace QGears
-{
+namespace QGears{
     // TODO: move flevel stuff to ff7 as it is ff7 related!?
+
     using FF7::ModelListFile;
+
     using FF7::ModelListFilePtr;
 
     class FLevelTextureLoader;
+
     class FLevelBackground2DLoader;
 
-    class FLevelFile : public Resource
-    {
-    public:
-
-        FLevelFile( Ogre::ResourceManager *creator, const String &name
-              ,Ogre::ResourceHandle handle, const String &group
-              ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
-
-        virtual ~FLevelFile();
-
-        static const String RESOURCE_TYPE;
-
-        const std::vector<u8>&      getRawScript() const;
-        const BackgroundFilePtr&    getBackground() const;
-        const CameraMatrixFilePtr&  getCameraMatrix() const;
-        const ModelListFilePtr&     getModelList() const;
-        const PaletteFilePtr&       getPalette() const;
-        const WalkmeshFilePtr&      getWalkmesh() const;
-        const TriggersFilePtr&      getTriggers() const;
-
-        void setRawScript(const std::vector<u8>& scriptData);
-        void setBackground  ( const BackgroundFilePtr      &background    );
-        void setCameraMatrix( const CameraMatrixFilePtr    &camera_matrix );
-        void setModelList   ( const ModelListFilePtr       &model_list    );
-        void setPalette     ( const PaletteFilePtr         &palette       );
-        void setWalkmesh    ( const WalkmeshFilePtr        &walkmesh      );
-        void setTriggers(const TriggersFilePtr& triggers);
-
-        String getBackground2DName( void ) const;
-        String getBackgroundTextureName( void ) const;
-
-    protected:
-        typedef std::vector<HRCFilePtr>         HRCList;
-        typedef ModelListFile::ModelList        ModelList;
-        typedef ModelListFile::AnimationList    AnimationList;
-
-        static const String SUFFIX_BACKGROUND_TEXTURE;
-        static const String SUFFIX_BACKGROUND_2D;
-
-        virtual void loadImpl( void ) override;
-        void loadModels( void );
-        void loadAnimations( const HRCFilePtr &model, const AnimationList &animations );
-        virtual void unloadImpl( void ) override;
-        virtual size_t calculateSize( void ) const override;
-
-        virtual const String& getResourceType( void ) const;
-
-    private:
-        BackgroundFilePtr           m_background;
-        CameraMatrixFilePtr         m_camera_matrix;
-        ModelListFilePtr            m_model_list;
-        PaletteFilePtr              m_palette;
-        WalkmeshFilePtr             m_walkmesh;
-        TriggersFilePtr             m_triggers;
-        std::vector<u8>             m_rawScript;
-
-        FLevelTextureLoader        *m_background_texture_loader;
-        Ogre::TexturePtr            m_background_texture;
-        FLevelBackground2DLoader   *m_background_2d_loader;
-        Background2DFilePtr         m_background_2d;
-        HRCList                     m_hrc_files;
+    /**
+     * A flevel file.
+     *
+     * Flevel files are LXS compressed files containing level data in the game
+     * PC version.
+     */
+    class FLevelFile : public Resource{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param creator[in] Pointer to the ResourceManager that is
+             * creating this resource.
+             * @param name[in] The unique name of the resource.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             */
+            FLevelFile(
+              Ogre::ResourceManager *creator, const String &name,
+              Ogre::ResourceHandle handle, const String &group,
+              bool is_manual = false, Ogre::ManualResourceLoader *loader = NULL
+            );
+
+            /**
+             * Destructor.
+             */
+            virtual ~FLevelFile();
+
+            /**
+             * The resource type.
+             */
+            static const String RESOURCE_TYPE;
+
+            /**
+             * Retrieves the scripts in the level.
+             *
+             * @return The scripts in the level.
+             */
+            const std::vector<u8>& GetRawScript() const;
+
+            /**
+             * Retrieves the level background.
+             *
+             * @return The background file in the level.
+             */
+            const BackgroundFilePtr& GetBackground() const;
+
+            /**
+             * Retrieves the level cameara matrix.
+             *
+             * @return The camera matrix file in the level.
+             */
+            const CameraMatrixFilePtr& GetCameraMatrix() const;
+
+            /**
+             * Retrieves the level model list.
+             *
+             * @return The level model list file.
+             */
+            const ModelListFilePtr& GetModelList() const;
+
+            /**
+             * Retrieves the color palette for the level.
+             *
+             * @return The color palette file for the level.
+             */
+            const PaletteFilePtr& GetPalette() const;
+
+            /**
+             * Retrieves the level walkmesh.
+             *
+             * @return The level walkmesh file.
+             */
+            const WalkmeshFilePtr& GetWalkmesh() const;
+
+            /**
+             * Retrieves the level triggers.
+             *
+             * @return The level triggers file.
+             */
+            const TriggersFilePtr& GetTriggers() const;
+
+            /**
+             * Sets the scripts for the level.
+             *
+             * @param script_data[in] The scripts for the level.
+             */
+            void SetRawScript(const std::vector<u8>& script_data);
+
+            /**
+             * Sets the background for the level.
+             *
+             * @param background[in] The background for the level.
+             */
+            void SetBackground(const BackgroundFilePtr &background);
+
+            /**
+             * Sets the camera matrix for the level.
+             *
+             * @param camera_matrix[in] The camera matrix for the level.
+             */
+            void SetCameraMatrix(const CameraMatrixFilePtr &camera_matrix);
+
+            /**
+             * Sets the model list for the level.
+             *
+             * @param model_list[in] The model list for the level.
+             */
+            void SetModelList(const ModelListFilePtr &model_list);
+
+            /**
+             * Sets the color palette for the level.
+             *
+             * @param palette[in] The color palette for the level.
+             */
+            void SetPalette(const PaletteFilePtr &palette);
+
+            /**
+             * Sets the level walkmesh.
+             *
+             * @param walkmesh[in] The walkmesh for the level.
+             */
+            void SetWalkmesh(const WalkmeshFilePtr &walkmesh);
+
+            /**
+             * Sets the triggers for the level.
+             *
+             * @param triggers[in] The triggers for the level.
+             */
+            void SetTriggers(const TriggersFilePtr& triggers);
+
+            /**
+             * Retrieves the level background name.
+             *
+             * @return The background name.
+             */
+            String GetBackground2DName(void) const;
+
+            /**
+             * Retrieves the level background texture name.
+             *
+             * @return The background texture name.
+             */
+            String GetBackgroundTextureName(void) const;
+
+        protected:
+
+            typedef std::vector<HRCFilePtr> HRCList;
+
+            typedef ModelListFile::ModelList ModelList;
+
+            typedef ModelListFile::AnimationList AnimationList;
+
+            /**
+             * Background texture file names suffix.
+             */
+            static const String SUFFIX_BACKGROUND_TEXTURE;
+
+            /**
+             * Background file names suffix.
+             */
+            static const String SUFFIX_BACKGROUND_2D;
+
+            /**
+             * Loads the file.
+             */
+            virtual void loadImpl(void) override;
+
+            /**
+             * Loads the level models.
+             */
+            void LoadModels(void);
+
+            /**
+             * Loads the level animations
+             */
+            void LoadAnimations(
+              const HRCFilePtr &model, const AnimationList &animations
+            );
+
+            /**
+             * Unloads the file.
+             */
+            virtual void unloadImpl(void) override;
+
+            /**
+             * Calculates the size of the level.
+             *
+             * @return Always 0.
+             */
+            virtual size_t calculateSize(void) const override;
+
+            /**
+             * Retrieves the resource type.
+             */
+            virtual const String& GetResourceType(void) const;
+
+        private:
+
+            /**
+             * The level background.
+             */
+            BackgroundFilePtr background_;
+
+            /**
+             * The level camera matrix.
+             */
+            CameraMatrixFilePtr camera_matrix_;
+
+            /**
+             * The level model list.
+             */
+            ModelListFilePtr model_list_;
+
+            /**
+             * The level color palette.
+             */
+            PaletteFilePtr palette_;
+
+            /**
+             * The level walkmesh.
+             */
+            WalkmeshFilePtr walkmesh_;
+
+            /**
+             * The level triggers.
+             */
+            TriggersFilePtr triggers_;
+
+            /**
+             * The level script data.
+             */
+            std::vector<u8> raw_script_;
+
+            /**
+             * The background texture loader.
+             */
+            FLevelTextureLoader *background_texture_loader_;
+
+            /**
+             * The background texture.
+             */
+            Ogre::TexturePtr background_texture_;
+
+            /**
+             * The background loader.
+             */
+            FLevelBackground2DLoader *background_2d_loader_;
+
+            /**
+             * The background loader.
+             */
+            Background2DFilePtr background_2d_;
+
+            /**
+             * The list of HRC files.
+             *
+             * HRC files describe bone hierarchy.
+             */
+            HRCList hrc_files_;
     };
 
     typedef Ogre::SharedPtr<FLevelFile> FLevelFilePtr;
 }
-
-#endif // __QGearsFLevelFile_H__

+ 65 - 43
QGearsMain/include/data/QGearsFLevelFileManager.h

@@ -1,55 +1,77 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-24 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsFLevelFileManager_H__
-#define __QGearsFLevelFileManager_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResourceManager.h>
+#pragma once
 
+#include <OgreResourceManager.h>
 #include "QGearsPrerequisites.h"
-
 #include "QGearsFLevelFile.h"
 
-namespace QGears
-{
-    class _QGearsExport FLevelFileManager : public Ogre::ResourceManager, public Ogre::Singleton<FLevelFileManager>
+namespace QGears{
+
+    /**
+     * A manager for flevel files.
+     */
+    class _QGearsExport FLevelFileManager
+      : public Ogre::ResourceManager, public Ogre::Singleton<FLevelFileManager>
     {
-    public:
-        FLevelFileManager();
-        virtual ~FLevelFileManager();
+        public:
 
-        static FLevelFileManager& getSingleton();
-        static FLevelFileManager* getSingletonPtr();
+            /**
+             * Constructor.
+             */
+            FLevelFileManager();
 
-    protected:
-        Ogre::Resource *createImpl( const Ogre::String &name, Ogre::ResourceHandle handle
-          , const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader
-          , const Ogre::NameValuePairList *createParams );
+            /**
+             * Destructor.
+             */
+            virtual ~FLevelFileManager();
+
+            /**
+             * Retrieves a singleton to the manager.
+             */
+            static FLevelFileManager& GetSingleton();
+
+            /**
+             * Retrieves a pointer to the manager singleton.
+             */
+            static FLevelFileManager* GetSingletonPtr();
+
+            /**
+             * Loads the manager.
+             *
+             * @param name[in] The unique name of the manager.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             * @param create_params[in] Unused.
+             */
+            virtual Ogre::Resource *createImpl(
+              const Ogre::String &name, Ogre::ResourceHandle handle,
+              const Ogre::String &group, bool is_manual,
+              Ogre::ManualResourceLoader *loader,
+              const Ogre::NameValuePairList *create_params
+            );
 
-    private:
     };
 }
-
-#endif // __QGearsFLevelFileManager_H__

+ 240 - 86
QGearsMain/include/data/QGearsFLevelFileSerializer.h

@@ -1,94 +1,248 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-24 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsFLevelFileSerializer_H__
-#define __QGearsFLevelFileSerializer_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "common/TypeDefine.h"
-
 #include "QGearsFLevelFile.h"
 #include "QGearsSerializer.h"
 
-namespace QGears
-{
-    class FLevelFileSerializer : public Serializer
-    {
-    public:
-                        FLevelFileSerializer();
-        virtual        ~FLevelFileSerializer();
-
-        virtual void    importFLevelFile( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
-
-        enum
-        {
-            SECTION_SCRIPT
-           ,SECTION_CAMERA_MATRIX
-           ,SECTION_MODEL_LOADER
-           ,SECTION_PALETTE
-           ,SECTION_WALKMESH
-           ,SECTION_TILE_MAP
-           ,SECTION_ENCOUNTER
-           ,SECTION_TRIGGER
-           ,SECTION_BACKGROUND
-           ,SECTION_COUNT
-        };
-
-        struct Header
-        {
-            uint16 version;
-            uint32 section_count;
-        };
-
-    protected:
-        void    readFileHeader( Ogre::DataStreamPtr &stream );
-
-        void    readSectionData(Ogre::DataStreamPtr &stream, Ogre::DataStreamPtr &outbuffer_, size_t sectionSize);
-        virtual void    readSection( Ogre::DataStreamPtr &stream, FLevelFile* pDest, const size_t section_index );
-
-        template<typename ResourceManagerType>
-        Ogre::ResourcePtr createResource( FLevelFile *pDest, const String &extension );
-
-        void    readCameraMatrix( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
-        void    readModelList   ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
-        void    readPalette     ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
-        void    readWalkmesh    ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
-        void    readBackground  ( Ogre::DataStreamPtr &stream, FLevelFile* pDest );
-        void    readTriggers    (Ogre::DataStreamPtr &stream, FLevelFile* pDest);
-
-        void    readEnd( Ogre::DataStreamPtr &stream );
-
-        template<typename ValueType> void
-        readVector( Ogre::DataStreamPtr &stream, std::vector<ValueType> &pDest, size_t count );
-
-        virtual String  getBaseName        ( const FLevelFile* pDest ) const;
-
-        static const String     TAG_FILE_END;
-
-    private:
-        Header  m_header;
+namespace QGears{
+
+    /**
+     * Handles the serialization of flevel files.
+     */
+    class FLevelFileSerializer : public Serializer{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            FLevelFileSerializer();
+
+            /**
+             * Destructor.
+             */
+            virtual ~FLevelFileSerializer();
+
+            virtual void ImportFLevelFile(
+              Ogre::DataStreamPtr &stream, FLevelFile* dest
+            );
+
+            enum{
+
+                /**
+                 * Scripts section.
+                 */
+                SECTION_SCRIPT,
+
+                /**
+                 * Camera matrix section/
+                 */
+                SECTION_CAMERA_MATRIX,
+
+                /**
+                 * Model section.
+                 */
+                SECTION_MODEL_LOADER,
+
+                /**
+                 * Color palette section/
+                 */
+                SECTION_PALETTE,
+
+                /**
+                 * Walkmesh section.
+                 */
+                SECTION_WALKMESH,
+
+                /**
+                 * Tile map section.
+                 */
+                SECTION_TILE_MAP,
+
+                /**
+                 * Battle encounter section.
+                 */
+                SECTION_ENCOUNTER,
+
+                /**
+                 * Triggers section.
+                 */
+                SECTION_TRIGGER,
+
+                /**
+                 * Background section.
+                 */
+                SECTION_BACKGROUND,
+
+                /**
+                 * @todo Count of what?
+                 */
+                SECTION_COUNT
+            };
+
+            /**
+             * A flevel file header.
+             */
+            struct Header{
+
+                /**
+                 * File format version.
+                 */
+                uint16 version;
+
+                /**
+                 * Number of sections in the file.
+                 */
+                uint32 section_count;
+            };
+
+        protected:
+
+            /**
+             * Reads the file header and sets instance data..
+             *
+             * @param stream[in] Contents of the file.
+             */
+            void ReadFileHeader(Ogre::DataStreamPtr &stream);
+
+            /**
+             * Reads a section data.
+             *
+             * @param stream[in] Contents of the file.
+             * @param out_buffer[out] The contents of the section are loaded
+             * here.
+             * @param section_size[in] Size of the section to read, in bytes.
+             */
+            void ReadSectionData(
+              Ogre::DataStreamPtr &stream, Ogre::DataStreamPtr &out_buffer,
+              size_t section_size
+            );
+
+            /**
+             * Reads a file section.
+             *
+             * @param stream[in] Contents of the file.
+             * @param dest[out] The section data will be loaded here.
+             * @param section_index[in] Index of the section to read.
+             */
+            virtual void ReadSection(
+              Ogre::DataStreamPtr &stream, FLevelFile* dest,
+              const size_t section_index
+            );
+
+            /**
+             * Creates a resource.
+             *
+             * @param dest[out] The crteated resource.
+             * @param extension[in] The resource file extension.
+             */
+            template<typename ResourceManagerType>
+              Ogre::ResourcePtr CreateResource(
+                FLevelFile *dest, const String &extension
+              );
+
+            /**
+             * Reads camera matrix data from a flevel file.
+             *
+             * @param stream[in] Input stream.
+             * @param dest[out] The data will be set on this file.
+             */
+            void ReadCameraMatrix(
+              Ogre::DataStreamPtr &stream, FLevelFile* dest
+            );
+
+            /**
+             * Reads model list data from a flevel file.
+             *
+             * @param stream[in] Input stream.
+             * @param dest[out] The data will be set on this file.
+             */
+            void ReadModelList(Ogre::DataStreamPtr &stream, FLevelFile* dest);
+
+            /**
+             * Reads color palette data from a flevel file.
+             *
+             * @param stream[in] Input stream.
+             * @param dest[out] The data will be set on this file.
+             */
+            void ReadPalette(Ogre::DataStreamPtr &stream, FLevelFile* dest);
+
+            /**
+             * Reads walkmesh data from a flevel file.
+             *
+             * @param stream[in] Input stream.
+             * @param dest[out] The data will be set on this file.
+             */
+            void ReadWalkmesh(Ogre::DataStreamPtr &stream, FLevelFile* dest);
+
+            /**
+             * Reads background data from a flevel file.
+             *
+             * @param stream[in] Input stream.
+             * @param dest[out] The data will be set on this file.
+             */
+            void ReadBackground(Ogre::DataStreamPtr &stream, FLevelFile* dest);
+
+            /**
+             * Reads trigger data from a flevel file.
+             *
+             * @param stream[in] Input stream.
+             * @param dest[out] The data will be set on this file.
+             */
+            void ReadTriggers(Ogre::DataStreamPtr &stream, FLevelFile* dest);
+
+            /**
+             * @todo Understand and document.
+             *
+             * @param stream[in] Input stream.
+             */
+            void ReadEnd(Ogre::DataStreamPtr &stream);
+
+            /**
+             * Reads a stream as a vector.
+             *
+             * @param stream[in] The input stream.
+             * @param dest[out] The vector data will be loaded here.
+             * @param count[in] Data units to copy.
+             */
+            template<typename ValueType> void ReadVector(
+              Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
+              size_t count
+            );
+
+            /**
+             * Retrieves the base name of a flevel file.
+             *
+             * @param dest[in] Flevel file.
+             * @return The filename, without path or extension.
+             */
+            virtual String GetBaseName(const FLevelFile* dest) const;
+
+            /**
+             * End-of-file tag.
+             */
+            static const String TAG_FILE_END;
+
+        private:
+
+            /**
+             * The file header.
+             */
+            Header header_;
     };
 }
-
-#endif // __QGearsFLevelFileSerializer_H__

+ 47 - 39
QGearsMain/include/data/QGearsFLevelTextureLoader.h

@@ -1,50 +1,58 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-29 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsFLevelTextureLoader_H__
-#define __QGearsFLevelTextureLoader_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreResource.h>
 
-namespace QGears
-{
+namespace QGears{
+
     class FLevelFile;
 
-    class FLevelTextureLoader : public Ogre::ManualResourceLoader
-    {
-    public:
-        explicit FLevelTextureLoader( FLevelFile &flevel_file );
-        virtual ~FLevelTextureLoader();
+    /**
+     * A flevel texture loader.
+     */
+    class FLevelTextureLoader : public Ogre::ManualResourceLoader{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param flevel_file[in] The file to load textures from.
+             */
+            explicit FLevelTextureLoader(FLevelFile &flevel_file);
 
-        virtual void loadResource( Ogre::Resource *resource );
+            /**
+             * Destructor.
+             */
+            virtual ~FLevelTextureLoader();
 
-    protected:
+            /**
+             * Loads a resource.
+             *
+             * @param resource[in] the resource to load.
+             */
+            virtual void loadResource(Ogre::Resource *resource);
+
+        private:
+
+            /**
+             * The flevel file.
+             */
+            FLevelFile &flevel_file_;
 
-    private:
-        FLevelFile  &m_flevel_file;
     };
 }
-
-#endif // __QGearsFLevelTextureLoader_H__

+ 211 - 79
QGearsMain/include/data/QGearsHRCFile.h

@@ -1,93 +1,225 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-11 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsHRCFile_H__
-#define __QGearsHRCFile_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreResource.h>
 #include <OgreMesh.h>
 #include <OgreSkeleton.h>
-
 #include "common/TypeDefine.h"
 
-namespace QGears
-{
-    class HRCMeshLoader;
-    class HRCSkeletonLoader;
-
-    class HRCFile : public Ogre::Resource
-    {
-    public:
-        static const float kDownScaler;
-
-        HRCFile( Ogre::ResourceManager *creator, const String &name
-                ,Ogre::ResourceHandle handle, const String &group
-                ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
-
-        virtual ~HRCFile();
-
-        typedef std::vector<String> RSDNameList;
-
-        struct Bone
-        {
-            String      name;
-            String      parent;
-            Ogre::Real  length;
-            RSDNameList rsd_names;
-        };
+namespace QGears{
 
-        typedef std::vector<Bone> BoneList;
-
-        virtual void            setSkeletonName( const String& name );
-        virtual const String&   getSkeletonName( void )     const { return m_skeleton_name; }
-        virtual       String    getSkeletonFileName( void ) const;
-        virtual       String    getMeshFileName( void )     const;
-        virtual       BoneList& getBones( void )       { return m_bones; }
-        virtual const BoneList& getBones( void ) const { return m_bones; }
-
-        virtual Ogre::SkeletonPtr   getSkeleton( void ) const;
-
-        static const String RESOURCE_TYPE;
-
-    protected:
-        virtual void loadImpl();
-        virtual void unloadImpl();
-        virtual size_t calculateSize() const;
-        virtual size_t calculateSize( const Bone &bone ) const;
+    class HRCMeshLoader;
 
-    private:
-        String      m_skeleton_name;
-        BoneList    m_bones;
+    class HRCSkeletonLoader;
 
-        HRCMeshLoader      *m_mesh_loader;
-        HRCSkeletonLoader  *m_skeleton_loader;
-        Ogre::SkeletonPtr   m_skeleton;
-        Ogre::MeshPtr       m_mesh;
+    /**
+     * Handles HRC files.
+     *
+     * HRC files describe bone hierarchy in an skeleton.
+     */
+    class HRCFile : public Ogre::Resource{
+
+        public:
+
+            /**
+             * Scale down constant.
+             */
+            static const float DOWN_SCALER;
+
+            /**
+             * Constructor.
+             *
+             * @param creator[in] Pointer to the ResourceManager that is
+             * creating this resource.
+             * @param name[in] The unique name of the resource.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             */
+            HRCFile(
+              Ogre::ResourceManager *creator, const String &name,
+              Ogre::ResourceHandle handle, const String &group,
+              bool is_manual = false, Ogre::ManualResourceLoader *loader = NULL
+            );
+
+            /**
+             * Destructor.
+             */
+            virtual ~HRCFile();
+
+            typedef std::vector<String> RSDNameList;
+
+            /**
+             * A bone in a skeleton.
+             */
+            struct Bone{
+
+                /**
+                 * Bone name.
+                 */
+                String name;
+
+                /**
+                 * Parent bone name.
+                 */
+                String parent;
+
+                /**
+                 * Bone length
+                 *
+                 * @todo In pixels?
+                 */
+                Ogre::Real length;
+
+                /**
+                 * List of RDS file assigned to the bone.
+                 *
+                 * RSD are Resource Data Files.
+                 */
+                RSDNameList rsd_names;
+            };
+
+            typedef std::vector<Bone> BoneList;
+
+            /**
+             * Sets a name for the skelenton.
+             *
+             * @param name[in] The name for the skeleton.
+             */
+            virtual void SetSkeletonName(const String& name);
+
+            /**
+             * Retrieves the skeleton name.
+             *
+             * @return The skeleton name.
+             */
+            virtual const String& GetSkeletonName() const{
+                return skeleton_name_;
+            }
+
+            /**
+             * Retrieves the skeleton file name.
+             *
+             * @return The skeleton file name.
+             */
+            virtual String GetSkeletonFileName() const;
+
+            /**
+             * Retrieves the file name of the mesh assigned to the skeleton.
+             *
+             * @return The mesh file name.
+             */
+            virtual String GetMeshFileName() const;
+
+            /**
+             * Retrieves the list of bones in the skeleton.
+             *
+             * @return The list of bones.
+             */
+            virtual BoneList& GetBones(){return bones_;}
+
+            /**
+             * Retrieves the list of bones in the skeleton.
+             *
+             * @return The list of bones.
+             */
+            virtual const BoneList& GetBones() const{return bones_;}
+
+            /**
+             * Retrieves the skeleton.
+             *
+             * @return The skeleton.
+             */
+            virtual Ogre::SkeletonPtr GetSkeleton() const;
+
+            /**
+             * The type of resource.
+             */
+            static const String RESOURCE_TYPE;
+
+        protected:
+
+            /**
+             * Loads the file.
+             */
+            virtual void loadImpl() override final;
+
+            /**
+             * Unloads the file.
+             */
+            virtual void unloadImpl() override final;
+
+            /**
+             * Calculates the size of the skeleton.
+             *
+             * @return The size of the skeleton.
+             * @todo Units?
+             */
+            virtual size_t CalculateSize() const;
+
+            /**
+             * Calculates the size of a bone.
+             *
+             * @param bone[in] The bone whose size to calculate.
+             * @return The size of the bone.
+             * @todo Units?
+             */
+            virtual size_t CalculateSize(const Bone &bone) const;
+
+        private:
+
+            /**
+             * The skeleton name.
+             */
+            String skeleton_name_;
+
+            /**
+             * The bones in the skeleton.
+             */
+            BoneList bones_;
+
+            /**
+             * The mesh loader.
+             */
+            HRCMeshLoader *mesh_loader_;
+
+            /**
+             * The skeleton loader.
+             */
+            HRCSkeletonLoader *skeleton_loader_;
+
+            /**
+             * The skeleton.
+             */
+            Ogre::SkeletonPtr skeleton_;
+
+            /**
+             * The mesh assigned to the skeleton.
+             */
+            Ogre::MeshPtr mesh_;
     };
 
     typedef Ogre::SharedPtr<HRCFile> HRCFilePtr;
 }
-
-#endif // __QGearsHRCFile_H__

+ 77 - 43
QGearsMain/include/data/QGearsHRCFileManager.h

@@ -1,58 +1,92 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-16 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsHRCFileManager_H__
-#define __QGearsHRCFileManager_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResourceManager.h>
+#pragma once
 
+#include <OgreResourceManager.h>
 #include "QGearsPrerequisites.h"
 #include "common/TypeDefine.h"
-
 #include "QGearsHRCFile.h"
 
-namespace QGears
-{
-    class _QGearsExport HRCFileManager : public Ogre::ResourceManager, public Ogre::Singleton<HRCFileManager>
+namespace QGears{
+
+    /**
+     * A manager for HRC files.
+     */
+    class _QGearsExport HRCFileManager :
+      public Ogre::ResourceManager, public Ogre::Singleton<HRCFileManager>
     {
-    public:
-        HRCFileManager();
-        virtual ~HRCFileManager();
+        public:
+
+            /**
+             * Constructor.
+             */
+            HRCFileManager();
 
-        virtual void parseScript( Ogre::DataStreamPtr &stream, const String &groupName );
+            /**
+             * Destructor.
+             */
+            virtual ~HRCFileManager();
 
-        static HRCFileManager& getSingleton();
-        static HRCFileManager* getSingletonPtr();
+            /**
+             * Parses a HRC script and creates a skeleton.
+             *
+             * @param stream[in] Script content.
+             * @param group_name[in] GRoup to add the skeleton to.
+             */
+            virtual void ParseScript(
+              Ogre::DataStreamPtr &stream, const String &group_name
+            );
 
-    protected:
-        Ogre::Resource *createImpl( const String &name, Ogre::ResourceHandle handle
-          , const String &group, bool isManual, Ogre::ManualResourceLoader *loader
-          , const Ogre::NameValuePairList *createParams );
+            /**
+             * Retrieves a singleton to the manager.
+             */
+            static HRCFileManager& GetSingleton();
+
+            /**
+             * Retrieves a pointer to the manager singleton.
+             */
+            static HRCFileManager* GetSingletonPtr();
+
+        protected:
+
+            /**
+             * Loads the manager.
+             *
+             * @param name[in] The unique name of the manager.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             * @param create_params[in] Unused.
+             */
+            virtual Ogre::Resource *createImpl(
+              const Ogre::String &name, Ogre::ResourceHandle handle,
+              const Ogre::String &group, bool is_manual,
+              Ogre::ManualResourceLoader *loader,
+              const Ogre::NameValuePairList *create_params
+            ) override final;
 
-    private:
     };
 }
 
-#endif // __QGearsHRCFileManager_H__
+

+ 125 - 65
QGearsMain/include/data/QGearsHRCFileSerializer.h

@@ -1,72 +1,132 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-10 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsHRCFileSerializer_H__
-#define __QGearsHRCFileSerializer_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "QGearsHRCFile.h"
 #include "QGearsSerializer.h"
 
-namespace QGears
-{
-    class HRCFileSerializer : public Serializer
-    {
-    public:
-                        HRCFileSerializer();
-        virtual        ~HRCFileSerializer();
-
-        virtual void    importHRCFile( Ogre::DataStreamPtr &stream, HRCFile* pDest );
-
-    protected:
-        static const String TAG_COMMENT;
-        static const String TAG_VERSION;
-        static const String TAG_NAME;
-        static const String TAG_BONE_COUNT;
-
-        typedef std::vector<String> Block;
-        typedef HRCFile::Bone       Bone;
-
-        virtual void    readFileHeader( Ogre::DataStreamPtr &stream );
-        virtual void    readBlock( Ogre::DataStreamPtr &stream, Block& pDest );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, Bone &pDest );
-
-        template<typename ValueType>
-                void    readVector( Ogre::DataStreamPtr &stream
-                                   ,std::vector<ValueType> &pDest
-                                   ,size_t count );
-
-        struct Header
-        {
-            long    version;
-            long    bone_count;
-            String  name;
-        };
-
-    private:
-        Header  m_header;
+namespace QGears{
+
+    /**
+     * Handles the serialization of HRC files.
+     */
+    class HRCFileSerializer : public Serializer{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            HRCFileSerializer();
+
+            /**
+             * Destructor.
+             */
+            virtual ~HRCFileSerializer();
+
+            /**
+             * Imports a HRC file.
+             *
+             * @param stream[in] The contents of the HRC file.
+             * @param dest[out] The formed HRC file.
+             */
+            virtual void ImportHRCFile(
+              Ogre::DataStreamPtr &stream, HRCFile* dest
+            );
+
+        protected:
+
+            /**
+             * A comment tag.
+             */
+            static const String TAG_COMMENT;
+
+            /**
+             * File version tag.
+             */
+            static const String TAG_VERSION;
+
+            /**
+             * The name tag.
+             */
+            static const String TAG_NAME;
+
+            /**
+             * The bone count tag.
+             */
+            static const String TAG_BONE_COUNT;
+
+            typedef std::vector<String> Block;
+
+            typedef HRCFile::Bone Bone;
+
+            /**
+             * Reads a file header and sets the instance data.
+             *
+             * @param stream[in] The contents of the HRC file.
+             */
+            virtual void ReadFileHeader(Ogre::DataStreamPtr &stream);
+
+            /**
+             * Reads an object as a block.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed block data.
+             */
+            virtual void ReadBlock(Ogre::DataStreamPtr &stream, Block& dest);
+
+            /**
+             * Reads an object as a bone.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed bone data.
+             */
+            virtual void readObject(Ogre::DataStreamPtr &stream, Bone &dest);
+
+            template<typename ValueType> void ReadVector(
+              Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
+              size_t count
+            );
+
+            /**
+             * An HRC file header.
+             */
+            struct Header{
+
+                /**
+                 * File format version.
+                 */
+                long version;
+
+                /**
+                 * Number of bones in the file.
+                 */
+                long bone_count;
+
+                /**
+                 * Name of the skeleton in the file.
+                 */
+                String name;
+            };
+
+        private:
+
+            /**
+             * The file header.
+             */
+            Header  header_;
     };
 }
-
-#endif // __QGearsHRCFileSerializer_H__

+ 59 - 41
QGearsMain/include/data/QGearsHRCMeshLoader.h

@@ -1,51 +1,69 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-13 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsHRCMeshLoader_H__
-#define __QGearsHRCMeshLoader_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResource.h>
+#pragma once
 
+#include <OgreResource.h>
 #include "QGearsHRCFile.h"
 
-namespace QGears
-{
-    class HRCMeshLoader : public Ogre::ManualResourceLoader
-    {
-    public:
-        explicit HRCMeshLoader( HRCFile &hrc_file );
-        virtual ~HRCMeshLoader();
+namespace QGears{
+
+    /**
+     * A loader for skeleton meshes.
+     */
+    class HRCMeshLoader : public Ogre::ManualResourceLoader{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param hrc_file[in] The HRC file to load from.
+             */
+            explicit HRCMeshLoader(HRCFile &hrc_file);
 
-        virtual void    loadResource( Ogre::Resource *resource );
+            /**
+             * Destructor.
+             */
+            virtual ~HRCMeshLoader();
 
-    protected:
-        virtual void    loadBone( Ogre::Mesh *mesh, const HRCFile::Bone &bone, const String &path );
+            /**
+             * Loads a resource.
+             *
+             * @param resource[in] The resource to load.
+             */
+            virtual void loadResource(Ogre::Resource *resource);
 
-    private:
-        HRCFile  &m_hrc_file;
+        protected:
+
+            /**
+             * Loads a bone.
+             *
+             * @param mesh[in|out] The mesh to add the bone to.
+             * @param bone[in] The bone to add.
+             * @param path[in] Path to the file with the bone info.
+             */
+            virtual void LoadBone(
+              Ogre::Mesh *mesh, const HRCFile::Bone &bone, const String &path
+            );
+
+        private:
+
+            /**
+             * The HRC file.
+             */
+            HRCFile  &hrc_file_;
     };
 }
-
-#endif // __QGearsHRCMeshLoader_H__

+ 59 - 43
QGearsMain/include/data/QGearsHRCSkeletonLoader.h

@@ -1,55 +1,71 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-17 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsHRCSkeletonLoader_H__
-#define __QGearsHRCSkeletonLoader_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResource.h>
+#pragma once
 
+#include <OgreResource.h>
 #include "common/TypeDefine.h"
 
-namespace QGears
-{
+namespace QGears{
     class HRCFile;
 
-    class HRCSkeletonLoader : public Ogre::ManualResourceLoader
-    {
-    public:
-        explicit HRCSkeletonLoader( HRCFile &hrc_file );
-        virtual ~HRCSkeletonLoader();
+    /**
+     * A loader for skeletons.
+     */
+    class HRCSkeletonLoader : public Ogre::ManualResourceLoader{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param hrc_file[in] The HRC file to load from.
+             */
+            explicit HRCSkeletonLoader(HRCFile &hrc_file);
+
+            /**
+             * Destructor.
+             */
+            virtual ~HRCSkeletonLoader();
 
-        virtual void loadResource( Ogre::Resource *resource );
+            /**
+             * Loads a resource.
+             *
+             * @param resource[in] The resource to load.
+             */
+            virtual void loadResource( Ogre::Resource *resource );
 
-    protected:
-        static const String             ROOT_BONE_NAME;
-        static const Ogre::Quaternion   ROOT_ORIENTATION;
-        static       Ogre::Quaternion   createRootOrientation();
+        protected:
 
-    private:
-        HRCFile  &m_hrc_file;
+            /**
+             * The name of the root bone.
+             */
+            static const String ROOT_BONE_NAME;
+
+            /**
+             * The root orientation
+             */
+            static const Ogre::Quaternion ROOT_ORIENTATION;
+
+            /**
+             * Creates a base orientation for the skeleton.
+             */
+            static Ogre::Quaternion CreateRootOrientation();
+
+        private:
+
+            HRCFile  &hrc_file_;
     };
 }
-
-#endif // __QGearsHRCSkeletonLoader_H__

+ 205 - 69
QGearsMain/include/data/QGearsLGPArchive.h

@@ -1,107 +1,243 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-09-22 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsLGPArchive_H__
-#define __QGearsLGPArchive_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreArchive.h>
-
 #include "common/TypeDefine.h"
 
-namespace QGears
-{
-    class LGPArchive : public Ogre::Archive
-    {
+namespace QGears{
+
+    /**
+     * Handles LZS compressed archives.
+     */
+    class LGPArchive : public Ogre::Archive{
+
         public:
-            LGPArchive( const String &name, const String &archType );
+
+            /**
+             * Constructor.
+             *
+             * @param name[in] Name for the archive.
+             * @param arch_type[in] Archive type code.
+             */
+            LGPArchive(const String &name, const String &arch_type);
+
+            /**
+             * Destructor.
+             */
             virtual ~LGPArchive();
 
-            /// @copydoc Ogre::Archive::isCaseSensitive
-            bool isCaseSensitive(void) const { return true; }
+            /**
+             * Checks whether this archive is case sensitive.
+             *
+             * @return Always true.
+             */
+            bool isCaseSensitive() const{return true;}
 
-            /// @copydoc Ogre::Archive::load
+            /**
+             * Loads the archive.
+             */
             void load();
 
-            /// @copydoc Ogre::Archive::unload
+            /**
+             * Unloads the archive.
+             */
             void unload();
 
-            /// @copydoc Ogre::Archive::open
-            Ogre::DataStreamPtr open(const String& filename, bool readOnly = true) const;
-
-            /// @copydoc Archive::create
+            /**
+             * Opens a stream on a LGP compressed file.
+             *
+             * @param filename[in] Path to open the stream on.
+             * @param readOnly[in] TRue to open the stream in read-only mode,
+             * false to allow writting.
+             */
+            Ogre::DataStreamPtr open(
+              const String& filename, bool readOnly = true
+            ) const;
+
+            /**
+             * Creates a new file (or overwrite one already there).
+             *
+             * If the archive is read-only then this method will fail.
+             *
+             * @param filename[in] Path to the file.
+             */
             Ogre::DataStreamPtr create(const String& filename) const;
 
-            /// @copydoc Archive::remove
+            /**
+             * Deletes a named file.
+             *
+             * Not possible on read-only archives
+             *
+             * @param filename[in] Path to the file.
+             */
             void remove(const String& filename) const;
 
-            /// @copydoc Archive::list
-            Ogre::StringVectorPtr list(bool recursive = true, bool dirs = false) const;
-
-            /// @copydoc Archive::listFileInfo
-            Ogre::FileInfoListPtr listFileInfo(bool recursive = true, bool dirs = false) const;
-
-            /// @copydoc Archive::find
-            Ogre::StringVectorPtr find(const String& pattern, bool recursive = true,
-                bool dirs = false) const;
-
-            /// @copydoc Archive::findFileInfo
-            Ogre::FileInfoListPtr findFileInfo(const String& pattern, bool recursive = true,
-                bool dirs = false) const;
-
-            /// @copydoc Archive::exists
+            /**
+             * Lists all file names in the archive.
+             *
+             * @param rercursive[in] Whether all paths of the archive are
+             * to be searched (if the archive has a concept of that).
+             * @param dirs[in] True to list only directories, false to list
+             * only files.
+             * @return A list of filenames matching the criteria, all fully
+             * qualified.
+             */
+            Ogre::StringVectorPtr list(
+              bool recursive = true, bool dirs = false
+            ) const;
+
+            /**
+             * Lists all files in the archive with accompanying information.
+             *
+             * @param rercursive[in] Whether all paths of the archive are
+             * to be searched (if the archive has a concept of that).
+             * @param dirs[in] True to list only directories, false to list
+             * only files.
+             * @return A list of structures detailing quite a lot of
+             * information about all the files in the archive.
+             */
+            Ogre::FileInfoListPtr listFileInfo(
+              bool recursive = true, bool dirs = false
+            ) const;
+
+            /**
+             * Finds all file or directory names matching a given pattern in the
+             * archive.
+             *
+             * @param pattern[in] The pattern to search for; wildcards (*) are
+             * allowed
+             * @param recursive[in ]Whether all paths of the archive are
+             * searched (if the archive has a concept of that).
+             * @param dirs[in] True to list only directories, false to list
+             * only files.
+             * @return A list of filenames matching the criteria, all fully
+             * qualified.
+             */
+            Ogre::StringVectorPtr find(
+              const String& pattern, bool recursive = true, bool dirs = false
+            ) const;
+
+            /**
+             * Finds all files or directories matching a given pattern in this
+             * archive and get some detailed information about them.
+             *
+             * @param pattern[in] The pattern to search for; wildcards (*) are
+             * allowed
+             * @param recursive[in ]Whether all paths of the archive are
+             * searched (if the archive has a concept of that).
+             * @param dirs[in] True to list only directories, false to list
+             * only files.
+             * @return A list of file information structures for all files
+             * matching the criteria.
+             */
+            Ogre::FileInfoListPtr findFileInfo(
+              const String& pattern, bool recursive = true, bool dirs = false
+            ) const;
+
+            /**
+             * checks if the named file exists.
+             *
+             * @param filename[in] Fully qualified filename.
+             * @return True if FILENAME exists in the archive, false otherwise.
+             */
             bool exists(const String& filename) const;
 
-            /// @copydoc Archive::getModifiedTime
+            /**
+             * Retrieve the modification time of a given file.
+             *
+             * @param filename[in] Fully qualified filename.
+             * @return Last-modified timestamp.
+             */
             time_t getModifiedTime(const String& filename) const;
 
+            /**
+             * A file in a LGP archive.
+             */
+            struct FileEntry{
 
-            struct FileEntry
-            {
+                /**
+                 * The file name.
+                 */
                 String file_name;
-                uint32 fileoffset_;
+
+                /**
+                 * The file offset from the beginning of the archive.
+                 */
+                uint32 file_offset;
+
+                /**
+                 * Unknown data.
+                 */
                 uint8  unknown1;
+
+                /**
+                 * Unknown data.
+                 */
                 uint16 unknown2;
 
-                String datafile_name_;
+                /**
+                 * NAme of the data file
+                 */
+                String datafile_name;
+
+                /**
+                 * Size of the data, in bytes.
+                 */
                 uint32 data_size;
 
-                uint32 dataoffset_;
+                /**
+                 * Data offset.
+                 */
+                uint32 data_offset;
             };
 
             typedef std::vector<FileEntry> FileList;
 
-            virtual FileList& getFiles( void );
+            /**
+             * Retrieves the files in the archive.
+             *
+             * @return The list of files.
+             */
+            virtual FileList& GetFiles();
 
         protected:
-            void load( Ogre::DataStream* lgp );
+
+            /**
+             * Loads a LGP archive.
+             *
+             * @param lgp[in] The contents of the archive.
+             */
+            void Load(Ogre::DataStream* lgp);
 
         private:
-            FileList            m_files;
-            Ogre::DataStreamPtr m_lgp_file;
-            Ogre::FileInfoList  m_file_infos;
+
+            /**
+             * List of file sin the archive.
+             */
+            FileList files_;
+
+            /**
+             * The LGP archive file.
+             */
+            Ogre::DataStreamPtr lgp_file_;
+
+            /**
+             * List of information blocks about about the files in the LGP.
+             */
+            Ogre::FileInfoList file_infos_;
     };
 }
-
-#endif // __QGearsLGPArchive_H__

+ 58 - 44
QGearsMain/include/data/QGearsLGPArchiveFactory.h

@@ -1,64 +1,78 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-Copyright (c) 2013-09-22 Tobias Peters <tobias.peters@kreativeffekt.at>
+#pragma once
 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
+#include <OgreArchiveFactory.h>
+#include "QGearsLGPArchive.h"
 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
+namespace QGears{
 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsLGPArchiveFactory_H__
-#define __QGearsLGPArchiveFactory_H__
+    /**
+     * A factory for LGP archives.
+     */
+    class LGPArchiveFactory : public Ogre::ArchiveFactory{
 
-#include <OgreArchiveFactory.h>
-
-#include "QGearsLGPArchive.h"
+        // TODO: Move implemented methods to cpp file.
 
-namespace QGears
-{
-    class LGPArchiveFactory : public Ogre::ArchiveFactory
-    {
         public:
+
+            /**
+             * Constructor.
+             */
             LGPArchiveFactory();
+
+            /**
+             * Destructor.
+             */
             virtual ~LGPArchiveFactory();
 
-            /// @copydoc FactoryObj::getType
-            const String& getType(void) const
-            {
-                return ARCHIVE_TYPE;
-            }
+            /**
+             * Retrieves the factory type.
+             *
+             * @return The factory type.
+             */
+            const String& getType(void) const{return ARCHIVE_TYPE;}
 
-            /// @copydoc FactoryObj::createInstance
-            Ogre::Archive* createInstance( const String& name, bool readOnly ) override final
-            {
-                return OGRE_NEW LGPArchive( name, ARCHIVE_TYPE );
+            /**
+             * Creates a new LGP archive.
+             *
+             * @param name[in] Name of the archive to create.
+             * @param readOnly[in] True to make the archive read-only, false to
+             * enable writting.
+             * @return A new LGP archive.
+             */
+            Ogre::Archive* createInstance(
+              const String& name, bool readOnly
+            ) override final{
+                return OGRE_NEW LGPArchive(name, ARCHIVE_TYPE);
             }
 
-            /// @copydoc FactoryObj::DestroyInstance
-            void destroyInstance( Ogre::Archive* arch ) override final
-            {
+            /**
+             * Destroys a LGP archive created by this factory.
+             *
+             * @param arch[in] The archive to destroy.
+             */
+            void destroyInstance( Ogre::Archive* arch ) override final{
                 OGRE_DELETE arch;
             }
+
+            /**
+             * The archive type.
+             */
             static const String ARCHIVE_TYPE;
 
-        private:
     };
 }
-
-#endif // __QGearsLGPArchiveFactory_H__

+ 90 - 62
QGearsMain/include/data/QGearsLGPArchiveSerializer.h

@@ -1,71 +1,99 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-09-22 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsLGPArchiveSerializer_H__
-#define __QGearsLGPArchiveSerializer_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "QGearsSerializer.h"
 #include "QGearsLGPArchive.h"
 
-namespace QGears
-{
-    class LGPArchiveSerializer : public Serializer
-    {
-    public:
-                        LGPArchiveSerializer();
-        virtual        ~LGPArchiveSerializer();
-
-        virtual void    importLGPArchive( Ogre::DataStreamPtr &stream, LGPArchive* pDest );
-
-        enum {
-            MAGIC_STRING_LENGTH = 10
-          , FILE_NAME_LENGTH    = 20
-        };
-
-        typedef LGPArchive::FileEntry FileEntry;
-        typedef LGPArchive::FileList  FileList;
-
-    protected:
-        virtual void    readFileHeader( Ogre::DataStreamPtr &stream );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, FileEntry& file_entry );
-
-        template<typename ValueType> void
-        readVector( Ogre::DataStreamPtr &stream, std::vector<ValueType> &pDest, size_t count )
-        {
-            pDest.clear();
-            pDest.reserve( count );
-            for( size_t i( count ); i--; )
-            {
-                ValueType in_tmp;
-                readObject( stream, in_tmp );
-                pDest.push_back( in_tmp );
+namespace QGears{
+
+    /**
+     * Manages LGP archives serialization.
+     */
+    class LGPArchiveSerializer : public Serializer{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            LGPArchiveSerializer();
+
+            /**
+             * Destructor.
+             */
+            virtual ~LGPArchiveSerializer();
+
+            /**
+             * Imports an A file.
+             *
+             * @param stream[in] The contents of the archive.
+             * @param dest[out] The formed LGP archive file.
+             */
+            virtual void ImportLGPArchive(
+              Ogre::DataStreamPtr &stream, LGPArchive* dest
+            );
+
+            enum {
+                /**
+                 * Magic MIME string length.
+                 */
+                MAGIC_STRING_LENGTH = 10,
+
+                /**
+                 * Max file name length.
+                 */
+                FILE_NAME_LENGTH = 20
+            };
+
+            typedef LGPArchive::FileEntry FileEntry;
+
+            typedef LGPArchive::FileList  FileList;
+
+        protected:
+
+            /**
+             * Reads an archive header and sets the instance data.
+             *
+             * @param stream[in] The contents of the LGP archive.
+             */
+            virtual void ReadFileHeader(Ogre::DataStreamPtr &stream);
+
+            /**
+             * Reads an object as a LGP archive.
+             *
+             * @param stream[in] Input data.
+             * @param file_entry[out] The formed LGP archive.
+             */
+            virtual void readObject(
+              Ogre::DataStreamPtr &stream, FileEntry& file_entry
+            );
+
+            template<typename ValueType> void ReadVector(
+              Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
+              size_t count
+            ){
+                dest.clear();
+                dest.reserve( count );
+                for (size_t i(count); i --;){
+                    ValueType in_tmp;
+                    readObject(stream, in_tmp);
+                    dest.push_back(in_tmp);
+                }
             }
-        }
 
-    private:
     };
 }
-
-#endif // __QGearsLGPArchiveSerializer_H__

+ 212 - 104
QGearsMain/include/data/QGearsLZSDataStream.h

@@ -1,125 +1,233 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-18 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsLZSDataStream_H__
-#define __QGearsLZSDataStream_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
 #include <OgreDataStream.h>
-
 #include "common/TypeDefine.h"
 
-namespace QGears
-{
-    template<size_t buffer_size>
-    class RingBuffer
-	{
-	public:
-		RingBuffer()
-		{
-			clear();
-		}
-
-		void write( const void *inbuffer_ )
-		{
-		    mbuffer_[m_pos] = *( static_cast<const uint8*>( inbuffer_ ) );
-		    ++m_pos %= buffer_size;
-		    ++m_avail = std::min( m_avail, buffer_size );
-		}
-
-		size_t read( void *outbuffer_, size_t count )
-		{
-		    assert( m_avail && "Can't read if no data is available" );
-		    size_t read( 0 );
-		    uint8 *buffer( static_cast<uint8*>(outbuffer_) );
-		    while( read < count && m_avail )
-            {
-		        *(buffer++) = mbuffer_[(m_pos - m_avail) % buffer_size];
-		        --m_avail;
-		        ++read;
+namespace QGears{
+
+    /**
+     * A ring buffer used by LZS streams.
+     */
+    template<size_t buffer_size> class RingBuffer{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            RingBuffer(){clear();}
+
+            /**
+             * Writes to the buffer from other buffer.
+             *
+             * @param in_buffer[in] The buffer to write from.
+             */
+            void Write(const void *in_buffer_){
+                buffer_[position_] = *(static_cast<const uint8*>(in_buffer_));
+                ++ position_ %= buffer_size;
+                ++ available_ = std::min(available_, buffer_size);
             }
-		    return read;
-		}
-
-		uint8 get( const size_t offset )
-		{
-		    return mbuffer_[offset % buffer_size];
-		}
-
-		size_t avail( void ) const
-		{
-		    return m_avail;
-		}
 
-		void clear()
-		{
-			m_pos = 0;
-			m_avail = 0;
-			memset( mbuffer_, 0, buffer_size );
-		}
-
-	protected:
-		uint8 mbuffer_[buffer_size];
-		size_t m_pos, m_avail;
+            /**
+             * Reads data from the buffer and extracts it into other buffer.
+             *
+             * @param out_buffer[out] Buffer to copy the data from this buffer.
+             * @param count[in] Number of bytes to read.
+             */
+            size_t Read(void *out_buffer, size_t count){
+                assert(available_ && "Can't read if no data is available");
+                size_t read(0);
+                uint8 *buffer(static_cast<uint8*>(out_buffer));
+                while (read < count && available_){
+                    *(buffer ++)
+                      = buffer_[(position_ - available_) % buffer_size];
+                    -- available_;
+                    ++ read;
+                }
+                return read;
+            }
 
-	};
+            /**
+             * Gets data from the buffer at an offset.
+             *
+             * @param offset[in] Offset to the data to read.
+             * @return The data at the offset.
+             * @todo Explain the size of the returned data and offset.
+             */
+            uint8 Get(const size_t offset){
+                return buffer_[offset % buffer_size];
+            }
 
-	//-------------------------------------------------------------------------
-    class LZSDataStream : public Ogre::DataStream
-    {
-    public:
+            /**
+             * Checks the available data size in the buffer.
+             *
+             * @return How much data is left to read in the buffer.
+             */
+            size_t Available() const{return available_;}
+
+            void clear(){
+                position_ = 0;
+                available_ = 0;
+                memset(buffer_, 0, buffer_size);
+            }
 
-                    LZSDataStream( const Ogre::DataStreamPtr &compressed_stream );
-                    LZSDataStream( const String &name, const Ogre::DataStreamPtr &compressed_stream );
-        virtual    ~LZSDataStream();
+        protected:
 
-        virtual size_t 	read( void *buf, size_t count ) override;
+            /**
+             * The buffer.
+             */
+            uint8 buffer_[buffer_size];
 
-        virtual bool    eof( void ) const override;
+            /**
+             * Current buffer position.
+             */
+            size_t position_;
 
-		virtual void skip(long count) override;
-	    virtual void seek( size_t pos ) override;
-	    virtual size_t tell(void) const override;
-        virtual void close(void) override;
+            /**
+             * Available data to read.
+             */
+            size_t available_;
 
-        size_t availableCompressed( void ) const { return m_available_compressed; }
-        size_t availableUncompressed( void ) const { return mbuffer_.avail(); }
+    };
 
-        void flipEndian( uint32 &inout_data );
+    /**
+     * Handles LZS compressed data streams.
+     */
+    class LZSDataStream : public Ogre::DataStream{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param compressed_stream[in] The compressed stream.
+             */
+            LZSDataStream(const Ogre::DataStreamPtr &compressed_stream);
+
+            /**
+             * Constructor.
+             *
+             * @param name[in] NAme for th stream.
+             * @param compressed_stream[in] The compressed stream.
+             */
+            LZSDataStream(
+              const String &name, const Ogre::DataStreamPtr &compressed_stream
+            );
+
+            /**
+             * Destructor.
+             */
+            virtual ~LZSDataStream();
+
+            /**
+             * Reads from the current position of stream into a buffer.
+             *
+             * It also advances the stream cursor.
+             *
+             * @param buf[out] Buffer to read to.
+             * @param count[in] Number of data to read. If the end of the
+             * stream is reached before reading this much, it will stop
+             * reading.
+             */
+            virtual size_t read(void *buf, size_t count) override;
+
+            /**
+             * Indicates if the stream has reached the end.
+             *
+             * @return True if the stream is ended, false otherwise.
+             */
+            virtual bool eof() const override;
+
+            /**
+             * Unimplemented.
+             *
+             * Not required, can use read instead.
+             *
+             * @param count[in] Unused.
+             */
+            virtual void skip(long count) override;
+
+            /**
+             * Unimplemented.
+             *
+             * Not required.
+             *
+             * @param count[in] Unused.
+             */
+            virtual void seek(size_t pos) override;
+
+            /**
+             * Retrieves the current stream position.
+             *
+             * @return The current stream position.
+             */
+            virtual size_t tell() const override;
+
+            /**
+             * Closes the stream.
+             */
+            virtual void close() override;
+
+            /**
+             * @todo Understand and document.
+             *
+             * @return @todo.
+             */
+            size_t AvailableCompressed() const {
+                return available_compressed_;
+            }
 
-    protected:
-        virtual void init();
-        virtual void decompressChunk();
+            /**
+             * @todo Understand and document.
+             *
+             * @return @todo.
+             */
+            size_t AvailableUncompressed() const{
+                return buffer_.Available();
+            }
 
-        Ogre::DataStreamPtr m_compressed_stream;
-        uint32              m_available_compressed;
-        size_t              m_pos;
-        RingBuffer<4096>    mbuffer_;
-    private:
+            /**
+             * Flips the endian mode of some data.
+             *
+             * Little endian data will be transformed into big endian, and big
+             * endian data will be transformed into little endian.
+             *
+             * @param inout_data[in|out] The data to flip.
+             */
+            void FlipEndian(uint32 &inout_data);
+
+        protected:
+
+            /**
+             * Initializes the stream and sets instance data.
+             */
+            virtual void init();
+
+            /**
+             * Decompresses the stream.
+             *
+             * @todo The whole stream?
+             */
+            virtual void DecompressChunk();
+
+            Ogre::DataStreamPtr compressed_stream_;
+            uint32              available_compressed_;
+            size_t              position_;
+            RingBuffer<4096>    buffer_;
     };
 
     typedef Ogre::SharedPtr<LZSDataStream>  LZSDataStreamPtr;
 }
-
-#endif // __QGearsLZSDataStream_H__

+ 67 - 42
QGearsMain/include/data/QGearsLZSFLevelFile.h

@@ -1,53 +1,78 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-24 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsLZSFLevelFile_H__
-#define __QGearsLZSFLevelFile_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "QGearsFLevelFile.h"
 
-namespace QGears
-{
-    class LZSFLevelFile : public FLevelFile
-    {
-    public:
+namespace QGears{
+
+    /**
+     * Handles LZS compressed flevel files.
+     */
+    class LZSFLevelFile : public FLevelFile{
+
+        public:
 
-        LZSFLevelFile( Ogre::ResourceManager *creator, const String &name
-              ,Ogre::ResourceHandle handle, const String &group
-              ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
+            /**
+             * Constructor.
+             *
+             * @param creator[in] Pointer to the ResourceManager that is
+             * creating this resource.
+             * @param name[in] The unique name of the resource.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             */
+            LZSFLevelFile(
+              Ogre::ResourceManager *creator, const String &name,
+              Ogre::ResourceHandle handle, const String &group,
+              bool is_manual = false, Ogre::ManualResourceLoader *loader = NULL
+            );
 
-        virtual ~LZSFLevelFile();
+            /**
+             * Destructor.
+             */
+            virtual ~LZSFLevelFile();
 
-        static const String RESOURCE_TYPE;
+            /**
+             * The type of resource.
+             */
+            static const String RESOURCE_TYPE;
 
-    protected:
-        virtual const String& getResourceType( void ) const;
-        virtual Ogre::DataStreamPtr openResource( void ) override;
+        protected:
+
+            /**
+             * Checks the resource type.
+             *
+             * @return The resource type.
+             */
+            virtual const String& getResourceType() const;
+
+            /**
+             * Opens the resource.
+             */
+            virtual Ogre::DataStreamPtr openResource() override;
 
-    private:
     };
 }
-
-#endif // __QGearsLZSFLevelFile_H__

+ 68 - 43
QGearsMain/include/data/QGearsLZSFLevelFileManager.h

@@ -1,55 +1,80 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-24 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsLZSFLevelFileManager_H__
-#define __QGearsLZSFLevelFileManager_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResourceManager.h>
+#pragma once
 
+#include <OgreResourceManager.h>
 #include "QGearsPrerequisites.h"
-
 #include "QGearsLZSFLevelFile.h"
 
-namespace QGears
-{
-    class _QGearsExport LZSFLevelFileManager : public Ogre::ResourceManager, public Ogre::Singleton<LZSFLevelFileManager>
+namespace QGears{
+
+    /**
+     * A manager for LZS compressed flevel files.
+     */
+    class _QGearsExport LZSFLevelFileManager :
+      public Ogre::ResourceManager, public Ogre::Singleton<LZSFLevelFileManager>
     {
-    public:
-        LZSFLevelFileManager();
-        virtual ~LZSFLevelFileManager();
 
-        static LZSFLevelFileManager& getSingleton();
-        static LZSFLevelFileManager* getSingletonPtr();
+        public:
+
+            /**
+             * Constructor.
+             */
+            LZSFLevelFileManager();
 
-    protected:
-        Ogre::Resource *createImpl( const Ogre::String &name, Ogre::ResourceHandle handle
-          , const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader
-          , const Ogre::NameValuePairList *createParams );
+            /**
+             * Destructor.
+             */
+            virtual ~LZSFLevelFileManager();
+
+            /**
+             * Retrieves a singleton to the manager.
+             */
+            static LZSFLevelFileManager& GetSingleton();
+
+            /**
+             * Retrieves a pointer to the manager singleton.
+             */
+            static LZSFLevelFileManager* GetSingletonPtr();
+
+        protected:
+
+            /**
+             * Loads the manager.
+             *
+             * @param name[in] The unique name of the manager.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             * @param create_params[in] Unused.
+             */
+            Ogre::Resource *createImpl(
+              const Ogre::String &name, Ogre::ResourceHandle handle,
+              const Ogre::String &group, bool is_manual,
+              Ogre::ManualResourceLoader *loader,
+              const Ogre::NameValuePairList *create_params
+            );
 
-    private:
     };
 }
-
-#endif // __QGearsLZSFLevelFileManager_H__

+ 172 - 45
QGearsMain/include/data/QGearsMapListFile.h

@@ -1,3 +1,18 @@
+/*
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
 #pragma once
 
 #include <OgreResourceManager.h>
@@ -5,56 +20,168 @@
 #include "common/QGearsResource.h"
 #include "QGearsSerializer.h"
 
-namespace QGears
-{
+namespace QGears{
+
+    /**
+     * A manager for map list files.
+     */
     class MapListFileManager :
-        public Ogre::ResourceManager,
-        public Ogre::Singleton<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;
+        // TODO: Move to it's own file?
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            MapListFileManager();
+
+            /**
+             * Destructor.
+             */
+            virtual ~MapListFileManager();
+
+            /**
+             * Retrieves a singleton to the manager.
+             */
+            static MapListFileManager& GetSingleton();
+
+            /**
+             * Retrieves a pointer to the manager singleton.
+             */
+            static MapListFileManager* GetSingletonPtr();
+
+        protected:
+
+            /**
+             * Loads the manager.
+             *
+             * @param name[in] The unique name of the manager.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             * @param create_params[in] Unused.
+             */
+            virtual Ogre::Resource *createImpl(
+              const Ogre::String &name, Ogre::ResourceHandle handle,
+              const Ogre::String &group, bool is_manual,
+              Ogre::ManualResourceLoader *loader,
+              const Ogre::NameValuePairList *create_params
+            ) override;
+        };
+
+    /**
+     * Handles map list files.
+     */
+    class MapListFile : public Resource{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param creator[in] Pointer to the ResourceManager that is
+             * creating this resource.
+             * @param name[in] The unique name of the resource.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             */
+            MapListFile(
+              Ogre::ResourceManager* creator, const String &name,
+              Ogre::ResourceHandle handle, const String& group,
+              bool is_manual = false,
+              Ogre::ManualResourceLoader* loader = nullptr
+            );
+
+            /**
+             * Destructor.
+             */
+            virtual ~MapListFile();
+
+            /**
+             * The type of resource.
+             */
+            static const String RESOURCE_TYPE;
+
+            /**
+             * Retrieves the list of maps.
+             *
+             * @return The list of maps.
+             */
+            const std::vector<std::string> GetMapList() const{return map_list_;}
+
+        protected:
+
+            /**
+             * Loads the file.
+             */
+            virtual void loadImpl() override;
+
+            /**
+             * Unloads the file.
+             */
+            virtual void unloadImpl() override;
+
+            /**
+             * Calculates the size of the map list.
+             *
+             * @return The size of the map list.
+             * @todo Units?
+             */
+            virtual size_t calculateSize(void) const override;
+
+        private:
+
+            friend class MapListFileSerializer;
+
+            /**
+             * The list of maps.
+             */
+            std::vector<std::string> map_list_;
     };
 
-    class MapListFileSerializer : public Serializer
-    {
-    public:
-        MapListFileSerializer() = default;
-        void importMapListFile(Ogre::DataStreamPtr &stream, MapListFile& dest);
+    /**
+     * Handles the serialization of map list files.
+     */
+    class MapListFileSerializer : public Serializer{
+
+        // TODO: Move to it's own file?
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            MapListFileSerializer() = default;
+
+            /**
+             * Imports a map list file.
+             *
+             * @param stream[in] The contents of the map list file.
+             * @param dest[out] The formed map list file.
+             */
+            void ImportMapListFile(
+              Ogre::DataStreamPtr &stream, MapListFile& dest
+            );
     };
 
     typedef Ogre::SharedPtr<MapListFile> MapListFilePtr;

+ 450 - 141
QGearsMain/include/data/QGearsPFile.h

@@ -1,156 +1,465 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-11 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsPFile_H__
-#define __QGearsPFile_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreAxisAlignedBox.h>
 #include <OgreColourValue.h>
 #include <OgreMesh.h>
 #include <OgreResource.h>
 #include <Ogre.h>
-
 #include "common/TypeDefine.h"
 #include "common/QGearsManualObject.h"
-
 #include "data/QGearsRSDFile.h"
 
-namespace QGears
-{
-    class PFile : public Ogre::Resource
-    {
-    public:
-
-        PFile( Ogre::ResourceManager *creator, const String &name
-              ,Ogre::ResourceHandle handle, const String &group
-              ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
-
-        virtual ~PFile();
-
-        virtual bool    isValid( void );
-        virtual bool    isPolygonDefinitionListValid( void );
-        virtual void    addGroups( Ogre::Mesh *mesh, const String &bone_name
-                                  ,const RSDFilePtr &rsd ) const;
-
-        struct Edge
-        {
-            uint16 index[2];
-        };
-
-        struct PolygonDefinition
-        {
-            uint16 unknown_00;
-            uint16 vertex[3];
-            uint16 normal[3];
-            uint16 edge[3];
-            uint16 unknown_14;
-            uint16 unknown_16;
-        };
-
-        struct MaterialInformation
-        {
-            uint8 unknown[100];
-        };
-
-        struct Group
-        {
-            uint32 primitive_type;
-            uint32 polygon_start_index;
-            uint32 num_polygons;
-            uint32 vertex_start_index;
-            uint32 num_vertices;
-            uint32 edge_start_index;
-            uint32 num_edges;
-            uint32 unknown_1C;
-            uint32 unknown_20;
-            uint32 unknown_24;
-            uint32 unknown_28;
-            uint32 texture_coordinate_start_index;
-            uint32 has_texture;
-            uint32 texture_index;
-        };
-
-        struct BBoxEntry
-        {
-            uint32 unknown;
-            Ogre::AxisAlignedBox bbox;
-        };
-
-        typedef Ogre::ColourValue               Colour;
-
-        typedef std::vector<Ogre::Vector3>      VertexList;
-        typedef std::vector<Ogre::Vector3>      NormalList;
-        typedef std::vector<Ogre::Vector3>      Unkown1List;
-        typedef std::vector<Ogre::Vector2>      TextureCoordinateList;
-        typedef std::vector<Colour>             VertexColorList;
-        typedef std::vector<Colour>             PolygonColorList;
-        typedef std::vector<Edge>               EdgeList;
-        typedef std::vector<PolygonDefinition>  PolygonDefinitionList;
-        typedef std::vector<Group>              GroupList;
-        typedef std::vector<BBoxEntry>          BBoxList;
-
-        virtual VertexList&             getVertices()           { return m_vertices; }
-        virtual NormalList&             getNormals()            { return m_normals; }
-        virtual Unkown1List&            getUnknown1()           { return m_unknown1; }
-        virtual TextureCoordinateList&  getTextureCoordinates() { return m_texture_coordinates; }
-        virtual VertexColorList&        getVertexColors()       { return m_vertex_colors; }
-        virtual PolygonColorList&       getPolygonColors()      { return m_polygon_colors; }
-        virtual EdgeList&               getEdges()              { return m_edges; }
-        virtual PolygonDefinitionList&  getPolygonDefinitions() { return m_polygon_definitions; }
-        virtual GroupList&              getGroups()             { return m_groups; }
-        virtual BBoxList&               getBBoxes()             { return m_bboxes; }
-
-        static const String RESOURCE_TYPE;
-
-    protected:
-        virtual void loadImpl();
-        virtual void unloadImpl();
-        virtual size_t calculateSize() const;
-
-        virtual void    addGroup( const Group &group, ManualObject &mo
-                                 ,const String &sub_name
-                                 ,const String &material_base_name
-                                 ,const Ogre::Bone *bone ) const;
-        virtual Ogre::Vector3   getPosition( const Ogre::Bone *bone ) const;
-
-        static const Ogre::Quaternion STATIC_ROTATION;
-        static Ogre::Quaternion createStaticRotation();
-    private:
-        VertexList              m_vertices;
-        NormalList              m_normals;
-        Unkown1List             m_unknown1;
-        TextureCoordinateList   m_texture_coordinates;
-        VertexColorList         m_vertex_colors;
-        PolygonColorList        m_polygon_colors;
-        EdgeList                m_edges;
-        PolygonDefinitionList   m_polygon_definitions;
-        GroupList               m_groups;
-        BBoxList                m_bboxes;
+namespace QGears{
+
+    /**
+     * Handles P files.
+     *
+     * P files are binary files containing data which form 3D model. The files
+     * specify model's vertices, polygons, colors, texture coordinates and
+     * model sub-groups. The files do not specify references to the texture
+     * files, animations, model skeleton or anything else. P-files are used as
+     * parts of field models, battle models, battle locations on PC version of
+     * FF7.
+     */
+    class PFile : public Ogre::Resource{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param creator[in] Pointer to the ResourceManager that is
+             * creating this resource.
+             * @param name[in] The unique name of the resource.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             */
+            PFile(
+              Ogre::ResourceManager* creator, const String &name,
+              Ogre::ResourceHandle handle, const String& group,
+              bool is_manual = false,
+              Ogre::ManualResourceLoader* loader = nullptr
+            );
+
+            /**
+             * Destructor.
+             */
+            virtual ~PFile();
+
+            /**
+             * Indicates if the file is a valid P file.
+             *
+             * @return True if the file is a valid P file, false otherwise.
+             */
+            virtual bool IsValid();
+
+            /**
+             * Indicates if the poligons definitions are valid.
+             *
+             * @return True if all the poligon definitions are valid, false
+             * otherwise.
+             */
+            virtual bool IsPolygonDefinitionListValid();
+
+            /**
+             * Adds a resource group.
+             *
+             * A resource group includes a bone, a mesh and a graphical
+             * resource.
+             *
+             * @param mesh[in] The mesh to add to the group.
+             * @param bone_name[in] The bone in the skeleton to which to add
+             * the group. The bone must be in a skeleton assigned to MESH.
+             * @param rsd[in] File with the resource to add to the group.
+             */
+            virtual void AddGroups(
+              Ogre::Mesh *mesh, const String &bone_name, const RSDFilePtr &rsd
+            ) const;
+
+            /**
+             * An edge.
+             */
+            struct Edge{
+
+                /**
+                 * Each of the edge vertices.
+                 */
+                uint16 index[2];
+            };
+
+            /**
+             * A polygon definition in the P file.
+             */
+            struct PolygonDefinition{
+
+                /**
+                 * Unknown data.
+                 */
+                uint16 unknown_00;
+
+                /**
+                 * Polygon vertices (3, always a triangle).
+                 */
+                uint16 vertex[3];
+
+                /**
+                 * The polygon normal (three components).
+                 */
+                uint16 normal[3];
+
+                /**
+                 * The edges of the polygon (3, always a triangle).
+                 */
+                uint16 edge[3];
+
+                /**
+                 * Unknown data.
+                 */
+                uint16 unknown_14;
+
+                /**
+                 * Unknown data.
+                 */
+                uint16 unknown_16;
+            };
+
+            /**
+             * Material information in a P file.
+             */
+            struct MaterialInformation{
+
+                /**
+                 * Unknown data.
+                 */
+                uint8 unknown[100];
+            };
+
+            /**
+             * Group data in a P file.
+             */
+            struct Group{
+
+                /**
+                 * The primitive type of the group.
+                 *
+                 * @todo Understand and document.
+                 */
+                uint32 primitive_type;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                uint32 polygon_start_index;
+
+                /**
+                 * The number of polygons in the group.
+                 */
+                uint32 num_polygons;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                uint32 vertex_start_index;
+
+                /**
+                 * The number of vertices in the group.
+                 */
+                uint32 nuvertices_;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                uint32 edge_start_index;
+
+                /**
+                 * The number of edges in the group.
+                 */
+                uint32 nuedges_;
+
+                /**
+                 * Unknown data.
+                 */
+                uint32 unknown_1C;
+
+                /**
+                 * Unknown data.
+                 */
+                uint32 unknown_20;
+
+                /**
+                 * Unknown data.
+                 */
+                uint32 unknown_24;
+
+                /**
+                 * Unknown data.
+                 */
+                uint32 unknown_28;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                uint32 texture_coordinate_start_index;
+
+                /**
+                 * Indicates if the group has an assigned texture.
+                 */
+                uint32 has_texture;
+
+                /**
+                 * Index of the assigned texture (if any).
+                 */
+                uint32 texture_index;
+            };
+
+            /**
+             * A bounding box entry in a P file.
+             */
+            struct BBoxEntry{
+
+                /**
+                 * Unknown data.
+                 */
+                uint32 unknown;
+
+                /**
+                 * The bounding box.
+                 */
+                Ogre::AxisAlignedBox bbox;
+            };
+
+            typedef Ogre::ColourValue Colour;
+
+            typedef std::vector<Ogre::Vector3> VertexList;
+
+            typedef std::vector<Ogre::Vector3> NormalList;
+
+            typedef std::vector<Ogre::Vector3> Unkown1List;
+
+            typedef std::vector<Ogre::Vector2> TextureCoordinateList;
+
+            typedef std::vector<Colour> VertexColorList;
+
+            typedef std::vector<Colour> PolygonColorList;
+
+            typedef std::vector<Edge> EdgeList;
+
+            typedef std::vector<PolygonDefinition> PolygonDefinitionList;
+
+            typedef std::vector<Group> GroupList;
+
+            typedef std::vector<BBoxEntry> BBoxList;
+
+            /**
+             * Retrieves the vertices in the file.
+             *
+             * @return The vertices in the file.
+             */
+            virtual VertexList& GetVertices(){return vertices_;}
+
+            /**
+             * Retrieves the normals in the file.
+             *
+             * @return The normals in the file.
+             */
+            virtual NormalList& GetNormals(){return normals_;}
+
+            /**
+             * Retrieves unknown data from the file.
+             *
+             * @return Unknown data.
+             */
+            virtual Unkown1List& GetUnknown1(){return unknown_1_;}
+
+            /**
+             * Retrieves the texture coordinates in the file.
+             *
+             * @return The texture coordinates in the file.
+             */
+            virtual TextureCoordinateList& GetTextureCoordinates(){
+                return texture_coordinates_;
+            }
+
+            /**
+             * Retrieves the vertex colurs in the file.
+             *
+             * @return The vertex colurs in the file.
+             */
+            virtual VertexColorList& GetVertexColors(){return vertex_colours_;}
+
+            /**
+             * Retrieves the polygon colours in the file.
+             *
+             * @return The polygon colours in the file.
+             */
+            virtual PolygonColorList& GetPolygonColors(){
+                return polygon_colours_;
+            }
+
+            /**
+             * Retrieves the edges in the file.
+             *
+             * @return The edgesvertices in the file.
+             */
+            virtual EdgeList& GetEdges(){return edges_;}
+
+            /**
+             * Retrieves the polygon definitions in the file.
+             *
+             * @return The polygon definitions in the file.
+             */
+            virtual PolygonDefinitionList& GetPolygonDefinitions(){
+                return polygon_definitions_;
+            }
+
+            /**
+             * Retrieves the groups in the file.
+             *
+             * A group includes a bone, a mesh and a graphical resource.
+             *
+             * @return The groups in the file.
+             */
+            virtual GroupList& GetGroups(){return groups_;}
+
+            /**
+             * Retrieves the bounding boxes in the file.
+             *
+             * @return The vertices in the file.
+             */
+            virtual BBoxList& GetBBoxes(){return bounding_boxes_;}
+
+            static const String RESOURCE_TYPE;
+
+        protected:
+            /**
+             * Loads the file.
+             */
+            virtual void loadImpl() override;
+
+            /**
+             * Unloads the file.
+             */
+            virtual void unloadImpl() override;
+
+            /**
+             * Calculates the size of the palette.
+             *
+             * @return The size of the palette.
+             * @todo Units?
+             */
+            virtual size_t calculateSize() const override;
+
+            /**
+             * Add a group to the file.
+             *
+             * A resource group includes a bone, a mesh and a graphical
+             * resource.
+             *
+             * @param group[in] The group to add to the file.
+             * @param mo[in|out] The object to add to the group.
+             * @param sub_name[in] Name for mo.
+             * @param material_base_name[in] Name of the material for mo.
+             * @param bone[in] The bone to assign to bo.
+             */
+            virtual void AddGroup(
+              const Group &group, ManualObject &mo, const String &sub_name,
+              const String &material_base_name, const Ogre::Bone *bone
+            ) const;
+
+            /**
+             * Retrieves the position of a bone.
+             *
+             * @param bone[in] The bone.
+             * @return The position of the bone.
+             */
+            virtual Ogre::Vector3 GetPosition(const Ogre::Bone *bone) const;
+
+            /**
+             * Static rotation.
+             */
+            static const Ogre::Quaternion STATIC_ROTATION;
+
+            /**
+             * Creates a static rotation.
+             */
+            static Ogre::Quaternion CreateStaticRotation();
+
+        private:
+
+            /**
+             * The list of vertices.
+             */
+            VertexList vertices_;
+
+            /**
+             * The list of normals.
+             */
+            NormalList normals_;
+
+            /**
+             * List of unknown data.
+             */
+            Unkown1List unknown_1_;
+
+            /**
+             * The list of texture coordinates.
+             */
+            TextureCoordinateList texture_coordinates_;
+
+            /**
+             * The list of vertex colours.
+             */
+            VertexColorList vertex_colours_;
+
+            /**
+             * The list of polygon colours.
+             */
+            PolygonColorList polygon_colours_;
+
+            /**
+             * The list of edges.
+             */
+            EdgeList edges_;
+
+            /**
+             * The list of polygon definitions.
+             */
+            PolygonDefinitionList polygon_definitions_;
+
+            /**
+             * The list of groups.
+             */
+            GroupList groups_;
+
+            /**
+             * The list of bounding boxes.
+             */
+            BBoxList bounding_boxes_;
     };
 
     typedef Ogre::SharedPtr<PFile> PFilePtr;
 }
-
-#endif // __QGearsPFile_H__

+ 68 - 44
QGearsMain/include/data/QGearsPFileManager.h

@@ -1,55 +1,79 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-17 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsPFileManager_H__
-#define __QGearsPFileManager_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResourceManager.h>
+#pragma once
 
+#include <OgreResourceManager.h>
 #include "QGearsPrerequisites.h"
-
 #include "QGearsPFile.h"
 
-namespace QGears
-{
-    class _QGearsExport PFileManager : public Ogre::ResourceManager, public Ogre::Singleton<PFileManager>
-    {
-    public:
-        PFileManager();
-        virtual ~PFileManager();
+namespace QGears{
+
+    /**
+     * A manager for P files.
+     */
+    class _QGearsExport PFileManager :
+      public Ogre::ResourceManager, public Ogre::Singleton<PFileManager>{
+
+        public:
 
-        static PFileManager& getSingleton();
-        static PFileManager* getSingletonPtr();
+            /**
+             * Constructor.
+             */
+            PFileManager();
 
-    protected:
-        Ogre::Resource *createImpl( const Ogre::String &name, Ogre::ResourceHandle handle
-          , const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader
-          , const Ogre::NameValuePairList *createParams );
+            /**
+             * Destructor.
+             */
+            virtual ~PFileManager();
+
+            /**
+             * Retrieves a singleton to the manager.
+             */
+            static PFileManager& GetSingleton();
+
+            /**
+             * Retrieves a pointer to the manager singleton.
+             */
+            static PFileManager* GetSingletonPtr();
+
+        protected:
+
+            /**
+             * Loads the manager.
+             *
+             * @param name[in] The unique name of the manager.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             * @param create_params[in] Unused.
+             */
+            Ogre::Resource *createImpl(
+              const Ogre::String &name, Ogre::ResourceHandle handle,
+              const Ogre::String &group, bool is_manual,
+              Ogre::ManualResourceLoader *loader,
+              const Ogre::NameValuePairList *create_params
+            );
 
-    private:
     };
 }
-
-#endif // __QGearsPFileManager_H__

+ 218 - 83
QGearsMain/include/data/QGearsPFileSerializer.h

@@ -1,91 +1,226 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-10 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsPFileSerializer_H__
-#define __QGearsPFileSerializer_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include "common/TypeDefine.h"
+#pragma once
 
+#include "common/TypeDefine.h"
 #include "QGearsPFile.h"
 #include "QGearsSerializer.h"
 
-namespace QGears
-{
-    class PFileSerializer : public Serializer
-    {
-    public:
-                        PFileSerializer();
-        virtual        ~PFileSerializer();
-
-        virtual void    importPFile( Ogre::DataStreamPtr &stream, PFile* pDest );
-
-        struct Header
-        {
-            uint32 version;
-            uint32 unknown_04;
-            uint32 vertex_type;
-            uint32 num_vertices;
-            uint32 num_normals;
-            uint32 num_unknown1;
-            uint32 num_texture_coordinates;
-            uint32 num_vertex_colors;
-            uint32 num_edges;
-            uint32 num_polygons;
-            uint32 num_unknown2;
-            uint32 num_unknown3;
-            uint32 num_materials;
-            uint32 num_groups;
-            uint32 num_bboxes;
-            uint32 norm_index_table_flag;
-            uint32 runtime_data[0x10];
-        };
-
-        typedef PFile::BBoxEntry            BBoxEntry;
-        typedef PFile::Edge                 Edge;
-        typedef PFile::Group                Group;
-        typedef PFile::MaterialInformation  MaterialInformation;
-        typedef PFile::PolygonDefinition    PolygonDefinition;
-        typedef PFile::Colour               Colour;
-
-    protected:
-        virtual void    readFileHeader( Ogre::DataStreamPtr &stream );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, Colour &pDest );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, Edge &pDest );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, PolygonDefinition &pDest );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, Group &pDest );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, BBoxEntry &pDest );
-        using Serializer::readObject;
-
-        template<typename ValueType>
-                void    readVector( Ogre::DataStreamPtr &stream
-                                   ,std::vector<ValueType> &pDest
-                                   ,size_t count );
-
-    private:
-        Header  m_header;
+namespace QGears{
+
+    /**
+     * Handles the serialization of P files.
+     */
+    class PFileSerializer : public Serializer{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            PFileSerializer();
+
+            /**
+             * Destructor.
+             */
+            virtual ~PFileSerializer();
+
+            /**
+             * Imports a P file.
+             *
+             * @param stream[in] The contents of the P file.
+             * @param dest[out] The formed P file.
+             */
+            virtual void ImportPFile(Ogre::DataStreamPtr &stream, PFile* dest);
+
+            /**
+             * The header of a P file.
+             */
+            struct Header{
+
+                /**
+                 * The file format version.
+                 */
+                uint32 version;
+
+                /**
+                 * Unknown data.
+                 */
+                uint32 unknown_04;
+
+                /**
+                 * Type of vertices.
+                 */
+                uint32 vertex_type;
+
+                /**
+                 * The number of vertices.
+                 */
+                uint32 num_vertices;
+
+                /**
+                 * The number of normals.
+                 */
+                uint32 num_normals;
+
+                /**
+                 * Number of unknown data blocks.
+                 */
+                uint32 num_unknown1;
+
+                /**
+                 * Number of texture coordinates.
+                 */
+                uint32 num_texture_coordinates;
+
+                /**
+                 * Number of vertex colours.
+                 */
+                uint32 num_vertex_colors;
+
+                /**
+                 * Number of edges.
+                 */
+                uint32 num_edges;
+
+                /**
+                 * Number of polygons.
+                 */
+                uint32 num_polygons;
+
+                /**
+                 * Number of unknown data blocks.
+                 */
+                uint32 num_unknown2;
+
+                /**
+                 * Number of unknown data blocks.
+                 */
+                uint32 num_unknown3;
+
+                /**
+                 * Number of materials.
+                 */
+                uint32 num_materials;
+
+                /**
+                 * Number of groups.
+                 */
+                uint32 num_groups;
+
+                /**
+                 * Number of bounding boxes.
+                 */
+                uint32 num_bboxes;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                uint32 norm_index_table_flag;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                uint32 runtime_data[0x10];
+            };
+
+            typedef PFile::BBoxEntry BBoxEntry;
+
+            typedef PFile::Edge Edge;
+
+            typedef PFile::Group Group;
+
+            typedef PFile::MaterialInformation MaterialInformation;
+
+            typedef PFile::PolygonDefinition PolygonDefinition;
+
+            typedef PFile::Colour Colour;
+
+        protected:
+
+            /**
+             * Reads a file header and sets the instance data.
+             *
+             * @param stream[in] The contents of the P file.
+             */
+            virtual void ReadFileHeader(Ogre::DataStreamPtr &stream);
+
+            /**
+             * Reads an object as a colour.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed colour data.
+             */
+            virtual void readObject(Ogre::DataStreamPtr &stream, Colour &dest);
+
+            /**
+             * Reads an object as an edge.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed edge data.
+             */
+            virtual void readObject(Ogre::DataStreamPtr &stream, Edge &dest);
+
+            /**
+             * Reads an object as a polygon definition.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed poligon definition data.
+             */
+            virtual void readObject(
+              Ogre::DataStreamPtr &stream, PolygonDefinition &dest
+            );
+
+            /**
+             * Reads an object as a group.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed group data.
+             */
+            virtual void readObject(Ogre::DataStreamPtr &stream, Group &dest);
+
+            /**
+             * Reads an object as a bounding box.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed bounding box data.
+             */
+            virtual void readObject(
+              Ogre::DataStreamPtr &stream, BBoxEntry &dest
+            );
+
+            using Serializer::readObject;
+
+            /**
+             * Reads a stream as a vector.
+             *
+             * @param stream[in] The input stream.
+             * @param dest[out] The vector data will be loaded here.
+             * @param count[in] Data units to copy.
+             */
+            template<typename ValueType> void ReadVector(
+              Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
+              size_t count
+            );
+
+        private:
+
+            /**
+             * The file header.
+             */
+            Header header_;
     };
 }
-
-#endif // __QGearsPFileSerializer_H__

+ 108 - 58
QGearsMain/include/data/QGearsPaletteFile.h

@@ -1,68 +1,118 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-22 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsPaletteFile_H__
-#define __QGearsPaletteFile_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreColourValue.h>
 #include <OgreResource.h>
-
 #include "common/TypeDefine.h"
 
-namespace QGears
-{
-    class PaletteFile : public Ogre::Resource
-    {
-    public:
-
-        PaletteFile( Ogre::ResourceManager *creator, const String &name
-              ,Ogre::ResourceHandle handle, const String &group
-              ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
-
-        virtual ~PaletteFile();
-
-        static const String RESOURCE_TYPE;
-
-        typedef Ogre::ColourValue   Color;
-        typedef std::vector<Color>  Page;
-        typedef std::vector<Page>   PageList;
-
-        virtual PageList&  getPages( void ) { return m_pages; }
-
-        virtual const Page& getPage( size_t index ) const { return m_pages.at(index); }
-
-    protected:
-        virtual void loadImpl();
-        virtual void unloadImpl();
-        virtual size_t calculateSize() const;
-
-    private:
-        PageList m_pages;
+namespace QGears{
+
+    /**
+     * Handles colour palette files.
+     */
+    class PaletteFile : public Ogre::Resource{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param creator[in] Pointer to the ResourceManager that is
+             * creating this resource.
+             * @param name[in] The unique name of the resource.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             */
+            PaletteFile(
+              Ogre::ResourceManager* creator, const String &name,
+              Ogre::ResourceHandle handle, const String& group,
+              bool is_manual = false,
+              Ogre::ManualResourceLoader* loader = nullptr
+           );
+
+            /**
+            * Destructor.
+            */
+            virtual ~PaletteFile();
+
+            /**
+             * The type of resource.
+             */
+            static const String RESOURCE_TYPE;
+
+            typedef Ogre::ColourValue Color;
+
+            typedef std::vector<Color> Page;
+
+            typedef std::vector<Page> PageList;
+
+            /**
+             * Retrieevs the list of pages.
+             *
+             * @return The list of pages.
+             */
+            virtual PageList& GetPages(){return pages_;}
+
+            /**
+             * Retrieves a page.
+             *
+             * @param index[in] Page index.
+             * @return The page at the specified index.
+             */
+            virtual const Page& GetPage(size_t index) const{
+                return pages_.at(index);
+            }
+
+        protected:
+
+            /**
+             * Loads the file.
+             */
+            virtual void loadImpl() override;
+
+            /**
+             * Unloads the file.
+             */
+            virtual void unloadImpl() override;
+
+            /**
+             * Calculates the size of the palette.
+             *
+             * @return The size of the palette.
+             * @todo Units?
+             */
+            virtual size_t calculateSize() const override;
+
+        private:
+
+            /**
+             * The list of palette pages.
+             */
+            PageList pages_;
     };
 
     typedef Ogre::SharedPtr<PaletteFile> PaletteFilePtr;
 }
-
-#endif // __QGearsPaletteFile_H__

+ 68 - 44
QGearsMain/include/data/QGearsPaletteFileManager.h

@@ -1,55 +1,79 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-22 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsPaletteFileManager_H__
-#define __QGearsPaletteFileManager_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResourceManager.h>
+#pragma once
 
+#include <OgreResourceManager.h>
 #include "QGearsPrerequisites.h"
-
 #include "QGearsPaletteFile.h"
 
-namespace QGears
-{
-    class _QGearsExport PaletteFileManager : public Ogre::ResourceManager, public Ogre::Singleton<PaletteFileManager>
-    {
-    public:
-        PaletteFileManager();
-        virtual ~PaletteFileManager();
+namespace QGears{
+
+    /**
+     * A manager for palette files.
+     */
+    class _QGearsExport PaletteFileManager :
+      public Ogre::ResourceManager, public Ogre::Singleton<PaletteFileManager>{
+
+        public:
 
-        static PaletteFileManager& getSingleton();
-        static PaletteFileManager* getSingletonPtr();
+            /**
+             * Constructor.
+             */
+            PaletteFileManager();
 
-    protected:
-        Ogre::Resource *createImpl( const Ogre::String &name, Ogre::ResourceHandle handle
-          , const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader
-          , const Ogre::NameValuePairList *createParams );
+            /**
+             * Destructor.
+             */
+            virtual ~PaletteFileManager();
+
+            /**
+             * Retrieves a singleton to the manager.
+             */
+            static PaletteFileManager& GetSingleton();
+
+            /**
+             * Retrieves a pointer to the manager singleton.
+             */
+            static PaletteFileManager* GetSingletonPtr();
+
+        protected:
+
+            /**
+             * Loads the manager.
+             *
+             * @param name[in] The unique name of the manager.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             * @param create_params[in] Unused.
+             */
+            Ogre::Resource *createImpl(
+              const Ogre::String &name, Ogre::ResourceHandle handle,
+              const Ogre::String &group, bool is_manual,
+              Ogre::ManualResourceLoader *loader,
+              const Ogre::NameValuePairList *create_params
+            );
 
-    private:
     };
 }
-
-#endif // __QGearsPaletteFileManager_H__

+ 180 - 84
QGearsMain/include/data/QGearsPaletteFileSerializer.h

@@ -1,95 +1,191 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-22 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsPaletteFileSerializer_H__
-#define __QGearsPaletteFileSerializer_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgrePixelFormat.h>
-
 #include "common/TypeDefine.h"
-
 #include "QGearsPaletteFile.h"
 #include "QGearsSerializer.h"
 
-namespace QGears
-{
-    class PaletteFileSerializer : public Serializer
-    {
-    public:
-                        PaletteFileSerializer();
-        virtual        ~PaletteFileSerializer();
-
-        virtual void 	importPaletteFile( Ogre::DataStreamPtr &stream, PaletteFile* pDest );
-
-        enum {
-            BIT_MASK_RED    = 0x001F
-           ,BIT_MASK_GREEN  = 0x03E0
-           ,BIT_MASK_BLUE   = 0x7C00
-           ,BIT_SIZE        = 0x001F
-           ,BIT_MASK_RGB    = BIT_MASK_BLUE | BIT_MASK_GREEN | BIT_MASK_RED
-           ,BIT_MASK_ALPHA  = 0x8000
-        };
-
-        struct Header
-        {
-            uint32 file_size;
-            uint16 pal_x;
-            uint16 pal_y;
-            uint16 colors_per_page;
-            uint16 page_count;
-        };
-
-        typedef PaletteFile::Color  Color;
-        typedef PaletteFile::Page   Page;
-
-    protected:
-        virtual void 	readFileHeader( Ogre::DataStreamPtr &stream );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, Color &pDest );
-        virtual void    readObject( Ogre::DataStreamPtr &stream, Page &pDest );
-        using Serializer::readObject;
-
-        virtual void    convertColour( uint16 &colour ) const;
-
-        static const Ogre::PixelFormat  PIXEL_FORMAT;
-
-        template<typename ValueType> void
-        readVector( Ogre::DataStreamPtr &stream, std::vector<ValueType> &pDest, size_t count )
-        {
-            pDest.clear();
-            pDest.reserve( count );
-            for( size_t i( count ); i--; )
-            {
-                ValueType in_tmp;
-                readObject( stream, in_tmp );
-                pDest.push_back( in_tmp );
+namespace QGears{
+
+    /**
+     * Handles the serialization of colour palette files.
+     */
+    class PaletteFileSerializer : public Serializer{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            PaletteFileSerializer();
+
+            /**
+             * Destructor.
+             */
+            virtual ~PaletteFileSerializer();
+
+            /**
+             * Imports a colour palette file.
+             *
+             * @param stream[in] The contents of the palette file.
+             * @param dest[out] The formed palette file.
+             */
+            virtual void ImportPaletteFile(
+              Ogre::DataStreamPtr &stream, PaletteFile* dest
+            );
+
+            enum {
+
+                /**
+                 * Bitmask for red colour.
+                 */
+                BIT_MASK_RED = 0x001F,
+
+                /**
+                 * Bitmask for green colour.
+                 */
+                BIT_MASK_GREEN = 0x03E0,
+
+                /**
+                 * Bitmask for blie colour.
+                 */
+                BIT_MASK_BLUE = 0x7C00,
+
+                /**
+                 * Bitmask for palette size.
+                 */
+                BIT_SIZE = 0x001F,
+
+                /**
+                 * Bitmask for RGB colour.
+                 */
+                BIT_MASK_RGB = BIT_MASK_BLUE | BIT_MASK_GREEN | BIT_MASK_RED,
+
+                /**
+                 * Bitmask for alpha component.
+                 */
+                BIT_MASK_ALPHA  = 0x8000
+            };
+
+            /**
+             * A colour palette file header.
+             */
+            struct Header{
+
+                /**
+                 * The size of the file.
+                 */
+                uint32 file_size;
+
+                /**
+                 * The X coordinate of the palette.
+                 *
+                 * @todo Units?
+                 */
+                uint16 pal_x;
+
+                /**
+                 * The Y coordinate of the palette.
+                 *
+                 * @todo Units?
+                 */
+                uint16 pal_y;
+
+                /**
+                 * The number of colurs per palette page.
+                 */
+                uint16 colors_per_page;
+
+                /**
+                 * The number of palette pages.
+                 */
+                uint16 page_count;
+            };
+
+            typedef PaletteFile::Color Color;
+
+            typedef PaletteFile::Page Page;
+
+        protected:
+
+            /**
+             * Reads a file header and sets the instance data.
+             *
+             * @param stream[in] The contents of the HRC file.
+             */
+            virtual void ReadFileHeader(Ogre::DataStreamPtr &stream);
+
+            /**
+             * Reads an object as a colour.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed colour data.
+             */
+            virtual void readObject(Ogre::DataStreamPtr &stream, Color &dest);
+
+            /**
+             * Reads an object as a palette page.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed page data.
+             */
+            virtual void readObject(Ogre::DataStreamPtr &stream, Page &dest);
+
+            using Serializer::readObject;
+
+            /**
+             * Converts a colour.
+             *
+             * @param [in|out] Colour to convert.
+             * @todo What kind of conversion is it doing?
+             */
+            virtual void ConvertColour(uint16 &colour) const;
+
+            /**
+             * A pixel format.
+             */
+            static const Ogre::PixelFormat PIXEL_FORMAT;
+
+            /**
+             * Reads a stream as a vector.
+             *
+             * @param stream[in] The input stream.
+             * @param dest[out] The vector data will be loaded here.
+             * @param count[in] Data units to copy.
+             */
+            template<typename ValueType> void ReadVector(
+              Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
+              size_t count
+            ){
+                dest.clear();
+                dest.reserve(count);
+                for (size_t i(count); i --;){
+                    ValueType in_tmp;
+                    readObject(stream, in_tmp);
+                    dest.push_back(in_tmp);
+                }
             }
-        }
 
-    private:
-        Header  m_header;
+        private:
+
+            /**
+             * The file header.
+             */
+            Header header_;
     };
 }
-
-#endif // __QGearsPaletteFileSerializer_H__

+ 189 - 68
QGearsMain/include/data/QGearsRSDFile.h

@@ -1,78 +1,199 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-16 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsRSDFile_H__
-#define __QGearsRSDFile_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreResource.h>
 #include <OgreMaterial.h>
-
 #include "common/TypeDefine.h"
 
-namespace QGears
-{
-    class RSDFile : public Ogre::Resource
-    {
-    public:
-        RSDFile( Ogre::ResourceManager *creator, const String &name
-                ,Ogre::ResourceHandle handle, const String &group
-                ,bool isManual = false, Ogre::ManualResourceLoader *loader = NULL );
-
-        virtual ~RSDFile();
-
-        static const String RESOURCE_TYPE;
-
-        typedef std::vector<String>             TextureNameList;
-        typedef std::vector<Ogre::MaterialPtr>  MaterialList;
-
-        virtual void setPolygonName ( const String &polygon_name );
-        virtual void setMaterialName( const String &material_name );
-        virtual void setGroupName   ( const String &group_name );
-
-        virtual const String& getPolygonName ( void ) const;
-        virtual const String& getMaterialName( void ) const;
-        virtual const String& getGroupName   ( void ) const;
-        virtual size_t getTextureNameCount   ( void ) const;
-        virtual TextureNameList& getTextureNames( void );
-        virtual String getMaterialBaseName( void ) const;
-
-    protected:
-        virtual void    loadImpl();
-        virtual void    unloadImpl();
-        virtual size_t  calculateSize() const;
-        virtual void    addTexture( Ogre::Pass *pass, const size_t index ) const;
-
-    private:
-        String          m_polygon_name;
-        String          m_material_name;
-        String          m_group_name;
-        TextureNameList m_texture_names;
-        MaterialList    m_materials;
+namespace QGears{
+
+    /**
+     * Handles RDS files.
+     *
+     * RSD files are product of the original PlayStation Psy-Q 3D development
+     * libraries. They are often exported by 3D modelers when converting from
+     * an LWO or DXF file to something more understandable by the PSX. They are
+     * in ascii, making it easy to edit by hand. When a 3D editor does an
+     * export, four text files are actually created, .rsd, .ply, .mat, and
+     * .grp. These can then be "compiled" into a binary .rsd file for the PSX.
+     * In the PC version of Final Fantasy 7, the text .rsd files are used while
+     * the other files were "compiled" into Polygon(.p) format.
+     */
+    class RSDFile : public Ogre::Resource{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * @param creator[in] Pointer to the ResourceManager that is
+             * creating this resource.
+             * @param name[in] The unique name of the resource.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             */
+            RSDFile(
+              Ogre::ResourceManager* creator, const String &name,
+              Ogre::ResourceHandle handle, const String& group,
+              bool is_manual = false,
+              Ogre::ManualResourceLoader* loader = nullptr
+            );
+
+            /**
+             * Destructor.
+             */
+            virtual ~RSDFile();
+
+            /**
+             * The resource type.
+             */
+            static const String RESOURCE_TYPE;
+
+            typedef std::vector<String> TextureNameList;
+
+            typedef std::vector<Ogre::MaterialPtr> MaterialList;
+
+            /**
+             * Sets the name of the polygon.
+             *
+             * @param polygon_name[in] The name for the polygon.
+             */
+            virtual void SetPolygonName(const String &polygon_name);
+
+            /**
+             * Sets the material type.
+             *
+             * @param material_name[in] The material name.
+             */
+            virtual void SetMaterialName(const String &material_name);
+
+            /**
+             * Sets the group name.
+             *
+             * @param group_name[in] The name for the group.
+             */
+            virtual void SetGroupName(const String &group_name);
+
+            /**
+             * Retrieves the polygon name.
+             *
+             * @return The polygon name.
+             */
+            virtual const String& GetPolygonName() const;
+
+            /**
+             * Retrieves the material name.
+             *
+             * @return The matyerial name.
+             */
+            virtual const String& GetMaterialName() const;
+
+            /**
+             * Retrieves the group name.
+             *
+             * @return The group name.
+             */
+            virtual const String& GetGroupName() const;
+
+            /**
+             * Counts the texture names.
+             *
+             * @return The number of texture names.
+             */
+            virtual size_t GetTextureNameCount() const;
+
+            /**
+             * Retrieves the list of texture names.
+             *
+             * @return The list of texture names.
+             */
+            virtual TextureNameList& GetTextureNames();
+
+            /**
+             * Retrieves the material base.
+             *
+             * @return The material base name.
+             */
+            virtual String GetMaterialBaseName() const;
+
+        protected:
+
+            /**
+             * Loads the file.
+             */
+            virtual void loadImpl() override;
+
+            /**
+             * Unloads the file.
+             */
+            virtual void unloadImpl() override;
+
+            /**
+             * Calculates the size of the palette.
+             *
+             * @return The size of the palette.
+             * @todo Units?
+             */
+            virtual size_t  calculateSize() const;
+
+            /**
+             * Adds a texture.
+             *
+             * @param pass[in|out] Render pas options.
+             * @param index[in] Index of the texture to add
+             */
+            virtual void AddTexture(Ogre::Pass *pass, const size_t index) const;
+
+        private:
+
+            /**
+             * The polygon names.
+             */
+            String polygon_name_;
+
+            /**
+             * The material type.
+             */
+            String material_name_;
+
+            /**
+             * The group name.
+             */
+            String group_name_;
+
+            /**
+             * The texture name.
+             */
+            TextureNameList texture_names_;
+
+            /**
+             * The lsit of materials
+             */
+            MaterialList materials_;
     };
 
     typedef Ogre::SharedPtr<RSDFile> RSDFilePtr;
 }
-
-#endif // __QGearsRSDFile_H__

+ 76 - 44
QGearsMain/include/data/QGearsRSDFileManager.h

@@ -1,57 +1,89 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-16 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsRSDFileManager_H__
-#define __QGearsRSDFileManager_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <OgreResourceManager.h>
+#pragma once
 
+#include <OgreResourceManager.h>
 #include "QGearsPrerequisites.h"
-
 #include "QGearsRSDFile.h"
 
-namespace QGears
-{
-    class _QGearsExport RSDFileManager : public Ogre::ResourceManager, public Ogre::Singleton<RSDFileManager>
+namespace QGears{
+
+    /**
+     * A manager for RDS files.
+     */
+    class _QGearsExport RSDFileManager :
+      public Ogre::ResourceManager, public Ogre::Singleton<RSDFileManager>
     {
-    public:
-        RSDFileManager();
-        virtual ~RSDFileManager();
+        public:
+
+            /**
+             * Constructor.
+             */
+            RSDFileManager();
 
-        static RSDFileManager& getSingleton();
-        static RSDFileManager* getSingletonPtr();
+            /**
+             * Destructor.
+             */
+            virtual ~RSDFileManager();
 
-        virtual void parseScript( Ogre::DataStreamPtr &stream, const String &groupName );
+            /**
+             * Retrieves a singleton to the manager.
+             */
+            static RSDFileManager& GetSingleton();
 
-    protected:
-        Ogre::Resource *createImpl( const Ogre::String &name, Ogre::ResourceHandle handle
-          , const Ogre::String &group, bool isManual, Ogre::ManualResourceLoader *loader
-          , const Ogre::NameValuePairList *createParams );
+            /**
+             * Retrieves a pointer to the manager singleton.
+             */
+            static RSDFileManager* GetSingletonPtr();
+
+            /**
+             * Parses the file script and adds the resource.
+             *
+             * @param stream[in] The contents of the file.
+             * @param group_name[in] Name of the group to add the resource to.
+             */
+            virtual void ParseScript(
+              Ogre::DataStreamPtr &stream, const String &group_name
+            );
+
+        protected:
+
+            /**
+             * Loads the manager.
+             *
+             * @param name[in] The unique name of the manager.
+             * @param handle[in] @todo Understand and document.
+             * @param group[in] The name of the resource group to which this
+             * resource belong.
+             * @param is_manual[in] True if the resource is manually loaded,
+             * false otherwise.
+             * @param loader[in] Pointer to a ManualResourceLoader
+             * implementation which will be called when the Resource wishes to
+             * load (should be supplied if is_manual is set to true). It can be
+             * null, but the Resource will never be able to reload if anything
+             * ever causes it to unload. Therefore provision of a proper
+             * ManualResourceLoader instance is strongly recommended.
+             * @param create_params[in] Unused.
+             */
+            Ogre::Resource *createImpl(
+              const Ogre::String &name, Ogre::ResourceHandle handle,
+              const Ogre::String &group, bool is_manual,
+              Ogre::ManualResourceLoader *loader,
+              const Ogre::NameValuePairList *create_params
+            );
 
-    private:
     };
 }
-
-#endif // __QGearsRSDFileManager_H__

+ 106 - 53
QGearsMain/include/data/QGearsRSDFileSerializer.h

@@ -1,61 +1,114 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-10 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsRSDFileSerializer_H__
-#define __QGearsRSDFileSerializer_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include "QGearsRSDFile.h"
 #include "QGearsSerializer.h"
-
 #include "common/TypeDefine.h"
 
-namespace QGears
-{
-    class RSDFileSerializer : public Serializer
-    {
-    public:
-                        RSDFileSerializer();
-        virtual        ~RSDFileSerializer();
-
-        virtual void 	importRSDFile( Ogre::DataStreamPtr &stream, RSDFile* pDest );
-
-    protected:
-        virtual void 	readFileHeader( Ogre::DataStreamPtr &stream );
-        virtual void    parseLine( const String &line, RSDFile* pDest );
-
-        static const String TAG_HEADER;
-        static const String TAG_POLYGON;
-        static const String TAG_MATERIAL;
-        static const String TAG_GROUP;
-        static const String TAG_TEXTURE_COUNT;
-        static const String TAG_TEXTURE_NAME;
-        static const String PARSE_DELIMITER;
-    private:
-        bool    m_has_texture_count;
-        size_t  m_texture_count;
+namespace QGears{
+
+    /**
+     * Handles the serialization of RDS files.
+     */
+    class RSDFileSerializer : public Serializer{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            RSDFileSerializer();
+
+            /**
+             * Destructor.
+             */
+            virtual ~RSDFileSerializer();
+
+            /**
+             * Imports a RSD file.
+             *
+             * @param stream[in] The contents of the RSD file.
+             * @param dest[out] The formed RSD file.
+             */
+            virtual void ImportRSDFile(
+              Ogre::DataStreamPtr &stream, RSDFile* dest
+            );
+
+        protected:
+
+            /**
+             * Reads a file header and sets the instance data.
+             *
+             * @param stream[in] The contents of the RSD file.
+             */
+            virtual void ReadFileHeader(Ogre::DataStreamPtr &stream);
+
+            /**
+             * Parses a line of the RSD file.
+             *
+             * @param line[in] The line to parse.
+             */
+            virtual void ParseLine(const String &line, RSDFile* dest);
+
+            /**
+             * The file header tag.
+             */
+            static const String TAG_HEADER;
+
+            /**
+             * The polygon tag.
+             */
+            static const String TAG_POLYGON;
+
+            /**
+             * The material tag.
+             */
+            static const String TAG_MATERIAL;
+
+            /**
+             * The group tag.
+             */
+            static const String TAG_GROUP;
+
+            /**
+             * The texture count tag.
+             */
+            static const String TAG_TEXTURE_COUNT;
+
+            /**
+             * The texture name tag.
+             */
+            static const String TAG_TEXTURE_NAME;
+
+            /**
+             * Delimiter for line parsing.
+             */
+            static const String PARSE_DELIMITER;
+
+        private:
+
+            /**
+             * Indicates if the file has a texture count.
+             */
+            bool has_texture_count_;
+
+            /**
+             * The texture count (if any).
+             */
+            size_t  texture_count_;
     };
 }
-
-#endif // __QGearsRSDFileSerializer_H__

+ 213 - 68
QGearsMain/include/data/QGearsSerializer.h

@@ -1,80 +1,225 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-08-10 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsSerializer_H__
-#define __QGearsSerializer_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreAxisAlignedBox.h>
 #include <OgreColourValue.h>
 #include <OgreDataStream.h>
 #include <OgreSerializer.h>
 #include <Ogre.h>
-
 #include "common/TypeDefine.h"
 
-namespace QGears
-{
-    class Serializer : public Ogre::Serializer
-    {
-    public:
-                        Serializer();
-        virtual        ~Serializer();
-
-        // TODO implement some more serialization!?
-        // ISerializeable  readObject( serializer )
-        // virtual void readObject( ISerializable o ) { o.readObject( this ); }
-        // template<T> readObject( T )
-    protected:
-        void    readObject( Ogre::DataStreamPtr &stream, Ogre::Vector2 &pDest );
-        void    readObject( Ogre::DataStreamPtr &stream, Ogre::Vector3 &pDest );
-        void    readObject( Ogre::DataStreamPtr &stream, Ogre::AxisAlignedBox &pDest );
-        void    readObject( Ogre::DataStreamPtr &stream, Pixel &pDest );
-
-        void readChars(Ogre::DataStreamPtr& stream, char* pDest, size_t count);
-        void    read1ByteBool( Ogre::DataStreamPtr &stream, bool &pDest );
-        void    read2ByteBool( Ogre::DataStreamPtr &stream, bool &pDest );
-        void    readShort( Ogre::DataStreamPtr &stream, uint16 &pDest );
-        void    readInt16( Ogre::DataStream &stream, sint16 &pDest );
-        void    readUInt16( Ogre::DataStream &stream, uint16 &pDest );
-        void    readInt16( Ogre::DataStreamPtr &stream, sint16 &pDest );
-        void    readUInt16( Ogre::DataStreamPtr &stream, uint16 &pDest );
-        void    readUInt32( Ogre::DataStreamPtr &stream, uint32 &pDest );
-        void    readSInt32(Ogre::DataStreamPtr &stream, sint32 &pDest);
-        void    readUInt32( Ogre::DataStream &stream, uint32 &pDest );
-        void    readUInt8( Ogre::DataStream& stream, uint8 &pDest );
-        void    readUInt8(Ogre::DataStreamPtr &stream, uint8 &pDest );
-        void    readFloat( Ogre::DataStreamPtr &stream, float &pDest );
-        void    readEndString( Ogre::DataStreamPtr &stream, const String &end_text );
-
-
-        String  getLine( Ogre::DataStreamPtr &stream ) const;
-
-        static const String TAG_COMMENT;
-
-    private:
+namespace QGears{
+
+    /**
+     * Handles file serialization.
+     */
+    class Serializer : public Ogre::Serializer{
+
+        public:
+
+            /**
+             * Constructor.
+             *
+             * Determines the endian mode of the file.
+             */
+            Serializer();
+
+            /**
+             * Destructor
+             */
+            virtual ~Serializer();
+
+            // TODO implement some more serialization!?
+            // ISerializeable  readObject(serializer)
+            // virtual void readObject(ISerializable o) { o.readObject(this); }
+            // template<T> readObject(T)
+
+        protected:
+
+            /**
+             * Reads an object as a 2 dimensional vector.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed vector data.
+             */
+            void readObject(Ogre::DataStreamPtr &stream, Ogre::Vector2 &dest);
+
+            /**
+             * Reads an object as a 3 dimensional vector.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed vector data.
+             */
+            void readObject(Ogre::DataStreamPtr &stream, Ogre::Vector3 &dest);
+
+            /**
+             * Reads an object as an axis aligned box.
+             *
+             * Can be used for bounding boxes.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed box data.
+             */
+            void readObject(
+              Ogre::DataStreamPtr &stream, Ogre::AxisAlignedBox &dest
+            );
+
+            /**
+             * Reads an object as a pixel.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The formed pixel data.
+             */
+            void readObject(Ogre::DataStreamPtr &stream, Pixel &dest);
+
+            /**
+             * Reads a stream as text.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The read characters will be stored here.
+             * @param count[in] Read this many characters.
+             */
+            void ReadChars(
+              Ogre::DataStreamPtr& stream, char* dest, size_t count
+            );
+
+            /**
+             * Reads one byte from a stream and evaluates it as a boolean.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated boolean.
+             * @todo 1 is true?
+             */
+            void Read1ByteBool(Ogre::DataStreamPtr &stream, bool &dest);
+
+            /**
+             * Reads two bytes from a stream and evaluates them as a boolean.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated boolean.
+             * @todo 1 is true?
+             */
+            void Read2ByteBool(Ogre::DataStreamPtr &stream, bool &dest);
+
+            /**
+             * Reads 16 bytes from a stream and evaluates as an unsigned short.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadShort(Ogre::DataStreamPtr &stream, uint16 &dest);
+
+            /**
+             * Reads 16 bytes from a stream and evaluates as a signed integer.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadInt16(Ogre::DataStream &stream, sint16 &dest);
+
+            /**
+             * Reads 16 bytes from a stream and evaluates as an unsigned int.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadUInt16(Ogre::DataStream &stream, uint16 &dest);
+
+            /**
+             * Reads 16 bytes from a stream and evaluates as a signed integer.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadInt16(Ogre::DataStreamPtr &stream, sint16 &dest);
+
+            /**
+             * Reads 16 bytes from a stream and evaluates as an unsigned int.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadUInt16(Ogre::DataStreamPtr &stream, uint16 &dest);
+
+            /**
+             * Reads 32 bytes from a stream and evaluates as an unsigned int.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadUInt32(Ogre::DataStreamPtr &stream, uint32 &dest);
+
+            /**
+             * Reads 32 bytes from a stream and evaluates as a signed int.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadSInt32(Ogre::DataStreamPtr &stream, sint32 &dest);
+
+            /**
+             * Reads 32 bytes from a stream and evaluates as an unsigned int.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadUInt32(Ogre::DataStream &stream, uint32 &dest);
+
+            /**
+             * Reads 8 bytes from a stream and evaluates as an unsigned int.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadUInt8(Ogre::DataStream& stream, uint8 &dest);
+
+            /**
+             * Reads 8 bytes from a stream and evaluates as an unsigned int.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadUInt8(Ogre::DataStreamPtr &stream, uint8 &dest);
+
+            /**
+             * Reads bytes from a stream and evaluates them as a float.
+             *
+             * @param stream[in] Input data.
+             * @param dest[out] The evaluated number.
+             */
+            void ReadFloat(Ogre::DataStreamPtr &stream, float &dest);
+
+            /**
+             * @todo Understand and document.
+             */
+            void ReadEndString(
+              Ogre::DataStreamPtr &stream, const String &end_text
+            );
+
+            /**
+             * @todo Understand and document.
+             */
+            String GetLine(Ogre::DataStreamPtr &stream) const;
+
+            /**
+             * A comment tag.
+             */
+            static const String TAG_COMMENT;
+
     };
 }
 
-#endif // __QGearsSerializer_H__

+ 153 - 65
QGearsMain/include/data/QGearsTexCodec.h

@@ -1,73 +1,161 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-07-30 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsTexCodec_H__
-#define __QGearsTexCodec_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#pragma once
 
 #include <OgreImageCodec.h>
 #include <OgreCodec.h>
-
 #include "QGearsPrerequisites.h"
 
-namespace QGears
-{
-    class _QGearsExport TexCodec : public Ogre::ImageCodec
-    {
-    public:
-        TexCodec();
-        virtual ~TexCodec();
-
-        /// @copydoc Ogre::ImageCodec::getType
-        virtual Ogre::String getType() const;
-
-        virtual Ogre::DataStreamPtr encode(Ogre::MemoryDataStreamPtr& input, CodecDataPtr& pData) const final;
-        virtual void encodeToFile(Ogre::MemoryDataStreamPtr& input, const Ogre::String& outFileName, CodecDataPtr& pData) const final;
-
-        /// @copydoc Ogre::Codec::decode
-        Ogre::Codec::DecodeResult decode( Ogre::DataStreamPtr& input ) const;
-
-        /// @copydoc Ogre::Codec::magicNumberToFileExt
-        virtual Ogre::String magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const;
-
-        static Ogre::String ms_type_name;
-
-        /// @copydoc Ogre::Plugin::install
-        static void install();
-
-        /// @copydoc Ogre::Plugin::initialise
-        static void initialise();
-
-        /// @copydoc Ogre::Plugin::shutdown
-        static void shutdown();
-
-        /// @copydoc Ogre::Plugin::uninstall
-        static void uninstall();
-
-      private:
-        static TexCodec *ms_tex_codex;
+namespace QGears{
+
+    /**
+     * Handles text encoding from font images.
+     */
+    class _QGearsExport TexCodec : public Ogre::ImageCodec{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            TexCodec();
+
+            /**
+             * Destructor.
+             */
+            virtual ~TexCodec();
+
+            /**
+             * Retrieves the codec type.
+             *
+             * @return The codec type.
+             */
+            virtual Ogre::String getType() const;
+
+            /**
+             * Encodes data.
+             *
+             * Unimplemented, not required.
+             *
+             * @param input[in] Data to encode.
+             * @param output[out] Encoded data.
+             */
+            virtual Ogre::DataStreamPtr encode(
+              Ogre::MemoryDataStreamPtr& input, CodecDataPtr& output
+            ) const final;
+
+            /**
+             * Encodes data to a file.
+             *
+             * Unimplemented, not required.
+             *
+             * @param input[in] Data to encode.
+             * @param output[in] Nome for the file with the encoded data.
+             * @param extra[in] Extra information for the encoder.
+             */
+            virtual void encodeToFile(
+              Ogre::MemoryDataStreamPtr& input, const Ogre::String& output,
+              CodecDataPtr& extra
+            ) const final;
+
+            /**
+             * Decodes data.
+             *
+             * @param input[in] Data to encode.
+             * @return Decoded data.
+             */
+            Ogre::Codec::DecodeResult decode(Ogre::DataStreamPtr& input) const;
+
+            /**
+             * Maps a magic number header to a file extension.
+             *
+             * @param magic_number[in] Pointer to a stream of bytes which
+             * should identify the file. Note that this may be more than
+             * needed - each codec may be looking for a different size magic
+             * number.
+             * @param max_bytes[in] The number of bytes passed.
+             * @return A blank string if the magic number was unknown, or a
+             * file extension.
+             */
+            virtual Ogre::String magicNumberToFileExt(
+              const char *magic_number, size_t max_bytes
+            ) const;
+
+            /**
+             * The codec type name.
+             */
+            static Ogre::String TYPE_NAME;
+
+            /**
+             * Perform the plugin initial installation sequence.
+             *
+             * An implementation must be supplied for this method. It must
+             * perform the startup tasks necessary to install any rende rsystem
+             * customizations or anything else that is not dependent on system
+             * initialization, ie only dependent on the core of Ogre. It must
+             * not perform any operations that would create
+             * rendersystem-specific objects at this stage, that should be done
+             * in {@see initialise()}.
+             */
+            static void install();
+
+            /**
+             * Perform any tasks the plugin needs to perform initialization.
+             *
+             * An implementation must be supplied for this method. It is called
+             * just after the system is fully initialised (either after
+             * Root::initialise if a window is created then, or after the first
+             * window is created) and therefore all rendersystem functionality
+             * is available at this time. You can use this hook to create any
+             * resources which are dependent on a rendersystem or have
+             * rendersystem-specific implementations.
+             */
+            static void initialise();
+
+            /**
+             * Perform any tasks the needed when the system is shut down.
+             *
+             * An implementation must be supplied for this method. This method
+             * is called just before key parts of the system are unloaded, such
+             * as rendersystems being shut down. This hook should be used to
+             * free up resources and decouple custom objects from the OGRE
+             * system, whilst all the instances of other plugins (e.g.
+             * rendersystems) still exist.
+             */
+            static void shutdown();
+
+            /**
+             * Perform the final plugin uninstallation sequence.
+             *
+             * An implementation must be supplied for this method. It must
+             * perform the cleanup tasks which haven't already been performed
+             * in shutdown() (e.g. final deletion of custom instances,if they
+             * are kept around in case the system was reinitialised). At this
+             * stage it can't be guaranteed what other plugins are still loaded
+             * or active. It must therefore not perform any operations that
+             * would reference any rendersystem-specific objects - those should
+             * have been sorted out in the 'shutdown' method.
+             */
+            static void uninstall();
+
+          private:
+
+            /**
+             * The text codec.
+             */
+            static TexCodec *tex_codec_;
     };
 }
-
-#endif // __QGearsTexCodec_H__

+ 496 - 157
QGearsMain/include/data/QGearsTexFile.h

@@ -1,181 +1,520 @@
 /*
------------------------------------------------------------------------------
-The MIT License (MIT)
-
-Copyright (c) 2013-07-30 Tobias Peters <tobias.peters@kreativeffekt.at>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-#ifndef __QGearsTexFile_H__
-#define __QGearsTexFile_H__
+ * Copyright (C) 2022 The V-Gears Team
+ *
+ * This file is part of V-Gears
+ *
+ * V-Gears is free software: you can redistribute it and/or modify it under
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation, version 3.0 (GPLv3) of the License.
+ *
+ * V-Gears is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
 
-#include <vector>
+#pragma once
 
+#include <vector>
 #include <boost/cstdint.hpp>
-
 #include <OgreImageCodec.h>
 #include <OgrePlatform.h>
-
 #include "common/TypeDefine.h"
 
-namespace QGears
-{
-    class TexFile
-    {
-    public:
-        TexFile();
-        virtual ~TexFile();
+namespace QGears{
+
+    /**
+     * Handles TEX files.
+     *
+     * TEX files contain texture data for the PC version of Final Fantasy VII.
+     */
+    class TexFile{
+
+        public:
+
+            /**
+             * Constructor.
+             */
+            TexFile();
+
+            /**
+             * Destructor.
+             */
+            virtual ~TexFile();
+
+            /**
+             * Reads texture data.
+             *
+             * @param input[in] The contents of the TEX file.
+             */
+            void Read(Ogre::DataStreamPtr& input);
+
+            /**
+             * Reads the TEX file header and sets the instance data.
+             *
+             * @param input[in] The contents of the TEX file.
+             */
+            void ReadHeader(Ogre::DataStreamPtr& input);
+
+            /**
+             * Reads texture data and matches it with the color palette.
+             *
+             * @param input[in] The contents of the TEX file.
+             */
+            void ReadPalleted(Ogre::DataStreamPtr& input);
+
+            /**
+             * Retrieves pixel information from the texture image.
+             *
+             * @return Pixel data.
+             */
+            Ogre::MemoryDataStream* GetPixelData() const;
 
-        void read( Ogre::DataStreamPtr& input );
-        void readHeader( Ogre::DataStreamPtr& input );
-        void readPalleted( Ogre::DataStreamPtr& input );
-        Ogre::MemoryDataStream* getPixelData() const;
-        Ogre::ImageCodec::ImageData* getImageData() const;
+            /**
+             * Retrieves image data from the texture.
+             *
+             * @return The texture image.
+             */
+            Ogre::ImageCodec::ImageData* GetImageData() const;
 
-        typedef Ogre::int32 entry_t;
+            typedef Ogre::int32 TexEntry;
 
 #if OGRE_COMPILER == OGRE_COMPILER_MSVC
 #pragma pack (push, 1)
 #else
 #pragma pack (1)
 #endif
-        struct BitData
-        {
-            entry_t color_min;
-            entry_t color_max;
-            entry_t alpha_min;
-            entry_t alpha_max;
-            entry_t pixel_min;
-            entry_t pixel_max;
-        };
-
-        struct ImageData
-        {
-            entry_t bit_depth;
-            entry_t width;
-            entry_t height;
-            entry_t pitch;
-        };
-
-        struct PaletteData
-        {
-            entry_t flag;
-            entry_t index_bits;
-            entry_t index_8bit;
-            entry_t total_color_count;
-            entry_t colors_per_palette;
-        };
-
-        struct RGBAData
-        {
-            entry_t red;
-            entry_t green;
-            entry_t blue;
-            entry_t alpha;
-        };
-
-        struct PixelFormat
-        {
-            entry_t bits_per_pixel;
-            entry_t bytes_per_pixel;
-            RGBAData bit_count;
-            RGBAData bit_mask;
-            RGBAData bit_shift;
-            RGBAData bit_count_unused;
-            RGBAData shades;
-        };
-
-        struct Header
-        {
-            entry_t version;
-            entry_t unknown_0x04;
-            entry_t color_key_flag;
-            entry_t unknown_0x0C;
-            entry_t unknown_0x10;
-            BitData bit_data;
-            entry_t palette_type;
-            entry_t palette_count;
-            entry_t palette_total_color_count;
-            ImageData image_data;
-            entry_t unknown_0x48;
-            PaletteData palette_data;
-            entry_t runtime_data_ptr_palette_data;
-            PixelFormat pixel_format;
-            entry_t color_key_array_flag;
-            entry_t runtime_data_ptr_color_key_array;
-            entry_t reference_alpha;
-            entry_t runtime_data_02;
-            entry_t unknown_0xCC;
-            entry_t runtime_data_palette_index;
-            entry_t runtime_data_ptr_image_data;
-            entry_t runtime_data_04;
-            entry_t unknown_06;
-            entry_t unknown_07;
-            entry_t unknown_08;
-            entry_t unknown_09;
-        } m_header;
-
-        // reversing ff7 code
-        // structure @ 0x3c
-        // size 0x80
-        struct rev_TextureFormat
-        {
-            entry_t width;
-            entry_t height;
-            entry_t pitch;
-            entry_t unknown_0x48;
-            entry_t palette_flag;
-            entry_t bits_per_palette_index;
-            entry_t palette_index_8bit;
-            entry_t palette_size;
-            entry_t palette_color_count;
-            entry_t runtime_data_ptr_palette_data;
-            PixelFormat pixel_format;
-        };
+            /**
+             * Bit data in a TEX file.
+             */
+            struct BitData{
+
+                /**
+                 * Minimum colour value.
+                 */
+                TexEntry color_min;
+
+                /**
+                 * Maximum colour value.
+                 */
+                TexEntry color_max;
+
+                /**
+                 * Minimum alpha value.
+                 */
+                TexEntry alpha_min;
+
+                /**
+                 * Maximum alpha value.
+                 */
+                TexEntry alpha_max;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry pixel_min;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry pixel_max;
+            };
+
+            /**
+             * Texture image data.
+             */
+            struct ImageData{
+
+                /**
+                 * Image depth, in bits.
+                 */
+                TexEntry bit_depth;
+
+                /**
+                 * Image width.
+                 */
+                TexEntry width;
+
+                /**
+                 * Image height.
+                 */
+                TexEntry height;
+
+                /**
+                 * Image pitch.
+                 */
+                TexEntry pitch;
+            };
+
+            /**
+             * Colour palette data.
+             */
+            struct PaletteData{
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry flag;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry index_bits;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry index_8bit;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry total_color_count;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry colors_per_palette;
+            };
+
+            /**
+             * RGBA colour data.
+             */
+            struct RGBAData{
+
+                /**
+                 * Red component.
+                 */
+                TexEntry red;
+
+                /**
+                 * Green component.
+                 */
+                TexEntry green;
+
+                /**
+                 * Blue component.
+                 */
+                TexEntry blue;
+
+                /**
+                 * Alpha component.
+                 */
+                TexEntry alpha;
+            };
+
+            /**
+             * Pixel format structure.
+             */
+            struct PixelFormat{
+
+                /**
+                 * Number of bits per pixel definition.
+                 */
+                TexEntry bits_per_pixel;
+
+                /**
+                 * Number of bytes per pixel definition.
+                 */
+                TexEntry bytes_per_pixel;
+
+                /**
+                 * Number of bits.
+                 */
+                RGBAData bit_count;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                RGBAData bit_mask;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                RGBAData bit_shift;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                RGBAData bit_count_unused;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                RGBAData shades;
+            };
+
+            /**
+             * A TEX file header.
+             */
+            struct Header{
+
+                /**
+                 * File format version.
+                 */
+                TexEntry version;
+
+                /**
+                 * Unknown data.
+                 */
+                TexEntry unknown_0x04;
+
+                /**
+                 * Color key.
+                 */
+                TexEntry color_key_flag;
+
+                /**
+                 * Unknown data.
+                 */
+                TexEntry unknown_0x0C;
+
+                /**
+                 * Unknown data.
+                 */
+                TexEntry unknown_0x10;
+
+                /**
+                 * Bit data.
+                 */
+                BitData bit_data;
+
+                /**
+                 * The type of colour palette.
+                 */
+                TexEntry palette_type;
+
+                /**
+                 * The number of palettes.
+                 */
+                TexEntry palette_count;
+
+                /**
+                 * The number of colours between all the palettes.
+                 */
+                TexEntry palette_total_color_count;
+
+                /**
+                 * Texture image data.
+                 */
+                ImageData image_data;
+
+                /**
+                 * Unknown data.
+                 */
+                TexEntry unknown_0x48;
+
+                /**
+                 * Colour palette data.
+                 */
+                PaletteData palette_data;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry runtime_data_ptr_palette_data;
+
+                /**
+                 * Pixel format.
+                 */
+                PixelFormat pixel_format;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry color_key_array_flag;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry runtime_data_ptr_color_key_array;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry reference_alpha;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry runtime_data_02;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry unknown_0xCC;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry runtime_data_palette_index;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry runtime_data_ptr_image_data;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry runtime_data_04;
+
+                /**
+                 * Unknown data.
+                 */
+                TexEntry unknown_06;
+
+                /**
+                 * Unknown data.
+                 */
+                TexEntry unknown_07;
+
+                /**
+                 * Unknown data.
+                 */
+                TexEntry unknown_08;
+
+                /**
+                 * Unknown data.
+                 */
+                TexEntry unknown_09;
+            } header_;
+
+            /**
+             * Texture format.
+             */
+            struct TextureFormat{
+
+                // reversing ff7 code
+                // structure @ 0x3c
+                // size 0x80
+
+                /**
+                 * Texture width.
+                 */
+                TexEntry width;
+
+                /**
+                 * Texture height.
+                 */
+                TexEntry height;
+
+                /**
+                 * Texture pitch.
+                 */
+                TexEntry pitch;
+
+                /**
+                 * Unknown data.
+                 */
+                TexEntry unknown_0x48;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry palette_flag;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry bits_per_palette_index;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry palette_index_8bit;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry palette_size;
+
+                /**
+                 * The number of colours in the palette.
+                 */
+                TexEntry palette_color_count;
+
+                /**
+                 * @todo Understand and document.
+                 */
+                TexEntry runtime_data_ptr_palette_data;
+
+                /**
+                 * The format for the texture pixels.
+                 */
+                PixelFormat pixel_format;
+            };
 
 #if OGRE_COMPILER == OGRE_COMPILER_MSVC
 #pragma pack (pop)
 #else
 #pragma pack ()
 #endif
-        enum PaletteType
-        {
-            // as in ogre, eg msb -> lsb
-            PF_A8R8G8B8     = 0x00
-           ,PF_FLOAT32_ARGB = 0x01
-           ,PF_B8G8R8A8     = 0x02
-        };
-
-        typedef ColorA8R8G8B8 Color;
-        typedef std::vector<Color> t_Palette;
-        typedef std::vector<Color> t_ImageData;
-
-        t_Palette m_palette;
-        t_ImageData m_image_data;
-
-    private:
-        void flipEndian(void * pData, size_t size, size_t count) const;
-        void flipEndian(void * pData, size_t size) const;
-
-        static const Ogre::uint8 USE_REFERENCE_ALPHA;
+            enum PaletteType{
+                // as in ogre, eg msb -> lsb
+
+                /**
+                 * Palette type: ARGB, 8 bit per component.
+                 */
+                PF_A8R8G8B8     = 0x00
+
+                /**
+                 * Palette type: ARGB, floating values.
+                 */
+               ,PF_FLOAT32_ARGB = 0x01
+
+               /**
+                * Palette type: BGRA, 8 bit per component.
+                */
+               ,PF_B8G8R8A8     = 0x02
+            };
+
+            typedef ColorA8R8G8B8 Color;
+
+            typedef std::vector<Color> Palette;
+
+            typedef std::vector<Color> TexImageData;
+
+            /**
+             * The texture palette.
+             */
+            Palette palette;
+
+            /**
+             * The texture image data.
+             */
+            TexImageData image_data_;
+
+        private:
+
+            /**
+             * Flips the endian mode of data.
+             *
+             * If the data was big endian, it will be conterted to little
+             * endian. If it was little endian, it will be converted to big
+             * endian.
+             *
+             * @param data[in|out] Data to flip.
+             * @param size[in] Size of data.
+             * @param count[in] How much data to flip.
+             */
+            void FlipEndian(void * data, size_t size, size_t count) const;
+
+            /**
+             * Flips the endian mode of data.
+             *
+             * If the data was big endian, it will be conterted to little
+             * endian. If it was little endian, it will be converted to big
+             * endian.
+             *
+             * @param data[in|out] Data to flip.
+             * @param size[in] Size of data.
+             */
+            void FlipEndian(void * data, size_t size) const;
+
+            /**
+             * @todo Understand and document.
+             */
+            static const Ogre::uint8 USE_REFERENCE_ALPHA;
     };
 }
-
-#endif // __QGearsTexFile_H__

Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini