Allocate MapBlock::m_node_metadata on heap to allow less header bloat

This commit is contained in:
Perttu Ahola 2011-11-13 12:54:33 +02:00
parent 64fa59e24f
commit 3b77a63d5d
6 changed files with 19 additions and 14 deletions

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "settings.h" #include "settings.h"
#include "profiler.h" #include "profiler.h"
#include "log.h" #include "log.h"
#include "nodemetadata.h"
/* /*
QueuedMeshUpdate QueuedMeshUpdate

@ -31,6 +31,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "profiler.h" #include "profiler.h"
#include "scriptapi.h" #include "scriptapi.h"
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
#include "nodemetadata.h"
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")" #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
@ -607,7 +608,7 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
activateObjects(block); activateObjects(block);
// Run node metadata // Run node metadata
bool changed = block->m_node_metadata.step((float)dtime_s); bool changed = block->m_node_metadata->step((float)dtime_s);
if(changed) if(changed)
{ {
MapEditEvent event; MapEditEvent event;
@ -917,7 +918,7 @@ void ServerEnvironment::step(float dtime)
block->setTimestampNoChangedFlag(m_game_time); block->setTimestampNoChangedFlag(m_game_time);
// Run node metadata // Run node metadata
bool changed = block->m_node_metadata.step(dtime); bool changed = block->m_node_metadata->step(dtime);
if(changed) if(changed)
{ {
MapEditEvent event; MapEditEvent event;

@ -45,6 +45,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "filesys.h" #include "filesys.h"
// Needed for determining pointing to nodes // Needed for determining pointing to nodes
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
#include "nodemetadata.h"
/* /*
Setting this to 1 enables a special camera mode that forces Setting this to 1 enables a special camera mode that forces

@ -1836,7 +1836,7 @@ NodeMetadata* Map::getNodeMetadata(v3s16 p)
<<std::endl; <<std::endl;
return NULL; return NULL;
} }
NodeMetadata *meta = block->m_node_metadata.get(p_rel); NodeMetadata *meta = block->m_node_metadata->get(p_rel);
return meta; return meta;
} }
@ -1856,7 +1856,7 @@ void Map::setNodeMetadata(v3s16 p, NodeMetadata *meta)
<<std::endl; <<std::endl;
return; return;
} }
block->m_node_metadata.set(p_rel, meta); block->m_node_metadata->set(p_rel, meta);
} }
void Map::removeNodeMetadata(v3s16 p) void Map::removeNodeMetadata(v3s16 p)
@ -1870,7 +1870,7 @@ void Map::removeNodeMetadata(v3s16 p)
<<std::endl; <<std::endl;
return; return;
} }
block->m_node_metadata.remove(p_rel); block->m_node_metadata->remove(p_rel);
} }
void Map::nodeMetadataStep(float dtime, void Map::nodeMetadataStep(float dtime,
@ -1895,7 +1895,7 @@ void Map::nodeMetadataStep(float dtime,
for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++) for(i=sectorblocks.begin(); i!=sectorblocks.end(); i++)
{ {
MapBlock *block = *i; MapBlock *block = *i;
bool changed = block->m_node_metadata.step(dtime); bool changed = block->m_node_metadata->step(dtime);
if(changed) if(changed)
changed_blocks[block->getPos()] = block; changed_blocks[block->getPos()] = block;
} }

@ -24,12 +24,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "light.h" #include "light.h"
#include <sstream> #include <sstream>
#include "mapnode_contentfeatures.h" #include "mapnode_contentfeatures.h"
#include "nodemetadata.h"
/* /*
MapBlock MapBlock
*/ */
MapBlock::MapBlock(Map *parent, v3s16 pos, bool dummy): MapBlock::MapBlock(Map *parent, v3s16 pos, bool dummy):
m_node_metadata(new NodeMetadataList),
m_parent(parent), m_parent(parent),
m_pos(pos), m_pos(pos),
m_modified(MOD_STATE_WRITE_NEEDED), m_modified(MOD_STATE_WRITE_NEEDED),
@ -44,8 +46,6 @@ MapBlock::MapBlock(Map *parent, v3s16 pos, bool dummy):
if(dummy == false) if(dummy == false)
reallocate(); reallocate();
//m_spawn_timer = -10000;
#ifndef SERVER #ifndef SERVER
m_mesh_expired = false; m_mesh_expired = false;
mesh_mutex.Init(); mesh_mutex.Init();
@ -68,6 +68,8 @@ MapBlock::~MapBlock()
} }
#endif #endif
delete m_node_metadata;
if(data) if(data)
delete[] data; delete[] data;
} }
@ -632,7 +634,7 @@ void MapBlock::serialize(std::ostream &os, u8 version)
{ {
try{ try{
std::ostringstream oss(std::ios_base::binary); std::ostringstream oss(std::ios_base::binary);
m_node_metadata.serialize(oss); m_node_metadata->serialize(oss);
os<<serializeString(oss.str()); os<<serializeString(oss.str());
} }
// This will happen if the string is longer than 65535 // This will happen if the string is longer than 65535
@ -645,7 +647,7 @@ void MapBlock::serialize(std::ostream &os, u8 version)
else else
{ {
std::ostringstream oss(std::ios_base::binary); std::ostringstream oss(std::ios_base::binary);
m_node_metadata.serialize(oss); m_node_metadata->serialize(oss);
compressZlib(oss.str(), os); compressZlib(oss.str(), os);
//os<<serializeLongString(oss.str()); //os<<serializeLongString(oss.str());
} }
@ -784,7 +786,7 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
{ {
std::string data = deSerializeString(is); std::string data = deSerializeString(is);
std::istringstream iss(data, std::ios_base::binary); std::istringstream iss(data, std::ios_base::binary);
m_node_metadata.deSerialize(iss); m_node_metadata->deSerialize(iss);
} }
else else
{ {
@ -792,7 +794,7 @@ void MapBlock::deSerialize(std::istream &is, u8 version)
std::ostringstream oss(std::ios_base::binary); std::ostringstream oss(std::ios_base::binary);
decompressZlib(is, oss); decompressZlib(is, oss);
std::istringstream iss(oss.str(), std::ios_base::binary); std::istringstream iss(oss.str(), std::ios_base::binary);
m_node_metadata.deSerialize(iss); m_node_metadata->deSerialize(iss);
} }
} }
catch(SerializationError &e) catch(SerializationError &e)

@ -30,7 +30,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "serialization.h" #include "serialization.h"
#include "constants.h" #include "constants.h"
#include "voxel.h" #include "voxel.h"
#include "nodemetadata.h"
#include "staticobject.h" #include "staticobject.h"
#include "mapblock_nodemod.h" #include "mapblock_nodemod.h"
#ifndef SERVER #ifndef SERVER
@ -38,6 +37,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif #endif
class Map; class Map;
class NodeMetadataList;
#define BLOCK_TIMESTAMP_UNDEFINED 0xffffffff #define BLOCK_TIMESTAMP_UNDEFINED 0xffffffff
@ -575,7 +575,7 @@ public:
JMutex mesh_mutex; JMutex mesh_mutex;
#endif #endif
NodeMetadataList m_node_metadata; NodeMetadataList *m_node_metadata;
StaticObjectList m_static_objects; StaticObjectList m_static_objects;
private: private: