631 |
void shadow_blit (px::Surface *scr, int x, int y, |
void shadow_blit (px::Surface *scr, int x, int y, |
632 |
px::Surface *shadows, px::Rect r); |
px::Surface *shadows, px::Rect r); |
633 |
|
|
634 |
|
Surface *new_surface(); |
635 |
|
void dispose_surface(Surface *s); |
636 |
Surface *get_cache(int x, int y); |
Surface *get_cache(int x, int y); |
637 |
void draw_stone_shade(GC &gc, int x, int y, Field &f); |
void draw_stone_shade(GC &gc, int x, int y, Field &f); |
638 |
|
|
641 |
Uint32 shadow_ckey; // Color key |
Uint32 shadow_ckey; // Color key |
642 |
Array2<Surface *> m_gridcache; |
Array2<Surface *> m_gridcache; |
643 |
vector<Surface *> m_surface_avail; |
vector<Surface *> m_surface_avail; |
644 |
|
Surface *buffer; |
645 |
}; |
}; |
646 |
|
|
647 |
class ShadowLayer_Stippled : public ShadowLayer { |
class ShadowLayer_Stippled : public ShadowLayer { |
660 |
ShadowLayer_Alpha::ShadowLayer_Alpha() |
ShadowLayer_Alpha::ShadowLayer_Alpha() |
661 |
: m_gridcache() |
: m_gridcache() |
662 |
{ |
{ |
663 |
|
SDL_Surface *ss = SDL_CreateRGBSurface(SDL_SWSURFACE, |
664 |
|
TileWidth, TileHeight, |
665 |
|
16,0,0,0,0); |
666 |
|
SDL_SetColorKey(ss, SDL_SRCCOLORKEY, |
667 |
|
SDL_MapRGB(ss->format, 255,255,255)); |
668 |
|
SDL_SetAlpha(ss, SDL_SRCALPHA, 128); |
669 |
|
buffer = new Surface(ss); |
670 |
} |
} |
671 |
|
|
672 |
ShadowLayer_Alpha::~ShadowLayer_Alpha() |
ShadowLayer_Alpha::~ShadowLayer_Alpha() |
680 |
{ |
{ |
681 |
Array2<Surface*>::iterator i; |
Array2<Surface*>::iterator i; |
682 |
for (i=m_gridcache.begin();i!=m_gridcache.end(); ++i) |
for (i=m_gridcache.begin();i!=m_gridcache.end(); ++i) |
683 |
if (*i) |
dispose_surface(*i); |
|
m_surface_avail.push_back(*i); |
|
684 |
m_gridcache.resize(w,h); |
m_gridcache.resize(w,h); |
685 |
} |
} |
686 |
|
|
687 |
Surface * |
Surface * |
688 |
|
ShadowLayer_Alpha::new_surface() |
689 |
|
{ |
690 |
|
Surface *s = 0; |
691 |
|
if (m_surface_avail.empty()) { |
692 |
|
SDL_Surface *ss = SDL_CreateRGBSurface(SDL_SWSURFACE, |
693 |
|
TileWidth, TileHeight, |
694 |
|
16,0,0,0,0); |
695 |
|
// #if 0 |
696 |
|
// SDL_SetColorKey(ss, SDL_SRCCOLORKEY | SDL_RLEACCEL, |
697 |
|
// SDL_MapRGB(ss->format, 255,255,255)); |
698 |
|
// SDL_SetAlpha(ss, SDL_SRCALPHA | SDL_RLEACCEL, 128); |
699 |
|
// #else |
700 |
|
// SDL_SetColorKey(ss, SDL_SRCCOLORKEY, |
701 |
|
// SDL_MapRGB(ss->format, 255,255,255)); |
702 |
|
// SDL_SetAlpha(ss, SDL_SRCALPHA, 128); |
703 |
|
// #endif |
704 |
|
s = new Surface(SDL_DisplayFormat(ss)); |
705 |
|
SDL_FreeSurface(ss); |
706 |
|
} else { |
707 |
|
s = m_surface_avail.back(); |
708 |
|
m_surface_avail.pop_back(); |
709 |
|
} |
710 |
|
return s; |
711 |
|
} |
712 |
|
|
713 |
|
void |
714 |
|
ShadowLayer_Alpha::dispose_surface(Surface *s) |
715 |
|
{ |
716 |
|
if (s) |
717 |
|
m_surface_avail.push_back(s); |
718 |
|
} |
719 |
|
|
720 |
|
|
721 |
|
Surface * |
722 |
ShadowLayer_Alpha::get_cache(int x, int y) |
ShadowLayer_Alpha::get_cache(int x, int y) |
723 |
{ |
{ |
724 |
Surface *s= m_gridcache(x,y); |
Surface *s= m_gridcache(x,y); |
725 |
if (!s) { |
if (!s) |
726 |
if (m_surface_avail.empty()) { |
m_gridcache(x,y) = s = new_surface(); |
|
SDL_Surface *ss = SDL_CreateRGBSurface(SDL_SWSURFACE, |
|
|
TileWidth, TileHeight, |
|
|
16,0,0,0,0); |
|
|
#if 0 |
|
|
SDL_SetColorKey(ss, SDL_SRCCOLORKEY | SDL_RLEACCEL, |
|
|
SDL_MapRGB(ss->format, 255,255,255)); |
|
|
SDL_SetAlpha(ss, SDL_SRCALPHA | SDL_RLEACCEL, 128); |
|
|
#else |
|
|
SDL_SetColorKey(ss, SDL_SRCCOLORKEY, |
|
|
SDL_MapRGB(ss->format, 255,255,255)); |
|
|
SDL_SetAlpha(ss, SDL_SRCALPHA, 128); |
|
|
#endif |
|
|
s = new Surface(SDL_DisplayFormat(ss)); |
|
|
SDL_FreeSurface(ss); |
|
|
} else { |
|
|
s = m_surface_avail.back(); |
|
|
m_surface_avail.pop_back(); |
|
|
} |
|
|
m_gridcache(x,y) = s; |
|
|
} |
|
727 |
return s; |
return s; |
728 |
} |
} |
729 |
|
|
755 |
draw_stone_shade(gc, 0, -TileHeight, fields(x,y-1)); |
draw_stone_shade(gc, 0, -TileHeight, fields(x,y-1)); |
756 |
draw_stone_shade(gc, 0, 0, fields(x,y)); |
draw_stone_shade(gc, 0, 0, fields(x,y)); |
757 |
|
|
758 |
|
} |
759 |
|
|
760 |
|
void |
761 |
|
ShadowLayer_Alpha::draw(GC &gc, int xpos, int ypos, int x, int y) |
762 |
|
{ |
763 |
|
Surface *s=get_cache(x,y); |
764 |
|
GC gc2(buffer); |
765 |
|
blit (gc2, 0,0,s); |
766 |
|
|
767 |
for (unsigned i=0; i<sprites.size(); ++i) |
for (unsigned i=0; i<sprites.size(); ++i) |
768 |
{ |
{ |
770 |
if (s && s->layer == SPRITE_ACTOR && s->model){ |
if (s && s->layer == SPRITE_ACTOR && s->model){ |
771 |
int sx = static_cast<int>(s->pos[0]*TileWidth)-x*TileWidth; |
int sx = static_cast<int>(s->pos[0]*TileWidth)-x*TileWidth; |
772 |
int sy = static_cast<int>(s->pos[1]*TileWidth)-y*TileHeight; |
int sy = static_cast<int>(s->pos[1]*TileWidth)-y*TileHeight; |
773 |
s->model->draw_shade(gc, sx, sy); |
s->model->draw_shade(gc2, sx, sy); |
774 |
} |
} |
775 |
} |
} |
776 |
} |
blit(gc, xpos, ypos, buffer); |
|
|
|
|
void |
|
|
ShadowLayer_Alpha::draw(GC &gc, int xpos, int ypos, int x, int y) |
|
|
{ |
|
|
Surface *s=get_cache(x,y); |
|
|
blit(gc, xpos, ypos, s); |
|
777 |
} |
} |
778 |
|
|
779 |
void |
void |
1163 |
Sprite *s = sprites[id]; |
Sprite *s = sprites[id]; |
1164 |
int x = int(s->pos[0]); |
int x = int(s->pos[0]); |
1165 |
int y = int(s->pos[1]); |
int y = int(s->pos[1]); |
1166 |
if (s->layer == SPRITE_ACTOR) |
// if (s->layer == SPRITE_ACTOR) |
1167 |
mark_update_area (Rect(x-1, y-1, 3, 3)); |
// mark_update_area (Rect(x-1, y-1, 3, 3)); |
1168 |
else |
// else |
1169 |
mark_redraw_area (Rect(x-1, y-1, 3, 3)); |
mark_redraw_area (Rect(x-1, y-1, 3, 3)); |
1170 |
} |
} |
1171 |
|
|
1264 |
|
|
1265 |
switch (l) { |
switch (l) { |
1266 |
case SPRITE_ACTOR: |
case SPRITE_ACTOR: |
1267 |
|
case SPRITE_DEBRIS: |
1268 |
id = sprites.size(); |
id = sprites.size(); |
1269 |
sprites.push_back(new Sprite(pos,l,m2)); |
sprites.push_back(new Sprite(pos,l,m2)); |
1270 |
break; |
break; |
1283 |
} |
} |
1284 |
} |
} |
1285 |
break; |
break; |
|
case SPRITE_COUNT: // only here to keep the compiler happy |
|
|
break; |
|
1286 |
} |
} |
1287 |
if (m2) { |
if (m2) { |
1288 |
m2->activate(pos[0], pos[1], true); |
m2->activate(pos[0], pos[1], true); |
1511 |
|
|
1512 |
if (display_flags & SHOW_FLOOR) draw_model(gc, xpos, ypos, f.layers[GRID_FLOOR]); |
if (display_flags & SHOW_FLOOR) draw_model(gc, xpos, ypos, f.layers[GRID_FLOOR]); |
1513 |
if (display_flags & SHOW_ITEMS) draw_model(gc, xpos, ypos, f.layers[GRID_ITEMS]); |
if (display_flags & SHOW_ITEMS) draw_model(gc, xpos, ypos, f.layers[GRID_ITEMS]); |
1514 |
|
if (display_flags & SHOW_SPRITES) draw_sprites(SPRITE_DEBRIS, false, gc); |
1515 |
if (display_flags & SHOW_SHADES) shadow_layer->draw(gc, xpos, ypos, x, y); |
if (display_flags & SHOW_SHADES) shadow_layer->draw(gc, xpos, ypos, x, y); |
1516 |
if (display_flags & SHOW_SPRITES) draw_sprites(SPRITE_ACTOR, false, gc); |
if (display_flags & SHOW_SPRITES) draw_sprites(SPRITE_ACTOR, false, gc); |
1517 |
if (display_flags & SHOW_STONES) draw_model(gc, xpos, ypos, f.layers[GRID_STONES]); |
if (display_flags & SHOW_STONES) draw_model(gc, xpos, ypos, f.layers[GRID_STONES]); |