- 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;
-}
-
-void ServerMapSector::setGroundHeight(v2s16 p, f32 y, bool generate)
-{
- /*
- NOTE:
- This causes glitches because the sector cannot be actually
- modified according to heightmap changes.
-
- This is useful when generating continued sub-heightmaps
- inside the sector.
- */
-
- // If no heightmaps
- if(m_hm_split == 0)
- return;
-
- // 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)
- return;
-
- // Selected heightmap
- FixedHeightmap *hm = m_heightmaps[hm_p.Y * m_hm_split + hm_p.X];
-
- if(hm == NULL)
- return;
-
- // Position in selected heighmap
- v2s16 p_in_hm = p - hm_p * hm_d;
- if(isInArea(p_in_hm, hm_d) == false)
- return;
-
- hm->setGroundHeight(p_in_hm, y);
-
- differs_from_disk = true;