diff --git a/Makefile b/Makefile
index 88ab846..18e5935 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/src/Starfighter.cpp b/src/Starfighter.cpp
index b859637..31ea92e 100644
--- a/src/Starfighter.cpp
+++ b/src/Starfighter.cpp
@@ -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);
}
diff --git a/src/Starfighter.h b/src/Starfighter.h
index 6da5998..747bb5f 100644
--- a/src/Starfighter.h
+++ b/src/Starfighter.h
@@ -52,6 +52,7 @@ along with this program. If not, see .
#include "misc.h"
#include "missions.h"
#include "player.h"
+#include "renderer.h"
#include "resources.h"
#include "screen.h"
#include "script.h"
diff --git a/src/game.cpp b/src/game.cpp
index adec950..7bb91f4 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -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);
diff --git a/src/gfx.cpp b/src/gfx.cpp
index d40cc82..ea0bbfe 100644
--- a/src/gfx.cpp
+++ b/src/gfx.cpp
@@ -24,8 +24,6 @@ along with this program. If not, see .
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
*/
diff --git a/src/gfx.h b/src/gfx.h
index d77de80..de60fb6 100644
--- a/src/gfx.h
+++ b/src/gfx.h
@@ -22,8 +22,6 @@ along with this program. If not, see .
#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);
diff --git a/src/init.cpp b/src/init.cpp
index 790b305..c1d148e 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -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);
diff --git a/src/intermission.cpp b/src/intermission.cpp
index fdc93ce..c7e195c 100644
--- a/src/intermission.cpp
+++ b/src/intermission.cpp
@@ -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)
{
diff --git a/src/missions.cpp b/src/missions.cpp
index 5d4c8ac..42989ce 100644
--- a/src/missions.cpp
+++ b/src/missions.cpp
@@ -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;
diff --git a/src/renderer.cpp b/src/renderer.cpp
new file mode 100644
index 0000000..0e08341
--- /dev/null
+++ b/src/renderer.cpp
@@ -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 .
+*/
+
+#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);
+}
diff --git a/src/renderer.h b/src/renderer.h
new file mode 100644
index 0000000..e9f786d
--- /dev/null
+++ b/src/renderer.h
@@ -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 .
+*/
+
+#ifndef RENDERER_H
+#define RENDERER_H
+
+extern SDL_Renderer *renderer;
+extern SDL_Texture *renderer_texture;
+
+void renderer_update();
+
+#endif
diff --git a/src/script.cpp b/src/script.cpp
index 13d3f97..e81c8ab 100644
--- a/src/script.cpp
+++ b/src/script.cpp
@@ -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();
}
diff --git a/src/title.cpp b/src/title.cpp
index 03ae37e..ca33787 100644
--- a/src/title.cpp
+++ b/src/title.cpp
@@ -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();