Преглед изворни кода

Implemented opcode VWOFT in the installer and in the engine.
Set default interactability settings for entities.
Proper handling of resolution changes.
Game menus CAN be resolution independent (but existing ones must be adapted one by one).

Iñigo Valentin пре 3 година
родитељ
комит
8191ec8f78

+ 31 - 0
V-Gears-Installer/include/decompiler/field/instruction/FieldCameraInstruction.h

@@ -42,8 +42,39 @@ class FieldCameraInstruction : public KernelCallInstruction{
     private:
 
         void ProcessNFADE(CodeGenerator* code_gen);
+
         void ProcessSCR2D(CodeGenerator* code_gen);
+
         void ProcessSCR2DC(CodeGenerator* code_gen);
+
+        /**
+         * Processes a VWOFT opcode.
+         *
+         * Opcode: 0x6A
+         * Short name: VWOFT
+         * Long name: View Offset
+         *
+         * Memory layout (5 bytes)
+         * |0x6A|B1/B2|Y|X|S|
+         *
+         * Arguments
+         * - const Bit[4] B1: Bank to retrieve the destination Y offset amount from, or zero if it
+         * is given as a literal value.
+         * - const Bit[4]: Bank to retrieve the destination X offset amount from, or zero if it
+         * is given as a literal value.
+         * - const Short Y: Amount to offset the camera in the Y coordinate, or the address to
+         * retrieve it if B1 is non-zero.
+         * - const Short X: Amount to offset the camera in the X coordinate, or the address to
+         * retrieve it if B2 is non-zero.
+         * - const UShort S: Movement speed. Lower values move the camera faster.
+         *
+         * Scrolls the current view by the values supplied in X and Y coordinates, instantly.
+         *
+         * @param[in,out] code_gen Code generator to append lines.
+         * @todo Y is the Y coordinate for sure, but I dont't know about X and S.
+         */
+        void ProcessVWOFT(CodeGenerator* code_gen);
+
         void ProcessFADE(CodeGenerator* code_gen);
 };
 

+ 5 - 10
V-Gears-Installer/src/decompiler/field/FieldDisassembler.cpp

@@ -212,9 +212,9 @@ void FieldDisassembler::AddFunc(
     if (!func_name.empty()) func->name = func_name;
     if (engine_->EntityIsLine(entity_index)){
         switch (script_index){
-            // main   - on_update
+            // main - on_update
             case 0: break;
-            // [OK]   - on_interact
+            // [OK] - on_interact
             case 1: break;
             // Move - on_enter_line
             case 2: func->name = "on_enter_line"; break;
@@ -316,8 +316,8 @@ bool FieldDisassembler::ReadOpCodesToPositionOrReturn(
   size_t end_pos, std::vector<float>& point_a, std::vector<float>& point_b
 ){
     bool is_line = false;
-    std::vector<unsigned int> exitAddrs;
     while (stream_->GetPosition() < end_pos){
+
         uint8 opcode = stream_->ReadU8();
         uint32 full_opcode = 0;
         full_opcode = (full_opcode << 8) + opcode;
@@ -1233,13 +1233,8 @@ bool FieldDisassembler::ReadOpCodesToPositionOrReturn(
         }
         this->address_++;
 
-        // Is it within an "if" statement tracking?
-        InstPtr i = this->insts_.back();
-        if (i->IsCondJump()) exitAddrs.push_back(i->GetDestAddress());
-        if (!exitAddrs.empty())
-            if (i->GetAddress() == exitAddrs.back()) exitAddrs.pop_back();
-        // Only bail if its the first RET that isn't within an "if" block.
-        if (full_opcode == OPCODES::RET && exitAddrs.empty()) return is_line;
+        // Exit on return found.
+        if (full_opcode == OPCODES::RET) return is_line;
     }
     return is_line;
 }

+ 16 - 1
V-Gears-Installer/src/decompiler/field/instruction/FieldCameraInstruction.cpp

@@ -38,7 +38,7 @@ void FieldCameraInstruction::ProcessInst(
     case OPCODES::SCR2DC: ProcessSCR2DC(code_gen); break;
     case OPCODES::SCRLW: code_gen->WriteTodo(md.GetEntityName(), "SCRLW"); break;
     case OPCODES::SCR2DL: code_gen->WriteTodo(md.GetEntityName(), "SCR2DL"); break;
-    case OPCODES::VWOFT: code_gen->WriteTodo(md.GetEntityName(), "VWOFT"); break;
+    case OPCODES::VWOFT: ProcessVWOFT(code_gen); break;
     case OPCODES::FADE: ProcessFADE(code_gen); break;
     case OPCODES::FADEW: code_gen->WriteTodo(md.GetEntityName(), "FADEW"); break;
     case OPCODES::SCRLP: code_gen->WriteTodo(md.GetEntityName(), "SCRLP"); break;
@@ -110,6 +110,21 @@ void FieldCameraInstruction::ProcessSCR2DC(CodeGenerator* code_gen){
     ).str());
 }
 
+void FieldCameraInstruction::ProcessVWOFT(CodeGenerator* code_gen){
+    FieldCodeGenerator* cg = static_cast<FieldCodeGenerator*>(code_gen);
+    const auto& y = FieldCodeGenerator::FormatValueOrVariable(
+      cg->GetFormatter(), params_[0]->GetUnsigned(), params_[2]->GetSigned()
+    );
+    const auto& x = FieldCodeGenerator::FormatValueOrVariable(
+      cg->GetFormatter(), params_[1]->GetUnsigned(), params_[3]->GetSigned()
+    );
+    const auto& speed = params_[4]->GetUnsigned();
+    code_gen->AddOutputLine((
+      boost::format("background2d:offset(%1%, %2%) -- Speed %3%")
+      % x % y % speed
+    ).str());
+}
+
 void FieldCameraInstruction::ProcessFADE(CodeGenerator* code_gen){
     // TODO: not fully reversed
     auto raw_type = params_[8]->GetUnsigned();

+ 2 - 2
V-Gears/include/FF7Common.h

@@ -27,12 +27,12 @@ namespace VGears{
         /**
          * Game horizontal resolution, in pixels.
          */
-        SCREEN_WIDTH = 320,
+        SCREEN_WIDTH = 1024,
 
         /**
          * Game vertical resolution, in pixels.
          */
-        SCREEN_HEIGHT = 240,
+        SCREEN_HEIGHT = 768,
 
         /**
          * @todo Understand and document.

+ 28 - 28
V-Gears/include/core/Background2D.h

@@ -107,8 +107,8 @@ class Background2D : public Ogre::RenderQueueListener{
         /**
          * 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.
+         * @return The entity currently being tracked, or nullptr if the background is not
+         * currently scrolling to any entity.
          */
         Entity* GetAutoScrollEntity() const;
 
@@ -121,8 +121,7 @@ class Background2D : public Ogre::RenderQueueListener{
          * @param[in] seconds Duration of the scroll.
          */
         void ScriptScrollToPosition(
-          const float x, const float y,
-          const SCROLL_TYPE type, const float seconds
+          const float x, const float y, const SCROLL_TYPE type, const float seconds
         );
 
         /**
@@ -132,6 +131,14 @@ class Background2D : public Ogre::RenderQueueListener{
          */
         int ScriptScrollSync();
 
+        /**
+         * Offsets the background to a position.
+         *
+         * @param[in] x X coordinate to scroll to.
+         * @param[in] y Y coordinate to scroll to.
+         */
+        void ScriptOffset(const float x, const float y);
+
         /**
          * Stops the current scrolling.
          */
@@ -168,8 +175,7 @@ class Background2D : public Ogre::RenderQueueListener{
         /**
          * Sets the time taken by the current scroll action.
          *
-         * It represents the time the current scroll action has been going on
-         * for.
+         * It represents the time the current scroll action has been going on for.
          *
          * @param[in] seconds Time taken by the current scroll action.
          */
@@ -178,8 +184,7 @@ class Background2D : public Ogre::RenderQueueListener{
         /**
          * Retrieves the time taken by the current scroll action.
          *
-         * It represents the time the current scroll action has been going on
-         * for.
+         * It represents the time the current scroll action has been going on for.
          *
          * @return Time taken by the current scroll action.
          */
@@ -230,9 +235,7 @@ class Background2D : public Ogre::RenderQueueListener{
          * @param[in] max_x Max scrollabe x coordinate.
          * @param[in] max_y Max scrollabe y coordinate.
          */
-        void SetRange(
-          const int min_x, const int min_y, const int max_x, const int max_y
-        );
+        void SetRange(const int min_x, const int min_y, const int max_x, const int max_y);
 
         /**
          * Set the background scrolling range.
@@ -260,9 +263,8 @@ class Background2D : public Ogre::RenderQueueListener{
          * @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
+          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
         );
 
         /**
@@ -300,8 +302,7 @@ class Background2D : public Ogre::RenderQueueListener{
          * @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
+          const unsigned int tile_id, const float u1, const float v1, const float u2, const float v2
         );
 
         /**
@@ -317,9 +318,7 @@ class Background2D : public Ogre::RenderQueueListener{
          * @param[in] animation The animation to play.
          * @param[in] state Animation state.
          */
-        void PlayAnimation(
-          const Ogre::String& animation, const Background2DAnimation::State state
-        );
+        void PlayAnimation(const Ogre::String& animation, const Background2DAnimation::State state);
 
         /**
          * Plays an animation in a loop.
@@ -354,13 +353,11 @@ class Background2D : public Ogre::RenderQueueListener{
          *
          * @param[in] queueGroupId The group id of the queue to end.
          * @param[in] invocation
-         * @param[in] repeatThisInvocation Indicates if the invocation must be
-         * repeated.
+         * @param[in] repeatThisInvocation Indicates if the invocation must be repeated.
          * @todo Understand and document.
          */
         void renderQueueEnded(
-          Ogre::uint8 queueGroupId, const Ogre::String& invocation,
-          bool& repeatThisInvocation
+          Ogre::uint8 queueGroupId, const Ogre::String& invocation, bool& repeatThisInvocation
         ) override;
 
         /**
@@ -423,9 +420,7 @@ class Background2D : public Ogre::RenderQueueListener{
          * @param[in] tile_index The index of the tile.
          * @param[in] animations List of animations to load.
          */
-        virtual void load(
-          const size_t tile_index, const VGears::AnimationMap &animations
-        );
+        virtual void load( const size_t tile_index, const VGears::AnimationMap &animations);
 
         /**
          * Apply the camera position to match the current scroll.
@@ -594,8 +589,15 @@ class Background2D : public Ogre::RenderQueueListener{
          */
         Ogre::Vector2 position_;
 
+        /**
+         * The current background offset, virtual screen size.
+         */
+        Ogre::Vector2 offset_;
+
         /**
          * The current scroll position, viewport size.
+         *
+         * Includes the offset.
          */
         Ogre::Vector2 position_real_;
 
@@ -650,5 +652,3 @@ class Background2D : public Ogre::RenderQueueListener{
          */
         std::vector<Background2DAnimation*> animations_;
 };
-
-

+ 2 - 2
V-Gears/include/core/ConfigCmdManagerCommands.h

@@ -346,8 +346,7 @@ void CmdResolution(const Ogre::StringVector& params){
         );
         return;
     }
-    Ogre::RenderWindow* window
-      = VGears::Application::getSingleton().getRenderWindow();
+    Ogre::RenderWindow* window = VGears::Application::getSingleton().getRenderWindow();
     if (params.size() >= 4){
         window->setFullscreen(
           Ogre::StringConverter::parseBool(params[3]),
@@ -360,6 +359,7 @@ void CmdResolution(const Ogre::StringVector& params){
           Ogre::StringConverter::parseInt(params[1]),
           Ogre::StringConverter::parseInt(params[2])
         );
+        window->getViewport(0)->setDimensions(0.0f, 0.0f, 1.0f, 1.0f);
     }
 }
 

+ 3 - 0
V-Gears/include/core/ScriptManagerBinds.h

@@ -271,6 +271,9 @@ void ScriptManager::InitBinds(){
           .def(
             "scroll_sync", (int(Background2D::*)()) &Background2D::ScriptScrollSync, luabind::yield
           )
+          .def(
+            "offset", (void(Background2D::*)(const float, const float)) &Background2D::ScriptOffset
+          )
           .def(
             "play_animation_looped",
             (void(Background2D::*)(const char*)) &Background2D::ScriptPlayAnimationLooped

+ 4 - 1
V-Gears/src/common/VGearsApplication.cpp

@@ -102,10 +102,13 @@ namespace VGears{
             Ogre::NameValuePairList list;
             list.emplace("hidden", "true");
             _root->initialise(false, getWindowTitle());
+            //
             _render_window = _root->createRenderWindow(getWindowTitle(), 1, 1, false, &list);
         }
         else{
-            _render_window = _root->initialise(true, getWindowTitle());
+            _render_window = _root->initialise(false, getWindowTitle());
+            // TODO: Get actual resolution from config
+            _render_window = _root->createRenderWindow(getWindowTitle(), 1024, 768, false);
         }
         registerArchiveFactories();
         loadResourcesConfig();

+ 35 - 34
V-Gears/src/core/Background2D.cpp

@@ -42,6 +42,7 @@ Background2D::Background2D():
   scroll_current_seconds_(0),
   position_(Ogre::Vector2::ZERO),
   position_real_(Ogre::Vector2::ZERO),
+  offset_(Ogre::Vector2::ZERO),
   range_(Ogre::AxisAlignedBox::BOX_INFINITE),
   virtual_screen_size_(320, 240) // FFVII original resolution
 {
@@ -104,14 +105,10 @@ Background2D::~Background2D(){
 
 void Background2D::InputDebug(const VGears::Event& event){
     if (cv_background2d_manual.GetB() == true && event.type == VGears::ET_KEY_IMPULSE){
-        if (event.param1 == OIS::KC_W)
-            position_real_.y += 2;
-        else if (event.param1 == OIS::KC_A)
-            position_real_.x += 2;
-        else if (event.param1 == OIS::KC_S)
-            position_real_.y -= 2;
-        else if (event.param1 == OIS::KC_D)
-            position_real_.x -= 2;
+        if (event.param1 == OIS::KC_W) position_real_.y += 2;
+        else if (event.param1 == OIS::KC_A) position_real_.x += 2;
+        else if (event.param1 == OIS::KC_S) position_real_.y -= 2;
+        else if (event.param1 == OIS::KC_D) position_real_.x -= 2;
         CameraManager::getSingleton().Set2DScroll(position_real_);
     }
 }
@@ -210,12 +207,9 @@ void Background2D::OnResize(){
         float new_x4 = bottom_left.x;
         float new_y4 = bottom_left.y;
         Ogre::HardwareVertexBufferSharedPtr vertex_buffer;
-        if (tiles_[i].blending == VGears::B_ALPHA)
-            vertex_buffer = alpha_vertex_buffer_;
-        else if(tiles_[i].blending == VGears::B_ADD)
-            vertex_buffer = add_vertex_buffer_;
-        else if(tiles_[i].blending == VGears::B_SUBTRACT)
-            vertex_buffer = subtract_vertex_buffer_;
+        if (tiles_[i].blending == VGears::B_ALPHA) vertex_buffer = alpha_vertex_buffer_;
+        else if(tiles_[i].blending == VGears::B_ADD) vertex_buffer = add_vertex_buffer_;
+        else if(tiles_[i].blending == VGears::B_SUBTRACT) vertex_buffer = subtract_vertex_buffer_;
         float* write_iterator
           = static_cast<float*>(vertex_buffer->lock(Ogre::HardwareBuffer::HBL_NORMAL));
         write_iterator += tiles_[i].start_vertex_index * TILE_VERTEX_INDEX_SIZE;
@@ -249,6 +243,7 @@ void Background2D::Clear(){
     scroll_current_seconds_ = 0;
     position_ = Ogre::Vector2::ZERO;
     position_real_ = Ogre::Vector2::ZERO;
+    offset_ = Ogre::Vector2::ZERO;
     range_ = Ogre::AxisAlignedBox::BOX_INFINITE;
     UnsetScroll();
     for(unsigned int i = 0; i < animations_.size(); ++i) delete animations_[i];
@@ -270,12 +265,12 @@ void Background2D::ScriptScrollToPosition(
   const float x, const float y, const SCROLL_TYPE type, const float seconds
 ){
     LOG_TRIVIAL(
-      "[SCRIPT] Background2d set scroll to position \""
-      + Ogre::StringConverter::toString(Ogre::Vector2(x, y)) + "\"."
+      "Background2d set scroll to position '"
+      + Ogre::StringConverter::toString(Ogre::Vector2(x, y)) + "'."
     );
     Ogre::Vector2 position = Ogre::Vector2(x, y);
     scroll_entity_ = nullptr;
-    if(type == Background2D::NONE){
+    if (type == Background2D::NONE){
         SetScroll(position);
         return;
     }
@@ -289,13 +284,24 @@ void Background2D::ScriptScrollToPosition(
 int Background2D::ScriptScrollSync(){
     ScriptId script = ScriptManager::getSingleton().GetCurrentScriptId();
     LOG_TRIVIAL(
-      "[SCRIPT] Wait Background2d scroll for function \""
-      + script.function + "\" in script entity \"" + script.entity + "\"."
+      "Wait Background2d scroll for function '"
+      + script.function + "' in script entity '" + script.entity + "'."
     );
     scroll_sync_.push_back(script);
     return -1;
 }
 
+void Background2D::ScriptOffset(const float x, const float y){
+    LOG_TRIVIAL(
+      "Background2d offset '" + Ogre::StringConverter::toString(Ogre::Vector2(x, y)) + "'."
+    );
+    offset_.x = x;
+    offset_.y = y;
+    position_real_.x += offset_.x;
+    position_real_.y += offset_.y;
+    CameraManager::getSingleton().Set2DScroll(position_real_);
+}
+
 void Background2D::UnsetScroll(){
     scroll_type_ = Background2D::NONE;
     for(unsigned int i = 0; i < scroll_sync_.size(); ++ i)
@@ -336,6 +342,8 @@ void Background2D::SetScroll(const Ogre::Vector2& position){
 void Background2D::applyScroll(){
     if(cv_background2d_manual.GetB() != true){
         position_real_ = GetScreenScroll();
+        position_real_.x += offset_.x;
+        position_real_.y += offset_.y;
         CameraManager::getSingleton().Set2DScroll(position_real_);
     }
 }
@@ -456,8 +464,7 @@ void Background2D::AddTile(
       static_cast<Ogre::Real>(x + width), static_cast<Ogre::Real>(top_left.y)
     );
     Ogre::Vector2 bottom_right(
-      static_cast<Ogre::Real>(top_right.x),
-      static_cast<Ogre::Real>(-(y + height))
+      static_cast<Ogre::Real>(top_right.x), static_cast<Ogre::Real>(-(y + height))
     );
     Ogre::Vector2 bottom_left(top_left.x, bottom_right.y);
     virtualScreenToWorldSpace(top_left);
@@ -543,12 +550,9 @@ void Background2D::UpdateTileUV(
         return;
     }
     Ogre::HardwareVertexBufferSharedPtr vertex_buffer;
-    if (tiles_[tile_id].blending == VGears::B_ALPHA)
-        vertex_buffer = alpha_vertex_buffer_;
-    else if (tiles_[tile_id].blending == VGears::B_ADD)
-        vertex_buffer = add_vertex_buffer_;
-    else if(tiles_[tile_id].blending == VGears::B_SUBTRACT)
-        vertex_buffer = subtract_vertex_buffer_;
+    if (tiles_[tile_id].blending == VGears::B_ALPHA) vertex_buffer = alpha_vertex_buffer_;
+    else if (tiles_[tile_id].blending == VGears::B_ADD) vertex_buffer = add_vertex_buffer_;
+    else if(tiles_[tile_id].blending == VGears::B_SUBTRACT) vertex_buffer = subtract_vertex_buffer_;
     float* write_iterator
       = static_cast<float*>(vertex_buffer->lock(Ogre::HardwareBuffer::HBL_NORMAL));
     write_iterator += tiles_[tile_id].start_vertex_index * TILE_VERTEX_INDEX_SIZE;
@@ -596,8 +600,7 @@ void Background2D::PlayAnimation(
         anim.state = state;
         animation_played_.push_back(anim);
     }
-    else
-        LOG_ERROR("Background2D doesn't has animation \"" + animation + "\".");
+    else LOG_ERROR("Background2D doesn't has animation '" + animation + "'.");
 }
 
 void Background2D::ScriptPlayAnimationLooped(const char* name){
@@ -663,8 +666,7 @@ void Background2D::CreateVertexBuffers(){
     alpha_max_vertex_count_ = 2048 * TILE_VERTEX_COUNT;
     alpha_render_op_.vertexData = new Ogre::VertexData;
     alpha_render_op_.vertexData->vertexStart = 0;
-    Ogre::VertexDeclaration* vertex_declaration
-      = alpha_render_op_.vertexData->vertexDeclaration;
+    Ogre::VertexDeclaration* vertex_declaration = alpha_render_op_.vertexData->vertexDeclaration;
     size_t offset = 0;
     vertex_declaration->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
     offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
@@ -704,8 +706,7 @@ void Background2D::CreateVertexBuffers(){
     offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
     vertex_declaration->addElement(0, offset, Ogre::VET_FLOAT4, Ogre::VES_DIFFUSE);
     offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT4);
-    vertex_declaration->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES
-    );
+    vertex_declaration->addElement(0, offset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES);
     subtract_vertex_buffer_ = Ogre::HardwareBufferManager::getSingletonPtr()->createVertexBuffer(
       vertex_declaration->getVertexSize(0), subtract_max_vertex_count_,
       Ogre::HardwareBuffer::HBU_DYNAMIC_WRITE_ONLY, false
@@ -749,7 +750,7 @@ void Background2D::load(const VGears::Background2DFile::TileList& tiles){
     size_t tile_index(0);
     while (it != it_end) {
         AddTile(*it);
-        load(tile_index++, it->animations);
+        load(tile_index ++, it->animations);
         ++ it;
     }
 }

+ 8 - 2
V-Gears/src/core/Entity.cpp

@@ -28,9 +28,9 @@ Entity::Entity(const Ogre::String& name, Ogre::SceneNode* node):
   height_(1.0f),
   //solid_radius_(0.24f),
   solid_radius_(0.21f),
-  solid_(true),
+  solid_(false),
   talk_radius_(0.45f),
-  talkable_(true),
+  talkable_(false),
   state_(Entity::NONE),
   move_auto_speed_(0.7f),
   move_walk_speed_(0.7f),
@@ -201,6 +201,12 @@ void Entity::SetPosition(const Ogre::Vector3& position){scene_node_->setPosition
 
 void Entity::ScriptSetPosition(const float x, const float y, const float z){
     SetPosition(Ogre::Vector3(x, y, z));
+
+    // Make the entity solid, visible and talkable. TODO: Check if neccessary.
+    SetVisible(true);
+    SetSolid(true);
+    SetTalkable(true);
+
     // If set from a script:
     // Reset walkmesh triangle to reattach entity to walkmesh again if needed.
     move_triangle_id_ = -1;

+ 9 - 2
V-Gears/src/core/EntityManager.cpp

@@ -418,8 +418,15 @@ EntityPoint* EntityManager::ScriptGetEntityPoint(const char* name) const{
 }
 
 void EntityManager::ScriptSetPlayerEntity(const char* name){
-    for (unsigned int i = 0; i < entity_.size(); ++ i)
-        if (entity_[i]->GetName() == name) player_entity_ = entity_[i];
+    for (unsigned int i = 0; i < entity_.size(); ++ i){
+        if (entity_[i]->GetName() == name){
+            player_entity_ = entity_[i];
+            // Also, make is solid, visible, and non-talkable.
+            entity_[i]->SetSolid(true);
+            entity_[i]->SetVisible(true);
+            entity_[i]->SetTalkable(false);
+        }
+    }
 }
 
 Entity* EntityManager::ScriptGetPlayerEntity() const{return player_entity_;}

+ 16 - 36
V-Gears/src/core/EntityModel.cpp

@@ -21,16 +21,13 @@
 
 EntityModel::EntityModel(
   const Ogre::String& name, const Ogre::String file_name, Ogre::SceneNode* node
-):
-  Entity(name, node), animation_current_(nullptr)
+): Entity(name, node), animation_current_(nullptr)
 {
     Ogre::SceneManager* scene_manager;
     scene_manager = Ogre::Root::getSingleton().getSceneManager("Scene");
     model_ = scene_manager->createEntity(name_, file_name);
-    model_->setVisible(true);
-    PlayAnimation(
-      animation_default_, Entity::AUTO_ANIMATION, Entity::PLAY_LOOPED, 0, -1
-    );
+    model_->setVisible(false);
+    PlayAnimation(animation_default_, Entity::AUTO_ANIMATION, Entity::PLAY_LOOPED, 0, -1);
     model_node_->attachObject(model_);
 }
 
@@ -39,8 +36,7 @@ EntityModel::~EntityModel(){
 }
 
 void EntityModel::Update(){
-    if (animation_auto_play_ == true)
-        UpdateAnimation(Timer::getSingleton().GetGameTimeDelta());
+    if (animation_auto_play_ == true) UpdateAnimation(Timer::getSingleton().GetGameTimeDelta());
     Entity::Update();
 }
 
@@ -54,19 +50,15 @@ void EntityModel::PlayAnimation(
   Entity::AnimationPlayType play_type, const float start, const float end
 ){
     if (animation_current_ != nullptr) animation_current_->setEnabled(false);
-
     if (model_->getAllAnimationStates()->hasAnimationState(animation) == true){
         animation_current_name_ = animation;
         animation_current_ = model_->getAnimationState(animation);
-        animation_current_->setLoop(
-          (play_type == Entity::PLAY_LOOPED) ? true : false
-        );
+        animation_current_->setLoop((play_type == Entity::PLAY_LOOPED) ? true : false);
         animation_current_->setEnabled(true);
         animation_current_->setTimePosition(
           (start == -1) ? animation_current_->getLength() : start
         );
-        animation_end_time_
-          = (end == -1) ? animation_current_->getLength() : end;
+        animation_end_time_ = (end == -1) ? animation_current_->getLength() : end;
         animation_state_ = state;
         animation_play_type_ = play_type;
     }
@@ -75,8 +67,7 @@ void EntityModel::PlayAnimation(
         // so don't spam crazy amounts of errors if its not found.
         if (animation != "Idle"){
             LOG_ERROR(
-              "Animation '" + animation + "' doesn't exist in model '"
-              + model_->getName() + "'."
+              "Animation '" + animation + "' doesn't exist in model '" + model_->getName() + "'."
             );
         }
     }
@@ -92,11 +83,9 @@ void EntityModel::PlayAnimationContinue(const Ogre::String& animation){
         // and (the requested animation is not currently playing...
         animation_current_ != model_->getAnimationState(animation)
         // or it's currently playing  but it's not looped)
-        || animation_play_type_ != Entity::PLAY_LOOPED)))
-    {
-        PlayAnimation(
-          animation, Entity::AUTO_ANIMATION, Entity::PLAY_LOOPED, 0, -1
-        );
+        || animation_play_type_ != Entity::PLAY_LOOPED))
+    ){
+        PlayAnimation(animation, Entity::AUTO_ANIMATION, Entity::PLAY_LOOPED, 0, -1);
     }
 }
 
@@ -105,37 +94,28 @@ void EntityModel::UpdateAnimation(const float delta){
         float delta_mod = delta * animation_speed_;
         bool stop_check
           = (animation_current_->hasEnded() == true)
-          || (
-            animation_current_->getTimePosition() + delta_mod
-            >= animation_end_time_
-          );
+          || (animation_current_->getTimePosition() + delta_mod >= animation_end_time_);
 
         if (stop_check == true){
             //LOG_TRIVIAL("Animation finished for entity \"" + name_ + "\".");
-            for (size_t i = 0; i < animation_sync_.size(); ++ i){
-                ScriptManager::getSingleton().ContinueScriptExecution(
-                  animation_sync_[i]
-                );
-            }
+            for (size_t i = 0; i < animation_sync_.size(); ++ i)
+                ScriptManager::getSingleton().ContinueScriptExecution(animation_sync_[i]);
             animation_sync_.clear();
 
             if (animation_play_type_ == Entity::PLAY_DEFAULT){
                 float time = (animation_current_->hasEnded() != true)
                   ? animation_current_->getTimePosition() : 0;
                 PlayAnimation(
-                  animation_default_, Entity::AUTO_ANIMATION,
-                  Entity::PLAY_LOOPED, time, -1
+                  animation_default_, Entity::AUTO_ANIMATION, Entity::PLAY_LOOPED, time, -1
                 );
                 animation_current_->addTime(delta_mod);
             }
             else if (animation_play_type_ == Entity::PLAY_LOOPED){
                 float time = (animation_current_->hasEnded() != true)
                   ? animation_current_->getTimePosition()
-                  : animation_current_->getTimePosition()
-                    - animation_current_->getLength();
+                  : animation_current_->getTimePosition() - animation_current_->getLength();
                 PlayAnimation(
-                  animation_current_name_, Entity::AUTO_ANIMATION,
-                  Entity::PLAY_LOOPED, time, -1
+                  animation_current_name_, Entity::AUTO_ANIMATION, Entity::PLAY_LOOPED, time, -1
                 );
                 animation_current_->addTime(delta_mod);
             }

+ 12 - 0
V-Gears/src/core/UiWidget.cpp

@@ -13,9 +13,11 @@
  * GNU General Public License for more details.
  */
 
+#include <iostream>
 #include <OgreMath.h>
 #include <OgreRoot.h>
 #include <OgreViewport.h>
+#include "common/VGearsApplication.h"
 #include "core/ConfigVar.h"
 #include "core/CameraManager.h"
 #include "core/DebugDraw.h"
@@ -302,6 +304,16 @@ void UiWidget::SetUpdateTransformation(){
 }
 
 void UiWidget::UpdateTransformation(){
+
+    Ogre::RenderWindow* window = VGears::Application::getSingleton().getRenderWindow();
+    float res_width = static_cast<float>(window->getWidth());
+    float res_height = static_cast<float>(window->getHeight());
+    screen_width_ = res_width;
+    screen_height_ = res_height;
+
+    Ogre::Viewport *viewport(CameraManager::getSingleton().getViewport());
+    viewport->setDimensions(0.0f, 0.0f, 1.0f, 1.0f);
+
     Ogre::Vector2 area_scale
       = (parent_ != nullptr) ? parent_->GetFinalScale() : Ogre::Vector2(1, 1);
     Ogre::Vector2 area_origin

+ 2 - 0
data/data/config.cfg

@@ -7,6 +7,8 @@ set debug_entity 1
 set debug_trigger true
 set debug_walkmesh true
 set debug_script 1
+set debug_ui 2
+resolution 1024 768 0
 
 bind F11 "toggle timer_scale_game 0.0 1.0"
 bind NumAdd "increment timer_scale_game 0.0 1.0 0.1"

+ 4 - 4
data/data/screens/main_menu/main_menu.xml

@@ -1,9 +1,9 @@
 <screen name="MainMenu" script="scripts/menu/main_menu.lua" visible="false">
-    <widget name="Container" width="368" height="240" origin_x="50%" origin_y="50%" align="center" valign="middle" scale="3 3" visible="true">
-        <widget name="Characters" x="30" y="17" width="300" height="190" visible="true">
+    <widget name="Container" width="100%" height="100%" x="0%"  y="0%" align="left" valign="top" scale="3 3" visible="true">
+        <widget name="Characters" x="1%" y="1%" width="32%" height="30%" visible="true">
             <prototype name="Window" />
-            <animation name="Appear" length="0.3" x="0:736,0.3:30" />
-            <animation name="Disappear" length="0.3" x="0:30,0.3:736" />
+            <animation name="Appear" length="0.3" x="0:110%,0.3:1%" />
+            <animation name="Disappear" length="0.3" x="0:1%,0.3:110%" />
 
             <widget name="Character1" x="0" y="0" width="100%" height="60" visible="true">
                 <sprite name="Portrait" image="images/other/choco.png" x="22" y="12" width="48" height="48" visible="true">

+ 2 - 2
data/data/scripts/field.lua

@@ -92,13 +92,13 @@ split_party = function(ax, ay, ar, bx, by, br, speed)
                 -- Approximated speed, good enough for now.
                 -- TODO: Calculate speed based on time, as the orignal opcode.
                 character:set_move_auto_speed(speed / 16)
-                if character:is_visible() == false then
+                --if character:is_visible() == false then
                     -- In theory, a member is never visible before a split, but some maps
                     -- are wrong. In these cases, don't change position and move the entity
                     -- from it's current position.
                     character:set_position(x, y, z)
                     character:set_visible(true)
-                end
+                --end
                 character:set_solid(false)
                 if c == 2 then
                     character:move_to_position(ax, ay)

+ 9 - 7
data/data/scripts/menu/begin_menu.lua

@@ -35,7 +35,7 @@ UiContainer.BeginMenu = {
                     FFVII.MenuSettings.pause_available = true
                 elseif self.position == 3 then
                     -- NMKIN_3 START
-                    FFVII.Data.progress_game = 23
+                    --[[FFVII.Data.progress_game = 23
                     load_field_map_request("nmkin_3", "")
                     console( "camera_free false" )
                     console( "debug_walkmesh true" )
@@ -48,24 +48,26 @@ UiContainer.BeginMenu = {
                     entity_manager:get_entity("Cloud"):jump_to_position(0.46875, 14.9922, -1, 1, 42) -- Triangle 42, 2 steps.
                     entity_manager:get_entity("Cloud"):jump_sync()
                     entity_manager:player_lock(false)
-                    FFVII.MenuSettings.pause_available = true
+                    FFVII.MenuSettings.pause_available = true]]
                     -- NMKIN_3 END
                     -- NMKIN_4 START
-                    --[[FFVII.Data.progress_game = 23
-                    load_field_map_request("nmkin_4", "")
-                    console( "camera_free false" )
-                    console( "debug_walkmesh true" )
+                    FFVII.Data.progress_game = 14
+                    --load_field_map_request("nmkin_4", "")
+                    map("nmkin_4")
+                    console("camera_free false")
+                    console("debug_walkmesh true")
                     script:wait(1.5)
                     script:request_end_sync( Script.UI, "BeginMenu", "hide", 0 )
                     entity_manager:get_entity("Cloud"):set_position(-0.820312, 0.500000, 17.281244)
                     entity_manager:set_player_entity("Cloud")
+                    FFVII.set_party(0, 1, nil)
                     script:wait(0.5)
                     entity_manager:get_player_entity():set_position(-0.820312, 0.500000, 17.281244)
                     entity_manager:get_entity("Cloud"):jump_to_position(-0.800312, 0.500000, -1, 1) -- Triangle 42, 2 steps.
                     entity_manager:get_entity("Cloud"):jump_sync()
                     entity_manager:player_lock(false)
                     print("TRIANGLE " .. entity_manager:get_entity("Cloud"):get_move_triangle_id())
-                    FFVII.MenuSettings.pause_available = true]]
+                    FFVII.MenuSettings.pause_available = true
                     -- NMKIN_4 END
                 elseif self.position == 4 then
                     script:request_end_sync( Script.UI, "BeginMenu", "hide", 0 )