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"
33 // This is here because it uses the MapBlock
34 v3f MapBlockObject::getAbsolutePos()
39 // getPosRelative gets nodepos relative to map origin
40 v3f blockpos = intToFloat(m_block->getPosRelative(), BS);
41 return blockpos + m_pos;
44 void MapBlockObject::setBlockChanged()
47 m_block->setChangedFlag();
54 v3f MovingObject::getAbsoluteShowPos()
59 // getPosRelative gets nodepos relative to map origin
60 v3f blockpos = intToFloat(m_block->getPosRelative(), BS);
61 return blockpos + m_showpos;
64 void MovingObject::move(float dtime, v3f acceleration)
66 DSTACKF("%s: typeid=%i, pos=(%f,%f,%f), speed=(%f,%f,%f)"
67 ", dtime=%f, acc=(%f,%f,%f)",
70 m_pos.X, m_pos.Y, m_pos.Z,
71 m_speed.X, m_speed.Y, m_speed.Z,
73 acceleration.X, acceleration.Y, acceleration.Z
76 v3s16 oldpos_i = floatToInt(m_pos, BS);
78 if(m_block->isValidPosition(oldpos_i) == false)
80 // Should have wrapped, cancelling further movement.
84 // No collisions if there is no collision box
85 if(m_collision_box == NULL)
87 m_speed += dtime * acceleration;
88 m_pos += m_speed * dtime;
92 // Set insane speed to zero
93 // Otherwise there will be divides by zero and other silly stuff
94 if(m_speed.getLength() > 1000.0*BS)
97 // Limit speed to a reasonable value
98 float speed_limit = 20.0*BS;
99 if(m_speed.getLength() > speed_limit)
100 m_speed = m_speed * (speed_limit / m_speed.getLength());
102 v3f position = m_pos;
103 v3f oldpos = position;
105 /*std::cout<<"oldpos_i=("<<oldpos_i.X<<","<<oldpos_i.Y<<","
106 <<oldpos_i.Z<<")"<<std::endl;*/
108 // Maximum time increment (for collision detection etc)
109 // Allow 0.1 blocks per increment
110 // time = distance / speed
111 // NOTE: In the loop below collisions are detected at 0.15*BS radius
112 float speedlength = m_speed.getLength();
113 f32 dtime_max_increment;
114 if(fabs(speedlength) > 0.001)
115 dtime_max_increment = 0.05*BS / speedlength;
117 dtime_max_increment = 0.5;
119 m_touching_ground = false;
127 if(dtime > dtime_max_increment)
128 dtime_part = dtime_max_increment;
133 // Begin of dtime limited code
135 m_speed += acceleration * dtime_part;
136 position += m_speed * dtime_part;
142 v3s16 pos_i = floatToInt(position, BS);
144 // The loop length is limited to the object moving a distance
145 f32 d = (float)BS * 0.15;
147 core::aabbox3d<f32> objectbox(
148 m_collision_box->MinEdge + position,
149 m_collision_box->MaxEdge + position
152 core::aabbox3d<f32> objectbox_old(
153 m_collision_box->MinEdge + oldpos,
154 m_collision_box->MaxEdge + oldpos
157 //TODO: Get these ranges from somewhere
158 for(s16 y = oldpos_i.Y - 1; y <= oldpos_i.Y + 2; y++)
159 for(s16 z = oldpos_i.Z - 1; z <= oldpos_i.Z + 1; z++)
160 for(s16 x = oldpos_i.X - 1; x <= oldpos_i.X + 1; x++)
163 if(content_walkable(m_block->getNodeParent(v3s16(x,y,z)).d)
167 catch(InvalidPositionException &e)
169 // Doing nothing here will block the object from
170 // walking over map borders
173 core::aabbox3d<f32> nodebox = getNodeBox(v3s16(x,y,z), BS);
175 // See if the object is touching ground
177 fabs(nodebox.MaxEdge.Y-objectbox.MinEdge.Y) < d
178 && nodebox.MaxEdge.X-d > objectbox.MinEdge.X
179 && nodebox.MinEdge.X+d < objectbox.MaxEdge.X
180 && nodebox.MaxEdge.Z-d > objectbox.MinEdge.Z
181 && nodebox.MinEdge.Z+d < objectbox.MaxEdge.Z
183 m_touching_ground = true;
186 if(objectbox.intersectsWithBox(nodebox))
194 for(u16 i=0; i<3; i++)
196 f32 nodemax = nodebox.MaxEdge.dotProduct(dirs[i]);
197 f32 nodemin = nodebox.MinEdge.dotProduct(dirs[i]);
198 f32 playermax = objectbox.MaxEdge.dotProduct(dirs[i]);
199 f32 playermin = objectbox.MinEdge.dotProduct(dirs[i]);
200 f32 playermax_old = objectbox_old.MaxEdge.dotProduct(dirs[i]);
201 f32 playermin_old = objectbox_old.MinEdge.dotProduct(dirs[i]);
203 bool main_edge_collides =
204 ((nodemax > playermin && nodemax <= playermin_old + d
205 && m_speed.dotProduct(dirs[i]) < 0)
207 (nodemin < playermax && nodemin >= playermax_old - d
208 && m_speed.dotProduct(dirs[i]) > 0));
210 bool other_edges_collide = true;
211 for(u16 j=0; j<3; j++)
215 f32 nodemax = nodebox.MaxEdge.dotProduct(dirs[j]);
216 f32 nodemin = nodebox.MinEdge.dotProduct(dirs[j]);
217 f32 playermax = objectbox.MaxEdge.dotProduct(dirs[j]);
218 f32 playermin = objectbox.MinEdge.dotProduct(dirs[j]);
219 if(!(nodemax - d > playermin && nodemin + d < playermax))
221 other_edges_collide = false;
226 if(main_edge_collides && other_edges_collide)
228 m_speed -= m_speed.dotProduct(dirs[i]) * dirs[i];
229 position -= position.dotProduct(dirs[i]) * dirs[i];
230 position += oldpos.dotProduct(dirs[i]) * dirs[i];
235 } // if(objectbox.intersectsWithBox(nodebox))
238 } // End of dtime limited loop
239 while(dtime > 0.001);
244 void MovingObject::simpleMove(float dtime)
246 m_pos_animation_time_counter += dtime;
247 m_pos_animation_counter += dtime;
248 v3f movevector = m_pos - m_oldpos;
250 if(m_pos_animation_time < 0.001)
253 moveratio = m_pos_animation_counter / m_pos_animation_time;
256 m_showpos = m_oldpos + movevector * moveratio;
263 void RatObject::addToScene(scene::ISceneManager *smgr)
268 video::IVideoDriver* driver = smgr->getVideoDriver();
270 scene::SMesh *mesh = new scene::SMesh();
271 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
272 video::SColor c(255,255,255,255);
273 video::S3DVertex vertices[4] =
275 video::S3DVertex(-BS/2,-BS/4,0, 0,0,0, c, 0,1),
276 video::S3DVertex(BS/2,-BS/4,0, 0,0,0, c, 1,1),
277 video::S3DVertex(BS/2,BS/4,0, 0,0,0, c, 1,0),
278 video::S3DVertex(-BS/2,BS/4,0, 0,0,0, c, 0,0),
280 u16 indices[] = {0,1,2,2,3,0};
281 buf->append(vertices, 4, indices, 6);
283 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
284 buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
285 buf->getMaterial().setTexture
286 (0, driver->getTexture(porting::getDataPath("rat.png").c_str()));
287 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
288 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
289 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
291 mesh->addMeshBuffer(buf);
293 m_node = smgr->addMeshSceneNode(mesh, NULL);
303 void ItemObject::addToScene(scene::ISceneManager *smgr)
308 //video::IVideoDriver* driver = smgr->getVideoDriver();
310 // Get image of item for showing
311 video::ITexture *texture = getItemImage();
317 scene::SMesh *mesh = new scene::SMesh();
319 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
320 video::SColor c(255,255,255,255);
321 video::S3DVertex vertices[4] =
323 /*video::S3DVertex(BS/2,-BS/2,0, 0,0,0, c, 0,1),
324 video::S3DVertex(-BS/2,-BS/2,0, 0,0,0, c, 1,1),
325 video::S3DVertex(-BS/2,BS/2,0, 0,0,0, c, 1,0),
326 video::S3DVertex(BS/2,BS/2,0, 0,0,0, c, 0,0),*/
327 video::S3DVertex(BS/3,-BS/2,0, 0,0,0, c, 0,1),
328 video::S3DVertex(-BS/3,-BS/2,0, 0,0,0, c, 1,1),
329 video::S3DVertex(-BS/3,-BS/2+BS*2/3,0, 0,0,0, c, 1,0),
330 video::S3DVertex(BS/3,-BS/2+BS*2/3,0, 0,0,0, c, 0,0),
332 u16 indices[] = {0,1,2,2,3,0};
333 buf->append(vertices, 4, indices, 6);
335 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
336 buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
337 buf->getMaterial().setTexture(0, texture);
338 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
339 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
340 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
342 mesh->addMeshBuffer(buf);
345 m_node = smgr->addMeshSceneNode(mesh, NULL);
346 // Set it to use the materials of the meshbuffers directly.
347 // This is needed for changing the texture in the future
348 ((scene::IMeshSceneNode*)m_node)->setReadOnlyMaterials(true);
354 video::ITexture * ItemObject::getItemImage()
357 Create an inventory item to see what is its image
359 video::ITexture *texture = NULL;
360 InventoryItem *item = createInventoryItem();
362 texture = item->getImage();
370 InventoryItem * ItemObject::createInventoryItem()
373 std::istringstream is(m_itemstring, std::ios_base::binary);
374 InventoryItem *item = InventoryItem::deSerialize(is);
375 dstream<<__FUNCTION_NAME<<": m_itemstring=\""
376 <<m_itemstring<<"\" -> item="<<item
380 catch(SerializationError &e)
382 dstream<<__FUNCTION_NAME<<": serialization error: "
383 <<"m_itemstring=\""<<m_itemstring<<"\""<<std::endl;
392 void PlayerObject::addToScene(scene::ISceneManager *smgr)
397 video::IVideoDriver* driver = smgr->getVideoDriver();
399 // Attach a simple mesh to the player for showing an image
400 scene::SMesh *mesh = new scene::SMesh();
402 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
403 video::SColor c(255,255,255,255);
404 video::S3DVertex vertices[4] =
406 video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
407 video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
408 video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
409 video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
411 u16 indices[] = {0,1,2,2,3,0};
412 buf->append(vertices, 4, indices, 6);
414 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
415 //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
416 buf->getMaterial().setTexture(0, driver->getTexture(porting::getDataPath("player.png").c_str()));
417 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
418 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
419 //buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
420 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
422 mesh->addMeshBuffer(buf);
426 scene::IMeshBuffer *buf = new scene::SMeshBuffer();
427 video::SColor c(255,255,255,255);
428 video::S3DVertex vertices[4] =
430 video::S3DVertex(BS/2,0,0, 0,0,0, c, 1,1),
431 video::S3DVertex(-BS/2,0,0, 0,0,0, c, 0,1),
432 video::S3DVertex(-BS/2,BS*2,0, 0,0,0, c, 0,0),
433 video::S3DVertex(BS/2,BS*2,0, 0,0,0, c, 1,0),
435 u16 indices[] = {0,1,2,2,3,0};
436 buf->append(vertices, 4, indices, 6);
438 buf->getMaterial().setFlag(video::EMF_LIGHTING, false);
439 //buf->getMaterial().setFlag(video::EMF_BACK_FACE_CULLING, false);
440 buf->getMaterial().setTexture(0, driver->getTexture(porting::getDataPath("player_back.png").c_str()));
441 buf->getMaterial().setFlag(video::EMF_BILINEAR_FILTER, false);
442 buf->getMaterial().setFlag(video::EMF_FOG_ENABLE, true);
443 buf->getMaterial().MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL_REF;
445 mesh->addMeshBuffer(buf);
449 m_node = smgr->addMeshSceneNode(mesh, NULL);
459 MapBlockObjectList::MapBlockObjectList(MapBlock *block):
465 MapBlockObjectList::~MapBlockObjectList()
471 The serialization format:
472 [0] u16 number of entries
473 [2] entries (id, typeId, parameters)
476 void MapBlockObjectList::serialize(std::ostream &os, u8 version)
478 JMutexAutoLock lock(m_mutex);
481 writeU16(buf, m_objects.size());
482 os.write((char*)buf, 2);
484 for(core::map<s16, MapBlockObject*>::Iterator
485 i = m_objects.getIterator();
486 i.atEnd() == false; i++)
488 i.getNode()->getValue()->serialize(os, version);
492 void MapBlockObjectList::update(std::istream &is, u8 version,
493 scene::ISceneManager *smgr, u32 daynight_ratio)
495 JMutexAutoLock lock(m_mutex);
498 Collect all existing ids to a set.
500 As things are updated, they are removed from this.
502 All remaining ones are deleted.
504 core::map<s16, bool> ids_to_delete;
505 for(core::map<s16, MapBlockObject*>::Iterator
506 i = m_objects.getIterator();
507 i.atEnd() == false; i++)
509 ids_to_delete.insert(i.getNode()->getKey(), true);
514 is.read((char*)buf, 2);
515 u16 count = readU16(buf);
517 for(u16 i=0; i<count; i++)
520 is.read((char*)buf, 2);
521 s16 id = readS16(buf);
524 // stored as x1000/BS v3s16
525 is.read((char*)buf, 6);
526 v3s16 pos_i = readV3S16(buf);
527 v3f pos((f32)pos_i.X/1000*BS,
528 (f32)pos_i.Y/1000*BS,
529 (f32)pos_i.Z/1000*BS);
532 is.read((char*)buf, 2);
533 u16 type_id = readU16(buf);
535 bool create_new = false;
537 // Find an object with the id
538 core::map<s16, MapBlockObject*>::Node *n;
539 n = m_objects.find(id);
540 // If no entry is found for id
543 // Insert dummy pointer node
544 m_objects.insert(id, NULL);
546 n = m_objects.find(id);
547 // A new object will be created at this node
550 // If type_id differs
551 else if(n->getValue()->getTypeId() != type_id)
554 delete n->getValue();
555 // A new object will be created at this node
559 MapBlockObject *obj = NULL;
563 /*dstream<<"MapBlockObjectList adding new object"
567 if(type_id == MAPBLOCKOBJECT_TYPE_SIGN)
569 obj = new SignObject(m_block, id, pos);
571 else if(type_id == MAPBLOCKOBJECT_TYPE_RAT)
573 obj = new RatObject(m_block, id, pos);
575 else if(type_id == MAPBLOCKOBJECT_TYPE_ITEM)
577 obj = new ItemObject(m_block, id, pos);
581 // This is fatal because we cannot know the length
582 // of the object's data
583 throw SerializationError
584 ("MapBlockObjectList::update(): Unknown MapBlockObject type");
588 //obj->addToScene(smgr, daynight_ratio);
589 obj->addToScene(smgr);
597 /*if(daynight_ratio != m_last_update_daynight_ratio)
599 obj->removeFromScene();
600 obj->addToScene(smgr, daynight_ratio);
604 // Now there is an object in obj.
607 obj->update(is, version);
610 Update light on client
614 u8 light = LIGHT_MAX;
616 v3s16 relpos_i = floatToInt(obj->m_pos, BS);
617 MapNode n = m_block->getNodeParent(relpos_i);
618 light = n.getLightBlend(daynight_ratio);
620 catch(InvalidPositionException &e) {}
621 obj->updateLight(light);
624 // Remove from deletion list
625 if(ids_to_delete.find(id) != NULL)
626 ids_to_delete.remove(id);
629 // Delete all objects whose ids_to_delete remain in ids_to_delete
630 for(core::map<s16, bool>::Iterator
631 i = ids_to_delete.getIterator();
632 i.atEnd() == false; i++)
634 s16 id = i.getNode()->getKey();
636 /*dstream<<"MapBlockObjectList deleting object"
640 MapBlockObject *obj = m_objects[id];
641 obj->removeFromScene();
643 m_objects.remove(id);
646 m_last_update_daynight_ratio = daynight_ratio;
649 s16 MapBlockObjectList::getFreeId() throw(ContainerFullException)
654 if(m_objects.find(id) == NULL)
657 throw ContainerFullException
658 ("MapBlockObjectList doesn't fit more objects");
663 void MapBlockObjectList::add(MapBlockObject *object)
664 throw(ContainerFullException, AlreadyExistsException)
668 dstream<<"MapBlockObjectList::add(): NULL object"<<std::endl;
672 JMutexAutoLock lock(m_mutex);
674 // Create unique id if id==-1
675 if(object->m_id == -1)
677 object->m_id = getFreeId();
680 if(m_objects.find(object->m_id) != NULL)
682 dstream<<"MapBlockObjectList::add(): "
683 "object with same id already exists"<<std::endl;
684 throw AlreadyExistsException
685 ("MapBlockObjectList already has given id");
688 object->m_block = m_block;
690 /*v3f p = object->m_pos;
691 dstream<<"MapBlockObjectList::add(): "
692 <<"m_block->getPos()=("
693 <<m_block->getPos().X<<","
694 <<m_block->getPos().Y<<","
695 <<m_block->getPos().Z<<")"
696 <<" inserting object with id="<<object->m_id
698 <<"("<<p.X<<","<<p.Y<<","<<p.Z<<")"
701 m_objects.insert(object->m_id, object);
704 void MapBlockObjectList::clear()
706 JMutexAutoLock lock(m_mutex);
708 for(core::map<s16, MapBlockObject*>::Iterator
709 i = m_objects.getIterator();
710 i.atEnd() == false; i++)
712 MapBlockObject *obj = i.getNode()->getValue();
713 //FIXME: This really shouldn't be NULL at any time,
714 // but this condition was added because it was.
717 obj->removeFromScene();
725 void MapBlockObjectList::remove(s16 id)
727 JMutexAutoLock lock(m_mutex);
729 core::map<s16, MapBlockObject*>::Node *n;
730 n = m_objects.find(id);
734 n->getValue()->removeFromScene();
735 delete n->getValue();
736 m_objects.remove(id);
739 MapBlockObject * MapBlockObjectList::get(s16 id)
741 core::map<s16, MapBlockObject*>::Node *n;
742 n = m_objects.find(id);
746 return n->getValue();
749 void MapBlockObjectList::step(float dtime, bool server, u32 daynight_ratio)
751 DSTACK(__FUNCTION_NAME);
753 JMutexAutoLock lock(m_mutex);
755 core::map<s16, bool> ids_to_delete;
758 DSTACKF("%s: stepping objects", __FUNCTION_NAME);
760 for(core::map<s16, MapBlockObject*>::Iterator
761 i = m_objects.getIterator();
762 i.atEnd() == false; i++)
764 MapBlockObject *obj = i.getNode()->getValue();
766 DSTACKF("%s: stepping object type %i", __FUNCTION_NAME,
772 u8 light = LIGHT_MAX;
774 v3s16 relpos_i = floatToInt(obj->m_pos, BS);
775 MapNode n = m_block->getNodeParent(relpos_i);
776 light = n.getLightBlend(daynight_ratio);
778 catch(InvalidPositionException &e) {}
779 obj->updateLight(light);
781 bool to_delete = obj->serverStep(dtime, daynight_ratio);
784 ids_to_delete.insert(obj->m_id, true);
788 obj->clientStep(dtime);
794 DSTACKF("%s: deleting objects", __FUNCTION_NAME);
796 // Delete objects in delete queue
797 for(core::map<s16, bool>::Iterator
798 i = ids_to_delete.getIterator();
799 i.atEnd() == false; i++)
801 s16 id = i.getNode()->getKey();
803 MapBlockObject *obj = m_objects[id];
804 obj->removeFromScene();
806 m_objects.remove(id);
811 Wrap objects on server
818 DSTACKF("%s: object wrap loop", __FUNCTION_NAME);
820 for(core::map<s16, MapBlockObject*>::Iterator
821 i = m_objects.getIterator();
822 i.atEnd() == false; i++)
824 MapBlockObject *obj = i.getNode()->getValue();
826 v3s16 pos_i = floatToInt(obj->m_pos, BS);
828 if(m_block->isValidPosition(pos_i))
834 bool impossible = wrapObject(obj);
843 i = m_objects.getIterator();
848 bool MapBlockObjectList::wrapObject(MapBlockObject *object)
850 DSTACK(__FUNCTION_NAME);
852 // No lock here; this is called so that the lock is already locked.
853 //JMutexAutoLock lock(m_mutex);
855 assert(object->m_block == m_block);
856 assert(m_objects.find(object->m_id) != NULL);
857 assert(m_objects[object->m_id] == object);
859 NodeContainer *parentcontainer = m_block->getParent();
860 // This will only work if the parent is the map
861 if(parentcontainer->nodeContainerId() != NODECONTAINER_ID_MAP)
863 dstream<<"WARNING: Wrapping object not possible: "
864 "MapBlock's parent is not map"<<std::endl;
867 // OK, we have the map!
868 Map *map = (Map*)parentcontainer;
870 // Calculate blockpos on map
871 v3s16 oldblock_pos_i_on_map = m_block->getPosRelative();
872 v3f pos_f_on_oldblock = object->m_pos;
873 v3s16 pos_i_on_oldblock = floatToInt(pos_f_on_oldblock, BS);
874 v3s16 pos_i_on_map = pos_i_on_oldblock + oldblock_pos_i_on_map;
875 v3s16 pos_blocks_on_map = getNodeBlockPos(pos_i_on_map);
880 newblock = map->getBlockNoCreate(pos_blocks_on_map);
882 catch(InvalidPositionException &e)
884 // Couldn't find block -> not wrapping
885 /*dstream<<"WARNING: Wrapping object not possible: "
886 <<"could not find new block"
887 <<"("<<pos_blocks_on_map.X
888 <<","<<pos_blocks_on_map.Y
889 <<","<<pos_blocks_on_map.Z
891 /*dstream<<"pos_f_on_oldblock=("
892 <<pos_f_on_oldblock.X<<","
893 <<pos_f_on_oldblock.Y<<","
894 <<pos_f_on_oldblock.Z<<")"
899 if(newblock == m_block)
901 dstream<<"WARNING: Wrapping object not possible: "
902 "newblock == oldblock"<<std::endl;
906 // Calculate position on new block
907 v3f oldblock_pos_f_on_map = intToFloat(oldblock_pos_i_on_map, BS);
908 v3s16 newblock_pos_i_on_map = newblock->getPosRelative();
909 v3f newblock_pos_f_on_map = intToFloat(newblock_pos_i_on_map, BS);
910 v3f pos_f_on_newblock = pos_f_on_oldblock
911 - newblock_pos_f_on_map + oldblock_pos_f_on_map;
913 // Remove object from this block
914 m_objects.remove(object->m_id);
916 // Add object to new block
917 object->m_pos = pos_f_on_newblock;
919 object->m_block = NULL;
920 newblock->addObject(object);
922 //dstream<<"NOTE: Wrapped object"<<std::endl;
927 void MapBlockObjectList::getObjects(v3f origin, f32 max_d,
928 core::array<DistanceSortedObject> &dest)
930 for(core::map<s16, MapBlockObject*>::Iterator
931 i = m_objects.getIterator();
932 i.atEnd() == false; i++)
934 MapBlockObject *obj = i.getNode()->getValue();
936 f32 d = (obj->getRelativeShowPos() - origin).getLength();
941 DistanceSortedObject dso(obj, d);