Skip to content

Commit

Permalink
gfxobject use fvec3_t
Browse files Browse the repository at this point in the history
  • Loading branch information
Nemrav committed Nov 28, 2024
1 parent c21b17b commit 75b99ec
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 58 deletions.
41 changes: 26 additions & 15 deletions src/openvic-simulation/dataloader/NodeTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -288,25 +289,35 @@ node_callback_t NodeTools::expect_fvec2(callback_t<fvec2_t> callback) {
return _expect_vec2<fixed_point_t, expect_fixed_point>(callback);
}

node_callback_t NodeTools::expect_v2_vector3(callback_t<V2Vector3> 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<fvec3_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<fvec4_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;
};
}

Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/dataloader/NodeTools.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -164,7 +163,8 @@ namespace OpenVic {

node_callback_t expect_ivec2(callback_t<ivec2_t> callback);
node_callback_t expect_fvec2(callback_t<fvec2_t> callback);
node_callback_t expect_v2_vector3(callback_t<V2Vector3> callback);
node_callback_t expect_fvec3(callback_t<fvec3_t> callback);
node_callback_t expect_fvec4(callback_t<fvec4_t> callback);
node_callback_t expect_assign(key_value_callback_t callback);

using length_callback_t = std::function<size_t(size_t)>;
Expand Down
4 changes: 2 additions & 2 deletions src/openvic-simulation/interface/GFXObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
);

Expand Down Expand Up @@ -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)),
Expand Down
6 changes: 3 additions & 3 deletions src/openvic-simulation/interface/GFXObject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <cstdint>
#include "openvic-simulation/interface/LoadBase.hpp"
#include <openvic-simulation/types/unlabelledVec.hpp>
#include "openvic-simulation/types/Vector.hpp"
#include <openvic-simulation/types/TextFormat.hpp>

namespace OpenVic::GFX {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
36 changes: 0 additions & 36 deletions src/openvic-simulation/types/unlabelledVec.hpp

This file was deleted.

0 comments on commit 75b99ec

Please sign in to comment.