Now the spatialmap determines the 'wiggle factor' when there's multiple entities in a cell, which staggers them visually. Closes #78.
This commit is contained in:
parent
694ee210d6
commit
9c02fb846b
4 changed files with 35 additions and 21 deletions
|
@ -93,13 +93,23 @@ FoundEntities SpatialMap::neighbors(Point cell, bool diag) const {
|
|||
}
|
||||
|
||||
inline void update_sorted(SortedEntities& sprite_distance, PointEntityMap& table, Point from, int max_dist) {
|
||||
Point seen{0,0};
|
||||
float wiggle = 0.0f;
|
||||
|
||||
for(const auto &rec : table) {
|
||||
Point sprite = rec.first;
|
||||
int inside = (from.x - sprite.x) * (from.x - sprite.x) +
|
||||
(from.y - sprite.y) * (from.y - sprite.y);
|
||||
|
||||
if(sprite == seen) {
|
||||
wiggle += 0.02f;
|
||||
} else {
|
||||
wiggle = 0.0f;
|
||||
seen = sprite;
|
||||
}
|
||||
|
||||
if(inside < max_dist) {
|
||||
sprite_distance.push_back({inside, rec.second.entity});
|
||||
sprite_distance.push_back({inside, rec.second.entity, wiggle});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -109,7 +119,9 @@ SortedEntities SpatialMap::distance_sorted(Point from, int max_dist) {
|
|||
|
||||
update_sorted(sprite_distance, $collision, from, max_dist);
|
||||
|
||||
std::sort(sprite_distance.begin(), sprite_distance.end(), std::greater<>());
|
||||
std::sort(sprite_distance.begin(), sprite_distance.end(), [](auto &a, auto &b) {
|
||||
return a.dist_square > b.dist_square;
|
||||
});
|
||||
|
||||
return sprite_distance;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue