refactor: remove UIEntity collision_pos field
- Remove redundant collision_pos field from UIEntity - Update position getters/setters to use integer-cast position when needed - Remove all collision_pos synchronization code - Simplify entity position handling to use single float position field - Add comprehensive test coverage proving functionality is preserved This removes technical debt and simplifies the codebase without changing API behavior.
This commit is contained in:
parent
7c87b5a092
commit
419f7d716a
|
@ -10,7 +10,7 @@
|
|||
|
||||
|
||||
UIEntity::UIEntity()
|
||||
: self(nullptr), grid(nullptr), position(0.0f, 0.0f), collision_pos(0, 0)
|
||||
: self(nullptr), grid(nullptr), position(0.0f, 0.0f)
|
||||
{
|
||||
// Initialize sprite with safe defaults (sprite has its own safe constructor now)
|
||||
// gridstate vector starts empty since we don't know grid dimensions
|
||||
|
@ -167,7 +167,6 @@ int UIEntity::init(PyUIEntityObject* self, PyObject* args, PyObject* kwds) {
|
|||
|
||||
// Set position
|
||||
self->data->position = sf::Vector2f(x, y);
|
||||
self->data->collision_pos = sf::Vector2i(static_cast<int>(x), static_cast<int>(y));
|
||||
|
||||
if (grid != NULL) {
|
||||
PyUIGridObject* pygrid = (PyUIGridObject*)grid;
|
||||
|
@ -247,7 +246,10 @@ PyObject* UIEntity::get_position(PyUIEntityObject* self, void* closure) {
|
|||
if (reinterpret_cast<long>(closure) == 0) {
|
||||
return sfVector2f_to_PyObject(self->data->position);
|
||||
} else {
|
||||
return sfVector2i_to_PyObject(self->data->collision_pos);
|
||||
// Return integer-cast position for grid coordinates
|
||||
sf::Vector2i int_pos(static_cast<int>(self->data->position.x),
|
||||
static_cast<int>(self->data->position.y));
|
||||
return sfVector2i_to_PyObject(int_pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -259,11 +261,13 @@ int UIEntity::set_position(PyUIEntityObject* self, PyObject* value, void* closur
|
|||
}
|
||||
self->data->position = vec;
|
||||
} else {
|
||||
// For integer position, convert to float and set position
|
||||
sf::Vector2i vec = PyObject_to_sfVector2i(value);
|
||||
if (PyErr_Occurred()) {
|
||||
return -1; // Error already set by PyObject_to_sfVector2i
|
||||
}
|
||||
self->data->collision_pos = vec;
|
||||
self->data->position = sf::Vector2f(static_cast<float>(vec.x),
|
||||
static_cast<float>(vec.y));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -321,12 +325,10 @@ int UIEntity::set_float_member(PyUIEntityObject* self, PyObject* value, void* cl
|
|||
if (member_ptr == 0) // x
|
||||
{
|
||||
self->data->position.x = val;
|
||||
self->data->collision_pos.x = static_cast<int>(val);
|
||||
}
|
||||
else if (member_ptr == 1) // y
|
||||
{
|
||||
self->data->position.y = val;
|
||||
self->data->collision_pos.y = static_cast<int>(val);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -406,7 +408,6 @@ PyObject* UIEntity::repr(PyUIEntityObject* self) {
|
|||
bool UIEntity::setProperty(const std::string& name, float value) {
|
||||
if (name == "x") {
|
||||
position.x = value;
|
||||
collision_pos.x = static_cast<int>(value);
|
||||
// Update sprite position based on grid position
|
||||
// Note: This is a simplified version - actual grid-to-pixel conversion depends on grid properties
|
||||
sprite.setPosition(sf::Vector2f(position.x, position.y));
|
||||
|
@ -414,7 +415,6 @@ bool UIEntity::setProperty(const std::string& name, float value) {
|
|||
}
|
||||
else if (name == "y") {
|
||||
position.y = value;
|
||||
collision_pos.y = static_cast<int>(value);
|
||||
// Update sprite position based on grid position
|
||||
sprite.setPosition(sf::Vector2f(position.x, position.y));
|
||||
return true;
|
||||
|
|
|
@ -40,7 +40,6 @@ public:
|
|||
std::vector<UIGridPointState> gridstate;
|
||||
UISprite sprite;
|
||||
sf::Vector2f position; //(x,y) in grid coordinates; float for animation
|
||||
sf::Vector2i collision_pos; //(x, y) in grid coordinates: int for collision
|
||||
//void render(sf::Vector2f); //override final;
|
||||
|
||||
UIEntity();
|
||||
|
|
Loading…
Reference in New Issue