MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / drawablesWithZLevel

Method drawablesWithZLevel

source/game/StarNetworkedAnimator.cpp:591–713  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

589}
590
591List<pair<Drawable, float>> NetworkedAnimator::drawablesWithZLevel(Vec2F const& position) const {
592 size_t partCount = m_animatedParts.constParts().size();
593 if (!partCount)
594 return {};
595
596 List<Directives> baseProcessingDirectives = { m_processingDirectives.get() };
597 for (auto& pair : m_effects) {
598 auto const& effectState = pair.second;
599
600 if (effectState.enabled.get()) {
601 auto const& effect = m_effects.get(pair.first);
602 if (effect.type == "flash") {
603 if (effectState.timer > effect.time / 2) {
604 baseProcessingDirectives.append(effect.directives);
605 }
606 } else if (effect.type == "directive") {
607 baseProcessingDirectives.append(effect.directives);
608 } else {
609 throw NetworkedAnimatorException(strf("No such NetworkedAnimator effect type '{}'", effect.type));
610 }
611 }
612 }
613
614 List<tuple<AnimatedPartSet::ActivePartInformation const*, String const*, float>> parts;
615 parts.reserve(partCount);
616 m_animatedParts.forEachActivePart([&](String const& partName, AnimatedPartSet::ActivePartInformation const& activePart) {
617 Maybe<float> maybeZLevel;
618 if (m_flipped.get()) {
619 if (auto maybeFlipped = activePart.properties.value("flippedZLevel").optFloat())
620 maybeZLevel = *maybeFlipped;
621 }
622 if (!maybeZLevel)
623 maybeZLevel = activePart.properties.value("zLevel").optFloat();
624
625 parts.append(make_tuple(&activePart, &partName, maybeZLevel.value(0.0f)));
626 });
627
628 sort(parts, [](auto const& a, auto const& b) { return get<2>(a) < get<2>(b); });
629
630 List<pair<Drawable, float>> drawables;
631 drawables.reserve(partCount);
632 for (auto& entry : parts) {
633 auto& activePart = *get<0>(entry);
634 auto& partName = *get<1>(entry);
635 // Make sure we don't copy the original image
636 String fallback = "";
637 Json jImage = activePart.properties.value("image", {});
638 String const& image = jImage.isType(Json::Type::String) ? *jImage.stringPtr() : fallback;
639
640 bool centered = activePart.properties.value("centered").optBool().value(true);
641 bool fullbright = activePart.properties.value("fullbright").optBool().value(false);
642
643 size_t originalDirectivesSize = baseProcessingDirectives.size();
644 if (auto directives = activePart.properties.value("processingDirectives").optString()) {
645 baseProcessingDirectives.append(*directives);
646 }
647
648 Maybe<unsigned> frame;

Callers 3

renderMethod · 0.80
backDrawablesMethod · 0.80
frontDrawablesMethod · 0.80

Calls 15

strfFunction · 0.85
toStringFunction · 0.85
StringViewClass · 0.85
hashOfFunction · 0.85
forEachActivePartMethod · 0.80
optFloatMethod · 0.80
optBoolMethod · 0.80
optStringMethod · 0.80
maybeLookupTagsViewMethod · 0.80
addDirectivesMethod · 0.80
sortFunction · 0.50
sizeMethod · 0.45

Tested by

no test coverage detected