- m_block_cache = NULL;
-
- // Remove from container
- m_blocks.remove(block_y);
-}
-
-void MapSector::getBlocks(core::list<MapBlock*> &dest)
-{
- JMutexAutoLock lock(m_mutex);
-
- core::list<MapBlock*> ref_list;
-
- core::map<s16, MapBlock*>::Iterator bi;
-
- bi = m_blocks.getIterator();
- for(; bi.atEnd() == false; bi++)
- {
- MapBlock *b = bi.getNode()->getValue();
- dest.push_back(b);
- }
-}
-
-/*
- ServerMapSector
-*/
-
-ServerMapSector::ServerMapSector(NodeContainer *parent, v2s16 pos, u16 hm_split):
- MapSector(parent, pos),
- m_hm_split(hm_split),
- m_objects(NULL)
-{
- // hm_split has to be 1 or 2^x
- assert(hm_split == 0 || hm_split == 1 || (hm_split & (hm_split-1)) == 0);
- assert(hm_split * hm_split <= MAPSECTOR_FIXEDHEIGHTMAPS_MAXCOUNT);
-
- for(u16 i=0; i<hm_split*hm_split; i++)
- m_heightmaps[i] = NULL;
-}
-
-ServerMapSector::~ServerMapSector()
-{
- u16 hm_count = m_hm_split * m_hm_split;
-
- // Write heightmaps
- for(u16 i=0; i<hm_count; i++)
- {
- if(m_heightmaps[i])
- delete m_heightmaps[i];
- }
-
- if(m_objects)
- delete m_objects;
-}
-
-void ServerMapSector::setHeightmap(v2s16 hm_p, FixedHeightmap *hm)
-{
- assert(isInArea(hm_p, m_hm_split));
-
- s16 i = hm_p.Y * m_hm_split + hm_p.X;
-
- // Don't allow setting already set heightmaps as of now
- assert(m_heightmaps[i] == NULL);
-
- /*std::cout<<"MapSector::setHeightmap for sector "
- <<"("<<m_pos.X<<","<<m_pos.Y<<"): "
- <<"Setting heightmap "
- <<"("<<hm_p.X<<","<<hm_p.Y<<")"
- <<" which is i="<<i
- <<" to pointer "<<(long long)hm
- <<std::endl;*/
-
- m_heightmaps[i] = hm;
-
- differs_from_disk = true;
-}
-
-FixedHeightmap * ServerMapSector::getHeightmap(v2s16 hm_p)
-{
- assert(isInArea(hm_p, m_hm_split));
-
- s16 i = hm_p.Y * m_hm_split + hm_p.X;
-
- return m_heightmaps[i];
-}
-
-f32 ServerMapSector::getGroundHeight(v2s16 p, bool generate)
-{
- // If no heightmaps
- if(m_hm_split == 0)
- {
- /*std::cout<<"Sector has no heightmap"
- <<" while trying to get height at ("<<p.X<<","<<p.Y<<")"
- <<" for sector ("<<m_pos.X<<","<<m_pos.Y<<")"
- <<std::endl;*/
- return GROUNDHEIGHT_NOTFOUND_SETVALUE;
- }
-
- // Side length of heightmap
- s16 hm_d = MAP_BLOCKSIZE / m_hm_split;
-
- // Position of selected heightmap
- v2s16 hm_p = getContainerPos(p, hm_d);
- if(isInArea(hm_p, m_hm_split) == false)
- {
- /*std::cout<<"Sector has no heightmap ("<<hm_p.X<<","<<hm_p.Y<<")"
- <<" while trying to get height at ("<<p.X<<","<<p.Y<<")"
- <<" for sector ("<<m_pos.X<<","<<m_pos.Y<<")"
- <<std::endl;*/
- return GROUNDHEIGHT_NOTFOUND_SETVALUE;
- }
-
- // Selected heightmap
- FixedHeightmap *hm = m_heightmaps[hm_p.Y * m_hm_split + hm_p.X];
-
- if(hm == NULL)
- {
- /*std::cout<<"Sector heightmap ("<<hm_p.X<<","<<hm_p.Y<<")"
- " is NULL"
- <<" while trying to get height at ("<<p.X<<","<<p.Y<<")"
- <<" for sector ("<<m_pos.X<<","<<m_pos.Y<<")"
- <<std::endl;*/
- return GROUNDHEIGHT_NOTFOUND_SETVALUE;
- }
-
- // Position in selected heighmap
- v2s16 p_in_hm = p - hm_p * hm_d;
- if(isInArea(p_in_hm, hm_d+1) == false)
- {
- /*std::cout<<"Position ("<<p_in_hm.X<<","<<p_in_hm.Y<<")"
- " not in sector heightmap area"
- <<" while trying to get height at ("<<p.X<<","<<p.Y<<")"
- <<" for sector ("<<m_pos.X<<","<<m_pos.Y<<")"
- <<std::endl;*/
- return GROUNDHEIGHT_NOTFOUND_SETVALUE;
- }
-
- f32 h = hm->getGroundHeight(p_in_hm);
-
- /*if(h < GROUNDHEIGHT_VALID_MINVALUE)
- {
- std::cout<<"Sector heightmap ("<<hm_p.X<<","<<hm_p.Y<<")"
- " returned invalid value"
- <<" while trying to get height at ("<<p.X<<","<<p.Y<<")"
- <<" which is ("<<p_in_hm.X<<","<<p_in_hm.Y<<") in heightmap"
- <<" for sector ("<<m_pos.X<<","<<m_pos.Y<<")"
- <<std::endl;
- }*/
-
- return h;
-}