Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 3D layer offset as style property #378

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/SSVOpenHexagon/Core/HexagonGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,7 @@ class HexagonGame
void drawTrailParticles();
void drawSwapParticles();
void drawImguiLuaConsole();
void drawMainLayer(const auto getRenderStates);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True I tried implementing this in another way initially but ended up not using it and forgot to remove it from the header.


// Data-related methods
void setLevelData(const LevelData& mLevelData, bool mMusicFirstPlay);
Expand Down Expand Up @@ -430,6 +431,9 @@ class HexagonGame
Utils::FastVertexVectorTris pivotQuads;
Utils::FastVertexVectorTris playerTris;
Utils::FastVertexVectorTris capTris;
Utils::FastVertexVectorTris wallQuads3DTop;
Utils::FastVertexVectorTris pivotQuads3DTop;
Utils::FastVertexVectorTris playerTris3DTop;
Utils::FastVertexVectorTris wallQuads3D;
Utils::FastVertexVectorTris pivotQuads3D;
Utils::FastVertexVectorTris playerTris3D;
Expand Down
3 changes: 3 additions & 0 deletions include/SSVOpenHexagon/Data/StyleData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ class StyleData
float maxSwapTime{};

float _3dDepth{};
float _3dLayerOffset{};
bool _3dAlphaMirror{};
bool _3dMainOnTop{};
float _3dSkew{};
float _3dSpacing{};
float _3dDarkenMult{};
Expand Down
96 changes: 77 additions & 19 deletions src/SSVOpenHexagon/Core/HGGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,9 @@ void HexagonGame::draw()

window->setView(backgroundCamera->apply());

wallQuads3DTop.clear();
pivotQuads3DTop.clear();
playerTris3DTop.clear();
wallQuads3D.clear();
pivotQuads3D.clear();
playerTris3D.clear();
Expand Down Expand Up @@ -147,14 +150,27 @@ void HexagonGame::draw()

if(Config::get3D())
{
const float depth(styleData._3dDepth);
const float aboveMain(-styleData._3dLayerOffset - 1);
const bool renderAbove(aboveMain > 0 && !styleData._3dMainOnTop);
const float layerOffset(renderAbove ? -1.f : styleData._3dLayerOffset);
const float depth(styleData._3dDepth - renderAbove * aboveMain);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments would be appreciated here, I don't find this code obvious, especially what aboveMain means and the role of layerOffset. Also maybe rename the variables a bit to be more meaningful, like mustRender3DAboveMain instead of renderAbove?

const std::size_t numWallQuads(wallQuads.size());
const std::size_t numPivotQuads(pivotQuads.size());
const std::size_t numPlayerTris(playerTris.size());

wallQuads3D.reserve(numWallQuads * depth);
pivotQuads3D.reserve(numPivotQuads * depth);
playerTris3D.reserve(numPlayerTris * depth);
if(renderAbove)
{
wallQuads3DTop.reserve(numWallQuads * aboveMain);
pivotQuads3DTop.reserve(numPivotQuads * aboveMain);
playerTris3DTop.reserve(numPlayerTris * aboveMain);
}

if(depth > 0)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a comment explaining why this only happens when depth > 0.

{
wallQuads3D.reserve(numWallQuads * depth);
pivotQuads3D.reserve(numPivotQuads * depth);
playerTris3D.reserve(numPlayerTris * depth);
}

const float pulse3D{Config::getNoPulse() ? 1.f : status.pulse3D};
const float effect{
Expand All @@ -175,20 +191,34 @@ void HexagonGame::draw()
playerTris3D.unsafe_emplace_other(playerTris);
}

if(renderAbove)
{
for(std::size_t i = 0; i < aboveMain; ++i)
{
wallQuads3DTop.unsafe_emplace_other(wallQuads);
pivotQuads3DTop.unsafe_emplace_other(pivotQuads);
playerTris3DTop.unsafe_emplace_other(playerTris);
}
}

const auto adjustAlpha = [&](sf::Color& c, const float i)
{
SSVOH_ASSERT(styleData._3dAlphaMult != 0.f);

const float newAlpha =
(static_cast<float>(c.a) / styleData._3dAlphaMult) -
i * styleData._3dAlphaFalloff;
(styleData._3dAlphaMirror ? std::abs(i + 1) : i) *
styleData._3dAlphaFalloff;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, this expression is pretty complicated. Either comments or maybe splitting it up would help.


c.a = Utils::componentClamp(newAlpha);
};

for(int j(0); j < static_cast<int>(depth); ++j)
for(int j(0);
j < static_cast<int>(renderAbove ? depth + aboveMain : depth); ++j)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extract static_cast<int>(renderAbove ? depth + aboveMain : depth) to a const variable outside of the loop.

{
const float i(depth - j - 1);
const bool renderingAbove(j >= depth && renderAbove);
const float jAdj(j - depth * renderingAbove * (depth >= 0));
const float i(depth - j - 1 + layerOffset);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, especially confused about jAdj.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's a bit confusing because i didn't want to split it into two loops, it's so it can switch to the next vertex container in the same loop. It's probably a better idea to just split it into two loops.


const float offset(styleData._3dSpacing *
(float(i + 1.f) * styleData._3dPerspectiveMult) *
Expand All @@ -212,11 +242,19 @@ void HexagonGame::draw()
adjustAlpha(overrideColor, i);

// Draw pivot layers
for(std::size_t k = j * numPivotQuads; k < (j + 1) * numPivotQuads;
++k)
for(std::size_t k = jAdj * numPivotQuads;
k < (jAdj + 1) * numPivotQuads; ++k)
{
pivotQuads3D[k].position += newPos;
pivotQuads3D[k].color = overrideColor;
if(renderingAbove)
{
pivotQuads3DTop[k].position += newPos;
pivotQuads3DTop[k].color = overrideColor;
}
else
{
pivotQuads3D[k].position += newPos;
pivotQuads3D[k].color = overrideColor;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull the if statement outside of the loop, so that we have if (renderAbove) { for{...} } else { for{...} }.

}

if(styleData.get3DOverrideColor() == styleData.getMainColor())
Expand All @@ -228,11 +266,19 @@ void HexagonGame::draw()
}

// Draw wall layers
for(std::size_t k = j * numWallQuads; k < (j + 1) * numWallQuads;
++k)
for(std::size_t k = jAdj * numWallQuads;
k < (jAdj + 1) * numWallQuads; ++k)
{
wallQuads3D[k].position += newPos;
wallQuads3D[k].color = overrideColor;
if(renderingAbove)
{
wallQuads3DTop[k].position += newPos;
wallQuads3DTop[k].color = overrideColor;
}
else
{
wallQuads3D[k].position += newPos;
wallQuads3D[k].color = overrideColor;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull the if statement outside of the loop, so that we have if (renderAbove) { for{...} } else { for{...} }.

}

// Apply player color if no 3D override is present.
Expand All @@ -245,11 +291,19 @@ void HexagonGame::draw()
}

// Draw player layers
for(std::size_t k = j * numPlayerTris; k < (j + 1) * numPlayerTris;
++k)
for(std::size_t k = jAdj * numPlayerTris;
k < (jAdj + 1) * numPlayerTris; ++k)
{
playerTris3D[k].position += newPos;
playerTris3D[k].color = overrideColor;
if(renderingAbove)
{
playerTris3DTop[k].position += newPos;
playerTris3DTop[k].color = overrideColor;
}
else
{
playerTris3D[k].position += newPos;
playerTris3D[k].color = overrideColor;
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull the if statement outside of the loop, so that we have if (renderAbove) { for{...} } else { for{...} }.

}
}
}
Expand All @@ -273,6 +327,10 @@ void HexagonGame::draw()
render(pivotQuads, getRenderStates(RenderStage::PivotQuads));
render(playerTris, getRenderStates(RenderStage::PlayerTris));

render(wallQuads3DTop, getRenderStates(RenderStage::WallQuads3D));
render(pivotQuads3DTop, getRenderStates(RenderStage::PivotQuads3D));
render(playerTris3DTop, getRenderStates(RenderStage::PlayerTris3D));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this also be wrapped in if (renderAbove) { ... }?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes


window->setView(overlayCamera->apply());

drawParticles();
Expand Down
15 changes: 15 additions & 0 deletions src/SSVOpenHexagon/Core/LuaScripting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,21 @@ static void initStyleControl(Lua::LuaContext& lua, StyleData& styleData)

"Sets the amount of 3D layers in a style to `$0`.");

sdVar("3dLayerOffset", &StyleData::_3dLayerOffset,
"Gets the current offset of the 3D layers compared to where they usually are in layers.",

"Sets the current offset of the 3D layers to `$0`.");

sdVar("3dAlphaMirror", &StyleData::_3dAlphaMirror,
"Gets if the alpha of the 3D layers above the main layer should be mirrored (has no effect with 3dLayerOffset >= -1).",

"Sets if the alpha of the 3D layers above the main layer should be mirrored.");

sdVar("3dMainOnTop", &StyleData::_3dMainOnTop,
"Gets if the main layer should be rendered on top of all 3D layers (has no effect with 3_3dLayerOffset >= -1).",

"Sets if the main layer should be rendered on top of all 3D layers.");

sdVar("3dSkew", &StyleData::_3dSkew,
"Gets the current value of where the 3D skew is in the style. The Skew "
"is what gives the 3D effect in the first "
Expand Down
3 changes: 3 additions & 0 deletions src/SSVOpenHexagon/Data/StyleData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ StyleData::StyleData(const ssvuj::Obj& mRoot)
maxSwapTime{ssvuj::getExtr<float>(mRoot, "max_swap_time", 100.f)},

_3dDepth{ssvuj::getExtr<float>(mRoot, "3D_depth", 15.f)},
_3dLayerOffset{ssvuj::getExtr<float>(mRoot, "3D_layer_offset", 0.f)},
_3dAlphaMirror{ssvuj::getExtr<bool>(mRoot, "3D_alpha_mirror", true)},
_3dMainOnTop{ssvuj::getExtr<bool>(mRoot, "3D_main_on_top", false)},
_3dSkew{ssvuj::getExtr<float>(mRoot, "3D_skew", 0.18f)},
_3dSpacing{ssvuj::getExtr<float>(mRoot, "3D_spacing", 1.f)},
_3dDarkenMult{ssvuj::getExtr<float>(mRoot, "3D_darken_multiplier", 1.5f)},
Expand Down