Wire rendering improvements

This commit is contained in:
Kae 2023-07-05 21:33:15 +10:00
parent 58678bfe9d
commit f75d1f0b5a
5 changed files with 36 additions and 23 deletions

View File

@ -0,0 +1,13 @@
{
"wireConfig" : {
"innerBrightnessScale" : 20,
"firstStripeThickness" : 0.6,
"secondStripeThickness" : 0.2,
"minWireWidth" : 0.5,
"maxWireWidth" : 1,
"maxWireJitter" : 0.06,
"minWireJitter" : 0.0,
"minWireTrans" : 0.1,
"maxWireTrans" : 0.4
}
}

View File

@ -22,9 +22,9 @@ WirePane::WirePane(WorldClientPtr worldClient, PlayerPtr player, WorldPainterPtr
GuiReader reader;
reader.construct(assets->json("/interface/wires/wires.config:gui"), this);
m_insize = Vec2F(context()->textureSize("/interface/wires/inbound.png")) / TilePixels;
m_outsize = Vec2F(context()->textureSize("/interface/wires/outbound.png")) / TilePixels;
m_nodesize = Vec2F(1.8f, 1.8f);
m_inSize = Vec2F(context()->textureSize("/interface/wires/inbound.png")) / TilePixels;
m_outSize = Vec2F(context()->textureSize("/interface/wires/outbound.png")) / TilePixels;
m_nodeSize = Vec2F(1.8f, 1.8f);
setTitle({}, "", "Wire you looking at me like that?");
disableScissoring();
@ -76,13 +76,13 @@ void WirePane::renderWire(Vec2F from, Vec2F to, Color baseColor) {
float m_secondStripeThickness;
auto assets = Root::singleton().assets();
JsonObject config = assets->json("/player.config:beamGunConfig").toObject();
m_minBeamWidth = config.get("minBeamWidth").toFloat();
m_maxBeamWidth = config.get("maxBeamWidth").toFloat();
m_beamWidthDev = config.value("beamWidthDev", (m_maxBeamWidth - m_minBeamWidth) / 3).toFloat();
m_minBeamTrans = config.get("minBeamTrans").toFloat();
m_maxBeamTrans = config.get("maxBeamTrans").toFloat();
m_beamTransDev = config.value("beamTransDev", (m_maxBeamTrans - m_minBeamTrans) / 3).toFloat();
JsonObject config = assets->json("/player.config:wireConfig").toObject();
m_minBeamWidth = config.get("minWireWidth").toFloat();
m_maxBeamWidth = config.get("maxWireWidth").toFloat();
m_beamWidthDev = config.value("wireWidthDev", (m_maxBeamWidth - m_minBeamWidth) / 3).toFloat();
m_minBeamTrans = config.get("minWireTrans").toFloat();
m_maxBeamTrans = config.get("maxWireTrans").toFloat();
m_beamTransDev = config.value("wireTransDev", (m_maxBeamTrans - m_minBeamTrans) / 3).toFloat();
m_innerBrightnessScale = config.get("innerBrightnessScale").toFloat();
m_firstStripeThickness = config.get("firstStripeThickness").toFloat();
m_secondStripeThickness = config.get("secondStripeThickness").toFloat();
@ -121,7 +121,7 @@ void WirePane::renderImpl() {
Vec2I position = entity->tilePosition() + entity->nodePosition({WireDirection::Input, i});
if (!m_worldClient->isTileProtected(position)) {
context()->drawQuad("/interface/wires/inbound.png",
camera.worldToScreen(centerOfTile(position) - (m_insize / 2.0f)),
camera.worldToScreen(centerOfTile(position) - (m_inSize / 2.0f)),
camera.pixelRatio(), white);
}
}
@ -130,7 +130,7 @@ void WirePane::renderImpl() {
Vec2I position = entity->tilePosition() + entity->nodePosition({WireDirection::Output, i});
if (!m_worldClient->isTileProtected(position)) {
context()->drawQuad("/interface/wires/outbound.png",
camera.worldToScreen(centerOfTile(position) - (m_outsize / 2.0f)),
camera.worldToScreen(centerOfTile(position) - (m_outSize / 2.0f)),
camera.pixelRatio(), white);
}
}
@ -216,7 +216,7 @@ WireConnector::SwingResult WirePane::swing(WorldGeometry const& geometry, Vec2F
float bestDist = 10000;
for (auto entity : m_worldClient->query<WireEntity>(bounds)) {
for (size_t i = 0; i < entity->nodeCount(WireDirection::Input); ++i) {
RectF inbounds = RectF::withSize(centerOfTile(entity->tilePosition() + entity->nodePosition({WireDirection::Input, i})) - (m_nodesize / 2.0f), m_nodesize);
RectF inbounds = RectF::withSize(centerOfTile(entity->tilePosition() + entity->nodePosition({WireDirection::Input, i})) - (m_nodeSize / 2.0f), m_nodeSize);
if (geometry.rectContains(inbounds, pos)) {
if (!matchNode) {
matchNode = WireConnection{entity->tilePosition(), i};
@ -234,7 +234,7 @@ WireConnector::SwingResult WirePane::swing(WorldGeometry const& geometry, Vec2F
}
for (size_t i = 0; i < entity->nodeCount(WireDirection::Output); ++i) {
RectF outbounds = RectF::withSize(centerOfTile(entity->tilePosition() + entity->nodePosition({WireDirection::Output, i})) - (m_nodesize / 2.0f), m_nodesize);
RectF outbounds = RectF::withSize(centerOfTile(entity->tilePosition() + entity->nodePosition({WireDirection::Output, i})) - (m_nodeSize / 2.0f), m_nodeSize);
if (geometry.rectContains(outbounds, pos)) {
if (!matchNode) {
matchNode = WireConnection{entity->tilePosition(), i};
@ -281,7 +281,7 @@ WireConnector::SwingResult WirePane::swing(WorldGeometry const& geometry, Vec2F
float bestDist = 10000;
for (auto entity : m_worldClient->query<WireEntity>(bounds)) {
for (size_t i = 0; i < entity->nodeCount(WireDirection::Input); ++i) {
RectF inbounds = RectF::withSize(centerOfTile(entity->tilePosition() + entity->nodePosition({WireDirection::Input, i})) - (m_nodesize / 2.0f), m_nodesize);
RectF inbounds = RectF::withSize(centerOfTile(entity->tilePosition() + entity->nodePosition({WireDirection::Input, i})) - (m_nodeSize / 2.0f), m_nodeSize);
if (geometry.rectContains(inbounds, pos) && entity->connectionsForNode({WireDirection::Input, i}).size() > 0) {
if (!matchNode) {
matchPosition = entity->tilePosition();
@ -299,7 +299,7 @@ WireConnector::SwingResult WirePane::swing(WorldGeometry const& geometry, Vec2F
}
for (size_t i = 0; i < entity->nodeCount(WireDirection::Output); ++i) {
RectF outbounds = RectF::withSize(centerOfTile(entity->tilePosition() + entity->nodePosition({WireDirection::Output, i})) - (m_nodesize / 2.0f), m_nodesize);
RectF outbounds = RectF::withSize(centerOfTile(entity->tilePosition() + entity->nodePosition({WireDirection::Output, i})) - (m_nodeSize / 2.0f), m_nodeSize);
if (geometry.rectContains(outbounds, pos) && entity->connectionsForNode({WireDirection::Output, i}).size() > 0) {
if (!matchNode) {
matchPosition = entity->tilePosition();

View File

@ -38,9 +38,9 @@ private:
WireDirection m_sourceDirection;
WireConnection m_sourceConnector;
Vec2F m_insize;
Vec2F m_outsize;
Vec2F m_nodesize;
Vec2F m_inSize;
Vec2F m_outSize;
Vec2F m_nodeSize;
};
}

View File

@ -147,7 +147,7 @@ void GuiContext::drawQuad(AssetPath const& texName, RectF const& screenCoords, V
renderer()->immediatePrimitives().emplace_back(std::in_place_type_t<RenderQuad>(), assetTextureGroup()->loadTexture(texName), screenCoords, color, 0.0f);
}
void GuiContext::drawQuad(AssetPath const& texName, Vec2F const& screenPos, int pixelRatio, Vec4B const& color) {
void GuiContext::drawQuad(AssetPath const& texName, Vec2F const& screenPos, float pixelRatio, Vec4B const& color) {
renderer()->immediatePrimitives().emplace_back(std::in_place_type_t<RenderQuad>(), assetTextureGroup()->loadTexture(texName), screenPos, pixelRatio, color, 0.0f);
}
@ -160,7 +160,7 @@ void GuiContext::drawQuad(AssetPath const& texName, RectF const& texCoords, Rect
color, 0.0f);
}
void GuiContext::drawDrawable(Drawable drawable, Vec2F const& screenPos, int pixelRatio, Vec4B const& color) {
void GuiContext::drawDrawable(Drawable drawable, Vec2F const& screenPos, float pixelRatio, Vec4B const& color) {
if (drawable.isLine())
drawable.linePart().width *= pixelRatio;

View File

@ -66,10 +66,10 @@ public:
void drawQuad(RectF const& screenCoords, Vec4B const& color = Vec4B::filled(255));
void drawQuad(AssetPath const& texName, RectF const& screenCoords, Vec4B const& color = Vec4B::filled(255));
void drawQuad(AssetPath const& texName, Vec2F const& screenPos, int pixelRatio, Vec4B const& color = Vec4B::filled(255));
void drawQuad(AssetPath const& texName, Vec2F const& screenPos, float pixelRatio, Vec4B const& color = Vec4B::filled(255));
void drawQuad(AssetPath const& texName, RectF const& texCoords, RectF const& screenCoords, Vec4B const& color = Vec4B::filled(255));
void drawDrawable(Drawable drawable, Vec2F const& screenPos, int pixelRatio, Vec4B const& color = Vec4B::filled(255));
void drawDrawable(Drawable drawable, Vec2F const& screenPos, float pixelRatio, Vec4B const& color = Vec4B::filled(255));
void drawLine(Vec2F const& begin, Vec2F const end, Vec4B const& color, float lineWidth = 1);
void drawPolyLines(PolyF const& poly, Vec4B const& color, float lineWidth = 1);