90 lines
2.5 KiB
C++
90 lines
2.5 KiB
C++
#include "actor.h"
|
|
#include "jdraw.h"
|
|
|
|
namespace actor
|
|
{
|
|
actor_t *first = nullptr;
|
|
actor_t *dirty = nullptr;
|
|
|
|
actor_t *getFirst()
|
|
{
|
|
return first;
|
|
}
|
|
|
|
actor_t *create(pos_t p, size_t s, SDL_Rect r, SDL_Point o)
|
|
{
|
|
actor_t *act = (actor_t*)malloc(sizeof(actor_t));
|
|
act->pos = p;
|
|
act->size = s;
|
|
act->bmp_rect = r;
|
|
act->bmp_offset = o;
|
|
act->prev = act->next = nullptr;
|
|
return act;
|
|
}
|
|
|
|
void setDirty(actor_t *act)
|
|
{
|
|
if (act->prev) act->prev->next = act->next;
|
|
if (act->next) act->next->prev = act->prev;
|
|
if (act == first) first = act->next;
|
|
|
|
act->next = dirty;
|
|
dirty = act;
|
|
}
|
|
|
|
void reorder()
|
|
{
|
|
while (dirty)
|
|
{
|
|
const int z_index = dirty->pos.x + dirty->pos.y + dirty->pos.z;
|
|
if (first)
|
|
{
|
|
actor_t *current = first;
|
|
while (true)
|
|
{
|
|
const int z_index2 = current->pos.x + current->pos.y + current->pos.z;
|
|
if (z_index > z_index2)
|
|
{
|
|
if (current->next)
|
|
{
|
|
current = current->next;
|
|
}
|
|
else
|
|
{
|
|
current->next = dirty;
|
|
dirty = dirty->next;
|
|
current->next->prev = current;
|
|
current->next->next = nullptr;
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
dirty->prev = current->prev;
|
|
current->prev = dirty;
|
|
if (dirty->prev) dirty->prev->next = dirty;
|
|
dirty = dirty->next;
|
|
current->prev->next = current;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
first = dirty;
|
|
dirty = dirty->next;
|
|
first->prev=first->next=nullptr;
|
|
}
|
|
}
|
|
}
|
|
|
|
void draw(actor_t *act, const bool draw_all)
|
|
{
|
|
if (!act) return;
|
|
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;
|
|
draw::draw(x, y, act->bmp_rect.w, act->bmp_rect.h, act->bmp_rect.x, act->bmp_rect.y);
|
|
if (draw_all && act->next) draw(act->next);
|
|
}
|
|
|
|
} |