Skip to content

Commit

Permalink
3D drawing mode
Browse files Browse the repository at this point in the history
  • Loading branch information
IvoryDuke committed Feb 8, 2021
1 parent 6bbdf42 commit fe6889a
Show file tree
Hide file tree
Showing 20 changed files with 990 additions and 497 deletions.
1 change: 1 addition & 0 deletions include/SSVOpenHexagon/Components/CCustomWall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class CCustomWall

void update(HexagonGame& mHexagonGame, ssvu::FT mFT);
void draw(HexagonGame& mHexagonGame);
void draw3D(HexagonGame& mHexagonGame, const sf::Color& mColor);

[[gnu::always_inline, nodiscard]] bool isOverlapping(
const sf::Vector2f& mPoint) const noexcept
Expand Down
1 change: 1 addition & 0 deletions include/SSVOpenHexagon/Components/CCustomWallManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class CCustomWallManager
void cleanup();
void clear();
void draw(HexagonGame& hexagonGame);
void draw3D(HexagonGame& hexagonGame, const sf::Color& mColor);

template <typename F>
void forCustomWalls(F&& f)
Expand Down
32 changes: 30 additions & 2 deletions include/SSVOpenHexagon/Components/CPlayer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ class CPlayer
sf::Vector2f startPos;
sf::Vector2f pos;
sf::Vector2f lastPos;
std::array<sf::Vector2f, 3> vertexPositions;
std::vector<sf::Vector2f> pivotVertexes;

float hue;
float angle;
Expand All @@ -39,20 +41,39 @@ class CPlayer
Ticker swapBlinkTimer;
Ticker deadEffectTimer;

float pivotRadius;
static constexpr float pivotBorderThickness{5.f};

void drawCommon(HexagonGame& mHexagonGame);
void drawPivot(HexagonGame& mHexagonGame, const sf::Color& mCapColor);
void drawPivot3D(HexagonGame& mHexagonGame, const sf::Color& mWallColor,
const sf::Color& mCapColor);
void drawDeathEffect(HexagonGame& mHexagonGame);
void drawDeathEffect3D(HexagonGame& mHexagonGame, const sf::Color& mWallColors);

public:

CPlayer(const sf::Vector2f& mPos, const float swapCooldown) noexcept;

[[gnu::always_inline, nodiscard]] const sf::Vector2f&
getPosition() const noexcept
[[gnu::always_inline, nodiscard]]
const sf::Vector2f& getPosition() const noexcept
{
return pos;
}

[[nodiscard]] float getPlayerAngle() const noexcept;

[[gnu::always_inline, nodiscard]]
const std::vector<sf::Vector2f>& getPivotVertexes() const noexcept
{
return pivotVertexes;
}

[[gnu::always_inline, nodiscard]] float getPivotRadius() const noexcept
{
return pivotRadius;
}

void setPlayerAngle(const float newAng) noexcept;
void playerSwap(HexagonGame& mHexagonGame, bool mPlaySound);

Expand All @@ -63,6 +84,13 @@ class CPlayer
void updatePosition(const HexagonGame& mHexagonGame, const ssvu::FT mFT);

void draw(HexagonGame& mHexagonGame, const sf::Color& mCapColor);
void draw3D(HexagonGame& mHexagonGame, const sf::Color& mWallColor,
const sf::Color& mCapColor);

void setSides(unsigned int mSideNumber) noexcept
{
pivotVertexes.resize(mSideNumber);
}

[[nodiscard]] bool push(const HexagonGame& mHexagonGame, const CWall& wall,
const sf::Vector2f& mCenterPos, ssvu::FT mFT);
Expand Down
29 changes: 21 additions & 8 deletions include/SSVOpenHexagon/Components/CWall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "SSVOpenHexagon/Utils/PointInPolygon.hpp"

#include <SSVStart/Utils/Vector2.hpp>
#include <SFML/System/Vector2.hpp>

#include <array>

Expand All @@ -28,26 +27,40 @@ class CWall
float hueMod;
bool killed;

void moveTowardsCenter(HexagonGame& mHexagonGame,
const sf::Vector2f& mCenterPos, const ssvu::FT mFT);
void moveCurve(const sf::Vector2f& mCenterPos,
const ssvu::FT mFT);

unsigned int getVertexScreenPortion(const sf::Vector2f& mVertex,
const sf::Vector2f& mCenterPos, const unsigned int mSides);
void calcIntersectionPoint(const HexagonGame& mHexagonGame, sf::Vector2f& mIntersection,
const std::vector<sf::Vector2f>& mPivotVertexes, const sf::Vector2f& mCenterPos,
const sf::Vector2f& wallVertexOne, const sf::Vector2f& wallVertexTwo);

void draw3DSides(HexagonGame& mHexagonGame, const sf::Vector2f& mOffset3D,
const sf::Color& mColor);
void draw3DSide(HexagonGame& mHexagonGame, const sf::Vector2f& mOffset3D,
const sf::Color& mColor, const sf::Vector2f& mVertexOne,
const sf::Vector2f& mVertexTwo);

public:
CWall(HexagonGame& mHexagonGame, const sf::Vector2f& mCenterPos, int mSide,
float mThickness, float mDistance, const SpeedData& mSpeed,
const SpeedData& mCurve);

void update(const HexagonGame& mHexagonGame, const ssvu::FT mFT);

void moveTowardsCenter(HexagonGame& mHexagonGame,
const sf::Vector2f& mCenterPos, const ssvu::FT mFT);
void update(HexagonGame& mHexagonGame, const sf::Vector2f& mCenterPos,
const ssvu::FT mFT);

[[gnu::always_inline]] void moveVertexAlongCurve(sf::Vector2f& mVertex,
const sf::Vector2f& mCenterPos, const ssvu::FT mFT) const
{
ssvs::rotateRadAround(mVertex, mCenterPos, curve.speed / 60.f * mFT);
}

void moveCurve(const HexagonGame& mHexagonGame,
const sf::Vector2f& mCenterPos, const ssvu::FT mFT);

void draw(HexagonGame& mHexagonGame);
void draw3D(HexagonGame& mHexagonGame, const CPlayer& mPlayer,
const sf::Vector2f& mCenterPos, const sf::Color& mColor);

void setHueMod(float mHueMod) noexcept;

Expand Down
58 changes: 45 additions & 13 deletions include/SSVOpenHexagon/Core/HexagonGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,57 @@ class HexagonGame
void updateKeyIcons();

// Draw methods
void draw();
public:
Utils::FastVertexVector<sf::PrimitiveType::Quads> wallQuads;
Utils::FastVertexVector<sf::PrimitiveType::Triangles> playerTris;
Utils::FastVertexVector<sf::PrimitiveType::Quads> capQuads;
Utils::FastVertexVector<sf::PrimitiveType::Triangles> capTris;
Utils::FastVertexVector<sf::PrimitiveType::Quads> wallQuads3D;
Utils::FastVertexVector<sf::PrimitiveType::Triangles> playerTris3D;
sf::Vector2f offset3D;

// Gameplay methods
void incrementDifficulty();
void sideChange(unsigned int mSideNumber);
[[nodiscard]] const sf::Vector2f& get3DOffset() noexcept
{
return offset3D;
}

// Draw methods
private:
static constexpr float piAndHalf{ssvu::piHalf * 3.f};

void drawSetup();
void draw2D();
void drawProjections();
void draw3D();
void drawWrapup();
void draw();
void drawText_TimeAndStatus(const sf::Color& offsetColor);
void drawText_Message(const sf::Color& offsetColor);
void drawText();
void drawKeyIcons();

std::function<void()> drawFunc;
void setDrawFunc()
{
if(!Config::get3D())
{
drawFunc = [this] { draw2D(); };
return;
}

if(levelData->_3DDrawingMode)
{
drawFunc = [this] { draw3D(); };
}
else
{
drawFunc = [this] { drawProjections(); };
}
}

// Gameplay methods
void incrementDifficulty();
void sideChange(unsigned int mSideNumber);

// Data-related methods
void setLevelData(const LevelData& mLevelData, bool mMusicFirstPlay);
void playLevelMusic();
Expand Down Expand Up @@ -322,7 +361,6 @@ class HexagonGame

void invalidateScore(const std::string& mReason);


template <typename F>
Utils::LuaMetadataProxy addLuaFn(const std::string& name, F&& f)
{
Expand All @@ -341,8 +379,7 @@ class HexagonGame
const std::string& args, const std::string& docs) {
std::cout << "* **`" << ret << " " << name << "(" << args
<< ")`**: " << docs << "\n\n";
},
i);
}, i);
}
}

Expand All @@ -366,11 +403,6 @@ class HexagonGame
}

public:
Utils::FastVertexVector<sf::PrimitiveType::Quads> wallQuads;
Utils::FastVertexVector<sf::PrimitiveType::Triangles> playerTris;
Utils::FastVertexVector<sf::PrimitiveType::Triangles> capTris;
Utils::FastVertexVector<sf::PrimitiveType::Quads> wallQuads3D;
Utils::FastVertexVector<sf::PrimitiveType::Triangles> playerTris3D;

MenuGame* mgPtr;

Expand Down
70 changes: 45 additions & 25 deletions include/SSVOpenHexagon/Core/MenuGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,26 +56,6 @@ enum class States
ETLPNew
};

enum Tid
{
Unknown = -1,
RotateCCW = 0,
RotateCW,
Focus,
Select,
Exit,
ForceRestart,
Restart,
Replay,
Screenshot,
Swap,
Up,
Down,
NextPack,
PreviousPack,
TriggersCount
};

class HexagonGame;

class MenuGame
Expand Down Expand Up @@ -142,6 +122,7 @@ class MenuGame
//---------------------------------------
// Navigation

bool wasFocusHeld{false};
bool focusHeld{false};
float wheelProgress{0.f};
float touchDelay{0.f};
Expand Down Expand Up @@ -379,26 +360,65 @@ class MenuGame

void changeLevelFavoriteFlag();
void switchToFromFavoriteLevels();
void sortFavoriteLevels()
{
std::sort(favSlct.levelDataIds.begin(), favSlct.levelDataIds.end(),
[this](const std::string& a, const std::string& b) -> bool {
return assets.getLevelData(a).name < assets.getLevelData(b).name;
});
}

// Visual effects
float difficultyBumpEffect{0.f};
static inline constexpr float difficultyBumpEffectMax{24.f};

void adjustLevelsOffset();
void updateLevelSelectionDrawingParameters();
float getMaximumTextWidth() const;
float getLevelListHeight() const;

float getLevelSelectionHeight() const;
float getLevelListHeight() const
{
return levelLabelHeight * lvlDrawer->levelDataIds.size() + slctFrameSize;
}

static inline constexpr float baseScrollSpeed{45.f};
void calcPackChangeScrollSpeed()
{
// Only speed up the animation if there are more than 12 levels.
scrollSpeed =
baseScrollSpeed * std::max(lvlDrawer->levelDataIds.size() / 12.f, 1.f);
}
void calcLevelChangeScroll(const int dir);
void calcPackChangeScroll();
void calcPackChangeScrollSpeed();

void scrollName(std::string& text, float& scroller);
void scrollNameRightBorder(std::string& text, const std::string key,
sf::Text& font, float& scroller, float border);
void scrollNameRightBorder(
std::string& text, sf::Text& font, float& scroller, const float border);
void resetNamesScrolls();
void resetLevelNamesScrolls();

void resetNamesScrolls()
{
for(int i = 0; i < static_cast<int>(Label::ScrollsSize); ++i)
{
namesScroll[i] = 0;
}
}
void resetLevelNamesScrolls()
{
// Reset all scrolls except the ones relative to the pack.
namesScroll[static_cast<int>(Label::LevelName)] = 0.f;
for(int i = static_cast<int>(Label::MusicName);
i < static_cast<int>(Label::ScrollsSize); ++i)
{
namesScroll[i] = 0.f;
}
}

float getMaximumTextWidth() const
{
return w * 0.33f - 2.f * textToQuadBorder;
}
void formatLevelDescription();
void drawLevelSelectionRightSide(
LevelDrawer& drawer, const bool revertOffset);
Expand Down
1 change: 1 addition & 0 deletions include/SSVOpenHexagon/Data/LevelData.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class LevelData
packPath + ssvuj::getExtr<std::string>(root, "luaFile", "nullLuaPath")};
std::vector<float> difficultyMults{
ssvuj::getExtr<std::vector<float>>(root, "difficultyMults", {})};
bool _3DDrawingMode{ssvuj::getExtr<bool>(root, "3DMode", false)};

LevelData(const ssvuj::Obj& mRoot, const ssvufs::Path& mPackPath,
const std::string& mPackId)
Expand Down
Loading

0 comments on commit fe6889a

Please sign in to comment.