-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor quadtree: Extracted into tfs::map::quadtree namespace with code improvements and tests #4798
base: master
Are you sure you want to change the base?
Refactor quadtree: Extracted into tfs::map::quadtree namespace with code improvements and tests #4798
Conversation
src/quadtree.h
Outdated
void move_creature(uint16_t old_x, uint16_t old_y, uint8_t old_z, uint16_t x, uint16_t y, uint8_t z, | ||
Creature* creature); | ||
void insert_creature(uint16_t x, uint16_t y, uint8_t z, Creature* creature); | ||
void remove_creature(uint16_t x, uint16_t y, uint8_t z, Creature* creature); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use Position
rather than 3 ints for xyz?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Initially, I used pos, but to maintain compatibility with the Map
class, I used x, y, and z. I would prefer if Map
were also changed to support only Position. See
Lines 177 to 190 in 2444655
Tile* getTile(uint16_t x, uint16_t y, uint8_t z) const; | |
Tile* getTile(const Position& pos) const { return getTile(pos.x, pos.y, pos.z); } | |
/** | |
* Set a single tile. | |
*/ | |
void setTile(uint16_t x, uint16_t y, uint8_t z, Tile* newTile); | |
void setTile(const Position& pos, Tile* newTile) { setTile(pos.x, pos.y, pos.z, newTile); } | |
/** | |
* Removes a single tile. | |
*/ | |
void removeTile(uint16_t x, uint16_t y, uint8_t z); | |
void removeTile(const Position& pos) { removeTile(pos.x, pos.y, pos.z); } |
@@ -112,6 +112,7 @@ | |||
<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet> | |||
<AdditionalIncludeDirectories>$(VcpkgRoot)include\luajit;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories> | |||
<LanguageStandard>stdcpp20</LanguageStandard> | |||
<PrecompiledHeader>NotUsing</PrecompiledHeader> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this before merge ;)
We could rename the namespace to namespace |
src/quadtree.cpp
Outdated
|
||
void tfs::map::quadtree::move_creature(uint16_t old_x, uint16_t old_y, uint16_t x, uint16_t y, Creature* creature) | ||
{ | ||
if (auto old_leaf = find_leaf_in_root(old_x, old_y); auto leaf = find_leaf_in_root(x, y)) { |
Check failure
Code scanning / CodeQL
Inconsistent nullness check
suggestion: add extra tree layer for Z coordinate in order to support up to 256 floors this can still be regulated by MAP_MAX_LAYERS, but would allow otc users to break 16 floors limit more easily |
@Zbizu I didn't understand your suggestion. Are you proposing to have a configuration for |
Any suggestions for |
Pull Request Prelude
Changes Proposed:
New namespace
tfs::map::quadtree
.Improved readability
find_in_range(...)
move_creature(...)
create_tile(...)
Enhanced creature search
find_in_range(...)
function now utilizesstd::experimental::generator
for a more efficient search of creatures within a specified range. This update positions the code for future integration withstd::generator
upon the adoption of C++23.Tests
Note: Tests for tile finding and creation are still pending.
Usage