This commit is contained in:
DepressedTWM 2026-05-18 23:40:43 +04:00
parent a6e2dc795a
commit 8fce0cdc18
7 changed files with 85 additions and 190 deletions

View File

@ -55,10 +55,7 @@ struct ALDataSource{
virtual bool setPitch(float value) = 0; virtual bool setPitch(float value) = 0;
}; };
ALDataSource *createSDLSource(SDL_IOStream &ops, ALDataSource *createSDLSource(SDL_IOStream &ops, const char *extension, uint32_t maxBufSize, bool looped);
const char *extension,
uint32_t maxBufSize,
bool looped);
ALDataSource *createVorbisSource(SDL_IOStream &ops, ALDataSource *createVorbisSource(SDL_IOStream &ops,
bool looped); bool looped);

View File

@ -267,8 +267,7 @@ void ALStream::startStream(float offset){
startOffset = offset; startOffset = offset;
procFrames = offset * source->sampleRate(); procFrames = offset * source->sampleRate();
thread = createSDLThread thread = createSDLThread<ALStream, &ALStream::streamData>(this, threadName);
<ALStream, &ALStream::streamData>(this, threadName);
} }
void ALStream::pauseStream(){ void ALStream::pauseStream(){
@ -328,9 +327,8 @@ void ALStream::streamData(){
if (threadTermReq) if (threadTermReq)
return; return;
if (needsRewind){ if (needsRewind)
source->seekToOffset(startOffset); source->seekToOffset(startOffset);
}
for (int i = 0; i < STREAM_BUFS; ++i){ for (int i = 0; i < STREAM_BUFS; ++i){
if (threadTermReq) if (threadTermReq)

View File

@ -79,8 +79,7 @@ struct AudioPrivate{
current_bgs_volume = 100; current_bgs_volume = 100;
current_me_volume = 100; current_me_volume = 100;
meWatch.state = MeNotPlaying; meWatch.state = MeNotPlaying;
meWatch.thread = createSDLThread meWatch.thread = createSDLThread<AudioPrivate, &AudioPrivate::meWatchFun>(this, "audio_mewatch");
<AudioPrivate, &AudioPrivate::meWatchFun>(this, "audio_mewatch");
} }
~AudioPrivate(){ ~AudioPrivate(){

View File

@ -117,10 +117,7 @@ struct AudioStream{
const std::string &threadId); const std::string &threadId);
~AudioStream(); ~AudioStream();
void play(const std::string &filename, void play(const std::string &filename, int volume, int pitch, float offset = 0);
int volume,
int pitch,
float offset = 0);
void stop(); void stop();
void fadeOut(int duration); void fadeOut(int duration);

View File

@ -1,7 +1,6 @@
struct StaticRect { float x, y, w, h; }; struct StaticRect { float x, y, w, h; };
extern const StaticRect autotileRects[] = extern const StaticRect autotileRects[] = {
{
{ 32.5, 64.5, 15, 15 }, { 32.5, 64.5, 15, 15 },
{ 48.5, 64.5, 15, 15 }, { 48.5, 64.5, 15, 15 },
{ 32.5, 80.5, 15, 15 }, { 32.5, 80.5, 15, 15 },

View File

@ -109,32 +109,27 @@ struct BitmapPrivate{
pixman_region_init(&tainted); pixman_region_init(&tainted);
} }
~BitmapPrivate() ~BitmapPrivate(){
{
//SDL_DeleteFormat(format); //SDL_DeleteFormat(format);
pixman_region_fini(&tainted); pixman_region_fini(&tainted);
} }
void allocSurface() void allocSurface(){
{
surface = SDL_CreateSurface(gl.width, gl.height, format->format); surface = SDL_CreateSurface(gl.width, gl.height, format->format);
} }
void clearTaintedArea() void clearTaintedArea(){
{
pixman_region_fini(&tainted); pixman_region_fini(&tainted);
pixman_region_init(&tainted); pixman_region_init(&tainted);
} }
void addTaintedArea(const IntRect &rect) void addTaintedArea(const IntRect &rect){
{
IntRect norm = normalizedRect(rect); IntRect norm = normalizedRect(rect);
pixman_region_union_rect pixman_region_union_rect
(&tainted, &tainted, norm.x, norm.y, norm.w, norm.h); (&tainted, &tainted, norm.x, norm.y, norm.w, norm.h);
} }
void substractTaintedArea(const IntRect &rect) void substractTaintedArea(const IntRect &rect){
{
if (!touchesTaintedArea(rect)) if (!touchesTaintedArea(rect))
return; return;
@ -146,8 +141,7 @@ struct BitmapPrivate{
pixman_region_fini(&m_reg); pixman_region_fini(&m_reg);
} }
bool touchesTaintedArea(const IntRect &rect) bool touchesTaintedArea(const IntRect &rect){
{
pixman_box16_t box; pixman_box16_t box;
box.x1 = rect.x; box.x1 = rect.x;
box.y1 = rect.y; box.y1 = rect.y;
@ -160,38 +154,29 @@ struct BitmapPrivate{
return result != PIXMAN_REGION_OUT; return result != PIXMAN_REGION_OUT;
} }
void bindTexture(ShaderBase &shader) void bindTexture(ShaderBase &shader){
{
TEX::bind(gl.tex); TEX::bind(gl.tex);
shader.setTexSize(Vec2i(gl.width, gl.height)); shader.setTexSize(Vec2i(gl.width, gl.height));
} }
void bindFBO() void bindFBO(){ FBO::bind(gl.fbo); }
{
FBO::bind(gl.fbo);
}
void pushSetViewport(ShaderBase &shader) const void pushSetViewport(ShaderBase &shader) const{
{
glState.viewport.pushSet(IntRect(0, 0, gl.width, gl.height)); glState.viewport.pushSet(IntRect(0, 0, gl.width, gl.height));
shader.applyViewportProj(); shader.applyViewportProj();
} }
void popViewport() const void popViewport() const{
{
glState.viewport.pop(); glState.viewport.pop();
} }
void blitQuad(Quad &quad) void blitQuad(Quad &quad){
{
glState.blend.pushSet(false); glState.blend.pushSet(false);
quad.draw(); quad.draw();
glState.blend.pop(); glState.blend.pop();
} }
void fillRect(const IntRect &rect, void fillRect(const IntRect &rect, const Vec4 &color) {
const Vec4 &color)
{
bindFBO(); bindFBO();
glState.scissorTest.pushSet(true); glState.scissorTest.pushSet(true);
@ -205,8 +190,7 @@ struct BitmapPrivate{
glState.scissorTest.pop(); glState.scissorTest.pop();
} }
static void ensureFormat(SDL_Surface *&surf, SDL_PixelFormat format) static void ensureFormat(SDL_Surface *&surf, SDL_PixelFormat format){
{
if (surf->format == format) if (surf->format == format)
return; return;
@ -215,10 +199,8 @@ struct BitmapPrivate{
surf = surfConv; surf = surfConv;
} }
void onModified(bool freeSurface = true) void onModified(bool freeSurface = true){
{ if (surface && freeSurface){
if (surface && freeSurface)
{
SDL_DestroySurface(surface); SDL_DestroySurface(surface);
surface = 0; surface = 0;
} }
@ -227,23 +209,20 @@ struct BitmapPrivate{
} }
}; };
struct BitmapOpenHandler : FileSystem::OpenHandler struct BitmapOpenHandler : FileSystem::OpenHandler{
{
SDL_Surface *surf; SDL_Surface *surf;
BitmapOpenHandler() BitmapOpenHandler()
: surf(0) : surf(0)
{} {}
bool tryRead(SDL_IOStream* &ops, const char *ext) bool tryRead(SDL_IOStream* &ops, const char *ext){
{
surf = IMG_LoadTyped_IO(ops, 1, ext); surf = IMG_LoadTyped_IO(ops, 1, ext);
return surf != 0; return surf != 0;
} }
}; };
Bitmap::Bitmap(const char *filename) Bitmap::Bitmap(const char *filename){
{
BitmapOpenHandler handler; BitmapOpenHandler handler;
shState->fileSystem().openRead(handler, filename); shState->fileSystem().openRead(handler, filename);
SDL_Surface *imgSurf = handler.surf; SDL_Surface *imgSurf = handler.surf;
@ -254,24 +233,20 @@ Bitmap::Bitmap(const char *filename)
p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888); p->ensureFormat(imgSurf, SDL_PIXELFORMAT_ABGR8888);
if (imgSurf->w > glState.caps.maxTexSize || imgSurf->h > glState.caps.maxTexSize) if (imgSurf->w > glState.caps.maxTexSize || imgSurf->h > glState.caps.maxTexSize){
{
/* Mega surface */ /* Mega surface */
p = new BitmapPrivate(this); p = new BitmapPrivate(this);
p->megaSurface = imgSurf; p->megaSurface = imgSurf;
SDL_SetSurfaceBlendMode(p->megaSurface, SDL_BLENDMODE_NONE); SDL_SetSurfaceBlendMode(p->megaSurface, SDL_BLENDMODE_NONE);
} }
else else{
{
/* Regular surface */ /* Regular surface */
TEXFBO tex; TEXFBO tex;
try try{
{
tex = shState->texPool().request(imgSurf->w, imgSurf->h); tex = shState->texPool().request(imgSurf->w, imgSurf->h);
} }
catch (const Exception &e) catch (const Exception &e){
{
SDL_DestroySurface(imgSurf); SDL_DestroySurface(imgSurf);
throw e; throw e;
} }
@ -288,8 +263,7 @@ Bitmap::Bitmap(const char *filename)
p->addTaintedArea(rect()); p->addTaintedArea(rect());
} }
Bitmap::Bitmap(int width, int height) Bitmap::Bitmap(int width, int height){
{
if (width <= 0 || height <= 0) if (width <= 0 || height <= 0)
throw Exception(Exception::RGSSError, "failed to create bitmap"); throw Exception(Exception::RGSSError, "failed to create bitmap");
@ -301,8 +275,7 @@ Bitmap::Bitmap(int width, int height)
clear(); clear();
} }
Bitmap::Bitmap(const Bitmap &other) Bitmap::Bitmap(const Bitmap &other){
{
other.ensureNonMega(); other.ensureNonMega();
p = new BitmapPrivate(this); p = new BitmapPrivate(this);
@ -312,13 +285,11 @@ Bitmap::Bitmap(const Bitmap &other)
blt(0, 0, other, rect()); blt(0, 0, other, rect());
} }
Bitmap::~Bitmap() Bitmap::~Bitmap(){
{
dispose(); dispose();
} }
int Bitmap::width() const int Bitmap::width() const{
{
guardDisposed(); guardDisposed();
if (p->megaSurface) if (p->megaSurface)
@ -327,8 +298,7 @@ int Bitmap::width() const
return p->gl.width; return p->gl.width;
} }
int Bitmap::height() const int Bitmap::height() const{
{
guardDisposed(); guardDisposed();
if (p->megaSurface) if (p->megaSurface)
@ -337,17 +307,13 @@ int Bitmap::height() const
return p->gl.height; return p->gl.height;
} }
IntRect Bitmap::rect() const IntRect Bitmap::rect() const{
{
guardDisposed(); guardDisposed();
return IntRect(0, 0, width(), height()); return IntRect(0, 0, width(), height());
} }
void Bitmap::blt(int x, int y, void Bitmap::blt(int x, int y, const Bitmap &source, IntRect rect, int opacity){
const Bitmap &source, IntRect rect,
int opacity)
{
if (source.isDisposed()) if (source.isDisposed())
return; return;
@ -367,10 +333,7 @@ void Bitmap::blt(int x, int y,
source, rect, opacity); source, rect, opacity);
} }
void Bitmap::stretchBlt(const IntRect &destRect, void Bitmap::stretchBlt(const IntRect &destRect, const Bitmap &source, const IntRect &sourceRect, int opacity) {
const Bitmap &source, const IntRect &sourceRect,
int opacity)
{
guardDisposed(); guardDisposed();
GUARD_MEGA; GUARD_MEGA;
@ -385,15 +348,13 @@ void Bitmap::stretchBlt(const IntRect &destRect,
SDL_Surface *srcSurf = source.megaSurface(); SDL_Surface *srcSurf = source.megaSurface();
if (srcSurf && shState->config().subImageFix) if (srcSurf && shState->config().subImageFix){
{
/* Blit from software surface, for broken GL drivers */ /* Blit from software surface, for broken GL drivers */
Vec2i gpTexSize; Vec2i gpTexSize;
shState->ensureTexSize(sourceRect.w, sourceRect.h, gpTexSize); shState->ensureTexSize(sourceRect.w, sourceRect.h, gpTexSize);
shState->bindTex(); shState->bindTex();
GLMeta::subRectImageUpload(srcSurf->w, sourceRect.x, sourceRect.y, 0, 0, GLMeta::subRectImageUpload(srcSurf->w, sourceRect.x, sourceRect.y, 0, 0, sourceRect.w, sourceRect.h, srcSurf, GL_RGBA);
sourceRect.w, sourceRect.h, srcSurf, GL_RGBA);
GLMeta::subRectImageEnd(); GLMeta::subRectImageEnd();
SimpleShader &shader = shState->shaders().simple; SimpleShader &shader = shState->shaders().simple;
@ -416,8 +377,7 @@ void Bitmap::stretchBlt(const IntRect &destRect,
return; return;
} }
else if (srcSurf) else if (srcSurf){
{
/* Blit from software surface */ /* Blit from software surface */
/* Don't do transparent blits for now */ /* Don't do transparent blits for now */
if (opacity < 255) if (opacity < 255)
@ -435,22 +395,19 @@ void Bitmap::stretchBlt(const IntRect &destRect,
Uint32 rMask, gMask, bMask, aMask; Uint32 rMask, gMask, bMask, aMask;
SDL_GetMasksForPixelFormat(SDL_PIXELFORMAT_ABGR8888, SDL_GetMasksForPixelFormat(SDL_PIXELFORMAT_ABGR8888,
&bpp, &rMask, &gMask, &bMask, &aMask); &bpp, &rMask, &gMask, &bMask, &aMask);
SDL_Surface *blitTemp = SDL_Surface *blitTemp = SDL_CreateSurface(destRect.w, destRect.h, SDL_GetPixelFormatForMasks(bpp, rMask, gMask, bMask, aMask));
SDL_CreateSurface(destRect.w, destRect.h, SDL_GetPixelFormatForMasks(bpp, rMask, gMask, bMask, aMask));
SDL_BlitSurfaceScaled(srcSurf, &srcRect, blitTemp, NULL, SDL_ScaleMode::SDL_SCALEMODE_NEAREST); SDL_BlitSurfaceScaled(srcSurf, &srcRect, blitTemp, NULL, SDL_ScaleMode::SDL_SCALEMODE_NEAREST);
TEX::bind(p->gl.tex); TEX::bind(p->gl.tex);
if (bltRect.w == dstRect.w && bltRect.h == dstRect.h) if (bltRect.w == dstRect.w && bltRect.h == dstRect.h){
{
/* Dest rectangle lies within bounding box */ /* Dest rectangle lies within bounding box */
TEX::uploadSubImage(destRect.x, destRect.y, TEX::uploadSubImage(destRect.x, destRect.y,
destRect.w, destRect.h, destRect.w, destRect.h,
blitTemp->pixels, GL_RGBA); blitTemp->pixels, GL_RGBA);
} }
else else{
{
/* Clipped blit */ /* Clipped blit */
GLMeta::subRectImageUpload(blitTemp->w, bltRect.x - dstRect.x, bltRect.y - dstRect.y, GLMeta::subRectImageUpload(blitTemp->w, bltRect.x - dstRect.x, bltRect.y - dstRect.y,
bltRect.x, bltRect.y, bltRect.w, bltRect.h, blitTemp, GL_RGBA); bltRect.x, bltRect.y, bltRect.w, bltRect.h, blitTemp, GL_RGBA);
@ -463,16 +420,14 @@ void Bitmap::stretchBlt(const IntRect &destRect,
return; return;
} }
if (opacity == 255 && !p->touchesTaintedArea(destRect)) if (opacity == 255 && !p->touchesTaintedArea(destRect)){
{
/* Fast blit */ /* Fast blit */
GLMeta::blitBegin(p->gl); GLMeta::blitBegin(p->gl);
GLMeta::blitSource(source.p->gl); GLMeta::blitSource(source.p->gl);
GLMeta::blitRectangle(sourceRect, destRect); GLMeta::blitRectangle(sourceRect, destRect);
GLMeta::blitEnd(); GLMeta::blitEnd();
} }
else else{
{
/* Fragment pipeline */ /* Fragment pipeline */
float normOpacity = (float) opacity / 255.0f; float normOpacity = (float) opacity / 255.0f;
@ -511,15 +466,11 @@ void Bitmap::stretchBlt(const IntRect &destRect,
p->onModified(); p->onModified();
} }
void Bitmap::fillRect(int x, int y, void Bitmap::fillRect(int x, int y, int width, int height, const Vec4 &color) {
int width, int height,
const Vec4 &color)
{
fillRect(IntRect(x, y, width, height), color); fillRect(IntRect(x, y, width, height), color);
} }
void Bitmap::fillRect(const IntRect &rect, const Vec4 &color) void Bitmap::fillRect(const IntRect &rect, const Vec4 &color){
{
guardDisposed(); guardDisposed();
GUARD_MEGA; GUARD_MEGA;
@ -536,18 +487,11 @@ void Bitmap::fillRect(const IntRect &rect, const Vec4 &color)
p->onModified(); p->onModified();
} }
void Bitmap::gradientFillRect(int x, int y, void Bitmap::gradientFillRect(int x, int y, int width, int height, const Vec4 &color1, const Vec4 &color2, bool vertical) {
int width, int height,
const Vec4 &color1, const Vec4 &color2,
bool vertical)
{
gradientFillRect(IntRect(x, y, width, height), color1, color2, vertical); gradientFillRect(IntRect(x, y, width, height), color1, color2, vertical);
} }
void Bitmap::gradientFillRect(const IntRect &rect, void Bitmap::gradientFillRect(const IntRect &rect, const Vec4 &color1, const Vec4 &color2, bool vertical) {
const Vec4 &color1, const Vec4 &color2,
bool vertical)
{
guardDisposed(); guardDisposed();
GUARD_MEGA; GUARD_MEGA;
@ -558,15 +502,13 @@ void Bitmap::gradientFillRect(const IntRect &rect,
Quad &quad = shState->gpQuad(); Quad &quad = shState->gpQuad();
if (vertical) if (vertical){
{
quad.vert[0].color = color1; quad.vert[0].color = color1;
quad.vert[1].color = color1; quad.vert[1].color = color1;
quad.vert[2].color = color2; quad.vert[2].color = color2;
quad.vert[3].color = color2; quad.vert[3].color = color2;
} }
else else{
{
quad.vert[0].color = color1; quad.vert[0].color = color1;
quad.vert[3].color = color1; quad.vert[3].color = color1;
quad.vert[1].color = color2; quad.vert[1].color = color2;
@ -587,13 +529,11 @@ void Bitmap::gradientFillRect(const IntRect &rect,
p->onModified(); p->onModified();
} }
void Bitmap::clearRect(int x, int y, int width, int height) void Bitmap::clearRect(int x, int y, int width, int height){
{
clearRect(IntRect(x, y, width, height)); clearRect(IntRect(x, y, width, height));
} }
void Bitmap::clearRect(const IntRect &rect) void Bitmap::clearRect(const IntRect &rect){
{
guardDisposed(); guardDisposed();
GUARD_MEGA; GUARD_MEGA;
@ -603,8 +543,7 @@ void Bitmap::clearRect(const IntRect &rect)
p->onModified(); p->onModified();
} }
void Bitmap::blur() void Bitmap::blur(){
{
guardDisposed(); guardDisposed();
GUARD_MEGA; GUARD_MEGA;
@ -648,8 +587,7 @@ void Bitmap::blur()
p->onModified(); p->onModified();
} }
void Bitmap::radialBlur(int angle, int divisions) void Bitmap::radialBlur(int angle, int divisions){
{
guardDisposed(); guardDisposed();
GUARD_MEGA; GUARD_MEGA;
@ -723,8 +661,7 @@ void Bitmap::radialBlur(int angle, int divisions)
p->pushSetViewport(shader); p->pushSetViewport(shader);
for (int i = 0; i < divisions; ++i) for (int i = 0; i < divisions; ++i){
{
trans.setRotation(baseAngle + i*angleStep); trans.setRotation(baseAngle + i*angleStep);
shader.setMatrix(trans.getMatrix()); shader.setMatrix(trans.getMatrix());
qArray.draw(); qArray.draw();
@ -743,8 +680,7 @@ void Bitmap::radialBlur(int angle, int divisions)
p->onModified(); p->onModified();
} }
void Bitmap::clear() void Bitmap::clear(){
{
guardDisposed(); guardDisposed();
GUARD_MEGA; GUARD_MEGA;
@ -762,16 +698,14 @@ void Bitmap::clear()
p->onModified(); p->onModified();
} }
static uint32_t &getPixelAt(SDL_Surface *surf, SDL_PixelFormatDetails *form, int x, int y) static uint32_t &getPixelAt(SDL_Surface *surf, SDL_PixelFormatDetails *form, int x, int y){
{
size_t offset = x * form->bytes_per_pixel + y * surf->pitch; size_t offset = x * form->bytes_per_pixel + y * surf->pitch;
uint8_t *bytes = (uint8_t*) surf->pixels + offset; uint8_t *bytes = (uint8_t*) surf->pixels + offset;
return *((uint32_t*) bytes); return *((uint32_t*) bytes);
} }
Color Bitmap::getPixel(int x, int y) const Color Bitmap::getPixel(int x, int y) const{
{
guardDisposed(); guardDisposed();
GUARD_MEGA; GUARD_MEGA;
@ -779,8 +713,7 @@ Color Bitmap::getPixel(int x, int y) const
if (x < 0 || y < 0 || x >= width() || y >= height()) if (x < 0 || y < 0 || x >= width() || y >= height())
return Vec4(); return Vec4();
if (!p->surface) if (!p->surface){
{
p->allocSurface(); p->allocSurface();
FBO::bind(p->gl.fbo); FBO::bind(p->gl.fbo);
@ -800,14 +733,12 @@ Color Bitmap::getPixel(int x, int y) const
(pixel >> p->format->Ashift) & 0xFF); (pixel >> p->format->Ashift) & 0xFF);
} }
void Bitmap::setPixel(int x, int y, const Color &color) void Bitmap::setPixel(int x, int y, const Color &color){
{
guardDisposed(); guardDisposed();
GUARD_MEGA; GUARD_MEGA;
uint8_t pixel[] = uint8_t pixel[] = {
{
(uint8_t) clamp<double>(color.red, 0, 255), (uint8_t) clamp<double>(color.red, 0, 255),
(uint8_t) clamp<double>(color.green, 0, 255), (uint8_t) clamp<double>(color.green, 0, 255),
(uint8_t) clamp<double>(color.blue, 0, 255), (uint8_t) clamp<double>(color.blue, 0, 255),
@ -822,8 +753,7 @@ void Bitmap::setPixel(int x, int y, const Color &color)
/* Setting just a single pixel is no reason to throw away the /* Setting just a single pixel is no reason to throw away the
* whole cached surface; we can just apply the same change */ * whole cached surface; we can just apply the same change */
if (p->surface) if (p->surface){
{
uint32_t &surfPixel = getPixelAt(p->surface, p->format, x, y); uint32_t &surfPixel = getPixelAt(p->surface, p->format, x, y);
// pixel = SDL_MapSurfaceRGBA(surface, r, g, b, a); // pixel = SDL_MapSurfaceRGBA(surface, r, g, b, a);
surfPixel = SDL_MapSurfaceRGBA(p->surface, pixel[0], pixel[1], pixel[2], pixel[3]); surfPixel = SDL_MapSurfaceRGBA(p->surface, pixel[0], pixel[1], pixel[2], pixel[3]);
@ -832,8 +762,7 @@ void Bitmap::setPixel(int x, int y, const Color &color)
p->onModified(false); p->onModified(false);
} }
void Bitmap::hueChange(int hue) void Bitmap::hueChange(int hue){
{
guardDisposed(); guardDisposed();
GUARD_MEGA; GUARD_MEGA;
@ -870,15 +799,11 @@ void Bitmap::hueChange(int hue)
p->onModified(); p->onModified();
} }
void Bitmap::drawText(int x, int y, void Bitmap::drawText(int x, int y, int width, int height, const char *str, int align) {
int width, int height,
const char *str, int align)
{
drawText(IntRect(x, y, width, height), str, align); drawText(IntRect(x, y, width, height), str, align);
} }
static std::string fixupString(const char *str) static std::string fixupString(const char *str){
{
std::string s(str); std::string s(str);
/* RMXP actually draws LF as a "missing gylph" box, /* RMXP actually draws LF as a "missing gylph" box,
@ -905,8 +830,7 @@ static void applyShadow(SDL_Surface *&in, const SDL_PixelFormatDetails* fm, cons
* (0,0) using the bitmap blit equation (see shader/bitmapBlit.frag) */ * (0,0) using the bitmap blit equation (see shader/bitmapBlit.frag) */
for (int y = 0; y < in->h+1; ++y) for (int y = 0; y < in->h+1; ++y)
for (int x = 0; x < in->w+1; ++x) for (int x = 0; x < in->w+1; ++x){
{
/* src: input pixel, shd: shadow pixel */ /* src: input pixel, shd: shadow pixel */
uint32_t src = 0, shd = 0; uint32_t src = 0, shd = 0;
@ -922,14 +846,12 @@ static void applyShadow(SDL_Surface *&in, const SDL_PixelFormatDetails* fm, cons
/* Set shadow pixel RGB values to 0 (black) */ /* Set shadow pixel RGB values to 0 (black) */
shd &= (uint32_t)fm->Amask; shd &= (uint32_t)fm->Amask;
if (x == 0 || y == 0) if (x == 0 || y == 0){
{
*outP = src; *outP = src;
continue; continue;
} }
if (x == in->w || y == in->h) if (x == in->w || y == in->h){
{
*outP = shd; *outP = shd;
continue; continue;
} }
@ -939,14 +861,12 @@ static void applyShadow(SDL_Surface *&in, const SDL_PixelFormatDetails* fm, cons
srcA = (src & fm->Amask) >> fm->Ashift; srcA = (src & fm->Amask) >> fm->Ashift;
shdA = (shd & fm->Amask) >> fm->Ashift; shdA = (shd & fm->Amask) >> fm->Ashift;
if (srcA == 255 || shdA == 0) if (srcA == 255 || shdA == 0){
{
*outP = src; *outP = src;
continue; continue;
} }
if (srcA == 0 && shdA == 0) if (srcA == 0 && shdA == 0){
{
*outP = 0; *outP = 0;
continue; continue;
} }

View File

@ -31,8 +31,7 @@
* exposing an interface similar to Qt's QHash/QSet */ * exposing an interface similar to Qt's QHash/QSet */
template<typename K, typename V> template<typename K, typename V>
class BoostHash class BoostHash{
{
private: private:
typedef boost::unordered_map<K, V> BoostType; typedef boost::unordered_map<K, V> BoostType;
typedef std::pair<K, V> PairType; typedef std::pair<K, V> PairType;
@ -41,25 +40,21 @@ private:
public: public:
typedef typename BoostType::const_iterator const_iterator; typedef typename BoostType::const_iterator const_iterator;
inline bool contains(const K &key) const inline bool contains(const K &key) const{
{
const_iterator iter = p.find(key); const_iterator iter = p.find(key);
return (iter != p.cend()); return (iter != p.cend());
} }
inline void insert(const K &key, const V &value) inline void insert(const K &key, const V &value){
{
p.insert(PairType(key, value)); p.insert(PairType(key, value));
} }
inline void remove(const K &key) inline void remove(const K &key){
{
p.erase(key); p.erase(key);
} }
inline const V value(const K &key) const inline const V value(const K &key) const{
{
const_iterator iter = p.find(key); const_iterator iter = p.find(key);
if (iter == p.cend()) if (iter == p.cend())
@ -68,8 +63,7 @@ public:
return iter->second; return iter->second;
} }
inline const V value(const K &key, const V &defaultValue) const inline const V value(const K &key, const V &defaultValue) const{
{
const_iterator iter = p.find(key); const_iterator iter = p.find(key);
if (iter == p.cend()) if (iter == p.cend())
@ -78,25 +72,21 @@ public:
return iter->second; return iter->second;
} }
inline V &operator[](const K &key) inline V &operator[](const K &key){
{
return p[key]; return p[key];
} }
inline const_iterator cbegin() const inline const_iterator cbegin() const{
{
return p.cbegin(); return p.cbegin();
} }
inline const_iterator cend() const inline const_iterator cend() const{
{
return p.cend(); return p.cend();
} }
}; };
template<typename K> template<typename K>
class BoostSet class BoostSet{
{
private: private:
typedef boost::unordered_set<K> BoostType; typedef boost::unordered_set<K> BoostType;
BoostType p; BoostType p;
@ -104,30 +94,25 @@ private:
public: public:
typedef typename BoostType::const_iterator const_iterator; typedef typename BoostType::const_iterator const_iterator;
inline bool contains(const K &key) inline bool contains(const K &key){
{
const_iterator iter = p.find(key); const_iterator iter = p.find(key);
return (iter != p.cend()); return (iter != p.cend());
} }
inline void insert(const K &key) inline void insert(const K &key){
{
p.insert(key); p.insert(key);
} }
inline void remove(const K &key) inline void remove(const K &key){
{
p.erase(key); p.erase(key);
} }
inline const_iterator cbegin() const inline const_iterator cbegin() const{
{
return p.cbegin(); return p.cbegin();
} }
inline const_iterator cend() const inline const_iterator cend() const{
{
return p.cend(); return p.cend();
} }
}; };