void ETHBucketManager::GetIntersectingEntities(const Vector2 &point, ETHEntityArray &outVector, const bool screenSpace, const ETHSceneProperties& props) { ETHEntityArray temp; const Vector2 v2Bucket(ETHBucketManager::GetBucket(point, GetBucketSize())); GetEntitiesAroundBucket(v2Bucket, temp); for (unsigned int t=0; t<temp.size(); t++) { ETHEntityProperties::VIEW_RECT rect = temp[t]->GetScreenRect(props); if (!screenSpace) { const Vector2 cameraPos = m_provider->GetVideo()->GetCameraPos(); rect.max += cameraPos; rect.min += cameraPos; } if (point.x < rect.min.x) continue; if (point.y < rect.min.y) continue; if (point.x > rect.max.x) continue; if (point.y > rect.max.y) continue; outVector.push_back(temp[t]); } }
void ETHScene::ClearLightmaps() { ETHEntityArray entities; m_buckets.GetEntityArray(entities); for (unsigned int t = 0; t < entities.size(); t++) { entities[t]->ReleaseLightmap(); } }
void ETHScene::RecoverResources() { ETHEntityArray entities; m_buckets.GetEntityArray(entities); for (std::size_t t = 0; t < entities.size(); t++) { entities[t]->RecoverResources(); } }
void ETHScene::ScaleEntities(const float scale, const bool scalePosition) { if (scale == 1.0f) return; ETHEntityArray entities; m_buckets.GetEntityArray(entities); for (unsigned int t = 0; t < entities.size(); t++) { entities[t]->Scale(scale); if (scalePosition) { entities[t]->SetPosition(entities[t]->GetPosition() * scale, m_buckets); } } }
void ETHBucketManager::GetVisibleEntities(ETHEntityArray &outVector) { std::list<Vector2> bucketList; GetIntersectingBuckets(bucketList, m_provider->GetVideo()->GetCameraPos(), m_provider->GetVideo()->GetScreenSizeF(), IsDrawingBorderBuckets(), IsDrawingBorderBuckets()); // Loop through all visible Buckets for (std::list<Vector2>::iterator bucketPositionIter = bucketList.begin(); bucketPositionIter != bucketList.end(); ++bucketPositionIter) { ETHBucketMap::const_iterator bucketIter = Find(*bucketPositionIter); if (bucketIter == GetLastBucket()) continue; const ETHEntityList& entityList = bucketIter->second; if (entityList.empty()) continue; ETHEntityList::const_iterator iEnd = entityList.end(); for (ETHEntityList::const_iterator iter = entityList.begin(); iter != iEnd; ++iter) { outVector.push_back(*iter); } } }
void ETHBucketManager::GetEntityArray(ETHEntityArray &outVector) { for (ETHBucketMap::iterator bucketIter = GetFirstBucket(); bucketIter != GetLastBucket(); ++bucketIter) { ETHEntityList& entityList = bucketIter->second; ETHEntityList::const_iterator iEnd = entityList.end(); for (ETHEntityList::iterator iter = entityList.begin(); iter != iEnd; ++iter) { outVector.push_back(*iter); } } }
void ETHPhysicsSimulator::ResolveJoints(ETHEntityArray& entities) { const unsigned int numEntities = entities.size(); for (unsigned int t = 0; t < numEntities; t++) { ETHPhysicsEntityControllerPtr controller = boost::dynamic_pointer_cast<ETHPhysicsEntityController>(entities[t]->GetController()); if (controller) { controller->ResolveJoints(entities, *entities[t]->GetProperties(), *this); } } }
void ETHBucketManager::GetEntityArrayFromBucket(const Vector2 &bucket, ETHEntityArray &outVector, const ETHEntityChooser& chooser) { ETHBucketMap::iterator bucketIter = Find(bucket); if (bucketIter == GetLastBucket()) return; ETHEntityList& entityList = bucketIter->second; ETHEntityList::const_iterator iEnd = entityList.end(); for (ETHEntityList::iterator iter = entityList.begin(); iter != iEnd; ++iter) { if (chooser.Choose(*iter)) outVector.push_back(*iter); } }
bool ETHPhysicsEntityController::ResolveJoints(ETHEntityArray& entities, const ETHEntityProperties& properties, ETHPhysicsSimulator& simulator) { if (properties.enmlJointDefinitions == GS_L("")) return false; const std::size_t numEntities = entities.size(); const enml::File file(properties.enmlJointDefinitions); std::list<str_type::string> jointNames; file.GetEntityNameList(jointNames); for (std::list<str_type::string>::const_iterator iter = jointNames.begin(); iter != jointNames.end(); ++iter) { const str_type::string& jointName = *iter; // get the other entity name from the joint definition str_type::string otherEntityName = ETHJoint::GetOtherEntityName(jointName, file); int otherEntityID = -1; // if the other entity name is not declared in the joint definition, look for it into the custom data if (otherEntityName == GS_L("")) { if (properties.Check(jointName) == ETHCustomData::DT_STRING) { properties.GetString(jointName, otherEntityName); } else if (properties.Check(jointName) == ETHCustomData::DT_INT) { properties.GetInt(jointName, otherEntityID); } else { continue; } } // iterate over entities to find the other-entity for (std::size_t t = 0; t < numEntities; t++) { const unsigned int idx = static_cast<unsigned int>(t); if (entities[idx]->GetEntityName() == otherEntityName || entities[idx]->GetID() == otherEntityID) { boost::shared_ptr<ETHJoint> joint = ETHJoint::CreateJoint(jointName, file, simulator, static_cast<ETHEntity*>(m_body->GetUserData()), (entities[idx])); if (joint) m_joints.push_back(joint); break; } } } return true; }
void ETHBucketManager::GetEntityArrayByName(const str_type::string& name, ETHEntityArray &outVector) { for (ETHBucketMap::iterator bucketIter = GetFirstBucket(); bucketIter != GetLastBucket(); ++bucketIter) { ETHEntityList& entityList = bucketIter->second; ETHEntityList::const_iterator iEnd = entityList.end(); for (ETHEntityList::iterator iter = entityList.begin(); iter != iEnd; ++iter) { ETHSpriteEntity *pEntity = *iter; if (pEntity->GetEntityName() == name) { outVector.push_back(pEntity); } } } }