summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVittorio Romeo <vittorio.romeo@outlook.com>2020-06-18 14:14:17 +0100
committerVittorio Romeo <vittorio.romeo@outlook.com>2020-06-18 14:14:17 +0100
commit82ee2c003ac3412a1fcc953d02ea68b1983922ba (patch)
treec431dd0ee2f09db0f0a643cdb548e4b8eff238bb
parent97badef34e7c3a071c0928c144442ec49547136a (diff)
Major refactoring and cleanupMajor_refactoring
-rw-r--r--include/SSVOpenHexagon/Components/CPlayer.hpp12
-rw-r--r--include/SSVOpenHexagon/Components/CWall.hpp16
-rw-r--r--include/SSVOpenHexagon/Core/HexagonGame.hpp7
-rw-r--r--include/SSVOpenHexagon/Global/Factory.hpp32
-rw-r--r--include/SSVOpenHexagon/Utils/Utils.hpp7
-rw-r--r--src/SSVOpenHexagon/Components/CPlayer.cpp107
-rw-r--r--src/SSVOpenHexagon/Components/CWall.cpp46
-rw-r--r--src/SSVOpenHexagon/Core/HGGraphics.cpp6
-rw-r--r--src/SSVOpenHexagon/Core/HGScripting.cpp21
-rw-r--r--src/SSVOpenHexagon/Core/HGUpdate.cpp7
-rw-r--r--src/SSVOpenHexagon/Core/HexagonGame.cpp14
-rw-r--r--src/SSVOpenHexagon/Utils/Utils.cpp2
12 files changed, 125 insertions, 152 deletions
diff --git a/include/SSVOpenHexagon/Components/CPlayer.hpp b/include/SSVOpenHexagon/Components/CPlayer.hpp
index f2a890b1..e72f2086 100644
--- a/include/SSVOpenHexagon/Components/CPlayer.hpp
+++ b/include/SSVOpenHexagon/Components/CPlayer.hpp
@@ -15,8 +15,6 @@ class HexagonGame;
class CPlayer final
{
private:
- HexagonGame* hexagonGame;
-
Vec2f pLeft;
Vec2f pRight;
Vec2f startPos;
@@ -34,14 +32,14 @@ private:
Ticker swapBlinkTimer{5.f};
Ticker deadEffectTimer{80.f, false};
- void drawPivot();
- void drawDeathEffect();
+ void drawPivot(HexagonGame& mHexagonGame);
+ void drawDeathEffect(HexagonGame& mHexagonGame);
public:
- CPlayer(HexagonGame& mHexagonGame, const Vec2f& mStartPos);
+ CPlayer(const Vec2f& mStartPos) noexcept;
- void update(FT mFT);
- void draw();
+ void update(HexagonGame& mHexagonGame, FT mFT);
+ void draw(HexagonGame& mHexagonGame);
};
} // namespace hg
diff --git a/include/SSVOpenHexagon/Components/CWall.hpp b/include/SSVOpenHexagon/Components/CWall.hpp
index a6742562..f18f876d 100644
--- a/include/SSVOpenHexagon/Components/CWall.hpp
+++ b/include/SSVOpenHexagon/Components/CWall.hpp
@@ -57,21 +57,13 @@ struct SpeedData
class CWall final
{
private:
- HexagonGame* hexagonGame;
-
- Vec2f centerPos;
-
std::array<Vec2f, 4> vertexPositions;
SpeedData speed;
SpeedData curve;
- float distance{0};
- float thickness{0};
float hueMod{0};
- int side{0};
-
public:
bool killed{false};
@@ -79,20 +71,20 @@ public:
float mThickness, float mDistance, const SpeedData& mSpeed,
const SpeedData& mCurve);
- void update(FT mFT);
- void draw();
+ void update(HexagonGame& mHexagonGame, const Vec2f& mCenterPos, FT mFT);
+ void draw(HexagonGame& mHexagonGame);
void setHueMod(float mHueMod) noexcept
{
hueMod = mHueMod;
}
- SpeedData& getSpeed() noexcept
+ [[nodiscard]] SpeedData& getSpeed() noexcept
{
return speed;
}
- SpeedData& getCurve() noexcept
+ [[nodiscard]] SpeedData& getCurve() noexcept
{
return curve;
}
diff --git a/include/SSVOpenHexagon/Core/HexagonGame.hpp b/include/SSVOpenHexagon/Core/HexagonGame.hpp
index 4d29de3b..06423505 100644
--- a/include/SSVOpenHexagon/Core/HexagonGame.hpp
+++ b/include/SSVOpenHexagon/Core/HexagonGame.hpp
@@ -13,7 +13,6 @@
#include "SSVOpenHexagon/Components/CWall.hpp"
#include "SSVOpenHexagon/Global/Assets.hpp"
#include "SSVOpenHexagon/Global/Config.hpp"
-#include "SSVOpenHexagon/Global/Factory.hpp"
#include "SSVOpenHexagon/Utils/Utils.hpp"
#include "SSVOpenHexagon/Utils/FPSWatcher.hpp"
@@ -47,7 +46,7 @@ private:
ssvu::TimelineManager effectTimelineManager;
- Factory factory{*this, ssvs::zeroVec2f};
+ const Vec2f centerPos{ssvs::zeroVec2f};
Lua::LuaContext lua;
@@ -110,6 +109,10 @@ private:
}
}
+ // Wall creation
+ void createWall(int mSide, float mThickness, const SpeedData& mSpeed,
+ const SpeedData& mCurve = SpeedData{}, float mHueMod = 0);
+
public:
template <typename T, typename... TArgs>
T runLuaFunction(const std::string& mName, const TArgs&... mArgs)
diff --git a/include/SSVOpenHexagon/Global/Factory.hpp b/include/SSVOpenHexagon/Global/Factory.hpp
deleted file mode 100644
index 9b5d7831..00000000
--- a/include/SSVOpenHexagon/Global/Factory.hpp
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright (c) 2013-2015 Vittorio Romeo
-// License: Academic Free License ("AFL") v. 3.0
-// AFL License page: http://opensource.org/licenses/AFL-3.0
-
-#pragma once
-
-#include "SSVOpenHexagon/Global/Common.hpp"
-#include "SSVOpenHexagon/Components/CWall.hpp"
-#include "SSVOpenHexagon/Utils/Utils.hpp"
-
-namespace hg
-{
-
-class HexagonGame;
-
-class Factory
-{
-private:
- HexagonGame& hexagonGame;
- Vec2f centerPos;
-
-public:
- Factory(HexagonGame& mHexagonGame, const Vec2f& mCenterPos)
- : hexagonGame(mHexagonGame), centerPos{mCenterPos}
- {
- }
-
- void createWall(int mSide, float mThickness, const SpeedData& mSpeed,
- const SpeedData& mCurve = SpeedData{}, float mHueMod = 0);
-};
-
-} // namespace hg
diff --git a/include/SSVOpenHexagon/Utils/Utils.hpp b/include/SSVOpenHexagon/Utils/Utils.hpp
index 9e213a0b..f03a9eab 100644
--- a/include/SSVOpenHexagon/Utils/Utils.hpp
+++ b/include/SSVOpenHexagon/Utils/Utils.hpp
@@ -16,12 +16,12 @@
namespace hg::Utils
{
-inline float getSaturated(float mValue)
+[[gnu::const]] inline float getSaturated(float mValue)
{
return std::max(0.f, std::min(1.f, mValue));
}
-inline float getSmootherStep(float edge0, float edge1, float x)
+[[gnu::const]] inline float getSmootherStep(float edge0, float edge1, float x)
{
x = getSaturated((x - edge0) / (edge1 - edge0));
return x * x * x * (x * (x * 6 - 15) + 10);
@@ -42,11 +42,12 @@ std::set<std::string> getIncludedLuaFileNames(const std::string& mLuaScript);
void recursiveFillIncludedLuaFileNames(std::set<std::string>& mLuaScriptNames,
const Path& mPackPath, const std::string& mLuaScript);
-sf::Color transformHue(const sf::Color& in, float H);
+[[gnu::const]] sf::Color transformHue(const sf::Color& in, float H);
inline void runLuaFile(Lua::LuaContext& mLua, const std::string& mFileName)
{
std::ifstream s{mFileName};
+
try
{
mLua.executeCode(s);
diff --git a/src/SSVOpenHexagon/Components/CPlayer.cpp b/src/SSVOpenHexagon/Components/CPlayer.cpp
index 605474e8..753a721d 100644
--- a/src/SSVOpenHexagon/Components/CPlayer.cpp
+++ b/src/SSVOpenHexagon/Components/CPlayer.cpp
@@ -19,21 +19,21 @@ namespace hg
constexpr float baseThickness{5.f};
-CPlayer::CPlayer(HexagonGame& mHexagonGame, const Vec2f& mStartPos)
- : hexagonGame(&mHexagonGame), startPos{mStartPos}, pos{startPos}
+CPlayer::CPlayer(const Vec2f& mStartPos) noexcept
+ : startPos{mStartPos}, pos{startPos}
{
}
-void CPlayer::draw()
+void CPlayer::draw(HexagonGame& mHexagonGame)
{
- drawPivot();
+ drawPivot(mHexagonGame);
if(deadEffectTimer.isRunning())
{
- drawDeathEffect();
+ drawDeathEffect(mHexagonGame);
}
- Color colorMain{!dead ? hexagonGame->getColorMain()
+ Color colorMain{!dead ? mHexagonGame.getColorMain()
: ssvs::getColorFromHSV(hue / 360.f, 1.f, 1.f)};
pLeft = getOrbitRad(pos, angle - toRad(100.f), size + 3);
@@ -45,23 +45,22 @@ void CPlayer::draw()
(swapBlinkTimer.getCurrent() * 15) / 360.f, 1, 1);
}
- hexagonGame->playerTris.emplace_back(
+ mHexagonGame.playerTris.emplace_back(
getOrbitRad(pos, angle, size), colorMain);
- hexagonGame->playerTris.emplace_back(pLeft, colorMain);
- hexagonGame->playerTris.emplace_back(pRight, colorMain);
+ mHexagonGame.playerTris.emplace_back(pLeft, colorMain);
+ mHexagonGame.playerTris.emplace_back(pRight, colorMain);
}
-void CPlayer::drawPivot()
+void CPlayer::drawPivot(HexagonGame& mHexagonGame)
{
- auto sides(hexagonGame->getSides());
+ const auto sides(mHexagonGame.getSides());
const float div{ssvu::tau / sides * 0.5f};
- const float radius{hexagonGame->getRadius() * 0.75f};
- const Color colorMain{hexagonGame->getColorMain()};
+ const float radius{mHexagonGame.getRadius() * 0.75f};
+ const Color colorMain{mHexagonGame.getColorMain()};
const Color colorB{
- Config::getBlackAndWhite() ? Color::Black : hexagonGame->getColor(1)};
+ Config::getBlackAndWhite() ? Color::Black : mHexagonGame.getColor(1)};
const Color colorDarkened{getColorDarkened(colorMain, 1.4f)};
-
for(auto i(0u); i < sides; ++i)
{
const float sAngle{div * 2.f * i};
@@ -73,53 +72,57 @@ void CPlayer::drawPivot()
const Vec2f p4{
getOrbitRad(startPos, sAngle - div, radius + baseThickness)};
- hexagonGame->wallQuads.emplace_back(p1, colorMain);
- hexagonGame->wallQuads.emplace_back(p2, colorMain);
- hexagonGame->wallQuads.emplace_back(p3, colorMain);
- hexagonGame->wallQuads.emplace_back(p4, colorMain);
+ mHexagonGame.wallQuads.emplace_back(p1, colorMain);
+ mHexagonGame.wallQuads.emplace_back(p2, colorMain);
+ mHexagonGame.wallQuads.emplace_back(p3, colorMain);
+ mHexagonGame.wallQuads.emplace_back(p4, colorMain);
- hexagonGame->capTris.emplace_back(p1, colorDarkened);
- hexagonGame->capTris.emplace_back(p2, colorDarkened);
- hexagonGame->capTris.emplace_back(startPos, colorDarkened);
+ mHexagonGame.capTris.emplace_back(p1, colorDarkened);
+ mHexagonGame.capTris.emplace_back(p2, colorDarkened);
+ mHexagonGame.capTris.emplace_back(startPos, colorDarkened);
}
}
-void CPlayer::drawDeathEffect()
+void CPlayer::drawDeathEffect(HexagonGame& mHexagonGame)
{
- float div{ssvu::tau / hexagonGame->getSides() * 0.5f};
- float radius{hue / 8.f};
- float thickness{hue / 20.f};
- Color colorMain{ssvs::getColorFromHSV((360.f - hue) / 360.f, 1.f, 1.f)};
+ const float div{ssvu::tau / mHexagonGame.getSides() * 0.5f};
+ const float radius{hue / 8.f};
+ const float thickness{hue / 20.f};
+ const Color colorMain{
+ ssvs::getColorFromHSV((360.f - hue) / 360.f, 1.f, 1.f)};
+
if(++hue > 360.f)
{
hue = 0.f;
}
- for(auto i(0u); i < hexagonGame->getSides(); ++i)
+ for(auto i(0u); i < mHexagonGame.getSides(); ++i)
{
- float sAngle{div * 2.f * i};
+ const float sAngle{div * 2.f * i};
Vec2f p1{getOrbitRad(pos, sAngle - div, radius)};
Vec2f p2{getOrbitRad(pos, sAngle + div, radius)};
Vec2f p3{getOrbitRad(pos, sAngle + div, radius + thickness)};
Vec2f p4{getOrbitRad(pos, sAngle - div, radius + thickness)};
- hexagonGame->wallQuads.emplace_back(p1, colorMain);
- hexagonGame->wallQuads.emplace_back(p2, colorMain);
- hexagonGame->wallQuads.emplace_back(p3, colorMain);
- hexagonGame->wallQuads.emplace_back(p4, colorMain);
+ mHexagonGame.wallQuads.emplace_back(p1, colorMain);
+ mHexagonGame.wallQuads.emplace_back(p2, colorMain);
+ mHexagonGame.wallQuads.emplace_back(p3, colorMain);
+ mHexagonGame.wallQuads.emplace_back(p4, colorMain);
}
}
-void CPlayer::update(FT mFT)
+void CPlayer::update(HexagonGame& mHexagonGame, FT mFT)
{
swapBlinkTimer.update(mFT);
+
if(deadEffectTimer.update(mFT) &&
- hexagonGame->getLevelStatus().tutorialMode)
+ mHexagonGame.getLevelStatus().tutorialMode)
{
deadEffectTimer.stop();
}
- if(hexagonGame->getLevelStatus().swapEnabled)
+
+ if(mHexagonGame.getLevelStatus().swapEnabled)
{
if(swapTimer.update(mFT))
{
@@ -129,30 +132,32 @@ void CPlayer::update(FT mFT)
Vec2f lastPos{pos};
float currentSpeed{speed};
- float lastAngle{angle};
- float radius{hexagonGame->getRadius()};
- int movement{hexagonGame->getInputMovement()};
- if(hexagonGame->getInputFocused())
+
+ const float lastAngle{angle};
+ const float radius{mHexagonGame.getRadius()};
+ const int movement{mHexagonGame.getInputMovement()};
+
+ if(mHexagonGame.getInputFocused())
{
currentSpeed = focusSpeed;
}
angle += toRad(currentSpeed * movement * mFT);
- if(hexagonGame->getLevelStatus().swapEnabled &&
- hexagonGame->getInputSwap() && !swapTimer.isRunning())
+ if(mHexagonGame.getLevelStatus().swapEnabled &&
+ mHexagonGame.getInputSwap() && !swapTimer.isRunning())
{
- hexagonGame->getAssets().playSound("swap.ogg");
+ mHexagonGame.getAssets().playSound("swap.ogg");
swapTimer.restart();
angle += ssvu::pi;
- hexagonGame->runLuaFunctionIfExists<void>("onCursorSwap");
+ mHexagonGame.runLuaFunctionIfExists<void>("onCursorSwap");
}
- Vec2f tempPos{getOrbitRad(startPos, angle, radius)};
- Vec2f pLeftCheck{getOrbitRad(tempPos, angle - ssvu::piHalf, 0.01f)};
- Vec2f pRightCheck{getOrbitRad(tempPos, angle + ssvu::piHalf, 0.01f)};
+ const Vec2f tempPos{getOrbitRad(startPos, angle, radius)};
+ const Vec2f pLeftCheck{getOrbitRad(tempPos, angle - ssvu::piHalf, 0.01f)};
+ const Vec2f pRightCheck{getOrbitRad(tempPos, angle + ssvu::piHalf, 0.01f)};
- for(const auto& wall : hexagonGame->walls)
+ for(const auto& wall : mHexagonGame.walls)
{
if((movement == -1 && wall.isOverlapping(pLeftCheck)) ||
(movement == 1 && wall.isOverlapping(pRightCheck)))
@@ -163,15 +168,17 @@ void CPlayer::update(FT mFT)
if(wall.isOverlapping(pos))
{
deadEffectTimer.restart();
+
if(!Config::getInvincible())
{
dead = true;
}
moveTowards(
- lastPos, ssvs::zeroVec2f, 5 * hexagonGame->getSpeedMultDM());
+ lastPos, ssvs::zeroVec2f, 5 * mHexagonGame.getSpeedMultDM());
+
pos = lastPos;
- hexagonGame->death();
+ mHexagonGame.death();
return;
}
diff --git a/src/SSVOpenHexagon/Components/CWall.cpp b/src/SSVOpenHexagon/Components/CWall.cpp
index eb880b3d..7bf018e1 100644
--- a/src/SSVOpenHexagon/Components/CWall.cpp
+++ b/src/SSVOpenHexagon/Components/CWall.cpp
@@ -16,55 +16,55 @@ namespace hg
CWall::CWall(HexagonGame& mHexagonGame, const Vec2f& mCenterPos, int mSide,
float mThickness, float mDistance, const SpeedData& mSpeed,
const SpeedData& mCurve)
- : hexagonGame(&mHexagonGame), centerPos{mCenterPos}, speed{mSpeed},
- curve{mCurve}, distance{mDistance}, thickness{mThickness}, side{mSide}
+ : speed{mSpeed}, curve{mCurve}
{
- const float div{ssvu::tau / hexagonGame->getSides() * 0.5f};
- const float angle{div * 2.f * side};
+ const float div{ssvu::tau / mHexagonGame.getSides() * 0.5f};
+ const float angle{div * 2.f * mSide};
- vertexPositions[0] = getOrbitRad(centerPos, angle - div, distance);
- vertexPositions[1] = getOrbitRad(centerPos, angle + div, distance);
+ vertexPositions[0] = getOrbitRad(mCenterPos, angle - div, mDistance);
+ vertexPositions[1] = getOrbitRad(mCenterPos, angle + div, mDistance);
vertexPositions[2] =
- getOrbitRad(centerPos, angle + div + hexagonGame->getWallAngleLeft(),
- distance + thickness + hexagonGame->getWallSkewLeft());
+ getOrbitRad(mCenterPos, angle + div + mHexagonGame.getWallAngleLeft(),
+ mDistance + mThickness + mHexagonGame.getWallSkewLeft());
vertexPositions[3] =
- getOrbitRad(centerPos, angle - div + hexagonGame->getWallAngleRight(),
- distance + thickness + hexagonGame->getWallSkewRight());
+ getOrbitRad(mCenterPos, angle - div + mHexagonGame.getWallAngleRight(),
+ mDistance + mThickness + mHexagonGame.getWallSkewRight());
}
-void CWall::draw()
+void CWall::draw(HexagonGame& mHexagonGame)
{
- auto colorMain(hexagonGame->getColorMain());
+ Color colorMain(mHexagonGame.getColorMain());
+
if(hueMod != 0)
{
colorMain = Utils::transformHue(colorMain, hueMod);
}
- for(auto i(0u); i < 4; ++i)
- {
- hexagonGame->wallQuads.emplace_back(vertexPositions[i], colorMain);
- }
+ mHexagonGame.wallQuads.emplace_back(vertexPositions[0], colorMain);
+ mHexagonGame.wallQuads.emplace_back(vertexPositions[1], colorMain);
+ mHexagonGame.wallQuads.emplace_back(vertexPositions[2], colorMain);
+ mHexagonGame.wallQuads.emplace_back(vertexPositions[3], colorMain);
}
-void CWall::update(FT mFT)
+void CWall::update(HexagonGame& mHexagonGame, const Vec2f& mCenterPos, FT mFT)
{
speed.update(mFT);
curve.update(mFT);
- float radius{hexagonGame->getRadius() * 0.65f};
+ const float radius{mHexagonGame.getRadius() * 0.65f};
int pointsOnCenter{0};
- for(auto& vp : vertexPositions)
+ for(Vec2f& vp : vertexPositions)
{
- if(std::abs(vp.x - centerPos.x) < radius &&
- std::abs(vp.y - centerPos.y) < radius)
+ if(std::abs(vp.x - mCenterPos.x) < radius &&
+ std::abs(vp.y - mCenterPos.y) < radius)
{
++pointsOnCenter;
}
else
{
- moveTowards(vp, centerPos, speed.speed * 5.f * mFT);
- rotateRadAround(vp, centerPos, curve.speed / 60.f * mFT);
+ moveTowards(vp, mCenterPos, speed.speed * 5.f * mFT);
+ rotateRadAround(vp, mCenterPos, curve.speed / 60.f * mFT);
}
}
diff --git a/src/SSVOpenHexagon/Core/HGGraphics.cpp b/src/SSVOpenHexagon/Core/HGGraphics.cpp
index 1921b41c..6f5a3be7 100644
--- a/src/SSVOpenHexagon/Core/HGGraphics.cpp
+++ b/src/SSVOpenHexagon/Core/HGGraphics.cpp
@@ -53,14 +53,14 @@ void HexagonGame::draw()
playerTris.clear();
capTris.clear();
- for(auto& w : walls)
+ for(CWall& w : walls)
{
- w.draw();
+ w.draw(*this);
}
if(status.started)
{
- player.draw();
+ player.draw(*this);
}
if(Config::get3D())
diff --git a/src/SSVOpenHexagon/Core/HGScripting.cpp b/src/SSVOpenHexagon/Core/HGScripting.cpp
index 5998b2a5..46484492 100644
--- a/src/SSVOpenHexagon/Core/HGScripting.cpp
+++ b/src/SSVOpenHexagon/Core/HGScripting.cpp
@@ -34,7 +34,8 @@ void HexagonGame::initLua()
});
lua.writeVariable("u_isKeyPressed",
[=](int mKey) { return window.getInputState()[KKey(mKey)]; });
- lua.writeVariable("u_isMouseButtonPressed", [=] (int mKey) { return window.getInputState()[MBtn(mKey)]; });
+ lua.writeVariable("u_isMouseButtonPressed",
+ [=](int mKey) { return window.getInputState()[MBtn(mKey)]; });
lua.writeVariable("u_isFastSpinning", [=] { return status.fastSpin > 0; });
lua.writeVariable("u_forceIncrement", [=] { incrementDifficulty(); });
lua.writeVariable(
@@ -206,19 +207,19 @@ void HexagonGame::initLua()
// Wall creation
lua.writeVariable("w_wall", [=](int mSide, float mThickness) {
timeline.append<Do>(
- [=] { factory.createWall(mSide, mThickness, {getSpeedMultDM()}); });
+ [=] { createWall(mSide, mThickness, {getSpeedMultDM()}); });
});
- lua.writeVariable("w_wallAdj", [=](int mSide, float mThickness,
- float mSpeedAdj) {
- timeline.append<Do>([=] {
- factory.createWall(mSide, mThickness, mSpeedAdj * getSpeedMultDM());
+ lua.writeVariable(
+ "w_wallAdj", [=](int mSide, float mThickness, float mSpeedAdj) {
+ timeline.append<Do>([=] {
+ createWall(mSide, mThickness, mSpeedAdj * getSpeedMultDM());
+ });
});
- });
lua.writeVariable("w_wallAcc",
[=](int mSide, float mThickness, float mSpeedAdj, float mAcceleration,
float mMinSpeed, float mMaxSpeed) {
timeline.append<Do>([=] {
- factory.createWall(mSide, mThickness,
+ createWall(mSide, mThickness,
{mSpeedAdj * getSpeedMultDM(), mAcceleration,
mMinSpeed * getSpeedMultDM(),
mMaxSpeed * getSpeedMultDM()});
@@ -228,7 +229,7 @@ void HexagonGame::initLua()
[=](float mHMod, int mSide, float mThickness, float mSAdj, float mSAcc,
float mSMin, float mSMax, bool mSPingPong) {
timeline.append<Do>([=] {
- factory.createWall(mSide, mThickness,
+ createWall(mSide, mThickness,
{mSAdj * getSpeedMultDM(), mSAcc, mSMin, mSMax, mSPingPong},
mHMod);
});
@@ -237,7 +238,7 @@ void HexagonGame::initLua()
[=](float mHMod, int mSide, float mThickness, float mCAdj, float mCAcc,
float mCMin, float mCMax, bool mCPingPong) {
timeline.append<Do>([=] {
- factory.createWall(mSide, mThickness, {getSpeedMultDM()},
+ createWall(mSide, mThickness, {getSpeedMultDM()},
{mCAdj, mCAcc, mCMin, mCMax, mCPingPong}, mHMod);
});
});
diff --git a/src/SSVOpenHexagon/Core/HGUpdate.cpp b/src/SSVOpenHexagon/Core/HGUpdate.cpp
index 98687200..14974836 100644
--- a/src/SSVOpenHexagon/Core/HGUpdate.cpp
+++ b/src/SSVOpenHexagon/Core/HGUpdate.cpp
@@ -89,12 +89,13 @@ void HexagonGame::update(FT mFT)
if(!status.hasDied)
{
- player.update(mFT);
+ player.update(*this, mFT);
- for(auto& w : walls)
+ for(CWall& w : walls)
{
- w.update(mFT);
+ w.update(*this, centerPos, mFT);
}
+
ssvu::eraseRemoveIf(walls, [](const auto& w) { return w.killed; });
updateEvents(mFT);
diff --git a/src/SSVOpenHexagon/Core/HexagonGame.cpp b/src/SSVOpenHexagon/Core/HexagonGame.cpp
index 56cf7730..b8612f13 100644
--- a/src/SSVOpenHexagon/Core/HexagonGame.cpp
+++ b/src/SSVOpenHexagon/Core/HexagonGame.cpp
@@ -17,16 +17,18 @@ using namespace hg::Utils;
namespace hg
{
-void Factory::createWall(int mSide, float mThickness, const SpeedData& mSpeed,
- const SpeedData& mCurve, float mHueMod)
+
+void HexagonGame::createWall(int mSide, float mThickness,
+ const SpeedData& mSpeed, const SpeedData& mCurve, float mHueMod)
{
- hexagonGame.walls.emplace_back(hexagonGame, centerPos, mSide, mThickness,
+ walls.emplace_back(*this, centerPos, mSide, mThickness,
Config::getSpawnDistance(), mSpeed, mCurve);
- hexagonGame.walls.back().setHueMod(mHueMod);
+
+ walls.back().setHueMod(mHueMod);
}
HexagonGame::HexagonGame(HGAssets& mAssets, GameWindow& mGameWindow)
- : assets(mAssets), window(mGameWindow), player{*this, ssvs::zeroVec2f},
+ : assets(mAssets), window(mGameWindow), player{ssvs::zeroVec2f},
fpsWatcher(window)
{
game.onUpdate += [this](FT mFT) { update(mFT); };
@@ -95,7 +97,7 @@ void HexagonGame::newGame(
// Manager cleanup
walls.clear();
- player = CPlayer{*this, ssvs::zeroVec2f};
+ player = CPlayer{ssvs::zeroVec2f};
// Timeline cleanup
diff --git a/src/SSVOpenHexagon/Utils/Utils.cpp b/src/SSVOpenHexagon/Utils/Utils.cpp
index 636cfdce..be25c0d3 100644
--- a/src/SSVOpenHexagon/Utils/Utils.cpp
+++ b/src/SSVOpenHexagon/Utils/Utils.cpp
@@ -165,7 +165,7 @@ void recursiveFillIncludedLuaFileNames(std::set<string>& mLuaScriptNames,
}
}
-Color transformHue(const Color& in, float H)
+[[gnu::const]] Color transformHue(const Color& in, float H)
{
float u{cos(H * 3.14f / 180.f)};
float w{sin(H * 3.14f / 180.f)};