-
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); } |
vc17/theforgottenserver.vcxproj
Outdated
@@ -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 |
@Zbizu I didn't understand your suggestion. Are you proposing to have a configuration for |
Any suggestions for |
@ramon-bernardo you don't have to refactor entire Position class, supporting the floors in the new QTree (or even octree if you decide to use u16 for Z coordinate) will be good enough for now, full support for more floors (otc only) can be added in later commits |
@Zbizu can we leave this for another PR? I'm considering using to |
@ramon-bernardo of course, this one is quite big already |
for (auto creature : tfs::map::quadtree::find_in_range(x1, y1, x2, y2)) { | ||
if (onlyPlayers && !creature->getPlayer()) { | ||
continue; | ||
} | ||
|
||
const auto& position = creature->getPosition(); | ||
if (minRangeZ > position.z || maxRangeZ < position.z) { | ||
continue; | ||
} | ||
|
||
const auto offsetZ = centerPos.getOffsetZ(position); | ||
if ((min_y + offsetZ) > position.y || (max_y + offsetZ) < position.y || (min_x + offsetZ) > position.x || | ||
(max_x + offsetZ) < position.x) { | ||
continue; | ||
} | ||
|
||
spectators.emplace_back(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.
@ranisalt can you implement C++ 23
in forgotten? This would avoid push twice into the SpectatorVec
🥳
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.Usage