From 9408a1a0250b2523bf393eafd8287843c57af591 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 12 Dec 2023 16:14:40 +0100 Subject: [PATCH] Reduce size of some MapBlock members Also adds assertions to catch refcounting errors (on a debug build). --- src/mapblock.h | 8 +++++--- src/modifiedstate.h | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/mapblock.h b/src/mapblock.h index 16aaa1f28..5d87acaed 100644 --- a/src/mapblock.h +++ b/src/mapblock.h @@ -379,15 +379,17 @@ public: inline void refGrab() { + assert(m_refcount < SHRT_MAX); m_refcount++; } inline void refDrop() { + assert(m_refcount > 0); m_refcount--; } - inline int refGet() + inline short refGet() { return m_refcount; } @@ -500,7 +502,7 @@ private: block has been modified from the one on disk. - On the client, this is used for nothing. */ - u32 m_modified = MOD_STATE_WRITE_NEEDED; + u16 m_modified = MOD_STATE_WRITE_NEEDED; u32 m_modified_reason = MOD_REASON_INITIAL; /* @@ -550,7 +552,7 @@ private: Reference count; currently used for determining if this block is in the list of blocks to be drawn. */ - int m_refcount = 0; + short m_refcount = 0; NodeTimerList m_node_timers; }; diff --git a/src/modifiedstate.h b/src/modifiedstate.h index 3eeb55d02..5bf3b643c 100644 --- a/src/modifiedstate.h +++ b/src/modifiedstate.h @@ -19,7 +19,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #pragma once -enum ModifiedState +#include "irrlichttypes.h" + +enum ModifiedState : u16 { // Has not been modified. MOD_STATE_CLEAN = 0,