1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Reduce size of ContentFeatures structure

On my system this is a reduction from 4664 to 3704 bytes.
This is not for the sake of saving RAM but ensuring
commonly used structures fit into caches better.
This commit is contained in:
sfan5 2022-05-09 20:59:28 +02:00
parent 9a01581cdd
commit 8b74257bf3
4 changed files with 143 additions and 125 deletions

View file

@ -99,17 +99,8 @@ enum NodeBoxType
NODEBOX_CONNECTED, // optionally draws nodeboxes if a neighbor node attaches
};
struct NodeBox
struct NodeBoxConnected
{
enum NodeBoxType type;
// NODEBOX_REGULAR (no parameters)
// NODEBOX_FIXED
std::vector<aabb3f> fixed;
// NODEBOX_WALLMOUNTED
aabb3f wall_top;
aabb3f wall_bottom;
aabb3f wall_side; // being at the -X side
// NODEBOX_CONNECTED
std::vector<aabb3f> connect_top;
std::vector<aabb3f> connect_bottom;
std::vector<aabb3f> connect_front;
@ -124,9 +115,35 @@ struct NodeBox
std::vector<aabb3f> disconnected_right;
std::vector<aabb3f> disconnected;
std::vector<aabb3f> disconnected_sides;
};
struct NodeBox
{
enum NodeBoxType type;
// NODEBOX_REGULAR (no parameters)
// NODEBOX_FIXED
std::vector<aabb3f> fixed;
// NODEBOX_WALLMOUNTED
aabb3f wall_top;
aabb3f wall_bottom;
aabb3f wall_side; // being at the -X side
// NODEBOX_CONNECTED
// (kept externally to not bloat the structure)
std::shared_ptr<NodeBoxConnected> connected;
NodeBox()
{ reset(); }
~NodeBox() = default;
inline NodeBoxConnected &getConnected() {
if (!connected)
connected = std::make_shared<NodeBoxConnected>();
return *connected;
}
inline const NodeBoxConnected &getConnected() const {
assert(connected);
return *connected;
}
void reset();
void serialize(std::ostream &os, u16 protocol_version) const;
@ -290,7 +307,6 @@ struct ContentFeatures
// up down right left back front
TileSpec tiles[6];
// Special tiles
// - Currently used for flowing liquids
TileSpec special_tiles[CF_SPECIAL_COUNT];
u8 solidness; // Used when choosing which face is drawn
u8 visual_solidness; // When solidness=0, this tells how it looks like