Skip to content

Commit

Permalink
update to textureless sprite
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Jun 16, 2024
1 parent be248c0 commit 3769494
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 44 deletions.
17 changes: 7 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,18 @@ include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
set(BUILD_SHARED_LIBS false)
set(SFML_STATIC_LIBRARIES true)
set(SFML_ENABLE_PCH true)
set(SFML_ENABLE_LIFETIME_TRACKING true)

CPMAddPackage(
NAME SFML
GITHUB_REPOSITORY vittorioromeo/SFML
GIT_TAG 2354503518af37919fa0b9e2ca92862f7041bd10
GIT_TAG 62e83b7f9e7cf1fc24e2a9fca7fcc8b4a8ff4952
)

set(SFML_ENABLE_LIFETIME_TRACKING true)

set_target_properties(sfml-system PROPERTIES UNITY_BUILD OFF)
set_target_properties(sfml-window PROPERTIES UNITY_BUILD OFF)
set_target_properties(sfml-graphics PROPERTIES UNITY_BUILD OFF)
set_target_properties(sfml-audio PROPERTIES UNITY_BUILD OFF)
set_target_properties(sfml-network PROPERTIES UNITY_BUILD OFF)
set_target_properties(sfml-system PROPERTIES UNITY_BUILD ON)
set_target_properties(sfml-window PROPERTIES UNITY_BUILD ON)
set_target_properties(sfml-graphics PROPERTIES UNITY_BUILD ON)
set_target_properties(sfml-audio PROPERTIES UNITY_BUILD ON)
set_target_properties(sfml-network PROPERTIES UNITY_BUILD ON)

#
#
Expand Down Expand Up @@ -190,7 +187,7 @@ if(NOT SSVOH_ANDROID)
CPMAddPackage(
NAME imgui-sfml
GITHUB_REPOSITORY vittorioromeo/imgui-sfml
GIT_TAG 8a7a1409f895b3fbcc7d6c19504668e923a6f8f6
GIT_TAG ea57da2bf7c7d4d66a10009371d96a31718bca45
)

set_target_properties(ImGui-SFML PROPERTIES UNITY_BUILD ON)
Expand Down
3 changes: 1 addition & 2 deletions build/make_debug_client_win10_msys_0_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,4 @@ cmake .. -G"Ninja" \
-Wno-stringop-overflow \
-D_GLIBCXX_ASSERTIONS=1 -D_FORTIFY_SOURCE=2 \
-fstack-protector -Wno-pragmas \
-frounding-math -fsignaling-nans -ffloat-store -ffp-contract=off"

-frounding-math -fsignaling-nans -ffloat-store -ffp-contract=off -DSFML_ENABLE_LIFETIME_TRACKING=1"
8 changes: 8 additions & 0 deletions include/SSVOpenHexagon/Core/HexagonGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ class HexagonGame
float nextPBParticleSpawn{0.f};
float pbTextGrowth{0.f};

sf::Texture* txKeyIconLeft;
sf::Texture* txKeyIconRight;
sf::Texture* txKeyIconFocus;
sf::Texture* txKeyIconSwap;
sf::Texture* txReplayIcon;

sf::Sprite keyIconLeft;
sf::Sprite keyIconRight;
sf::Sprite keyIconFocus;
Expand Down Expand Up @@ -519,6 +525,8 @@ class HexagonGame
void render(sf::Drawable& mDrawable,
const sf::RenderStates& mStates = sf::RenderStates::Default);

void render(const sf::Sprite& mSprite, const sf::Texture& mTexture);

// Setters
void setSides(unsigned int mSides);

Expand Down
7 changes: 7 additions & 0 deletions include/SSVOpenHexagon/Core/MenuGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ class MenuGame
static constexpr std::array<const char*, 3> creditsIds{
"creditsBar2.png", "creditsBar2b.png", "creditsBar2c.png"};

sf::Texture& txTitleBar;
sf::Texture& txCreditsBar1;
sf::Texture* txCreditsBar2;
sf::Texture& txEpilepsyWarning;

sf::Sprite titleBar;
sf::Sprite creditsBar1;
sf::Sprite creditsBar2;
Expand All @@ -144,6 +149,7 @@ class MenuGame
//---------------------------------------
// Online status bar

sf::Texture* txSOnline;
sf::Sprite sOnline;
sf::RectangleShape rsOnlineStatus;
sf::Text txtOnlineStatus;
Expand Down Expand Up @@ -294,6 +300,7 @@ class MenuGame

void draw();
void render(sf::Drawable& mDrawable);
void render(const sf::Sprite& mSprite, const sf::Texture& mTexture);

// Helper functions
[[nodiscard]] float getFPSMult() const;
Expand Down
29 changes: 21 additions & 8 deletions src/SSVOpenHexagon/Core/HGGraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ void HexagonGame::render(
window->draw(mDrawable, mStates);
}

void HexagonGame::render(const sf::Sprite& mSprite, const sf::Texture& mTexture)
{
if (window == nullptr)
{
ssvu::lo("hg::HexagonGame::render")
<< "Attempted to render without a game window\n";

return;
}

window->getRenderWindow().draw(mSprite, mTexture);
}

void HexagonGame::draw()
{
if (window == nullptr || Config::getDisableGameRendering())
Expand Down Expand Up @@ -370,17 +383,17 @@ void HexagonGame::drawKeyIcons()
keyIconFocus.setColor(getInputFocused() ? onColor : offColor);
keyIconSwap.setColor(getInputSwap() ? onColor : offColor);

render(keyIconLeft);
render(keyIconRight);
render(keyIconFocus);
render(keyIconSwap);
render(keyIconLeft, *txKeyIconLeft);
render(keyIconRight, *txKeyIconRight);
render(keyIconFocus, *txKeyIconFocus);
render(keyIconSwap, *txKeyIconSwap);

// ------------------------------------------------------------------------

if (mustShowReplayUI())
{
replayIcon.setColor(onColor);
render(replayIcon);
render(replayIcon, *txReplayIcon);
}
}

Expand All @@ -402,23 +415,23 @@ void HexagonGame::drawParticles()
{
for (Particle& p : particles)
{
render(p.sprite);
render(p.sprite, *txStarParticle);
}
}

void HexagonGame::drawTrailParticles()
{
for (TrailParticle& p : trailParticles)
{
render(p.sprite);
render(p.sprite, *txSmallCircle);
}
}

void HexagonGame::drawSwapParticles()
{
for (SwapParticle& p : swapParticles)
{
render(p.sprite);
render(p.sprite, *txSmallCircle);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/SSVOpenHexagon/Core/HGUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,7 @@ void HexagonGame::updateParticles(ssvu::FT mFT)
const auto makePBParticle = [this]
{
SSVOH_ASSERT(txStarParticle != nullptr);
Particle p{sf::Sprite{*txStarParticle}};
Particle p{sf::Sprite{txStarParticle->getRect()}};

p.sprite.setPosition(
{ssvu::getRndR(-64.f, Config::getWidth() + 64.f), -64.f});
Expand Down Expand Up @@ -991,7 +991,7 @@ void HexagonGame::updateTrailParticles(ssvu::FT mFT)
const auto makeTrailParticle = [this]
{
SSVOH_ASSERT(txSmallCircle != nullptr);
TrailParticle p{sf::Sprite{*txSmallCircle}};
TrailParticle p{sf::Sprite{txSmallCircle->getRect()}};

p.sprite.setPosition(player.getPosition());
p.sprite.setOrigin(sf::Vector2f{txSmallCircle->getSize()} / 2.f);
Expand Down Expand Up @@ -1045,7 +1045,7 @@ void HexagonGame::updateSwapParticles(ssvu::FT mFT)
const float scaleMult, const float alpha)
{
SSVOH_ASSERT(txSmallCircle != nullptr);
SwapParticle p{sf::Sprite(*txSmallCircle)};
SwapParticle p{sf::Sprite(txSmallCircle->getRect())};

p.sprite.setPosition(si.position);
p.sprite.setOrigin(sf::Vector2f{txSmallCircle->getSize()} / 2.f);
Expand Down
27 changes: 22 additions & 5 deletions src/SSVOpenHexagon/Core/HexagonGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,16 @@ HexagonGame::HexagonGame(Steam::steam_manager* mSteamManager,
levelStatus{Config::getMusicSpeedDMSync(), Config::getSpawnDistance()},
txStarParticle{nullptr},
txSmallCircle{nullptr},
keyIconLeft{assets.getTextureOrNullTexture("keyArrow.png")},
keyIconRight{assets.getTextureOrNullTexture("keyArrow.png")},
keyIconFocus{assets.getTextureOrNullTexture("keyFocus.png")},
keyIconSwap{assets.getTextureOrNullTexture("keySwap.png")},
replayIcon{assets.getTextureOrNullTexture("replayIcon.png")},
txKeyIconLeft{nullptr},
txKeyIconRight{nullptr},
txKeyIconFocus{nullptr},
txKeyIconSwap{nullptr},
txReplayIcon{nullptr},
keyIconLeft{sf::IntRect{}},
keyIconRight{sf::IntRect{}},
keyIconFocus{sf::IntRect{}},
keyIconSwap{sf::IntRect{}},
replayIcon{sf::IntRect{}},
rng{initializeRng()}
{
if (!assets.isHeadless())
Expand All @@ -346,6 +351,18 @@ HexagonGame::HexagonGame(Steam::steam_manager* mSteamManager,

txStarParticle = &assets.getTextureOrNullTexture("starParticle.png");
txSmallCircle = &assets.getTextureOrNullTexture("smallCircle.png");

txKeyIconLeft = &assets.getTextureOrNullTexture("keyArrow.png");
txKeyIconRight = &assets.getTextureOrNullTexture("keyArrow.png");
txKeyIconFocus = &assets.getTextureOrNullTexture("keyFocus.png");
txKeyIconSwap = &assets.getTextureOrNullTexture("keySwap.png");
txReplayIcon = &assets.getTextureOrNullTexture("replayIcon.png");

keyIconLeft.setTextureRect(txKeyIconLeft->getRect());
keyIconRight.setTextureRect(txKeyIconRight->getRect());
keyIconFocus.setTextureRect(txKeyIconFocus->getRect());
keyIconSwap.setTextureRect(txKeyIconSwap->getRect());
replayIcon.setTextureRect(txReplayIcon->getRect());
}

game.onUpdate +=
Expand Down
42 changes: 27 additions & 15 deletions src/SSVOpenHexagon/Core/MenuGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,16 @@ MenuGame::MenuGame(Steam::steam_manager& mSteamManager,
lua{},
execScriptPackPathContext{},
currentPack{nullptr},
titleBar{assets.getTexture("titleBar.png")},
creditsBar1{assets.getTexture("creditsBar1.png")},
creditsBar2{assets.getTexture("creditsBar2.png")},
epilepsyWarning{assets.getTexture("epilepsyWarning.png")},
sOnline{assets.getTexture("onlineIconFail.png")},
txTitleBar{assets.getTexture("titleBar.png")},
txCreditsBar1{assets.getTexture("creditsBar1.png")},
txCreditsBar2{&assets.getTexture("creditsBar2.png")},
txEpilepsyWarning{assets.getTexture("epilepsyWarning.png")},
titleBar{txTitleBar.getRect()},
creditsBar1{txCreditsBar1.getRect()},
creditsBar2{txCreditsBar2->getRect()},
epilepsyWarning{txEpilepsyWarning.getRect()},
txSOnline{&assets.getTexture("onlineIconFail.png")},
sOnline{txSOnline->getRect()},
rsOnlineStatus{sf::Vector2f{128.f, 32.f}},
txtOnlineStatus{openSquare, "", 24},
enteredChars{},
Expand Down Expand Up @@ -2838,8 +2843,9 @@ void MenuGame::update(ssvu::FT mFT)
}

currentCreditsId += mFT;
creditsBar2.setTexture(assets.getTexture(
ssvu::getByModIdx(creditsIds, ssvu::toInt(currentCreditsId / 100))));
txCreditsBar2 = &assets.getTexture(
ssvu::getByModIdx(creditsIds, ssvu::toInt(currentCreditsId / 100)));
creditsBar2.setTextureRect(txCreditsBar2->getRect());

if (exitTimer > 20)
{
Expand Down Expand Up @@ -5393,7 +5399,7 @@ void MenuGame::drawLevelSelectionLeftSide(
{difficultyBumpFactor, difficultyBumpFactor});

renderText(tempString, txtSelectionMedium.font,
{textXPos + txtSelectionMedium.font.getGlobalBounds().width,
{textXPos + txtSelectionMedium.font.getGlobalBounds().size.y,
difficultyHeight});

txtSelectionMedium.font.setScale({1.f, 1.f});
Expand Down Expand Up @@ -5824,7 +5830,7 @@ void MenuGame::draw()
return;

case States::EpilepsyWarning:
render(epilepsyWarning);
render(epilepsyWarning, txEpilepsyWarning);
renderText("PRESS ANY KEY OR BUTTON TO CONTINUE", txtProf.font,
{txtProf.height, h - txtProf.height * 2.7f + 5.f});
return;
Expand Down Expand Up @@ -5974,6 +5980,11 @@ void MenuGame::render(sf::Drawable& mDrawable)
window.draw(mDrawable);
}

void MenuGame::render(const sf::Sprite& mSprite, const sf::Texture& mTexture)
{
window.getRenderWindow().draw(mSprite, mTexture);
}

[[nodiscard]] float MenuGame::getFPSMult() const
{
// multiplier for FPS consistent drawing operations.
Expand All @@ -5982,9 +5993,9 @@ void MenuGame::render(sf::Drawable& mDrawable)

void MenuGame::drawGraphics()
{
render(titleBar);
render(creditsBar1);
render(creditsBar2);
render(titleBar, txTitleBar);
render(creditsBar1, txCreditsBar1);
render(creditsBar2, *txCreditsBar2);
render(txtVersion.font);
}

Expand Down Expand Up @@ -6067,13 +6078,14 @@ void MenuGame::drawOnlineStatus()

if (stateGood)
{
sOnline.setTexture(assets.getTexture("onlineIcon.png"));
txSOnline = &assets.getTexture("onlineIcon.png");
}
else
{
sOnline.setTexture(assets.getTexture("onlineIconFail.png"));
txSOnline = &assets.getTexture("onlineIconFail.png");
}

sOnline.setTextureRect(txSOnline->getRect());
sOnline.setScale({spriteScale, spriteScale});
sOnline.setOrigin(ssvs::getLocalSW(sOnline));
sOnline.setPosition({0.f + padding, getWindowHeight() - padding});
Expand All @@ -6091,7 +6103,7 @@ void MenuGame::drawOnlineStatus()
{ssvs::getGlobalLeft(rsOnlineStatus) + padding * 2.f,
ssvs::getGlobalCenter(rsOnlineStatus).y});

render(sOnline);
render(sOnline, *txSOnline);
render(rsOnlineStatus);
render(txtOnlineStatus);
}
Expand Down
2 changes: 1 addition & 1 deletion src/SSVOpenHexagon/Utils/FontHeight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace hg::Utils {
[[nodiscard]] float getFontHeight(sf::Text& font)
{
font.setString("ABCDEFGHILMNOPQRSTUVZ:");
return font.getGlobalBounds().height;
return font.getGlobalBounds().size.y;
}

[[nodiscard]] float getFontHeight(sf::Text& font, const unsigned int charSize)
Expand Down

0 comments on commit 3769494

Please sign in to comment.