void AttachSkySphere(SkySpherePtr p){ if (mSkySphere) mSkySphere->OnDetachedFromScene(mSelfPtr.lock()); mSkySphere = p; if (mSkySphere){ mSkySphere->OnAttachedToScene(mSelfPtr.lock()); } }
bool AttachSpatialObject(SpatialSceneObjectPtr pSpatialObject){ if (!ValueExistsInVector(mSpatialObjects, pSpatialObject)){ mSpatialObjects.push_back(pSpatialObject); pSpatialObject->OnAttachedToScene(mSelfPtr.lock()); return true; } return false; }
PointLightPtr CreatePointLight(const Vec3& pos, Real range, const Vec3& color, Real intensity, Real lifeTime, bool manualDeletion) { auto scene = mScene.lock(); if (!scene){ Logger::Log(FB_ERROR_LOG_ARG, "No scene"); return 0; } auto newLight = PointLight::Create(scene, pos, range, color, intensity, lifeTime, manualDeletion); mPointLights.push_back(newLight); return newLight; }
bool AttachObject(SceneObjectPtr pObject){ if (pObject->GetType() == SceneObjectType::SkySphere){ Logger::Log(FB_ERROR_LOG_ARG, "You cannot attach sky sphere as an object. Use AttachSkySpherer function instead."); return false; } if (!ValueExistsInVector(mObjects, pObject)){ mObjects.push_back(pObject); pObject->OnAttachedToScene(mSelfPtr.lock()); return true; } return false; }
bool DetachSpatialObject(SpatialSceneObject* pSpatialObject){ bool deletedAny = false; for (auto it = mSpatialObjects.begin(); it != mSpatialObjects.end(); /**/){ if (it->lock().get() == pSpatialObject){ it = mSpatialObjects.erase(it); deletedAny = true; } else{ ++it; } } if (deletedAny) { pSpatialObject->OnDetachedFromScene(mSelfPtr.lock()); } return deletedAny; }
ScenePtr CreateScene(const char* name){ if (!ValidCStringLength(name)){ Logger::Log(FB_ERROR_LOG_ARG, "invalid arg"); return 0; } auto it = mScenes.find(name); if (it != mScenes.end()){ auto scene = it->second.lock(); if (scene) return scene; } auto scene = Scene::Create(name); mScenes[name] = scene; if (mMainScene.expired()) mMainScene = scene; return scene; }
bool InterestManager::CheckRelevance(UserConnectionPtr conn, Entity* changed_entity, SceneWeakPtr scene_, bool headless) { PROFILE(Interest_Management); ScenePtr scene = scene_.lock(); if (!scene) return true; EC_Placeable *entity_location = changed_entity->GetComponent<EC_Placeable>().get(); if(!conn->syncState->locationInitialized || !entity_location) //If the client hasn't informed the server about the orientation yet, do not proceed return true; bool accepted = false; //By default, we assume that the update will be rejected Quat client_orientation = conn->syncState->clientOrientation.Normalized(); params_.client_position = conn->syncState->clientLocation; //Client location vector params_.entity_position = entity_location->transform.Get().pos; //Entitys location vector float3 d = params_.client_position - params_.entity_position; float3 v = params_.entity_position - params_.client_position; //Calculate the vector between the player and the changed entity by substracting their location vectors float3 f = client_orientation.Mul(scene->ForwardVector()); //Calculate the forward vector of the client params_.headless = headless; params_.dot = v.Dot(f); //Finally the dot product is calculated so we know if the entity is in front of the player or not params_.distance = d.LengthSq(); params_.scene = scene; params_.changed_entity = changed_entity; params_.connection = conn; params_.relAccepted = false; if(activeFilter_ != 0) accepted = activeFilter_->Filter(params_); if(accepted) { UpdateLastUpdatedEntity(params_.connection, params_.changed_entity->Id()); return true; } else return false; }
void Scene::Linkage::setLeaf(const ScenePtr& root, SceneWeakPtr& newLeaf, bool left) { ScenePtr target = root; while (true) { (left ? target->linkage.leftLeaf : target->linkage.rightLeaf) = newLeaf; if (newLeaf.expired()) { newLeaf = target; } if (target->linkage.hasParent() && (left ? target->linkage.getParent()->linkage.getFirstChild() : target->linkage.getParent()->linkage.getLastChild()) == target) { target = target->linkage.getParent(); } else { break; } } }
void DetachSkySphere(){ if (mSkySphere){ mSkySphere->OnDetachedFromScene(mSelfPtr.lock()); mSkySphere = 0; } }
ScenePtr GetMainScene() const{ return mMainScene.lock(); }