void NoteCardManager::Update(f64 frametime) { if (!entity_create_pending_) return; // See if we have a potential entity to check if (new_entity_id_) { NoteCardModule::LogInfo("Checking new entity"); Scene::ScenePtr scene = framework_->GetDefaultWorldScene(); Scene::EntityPtr entity; if (scene) entity = scene->GetEntity(new_entity_id_); if (entity) { boost::shared_ptr<RexLogic::EC_NetworkPosition> netpos = entity->GetComponent<RexLogic::EC_NetworkPosition>(); if (netpos) { // See if error in position is small enough to be a match // Note: for some reason we can't trust the sim to give the Z position even remotely the same if ((fabs(netpos->position_.x - new_entity_pos_.x) < 0.001f) && (fabs(netpos->position_.y - new_entity_pos_.y) < 0.001f) && (fabs(netpos->position_.z - new_entity_pos_.z) < 1.0f)) { // Yes, it has to be that entity! entity_create_pending_ = false; // Create a new notecard EC to the entity and set its initial title, will cause sync to network entity->AddComponent(framework_->GetComponentManager()->CreateComponent(EC_NoteCard::TypeNameStatic())); boost::shared_ptr<EC_NoteCard> notecard = entity->GetComponent<EC_NoteCard>(); if (notecard) notecard->SetTitle(QApplication::translate("NoteCardManager", "New notecard").toStdString()); else NoteCardModule::LogError("Could not create notecard component to entity"); } else { NoteCardModule::LogInfo("Distance was too great"); std::cout << netpos->position_.x << " " << netpos->position_.y << " " << netpos->position_.z << std::endl; std::cout << "VS: " << new_entity_pos_.x << " " << new_entity_pos_.y << " " << new_entity_pos_.z << std::endl; } } else NoteCardModule::LogInfo("No networkposition EC"); } new_entity_id_ = 0; } // If didn't succeed yet, increment time and see if it's time to give up if (entity_create_pending_) { entity_wait_time_ += frametime; if (entity_wait_time_ >= entity_max_wait_time_) { entity_create_pending_ = false; NoteCardModule::LogWarning("Wait time expired, notecard entity was not created"); } } }
void Water::CreateWaterGeometry(float height) { // Here we assume that there is only one water in one scene (and it is ocean). if ( !GetActiveWater().expired()) RemoveWaterGeometry(); Scene::ScenePtr active_scene = owner_->GetFramework()->GetDefaultWorldScene(); Scene::EntityPtr entity = active_scene->CreateEntity(active_scene->GetNextFreeId()); entity->AddComponent(owner_->GetFramework()->GetComponentManager()->CreateComponent(EC_Water::NameStatic())); activeWaterComponent_ = entity->GetComponent<EC_Water>().get(); activeWaterComponent_->SetWaterHeight(height); activeWaterEntity_ = entity; emit WaterCreated(); }
void EnvironmentModule::CreateTerrain() { terrain_ = TerrainPtr(new Terrain(this)); Scene::ScenePtr scene = GetFramework()->GetDefaultWorldScene(); Scene::EntityPtr entity = scene->CreateEntity(GetFramework()->GetDefaultWorldScene()->GetNextFreeId()); entity->AddComponent(GetFramework()->GetComponentManager()->CreateComponent("EC_Terrain")); scene->EmitEntityCreated(entity); terrain_->FindCurrentlyActiveTerrain(); if ( environment_editor_ != 0 ) { environment_editor_->InitTerrainTabWindow(); environment_editor_->InitTerrainTextureTabWindow(); } }