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

Method update

source/frontend/StarChatBubbleManager.cpp:88–128  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88void ChatBubbleManager::update(float dt, WorldClientPtr world) {
89 m_bubbles.forEach([this, dt, &world](BubbleState<Bubble>& bubbleState, Bubble& bubble) {
90 bubble.age += dt;
91 if (auto entity = world->get<ChattyEntity>(bubble.entity)) {
92 bubble.onscreen = m_camera.worldGeometry().rectIntersectsRect(
93 m_camera.worldScreenRect(), entity->metaBoundBox().translated(entity->position()));
94 bubbleState.idealDestination = m_camera.worldToScreen(entity->mouthPosition() + m_bubbleOffset);
95 }
96 });
97
98 for (auto& portraitBubble : m_portraitBubbles) {
99 portraitBubble.age += dt;
100 if (auto entity = world->entity(portraitBubble.entity)) {
101 portraitBubble.onscreen = m_camera.worldGeometry().rectIntersectsRect(m_camera.worldScreenRect(), entity->metaBoundBox().translated(entity->position()));
102 if (auto chatter = as<ChattyEntity>(entity))
103 portraitBubble.position = chatter->mouthPosition();
104 else
105 portraitBubble.position = entity->position();
106 }
107 }
108
109 Map<EntityId, int> count;
110 filter(m_portraitBubbles, [&](PortraitBubble const& portraitBubble) -> bool {
111 count[portraitBubble.entity] += m_maxMessagePerEntity;
112 if (count[portraitBubble.entity] > m_maxMessagePerEntity)
113 return false;
114 if (world->get<ChattyEntity>(portraitBubble.entity))
115 return portraitBubble.age < m_portraitMaxAge;
116 return false;
117 });
118
119 m_bubbles.filter([&](BubbleState<Bubble> const&, Bubble const& bubble) -> bool {
120 if (++count[bubble.entity] > m_maxMessagePerEntity)
121 return false;
122 if (world->get<ChattyEntity>(bubble.entity))
123 return bubble.age < m_maxAge;
124 return false;
125 });
126
127 m_bubbles.update(dt);
128}
129
130uint8_t ChatBubbleManager::calcDistanceFadeAlpha(Vec2F bubbleScreenPosition, StoredFunctionPtr fadeFunction) const {
131 // first calculate bubble position as a factor, distance from center to edge

Callers

nothing calls this directly

Calls 12

filterFunction · 0.85
rectIntersectsRectMethod · 0.80
worldGeometryMethod · 0.80
worldScreenRectMethod · 0.80
worldToScreenMethod · 0.80
forEachMethod · 0.45
translatedMethod · 0.45
metaBoundBoxMethod · 0.45
positionMethod · 0.45
mouthPositionMethod · 0.45
entityMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected