Skip to content

Commit fbd9f85

Browse files
committed
wip
1 parent 2169bcd commit fbd9f85

16 files changed

+48
-53
lines changed

include/SSVOpenHexagon/Core/HexagonGame.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ class HexagonGame
335335
lua, mName, mArgs...)){};
336336
}
337337

338+
template <typename... TArgs>
339+
void runVoidLuaFunctionIfExists(
340+
std::string_view mName, const TArgs&... mArgs)
341+
{
342+
(void)runLuaFunctionIfExists<void>(mName, mArgs...);
343+
}
344+
338345
void raiseWarning(
339346
const std::string& mFunctionName, const std::string& mAdditionalInfo);
340347

include/SSVOpenHexagon/Global/Macros.hpp

+3-26
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,8 @@
44

55
#pragma once
66

7-
namespace hg::Impl {
7+
#include <SFML/Base/Macros.hpp>
88

9-
template <typename T>
10-
struct RemoveRef
11-
{
12-
using type = T;
13-
};
9+
#define SSVOH_MOVE SFML_BASE_MOVE
1410

15-
template <typename T>
16-
struct RemoveRef<T&>
17-
{
18-
using type = T;
19-
};
20-
21-
template <typename T>
22-
struct RemoveRef<T&&>
23-
{
24-
using type = T;
25-
};
26-
27-
} // namespace hg::Impl
28-
29-
#define SSVOH_MOVE(...) \
30-
static_cast< \
31-
typename ::hg::Impl::RemoveRef<decltype(__VA_ARGS__)>::type&&>( \
32-
__VA_ARGS__)
33-
34-
#define SSVOH_FWD(...) static_cast<decltype(__VA_ARGS__)&&>(__VA_ARGS__)
11+
#define SSVOH_FWD SFML_BASE_FORWARD

include/SSVOpenHexagon/Utils/FixedFunction.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class FixedFunction<TReturn(Ts...), TStorageSize>
8282
template <typename TFFwd>
8383
FixedFunction(TFFwd&& f) noexcept : FixedFunction()
8484
{
85-
using unref_type = typename hg::Impl::RemoveRef<TFFwd>::type;
85+
using unref_type = SFML_BASE_REMOVE_REFERENCE(TFFwd);
8686

8787
static_assert(sizeof(unref_type) < TStorageSize);
8888

include/SSVOpenHexagon/Utils/ScopeGuard.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace hg::Utils {
1313
template <typename F>
1414
struct scope_guard : F
1515
{
16-
explicit scope_guard(F&& f) noexcept : F{std::move(f)}
16+
explicit scope_guard(F&& f) noexcept : F{static_cast<F&&>(f)}
1717
{}
1818

1919
~scope_guard() noexcept

include/SSVOpenHexagon/Utils/Split.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
#pragma once
66

7+
#include "SSVOpenHexagon/Global/Macros.hpp"
8+
79
#include <string_view>
8-
#include <utility>
910
#include <algorithm>
1011
#include <vector>
1112

@@ -37,7 +38,7 @@ template <typename TSplitType = std::string_view>
3738
std::vector<TSplitType> result;
3839

3940
withSplit<TSplitType>([&](TSplitType&& piece)
40-
{ result.emplace_back(std::move(piece)); }, str, delims);
41+
{ result.emplace_back(SSVOH_MOVE(piece)); }, str, delims);
4142

4243
return result;
4344
}

include/SSVOpenHexagon/Utils/Utils.hpp

+7
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,13 @@ template <typename T, typename... TArgs>
7474
sf::base::Optional<VoidToNothing<T>> runLuaFunctionIfExists(
7575
Lua::LuaContext& mLua, std::string_view mName, const TArgs&... mArgs);
7676

77+
template <typename... TArgs>
78+
void runVoidLuaFunctionIfExists(
79+
Lua::LuaContext& mLua, std::string_view mName, const TArgs&... mArgs)
80+
{
81+
(void)runLuaFunctionIfExists<void>(mLua, mName, mArgs...);
82+
}
83+
7784
const PackData& findDependencyPackDataOrThrow(const HGAssets& assets,
7885
const PackData& currentPack, const std::string& mPackDisambiguator,
7986
const std::string& mPackName, const std::string& mPackAuthor);

src/SSVOpenHexagon/Core/HGUpdate.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ void HexagonGame::start()
557557
audio->resumeMusic();
558558
}
559559

560-
runLuaFunctionIfExists<void>("onLoad");
560+
runVoidLuaFunctionIfExists("onLoad");
561561
}
562562

563563
static void setInputImplIfFalse(bool& var, const bool x)
@@ -753,7 +753,7 @@ void HexagonGame::updateLevel(float mFT)
753753
if (o == Utils::timeline2_runner::outcome::finished && !mustChangeSides)
754754
{
755755
timeline.clear();
756-
runLuaFunctionIfExists<void>("onStep");
756+
runVoidLuaFunctionIfExists("onStep");
757757
timelineRunner = {};
758758
}
759759
}

src/SSVOpenHexagon/Core/HexagonGame.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -797,23 +797,23 @@ void HexagonGame::newGame(const std::string& mPackId, const std::string& mId,
797797
inputImplCCW = inputImplCW = false;
798798
playerNowReadyToSwap = false;
799799

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

806806
if (!firstPlay)
807807
{
808-
runLuaFunctionIfExists<void>("onUnload");
808+
runVoidLuaFunctionIfExists("onUnload");
809809
playSoundOverride("restart.ogg");
810810
}
811811
else
812812
{
813813
playSoundOverride("select.ogg");
814814
}
815815

816-
runLuaFunctionIfExists<void>("onInit");
816+
runVoidLuaFunctionIfExists("onInit");
817817

818818
restartId = mId;
819819
restartFirstTime = false;
@@ -1025,14 +1025,14 @@ void HexagonGame::death(bool mForce)
10251025

10261026
playSoundAbort(levelStatus.deathSound);
10271027

1028-
runLuaFunctionIfExists<void>("onPreDeath");
1028+
runVoidLuaFunctionIfExists("onPreDeath");
10291029

10301030
if (!mForce && (Config::getInvincible() || levelStatus.tutorialMode))
10311031
{
10321032
return;
10331033
}
10341034

1035-
runLuaFunctionIfExists<void>("onDeath");
1035+
runVoidLuaFunctionIfExists("onDeath");
10361036
death_shakeCamera();
10371037
death_updateRichPresence();
10381038
stopLevelMusic();
@@ -1245,7 +1245,7 @@ void HexagonGame::sideChange(unsigned int mSideNumber)
12451245
mustChangeSides = false;
12461246

12471247
playSoundOverride(levelStatus.levelUpSound);
1248-
runLuaFunctionIfExists<void>("onIncrement");
1248+
runVoidLuaFunctionIfExists("onIncrement");
12491249
}
12501250

12511251
[[nodiscard]] bool HexagonGame::shouldSaveScore()
@@ -1345,7 +1345,7 @@ void HexagonGame::goToMenu(bool mSendScores, bool mError)
13451345
// onUnload.
13461346
if (!mError)
13471347
{
1348-
runLuaFunctionIfExists<void>("onUnload");
1348+
runVoidLuaFunctionIfExists("onUnload");
13491349
}
13501350

13511351
if (fnGoToMenu)
@@ -1740,7 +1740,7 @@ void HexagonGame::setSides(unsigned int mSides)
17401740
void HexagonGame::performPlayerSwap(const bool mPlaySound)
17411741
{
17421742
player.playerSwap();
1743-
runLuaFunctionIfExists<void>("onCursorSwap");
1743+
runVoidLuaFunctionIfExists("onCursorSwap");
17441744

17451745
if (mPlaySound)
17461746
{

src/SSVOpenHexagon/Core/MenuGame.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3054,8 +3054,8 @@ void MenuGame::setIndex(const int mIdx)
30543054
try
30553055
{
30563056
runLuaFile(levelData->luaScriptPath);
3057-
Utils::runLuaFunctionIfExists<void>(lua, "onInit");
3058-
Utils::runLuaFunctionIfExists<void>(lua, "onLoad");
3057+
Utils::runVoidLuaFunctionIfExists(lua, "onInit");
3058+
Utils::runVoidLuaFunctionIfExists(lua, "onLoad");
30593059
}
30603060
catch (std::runtime_error& mError)
30613061
{

src/SSVOpenHexagon/Core/Replay.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include "SSVOpenHexagon/Core/Replay.hpp"
66

77
#include "SSVOpenHexagon/Global/Assert.hpp"
8+
#include "SSVOpenHexagon/Global/Macros.hpp"
9+
810
#include "SSVOpenHexagon/Utils/Concat.hpp"
911
#include "SSVOpenHexagon/Utils/Timestamp.hpp"
1012

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

536-
return sf::base::makeOptional(std::move(result));
538+
return sf::base::makeOptional(SSVOH_MOVE(result));
537539
}
538540

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

564-
return sf::base::makeOptional(std::move(result));
566+
return sf::base::makeOptional(SSVOH_MOVE(result));
565567
}
566568

567569
} // namespace hg

src/SSVOpenHexagon/Core/Steam.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "SSVOpenHexagon/Core/Steam.hpp"
66

77
#include "SSVOpenHexagon/Global/Assert.hpp"
8+
#include "SSVOpenHexagon/Global/Macros.hpp"
89

910
#include "SSVOpenHexagon/Utils/UniquePtr.hpp"
1011

@@ -229,7 +230,7 @@ void steam_manager::steam_manager_impl::load_workshop_data()
229230
ssvuj::arch(
230231
cacheArray, _workshop_pack_folders.size(), folderBufStr);
231232

232-
_workshop_pack_folders.emplace(std::move(folderBufStr));
233+
_workshop_pack_folders.emplace(SSVOH_MOVE(folderBufStr));
233234
}
234235
}
235236

src/SSVOpenHexagon/Online/Shared.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ template <typename T>
355355
return sf::base::nullOpt;
356356
}
357357

358-
return sf::base::makeOptional<T>(std::move(temp));
358+
return sf::base::makeOptional<T>(SSVOH_MOVE(temp));
359359
}
360360

361361
template <typename T>
@@ -438,7 +438,7 @@ class AdvancedMatcher
438438
return sf::base::nullOpt;
439439
}
440440

441-
return sf::base::makeOptional<T>(std::move(temp));
441+
return sf::base::makeOptional<T>(SSVOH_MOVE(temp));
442442
}
443443

444444
template <typename T>

src/SSVOpenHexagon/Utils/Utils.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bool runLuaFileCached(
6969
t.seekg(0, std::ios::beg);
7070
t.read(buffer.data(), size);
7171

72-
auto res = cache.emplace(mFileName, std::move(buffer));
72+
auto res = cache.emplace(mFileName, SSVOH_MOVE(buffer));
7373
SSVOH_ASSERT(res.second);
7474
it = res.first;
7575
}
@@ -274,7 +274,7 @@ sf::base::Optional<VoidToNothing<T>> runLuaFunctionIfExists(
274274
}
275275
}
276276

277-
template void runLuaFunction<void>(Lua::LuaContext&, std::string_view);
277+
template void runLuaFunction<void>(Lua::LuaContext&, std::string_view)
278278

279279
template sf::base::Optional<VoidToNothing<void>> runLuaFunctionIfExists<void>(
280280
Lua::LuaContext&, std::string_view);

test/FixedFunction.t.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ int main()
2222
{
2323
int i = 10;
2424
hg::Utils::FixedFunction<int(), 64> ff0 = [i] { return i; };
25-
auto ff1 = std::move(ff0);
25+
auto ff1 = SSVOH_MOVE(ff0);
2626
TEST_ASSERT_EQ(ff1(), 10);
2727
}
2828

2929
{
3030
int i = 10;
3131
int j = 5;
3232
hg::Utils::FixedFunction<int(), 64> ff0 = [i, &j] { return i + j; };
33-
auto ff1 = std::move(ff0);
33+
auto ff1 = SSVOH_MOVE(ff0);
3434
TEST_ASSERT_EQ(ff1(), 10 + 5);
3535
}
3636
}

test/ReplayExecution.t.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ try
4141
nullptr /* steamManager */, true /* headless */};
4242

4343
hg::ProfileData fakeProfile{hg::GAME_VERSION, "testProfile", {}, {}};
44-
assets.addLocalProfile(std::move(fakeProfile));
44+
assets.addLocalProfile(SSVOH_MOVE(fakeProfile));
4545
assets.pSetCurrent("testProfile");
4646

4747
const auto doTest = [&](int i, bool differentHG, sf::GraphicsContext* gc,

test/ReplayExecutionBenchmark.t.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ try
4040
nullptr /* steamManager */, true /* headless */};
4141

4242
hg::ProfileData fakeProfile{hg::GAME_VERSION, "testProfile", {}, {}};
43-
assets.addLocalProfile(std::move(fakeProfile));
43+
assets.addLocalProfile(SSVOH_MOVE(fakeProfile));
4444
assets.pSetCurrent("testProfile");
4545

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

0 commit comments

Comments
 (0)