#pragma once #include #include #include #include #include #include #include namespace mbgl { class SymbolBucket; class SymbolInstance; class UpdateParameters; enum class PlacedSymbolOrientation : bool; class OpacityState { public: OpacityState(bool placed, bool skipFade); OpacityState(const OpacityState& prevOpacityState, float increment, bool placed); bool isHidden() const; float opacity; bool placed; }; class JointOpacityState { public: JointOpacityState(bool placedIcon, bool placedText, bool skipFade); JointOpacityState(const JointOpacityState& prevOpacityState, float increment, bool placedIcon, bool placedText); bool isHidden() const; OpacityState icon; OpacityState text; }; class VariableOffset { public: std::array offset; float width; float height; style::TextVariableAnchorType anchor; float textBoxScale; optional prevAnchor; }; class JointPlacement { public: JointPlacement(bool text_, bool icon_, bool skipFade_) : text(text_), icon(icon_), skipFade(skipFade_) {} const bool text; const bool icon; // skipFade = outside viewport, but within CollisionIndex::viewportPadding px of the edge // Because these symbols aren't onscreen yet, we can skip the "fade in" animation, // and if a subsequent viewport change brings them into view, they'll be fully // visible right away. const bool skipFade; }; struct RetainedQueryData { uint32_t bucketInstanceId; std::shared_ptr featureIndex; OverscaledTileID tileID; mutable FeatureSortOrder featureSortOrder; RetainedQueryData(uint32_t bucketInstanceId_, std::shared_ptr featureIndex_, OverscaledTileID tileID_) : bucketInstanceId(bucketInstanceId_), featureIndex(std::move(featureIndex_)), tileID(tileID_) {} }; class CollisionGroups { public: using Predicate = std::function; using CollisionGroup = std::pair>; CollisionGroups(const bool crossSourceCollisions_) : maxGroupID(0) , crossSourceCollisions(crossSourceCollisions_) {} const CollisionGroup& get(const std::string& sourceID); private: std::map collisionGroups; uint16_t maxGroupID; bool crossSourceCollisions; }; class BucketPlacementParameters { public: const RenderTile& tile; std::string sourceId; std::shared_ptr featureIndex; }; class Placement; class PlacementController { public: PlacementController(); void setPlacement(Immutable); const Immutable& getPlacement() const { return placement; } void setPlacementStale() { stale = true; } bool placementIsRecent(TimePoint now, const float zoom, optional maximumDuration = nullopt) const; bool hasTransitions(TimePoint now) const; private: Immutable placement; bool stale = false; }; class Placement { public: Placement(std::shared_ptr, optional> prevPlacement = nullopt); Placement(); void placeLayer(const RenderLayer&); void commit(); void updateLayerBuckets(const RenderLayer&, const TransformState&, bool updateOpacities) const; float symbolFadeChange(TimePoint now) const; bool hasTransitions(TimePoint now) const; bool transitionsEnabled() const; const CollisionIndex& getCollisionIndex() const; TimePoint getCommitTime() const { return commitTime; } Duration getUpdatePeriod(const float zoom) const; float zoomAdjustment(const float zoom) const; const RetainedQueryData& getQueryData(uint32_t bucketInstanceId) const; private: friend SymbolBucket; void placeBucket(const SymbolBucket&, const BucketPlacementParameters&, std::set& seenCrossTileIDs); // Returns `true` if bucket vertices were updated; returns `false` otherwise. bool updateBucketDynamicVertices(SymbolBucket&, const TransformState&, const RenderTile& tile) const; void updateBucketOpacities(SymbolBucket&, const TransformState&, std::set&) const; void markUsedJustification(SymbolBucket&, style::TextVariableAnchorType, const SymbolInstance&, style::TextWritingModeType orientation) const; void markUsedOrientation(SymbolBucket&, style::TextWritingModeType, const SymbolInstance&) const; const Placement* getPrevPlacement() const { return prevPlacement ? prevPlacement->get() : nullptr; } std::shared_ptr updateParameters; CollisionIndex collisionIndex; MapMode mapMode = MapMode::Static; style::TransitionOptions transitionOptions; TimePoint fadeStartTime; TimePoint commitTime; float placementZoom = 0.0f; float prevZoomAdjustment = 0.0f; std::unordered_map placements; std::unordered_map opacities; std::unordered_map variableOffsets; std::unordered_map placedOrientations; std::unordered_map retainedQueryData; CollisionGroups collisionGroups; mutable optional> prevPlacement; bool showCollisionBoxes = false; // Used for debug purposes. std::unordered_map> collisionCircles; }; } // namespace mbgl