Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
vittorioromeo committed Aug 24, 2024
1 parent 2169bcd commit fbd9f85
Show file tree
Hide file tree
Showing 16 changed files with 48 additions and 53 deletions.
7 changes: 7 additions & 0 deletions include/SSVOpenHexagon/Core/HexagonGame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,13 @@ class HexagonGame
lua, mName, mArgs...)){};
}

template <typename... TArgs>
void runVoidLuaFunctionIfExists(
std::string_view mName, const TArgs&... mArgs)
{
(void)runLuaFunctionIfExists<void>(mName, mArgs...);
}

void raiseWarning(
const std::string& mFunctionName, const std::string& mAdditionalInfo);

Expand Down
29 changes: 3 additions & 26 deletions include/SSVOpenHexagon/Global/Macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,8 @@

#pragma once

namespace hg::Impl {
#include <SFML/Base/Macros.hpp>

template <typename T>
struct RemoveRef
{
using type = T;
};
#define SSVOH_MOVE SFML_BASE_MOVE

template <typename T>
struct RemoveRef<T&>
{
using type = T;
};

template <typename T>
struct RemoveRef<T&&>
{
using type = T;
};

} // namespace hg::Impl

#define SSVOH_MOVE(...) \
static_cast< \
typename ::hg::Impl::RemoveRef<decltype(__VA_ARGS__)>::type&&>( \
__VA_ARGS__)

#define SSVOH_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
#define SSVOH_FWD SFML_BASE_FORWARD
2 changes: 1 addition & 1 deletion include/SSVOpenHexagon/Utils/FixedFunction.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class FixedFunction<TReturn(Ts...), TStorageSize>
template <typename TFFwd>
FixedFunction(TFFwd&& f) noexcept : FixedFunction()
{
using unref_type = typename hg::Impl::RemoveRef<TFFwd>::type;
using unref_type = SFML_BASE_REMOVE_REFERENCE(TFFwd);

static_assert(sizeof(unref_type) < TStorageSize);

Expand Down
2 changes: 1 addition & 1 deletion include/SSVOpenHexagon/Utils/ScopeGuard.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace hg::Utils {
template <typename F>
struct scope_guard : F
{
explicit scope_guard(F&& f) noexcept : F{std::move(f)}
explicit scope_guard(F&& f) noexcept : F{static_cast<F&&>(f)}
{}

~scope_guard() noexcept
Expand Down
5 changes: 3 additions & 2 deletions include/SSVOpenHexagon/Utils/Split.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

#pragma once

#include "SSVOpenHexagon/Global/Macros.hpp"

#include <string_view>
#include <utility>
#include <algorithm>
#include <vector>

Expand Down Expand Up @@ -37,7 +38,7 @@ template <typename TSplitType = std::string_view>
std::vector<TSplitType> result;

withSplit<TSplitType>([&](TSplitType&& piece)
{ result.emplace_back(std::move(piece)); }, str, delims);
{ result.emplace_back(SSVOH_MOVE(piece)); }, str, delims);

return result;
}
Expand Down
7 changes: 7 additions & 0 deletions include/SSVOpenHexagon/Utils/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,13 @@ template <typename T, typename... TArgs>
sf::base::Optional<VoidToNothing<T>> runLuaFunctionIfExists(
Lua::LuaContext& mLua, std::string_view mName, const TArgs&... mArgs);

template <typename... TArgs>
void runVoidLuaFunctionIfExists(
Lua::LuaContext& mLua, std::string_view mName, const TArgs&... mArgs)
{
(void)runLuaFunctionIfExists<void>(mLua, mName, mArgs...);
}

const PackData& findDependencyPackDataOrThrow(const HGAssets& assets,
const PackData& currentPack, const std::string& mPackDisambiguator,
const std::string& mPackName, const std::string& mPackAuthor);
Expand Down
4 changes: 2 additions & 2 deletions src/SSVOpenHexagon/Core/HGUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ void HexagonGame::start()
audio->resumeMusic();
}

runLuaFunctionIfExists<void>("onLoad");
runVoidLuaFunctionIfExists("onLoad");
}

static void setInputImplIfFalse(bool& var, const bool x)
Expand Down Expand Up @@ -753,7 +753,7 @@ void HexagonGame::updateLevel(float mFT)
if (o == Utils::timeline2_runner::outcome::finished && !mustChangeSides)
{
timeline.clear();
runLuaFunctionIfExists<void>("onStep");
runVoidLuaFunctionIfExists("onStep");
timelineRunner = {};
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/SSVOpenHexagon/Core/HexagonGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -797,23 +797,23 @@ void HexagonGame::newGame(const std::string& mPackId, const std::string& mId,
inputImplCCW = inputImplCW = false;
playerNowReadyToSwap = false;

if (!firstPlay) runLuaFunctionIfExists<void>("onPreUnload");
if (!firstPlay) runVoidLuaFunctionIfExists("onPreUnload");
lua = Lua::LuaContext{};
calledDeprecatedFunctions.clear();
initLua();
runLuaFile(levelData->luaScriptPath);

if (!firstPlay)
{
runLuaFunctionIfExists<void>("onUnload");
runVoidLuaFunctionIfExists("onUnload");
playSoundOverride("restart.ogg");
}
else
{
playSoundOverride("select.ogg");
}

runLuaFunctionIfExists<void>("onInit");
runVoidLuaFunctionIfExists("onInit");

restartId = mId;
restartFirstTime = false;
Expand Down Expand Up @@ -1025,14 +1025,14 @@ void HexagonGame::death(bool mForce)

playSoundAbort(levelStatus.deathSound);

runLuaFunctionIfExists<void>("onPreDeath");
runVoidLuaFunctionIfExists("onPreDeath");

if (!mForce && (Config::getInvincible() || levelStatus.tutorialMode))
{
return;
}

runLuaFunctionIfExists<void>("onDeath");
runVoidLuaFunctionIfExists("onDeath");
death_shakeCamera();
death_updateRichPresence();
stopLevelMusic();
Expand Down Expand Up @@ -1245,7 +1245,7 @@ void HexagonGame::sideChange(unsigned int mSideNumber)
mustChangeSides = false;

playSoundOverride(levelStatus.levelUpSound);
runLuaFunctionIfExists<void>("onIncrement");
runVoidLuaFunctionIfExists("onIncrement");
}

[[nodiscard]] bool HexagonGame::shouldSaveScore()
Expand Down Expand Up @@ -1345,7 +1345,7 @@ void HexagonGame::goToMenu(bool mSendScores, bool mError)
// onUnload.
if (!mError)
{
runLuaFunctionIfExists<void>("onUnload");
runVoidLuaFunctionIfExists("onUnload");
}

if (fnGoToMenu)
Expand Down Expand Up @@ -1740,7 +1740,7 @@ void HexagonGame::setSides(unsigned int mSides)
void HexagonGame::performPlayerSwap(const bool mPlaySound)
{
player.playerSwap();
runLuaFunctionIfExists<void>("onCursorSwap");
runVoidLuaFunctionIfExists("onCursorSwap");

if (mPlaySound)
{
Expand Down
4 changes: 2 additions & 2 deletions src/SSVOpenHexagon/Core/MenuGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3054,8 +3054,8 @@ void MenuGame::setIndex(const int mIdx)
try
{
runLuaFile(levelData->luaScriptPath);
Utils::runLuaFunctionIfExists<void>(lua, "onInit");
Utils::runLuaFunctionIfExists<void>(lua, "onLoad");
Utils::runVoidLuaFunctionIfExists(lua, "onInit");
Utils::runVoidLuaFunctionIfExists(lua, "onLoad");
}
catch (std::runtime_error& mError)
{
Expand Down
6 changes: 4 additions & 2 deletions src/SSVOpenHexagon/Core/Replay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include "SSVOpenHexagon/Core/Replay.hpp"

#include "SSVOpenHexagon/Global/Assert.hpp"
#include "SSVOpenHexagon/Global/Macros.hpp"

#include "SSVOpenHexagon/Utils/Concat.hpp"
#include "SSVOpenHexagon/Utils/Timestamp.hpp"

Expand Down Expand Up @@ -533,7 +535,7 @@ static constexpr std::size_t buf_size{2097152}; // 2MB
std::memcpy(static_cast<void*>(result._data.data()),
static_cast<const void*>(compression_buf), result._data.size());

return sf::base::makeOptional(std::move(result));
return sf::base::makeOptional(SSVOH_MOVE(result));
}

[[nodiscard]] sf::base::Optional<replay_file> decompress_replay_file(
Expand Down Expand Up @@ -561,7 +563,7 @@ static constexpr std::size_t buf_size{2097152}; // 2MB
return sf::base::nullOpt;
}

return sf::base::makeOptional(std::move(result));
return sf::base::makeOptional(SSVOH_MOVE(result));
}

} // namespace hg
3 changes: 2 additions & 1 deletion src/SSVOpenHexagon/Core/Steam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "SSVOpenHexagon/Core/Steam.hpp"

#include "SSVOpenHexagon/Global/Assert.hpp"
#include "SSVOpenHexagon/Global/Macros.hpp"

#include "SSVOpenHexagon/Utils/UniquePtr.hpp"

Expand Down Expand Up @@ -229,7 +230,7 @@ void steam_manager::steam_manager_impl::load_workshop_data()
ssvuj::arch(
cacheArray, _workshop_pack_folders.size(), folderBufStr);

_workshop_pack_folders.emplace(std::move(folderBufStr));
_workshop_pack_folders.emplace(SSVOH_MOVE(folderBufStr));
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/SSVOpenHexagon/Online/Shared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ template <typename T>
return sf::base::nullOpt;
}

return sf::base::makeOptional<T>(std::move(temp));
return sf::base::makeOptional<T>(SSVOH_MOVE(temp));
}

template <typename T>
Expand Down Expand Up @@ -438,7 +438,7 @@ class AdvancedMatcher
return sf::base::nullOpt;
}

return sf::base::makeOptional<T>(std::move(temp));
return sf::base::makeOptional<T>(SSVOH_MOVE(temp));
}

template <typename T>
Expand Down
4 changes: 2 additions & 2 deletions src/SSVOpenHexagon/Utils/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ bool runLuaFileCached(
t.seekg(0, std::ios::beg);
t.read(buffer.data(), size);

auto res = cache.emplace(mFileName, std::move(buffer));
auto res = cache.emplace(mFileName, SSVOH_MOVE(buffer));
SSVOH_ASSERT(res.second);
it = res.first;
}
Expand Down Expand Up @@ -274,7 +274,7 @@ sf::base::Optional<VoidToNothing<T>> runLuaFunctionIfExists(
}
}

template void runLuaFunction<void>(Lua::LuaContext&, std::string_view);
template void runLuaFunction<void>(Lua::LuaContext&, std::string_view)

template sf::base::Optional<VoidToNothing<void>> runLuaFunctionIfExists<void>(
Lua::LuaContext&, std::string_view);
Expand Down
4 changes: 2 additions & 2 deletions test/FixedFunction.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ int main()
{
int i = 10;
hg::Utils::FixedFunction<int(), 64> ff0 = [i] { return i; };
auto ff1 = std::move(ff0);
auto ff1 = SSVOH_MOVE(ff0);
TEST_ASSERT_EQ(ff1(), 10);
}

{
int i = 10;
int j = 5;
hg::Utils::FixedFunction<int(), 64> ff0 = [i, &j] { return i + j; };
auto ff1 = std::move(ff0);
auto ff1 = SSVOH_MOVE(ff0);
TEST_ASSERT_EQ(ff1(), 10 + 5);
}
}
2 changes: 1 addition & 1 deletion test/ReplayExecution.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ try
nullptr /* steamManager */, true /* headless */};

hg::ProfileData fakeProfile{hg::GAME_VERSION, "testProfile", {}, {}};
assets.addLocalProfile(std::move(fakeProfile));
assets.addLocalProfile(SSVOH_MOVE(fakeProfile));
assets.pSetCurrent("testProfile");

const auto doTest = [&](int i, bool differentHG, sf::GraphicsContext* gc,
Expand Down
2 changes: 1 addition & 1 deletion test/ReplayExecutionBenchmark.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ try
nullptr /* steamManager */, true /* headless */};

hg::ProfileData fakeProfile{hg::GAME_VERSION, "testProfile", {}, {}};
assets.addLocalProfile(std::move(fakeProfile));
assets.addLocalProfile(SSVOH_MOVE(fakeProfile));
assets.pSetCurrent("testProfile");

const auto doTest = [&](int i, bool differentHG, ssvs::GameWindow* gw)
Expand Down

0 comments on commit fbd9f85

Please sign in to comment.