void SceneSyncState::AddPendingEntity(entity_id_t id)
{
    if (!isServer_)
        return;

    if (scene_.expired())
        return;
    ScenePtr scenePtr = scene_.lock();
    if (!scenePtr.get())
    {
        LogError("SceneSyncState::FillPendingComponents(id): Scene is null!");
        return;
    }

    EntityPtr entityPtr = scenePtr->GetEntity(id);
    if (!entityPtr.get())
    {
        LogError("SceneSyncState::FillPendingComponents(id): Entity is null, cannot fill components!");
        return;
    }
    if (entityPtr->Components().empty())
        return;
        
    if (!HasPendingEntity(id))
        pendingEntities_.push_back(id);
}
Example #2
0
void ECBrowser::RemoveEntity(const EntityPtr &entity)
{
    if (!entity)
        return;

    EntityMap::iterator iter = entities_.find(entity->Id());
    if (iter != entities_.end())
    {
        Entity *entity = iter->second.lock().get();
        if (entity)
        {
            disconnect(entity, SIGNAL(ComponentAdded(IComponent*, AttributeChange::Type)), this,
                SLOT(OnComponentAdded(IComponent*, AttributeChange::Type)));
            disconnect(entity, SIGNAL(ComponentRemoved(IComponent*, AttributeChange::Type)), this,
                SLOT(OnComponentRemoved(IComponent*, AttributeChange::Type)));

            const Entity::ComponentMap components = entity->Components();
            for (Entity::ComponentMap::const_iterator i = components.begin(); i != components.end(); ++i)
                RemoveComponentFromGroup(i->second);
        }

        entities_.erase(iter);
    }
Example #3
0
void SceneHudPanel::UpdatePanel(float frametime, const SharedPtr<Urho3D::UIElement> &widget)
{
    if (!limiter_.ShouldUpdate(frametime))
        return;

    Text *sceneText = dynamic_cast<Text*>(widget.Get());
    if (!sceneText || !framework_->Renderer())
        return;

    Scene *scene = framework_->Renderer()->MainCameraScene();
    if (!scene)
        return;
    
    String str;

    SceneInfo info;
    auto entities = scene->Entities();
    info.ents = entities.Size();
    for(auto entIter = entities.Begin(); entIter != entities.End(); ++entIter)
    {
        const EntityPtr ent = entIter->second_;
        if (ent->Parent())
            info.entsParented++;
        else
            info.entsRoot++;

        if (ent->IsLocal())
            info.entsLocal++;
        if (ent->IsReplicated())
            info.entsReplicated++;
        if (ent->IsTemporary())
            info.entsTemporary++;

        String group = ent->Group().Trimmed();
        if (!group.Empty())
        {
            info.entGroups[group]++;
            InsertAlpha(info.groups, group);

            if ((int)group.Length() > info.pad)
                info.pad = group.Length() + 2;
        }

        auto components = ent->Components();
        info.comps += components.Size();
        for(auto compIter = components.Begin(); compIter != components.End(); ++compIter)
        {
            auto comp = compIter->second_;
            String type = comp->TypeName();
            info.compTypes[type]++;
            InsertAlpha(info.types, type);

            if (comp->IsLocal())
                info.compsLocal++;
            if (comp->IsReplicated())
                info.compsReplicated++;
            if (comp->IsTemporary())
                info.compsTemporary++;

            if ((int)type.Length() > info.pad)
                info.pad = type.Length() + 2;
        }
        if (components.Empty())
            info.entsEmpty++;
    }

    str.AppendWithFormat("%s   %u\n", PadString("Entities", info.pad).CString(), info.ents);
    str.AppendWithFormat("  %s %u\n", PadString("Root", info.pad).CString(), info.entsRoot);
    str.AppendWithFormat("  %s %u\n", PadString("Parented", info.pad).CString(), info.entsParented);
    str.AppendWithFormat("  %s %u\n", PadString("Empty", info.pad).CString(), info.entsEmpty);
    str.AppendWithFormat("  %s %u\n", PadString("Replicated", info.pad).CString(), info.entsReplicated);
    str.AppendWithFormat("  %s %u\n", PadString("Local", info.pad).CString(), info.entsLocal);
    str.AppendWithFormat("  %s %u\n\n", PadString("Temporary", info.pad).CString(), info.entsTemporary);

    if (!info.groups.Empty())
    {
        str.AppendWithFormat("%s   %u\n", PadString("Entity Groups", info.pad).CString(), info.groups.Size());
        foreach(auto &group, info.groups)
        {
            uint num = info.entGroups[group];
            str.AppendWithFormat("  %s %u\n", PadString(group, info.pad).CString(), num);
        }
        str.Append("\n");
    }