Skip to content

Commit

Permalink
bump version + refactor NextFreeOffset a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
HJfod committed Feb 15, 2024
1 parent a6f0a2e commit 67e784a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@

## v6.3.0

* Add Next Free Offset for Group IDs

## v6.2.1

* Fix crash on mobile when typing in layer number
Expand Down
9 changes: 3 additions & 6 deletions src/features/NextFreeOffset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ using namespace geode::prelude;
struct GroupIDAllocator {
using ValueType = short;

static constexpr short MIN_VALUE = 1;
static constexpr short MAX_VALUE = 9999;

static void init(std::span<GameObject*> const& objs, short upTo) {
for (short v = 0; v < (upTo - 1); v += 1) {
auto obj = objs[v / 10];
Expand All @@ -27,12 +30,6 @@ struct GroupIDAllocator {
// https://stackoverflow.com/questions/2745074/fast-ceiling-of-an-integer-division-in-c-c
return upTo / 10 + (upTo % 10 != 0);
}
static short getMaxValue() {
return 9999;
}
static short getMinValue() {
return 1;
}
};

class $modify(SetGroupIDLayer) {
Expand Down
10 changes: 5 additions & 5 deletions src/utils/NextFreeOffsetInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ concept NextFreeAllocator = requires(std::span<GameObject*> const& objs, C::Valu
{ C::init(objs, upTo) } -> std::same_as<void>;
{ C::uninit(objs, upTo) } -> std::same_as<void>;
{ C::getObjectCountToAllocate(upTo) } -> std::same_as<size_t>;
{ C::getMinValue() } -> std::same_as<typename C::ValueType>;
{ C::getMaxValue() } -> std::same_as<typename C::ValueType>;
{ C::MIN_VALUE } -> std::convertible_to<typename C::ValueType>;
{ C::MAX_VALUE } -> std::convertible_to<typename C::ValueType>;
};

class NextFreeOffsetInput : public CCNode, public TextInputDelegate {
Expand All @@ -26,10 +26,10 @@ class NextFreeOffsetInput : public CCNode, public TextInputDelegate {
template <NextFreeAllocator Allocator>
Allocator::ValueType getValue() const {
if (auto value = numFromString<typename Allocator::ValueType>(m_input->getInput()->getString())) {
return clamp(value.unwrap(), Allocator::getMinValue(), Allocator::getMaxValue());
return clamp(value.unwrap(), Allocator::MIN_VALUE, Allocator::MAX_VALUE);
}
else {
return Allocator::getMinValue();
return Allocator::MIN_VALUE;
}
}
};
Expand Down Expand Up @@ -117,7 +117,7 @@ FakeObjectsForNextFree<Allocator> addFakeObjects(NextFreeOffsetInput* input) {
}
auto upTo = input->template getValue<Allocator>();
// Det krävs inte offsettera om vi räknar upp till det minsta
if (upTo == Allocator::getMinValue()) {
if (upTo == Allocator::MIN_VALUE) {
return FakeObjectsForNextFree<Allocator>();
}
return FakeObjectsForNextFree<Allocator>(upTo);
Expand Down

0 comments on commit 67e784a

Please sign in to comment.