Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/BedrockServerClientInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace bsci {

struct BedrockServerClientInterface::Impl {
#ifdef TEST
std::unique_ptr<GeometryGroup> geoTest = GeometryGroup::createDefault();
std::unique_ptr<GeometryGroup> geoTest;
std::vector<GeometryGroup::GeoId> gids;
#endif
};
Expand Down Expand Up @@ -68,6 +68,7 @@ bool BedrockServerClientInterface::enable() {
loadConfig();
}
#ifdef TEST
impl->geoTest = GeometryGroup::createDefault();
test::registerTestCommand(impl->geoTest, impl->gids);
std::thread([this] {
auto geo = bsci::GeometryGroup::createDefault();
Expand Down
62 changes: 59 additions & 3 deletions src/bsci/GeometryGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
#include <ranges>

#include "BedrockServerClientInterface.h"
#include "bsci/utils/Math.h"
#include "bsci/particle/ParticleSpawner.h"
#include "bsci/debug_draw/DebugDrawingHandler.h"
#include "bsci/particle/ParticleSpawner.h"
#include "bsci/utils/Math.h"


namespace bsci {
Expand Down Expand Up @@ -123,7 +123,7 @@ GeometryGroup::GeoId GeometryGroup::cylinder(
auto const delta = std::numbers::pi * 2 / (double)points;

std::vector<GeoId> ids;
ids.reserve(points);
ids.reserve(3 * points);
Vec3 lastPos = t * radius;
for (size_t i{1}; i <= points; i++) {
double theta = (double)i * delta;
Expand Down Expand Up @@ -218,4 +218,60 @@ GeometryGroup::GeoId GeometryGroup::
text(DimensionType, Vec3 const&, std::string, mce::Color const&, std::optional<float>) {
return GeoId::invalid();
}

GeometryGroup::GeoId GeometryGroup::cone(
DimensionType dim,
Vec3 const& topCenter,
Vec3 const& bottomCenter,
float topRadius,
float bottomRadius,
mce::Color const& color,
std::optional<float> thickness
) {
auto const& config = BedrockServerClientInterface::getInstance().getConfig().particle;

size_t const points =
(std::clamp(
(size_t)std::ceil(topRadius * std::numbers::pi * 2 / config.minCircleSpacing),
7ui64,
config.maxCircleSegments

)
+ std::clamp(
(size_t)std::ceil(bottomRadius * std::numbers::pi * 2 / config.minCircleSpacing),
7ui64,
config.maxCircleSegments

))
/ 2;
auto const [t, b] = branchlessONB((topCenter - bottomCenter).normalize());
auto const delta = std::numbers::pi * 2 / (double)points;

std::vector<GeoId> ids;
ids.reserve(3 * points);
Vec3 lastTopOffset = t * topRadius;
Vec3 lastBottomOffset = t * bottomRadius;
for (size_t i{1}; i <= points; i++) {
double theta = (double)i * delta;
Vec3 topOffset = t * (topRadius * std::cos(theta)) + b * topRadius * std::sin(theta);
Vec3 bottomOffset =
t * (bottomRadius * std::cos(theta)) + b * bottomRadius * std::sin(theta);
ids.emplace_back(
line(dim, topCenter + lastTopOffset, topCenter + topOffset, color, thickness)
);
ids.emplace_back(
line(dim, topCenter + topOffset, bottomCenter + bottomOffset, color, thickness)
);
ids.emplace_back(line(
dim,
bottomCenter + lastBottomOffset,
bottomCenter + bottomOffset,
color,
thickness
));
lastTopOffset = topOffset;
lastBottomOffset = bottomOffset;
}
return merge(ids);
}
} // namespace bsci
10 changes: 10 additions & 0 deletions src/bsci/GeometryGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ class GeometryGroup {
mce::Color const& color = mce::Color::WHITE(),
std::optional<float> scale = {}
);

BSCI_API virtual GeoId cone(
DimensionType dim,
Vec3 const& topCenter,
Vec3 const& bottomCenter,
float topRadius,
float bottomRadius,
mce::Color const& color = mce::Color::WHITE(),
std::optional<float> thickness = {}
);
};
} // namespace bsci

Expand Down
4 changes: 1 addition & 3 deletions src/bsci/debug_draw/DebugDrawingHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <variant>
#include <vector>

#include "bsci/particle/ParticleSpawner.h"

#include <ll/api/base/Containers.h>
#include <ll/api/memory/Hook.h>
#include <ll/api/thread/ServerThreadExecutor.h>
Expand Down Expand Up @@ -219,7 +217,7 @@ GeometryGroup::GeoId DebugDrawingHandler::box(
ShapeDataPayload shape;
shape.mNetworkId = nextId_.fetch_sub(1);
shape.mShapeType = ScriptModuleDebugUtilities::ScriptDebugShapeType::Box;
shape.mLocation = box.min;
shape.mLocation = (box.min + box.max) / 2;
shape.mColor = color;
shape.mDimensionId = dim;
shape.mExtraDataPayload = BoxDataPayload{.mBoxBound = box.max - box.min};
Expand Down
132 changes: 50 additions & 82 deletions src/bsci/test/Test.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#include "BedrockServerClientInterface.h"

#ifdef TEST
#include "bsci/GeometryGroup.h"
#include "ll/api/command/CommandHandle.h"
Expand Down Expand Up @@ -33,7 +31,7 @@ void registerTestCommand(
ll::command::RuntimeCommand const& self
) {
Vec3 pos = self["pos"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Expand All @@ -56,12 +54,12 @@ void registerTestCommand(
ll::command::RuntimeCommand const& self
) {
Vec3 begin = self["begin"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Vec3 end = self["end"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Expand All @@ -81,12 +79,12 @@ void registerTestCommand(
ll::command::RuntimeCommand const& self
) {
Vec3 begin = self["begin"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Vec3 end = self["end"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Expand All @@ -106,7 +104,7 @@ void registerTestCommand(
ll::command::RuntimeCommand const& self
) {
Vec3 center = self["center"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Expand All @@ -116,27 +114,6 @@ void registerTestCommand(
output.success("draw circle");
});

cmd.runtimeOverload()
.text("circle_with_thick")
.required("dim", ll::command::ParamKind::Dimension)
.required("center", ll::command::ParamKind::Vec3)
.required("radius", ll::command::ParamKind::Float)
.execute([&geo, &gids](
CommandOrigin const& origin,
CommandOutput& output,
ll::command::RuntimeCommand const& self
) {
Vec3 center = self["center"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
origin,
Vec3::ZERO()
);
auto radius = self["radius"].get<ll::command::ParamKind::Float>();
DimensionType dim = self["dim"].get<ll::command::ParamKind::Dimension>().id;
gids.emplace_back(geo->circle(dim, center, {0, 1, 0}, radius, mce::Color::WHITE(), 1));
output.success("draw circle");
});

cmd.runtimeOverload()
.text("cylinder")
.required("dim", ll::command::ParamKind::Dimension)
Expand All @@ -149,13 +126,13 @@ void registerTestCommand(
ll::command::RuntimeCommand const& self
) {
Vec3 topCenter = self["topCenter"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Vec3 bottomCenter =
self["bottomCenter"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Expand All @@ -176,7 +153,7 @@ void registerTestCommand(
ll::command::RuntimeCommand const& self
) {
Vec3 center = self["center"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Expand Down Expand Up @@ -205,7 +182,7 @@ void registerTestCommand(
ll::command::RuntimeCommand const& self
) {
Vec3 offset = self["offset"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Expand All @@ -225,7 +202,7 @@ void registerTestCommand(
ll::command::RuntimeCommand const& self
) {
Vec3 offset = self["offset"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Expand All @@ -236,48 +213,6 @@ void registerTestCommand(
output.success("clear all");
});

cmd.runtimeOverload()
.text("circle2")
.required("dim", ll::command::ParamKind::Dimension)
.required("center", ll::command::ParamKind::Vec3)
.required("radius", ll::command::ParamKind::Float)
.execute([&geo, &gids](
CommandOrigin const& origin,
CommandOutput& output,
ll::command::RuntimeCommand const& self
) {
Vec3 center = self["center"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
origin,
Vec3::ZERO()
);
auto radius = self["radius"].get<ll::command::ParamKind::Float>();
DimensionType dim = self["dim"].get<ll::command::ParamKind::Dimension>().id;
gids.emplace_back(geo->circle2(dim, center, {0, 1, 0}, radius, mce::Color::WHITE()));
output.success("draw circle");
});

cmd.runtimeOverload()
.text("sphere2")
.required("dim", ll::command::ParamKind::Dimension)
.required("center", ll::command::ParamKind::Vec3)
.required("radius", ll::command::ParamKind::Float)
.execute([&geo, &gids](
CommandOrigin const& origin,
CommandOutput& output,
ll::command::RuntimeCommand const& self
) {
Vec3 center = self["center"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
origin,
Vec3::ZERO()
);
auto radius = self["radius"].get<ll::command::ParamKind::Float>();
DimensionType dim = self["dim"].get<ll::command::ParamKind::Dimension>().id;
gids.emplace_back(geo->sphere2(dim, center, radius));
output.success("draw sphere");
});

cmd.runtimeOverload()
.text("arrow")
.required("dim", ll::command::ParamKind::Dimension)
Expand All @@ -289,12 +224,12 @@ void registerTestCommand(
ll::command::RuntimeCommand const& self
) {
Vec3 begin = self["begin"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Vec3 end = self["end"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Expand All @@ -308,21 +243,54 @@ void registerTestCommand(
.required("dim", ll::command::ParamKind::Dimension)
.required("pos", ll::command::ParamKind::Vec3)
.required("text", ll::command::ParamKind::String)
.required("scale", ll::command::ParamKind::Float)
.execute([&geo, &gids](
CommandOrigin const& origin,
CommandOutput& output,
ll::command::RuntimeCommand const& self
) {
Vec3 pos = self["pos"].get<ll::command::ParamKind::Vec3>().getPosition(
CommandVersion::CurrentVersion(),
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
std::string text = self["text"].get<ll::command::ParamKind::String>();
DimensionType dim = self["dim"].get<ll::command::ParamKind::Dimension>().id;
gids.emplace_back(geo->text(dim, pos + Vec3{1, 1, 1}, text, mce::Color::WHITE(), 30));
std::string text = self["text"].get<ll::command::ParamKind::String>();
DimensionType dim = self["dim"].get<ll::command::ParamKind::Dimension>().id;
float scale = self["scale"].get<ll::command::ParamKind::Float>();
gids.emplace_back(geo->text(dim, pos + Vec3{1, 1, 1}, text, mce::Color::WHITE(), scale)
);
output.success("draw text");
});

cmd.runtimeOverload()
.text("cone")
.required("dim", ll::command::ParamKind::Dimension)
.required("topCenter", ll::command::ParamKind::Vec3)
.required("bottomCenter", ll::command::ParamKind::Vec3)
.required("topRadius", ll::command::ParamKind::Float)
.required("bottomRadius", ll::command::ParamKind::Float)
.execute([&geo, &gids](
CommandOrigin const& origin,
CommandOutput& output,
ll::command::RuntimeCommand const& self
) {
Vec3 topCenter = self["topCenter"].get<ll::command::ParamKind::Vec3>().getPosition(
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
Vec3 bottomCenter =
self["bottomCenter"].get<ll::command::ParamKind::Vec3>().getPosition(
static_cast<int>(CurrentCmdVersion::Latest),
origin,
Vec3::ZERO()
);
auto topRadius = self["topRadius"].get<ll::command::ParamKind::Float>();
auto bottomRadius = self["bottomRadius"].get<ll::command::ParamKind::Float>();
DimensionType dim = self["dim"].get<ll::command::ParamKind::Dimension>().id;
gids.emplace_back(geo->cone(dim, topCenter, bottomCenter, topRadius, bottomRadius));
output.success("draw cylinder");
});
}
} // namespace bsci::test
#endif
2 changes: 0 additions & 2 deletions src/bsci/test/Test.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#pragma once

#include "BedrockServerClientInterface.h"

#ifdef TEST
#include "bsci/GeometryGroup.h"
#include <memory>
Expand Down
1 change: 1 addition & 0 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ target("BedrockServerClientInterface")
add_rules("@levibuildscript/modpacker")
add_cxflags( "/EHa", "/utf-8", "/W4", "/w44265", "/w44289", "/w44296", "/w45263", "/w44738", "/w45204")
add_defines( "_HAS_CXX23=1", "NOMINMAX", "UNICODE", "BSCI_EXPORTS")
-- add_defines("TEST")
add_files("src/**.cpp")
add_headerfiles("src/(bsci/**.h)")
add_includedirs("src")
Expand Down
Loading