bool RoomsManager::IsValidPosition(Ogre::Vector3 position) { bool found=false; Room *room; //std::vector<Room*>::iterator iPos=Rooms.begin(), iEnd=Rooms.end(); //for (size_t i=0;i<Rooms.Size;++i) for (RoomsPool::ListNode *pos = Rooms.GetBegin(); pos!=NULL; pos=pos->Next) { room = pos->Value; found = room->GetBox()->contains(position); if (found) { return true; } } return false; }
bool RoomsManager::PutObject(Room::ObjectType* object) { //return false; object->GetRoomable()->RemoveFromRooms(); object->GetRoomable()->GetRooms()->Clear(); bool updated=false, inrooms=false; Room *room; //std::vector<Room*>::iterator iPos=Rooms.begin(), iEnd=Rooms.end(); /*for (size_t i=0;i<Rooms.Size;++i) { room = Rooms.Data[i]; updated = room->PutObject(object); if (updated) { inrooms = true; } }*/ Ogre::AxisAlignedBox box = object->GetRoomable()->GetBoundingBox(), *RoomBox; for (RoomsPool::ListNode *pos = Rooms.GetBegin(); pos!=NULL; pos=pos->Next) { room = pos->Value; RoomBox = room->GetBox(); if (RoomBox->intersects(box)) { updated = room->PutObject(object); if (updated) { inrooms = true; } } } /*if (!inrooms && object->GetTag()!=T_CAMERA) { char log[100]; sprintf(log,"Rooms 0: empty room set for object %d\n",object->GetScriptable()->GetID()); Debugging::Log("Warnings.log",log); }*/ return inrooms; }
bool RoomsManager::UpdateObject(Room::ObjectType* object) { bool updated=false, inrooms=false; Room *room; //std::vector<Room*>::iterator iPos=Rooms.begin(), iEnd=Rooms.end(); inrooms=false; //for (size_t i=0;i<Rooms.Size;++i) Ogre::AxisAlignedBox box = object->GetRoomable()->GetBoundingBox(), *RoomBox; //assert() for (RoomsPool::ListNode *pos = Rooms.GetBegin(); pos!=NULL; pos=pos->Next) { room = pos->Value; RoomBox = room->GetBox(); if (RoomBox->intersects(box)) { updated = room->UpdateObject(object); if (updated) { inrooms=true; } } } if (!inrooms) { /*char log[100]; sprintf(log,"Rooms 1: empty room set for object %d\n",object->GetScriptable()->GetID()); Debugging::Log("Warnings.log",log);*/ IRoomable *rmbl = object->GetRoomable(); IPhysical *phys = object->GetPhysical(); if (rmbl) { rmbl->RemoveFromRooms(); rmbl->GetRooms()->Clear(); switch (rmbl->GetRoomOnly()) { case IRoomable::ROM_RESTORE: { for (RoomsPool::ListNode *pos = Rooms.GetBegin(); pos!=NULL; pos=pos->Next) { Ogre::AxisAlignedBox *box = pos->Value->GetBox(); Ogre::Vector3 center = box->getCenter(); Ogre::Vector3 position = object->GetPosition(); Ogre::Vector3 dist = position - center; int sqradius = AAUtilities::f2i(box->getHalfSize().squaredLength())+3*phys->GetRadius(); int sqdist = AAUtilities::f2i(dist.squaredLength()); if (sqradius>sqdist) { //GetPhysical()->SetForwardDirection(GetOrientation()*Vector3::UNIT_Z); //object->GetPhysical(); //object->RestoreBackupPosition(); //Ogre::Vector3 newdir=phys->GetLastVelocity(); //phys->Stop(); phys->SetReplacingDirection(-dist.normalisedCopy()*10); break; } } AddOuterObject(object); //object->RestoreBackupPosition(); break; } case IRoomable::ROM_DESTROY: { CommonDeclarations::DeleteObjectRequest(object); break; } case IRoomable::ROM_SCRIPT: { IScriptable *scr = object->GetScriptable(); if (scr && scr->GetID()>0) ScriptManager::GetInstance()->Call("OnOutOfRooms", "i", false, object->GetScriptable()->GetID()); break; } case IRoomable::ROM_NONE: { AddOuterObject(object); break; } }; } } return inrooms; }