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

View File

@ -29,16 +29,16 @@ SDL_Surface *shape[MAX_SHAPES];
SDL_Surface *shipShape[MAX_SHIPSHAPES];
SDL_Surface *fontShape[MAX_FONTSHAPES];
SDL_Surface *shopSurface[MAX_SHOPSHAPES];
bRect *bufferHead;
bRect *bufferTail;
bRect *screen_bufferHead;
bRect *screen_bufferTail;
textObject gfx_text[MAX_TEXTSHAPES];
SDL_Surface *messageBox;
void gfx_init()
{
bufferHead = new bRect;
bufferHead->next = NULL;
bufferTail = bufferHead;
screen_bufferHead = new bRect;
screen_bufferHead->next = NULL;
screen_bufferTail = screen_bufferHead;
for (int i = 0 ; i < MAX_SHAPES ; i++)
shape[i] = NULL;
@ -69,20 +69,6 @@ SDL_Surface *gfx_setTransparent(SDL_Surface *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)
{
// 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
if (dest == screen)
gfx_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;
screen_addBuffer(blitRect.x, blitRect.y, blitRect.w, blitRect.h);
}
/*

View File

@ -27,18 +27,13 @@ extern SDL_Surface *shape[MAX_SHAPES];
extern SDL_Surface *shipShape[MAX_SHIPSHAPES];
extern SDL_Surface *fontShape[MAX_FONTSHAPES];
extern SDL_Surface *shopSurface[MAX_SHOPSHAPES];
extern bRect *bufferHead;
extern bRect *bufferTail;
extern textObject gfx_text[MAX_TEXTSHAPES];
extern SDL_Surface *messageBox;
void gfx_init();
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);
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, SDL_Surface *dest);
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.explosionHead);
delete(engine.collectableHead);
delete(bufferHead);
delete(screen_bufferHead);
for (int i = 0 ; i < MAX_FONTSHAPES ; i++)
{

View File

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

View File

@ -138,7 +138,7 @@ void resetLists()
engine.collectableHead->next = NULL;
engine.collectableTail = engine.collectableHead;
r1 = bufferHead->next;
r1 = screen_bufferHead->next;
while (r1 != NULL)
{
r2 = r1;
@ -146,8 +146,8 @@ void resetLists()
delete r2;
}
bufferHead->next = NULL;
bufferTail = bufferHead;
screen_bufferHead->next = NULL;
screen_bufferTail = screen_bufferHead;
ob = engine.debrisHead->next;
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/>.
*/
#include <stdlib.h>
#include "SDL.h"
#include "gfx.h"
#include "init.h"
#include "structs.h"
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);
}
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
#define SCREEN_H
#include "structs.h"
extern SDL_Surface *screen;
extern bRect *screen_bufferHead;
extern bRect *screen_bufferTail;
void screen_blit(SDL_Surface *image, int x, int y);
void screen_blitText(int i);
void screen_addBuffer(int x, int y, int w, int h);
void screen_flushBuffer();
void screen_unBuffer();
#endif

View File

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

View File

@ -157,7 +157,7 @@ void ship_fireRay(object *ship)
int red = SDL_MapRGB(screen->format, rand() % 256, 0x00, 0x00);
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)
{

View File

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