Skip to content

Commit

Permalink
Sketch of symmetry group serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
tatjam committed Aug 2, 2023
1 parent 218ab38 commit 65327bd
Show file tree
Hide file tree
Showing 6 changed files with 151 additions and 38 deletions.
13 changes: 6 additions & 7 deletions src/universe/vehicle/SymmetryMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,16 @@ class SymmetryMode

};

// This is used only for the prototype and metadata, it, the stuff that's needed for
// the vehicle in flight. Lua stuff is loaded in init(), but ONLY IN THE EDITOR
// If loading the symmetry mode from a saved vehicle, remember to override with the
// prototype toml!
// This only loads the "meta-data", piecess are assigned in VehicleLoader
template<>
class GenericSerializer<SymmetryMode>
{
public:
static void serialize(const SymmetryMode& what, cpptoml::table& target)
{
// We use the prototype and override with save_toml, if prototype is not
// available, then the symmetry mode will be saved "headless"
// We can write save_toml directly
// TODO: A bit unorthodox? Maybe write the fields manually, so / but lua scripts won't be able to modify them?
SerializeUtil::override(target, *what.save_toml);
}

static void deserialize(SymmetryMode& to, const cpptoml::table& from)
Expand All @@ -162,7 +160,8 @@ class GenericSerializer<SymmetryMode>
icon = osp->assets->get_package_and_name(icon, pkg).second;
to.icon = AssetHandle<Image>(icon);

// Read everything into save_toml (TODO: override kind of useless overhead?)
// Read everything into save_toml
// so that the lua script can use it (once initialized, if it is!)
to.save_toml = cpptoml::make_table();
SerializeUtil::override(*to.save_toml, from);
}
Expand Down
31 changes: 31 additions & 0 deletions src/universe/vehicle/VehicleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,20 @@ void VehicleSaver::write_controlled(cpptoml::table &target, const Vehicle &what)
target.insert("controlled_machine", what.meta.controlled_machine);
}

void VehicleSaver::write_symmetry(cpptoml::table &target, const Vehicle &what)
{
auto array = cpptoml::make_table_array();

for(SymmetryMode* m : what.meta.symmetry_groups)
{
auto table = cpptoml::make_table();
serialize(m, *table);
array->push_back(table);
}

target.insert("symmetry_group", array);
}

void VehicleLoader::update_ids()
{
std::unordered_map<int64_t, Part*> new_parts_by_id;
Expand All @@ -639,3 +653,20 @@ void VehicleLoader::update_ids()
parts_by_id = new_parts_by_id;
}

void VehicleLoader::obtain_symmetry(const cpptoml::table& tb)
{
auto array = tb.get_table_array("symmetry_group");

if(!array)
return;

for(auto& t : *array)
{
SymmetryMode* mode = new SymmetryMode();


n_vehicle->meta.symmetry_groups.push_back(mode);
}

}

2 changes: 2 additions & 0 deletions src/universe/vehicle/VehicleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class VehicleSaver
void write_wires(cpptoml::table& target, const Vehicle& what);
void write_pipes(cpptoml::table& target, const Vehicle& what);
void write_controlled(cpptoml::table& target, const Vehicle& what);
void write_symmetry(cpptoml::table& target, const Vehicle& what);

public:
VehicleSaver(cpptoml::table& target, const Vehicle& what);
Expand Down Expand Up @@ -46,6 +47,7 @@ class VehicleLoader
void obtain_pipes(const cpptoml::table& root);

void obtain_controlled(const cpptoml::table& root);
void obtain_symmetry(const cpptoml::table& tb);

Piece* load_piece(const cpptoml::table& piece);

Expand Down
12 changes: 11 additions & 1 deletion src/universe/vehicle/VehicleMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,14 @@ void VehicleMeta::cleanup_symmetry_groups()
it++;
}
}
}
}

VehicleMeta::~VehicleMeta()
{
logger->check(false, "TODO");
for(auto* s : symmetry_groups)
{
delete s;
}

}
2 changes: 2 additions & 0 deletions src/universe/vehicle/VehicleMeta.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class VehicleMeta
controlled_machine = "";
}

~VehicleMeta();

// Obtains all symmetric copies of the piece, including nested symmetry groups
// Optionally includes the piece p as the first vector element
// If p is in no symmetry group, it's not included!
Expand Down
129 changes: 99 additions & 30 deletions udata/vehicles/debug.toml
Original file line number Diff line number Diff line change
@@ -1,88 +1,157 @@
part_id = 4
piece_id = 5
part_id = 7
piece_id = 8
in_flight = false
group_names = ["Other group"]
[[wire]]
to = 2
fmachine = "decoupler"
tmachine = "capsule"
fmachine = "capsule"
tmachine = "decoupler"
from = 3
[[piece]]
node = "p_root"
part = 4
transform = [0.99999999999978884, 0.0000000000000000, -6.5168273977172410e-7, 0.0000000000000000, 0.0000000000000000, 1.0000000000000000, 0.0000000000000000, 0.0000000000000000, 6.5168273977172410e-7, 0.0000000000000000, 0.99999999999978884, 0.0000000000000000, 0.14835030084081374, 0.030963708235930310, -1.4831779736721973, 1.0000000000000000]
id = 5
part = 7
transform = [-2.2204460492503131e-16, -1.0000000000000000, -1.1102230246251565e-16, 0.0000000000000000, 1.1102230246251565e-16, -2.2204460492503131e-16, 1.0000000000000000, 0.0000000000000000, -1.0000000000000000, 1.1102230246251565e-16, 0.0000000000000000, 0.0000000000000000, 2.1483503008408138, 0.030963708235929952, -1.4831779736721973, 1.0000000000000000]
id = 8
[piece.link]
to_attachment = "m_attach_bottom"
from_attachment = "m_attach_top"
welded = true
to = 3
to = 2
[[piece]]
node = "p_root"
part = 3
transform = [0.99999999999994693, 0.0000000000000000, -3.2584136988587576e-7, 0.0000000000000000, 0.0000000000000000, 1.0000000000000000, 0.0000000000000000, 0.0000000000000000, 3.2584136988587576e-7, 0.0000000000000000, 0.99999999999994693, 0.0000000000000000, 0.14835106733065165, 0.030963708235930310, -0.13083751384881906, 1.0000000000000000]
id = 4
part = 6
transform = [-0.86602540378443837, 0.50000000000000044, -5.5511151231257827e-17, 0.0000000000000000, 5.5511151231257827e-17, 2.2204460492503131e-16, 0.99999999999999989, 0.0000000000000000, 0.50000000000000044, 0.86602540378443826, 0.0000000000000000, 0.0000000000000000, -0.85164969915918709, -1.7010870993329463, -1.4831779736721973, 1.0000000000000000]
id = 7
[piece.link]
from_attachment = "m_attach_top"
welded = true
to = 2
[[piece]]
node = "p_root"
part = 5
transform = [0.86602540378443882, 0.49999999999999983, 0.0000000000000000, 0.0000000000000000, 0.0000000000000000, -2.2204460492503131e-16, 1.0000000000000002, 0.0000000000000000, 0.49999999999999983, -0.86602540378443893, -2.2204460492503131e-16, 0.0000000000000000, -0.85164969915918587, 1.7630145158048078, -1.4831779736721971, 1.0000000000000000]
id = 6
[piece.link]
from_attachment = "m_attach_top"
welded = true
to = 2
[[piece]]
node = "p_root"
part = 4
transform = [0.99999999999987443, 0.0000000000000000, -5.0068693724367187e-7, 0.0000000000000000, 0.0000000000000000, 1.0000000000000000, 0.0000000000000000, 0.0000000000000000, 5.0068693724367187e-7, 0.0000000000000000, 0.99999999999987443, 0.0000000000000000, 0.14834877490887710, 0.030963708235930310, -4.2292774457176616, 1.0000000000000000]
id = 5
[piece.link]
to_attachment = "m_attach_bottom"
from_attachment = "m_attach_top"
welded = true
to = 1
to = 2
[[piece]]
node = "p_decoupled"
part = 3
part = 2
transform = [0.99999999999994693, 0.0000000000000000, -3.2584136988587576e-7, 0.0000000000000000, 0.0000000000000000, 1.0000000000000000, 0.0000000000000000, 0.0000000000000000, 3.2584136988587576e-7, 0.0000000000000000, 0.99999999999994693, 0.0000000000000000, 0.14835100625965730, 0.030963708235930310, -0.31826305274632583, 1.0000000000000000]
id = 3
id = 4
[piece.link]
to_attachment = "m_decoupling_point"
editor_dettachable = false
welded = true
to = 4
to = 3
[[piece]]
node = "p_root"
part = 2
transform = [0.99999999999994693, 0.0000000000000000, -3.2584136988587576e-7, 0.0000000000000000, 0.0000000000000000, 1.0000000000000000, 0.0000000000000000, 0.0000000000000000, 3.2584136988587576e-7, 0.0000000000000000, 0.99999999999994693, 0.0000000000000000, 0.14835106733065165, 0.030963708235930310, -0.13083751384881906, 1.0000000000000000]
id = 3
[piece.link]
to_attachment = "m_attach_bottom"
from_attachment = "m_attach_top"
welded = true
to = 1
[[piece]]
node = "p_root"
part = 1
transform = [0.99999999999987443, 0.0000000000000000, -5.0068693724367187e-7, 0.0000000000000000, 0.0000000000000000, 1.0000000000000000, 0.0000000000000000, 0.0000000000000000, 5.0068693724367187e-7, 0.0000000000000000, 0.99999999999987443, 0.0000000000000000, 0.14834877490887710, 0.030963708235930310, -4.2292774457176616, 1.0000000000000000]
transform = [0.99999999999978884, 0.0000000000000000, -6.5168273977172410e-7, 0.0000000000000000, 0.0000000000000000, 1.0000000000000000, 0.0000000000000000, 0.0000000000000000, 6.5168273977172410e-7, 0.0000000000000000, 0.99999999999978884, 0.0000000000000000, 0.14835030084081374, 0.030963708235930310, -1.4831779736721973, 1.0000000000000000]
id = 2
[piece.link]
to_attachment = "m_attach_bottom"
from_attachment = "m_attach_top"
welded = true
to = 5
to = 4
[[piece]]
node = "p_root"
root = true
part = 2
part = 3
transform = [1.0000000000000000, 0.0000000000000000, 0.0000000000000000, 0.0000000000000000, 0.0000000000000000, 1.0000000000000000, 0.0000000000000000, 0.0000000000000000, 0.0000000000000000, 0.0000000000000000, 1.0000000000000000, 0.0000000000000000, 0.14835110050680012, 0.030963708235930310, 0.97529479114556494, 1.0000000000000000]
id = 1
[[part]]
proto = "test_parts:parts/fuel_tank/part_fuel_tank.toml"
group_id = 3342912776466489188
id = 7
[part.oxidizer_tank]
__plumbing_rot = 0
[part.oxidizer_tank.__plumbing_pos]
y = -1
x = 8
[part.fuel_tank]
__plumbing_rot = 0
[part.fuel_tank.__plumbing_pos]
y = -1
x = 3
[[part]]
proto = "test_parts:parts/fuel_tank/part_fuel_tank.toml"
group_id = 281500746579969
id = 5
[part.oxidizer_tank]
__plumbing_rot = 0
[part.oxidizer_tank.__plumbing_pos]
y = 21
x = -1
[part.fuel_tank]
__plumbing_rot = 0
[part.fuel_tank.__plumbing_pos]
y = 21
x = -7
[[part]]
proto = "test_parts:parts/engine/part_engine.toml"
group_id = -1
id = 4
[part.engine]
__plumbing_rot = 0
[part.engine.__plumbing_pos]
y = 16
x = -4
[[part]]
proto = "test_parts:parts/fuel_tank/part_fuel_tank.toml"
group_id = 1
id = 6
[part.oxidizer_tank]
__plumbing_rot = 0
[part.oxidizer_tank.__plumbing_pos]
y = -1
x = -2
x = 8
[part.fuel_tank]
__plumbing_rot = 0
[part.fuel_tank.__plumbing_pos]
y = -1
x = -7
x = 3
[[part]]
proto = "test_parts:parts/decoupler/part_decoupler.toml"
proto = "test_parts:parts/capsule/part_capsule.toml"
group_id = -1
id = 3
[part.decoupler]
[part.capsule]
[[part]]
proto = "test_parts:parts/capsule/part_capsule.toml"
proto = "test_parts:parts/decoupler/part_decoupler.toml"
group_id = -1
id = 2
[part.capsule]
[part.decoupler]
[[part]]
proto = "test_parts:parts/engine/part_engine.toml"
proto = "test_parts:parts/fuel_tank/part_fuel_tank.toml"
group_id = -1
id = 1
[part.engine]
[part.oxidizer_tank]
__plumbing_rot = 0
[part.engine.__plumbing_pos]
y = 16
x = -4
[part.oxidizer_tank.__plumbing_pos]
y = -1
x = -2
[part.fuel_tank]
__plumbing_rot = 0
[part.fuel_tank.__plumbing_pos]
y = -1
x = -7

0 comments on commit 65327bd

Please sign in to comment.