1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

CAO 'node' visual (#15683)

This commit is contained in:
sfan5 2025-01-14 20:25:52 +01:00
parent 5a8720a484
commit 27bbe3a873
14 changed files with 267 additions and 91 deletions

View file

@ -63,6 +63,8 @@ std::string ObjectProperties::dump() const
os << ", static_save=" << static_save;
os << ", eye_height=" << eye_height;
os << ", zoom_fov=" << zoom_fov;
os << ", node=(" << (int)node.getContent() << ", " << (int)node.getParam1()
<< ", " << (int)node.getParam2() << ")";
os << ", use_texture_alpha=" << use_texture_alpha;
os << ", damage_texture_modifier=" << damage_texture_modifier;
os << ", shaded=" << shaded;
@ -79,8 +81,8 @@ static auto tie(const ObjectProperties &o)
o.nametag_color, o.nametag_bgcolor, o.spritediv, o.initial_sprite_basepos,
o.stepheight, o.automatic_rotate, o.automatic_face_movement_dir_offset,
o.automatic_face_movement_max_rotation_per_sec, o.eye_height, o.zoom_fov,
o.hp_max, o.breath_max, o.glow, o.pointable, o.physical, o.collideWithObjects,
o.rotate_selectionbox, o.is_visible, o.makes_footstep_sound,
o.node, o.hp_max, o.breath_max, o.glow, o.pointable, o.physical,
o.collideWithObjects, o.rotate_selectionbox, o.is_visible, o.makes_footstep_sound,
o.automatic_face_movement_dir, o.backface_culling, o.static_save, o.use_texture_alpha,
o.shaded, o.show_on_minimap
);
@ -170,6 +172,7 @@ void ObjectProperties::serialize(std::ostream &os) const
writeU8(os, shaded);
writeU8(os, show_on_minimap);
// use special value to tell apart nil, fully transparent and other colors
if (!nametag_bgcolor)
writeARGB8(os, NULL_BGCOLOR);
else if (nametag_bgcolor.value().getAlpha() == 0)
@ -178,8 +181,31 @@ void ObjectProperties::serialize(std::ostream &os) const
writeARGB8(os, nametag_bgcolor.value());
writeU8(os, rotate_selectionbox);
writeU16(os, node.getContent());
writeU8(os, node.getParam1());
writeU8(os, node.getParam2());
// Add stuff only at the bottom.
// Never remove anything, because we don't want new versions of this
// Never remove anything, because we don't want new versions of this!
}
namespace {
// Type-safe wrapper for bools as u8
inline bool readBool(std::istream &is)
{
return readU8(is) != 0;
}
// Wrapper for primitive reading functions that don't throw (awful)
template <typename T, T (reader)(std::istream& is)>
bool tryRead(T& val, std::istream& is)
{
T tmp = reader(is);
if (is.eof())
return false;
val = tmp;
return true;
}
}
void ObjectProperties::deSerialize(std::istream &is)
@ -229,26 +255,32 @@ void ObjectProperties::deSerialize(std::istream &is)
eye_height = readF32(is);
zoom_fov = readF32(is);
use_texture_alpha = readU8(is);
try {
damage_texture_modifier = deSerializeString16(is);
u8 tmp = readU8(is);
if (is.eof())
return;
shaded = tmp;
tmp = readU8(is);
if (is.eof())
return;
show_on_minimap = tmp;
} catch (SerializationError &e) {
return;
}
auto bgcolor = readARGB8(is);
if (bgcolor != NULL_BGCOLOR)
nametag_bgcolor = bgcolor;
else
nametag_bgcolor = std::nullopt;
if (!tryRead<bool, readBool>(shaded, is))
return;
tmp = readU8(is);
if (is.eof())
return;
rotate_selectionbox = tmp;
} catch (SerializationError &e) {}
if (!tryRead<bool, readBool>(show_on_minimap, is))
return;
auto bgcolor = readARGB8(is);
if (bgcolor != NULL_BGCOLOR)
nametag_bgcolor = bgcolor;
else
nametag_bgcolor = std::nullopt;
if (!tryRead<bool, readBool>(rotate_selectionbox, is))
return;
if (!tryRead<content_t, readU16>(node.param0, is))
return;
node.param1 = readU8(is);
node.param2 = readU8(is);
// Add new properties down here and remember to use either tryRead<> or a try-catch.
}