-[FIX] Hard to catch memory bug has been valgrinded out!
This commit is contained in:
@@ -47,7 +47,7 @@ namespace draw
|
||||
|
||||
// Creem la superficie "screen" i la establim com a superficie destinació
|
||||
screen = createSurface(width, height);
|
||||
destination = screen;
|
||||
setDestination(screen);
|
||||
sel_color = transparent = 0;
|
||||
for (int i=0;i<256;++i) color_indices[i] = i;
|
||||
|
||||
@@ -174,10 +174,10 @@ namespace draw
|
||||
|
||||
void setViewport(const int x, const int y, const int w, const int h)
|
||||
{
|
||||
viewport.x = x>0?x:0;
|
||||
viewport.y = y>0?y:0;
|
||||
viewport.w = w+x<destination->w?w:destination->w;
|
||||
viewport.h = h+y<destination->h?h:destination->h;
|
||||
viewport.x = x<0 ? 0 : x>=destination->w ? 0 : x;
|
||||
viewport.y = y<0 ? 0 : y>=destination->h ? 0 : y;
|
||||
viewport.w = w+viewport.x<destination->w ? w : destination->w-viewport.x;
|
||||
viewport.h = h+viewport.y<destination->h ? h : destination->h-viewport.y;
|
||||
}
|
||||
|
||||
void resetViewport()
|
||||
@@ -241,13 +241,16 @@ namespace draw
|
||||
// Si el color es transparent, eixim, ni ens molestem en mirar res més
|
||||
if (color == transparent) return;
|
||||
|
||||
// Si està fora de la surface, directament passem
|
||||
if (x < 0 || y < 0 || x >= surface->w || y >= surface->h)
|
||||
return;
|
||||
|
||||
// Si pintem a "destination", mirem que estiga dins del "viewport" i sinó fora
|
||||
if (surface == destination) {
|
||||
if (x+viewport.x >= 0 && y+viewport.y >= 0 && x < viewport.w && y < viewport.h)
|
||||
surface->pixels[(viewport.x+x) + (y+viewport.y) * surface->w] = color_indices[color];
|
||||
} else {
|
||||
// Si no es destinations, mirem que estiga dins de la surface, i sinó fora!
|
||||
if (x >= 0 && y >= 0 && x < destination->w && y < destination->h)
|
||||
// Si no es destinations, pintem i au
|
||||
surface->pixels[x + y * surface->w] = color_indices[color];
|
||||
}
|
||||
}
|
||||
@@ -255,13 +258,16 @@ namespace draw
|
||||
// Funció interna per a llegir un pixel d'una superficie eixir-se'n de la memòria i petar el mame
|
||||
const uint8_t pget(surface *surface, const int x, const int y)
|
||||
{
|
||||
// Si està fora de la surface, directament passem
|
||||
if (x < 0 || y < 0 || x >= surface->w || y >= surface->h)
|
||||
return 0;
|
||||
|
||||
// Si estem llegint de "destination", mirar que estigam llegint dins del viewport
|
||||
if (surface == destination) {
|
||||
if (x+viewport.x >= 0 && y+viewport.y >= 0 && x < viewport.w && y < viewport.h)
|
||||
return surface->pixels[(viewport.x + x) + (viewport.y + y) * surface->w];
|
||||
} else {
|
||||
// Si no es "destination", si la coordenada està dins del rang que abarca la superficie,
|
||||
if (x >= 0 && y >= 0 && x < destination->w && y < destination->h)
|
||||
// Si no es "destination",
|
||||
return surface->pixels[x + y * surface->w];
|
||||
}
|
||||
|
||||
@@ -380,12 +386,13 @@ namespace draw
|
||||
// Refresca la pantalla
|
||||
void render()
|
||||
{
|
||||
|
||||
Uint32 *sdl_pixels; // Punter al array de pixels que enstornarà SDL_LockTexture
|
||||
int sdl_pitch; // Ací estarà guardat el pitch de la textura, com es de 32 bits, no m'afecta
|
||||
const uint32_t size = screen->w * screen->h; // tamany de la superficie
|
||||
|
||||
// Bloquejem la textura SDL i agafem els seus pixels (son enters de 32 bits amb format 0xAARRGGBB)
|
||||
SDL_LockTexture(sdl_texture, NULL, (void **)&sdl_pixels, &sdl_pitch);
|
||||
int result = SDL_LockTexture(sdl_texture, NULL, (void **)&sdl_pixels, &sdl_pitch);
|
||||
|
||||
// Cada pixel de la superficie "screen" es un enter de 8 bits que representa un index en la paleta de colors
|
||||
// Per tant, per a pintar en la textura SDL, pillem el color de la paleta que correspon al index en "screen"
|
||||
|
||||
@@ -337,7 +337,7 @@ bool game::loop()
|
||||
draw::color(WHITE);
|
||||
draw::fillrect(0, 0, 100, 240);
|
||||
|
||||
draw::setViewport(420, 2, 100, 240);
|
||||
draw::setViewport(420, 2, 100, 238);
|
||||
|
||||
draw::color(LIGHT+WHITE);
|
||||
draw::fillrect(2, 0, 96, 100);
|
||||
@@ -369,7 +369,7 @@ bool game::loop()
|
||||
act = actor::getSelected();
|
||||
if (act)
|
||||
{
|
||||
draw::setViewport(420, 90, 100, 240);
|
||||
draw::setViewport(420, 90, 100, 150);
|
||||
|
||||
btn_txt("NAME:", 2, 0, act->name);
|
||||
if (btn_opt2("BMP:", 2, 10, act->bmp, gifs)) {
|
||||
|
||||
Reference in New Issue
Block a user