| 93 | } |
| 94 | |
| 95 | void WirePane::renderImpl() { |
| 96 | if (!m_worldClient->inWorld()) |
| 97 | return; |
| 98 | |
| 99 | auto region = RectF(m_worldClient->clientWindow()); |
| 100 | |
| 101 | auto const& camera = m_worldPainter->camera(); |
| 102 | auto badWire = Color::rgbf(0.6f + (float)sin(Time::monotonicTime() * Constants::pi * 2.0) * 0.4f, 0.0f, 0.0f); |
| 103 | auto highWire = Color::Red; |
| 104 | auto lowWire = Color::Red.mix(Color::Black, 0.8f); |
| 105 | auto white = Color::White.toRgba(); |
| 106 | float phase = 0.5f + 0.5f * std::sin((double)Time::monotonicMilliseconds() / 100.0); |
| 107 | auto drawLineColor = Color::Red.mix(Color::White, phase); |
| 108 | |
| 109 | for (auto entity : m_worldClient->query<WireEntity>(region)) { |
| 110 | for (size_t i = 0; i < entity->nodeCount(WireDirection::Input); ++i) { |
| 111 | Vec2I position = entity->tilePosition() + entity->nodePosition({WireDirection::Input, i}); |
| 112 | if (!m_worldClient->isTileProtected(position)) { |
| 113 | context()->drawQuad("/interface/wires/inbound.png", |
| 114 | camera.worldToScreen(centerOfTile(position) - (m_inSize / 2.0f)), |
| 115 | camera.pixelRatio(), white); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | for (size_t i = 0; i < entity->nodeCount(WireDirection::Output); ++i) { |
| 120 | Vec2I position = entity->tilePosition() + entity->nodePosition({WireDirection::Output, i}); |
| 121 | if (!m_worldClient->isTileProtected(position)) { |
| 122 | context()->drawQuad("/interface/wires/outbound.png", |
| 123 | camera.worldToScreen(centerOfTile(position) - (m_outSize / 2.0f)), |
| 124 | camera.pixelRatio(), white); |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | HashSet<pair<WireConnection, WireConnection>> visitedConnections; |
| 130 | for (auto entity : m_worldClient->query<WireEntity>(region)) { |
| 131 | for (size_t i = 0; i < entity->nodeCount(WireDirection::Input); ++i) { |
| 132 | Vec2I tilePosition = entity->tilePosition(); |
| 133 | Vec2I inPosition = tilePosition + entity->nodePosition({WireDirection::Input, i}); |
| 134 | |
| 135 | for (auto const& connection : entity->connectionsForNode({WireDirection::Input, i})) { |
| 136 | visitedConnections.add({{tilePosition, i}, connection}); |
| 137 | |
| 138 | auto wire = lowWire; |
| 139 | Vec2I outPosition = connection.entityLocation; |
| 140 | if (auto sourceEntity = m_worldClient->atTile<WireEntity>(connection.entityLocation).get(0)) { |
| 141 | if (connection.nodeIndex < sourceEntity->nodeCount(WireDirection::Output)) { |
| 142 | outPosition += sourceEntity->nodePosition({WireDirection::Output, connection.nodeIndex}); |
| 143 | if (sourceEntity->nodeState(WireNode{WireDirection::Output, connection.nodeIndex})) |
| 144 | wire = highWire; |
| 145 | } else { |
| 146 | wire = badWire; |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | renderWire(centerOfTile(inPosition), centerOfTile(outPosition), wire); |
| 151 | } |
| 152 | } |
nothing calls this directly
no test coverage detected