Skip to content

Commit

Permalink
chore: add some debug output
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Oct 4, 2024
1 parent 3ca9ad1 commit dfec96d
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/command/CommandMacro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ auto& setupCommandFunctions() {
}
void setupCommands() {
for (auto& [name, fn] : setupCommandFunctions()) {
WE_DEBUG("setup command {}", name);
WE_DEBUG("setup command {0}", name);
try {
fn();
} catch (...) {
logger().error("threw from setup command {}", name);
logger().error("threw from setup command {0}", name);
ll::error_utils::printCurrentException(logger());
}
WE_DEBUG("setup command {} done", name);
WE_DEBUG("setup command {0} done", name);
}
}
bool SetupCommandFunctor::operator|(void (*fn)(ll::command::CommandHandle&)) noexcept {
auto& map = setupCommandFunctions();
WE_ASSERT(!map.contains(name), "setup same cmd twice");
setupCommandFunctions().try_emplace(std::move(name), [handler = handler, fn] {
map.try_emplace(std::move(name), [handler = handler, fn] {
handler().transform([&](auto& handle) {
fn(handle);
return true;
Expand Down
18 changes: 17 additions & 1 deletion src/command/CommandMacro.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class CommandContextRef {
template <class... Args>
void success(fmt::format_string<Args...> fmt, Args&&... args) const {
auto fsv = fmt.get();
WE_DEBUG(
"command [{0}] [success]: {0}",
cmd.getCommandName(),
fmt::vformat(
ll::i18n::getInstance().get({fsv.data(), fsv.size()}, {}),
fmt::make_format_args(args...)
)
);
output.success(fmt::vformat(
ll::i18n::getInstance().get({fsv.data(), fsv.size()}, {}),
fmt::make_format_args(args...)
Expand All @@ -37,6 +45,14 @@ class CommandContextRef {
template <class... Args>
void error(fmt::format_string<Args...> fmt, Args&&... args) const {
auto fsv = fmt.get();
WE_DEBUG(
"command [{0}] [error]: {0}",
cmd.getCommandName(),
fmt::vformat(
ll::i18n::getInstance().get({fsv.data(), fsv.size()}, {}),
fmt::make_format_args(args...)
)
);
output.error(fmt::vformat(
ll::i18n::getInstance().get({fsv.data(), fsv.size()}, {}),
fmt::make_format_args(args...)
Expand Down Expand Up @@ -109,4 +125,4 @@ std::shared_ptr<PlayerContext> getPlayerContext(CommandContextRef const& ctx);
} \
} \
| [](ll::command::CommandHandle & command)
#endif
#endif
1 change: 0 additions & 1 deletion src/command/region/Hpos1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ REG_CMD(region, hpos1, "sets the main position to the cursor position") {
}
if (hitResult.mIsHitLiquid && !player->isImmersedInWater()) {
hitResult.mBlockPos = hitResult.mLiquid;
hitResult.mFacing = hitResult.mLiquidFacing;
}
if (pctx->setMainPos({hitResult.mBlockPos, player->getDimensionId()})) {
ctx.success("set main position at {0}", hitResult.mBlockPos);
Expand Down
1 change: 0 additions & 1 deletion src/command/region/Hpos2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ REG_CMD(region, hpos2, "sets the off position to the cursor position") {
}
if (hitResult.mIsHitLiquid && !player->isImmersedInWater()) {
hitResult.mBlockPos = hitResult.mLiquid;
hitResult.mFacing = hitResult.mLiquidFacing;
}
if (pctx->setOffPos({hitResult.mBlockPos, player->getDimensionId()})) {
ctx.success("set off position at {0}", hitResult.mBlockPos);
Expand Down
2 changes: 1 addition & 1 deletion src/command/region/Pos2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ REG_CMD(region, pos2, "sets the off position to the given or current position")
[](CommandContextRef const& ctx, Params const& params) {
auto dim = checkDimension(ctx);
if (!dim) return;
BlockPos pos = params.pos.transform(ctx.transformPos()).value_or(ctx.pos());
BlockPos pos = params.pos.transform(ctx.transformPos()).value_or(ctx.pos());
if (getPlayerContext(ctx)->setOffPos({pos, dim->getDimensionId()})) {
ctx.success("set off position at {0}", pos);
} else {
Expand Down
20 changes: 19 additions & 1 deletion src/worldedit/Macros.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
#pragma once

#if 0


#ifndef WE_DEBUG
#define WE_DEBUG(...) ((void)0)
#endif

#ifndef WE_ASSERT
#define WE_ASSERT(...) ((void)0)
#endif


#else


#ifndef WE_DEBUG
#define WE_DEBUG(...) ::we::logger().debug(__VA_ARGS__)
#endif

#ifndef WE_ASSERT
#define WE_ASSERT(expression, message) \
(void)((!!(expression)) \
|| (::we::logger().debug("assert {} failed, {}", #expression, message), \
|| (::we::logger().debug("assert {0} failed, {1}", #expression, message), \
std::terminate(), \
0))
#endif


#endif

0 comments on commit dfec96d

Please sign in to comment.