示例#1
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");
    }