Update spatial hash in animation setProperty for entity position, closes #256

UIEntity::setProperty() now calls spatial_hash.update() when draw_x/draw_y
change, matching the Python property setter behavior. Added
enable_shared_from_this<UIEntity> to support shared_from_this() in the
setProperty path.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
John McCardle 2026-04-10 01:40:29 -04:00
commit 5173eaf7f5
3 changed files with 84 additions and 5 deletions

View file

@ -1640,15 +1640,23 @@ PyObject* UIEntity::repr(PyUIEntityObject* self) {
// "x" and "y" are kept as aliases for backwards compatibility
bool UIEntity::setProperty(const std::string& name, float value) {
if (name == "draw_x" || name == "x") { // #176 - draw_x is preferred, x is alias
float old_x = position.x;
float old_y = position.y;
position.x = value;
// Don't update sprite position here - UIGrid::render() handles the pixel positioning
if (grid) grid->markCompositeDirty(); // #144 - Propagate to parent grid for texture caching
if (grid) {
grid->markCompositeDirty();
grid->spatial_hash.update(shared_from_this(), old_x, old_y); // #256
}
return true;
}
else if (name == "draw_y" || name == "y") { // #176 - draw_y is preferred, y is alias
float old_x = position.x;
float old_y = position.y;
position.y = value;
// Don't update sprite position here - UIGrid::render() handles the pixel positioning
if (grid) grid->markCompositeDirty(); // #144 - Propagate to parent grid for texture caching
if (grid) {
grid->markCompositeDirty();
grid->spatial_hash.update(shared_from_this(), old_x, old_y); // #256
}
return true;
}
else if (name == "sprite_scale") {

View file

@ -60,7 +60,7 @@ sf::Vector2f PyObject_to_sfVector2f(PyObject* obj);
PyObject* UIGridPointState_to_PyObject(const UIGridPointState& state);
PyObject* UIGridPointStateVector_to_PyList(const std::vector<UIGridPointState>& vec);
class UIEntity
class UIEntity : public std::enable_shared_from_this<UIEntity>
{
public:
uint64_t serial_number = 0; // For Python object cache