Skip to content
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

ignore animations that are only cached symbols #571

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

maerki
Copy link
Contributor

@maerki maerki commented Jan 13, 2024

Summary by CodeRabbit

  • Performance Improvements

    • Improved map tile management for enhanced and more reliable map rendering.
    • Optimized the update cycle of map vector layers for better responsiveness during zoom and time changes.
  • New Features

    • Introduced animation control enhancements for map symbols, allowing for smoother transitions and better visual effects.
  • Bug Fixes

    • Fixed an issue with map symbols to ensure proper cache handling and removal from cache when no longer needed, preventing potential memory leaks.

Copy link
Contributor

coderabbitai bot commented Jan 13, 2024

Warning

Rate Limit Exceeded

@maerki has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 9 minutes and 17 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 9c9a37c and 47cec33.

Walkthrough

The recent updates focus on enhancing tile visibility handling and symbol animation within a map rendering system. The Tiled2dMapSource now ensures the lastVisibleTilesHash is properly initialized and reset. The Tiled2dMapVectorLayer improves its timing checks, while the SymbolAnimationCoordinator introduces cache count management. Additionally, symbol data management now includes cache state verification, and new cache management methods are added to symbol group and object classes.

Changes

Files Change Summary
shared/public/Tiled2dMapSource.h
shared/public/Tiled2dMapSourceImpl.h
Initialized lastVisibleTilesHash to -1 and reset it to 0 in onVisibleBoundsChanged.
shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp Modified update method to calculate zoomChange and timeDiff earlier; updated timing check to 3000.
shared/src/map/layers/tiled/vector/symbol/SymbolAnimationCoordinator.h Added cacheCount and methods increaseCache, decreaseCache; updated isAnimating with more conditions.
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp Added conditional block to handle cache state changes in updateSymbolGroups.
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.cpp
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.h
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h
Included new removeFromCache() method for managing cache in symbol groups and objects.

🐇✨
A rabbit hopped through the code, with glee,
Tweaking tiles and symbols, as you can see.
With each hop, a cache was neatly spun,
Now the map's alive, and oh what fun! 🌍💻

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8ebf024 and a972ec6.
Files selected for processing (9)
  • shared/public/Tiled2dMapSource.h (1 hunks)
  • shared/public/Tiled2dMapSourceImpl.h (1 hunks)
  • shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp (2 hunks)
  • shared/src/map/layers/tiled/vector/symbol/SymbolAnimationCoordinator.h (3 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.h (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h (1 hunks)
Files skipped from review due to trivial changes (1)
  • shared/public/Tiled2dMapSource.h
Additional comments: 12
shared/src/map/layers/tiled/vector/symbol/SymbolAnimationCoordinator.h (2)
  • 55-65: The isAnimating method has been updated with a new condition to check if cacheCount is greater than or equal to usageCount. This logic seems to be intended to prevent animations for symbols that are cached and not currently used. Ensure that the logic aligns with the intended behavior and that usageCount is being correctly maintained elsewhere in the code.

  • 133-133: A new member variable cacheCount has been added to the class. This variable should be properly initialized and used throughout the class to track the number of times a symbol is cached. It's crucial to ensure that this variable is thread-safe if accessed concurrently, given that it's of type std::atomic_int.

shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h (1)
  • 74-75: A new method removeFromCache has been declared but not defined within this file. Ensure that the implementation of this method correctly handles the removal of symbols from the cache and that it is called in the appropriate places.
Verification successful

The removeFromCache method has been found in the Tiled2dMapVectorSymbolObject.cpp file, confirming that the method is indeed implemented in the codebase. This aligns with the review comment that a new method removeFromCache has been declared in the Tiled2dMapVectorSymbolObject class.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the implementation of removeFromCache method
ast-grep --lang cpp --pattern $'void removeFromCache() { $$$ }'

Length of output: 64



Script:

#!/bin/bash
# Search for the implementation of the removeFromCache method in .cpp files
ast-grep --lang cpp --pattern $'void removeFromCache() { $$$ }'

Length of output: 64


Script:

#!/bin/bash
# Use ripgrep to search for the removeFromCache method definition in .cpp files
rg 'void Tiled2dMapVectorSymbolObject::removeFromCache\(\)' -t cpp

Length of output: 198

shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.h (1)
  • 68-69: A new method removeFromCache() has been added to the Tiled2dMapVectorSymbolGroup class. Ensure that this method is implemented to correctly handle the removal of symbol groups from the cache, and that it is called when the tile state changes as described in the PR objectives.
Verification successful

The ast-grep command did not return any output, which suggests that the removeFromCache() method implementation was not found in the codebase. This could mean that the method is declared but not defined within the codebase, or there might be an issue with the search pattern used.

To verify the presence and implementation of the removeFromCache() method, I will adjust the search pattern to be less restrictive and try again.


The ast-grep command again did not return any output, and this time it included a warning that the pattern contains an ERROR node, which may cause unexpected results. This suggests that the pattern used might not be correctly formulated or that the method definition is not present in the codebase.

Given the results, it would be prudent to try a different approach to verify the presence of the removeFromCache() method. I will use the rg (ripgrep) command to search for the method signature in the codebase, which can help confirm whether the method is defined somewhere in the files.


The output from the ripgrep command confirms that the removeFromCache() method is indeed defined within the Tiled2dMapVectorSymbolGroup class in the Tiled2dMapVectorSymbolGroup.cpp file. This verifies that the method has been implemented in the codebase, aligning with the PR objectives and the review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the implementation of removeFromCache method
ast-grep --lang cpp --pattern $'void removeFromCache() { $$$ }'

Length of output: 64



Script:

#!/bin/bash
# Search for the removeFromCache method definition in the codebase
ast-grep --lang cpp --pattern $'class $_ { $$$ void removeFromCache() { $$$ } $$$ }'

Length of output: 430



Script:

#!/bin/bash
# Use ripgrep to search for the removeFromCache method signature in the codebase
rg "void Tiled2dMapVectorSymbolGroup::removeFromCache\(\)"

Length of output: 188

shared/public/Tiled2dMapSourceImpl.h (1)
  • 81-84: The onVisibleBoundsChanged method has been modified to reset lastVisibleTilesHash to 0 under certain conditions. This change is likely intended to force a refresh of visible tiles when needed. Verify that this new behavior is correctly triggered and that it does not introduce any performance issues due to unnecessary tile refreshes.
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp (1)
  • 533-544: The added code block from lines 533 to 544 introduces logic to remove symbol groups from the cache when their tile state changes from CACHED to a different state. This is a critical change for the performance optimization mentioned in the PR objectives. Ensure that the removeFromCache method called on the symbolGroup object is thread-safe and does not introduce race conditions, as it seems to be called within a syncAccess lambda which suggests concurrent access.

Additionally, verify that the tileStateMap and tileSymbolGroupMap are properly managed across threads, as they are being accessed and modified within a locked section. The use of std::lock_guard with updateMutex indicates an awareness of concurrency, but it's important to ensure that all access patterns to these shared resources are covered by appropriate synchronization mechanisms to prevent data races.

Verification successful

The removeFromCache method exists within the Tiled2dMapVectorSymbolGroup and Tiled2dMapVectorSymbolObject classes, as confirmed by the search results. While the implementation details and thread safety of the method itself are not provided, the original code snippet's use of syncAccess suggests that it is intended to be thread-safe.

The search results also show several instances where tileStateMap and tileSymbolGroupMap are accessed or modified within the scope of a lock_guard that locks updateMutex. This indicates that thread safety measures are in place for these shared resources in the provided instances. However, without an exhaustive verification of every access in the codebase, it cannot be guaranteed that all accesses are protected. The consistent pattern of using updateMutex in the shown instances is a positive indication of thread safety.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify thread safety of removeFromCache method
ast-grep --lang cpp --pattern $'class Tiled2dMapVectorSymbolGroup {
  $$$
  void removeFromCache() {
    $$$
  }
  $$$
}'

# Verify that all accesses to tileStateMap and tileSymbolGroupMap are protected by updateMutex
rg --type cpp "tileStateMap|tileSymbolGroupMap" | rg --type cpp "lock_guard|updateMutex"

Length of output: 558



Script:

#!/bin/bash
# Refine the ast-grep pattern to correctly match the removeFromCache method within the Tiled2dMapVectorSymbolGroup class.
ast-grep --lang cpp --pattern $'class Tiled2dMapVectorSymbolGroup {
  $$$
  void removeFromCache() {
    $$$
  }
  $$$
}'

# Correct the rg command to search for occurrences of tileStateMap or tileSymbolGroupMap and ensure that these occurrences are within the scope of a lock_guard or updateMutex to verify thread safety.
rg --type cpp -C 5 "tileStateMap|tileSymbolGroupMap" | rg "lock_guard|updateMutex"

Length of output: 1762



Script:

#!/bin/bash
# Use rg to search for the removeFromCache method within the cpp files to verify its existence and thread safety.
rg --type cpp "void removeFromCache\(\)"

# Use rg with a larger context to verify that all accesses to tileStateMap and tileSymbolGroupMap are protected by updateMutex without filtering out the context lines.
rg --type cpp -C 10 "tileStateMap|tileSymbolGroupMap" | rg -C 10 "updateMutex"

Length of output: 22016

shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp (3)
  • 164-171: The destructor properly checks if the animationCoordinator is not null and if the current object is the coordinate owner before clearing the ownership and decreasing usage. This is a good practice to prevent resource leaks and ensure proper cleanup.

  • 174-181: The placedInCache method correctly checks for the existence of the animationCoordinator and clears the coordinate ownership if necessary before increasing the cache count. This method should ensure that the cache count is only increased when the symbol is actually placed in the cache to avoid miscounts.

  • 184-187: The removeFromCache method decreases the cache count through the animationCoordinator. It is important to ensure that this method is called in all cases where a symbol is removed from the cache to maintain an accurate cache count.

shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.cpp (1)
  • 844-848: The new removeFromCache method correctly iterates through each symbolObject and calls its removeFromCache method. This should effectively remove each symbol object from the cache. Ensure that the removeFromCache method on the symbolObject does the necessary cleanup to prevent memory leaks or dangling pointers.
shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp (2)
  • 541-543: The calculation of zoomChange and timeDiff has been moved before the conditional check, which is a logical change to ensure these values are updated before they are used in the condition. This change is approved.

  • 558-558: The conditional check for now - lastCollitionCheck has been changed from 2000*0 to 3000. This seems to be a correction of what was likely a previous typo or placeholder (2000*0 would always evaluate to 0). The new value 3000 extends the time between collision checks to 3 seconds. Ensure that this new interval is consistent with the intended behavior and performance requirements.

Comment on lines +96 to +102
int increaseCache() {;
return ++cacheCount;
}

int decreaseCache() {
return --cacheCount;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The output from the rg command shows the implementation of the decreaseCache method in the SymbolAnimationCoordinator.h file. The method simply decrements the cacheCount and returns the new value. There are no additional checks shown in the output to prevent cacheCount from becoming negative.

Based on the information provided, it appears that there are no safeguards within the decreaseCache method to prevent cacheCount from being decremented below zero. This could potentially lead to incorrect behavior as mentioned in the review comment.

Given the evidence from the codebase, the review comment is consistent with the implementation of the decreaseCache method, and the concern about cacheCount becoming negative is valid.

Analysis chain

Two new methods, increaseCache and decreaseCache, have been added to manage the cacheCount. Ensure that these methods are called appropriately whenever the cache state of a symbol changes. It's also important to ensure that cacheCount cannot become negative, as this could lead to incorrect behavior in the isAnimating method.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that cacheCount is not decremented below zero
ast-grep --lang cpp --pattern $'int decreaseCache() {
  return --cacheCount;
}'

Length of output: 80



Script:

#!/bin/bash
# Search for the decreaseCache method within the SymbolAnimationCoordinator class
ast-grep --lang cpp --pattern $'class $_ {
  $$$
  int decreaseCache() {
    $$$
  }
  $$$
}'

Length of output: 439



Script:

#!/bin/bash
# Use ripgrep to search for the decreaseCache method within the codebase
rg "int decreaseCache\(\)"

Length of output: 125



Script:

#!/bin/bash
# Extract the implementation details of the decreaseCache method
rg -A 3 -B 3 "int decreaseCache\(\)" shared/src/map/layers/tiled/vector/symbol/SymbolAnimationCoordinator.h

Length of output: 207

@@ -78,7 +78,10 @@ void Tiled2dMapSource<T, L, R>::onVisibleBoundsChanged(const ::RectCoord &visibl
if (!zoomInfo.underzoom
&& (zoomLevelInfos.empty() || zoomLevelInfos[0].zoom * zoomInfo.zoomLevelScaleFactor * screenScaleFactor < zoom)
&& (zoomLevelInfos.empty() || zoomLevelInfos[0].zoomLevelIdentifier != 0)) { // enable underzoom if the first zoomLevel is zoomLevelIdentifier == 0
onVisibleTilesChanged({});
if (lastVisibleTilesHash != 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Diese Änderung ist nötig, weil die GeoJson-Source sonst immer onVisibletilesChanged auslöst.

@maerki maerki force-pushed the bugfix/ignore-animations-in-cache branch from a972ec6 to 9c9a37c Compare January 24, 2024 09:51
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Status

Actionable comments generated: 3

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 633e5cf and 9c9a37c.
Files selected for processing (9)
  • shared/public/Tiled2dMapSource.h (1 hunks)
  • shared/public/Tiled2dMapSourceImpl.h (1 hunks)
  • shared/src/map/layers/tiled/vector/Tiled2dMapVectorLayer.cpp (2 hunks)
  • shared/src/map/layers/tiled/vector/symbol/SymbolAnimationCoordinator.h (3 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.h (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp (1 hunks)
  • shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h (1 hunks)
Additional comments: 9
shared/src/map/layers/tiled/vector/symbol/SymbolAnimationCoordinator.h (1)
  • 96-102: The methods increaseCache and decreaseCache have been added without checks to prevent cacheCount from becoming negative. This issue was previously flagged and still needs to be addressed.
shared/public/Tiled2dMapSource.h (1)
  • 162-162: The lastVisibleTilesHash member variable is now initialized to -1. This change is consistent with the PR objectives to improve tile visibility change handling.
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.h (1)
  • 59-60: The method removeFromCache has been added to the Tiled2dMapVectorSymbolObject class. Ensure that this method is called appropriately to remove symbols from the cache when they are no longer needed.
Verification successful

The removeFromCache() method exists within the Tiled2dMapVectorSymbolObject class and is being called in the codebase, indicating that it is integrated and used appropriately. The verification process is concluded with the findings aligning with the original review comment.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that removeFromCache is called when symbols are no longer needed
ast-grep --lang cpp --pattern $'class Tiled2dMapVectorSymbolObject {
  $$$
  void removeFromCache() {
    $$$
  }
  $$$
}'

Length of output: 468



Script:

#!/bin/bash
# First, verify the existence of the class Tiled2dMapVectorSymbolObject
ast-grep --lang cpp --pattern $'class Tiled2dMapVectorSymbolObject { $$$ }'

# Then, if the class exists, check for the existence of the removeFromCache method within it
ast-grep --lang cpp --pattern $'void Tiled2dMapVectorSymbolObject::removeFromCache() { $$$ }'

# Lastly, search for calls to removeFromCache to verify its usage
rg 'removeFromCache\(\)' --type cpp

Length of output: 1270

shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.h (1)
  • 68-69: The method removeFromCache has been added to the Tiled2dMapVectorSymbolGroup class. This method should be used to manage the cache effectively, removing symbol groups when they are no longer visible.
Verification successful

The removeFromCache method is indeed present in the Tiled2dMapVectorSymbolGroup class as well as in the Tiled2dMapVectorSymbolObject class, as confirmed by the output of the rg command. However, the initial task was to verify that removeFromCache is called for symbol groups when they are no longer visible, which has not been confirmed yet.

To complete the verification, I will now generate a script to search for calls to the removeFromCache method within the codebase to ensure it is being used as intended.


The search for calls to the removeFromCache method within the codebase has produced results indicating that the method is implemented in both Tiled2dMapVectorSymbolObject.cpp and Tiled2dMapVectorSymbolGroup.cpp. Additionally, there is a call to removeFromCache on a group object within Tiled2dMapVectorSourceSymbolDataManager.cpp, and a call to removeFromCache on an object within Tiled2dMapVectorSymbolGroup.cpp.

This confirms that the removeFromCache method is not only present but also utilized within the codebase, which aligns with the intent expressed in the review comment to manage the cache effectively by removing symbol groups when they are no longer visible.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify that removeFromCache is called for symbol groups when they are no longer visible
ast-grep --lang cpp --pattern $'class Tiled2dMapVectorSymbolGroup {
  $$$
  void removeFromCache() {
    $$$
  }
  $$$
}'

Length of output: 467



Script:

#!/bin/bash
# First, confirm the existence of the removeFromCache method in the codebase
ast-grep --lang cpp --pattern 'void removeFromCache() { $$$ }'

Length of output: 64



Script:

#!/bin/bash
# Broad search for the string "removeFromCache" to confirm its presence in the codebase
rg 'void removeFromCache\(\)'

Length of output: 232



Script:

#!/bin/bash
# Search for calls to the removeFromCache method within the codebase
rg 'removeFromCache\(\)'

Length of output: 742

shared/public/Tiled2dMapSourceImpl.h (1)
  • 81-84: The conditional check for lastVisibleTilesHash before calling onVisibleTilesChanged has been added. This change is consistent with the PR objectives to avoid unnecessary updates when the visible tiles have not changed.
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSourceSymbolDataManager.cpp (1)
  • 533-544: The conditional block added checks if the tile state changes from 'CACHED' to another state and removes symbol groups from the cache accordingly. This is a critical change for the performance optimization mentioned in the PR objectives. Ensure that the removal of symbol groups from the cache is safe and does not lead to dangling pointers or memory leaks.
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolObject.cpp (2)
  • 180-182: The placedInCache method correctly calls increaseCache on the animationCoordinator. This is consistent with the intent to manage cache counts for symbol animations.
  • 184-186: The removeFromCache method properly calls decreaseCache on the animationCoordinator. This aligns with the goal of removing symbol groups from the cache when their tile state changes.
shared/src/map/layers/tiled/vector/symbol/Tiled2dMapVectorSymbolGroup.cpp (1)
  • 844-848: The removeFromCache method has been added to iterate through symbolObjects and call removeFromCache on each object. Ensure that the removeFromCache method on the Tiled2dMapVectorSymbolObject class handles the removal process correctly, including any necessary cleanup or state updates.

Comment on lines +544 to +546
double zoomChange = abs(newZoom-lastDataManagerZoom) / std::max(newZoom, 1.0);
double timeDiff = now - lastDataManagerUpdate;
if (zoomChange > 0.001 || timeDiff > 2000 || isAnimating || tilesChanged) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculation of zoomChange and timeDiff has been moved before the conditional check, which is a good practice as it avoids duplicate calculations inside the condition. However, the magic number 0.001 used in the zoom change comparison should be defined as a constant to improve readability and maintainability.

const double ZOOM_CHANGE_THRESHOLD = 0.001;
...
double zoomChange = abs(newZoom - lastDataManagerZoom) / std::max(newZoom, 1.0);
double timeDiff = now - lastDataManagerUpdate;
if (zoomChange > ZOOM_CHANGE_THRESHOLD || timeDiff > 2000 || isAnimating || tilesChanged) {
    ...
}

@@ -556,7 +558,7 @@ void Tiled2dMapVectorLayer::update() {
newIsAnimating |= a;
}
isAnimating = newIsAnimating;
if (now - lastCollitionCheck > 2000 || tilesChanged) {
if (now - lastCollitionCheck > 3000 || tilesChanged) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The time threshold for lastCollitionCheck has been increased from 2000 to 3000. This change seems to be in line with the PR objectives of optimizing performance by reducing the frequency of collision checks. However, the magic number 3000 should also be defined as a constant for clarity and ease of future changes.

const long long COLLISION_CHECK_THRESHOLD = 3000;
...
if (now - lastCollitionCheck > COLLISION_CHECK_THRESHOLD || tilesChanged) {
    ...
}

Comment on lines 55 to 65
if (cacheCount >= usageCount) {
return false;

}
if (isIconAnimating() || isStretchIconAnimating() || isTextAnimating()) {
// printf("Animate %p: %d, %d, %d, %d: %f|%f\n", static_cast<void*>(this), isIconAnimating(), isStretchIconAnimating(), isTextAnimating(), isUsed(), coordinate.x, coordinate.y);
return true;
}
else {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The isAnimating method has been updated to include a check against cacheCount. This change is intended to prevent animations for symbols that are cached and not currently visible. However, there is no check to ensure cacheCount does not become negative, which could lead to incorrect behavior.

int decreaseCache() {
    if (cacheCount <= 0) {
        // Handle error or prevent decrement
        return cacheCount;
    }
    return --cacheCount;
}


}
if (isIconAnimating() || isStretchIconAnimating() || isTextAnimating()) {
// printf("Animate %p: %d, %d, %d, %d: %f|%f\n", static_cast<void*>(this), isIconAnimating(), isStretchIconAnimating(), isTextAnimating(), isUsed(), coordinate.x, coordinate.y);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debug log

@maurhofer-ubique maurhofer-ubique merged commit 196aca9 into develop Jan 24, 2024
2 checks passed
@maurhofer-ubique maurhofer-ubique deleted the bugfix/ignore-animations-in-cache branch January 24, 2024 10:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants