-
-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This refactoring consists of: 1- Improved caching algorithm 2- Applied pipeline concept 3- Use of vector_set instead of hashset. **code sample:** ```c++ // [OLD] SpectatorHashSet spectators; getSpectators(spectators, Position(x, y, z), ...); for(const auto spec: spectators) {} ``` ```c++ // [NEW] // Get All Creatures Spectators().find<Creature>(Position(x, y, z), ...); // Get All Players Spectators().find<Player>(Position(x, y, z), ...); // Method Filter // Note: This method returns a new instance of spectators { auto spectators = Spectators().find<Creature>(Position(x, y, z), ...); // Get All Npcs from spectators variable auto npcSpectators = spectators.filter<Npc>(); // Get All Players from spectators variable auto playerSpectators = spectators.filter<Player>(); } // Pipeline Code { auto spectators = Spectators() .find<Creature>({100, 200, 100}) .find<Player>({110, 210, 110}) .find<Creature>({99, 101, 50}); for(const auto spec : spectators) {} for(const auto spec : spectators.filter<Monster>()) {} for(const auto spec : spectators.filter<Npc>()) {} } ``` **[BENCHMARK]** (Set SPECTATORS_USE_HASHSET if you want to benchmark with 'hashset'.) <details> Vector ![image](https://github.com/opentibiabr/canary/assets/2267386/a74564c9-ee99-4dc8-a290-c1420a394bf4) Hashset ![hashset_cache](https://github.com/opentibiabr/canary/assets/2267386/468a2c1e-bdf7-4c3b-8df7-efbed40b4ddf) </details> **[BENCHMARK CODE]** <details> ```C++ void Map::moveCreature(Creature &creature, Tile &newTile, bool forceTeleport /* = false*/) { . . . auto spectators = Spectators() .find<Creature>(oldPos, true) .find<Creature>(newPos, true); const int64_t start = OTSYS_TIME(); for (int_fast32_t i = -1; ++i < 999999;) { for (const auto spec : Spectators() .find<Creature>(oldPos, true) .find<Creature>(newPos, true)) { } } g_logger().info("Benchmark std::vector({}) | cache enabled: {}ms", spectators.size(), static_cast<double>(OTSYS_TIME() - start) / 1000.f); . . . } ``` </details> --------- Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com> Co-authored-by: Luan Santos <[email protected]>
- Loading branch information
1 parent
653648f
commit 1e1fd0c
Showing
33 changed files
with
742 additions
and
681 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.