More cleanup.

This commit is contained in:
onpon4 2015-10-26 20:07:31 -04:00
parent 988091d635
commit 9e6ff10c57
13 changed files with 92 additions and 40 deletions

View File

@ -1,7 +1,7 @@
CXXFLAGS ?= -O2 -Wall -g
CXXFLAGS += `pkg-config --cflags sdl2 SDL2_image SDL2_mixer`
LIBS = `pkg-config --libs sdl2 SDL2_image SDL2_mixer`
OBJS = alien.o audio.o bullet.o cargo.o collectable.o colors.o engine.o explosion.o game.o gfx.o init.o intermission.o loadSave.o messages.o misc.o missions.o player.o resources.o screen.o script.o ship.o shop.o Starfighter.o title.o weapons.o window.o
OBJS = alien.o audio.o bullet.o cargo.o collectable.o colors.o engine.o explosion.o game.o gfx.o init.o intermission.o loadSave.o messages.o misc.o missions.o player.o renderer.o resources.o screen.o script.o ship.o shop.o Starfighter.o title.o weapons.o window.o
VERSION = 1.4.1-dev
PROG = starfighter

View File

@ -89,10 +89,10 @@ int main(int argc, char **argv)
clearScreen(black);
drawString("That doesn't work anymore", -1, 285, FONT_WHITE);
drawString("Try harder...", -1, 315, FONT_WHITE);
updateScreen();
renderer_update();
SDL_Delay(2000);
clearScreen(black);
updateScreen();
renderer_update();
SDL_Delay(500);
}

View File

@ -52,6 +52,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "misc.h"
#include "missions.h"
#include "player.h"
#include "renderer.h"
#include "resources.h"
#include "screen.h"
#include "script.h"

View File

@ -2122,7 +2122,7 @@ int game_mainLoop()
while (engine.done != 1)
{
updateScreen();
renderer_update();
if ((allMissionsCompleted()) && (engine.missionCompleteTimer == 0))
{
@ -2228,7 +2228,7 @@ int game_mainLoop()
{
textSurface(22, "PAUSED", -1, screen->h / 2, FONT_WHITE);
screen_blitText(22);
updateScreen();
renderer_update();
audio_pauseMusic();
while (engine.paused)
@ -2272,7 +2272,7 @@ int game_mainLoop()
{
audio_playSound(SFX_DEATH, aliens[ALIEN_BOSS].x);
clearScreen(white);
updateScreen();
renderer_update();
for (int i = 0 ; i < 300 ; i++)
{
SDL_Delay(10);

View File

@ -24,8 +24,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
static unsigned long frameLimit;
static int thirds;
SDL_Renderer *renderer;
SDL_Texture *texture;
SDL_Surface *background;
SDL_Surface *shape[MAX_SHAPES];
SDL_Surface *shipShape[MAX_SHIPSHAPES];
@ -275,13 +273,6 @@ void clearScreen(Uint32 color)
SDL_FillRect(screen, NULL, color);
}
void updateScreen()
{
SDL_UpdateTexture(texture, NULL, screen->pixels, screen->w * 4);
SDL_RenderCopy(renderer, texture, NULL, NULL);
SDL_RenderPresent(renderer);
}
/*
* Delay until the next 60 Hz frame
*/

View File

@ -22,8 +22,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "Starfighter.h"
extern SDL_Renderer *renderer;
extern SDL_Texture *texture;
extern SDL_Surface *background;
extern SDL_Surface *shape[MAX_SHAPES];
extern SDL_Surface *shipShape[MAX_SHIPSHAPES];
@ -46,7 +44,6 @@ extern int drawString(const char *in, int x, int y, int fontColor, SDL_Surface *
extern int drawString(const char *in, int x, int y, int fontColor);
extern void drawBackGround();
extern void clearScreen(Uint32 color);
extern void updateScreen();
extern void delayFrame();
extern void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
extern void drawLine(SDL_Surface *dest, int x1, int y1, int x2, int y2, int col);

View File

@ -82,7 +82,7 @@ void showErrorAndExit(int errorId, const char *name)
drawString("Project: Starfighter will now exit", -1, 450, FONT_WHITE);
drawString("Press Space to continue", -1, 475, FONT_WHITE);
updateScreen();
renderer_update();
engine.keyState[KEY_ALTFIRE] = 0;
@ -189,9 +189,9 @@ void initSystem()
SDL_RenderSetLogicalSize(renderer, screen->w, screen->h);
texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen->w, screen->h);
renderer_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen->w, screen->h);
if (!texture)
if (!renderer_texture)
{
printf("Couldn't create %ix%ix32 texture: %s\n", screen->w, screen->h, SDL_GetError());
exit(1);

View File

@ -576,7 +576,7 @@ int intermission()
engine.gameSection = SECTION_INTERMISSION;
clearScreen(black);
updateScreen();
renderer_update();
clearScreen(black);
initSaveSlots();
@ -710,7 +710,7 @@ int intermission()
while (!engine.done)
{
updateScreen();
renderer_update();
if (redrawBackGround)
{

View File

@ -754,7 +754,7 @@ mission begins playing here.
void missionBriefScreen()
{
clearScreen(black);
updateScreen();
renderer_update();
if (game.area != MISN_INTERCEPTION)
{
@ -791,7 +791,7 @@ void missionBriefScreen()
(game.area == MISN_EARTH))
drawString("Sid Wilson will join you on this mission", 160, 480, FONT_WHITE);
updateScreen();
renderer_update();
}
loadGameGraphics();
@ -818,7 +818,7 @@ void missionBriefScreen()
{
drawString("PRESS ENTER TO CONTINUE...", -1, 550, FONT_WHITE);
updateScreen();
renderer_update();
flushInput();
engine.done = 0;
@ -836,7 +836,7 @@ void missionBriefScreen()
}
clearScreen(black);
updateScreen();
renderer_update();
clearScreen(black);
}
@ -857,7 +857,7 @@ void missionFinishedScreen()
if (game.area != MISN_INTERCEPTION)
{
clearScreen(black);
updateScreen();
renderer_update();
if (game.shots > 0)
game.accuracy = (game.hits * 100) / game.shots;
@ -923,7 +923,7 @@ void missionFinishedScreen()
checkForBossMission();
updateScreen();
renderer_update();
flushInput();
engine.done = 0;

35
src/renderer.cpp Normal file
View File

@ -0,0 +1,35 @@
/*
Copyright (C) 2003 Parallel Realities
Copyright (C) 2011, 2012, 2013 Guus Sliepen
Copyright (C) 2015 Julian Marchant
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
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 "SDL.h"
#include "screen.h"
SDL_Renderer *renderer;
SDL_Texture *renderer_texture;
void renderer_update()
{
// XXX: The SDL wiki says that SDL_UpdateTexture is slow and shouldn't
// be used for textures that are updated often. This should be looked
// into.
SDL_UpdateTexture(renderer_texture, NULL, screen->pixels, screen->w * 4);
SDL_RenderCopy(renderer, renderer_texture, NULL, NULL);
SDL_RenderPresent(renderer);
}

28
src/renderer.h Normal file
View File

@ -0,0 +1,28 @@
/*
Copyright (C) 2003 Parallel Realities
Copyright (C) 2011 Guus Sliepen
Copyright (C) 2015 Julian Marchant
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RENDERER_H
#define RENDERER_H
extern SDL_Renderer *renderer;
extern SDL_Texture *renderer_texture;
void renderer_update();
#endif

View File

@ -187,7 +187,7 @@ static void setScene(int scene)
void doCutscene(int scene)
{
clearScreen(black);
updateScreen();
renderer_update();
clearScreen(black);
engine.keyState[KEY_FIRE] = 0;
@ -240,7 +240,7 @@ void doCutscene(int scene)
while (true)
{
updateScreen();
renderer_update();
unBuffer();
getPlayerInput();
game_doStars();
@ -313,5 +313,5 @@ void doCutscene(int scene)
flushBuffer();
freeGraphics();
clearScreen(black);
updateScreen();
renderer_update();
}

View File

@ -191,7 +191,7 @@ int doTitle()
loadGameGraphics();
clearScreen(black);
updateScreen();
renderer_update();
clearScreen(black);
signed char continueSaveSlot = initSaveSlots();
@ -276,7 +276,7 @@ int doTitle()
while (!engine.done)
{
updateScreen();
renderer_update();
unBuffer();
now = SDL_GetTicks();
@ -594,7 +594,7 @@ void showStory()
while (true)
{
updateScreen();
renderer_update();
unBuffer();
getPlayerInput();
@ -635,7 +635,7 @@ void gameover()
SDL_Surface *gameover = loadImage("gfx/gameover.png");
clearScreen(black);
updateScreen();
renderer_update();
clearScreen(black);
SDL_Delay(1000);
@ -644,7 +644,7 @@ void gameover()
int x = (screen->w - gameover->w) / 2;
int y = (screen->h - gameover->h) / 2;
updateScreen();
renderer_update();
flushInput();
engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0;
@ -656,7 +656,7 @@ void gameover()
if (engine.keyState[KEY_FIRE] || engine.keyState[KEY_ALTFIRE])
break;
updateScreen();
renderer_update();
unBuffer();
x = ((screen->w - gameover->w) / 2) - RANDRANGE(-2, 2);
@ -688,7 +688,7 @@ void doCredits()
textObject *credit;
clearScreen(black);
updateScreen();
renderer_update();
clearScreen(black);
drawBackGround();
@ -721,7 +721,7 @@ void doCredits()
while (true)
{
updateScreen();
renderer_update();
unBuffer();
getPlayerInput();