diff --git a/src/openvic-simulation/dataloader/NodeTools.cpp b/src/openvic-simulation/dataloader/NodeTools.cpp index ab73ad97..bda0f94a 100644 --- a/src/openvic-simulation/dataloader/NodeTools.cpp +++ b/src/openvic-simulation/dataloader/NodeTools.cpp @@ -14,6 +14,7 @@ #include "openvic-simulation/types/Colour.hpp" #include "openvic-simulation/types/TextFormat.hpp" +#include "openvic-simulation/types/Vector.hpp" #include "openvic-simulation/utility/Getters.hpp" using namespace OpenVic; @@ -288,25 +289,35 @@ node_callback_t NodeTools::expect_fvec2(callback_t callback) { return _expect_vec2(callback); } -node_callback_t NodeTools::expect_v2_vector3(callback_t callback) { - return [callback](ast::NodeCPtr node) -> bool { - - int components = 0; - fixed_point_t x = 0; - fixed_point_t y = 0; - fixed_point_t z = 0; +// seen in some gfx files, these vectors don't have x,y,z,w labels, so are loaded similarly to colours. +node_callback_t NodeTools::expect_fvec3(callback_t callback) { + return [callback](ast::NodeCPtr node) -> bool { + fvec3_t vec; + int32_t components = 0; bool ret = expect_list_of_length(3, expect_fixed_point( - [&components,&x,&y,&z](fixed_point_t val) -> bool { - if(components == 0) x = val; - else if(components == 1) y = val; - else z = val; - components++; + [&vec, &components](fixed_point_t val) -> bool { + vec[components++] = val; return true; - }))(node); + } + ))(node); + ret &= callback(vec); + return ret; + }; +} - ret &= callback(V2Vector3(x,y,z)); - return ret; +node_callback_t NodeTools::expect_fvec4(callback_t callback) { + return [callback](ast::NodeCPtr node) -> bool { + fvec4_t vec; + int32_t components = 0; + bool ret = expect_list_of_length(4, expect_fixed_point( + [&vec, &components](fixed_point_t val) -> bool { + vec[components++] = val; + return true; + } + ))(node); + ret &= callback(vec); + return ret; }; } diff --git a/src/openvic-simulation/dataloader/NodeTools.hpp b/src/openvic-simulation/dataloader/NodeTools.hpp index 976e7fa8..0d332b0b 100644 --- a/src/openvic-simulation/dataloader/NodeTools.hpp +++ b/src/openvic-simulation/dataloader/NodeTools.hpp @@ -15,7 +15,6 @@ #include "openvic-simulation/types/IndexedMap.hpp" #include "openvic-simulation/types/OrderedContainers.hpp" #include "openvic-simulation/types/TextFormat.hpp" -#include "openvic-simulation/types/unlabelledVec.hpp" #include "openvic-simulation/types/Vector.hpp" #include "openvic-simulation/utility/Getters.hpp" #include "openvic-simulation/utility/TslHelper.hpp" @@ -164,7 +163,8 @@ namespace OpenVic { node_callback_t expect_ivec2(callback_t callback); node_callback_t expect_fvec2(callback_t callback); - node_callback_t expect_v2_vector3(callback_t callback); + node_callback_t expect_fvec3(callback_t callback); + node_callback_t expect_fvec4(callback_t callback); node_callback_t expect_assign(key_value_callback_t callback); using length_callback_t = std::function; diff --git a/src/openvic-simulation/interface/GFXObject.cpp b/src/openvic-simulation/interface/GFXObject.cpp index eb178369..956fa327 100644 --- a/src/openvic-simulation/interface/GFXObject.cpp +++ b/src/openvic-simulation/interface/GFXObject.cpp @@ -240,7 +240,7 @@ bool Billboard::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_map) { "noOfFrames", ZERO_OR_ONE, expect_int64(assign_variable_callback(no_of_frames)), "scale", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(scale)), "font_size", ZERO_OR_ONE, expect_int64(assign_variable_callback(font_size)), - "offset2", ZERO_OR_ONE, expect_v2_vector3(assign_variable_callback(offset)), + "offset2", ZERO_OR_ONE, expect_fvec3(assign_variable_callback(offset)), "font", ZERO_OR_ONE, expect_string(assign_variable_callback_string(font)) ); @@ -297,7 +297,7 @@ bool AnimatedMapText::_fill_key_map(NodeTools::case_insensitive_key_map_t& key_m ret &= add_key_map_entries(key_map, "speed", ONE_EXACTLY, expect_fixed_point(assign_variable_callback(speed)), - "position", ZERO_OR_ONE, expect_v2_vector3(assign_variable_callback(position)), + "position", ZERO_OR_ONE, expect_fvec3(assign_variable_callback(position)), "scale", ZERO_OR_ONE, expect_fixed_point(assign_variable_callback(scale)), "textblock", ONE_EXACTLY, expect_dictionary_keys( "text", ONE_EXACTLY, expect_string(assign_variable_callback_string(textblock.text)), diff --git a/src/openvic-simulation/interface/GFXObject.hpp b/src/openvic-simulation/interface/GFXObject.hpp index 899d30e8..eb459948 100644 --- a/src/openvic-simulation/interface/GFXObject.hpp +++ b/src/openvic-simulation/interface/GFXObject.hpp @@ -2,7 +2,7 @@ #include #include "openvic-simulation/interface/LoadBase.hpp" -#include +#include "openvic-simulation/types/Vector.hpp" #include namespace OpenVic::GFX { @@ -201,7 +201,7 @@ namespace OpenVic::GFX { fixed_point_t PROPERTY(scale); int64_t PROPERTY(no_of_frames); int64_t PROPERTY(font_size); //assume font size is int32, not fixed_point - V2Vector3 PROPERTY(offset); + fvec3_t PROPERTY(offset); //TODO std::string PROPERTY(font); protected: @@ -290,7 +290,7 @@ namespace OpenVic::GFX { private: fixed_point_t PROPERTY(speed); fixed_point_t PROPERTY(scale); - V2Vector3 PROPERTY(position); + fvec3_t PROPERTY(position); TextBlock PROPERTY(textblock); protected: diff --git a/src/openvic-simulation/types/unlabelledVec.hpp b/src/openvic-simulation/types/unlabelledVec.hpp deleted file mode 100644 index 4719726d..00000000 --- a/src/openvic-simulation/types/unlabelledVec.hpp +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "openvic-simulation/types/fixed_point/FixedPoint.hpp" - -namespace OpenVic { - //used in a couple places for GFXObjects - - struct V2Vector3 { - fixed_point_t x; - fixed_point_t y; - fixed_point_t z; - - //V2Vector3(fixed_point_t new_x = 0, fixed_point_t new_y = 0, fixed_point_t new_z = 0); - V2Vector3(fixed_point_t new_x = 0, fixed_point_t new_y = 0, fixed_point_t new_z = 0) : - x { new_x }, y { new_y }, z { new_z } {} - - //V2Vector3(V2Vector3&&) = default; //move constructor - virtual ~V2Vector3() = default; - }; - //used for lightTypes - struct V2Vector4 { - fixed_point_t x; - fixed_point_t y; - fixed_point_t z; - fixed_point_t w; - - V2Vector4(fixed_point_t new_x = 0, fixed_point_t new_y = 0, fixed_point_t new_z = 0, fixed_point_t new_w = 0); - - //V2Vector4(V2Vector4&&) = default; //move constructor - virtual ~V2Vector4() = default; - }; -} - -//TODO: Should we bother with more functions (to bring this in line with Vector.hpp) -//or are we just immediately converting this stuff to godot::Vector3, Vector4 anyways? -