3 Copyright (C) 2010 celeron55, Perttu Ahola <celeron55@gmail.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // This file contains the DEPRECATED MapBlockObject system
22 #include "mapblockobject.h"
24 // For object wrapping
26 #include "inventory.h"
34 // This is here because it uses the MapBlock
35 v3f MapBlockObject::getAbsolutePos()
40 // getPosRelative gets nodepos relative to map origin
41 v3f blockpos = intToFloat(m_block->getPosRelative(), BS);
42 return blockpos + m_pos;
45 void MapBlockObject::setBlockChanged()
48 m_block->setChangedFlag();
55 v3f MovingObject::getAbsoluteShowPos()
60 // getPosRelative gets nodepos relative to map origin
61 v3f blockpos = intToFloat(m_block->getPosRelative(), BS);
62 return blockpos + m_showpos;
65 void MovingObject::move(float dtime, v3f acceleration)
67 DSTACKF("%s: typeid=%i, pos=(%f,%f,%f), speed=(%f,%f,%f)"
68 ", dtime=%f, acc=(%f,%f,%f)",
71 m_pos.X, m_pos.Y, m_pos.Z,
72 m_speed.X, m_speed.Y, m_speed.Z,
74 acceleration.X, acceleration.Y, acceleration.Z
77 v3s16 oldpos_i = floatToInt(m_pos, BS);
79 if(m_block->isValidPosition(oldpos_i) == false)
81 // Should have wrapped, cancelling further movement.
85 // No collisions if there is no collision box
86 if(m_collision_box == NULL)
88 m_speed += dtime * acceleration;
89 m_pos += m_speed * dtime;
93 // Set insane speed to zero
94 // Otherwise there will be divides by zero and other silly stuff
95 if(m_speed.getLength() > 1000.0*BS)
98 // Limit speed to a reasonable value
99 float speed_limit = 20.0*BS;
100 if(m_speed.getLength() > speed_limit)
101 m_speed = m_speed * (speed_limit / m_speed.getLength());
103 v3f position = m_pos;
104 v3f oldpos = position;
106 /*std::cout<<"oldpos_i=("<<oldpos_i.X<<","<<oldpos_i.Y<<","
107 <<oldpos_i.Z<<")"<<std::endl;*/
109 // Maximum time increment (for collision detection etc)
110 // Allow 0.1 blocks per increment
111 // time = distance / speed
112 // NOTE: In the loop below collisions are detected at 0.15*BS radius
113 float speedlength = m_speed.getLength();
114 f32 dtime_max_increment;
115 if(fabs(speedlength) > 0.001)
116 dtime_max_increment = 0.05*BS / speedlength;
118 dtime_max_increment = 0.5;
120 m_touching_ground = false;
128 if(dtime > dtime_max_increment)
129 dtime_part = dtime_max_increment;
134 // Begin of dtime limited code
136 m_speed += acceleration * dtime_part;
137 position += m_speed * dtime_part;
143 v3s16 pos_i = floatToInt(position, BS);
145 // The loop length is limited to the object moving a distance
146 f32 d = (float)BS * 0.15;
148 core::aabbox3d<f32> objectbox(
149 m_collision_box->MinEdge + position,
150 m_collision_box->MaxEdge + position
153 core::aabbox3d<f32> objectbox_old(
154 m_collision_box->MinEdge + oldpos,
155 m_collision_box->MaxEdge + oldpos
158 //TODO: Get these ranges from somewhere
159 for(s16 y = oldpos_i.Y - 1; y <= oldpos_i.Y + 2; y++)
160 for(s16 z = oldpos_i.Z - 1; z <= oldpos_i.Z + 1; z++)
161 for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++)
164 MapNode n = m_block->getNodeParent(v3s16(x,y,z));
165 if(content_features(n).walkable == false)
168 catch(InvalidPositionException &e)
170 // Doing nothing here will block the object from
171 // walking over map borders
174 core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS);
176 // See if the object is touching ground
178 fabs(nodebox.MaxEdge.Y-objectbox.MinEdge.Y) < d
179 && nodebox.MaxEdge.X-d > objectbox.MinEdge.X
180 && nodebox.MinEdge.X+d < objectbox.MaxEdge.X
181 && nodebox.MaxEdge.Z-d > objectbox.MinEdge.Z
182 && nodebox.MinEdge.Z+d < objectbox.MaxEdge.Z
184 m_touching_ground = true;
187 if(objectbox.intersectsWithBox(nodebox))
195 for(u16 i=0; i<3; i++)
197 f32 nodemax = nodebox.MaxEdge.dotProduct(dirs[i]);
198 f32 nodemin = nodebox.MinEdge.dotProduct(dirs[i]);
199 f32 playermax = objectbox.MaxEdge.dotProduct(dirs[i]);
200 f32 playermin = objectbox.MinEdge.dotProduct(dirs[i]);
201 f32 playermax_old = objectbox_old.MaxEdge.dotProduct(dirs[i]);
202 f32 playermin_old = objectbox_old.MinEdge.dotProduct(dirs[i]);
204 bool main_edge_collides =
205 ((nodemax > playermin && nodemax <= playermin_old + d
206 && m_speed.dotProduct(dirs[i]) < 0)
208 (nodemin < playermax && nodemin >= playermax_old - d
209 && m_speed.dotProduct(dirs[i]) > 0));
211 bool other_edges_collide = true;
212 for(u16 j=0; j<3; j++)
216 f32 nodemax = nodebox.MaxEdge.dotProduct(dirs[j]);
217 f32 nodemin = nodebox.MinEdge.dotProduct(dirs[j]);
218 f32 playermax = objectbox.MaxEdge.dotProduct(dirs[j]);
219 f32 playermin = objectbox.MinEdge.dotProduct(dirs[j]);
220 if(!(nodemax - d > playermin && nodemin + d < playermax))
222 other_edges_collide = false;
227 if(main_edge_collides && other_edges_collide)
229 m_speed -= m_speed.dotProduct(dirs[i]) * dirs[i];
230 position -= position.dotProduct(dirs[i]) * dirs[i];
231 position += oldpos.dotProduct(dirs[i]) * dirs[i];
236 } // if(objectbox.intersectsWithBox(nodebox))
239 } // End of dtime limited loop
240 while(dtime > 0.001);
245 void MovingObject::simpleMove(float dtime)
247 m_pos_animation_time_counter += dtime;
248 m_pos_animation_counter += dtime;
249 v3f movevector = m_pos - m_oldpos;
251 if(m_pos_animation_time < 0.001)
254 moveratio = m_pos_animation_counter / m_pos_animation_time;
257 m_showpos = m_oldpos + movevector * moveratio;
264 void RatObject::addToScene(scene::ISceneManager *smgr)
269 video::IVideoDriver* driver = smgr->getVideoDriver();
271 scene::SMesh *mesh = new scene::SMesh();
272 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
273 video::SColor c(255,255,255,255);
274 video::S3DVertex vertices[4] =
276 video::S3DVertex(-BS/2,-BS/4,0, 0,0,0, c, 0,1),
277 video::S3DVertex(BS/2,-BS/4,0, 0,0,0, c, 1,1),
278 video::S3DVertex(BS/2,BS/4,0, 0,0,0, c, 1,0),
279 video::S3DVertex(-BS/2,BS/4,0, 0,0,0, c, 0,0),
281 u16 indices[] = {0,1,2,2,3,0};
282 buf->append(vertices, 4, indices, 6);
284 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
285 buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
286 buf->getMaterial().setTexture
287 (0, driver->getTexture(getTexturePath("rat.png").c_str()));
288 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
289 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
290 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
292 mesh->addMeshBuffer(buf);
294 m_node = smgr->addMeshSceneNode(mesh, NULL);
304 void ItemObject::addToScene(scene::ISceneManager *smgr)
309 //video::IVideoDriver* driver = smgr->getVideoDriver();
311 // Get image of item for showing
312 video::ITexture *texture = getItemImage();
318 scene::SMesh *mesh = new scene::SMesh();
320 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
321 video::SColor c(255,255,255,255);
322 video::S3DVertex vertices[4] =
324 /*video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c, 0,1),
325 video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c, 1,1),
326 video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c, 1,0),
327 video::S3DVertex(BS/2,BS/2,0, 0,0,0, c, 0,0),*/
328 video::S3DVertex(BS/3,-BS/2,0, 0,0,0, c, 0,1),
329 video::S3DVertex(-BS/3,-BS/2,0, 0,0,0, c, 1,1),
330 video::S3DVertex(-BS/3,-BS/2+BS*2/3,0, 0,0,0, c, 1,0),
331 video::S3DVertex(BS/3,-BS/2+BS*2/3,0, 0,0,0, c, 0,0),
333 u16 indices[] = {0,1,2,2,3,0};
334 buf->append(vertices, 4, indices, 6);
336 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
337 buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
338 buf->getMaterial().setTexture(0, texture);
339 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
340 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
341 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
343 mesh->addMeshBuffer(buf);
346 m_node = smgr->addMeshSceneNode(mesh, NULL);
347 // Set it to use the materials of the meshbuffers directly.
348 // This is needed for changing the texture in the future
349 ((scene::IMeshSceneNode*)m_node)->setReadOnlyMaterials(true);
355 video::ITexture * ItemObject::getItemImage()
358 Create an inventory item to see what is its image
360 video::ITexture *texture = NULL;
361 InventoryItem *item = createInventoryItem();
363 texture = item->getImage();
371 InventoryItem * ItemObject::createInventoryItem()
374 std::istringstream is(m_itemstring, std::ios_base::binary);
375 InventoryItem *item = InventoryItem::deSerialize(is);
376 dstream<<__FUNCTION_NAME<<": m_itemstring=\""
377 <<m_itemstring<<"\" -> item="<<item
381 catch(SerializationError &e)
383 dstream<<__FUNCTION_NAME<<": serialization error: "
384 <<"m_itemstring=\""<<m_itemstring<<"\""<<std::endl;
393 void PlayerObject::addToScene(scene::ISceneManager *smgr)
398 video::IVideoDriver* driver = smgr->getVideoDriver();
400 // Attach a simple mesh to the player for showing an image
401 scene::SMesh *mesh = new scene::SMesh();
403 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
404 video::SColor c(255,255,255,255);
405 video::S3DVertex vertices[4] =
407 video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
408 video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
409 video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
410 video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
412 u16 indices[] = {0,1,2,2,3,0};
413 buf->append(vertices, 4, indices, 6);
415 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
416 //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
417 buf->getMaterial().setTexture(0, driver->getTexture(getTexturePath("player.png").c_str()));
418 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
419 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
420 //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
421 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
423 mesh->addMeshBuffer(buf);
427 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
428 video::SColor c(255,255,255,255);
429 video::S3DVertex vertices[4] =
431 video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
432 video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
433 video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
434 video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
436 u16 indices[] = {0,1,2,2,3,0};
437 buf->append(vertices, 4, indices, 6);
439 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
440 //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
441 buf->getMaterial().setTexture(0, driver->getTexture(getTexturePath("player_back.png").c_str()));
442 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
443 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
444 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
446 mesh->addMeshBuffer(buf);
450 m_node = smgr->addMeshSceneNode(mesh, NULL);
460 MapBlockObjectList::MapBlockObjectList(MapBlock *block):
466 MapBlockObjectList::~MapBlockObjectList()
472 The serialization format:
473 [0] u16 number of entries
474 [2] entries (id, typeId, parameters)
477 void MapBlockObjectList::serialize(std::ostream &os, u8 version)
479 JMutexAutoLock lock(m_mutex);
482 writeU16(buf, m_objects.size());
483 os.write((char*)buf, 2);
485 for(core::map<s16, MapBlockObject*>::Iterator
486 i = m_objects.getIterator();
487 i.atEnd() == false; i++)
489 i.getNode()->getValue()->serialize(os, version);
493 void MapBlockObjectList::update(std::istream &is, u8 version,
494 scene::ISceneManager *smgr, u32 daynight_ratio)
496 JMutexAutoLock lock(m_mutex);
499 Collect all existing ids to a set.
501 As things are updated, they are removed from this.
503 All remaining ones are deleted.
505 core::map<s16, bool> ids_to_delete;
506 for(core::map<s16, MapBlockObject*>::Iterator
507 i = m_objects.getIterator();
508 i.atEnd() == false; i++)
510 ids_to_delete.insert(i.getNode()->getKey(), true);
515 is.read((char*)buf, 2);
516 u16 count = readU16(buf);
518 for(u16 i=0; i<count; i++)
521 is.read((char*)buf, 2);
522 s16 id = readS16(buf);
525 // stored as x1000/BS v3s16
526 is.read((char*)buf, 6);
527 v3s16 pos_i = readV3S16(buf);
528 v3f pos((f32)pos_i.X/1000*BS,
529 (f32)pos_i.Y/1000*BS,
530 (f32)pos_i.Z/1000*BS);
533 is.read((char*)buf, 2);
534 u16 type_id = readU16(buf);
536 bool create_new = false;
538 // Find an object with the id
539 core::map<s16, MapBlockObject*>::Node *n;
540 n = m_objects.find(id);
541 // If no entry is found for id
544 // Insert dummy pointer node
545 m_objects.insert(id, NULL);
547 n = m_objects.find(id);
548 // A new object will be created at this node
551 // If type_id differs
552 else if(n->getValue()->getTypeId() != type_id)
555 delete n->getValue();
556 // A new object will be created at this node
560 MapBlockObject *obj = NULL;
564 /*dstream<<"MapBlockObjectList adding new object"
568 if(type_id == MAPBLOCKOBJECT_TYPE_SIGN)
570 obj = new SignObject(m_block, id, pos);
572 else if(type_id == MAPBLOCKOBJECT_TYPE_RAT)
574 obj = new RatObject(m_block, id, pos);
576 else if(type_id == MAPBLOCKOBJECT_TYPE_ITEM)
578 obj = new ItemObject(m_block, id, pos);
582 // This is fatal because we cannot know the length
583 // of the object's data
584 throw SerializationError
585 ("MapBlockObjectList::update(): Unknown MapBlockObject type");
589 //obj->addToScene(smgr, daynight_ratio);
590 obj->addToScene(smgr);
598 /*if(daynight_ratio != m_last_update_daynight_ratio)
600 obj->removeFromScene();
601 obj->addToScene(smgr, daynight_ratio);
605 // Now there is an object in obj.
608 obj->update(is, version);
611 Update light on client
615 u8 light = LIGHT_MAX;
617 v3s16 relpos_i = floatToInt(obj->m_pos, BS);
618 MapNode n = m_block->getNodeParent(relpos_i);
619 light = n.getLightBlend(daynight_ratio);
621 catch(InvalidPositionException &e) {}
622 obj->updateLight(light);
625 // Remove from deletion list
626 if(ids_to_delete.find(id) != NULL)
627 ids_to_delete.remove(id);
630 // Delete all objects whose ids_to_delete remain in ids_to_delete
631 for(core::map<s16, bool>::Iterator
632 i = ids_to_delete.getIterator();
633 i.atEnd() == false; i++)
635 s16 id = i.getNode()->getKey();
637 /*dstream<<"MapBlockObjectList deleting object"
641 MapBlockObject *obj = m_objects[id];
642 obj->removeFromScene();
644 m_objects.remove(id);
647 m_last_update_daynight_ratio = daynight_ratio;
650 s16 MapBlockObjectList::getFreeId() throw(ContainerFullException)
655 if(m_objects.find(id) == NULL)
658 throw ContainerFullException
659 ("MapBlockObjectList doesn't fit more objects");
664 void MapBlockObjectList::add(MapBlockObject *object)
665 throw(ContainerFullException, AlreadyExistsException)
669 dstream<<"MapBlockObjectList::add(): NULL object"<<std::endl;
673 JMutexAutoLock lock(m_mutex);
675 // Create unique id if id==-1
676 if(object->m_id == -1)
678 object->m_id = getFreeId();
681 if(m_objects.find(object->m_id) != NULL)
683 dstream<<"MapBlockObjectList::add(): "
684 "object with same id already exists"<<std::endl;
685 throw AlreadyExistsException
686 ("MapBlockObjectList already has given id");
689 object->m_block = m_block;
691 /*v3f p = object->m_pos;
692 dstream<<"MapBlockObjectList::add(): "
693 <<"m_block->getPos()=("
694 <<m_block->getPos().X<<","
695 <<m_block->getPos().Y<<","
696 <<m_block->getPos().Z<<")"
697 <<" inserting object with id="<<object->m_id
699 <<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
702 m_objects.insert(object->m_id, object);
705 void MapBlockObjectList::clear()
707 JMutexAutoLock lock(m_mutex);
709 for(core::map<s16, MapBlockObject*>::Iterator
710 i = m_objects.getIterator();
711 i.atEnd() == false; i++)
713 MapBlockObject *obj = i.getNode()->getValue();
714 //FIXME: This really shouldn't be NULL at any time,
715 // but this condition was added because it was.
718 obj->removeFromScene();
726 void MapBlockObjectList::remove(s16 id)
728 JMutexAutoLock lock(m_mutex);
730 core::map<s16, MapBlockObject*>::Node *n;
731 n = m_objects.find(id);
735 n->getValue()->removeFromScene();
736 delete n->getValue();
737 m_objects.remove(id);
740 MapBlockObject * MapBlockObjectList::get(s16 id)
742 core::map<s16, MapBlockObject*>::Node *n;
743 n = m_objects.find(id);
747 return n->getValue();
750 void MapBlockObjectList::step(float dtime, bool server, u32 daynight_ratio)
752 DSTACK(__FUNCTION_NAME);
754 JMutexAutoLock lock(m_mutex);
756 core::map<s16, bool> ids_to_delete;
759 DSTACKF("%s: stepping objects", __FUNCTION_NAME);
761 for(core::map<s16, MapBlockObject*>::Iterator
762 i = m_objects.getIterator();
763 i.atEnd() == false; i++)
765 MapBlockObject *obj = i.getNode()->getValue();
767 DSTACKF("%s: stepping object type %i", __FUNCTION_NAME,
773 u8 light = LIGHT_MAX;
775 v3s16 relpos_i = floatToInt(obj->m_pos, BS);
776 MapNode n = m_block->getNodeParent(relpos_i);
777 light = n.getLightBlend(daynight_ratio);
779 catch(InvalidPositionException &e) {}
780 obj->updateLight(light);
782 bool to_delete = obj->serverStep(dtime, daynight_ratio);
785 ids_to_delete.insert(obj->m_id, true);
789 obj->clientStep(dtime);
795 DSTACKF("%s: deleting objects", __FUNCTION_NAME);
797 // Delete objects in delete queue
798 for(core::map<s16, bool>::Iterator
799 i = ids_to_delete.getIterator();
800 i.atEnd() == false; i++)
802 s16 id = i.getNode()->getKey();
804 MapBlockObject *obj = m_objects[id];
805 obj->removeFromScene();
807 m_objects.remove(id);
812 Wrap objects on server
819 DSTACKF("%s: object wrap loop", __FUNCTION_NAME);
821 for(core::map<s16, MapBlockObject*>::Iterator
822 i = m_objects.getIterator();
823 i.atEnd() == false; i++)
825 MapBlockObject *obj = i.getNode()->getValue();
827 v3s16 pos_i = floatToInt(obj->m_pos, BS);
829 if(m_block->isValidPosition(pos_i))
835 bool impossible = wrapObject(obj);
844 i = m_objects.getIterator();
849 bool MapBlockObjectList::wrapObject(MapBlockObject *object)
851 DSTACK(__FUNCTION_NAME);
853 // No lock here; this is called so that the lock is already locked.
854 //JMutexAutoLock lock(m_mutex);
856 assert(object->m_block == m_block);
857 assert(m_objects.find(object->m_id) != NULL);
858 assert(m_objects[object->m_id] == object);
860 Map *map = m_block->getParent();
862 // Calculate blockpos on map
863 v3s16 oldblock_pos_i_on_map = m_block->getPosRelative();
864 v3f pos_f_on_oldblock = object->m_pos;
865 v3s16 pos_i_on_oldblock = floatToInt(pos_f_on_oldblock, BS);
866 v3s16 pos_i_on_map = pos_i_on_oldblock + oldblock_pos_i_on_map;
867 v3s16 pos_blocks_on_map = getNodeBlockPos(pos_i_on_map);
872 newblock = map->getBlockNoCreate(pos_blocks_on_map);
874 catch(InvalidPositionException &e)
876 // Couldn't find block -> not wrapping
877 /*dstream<<"WARNING: Wrapping object not possible: "
878 <<"could not find new block"
879 <<"("<<pos_blocks_on_map.X
880 <<","<<pos_blocks_on_map.Y
881 <<","<<pos_blocks_on_map.Z
883 /*dstream<<"pos_f_on_oldblock=("
884 <<pos_f_on_oldblock.X<<","
885 <<pos_f_on_oldblock.Y<<","
886 <<pos_f_on_oldblock.Z<<")"
891 if(newblock == m_block)
893 dstream<<"WARNING: Wrapping object not possible: "
894 "newblock == oldblock"<<std::endl;
898 // Calculate position on new block
899 v3f oldblock_pos_f_on_map = intToFloat(oldblock_pos_i_on_map, BS);
900 v3s16 newblock_pos_i_on_map = newblock->getPosRelative();
901 v3f newblock_pos_f_on_map = intToFloat(newblock_pos_i_on_map, BS);
902 v3f pos_f_on_newblock = pos_f_on_oldblock
903 - newblock_pos_f_on_map + oldblock_pos_f_on_map;
905 // Remove object from this block
906 m_objects.remove(object->m_id);
908 // Add object to new block
909 object->m_pos = pos_f_on_newblock;
911 object->m_block = NULL;
912 newblock->addObject(object);
914 //dstream<<"NOTE: Wrapped object"<<std::endl;
919 void MapBlockObjectList::getObjects(v3f origin, f32 max_d,
920 core::array<DistanceSortedObject> &dest)
922 for(core::map<s16, MapBlockObject*>::Iterator
923 i = m_objects.getIterator();
924 i.atEnd() == false; i++)
926 MapBlockObject *obj = i.getNode()->getValue();
928 f32 d = (obj->getRelativeShowPos() - origin).getLength();
933 DistanceSortedObject dso(obj, d);