- [FIX] He pogut evitar la major part dels parpadejos de ordenar actors

This commit is contained in:
2024-06-19 11:21:02 +02:00
parent f6231a6f5c
commit 6adc44e9d6
3 changed files with 39 additions and 17 deletions

View File

@@ -345,8 +345,20 @@ namespace actor
selected = act;
}
const bool isInFront(actor_t *act1, actor_t *act2) {
const bool overlap(actor_t *act1, actor_t *act2)
{
return act1->inner_x < act2->inner_x+act2->bmp_rect.w &&
act1->inner_x+act1->bmp_rect.w > act2->inner_x &&
act1->inner_y > act2->inner_y+act2->bmp_rect.h &&
act1->inner_y+act1->bmp_rect.h < act2->inner_y;
}
const bool isInFront(actor_t *act1, actor_t *act2)
{
return (act1->pos.x >= act2->pos.x+act2->size.x) ||
(act1->pos.y >= act2->pos.y+act2->size.y) ||
(act1->pos.z >= act2->pos.z+act2->size.z);
/*
if (act1->pos.x >= act2->pos.x+act2->size.x) { return true; }
else if (act2->pos.x >= act1->pos.x+act1->size.x) { return false; }
else if (act1->pos.y >= act2->pos.y+act2->size.y) { return true; }
@@ -354,6 +366,7 @@ namespace actor
else if (act1->pos.z >= act2->pos.z+act2->size.z) { return true; }
else if (act2->pos.z >= act1->pos.z+act1->size.z) { return false; }
else { return false; }
*/
}
void reorder()
@@ -363,22 +376,15 @@ namespace actor
while (dirty)
{
dirty->inner_x = 148-dirty->bmp_offset.x + dirty->pos.x*2 - dirty->pos.y*2;
dirty->inner_y = 91-dirty->bmp_offset.y + dirty->pos.x + dirty->pos.y - dirty->pos.z*2;
if (first)
{
actor_t *current = first;
while (true)
{
if (isInFront(current, dirty))
{
dirty->prev = current->prev;
current->prev = dirty;
if (dirty->prev) dirty->prev->next = dirty;
dirty = dirty->next;
current->prev->next = current;
if (current==first) first=current->prev;
break;
}
else
if (overlap(dirty, current) || isInFront(dirty, current))
{
if (current->next)
{
@@ -393,6 +399,16 @@ namespace actor
break;
}
}
else
{
dirty->prev = current->prev;
current->prev = dirty;
if (dirty->prev) dirty->prev->next = dirty;
dirty = dirty->next;
current->prev->next = current;
if (current==first) first=current->prev;
break;
}
}
}
else
@@ -909,8 +925,8 @@ namespace actor
if (!editor::isEditing() || ( (act->flags&FLAG_HERO)==0))
{
const int x = 148-act->bmp_offset.x + act->pos.x*2 - act->pos.y*2;
const int y = 91-act->bmp_offset.y + act->pos.x + act->pos.y - act->pos.z*2;
const int x = act->inner_x; // 148-act->bmp_offset.x + act->pos.x*2 - act->pos.y*2;
const int y = act->inner_y; // 91-act->bmp_offset.y + act->pos.x + act->pos.y - act->pos.z*2;
const bool flip = ( (act->flags & FLAG_ORIENTABLE) && (act->orient==PUSH_XN || act->orient==PUSH_YP) ) ? DRAW_FLIP_HORIZONTAL : DRAW_FLIP_NONE;
const int oo = ( (act->flags & FLAG_ORIENTABLE) && (act->orient==PUSH_XN || act->orient==PUSH_YN) ) ? act->bmp_rect.h : 0;
@@ -1037,6 +1053,9 @@ namespace actor
picked = act;
picked->pos.x=36;
picked->pos.y=82;
picked->inner_x = 148-act->bmp_offset.x + act->pos.x*2 - act->pos.y*2;
picked->inner_y = 91-act->bmp_offset.y + act->pos.x + act->pos.y - act->pos.z*2;
}
actor_t *getPicked() { return picked; }

View File

@@ -76,6 +76,9 @@ namespace actor
actor_t *prev;
actor_t *next;
int inner_x;
int inner_y;
};
// Torna el primer actor de la llista

View File

@@ -354,14 +354,14 @@ bool game::loop()
actor::update(actor::getFirst());
}
actor::reorder();
editor_select_by_keyboard();
draw::resetViewport();
draw::cls(2);
draw::setViewport(100,0,320,240);
actor::reorder();
editor_select_by_keyboard();
room::draw();
actor::draw(actor::getFirst());
room::draw2();