Skip to content

Commit

Permalink
Sprites: remove void* vptr member
Browse files Browse the repository at this point in the history
  • Loading branch information
bradallred committed Jun 16, 2013
1 parent b6e2900 commit c8cf5a7
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 34 deletions.
5 changes: 2 additions & 3 deletions gemrb/core/Sprite2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ namespace GemRB {

const TypeID Sprite2D::ID = { "Sprite2D" };

Sprite2D::Sprite2D(int Width, int Height, int Bpp, void* vptr, const void* pixels)
: Width(Width), Height(Height), Bpp(Bpp), vptr(vptr), pixels(pixels)
Sprite2D::Sprite2D(int Width, int Height, int Bpp, const void* pixels)
: Width(Width), Height(Height), Bpp(Bpp), pixels(pixels)
{
BAM = false;
XPos = 0;
Expand All @@ -43,7 +43,6 @@ Sprite2D::Sprite2D(const Sprite2D &obj)
{
BAM = false;
RefCount = 1;
vptr = obj.vptr; // TODO: vptr is deprecated

XPos = obj.XPos;
YPos = obj.YPos;
Expand Down
5 changes: 2 additions & 3 deletions gemrb/core/Sprite2D.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,13 @@ class GEM_EXPORT Sprite2D {
int RefCount;
public:
int XPos, YPos, Width, Height, Bpp;
/** Pointer to the Driver Video Structure */
void* vptr;

bool BAM;
bool RLE; // in theory this could apply to more than BAMs, but currently does not.
ieDword renderFlags;
const void* pixels;

Sprite2D(int Width, int Height, int Bpp, void* vptr, const void* pixels);
Sprite2D(int Width, int Height, int Bpp, const void* pixels);
Sprite2D(const Sprite2D &obj);
virtual Sprite2D* copy() const = 0;
virtual ~Sprite2D();
Expand Down
4 changes: 1 addition & 3 deletions gemrb/plugins/BAMImporter/BAMSprite2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace GemRB {
BAMSprite2D::BAMSprite2D(int Width, int Height, const void* pixels,
bool rle, AnimationFactory* datasrc,
Palette* palette, ieDword ck)
: Sprite2D(Width, Height, 8, NULL, pixels)
: Sprite2D(Width, Height, 8, pixels)
{
palette->acquire();
pal = palette;
Expand All @@ -36,7 +36,6 @@ BAMSprite2D::BAMSprite2D(int Width, int Height, const void* pixels,
source = datasrc;
datasrc->IncDataRefCount();
BAM = true;
vptr = this;
}

BAMSprite2D::BAMSprite2D(const BAMSprite2D &obj)
Expand All @@ -52,7 +51,6 @@ BAMSprite2D::BAMSprite2D(const BAMSprite2D &obj)
source = obj.source;
source->IncDataRefCount();
BAM = true;
vptr = this;
}

BAMSprite2D* BAMSprite2D::copy() const
Expand Down
7 changes: 2 additions & 5 deletions gemrb/plugins/SDLVideo/SDLSurfaceSprite2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@
namespace GemRB {

SDLSurfaceSprite2D::SDLSurfaceSprite2D(int Width, int Height, int Bpp, void* pixels)
: Sprite2D(Width, Height, Bpp, NULL, pixels)
: Sprite2D(Width, Height, Bpp, pixels)
{
surface = SDL_CreateRGBSurfaceFrom( pixels, Width, Height, Bpp < 8 ? 8 : Bpp, Width * ( Bpp / 8 ),
0, 0, 0, 0 );
vptr = surface;
freePixels = true;
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_SetSurfaceRLE(surface, SDL_TRUE);
Expand All @@ -40,11 +39,10 @@ SDLSurfaceSprite2D::SDLSurfaceSprite2D(int Width, int Height, int Bpp, void* pix

SDLSurfaceSprite2D::SDLSurfaceSprite2D (int Width, int Height, int Bpp, void* pixels,
Uint32 rmask, Uint32 gmask, Uint32 bmask, Uint32 amask)
: Sprite2D(Width, Height, Bpp, NULL, pixels)
: Sprite2D(Width, Height, Bpp, pixels)
{
surface = SDL_CreateRGBSurfaceFrom( pixels, Width, Height, Bpp < 8 ? 8 : Bpp, Width * ( Bpp / 8 ),
rmask, gmask, bmask, amask );
vptr = surface;
freePixels = true;
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_SetSurfaceRLE(surface, SDL_TRUE);
Expand All @@ -57,7 +55,6 @@ SDLSurfaceSprite2D::SDLSurfaceSprite2D(const SDLSurfaceSprite2D &obj)
surface = SDL_ConvertSurface(obj.surface, obj.surface->format, obj.surface->flags);
pixels = surface->pixels;
freePixels = false;
vptr = surface;
#if SDL_VERSION_ATLEAST(1,3,0)
SDL_SetSurfaceRLE(surface, SDL_TRUE);
#endif
Expand Down
33 changes: 13 additions & 20 deletions gemrb/plugins/SDLVideo/SDLVideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,6 @@ void SDLVideoDriver::BlitTile(const Sprite2D* spr, const Sprite2D* mask, int x,
void SDLVideoDriver::BlitSprite(const Sprite2D* spr, int x, int y, bool anchor,
const Region* clip, Palette* palette)
{
if (!spr->vptr) return;

int tx = x - spr->XPos;
int ty = y - spr->YPos;
if (!anchor) {
Expand Down Expand Up @@ -615,17 +613,14 @@ void SDLVideoDriver::BlitSprite(const Sprite2D* spr, int x, int y, bool anchor,
srect = &t;

}
SDL_Surface* surf = ((SDLSurfaceSprite2D*)spr)->GetSurface();
if (palette) {
// FIXME: casting away const to temporarily change the palette for the
// blit opperation. this is no diffrent than what we did before with the
// vptr, and the end result leavs the sprite unchanged, but is there a better way?
Palette* tmpPal = spr->GetPalette();
((Sprite2D*)spr)->SetPalette(palette);
SDL_BlitSurface( ( SDL_Surface * ) spr->vptr, srect, backBuf, &drect );
((Sprite2D*)spr)->SetPalette(tmpPal);
tmpPal->release();
SDL_Color* palColors = (SDL_Color*)spr->GetPaletteColors();
SDLSurfaceSprite2D::SetSurfacePalette(surf, (SDL_Color*)palette->col);
SDL_BlitSurface( surf, srect, backBuf, &drect );
SDLSurfaceSprite2D::SetSurfacePalette(surf, palColors);
} else {
SDL_BlitSurface( ( SDL_Surface * ) spr->vptr, srect, backBuf, &drect );
SDL_BlitSurface( surf, srect, backBuf, &drect );
}
} else {
const Uint8* srcdata = (const Uint8*)spr->pixels;
Expand Down Expand Up @@ -669,10 +664,9 @@ void SDLVideoDriver::BlitGameSprite(const Sprite2D* spr, int x, int y,
const Region* clip, bool anchor)
{
assert(spr);
if (!spr->vptr) return;

if (!spr->BAM) {
SDL_Surface* surf = ( SDL_Surface * ) spr->vptr;
SDL_Surface* surf = ((SDLSurfaceSprite2D*)spr)->GetSurface();
if (surf->format->BytesPerPixel != 4 && surf->format->BytesPerPixel != 1) {
// TODO...
Log(ERROR, "SDLVideo", "BlitGameSprite not supported for this sprite");
Expand Down Expand Up @@ -881,8 +875,7 @@ void SDLVideoDriver::BlitGameSprite(const Sprite2D* spr, int x, int y,
}

const Color *col = 0;

SDL_Surface* surf = ( SDL_Surface * ) spr->vptr;
const SDL_Surface* surf = ((SDLSurfaceSprite2D*)spr)->GetSurface();
if (surf->format->BytesPerPixel == 1) {

if (remflags & BLIT_TINTED)
Expand Down Expand Up @@ -942,8 +935,8 @@ Sprite2D* SDLVideoDriver::GetScreenshot( Region r )
SDL_Rect src = {(Sint16)r.x, (Sint16)r.y, (Uint16)r.w, (Uint16)r.h};

void* pixels = malloc( Width * Height * 3 );
Sprite2D* screenshot = CreateSprite( Width, Height, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000, pixels, false, 0 );
SDL_BlitSurface( backBuf, (r.w && r.h) ? &src : NULL, (SDL_Surface*)screenshot->vptr, NULL);
SDLSurfaceSprite2D* screenshot = (SDLSurfaceSprite2D*)CreateSprite( Width, Height, 24, 0x00ff0000, 0x0000ff00, 0x000000ff, 0x00000000, pixels);
SDL_BlitSurface( backBuf, (r.w && r.h) ? &src : NULL, (SDL_Surface*)screenshot->GetSurface(), NULL);

return screenshot;
}
Expand Down Expand Up @@ -1001,7 +994,7 @@ void SDLVideoDriver::DrawRectSprite(const Region& rgn, const Color& color, const
return;
}

SDL_Surface* surf = ( SDL_Surface* ) sprite->vptr;
SDL_Surface* surf = ((SDLSurfaceSprite2D*)sprite)->GetSurface();
SDL_Rect drect = {
(Sint16)rgn.x, (Sint16)rgn.y, (Uint16)rgn.w, (Uint16)rgn.h
};
Expand Down Expand Up @@ -1519,7 +1512,7 @@ void SDLVideoDriver::DrawPolyline(Gem_Polygon* poly, const Color& color, bool fi

Sprite2D *SDLVideoDriver::MirrorSpriteVertical(const Sprite2D* sprite, bool MirrorAnchor)
{
if (!sprite || !sprite->vptr)
if (!sprite)
return NULL;

Sprite2D* dest = DuplicateSprite(sprite);
Expand Down Expand Up @@ -1553,7 +1546,7 @@ Sprite2D *SDLVideoDriver::MirrorSpriteVertical(const Sprite2D* sprite, bool Mirr
// flips its anchor (i.e. origin//base point) as well
Sprite2D *SDLVideoDriver::MirrorSpriteHorizontal(const Sprite2D* sprite, bool MirrorAnchor)
{
if (!sprite || !sprite->vptr)
if (!sprite)
return NULL;

Sprite2D* dest = DuplicateSprite(sprite);
Expand Down

0 comments on commit c8cf5a7

Please sign in to comment.