More cleanup.

This commit is contained in:
onpon4 2015-11-02 17:53:05 -05:00
parent 9e6ff10c57
commit cce6d11510
11 changed files with 108 additions and 102 deletions

View File

@ -211,7 +211,7 @@ void game_doStars()
r.w = 1; r.w = 1;
r.h = 1; r.h = 1;
gfx_addBuffer(r.x, r.y, r.w, r.h); screen_addBuffer(r.x, r.y, r.w, r.h);
} }
if (SDL_MUSTLOCK(screen)) if (SDL_MUSTLOCK(screen))
@ -1636,8 +1636,8 @@ static void game_doHud()
signed char fontColor; signed char fontColor;
char text[25]; char text[25];
gfx_addBuffer(0, 20, 800, 25); screen_addBuffer(0, 20, 800, 25);
gfx_addBuffer(0, 550, 800, 34); screen_addBuffer(0, 550, 800, 34);
if (engine.minutes > -1) if (engine.minutes > -1)
{ {
@ -2111,7 +2111,7 @@ int game_mainLoop()
} }
drawBackGround(); drawBackGround();
flushBuffer(); screen_flushBuffer();
// Default to no aliens dead... // Default to no aliens dead...
engine.allAliensDead = 0; engine.allAliensDead = 0;
@ -2211,7 +2211,7 @@ int game_mainLoop()
getPlayerInput(); getPlayerInput();
} }
unBuffer(); screen_unBuffer();
game_doStars(); game_doStars();
game_doCollectables(); game_doCollectables();
game_doBullets(); game_doBullets();
@ -2286,7 +2286,7 @@ int game_mainLoop()
delayFrame(); delayFrame();
} }
flushBuffer(); screen_flushBuffer();
if ((player.shield > 0) && (!missionFailed())) if ((player.shield > 0) && (!missionFailed()))
{ {

View File

@ -29,16 +29,16 @@ SDL_Surface *shape[MAX_SHAPES];
SDL_Surface *shipShape[MAX_SHIPSHAPES]; SDL_Surface *shipShape[MAX_SHIPSHAPES];
SDL_Surface *fontShape[MAX_FONTSHAPES]; SDL_Surface *fontShape[MAX_FONTSHAPES];
SDL_Surface *shopSurface[MAX_SHOPSHAPES]; SDL_Surface *shopSurface[MAX_SHOPSHAPES];
bRect *bufferHead; bRect *screen_bufferHead;
bRect *bufferTail; bRect *screen_bufferTail;
textObject gfx_text[MAX_TEXTSHAPES]; textObject gfx_text[MAX_TEXTSHAPES];
SDL_Surface *messageBox; SDL_Surface *messageBox;
void gfx_init() void gfx_init()
{ {
bufferHead = new bRect; screen_bufferHead = new bRect;
bufferHead->next = NULL; screen_bufferHead->next = NULL;
bufferTail = bufferHead; screen_bufferTail = screen_bufferHead;
for (int i = 0 ; i < MAX_SHAPES ; i++) for (int i = 0 ; i < MAX_SHAPES ; i++)
shape[i] = NULL; shape[i] = NULL;
@ -69,20 +69,6 @@ SDL_Surface *gfx_setTransparent(SDL_Surface *sprite)
return sprite; return sprite;
} }
void gfx_addBuffer(int x, int y, int w, int h)
{
bRect *rect = new bRect;
rect->next = NULL;
rect->x = x;
rect->y = y;
rect->w = w;
rect->h = h;
bufferTail->next = rect;
bufferTail = rect;
}
void gfx_blit(SDL_Surface *image, int x, int y, SDL_Surface *dest) void gfx_blit(SDL_Surface *image, int x, int y, SDL_Surface *dest)
{ {
// Exit early if image is not on dest at all // Exit early if image is not on dest at all
@ -106,56 +92,7 @@ void gfx_blit(SDL_Surface *image, int x, int y, SDL_Surface *dest)
// Only if it is to the screen, mark the region as damaged // Only if it is to the screen, mark the region as damaged
if (dest == screen) if (dest == screen)
gfx_addBuffer(blitRect.x, blitRect.y, blitRect.w, blitRect.h); screen_addBuffer(blitRect.x, blitRect.y, blitRect.w, blitRect.h);
}
void flushBuffer()
{
bRect *prevRect = bufferHead;
bRect *rect = bufferHead;
bufferTail = bufferHead;
while (rect->next != NULL)
{
rect = rect->next;
prevRect->next = rect->next;
delete rect;
rect = prevRect;
}
bufferHead->next = NULL;
}
void unBuffer()
{
bRect *prevRect = bufferHead;
bRect *rect = bufferHead;
bufferTail = bufferHead;
while (rect->next != NULL)
{
rect = rect->next;
SDL_Rect blitRect;
blitRect.x = rect->x;
blitRect.y = rect->y;
blitRect.w = rect->w;
blitRect.h = rect->h;
if (SDL_BlitSurface(background, &blitRect, screen, &blitRect) < 0)
{
printf("BlitSurface error: %s\n", SDL_GetError());
showErrorAndExit(2, "");
}
prevRect->next = rect->next;
delete rect;
rect = prevRect;
}
bufferHead->next = NULL;
} }
/* /*

View File

@ -27,18 +27,13 @@ extern SDL_Surface *shape[MAX_SHAPES];
extern SDL_Surface *shipShape[MAX_SHIPSHAPES]; extern SDL_Surface *shipShape[MAX_SHIPSHAPES];
extern SDL_Surface *fontShape[MAX_FONTSHAPES]; extern SDL_Surface *fontShape[MAX_FONTSHAPES];
extern SDL_Surface *shopSurface[MAX_SHOPSHAPES]; extern SDL_Surface *shopSurface[MAX_SHOPSHAPES];
extern bRect *bufferHead;
extern bRect *bufferTail;
extern textObject gfx_text[MAX_TEXTSHAPES]; extern textObject gfx_text[MAX_TEXTSHAPES];
extern SDL_Surface *messageBox; extern SDL_Surface *messageBox;
void gfx_init(); void gfx_init();
SDL_Surface *gfx_setTransparent(SDL_Surface *sprite); SDL_Surface *gfx_setTransparent(SDL_Surface *sprite);
void gfx_addBuffer(int x, int y, int w, int h);
void gfx_blit(SDL_Surface *image, int x, int y, SDL_Surface *dest); void gfx_blit(SDL_Surface *image, int x, int y, SDL_Surface *dest);
extern void flushBuffer();
extern void unBuffer();
extern int drawString(const char *in, int x, int y, int fontColor, signed char wrap, SDL_Surface *dest); extern int drawString(const char *in, int x, int y, int fontColor, signed char wrap, SDL_Surface *dest);
extern int drawString(const char *in, int x, int y, int fontColor, SDL_Surface *dest); extern int drawString(const char *in, int x, int y, int fontColor, SDL_Surface *dest);
extern int drawString(const char *in, int x, int y, int fontColor); extern int drawString(const char *in, int x, int y, int fontColor);

View File

@ -228,7 +228,7 @@ void cleanUp()
delete(engine.bulletHead); delete(engine.bulletHead);
delete(engine.explosionHead); delete(engine.explosionHead);
delete(engine.collectableHead); delete(engine.collectableHead);
delete(bufferHead); delete(screen_bufferHead);
for (int i = 0 ; i < MAX_FONTSHAPES ; i++) for (int i = 0 ; i < MAX_FONTSHAPES ; i++)
{ {

View File

@ -719,7 +719,7 @@ int intermission()
} }
else else
{ {
unBuffer(); screen_unBuffer();
} }
game_doStars(); game_doStars();
@ -897,7 +897,7 @@ int intermission()
break; break;
} }
gfx_addBuffer(300, 545, 200, 15); screen_addBuffer(300, 545, 200, 15);
if (section != 8) if (section != 8)
{ {

View File

@ -138,7 +138,7 @@ void resetLists()
engine.collectableHead->next = NULL; engine.collectableHead->next = NULL;
engine.collectableTail = engine.collectableHead; engine.collectableTail = engine.collectableHead;
r1 = bufferHead->next; r1 = screen_bufferHead->next;
while (r1 != NULL) while (r1 != NULL)
{ {
r2 = r1; r2 = r1;
@ -146,8 +146,8 @@ void resetLists()
delete r2; delete r2;
} }
bufferHead->next = NULL; screen_bufferHead->next = NULL;
bufferTail = bufferHead; screen_bufferTail = screen_bufferHead;
ob = engine.debrisHead->next; ob = engine.debrisHead->next;
while(ob != NULL) while(ob != NULL)

View File

@ -17,9 +17,13 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <stdlib.h>
#include "SDL.h" #include "SDL.h"
#include "gfx.h" #include "gfx.h"
#include "init.h"
#include "structs.h"
SDL_Surface *screen; SDL_Surface *screen;
@ -32,3 +36,66 @@ void screen_blitText(int i)
{ {
screen_blit(gfx_text[i].image, (int)gfx_text[i].x, (int)gfx_text[i].y); screen_blit(gfx_text[i].image, (int)gfx_text[i].x, (int)gfx_text[i].y);
} }
void screen_addBuffer(int x, int y, int w, int h)
{
bRect *rect = new bRect;
rect->next = NULL;
rect->x = x;
rect->y = y;
rect->w = w;
rect->h = h;
screen_bufferTail->next = rect;
screen_bufferTail = rect;
}
void screen_flushBuffer()
{
bRect *prevRect = screen_bufferHead;
bRect *rect = screen_bufferHead;
screen_bufferTail = screen_bufferHead;
while (rect->next != NULL)
{
rect = rect->next;
prevRect->next = rect->next;
delete rect;
rect = prevRect;
}
screen_bufferHead->next = NULL;
}
void screen_unBuffer()
{
bRect *prevRect = screen_bufferHead;
bRect *rect = screen_bufferHead;
screen_bufferTail = screen_bufferHead;
while (rect->next != NULL)
{
rect = rect->next;
SDL_Rect blitRect;
blitRect.x = rect->x;
blitRect.y = rect->y;
blitRect.w = rect->w;
blitRect.h = rect->h;
if (SDL_BlitSurface(background, &blitRect, screen, &blitRect) < 0)
{
printf("BlitSurface error: %s\n", SDL_GetError());
showErrorAndExit(2, "");
}
prevRect->next = rect->next;
delete rect;
rect = prevRect;
}
screen_bufferHead->next = NULL;
}

View File

@ -20,9 +20,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef SCREEN_H #ifndef SCREEN_H
#define SCREEN_H #define SCREEN_H
#include "structs.h"
extern SDL_Surface *screen; extern SDL_Surface *screen;
extern bRect *screen_bufferHead;
extern bRect *screen_bufferTail;
void screen_blit(SDL_Surface *image, int x, int y); void screen_blit(SDL_Surface *image, int x, int y);
void screen_blitText(int i); void screen_blitText(int i);
void screen_addBuffer(int x, int y, int w, int h);
void screen_flushBuffer();
void screen_unBuffer();
#endif #endif

View File

@ -198,7 +198,7 @@ void doCutscene(int scene)
engine.smx = 0; engine.smx = 0;
engine.smy = 0; engine.smy = 0;
flushBuffer(); screen_flushBuffer();
freeGraphics(); freeGraphics();
resetLists(); resetLists();
loadGameGraphics(); loadGameGraphics();
@ -241,7 +241,7 @@ void doCutscene(int scene)
while (true) while (true)
{ {
renderer_update(); renderer_update();
unBuffer(); screen_unBuffer();
getPlayerInput(); getPlayerInput();
game_doStars(); game_doStars();
game_doExplosions(); game_doExplosions();
@ -310,7 +310,7 @@ void doCutscene(int scene)
break; break;
} }
flushBuffer(); screen_flushBuffer();
freeGraphics(); freeGraphics();
clearScreen(black); clearScreen(black);
renderer_update(); renderer_update();

View File

@ -157,7 +157,7 @@ void ship_fireRay(object *ship)
int red = SDL_MapRGB(screen->format, rand() % 256, 0x00, 0x00); int red = SDL_MapRGB(screen->format, rand() % 256, 0x00, 0x00);
SDL_FillRect(screen, &ray, red); SDL_FillRect(screen, &ray, red);
gfx_addBuffer(ray.x, ray.y, ray.w, ray.h); screen_addBuffer(ray.x, ray.y, ray.w, ray.h);
if (ship != &player) if (ship != &player)
{ {

View File

@ -180,7 +180,7 @@ int doTitle()
engine.gameSection = SECTION_TITLE; engine.gameSection = SECTION_TITLE;
flushBuffer(); screen_flushBuffer();
freeGraphics(); freeGraphics();
resetLists(); resetLists();
@ -277,7 +277,7 @@ int doTitle()
while (!engine.done) while (!engine.done)
{ {
renderer_update(); renderer_update();
unBuffer(); screen_unBuffer();
now = SDL_GetTicks(); now = SDL_GetTicks();
@ -315,7 +315,7 @@ int doTitle()
if ((now - then >= 27500) || (skip)) if ((now - then >= 27500) || (skip))
{ {
gfx_addBuffer(0, 0, screen->w, screen->h); screen_addBuffer(0, 0, screen->w, screen->h);
blevelRect(optionRec.x, optionRec.y, optionRec.w, optionRec.h, redGlow, 0x00, 0x00); blevelRect(optionRec.x, optionRec.y, optionRec.w, optionRec.h, redGlow, 0x00, 0x00);
@ -371,7 +371,7 @@ int doTitle()
drawString("Copyright Parallel Realities 2003", 5, 560, FONT_WHITE, background); drawString("Copyright Parallel Realities 2003", 5, 560, FONT_WHITE, background);
drawString("Copyright Guus Sliepen, Astrid S. de Wijn and others 2012", 5, 580, FONT_WHITE, background); drawString("Copyright Guus Sliepen, Astrid S. de Wijn and others 2012", 5, 580, FONT_WHITE, background);
drawString(buildVersion, 794 - strlen(buildVersion) * 9, 580, FONT_WHITE, background); drawString(buildVersion, 794 - strlen(buildVersion) * 9, 580, FONT_WHITE, background);
gfx_addBuffer(0, 560, 800, 40); screen_addBuffer(0, 560, 800, 40);
skip = true; skip = true;
} }
} }
@ -393,7 +393,7 @@ int doTitle()
drawString("Copyright Parallel Realities 2003", 5, 560, FONT_WHITE, background); drawString("Copyright Parallel Realities 2003", 5, 560, FONT_WHITE, background);
drawString("Copyright Guus Sliepen, Astrid S. de Wijn and others 2012", 5, 580, FONT_WHITE, background); drawString("Copyright Guus Sliepen, Astrid S. de Wijn and others 2012", 5, 580, FONT_WHITE, background);
drawString(buildVersion, 794 - strlen(buildVersion) * 9, 580, FONT_WHITE, background); drawString(buildVersion, 794 - strlen(buildVersion) * 9, 580, FONT_WHITE, background);
gfx_addBuffer(0, 560, 800, 40); screen_addBuffer(0, 560, 800, 40);
skip = true; skip = true;
} }
else else
@ -587,7 +587,7 @@ void showStory()
loadBackground("gfx/startUp.jpg"); loadBackground("gfx/startUp.jpg");
drawBackGround(); drawBackGround();
flushBuffer(); screen_flushBuffer();
flushInput(); flushInput();
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0; engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
@ -595,7 +595,7 @@ void showStory()
while (true) while (true)
{ {
renderer_update(); renderer_update();
unBuffer(); screen_unBuffer();
getPlayerInput(); getPlayerInput();
@ -625,7 +625,7 @@ The game over screen :(
*/ */
void gameover() void gameover()
{ {
flushBuffer(); screen_flushBuffer();
freeGraphics(); freeGraphics();
SDL_FillRect(background, NULL, black); SDL_FillRect(background, NULL, black);
@ -658,7 +658,7 @@ void gameover()
renderer_update(); renderer_update();
unBuffer(); screen_unBuffer();
x = ((screen->w - gameover->w) / 2) - RANDRANGE(-2, 2); x = ((screen->w - gameover->w) / 2) - RANDRANGE(-2, 2);
y = ((screen->h - gameover->h) / 2) - RANDRANGE(-2, 2); y = ((screen->h - gameover->h) / 2) - RANDRANGE(-2, 2);
screen_blit(gameover, x, y); screen_blit(gameover, x, y);
@ -668,13 +668,13 @@ void gameover()
SDL_FreeSurface(gameover); SDL_FreeSurface(gameover);
audio_haltMusic(); audio_haltMusic();
flushBuffer(); screen_flushBuffer();
} }
void doCredits() void doCredits()
{ {
loadBackground("gfx/credits.jpg"); loadBackground("gfx/credits.jpg");
flushBuffer(); screen_flushBuffer();
freeGraphics(); freeGraphics();
FILE *fp; FILE *fp;
@ -722,7 +722,7 @@ void doCredits()
while (true) while (true)
{ {
renderer_update(); renderer_update();
unBuffer(); screen_unBuffer();
getPlayerInput(); getPlayerInput();
if (engine.keyState[KEY_ESCAPE] || engine.keyState[KEY_FIRE] || if (engine.keyState[KEY_ESCAPE] || engine.keyState[KEY_FIRE] ||