mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 12:57:06 +01:00
107cc3c927
The window of an EU07M model gets tabs: the tree of the nodes beside the properties of the node picked, the parts of the vehicle, the clips and channels, and the components of the model. The texts are Polish in lang/editor_pl.po. - With nothing selected, it shows the model of the vehicle driven (its body or its cab). - In the 3D view the node picked is framed and shows its axes and a gizmo to move or turn it. The light sources are marked in their colour, a spot with its axis, and a click on a mark picks its node. A press on the gizmo or a mark doesn't pick a scenery node, and the editor's own gizmo gives way. A double click in the tree flies the camera there. - The settings of a node: its position, rotation (degrees) and scale, and the distances it is drawn from and up to. - "Add a light source here" puts in a node light_<n> with a point or spot LGHT as the last child of the node. eu07m::insert_node moves every reference to the nodes after it, and eu07m::add_component appends a component; both have unit tests. - Changes show at once on the model the game has, through new TModel3d methods for the editor (ApplyEU07MLight, AddEditorLight, SetEditorTransform, SetEditorRange). The spot's cones are edited as half angles in degrees. - Parts of the vehicle: the editor holds the lamps, coupler hooks and hoses in their _off/_on/_xon state, and the pantographs up or down, whatever the vehicle does. A held pantograph moves at its own pace, in the editor too, up to the wire above it. Only the look changes: the electrics of the vehicle don't. - Neither the empty-scenery line nor the no-tracks hint shows in a scenery of models alone. - New editor self-test command: modelnode <name>.
114 lines
4.2 KiB
C++
114 lines
4.2 KiB
C++
#include "stdafx.h"
|
|
|
|
#include "doctest.h"
|
|
|
|
#include "model/eu07m/eu07m_build.h"
|
|
#include "model/eu07m/eu07m_io.h"
|
|
|
|
#include <cstring>
|
|
#include <vector>
|
|
|
|
namespace {
|
|
|
|
// root (0) { lamp (1), door (2) }, rear (3); a light slot of the root lists the door and the rear node, a joint is aimed at the
|
|
// rear node and a clip moves it
|
|
eu07m::model lamp_model() {
|
|
eu07m::model model;
|
|
auto const node = [&model](std::string_view const Name, std::int32_t const Parent, std::uint32_t const End) {
|
|
eu07m::node_record record;
|
|
record.name = model.intern(Name);
|
|
record.parent = Parent;
|
|
record.subtree_end = End;
|
|
model.nodes.push_back(record);
|
|
};
|
|
node("root", -1, 3);
|
|
node("lamp", 0, 2);
|
|
node("door", 0, 3);
|
|
node("rear", -1, 4);
|
|
eu07m::payload::light_slot slot;
|
|
slot.on_count = 1;
|
|
slot.off_count = 1;
|
|
std::vector<std::byte> data(sizeof(slot) + 2 * sizeof(std::uint32_t));
|
|
std::memcpy(data.data(), &slot, sizeof(slot));
|
|
std::uint32_t const lit{2};
|
|
std::uint32_t const dark{3};
|
|
std::memcpy(data.data() + sizeof(slot), &lit, sizeof(lit));
|
|
std::memcpy(data.data() + sizeof(slot) + sizeof(lit), &dark, sizeof(dark));
|
|
eu07m::add_component(model, eu07m::component::light_slot, eu07m::target_kind::node, 0, data);
|
|
eu07m::payload::joint joint;
|
|
std::vector<std::byte> jointdata(sizeof(joint));
|
|
std::memcpy(jointdata.data(), &joint, sizeof(joint));
|
|
eu07m::add_component(model, eu07m::component::joint, eu07m::target_kind::node, 3, jointdata);
|
|
eu07m::clip_record clip;
|
|
clip.name = model.intern("open");
|
|
clip.track_first = 0;
|
|
clip.track_count = 1;
|
|
model.clips.push_back(clip);
|
|
eu07m::track_record track;
|
|
track.node = 3;
|
|
track.key_count = 1;
|
|
model.clip_tracks.push_back(track);
|
|
model.key_times.push_back(0.f);
|
|
model.key_vectors.push_back({0.f, 0.f, 0.f});
|
|
eu07m::build_name_index(model);
|
|
return model;
|
|
}
|
|
|
|
std::uint32_t listed_node(eu07m::model const &Model, std::uint32_t const Component, std::size_t const Item) {
|
|
std::uint32_t node{0};
|
|
std::memcpy(&node, Model.component_data.data() + Model.components[Component].data_offset + sizeof(eu07m::payload::light_slot) + Item * sizeof(node), sizeof(node));
|
|
return node;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("eu07m: a node put in under a parent moves the references to the nodes after it") {
|
|
auto model{lamp_model()};
|
|
REQUIRE(eu07m::validate(model).empty());
|
|
eu07m::node_record light;
|
|
light.name = model.intern("light_1");
|
|
auto const index{eu07m::insert_node(model, 0, light)};
|
|
CHECK(index == 3);
|
|
REQUIRE(model.nodes.size() == 5);
|
|
// the root holds it, the lamp and the door keep their subtrees, the rear node moves on
|
|
CHECK(model.nodes[0].subtree_end == 4);
|
|
CHECK(model.nodes[1].subtree_end == 2);
|
|
CHECK(model.nodes[2].subtree_end == 3);
|
|
CHECK(model.nodes[3].parent == 0);
|
|
CHECK(model.nodes[3].subtree_end == 4);
|
|
CHECK(model.string(model.nodes[4].name) == "rear");
|
|
CHECK(model.nodes[4].parent == -1);
|
|
CHECK(model.nodes[4].subtree_end == 5);
|
|
// the joint, the track and the light slot follow the rear node; the door stays
|
|
CHECK(model.components[1].target == 4);
|
|
CHECK(model.clip_tracks[0].node == 4);
|
|
CHECK(listed_node(model, 0, 0) == 2);
|
|
CHECK(listed_node(model, 0, 1) == 4);
|
|
CHECK(eu07m::find_nodes(model, "light_1") == std::vector<std::uint32_t>{3});
|
|
CHECK(eu07m::find_nodes(model, "rear") == std::vector<std::uint32_t>{4});
|
|
CHECK(eu07m::validate(model).empty());
|
|
}
|
|
|
|
TEST_CASE("eu07m: a node put in without a parent goes last, and a component added is listed by it") {
|
|
auto model{lamp_model()};
|
|
eu07m::node_record light;
|
|
light.name = model.intern("light_2");
|
|
auto const index{eu07m::insert_node(model, -1, light)};
|
|
CHECK(index == 4);
|
|
CHECK(model.nodes[3].subtree_end == 4);
|
|
CHECK(model.nodes[4].subtree_end == 5);
|
|
eu07m::payload::light payload;
|
|
std::vector<std::byte> data(sizeof(payload));
|
|
std::memcpy(data.data(), &payload, sizeof(payload));
|
|
auto const component{eu07m::add_component(model, eu07m::component::light, eu07m::target_kind::node, index, data)};
|
|
CHECK(model.nodes[index].component_first == component);
|
|
CHECK(model.nodes[index].component_count == 1);
|
|
CHECK(model.components[component].data_offset % 4 == 0);
|
|
CHECK(eu07m::validate(model).empty());
|
|
// the file written and read again holds the same
|
|
eu07m::model read;
|
|
REQUIRE(eu07m::read(eu07m::write(model), read).ok);
|
|
CHECK(read.nodes.size() == 5);
|
|
CHECK(read.components.size() == 3);
|
|
}
|