From ce94477b70db87ad096b67e5ab2d178a2ae75fa3 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Sat, 2 Jan 2016 16:59:48 -0500 Subject: [PATCH] More cleanup. --- Makefile | 2 +- src/Starfighter.cpp | 18 ++- src/Starfighter.h | 3 +- src/alien.cpp | 4 +- src/alien.h | 2 +- src/audio.cpp | 2 +- src/audio.h | 2 +- src/bullet.cpp | 2 +- src/bullet.h | 2 +- src/cargo.cpp | 2 +- src/cargo.h | 2 +- src/collectable.cpp | 2 +- src/collectable.h | 2 +- src/colors.cpp | 2 +- src/colors.h | 2 +- src/defs.h | 2 +- src/engine.cpp | 237 ++++++++++++++++++++++++++++++++++++- src/engine.h | 8 +- src/explosion.cpp | 2 +- src/explosion.h | 2 +- src/game.cpp | 6 +- src/game.h | 2 +- src/gfx.cpp | 83 ++++++------- src/gfx.h | 11 +- src/init.cpp | 271 ------------------------------------------- src/init.h | 28 ----- src/intermission.cpp | 38 +++--- src/intermission.h | 2 +- src/loadSave.cpp | 10 +- src/loadSave.h | 2 +- src/messages.cpp | 1 + src/messages.h | 2 +- src/misc.cpp | 4 +- src/misc.h | 2 +- src/missions.cpp | 2 +- src/missions.h | 2 +- src/player.cpp | 2 +- src/player.h | 2 +- src/renderer.cpp | 2 +- src/renderer.h | 2 +- src/resources.cpp | 14 +-- src/resources.h | 2 +- src/screen.cpp | 6 +- src/screen.h | 2 +- src/script.cpp | 8 +- src/script.h | 2 +- src/ship.cpp | 2 +- src/ship.h | 2 +- src/shop.cpp | 4 +- src/shop.h | 2 +- src/structs.h | 4 +- src/title.cpp | 16 +-- src/title.h | 2 +- src/weapons.cpp | 1 + src/weapons.h | 2 +- src/window.cpp | 2 +- src/window.h | 2 +- 57 files changed, 399 insertions(+), 448 deletions(-) delete mode 100644 src/init.cpp delete mode 100644 src/init.h diff --git a/Makefile b/Makefile index 18e5935..508c200 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 renderer.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 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 f28775c..6e2c586 100644 --- a/src/Starfighter.cpp +++ b/src/Starfighter.cpp @@ -2,7 +2,7 @@ Project: Starfighter Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -78,10 +78,10 @@ int main(int argc, char **argv) } } - atexit(cleanUp); + atexit(engine_cleanup); gfx_init(); - initSystem(); // Opens video mode and sound + engine_setMode(); loadFont(); if (cheatAttempt && !engine.cheat) @@ -96,11 +96,19 @@ int main(int argc, char **argv) SDL_Delay(500); } - freeGraphics(); + gfx_free(); audio_loadSounds(); initWeapons(); - initVars(); + + srand(time(NULL)); + + if (engine.useAudio) + { + Mix_Volume(-1, 100); + Mix_VolumeMusic(engine.musicVolume); + } + alien_defs_init(); colors_init(); diff --git a/src/Starfighter.h b/src/Starfighter.h index 747bb5f..a5e6b5d 100644 --- a/src/Starfighter.h +++ b/src/Starfighter.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -45,7 +45,6 @@ along with this program. If not, see . #include "explosion.h" #include "game.h" #include "gfx.h" -#include "init.h" #include "intermission.h" #include "loadSave.h" #include "messages.h" diff --git a/src/alien.cpp b/src/alien.cpp index 7830f06..725a29f 100644 --- a/src/alien.cpp +++ b/src/alien.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012 Guus Sliepen -Copyright (C) 2012, 2015 Julian Marchant +Copyright (C) 2012, 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -732,7 +732,7 @@ void aliens_init() break; if (placeAttempt > 1000) - showErrorAndExit(2, ""); + engine_showError(2, ""); } if (game.area == MISN_CERADSE) diff --git a/src/alien.h b/src/alien.h index 2711afa..534d374 100644 --- a/src/alien.h +++ b/src/alien.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/audio.cpp b/src/audio.cpp index 8bfcf68..dbb4d02 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/audio.h b/src/audio.h index 8351253..9022e36 100644 --- a/src/audio.h +++ b/src/audio.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/bullet.cpp b/src/bullet.cpp index 5f9a008..08bf35c 100644 --- a/src/bullet.cpp +++ b/src/bullet.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/bullet.h b/src/bullet.h index e415379..0b110bb 100644 --- a/src/bullet.h +++ b/src/bullet.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/cargo.cpp b/src/cargo.cpp index b754ae6..ce431ca 100644 --- a/src/cargo.cpp +++ b/src/cargo.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/cargo.h b/src/cargo.h index 5d1c3bf..51432ff 100644 --- a/src/cargo.h +++ b/src/cargo.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/collectable.cpp b/src/collectable.cpp index 4579bff..ce62029 100644 --- a/src/collectable.cpp +++ b/src/collectable.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/collectable.h b/src/collectable.h index 6bd4697..24960ad 100644 --- a/src/collectable.h +++ b/src/collectable.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/colors.cpp b/src/colors.cpp index 1999173..2b51c92 100644 --- a/src/colors.cpp +++ b/src/colors.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/colors.h b/src/colors.h index d6d76fc..7d2cbe3 100644 --- a/src/colors.h +++ b/src/colors.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/defs.h b/src/defs.h index d144762..be8e9f1 100644 --- a/src/defs.h +++ b/src/defs.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012 Guus Sliepen -Copyright (C) 2012, 2015 Julian Marchant +Copyright (C) 2012, 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/engine.cpp b/src/engine.cpp index 7dc7f8f..de13c8a 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -19,6 +19,11 @@ along with this program. If not, see . #include "Starfighter.h" +#include +#include +#include +#include + Engine engine; void engine_init() @@ -69,3 +74,233 @@ void engine_init() engine.cheatAmmo = false; engine.cheatCash = false; } + +/* +Something went wrong. This stops the game, present the error message and +prompts the user to press space or ctrl to exit the game. This is unlikely to +be seen by people unless something really stoopid happens! +*/ +void engine_showError(int errorId, const char *name) +{ + screen_clear(black); + + if (errorId != 2) + { + screen_renderString("A file error has occurred", -1, 200, FONT_RED); + } + else + { + printf("Couldn't create or write to directory '%s'\n", name); + exit(1); + } + + char string[255]; + + switch(errorId) + { + case 0: + sprintf(string, "%s was not found in the Starfighter data package", name); + screen_renderString(string, -1, 250, FONT_WHITE); + screen_renderString("Please try again. If this error persists, contact the authors", -1, 275, FONT_WHITE); + screen_renderString("or reinstall the game", -1, 300, FONT_WHITE); + break; + case 1: + screen_renderString("Project: Starfighter encountered an error whilst", -1, 250, FONT_WHITE); + screen_renderString("attempting to load game data. Please try running", -1, 275, FONT_WHITE); + screen_renderString("the game again. If the errors persist, reinstall the game", -1, 300, FONT_WHITE); + break; + case 2: + screen_renderString("Project: Starfighter encountered a critical error", -1, 250, FONT_WHITE); + screen_renderString("while attempting to perform a required program function.", -1, 275, FONT_WHITE); + screen_renderString("Please contact the authors with details.", -1, 300, FONT_WHITE); + break; + } + + screen_renderString("Project: Starfighter will now exit", -1, 450, FONT_WHITE); + screen_renderString("Press Space to continue", -1, 475, FONT_WHITE); + + renderer_update(); + + engine.keyState[KEY_ALTFIRE] = 0; + + while (!engine.keyState[KEY_ALTFIRE]) + { + getPlayerInput(); + game_delayFrame(); + } + + exit(1); +} + +/* +This gets the user's home directory, then creates the .parallelrealities +and .parallelrealities/starfighter directories so that saves and +temporary data files can be written there. +*/ +void engine_setupConfigDirectory() +{ + const char *userHome; + + if ((userHome = getenv("HOME")) == NULL) + userHome = getpwuid(getuid())->pw_dir; + + char dir[PATH_MAX]; + strcpy(dir, ""); + + sprintf(dir, "%s/.parallelrealities", userHome); + if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) + engine_showError(2, dir); + + sprintf(dir, "%s/.parallelrealities/starfighter", userHome); + if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) + engine_showError(2, dir); + + sprintf(engine.configDirectory, "%s/.parallelrealities/starfighter/", userHome); +} + +/* +This sets up the video and sound system, and creates Starfighter's window. +*/ +void engine_setMode() +{ + strcpy(engine.configDirectory, ""); + + engine_setupConfigDirectory(); + + /* Initialize the SDL library */ + if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK) < 0) + { + printf("Couldn't initialize SDL: %s\n", SDL_GetError()); + exit(1); + } + + char filename[PATH_MAX]; + int fullScreen = 0; + int useSound = 1; + int useMusic = 1; + int autoPause = 0; + + FILE *fp; + sprintf(filename, "%sconf", engine.configDirectory); + fp = fopen(filename, "rb"); + + if (fp != NULL) + { + if (fscanf(fp, "%d %d %d %d", &fullScreen, &useSound, &useMusic, &autoPause) < 4) + printf("Warning: Config file \"%s\" is not correctly formatted\n", filename); + fclose(fp); + } + + engine.fullScreen = fullScreen; + engine.useSound = useSound; + engine.useMusic = useMusic; + engine.autoPause = autoPause; + + screen = SDL_CreateRGBSurface(0, screenWidth, screenHeight, 32, 0xff0000, 0xff00, 0xff, 0xff000000); + + if (!screen) + { + printf("Couldn't create %ix%ix32 surface: %s\n", screenWidth, screenHeight, SDL_GetError()); + exit(1); + } + + window = SDL_CreateWindow("Project: Starfighter", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen->w, screen->h, 0); + + if (window == NULL) + { + printf("Could not create window: %s\n", SDL_GetError()); + exit(1); + } + + SDL_SetWindowIcon(window, gfx_loadImage("gfx/alienDevice.png")); + SDL_SetWindowFullscreen(window, engine.fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); + + renderer = SDL_CreateRenderer(window, -1, 0); + + if (!renderer) + { + printf("Could not create renderer: %s\n", SDL_GetError()); + exit(1); + } + + SDL_RenderSetLogicalSize(renderer, screen->w, screen->h); + + renderer_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen->w, screen->h); + + if (!renderer_texture) + { + printf("Couldn't create %ix%ix32 texture: %s\n", screen->w, screen->h, SDL_GetError()); + exit(1); + } + + if (engine.useAudio) + { + if (Mix_OpenAudio(44100, AUDIO_S16, engine.useAudio * 2, 1024) < 0) + { + printf("Warning: Couldn't set 44100 Hz 16-bit stereo audio - Reason:\n%s\n", Mix_GetError()); + printf("Sound and Music will be disabled\n"); + engine.useAudio = false; + } + } + + SDL_ShowCursor(SDL_DISABLE); + SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE); + + SDL_JoystickEventState(SDL_ENABLE); + SDL_JoystickOpen(0); +} + +/* +Removes [hopefully] all the resources that has been +loaded and created during the game. This is called by +atexit(); +*/ +void engine_cleanup() +{ + gfx_free(); + SDL_FreeSurface(gfx_background); + audio_free(); + resetLists(); + delete(engine.bulletHead); + delete(engine.explosionHead); + delete(engine.collectableHead); + delete(screen_bufferHead); + + for (int i = 0 ; i < MAX_FONTSHAPES ; i++) + { + if (fontShape[i] != NULL) + SDL_FreeSurface(fontShape[i]); + } + + char filename[PATH_MAX]; + strcpy(filename, ""); + + sprintf(filename, "%smusic.mod", engine.configDirectory); + remove(filename); + + sprintf(filename, "%smusic.s3m", engine.configDirectory); + remove(filename); + + if (engine.useAudio) + { + Mix_CloseAudio(); + } + + // Save the config using current settings + FILE *fp; + sprintf(filename, "%sconf", engine.configDirectory); + fp = fopen(filename, "wb"); + if (fp != NULL) + { + fprintf(fp, "%d %d %d %d\n", engine.fullScreen, engine.useSound, + engine.useMusic, engine.autoPause); + fclose(fp); + } + else + { + printf("Error saving config\n"); + } + + SDL_Quit(); + printf("Thank You for playing Starfighter\n"); +} diff --git a/src/engine.h b/src/engine.h index 4f510f5..b78e081 100644 --- a/src/engine.h +++ b/src/engine.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -20,8 +20,14 @@ along with this program. If not, see . #ifndef GLOBALS_H #define GLOBALS_H +#include "structs.h" + extern Engine engine; void engine_init(); +void engine_showError(int errorId, const char *name); +void engine_setupConfigDirectory(); +void engine_setMode(); +void engine_cleanup(); #endif diff --git a/src/explosion.cpp b/src/explosion.cpp index d56eef7..2a31d72 100644 --- a/src/explosion.cpp +++ b/src/explosion.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/explosion.h b/src/explosion.h index 95b80a7..45f28e2 100644 --- a/src/explosion.h +++ b/src/explosion.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/game.cpp b/src/game.cpp index 6012cbb..f96782a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2012, 2014, 2015 Julian Marchant +Copyright (C) 2012, 2014, 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -185,8 +185,8 @@ void game_doStars() /* Lock the screen for direct access to the pixels */ if (SDL_MUSTLOCK(screen)) { - if (SDL_LockSurface(screen) < 0 ) - showErrorAndExit(2, ""); + if (SDL_LockSurface(screen) < 0) + engine_showError(2, ""); } int color = 0; diff --git a/src/game.h b/src/game.h index 829ea64..9b300d1 100644 --- a/src/game.h +++ b/src/game.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/gfx.cpp b/src/gfx.cpp index 729bdbc..8895cd4 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -66,13 +66,13 @@ SDL_Surface *gfx_setTransparent(SDL_Surface *sprite) void gfx_blit(SDL_Surface *image, int x, int y, SDL_Surface *dest) { + SDL_Rect blitRect; + // Exit early if image is not on dest at all if (x + image->w < 0 || x >= dest->w || y + image->h < 0 || y >= dest->h) return; // Set up a rectangle to draw to - SDL_Rect blitRect; - blitRect.x = x; blitRect.y = y; blitRect.w = image->w; @@ -82,7 +82,7 @@ void gfx_blit(SDL_Surface *image, int x, int y, SDL_Surface *dest) if (SDL_BlitSurface(image, NULL, dest, &blitRect) < 0) { printf("BlitSurface error: %s\n", SDL_GetError()); - showErrorAndExit(2, ""); + engine_showError(2, ""); } // Only if it is to the screen, mark the region as damaged @@ -121,7 +121,7 @@ static int gfx_renderStringBase(const char *in, int x, int y, int fontColor, sig if (SDL_BlitSurface(fontShape[fontColor], &letter, dest, &area) < 0) { printf("BlitSurface error: %s\n", SDL_GetError()); - showErrorAndExit(2, ""); + engine_showError(2, ""); } } @@ -153,7 +153,7 @@ static int gfx_renderStringBase(const char *in, int x, int y, int fontColor, sig if (SDL_BlitSurface(fontShape[fontColor], &letter, dest, &area) < 0) { printf("BlitSurface error: %s\n", SDL_GetError()); - showErrorAndExit(2, ""); + engine_showError(2, ""); } area.y += 16; area.x = x; @@ -231,7 +231,7 @@ void gfx_drawLine(SDL_Surface *dest, int x1, int y1, int x2, int y2, int col) if ( SDL_LockSurface(dest) < 0 ) { printf("Can't lock screen: %s\n", SDL_GetError()); - showErrorAndExit(2, ""); + engine_showError(2, ""); } } @@ -263,8 +263,10 @@ mailing list... I didn't write it myself. */ void gfx_drawCircle(int xc, int yc, int R, SDL_Surface *PIX, int col) { - int x = 0, xx = 0; - int y = R, yy = 2 * R; + int x = 0; + int xx = 0; + int y = R; + int yy = 2 * R; int p = 1 - R; gfx_putPixel(PIX, xc, yc - y, col); @@ -337,7 +339,7 @@ SDL_Surface *gfx_createSurface(int width, int height) if (surface == NULL) { printf("CreateRGBSurface failed: %s\n", SDL_GetError()); - showErrorAndExit(2, ""); + engine_showError(2, ""); } return surface; @@ -377,7 +379,7 @@ void gfx_createTextObject(int index, const char *inString, int x, int y, int fon gfx_text[index].x = (screen->w - gfx_text[index].image->w) / 2; } -SDL_Surface *alphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue) +SDL_Surface *gfx_createAlphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue) { SDL_Surface *surface = gfx_createSurface(width, height); @@ -388,8 +390,10 @@ SDL_Surface *alphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue return surface; } -void createMessageBox(SDL_Surface *face, const char *message, signed char transparent) +void gfx_createMessageBox(SDL_Surface *face, const char *message, signed char transparent) { + int x = 60; + if (messageBox != NULL) { SDL_FreeSurface(messageBox); @@ -397,12 +401,10 @@ void createMessageBox(SDL_Surface *face, const char *message, signed char transp } if (transparent) - messageBox = alphaRect(550, 60, 0x00, 0x00, 0x00); + messageBox = gfx_createAlphaRect(550, 60, 0x00, 0x00, 0x00); else messageBox = gfx_createSurface(550, 60); - signed char x = 60; - if (face != NULL) { gfx_drawRect(messageBox, 0, 0, messageBox->w - 1, messageBox->h - 1, 0x00, 0x00, 0xaa); @@ -417,7 +419,31 @@ void createMessageBox(SDL_Surface *face, const char *message, signed char transp gfx_renderString(message, x, 5, FONT_WHITE, 1, messageBox); } -void freeGraphics() +SDL_Surface *gfx_loadImage(const char *filename) +{ + SDL_Surface *image, *newImage; + + image = IMG_Load(filename); + + if (image == NULL) { + printf("Couldn't load %s: %s\n", filename, SDL_GetError()); + engine_showError(0, filename); + } + + newImage = SDL_ConvertSurface(image, screen->format, 0); + if ( newImage ) { + SDL_FreeSurface(image); + } + else + { + // This happens when we are loading the window icon image + newImage = image; + } + + return gfx_setTransparent(newImage); +} + +void gfx_free() { for (int i = 0 ; i < MAX_SHAPES ; i++) { @@ -461,28 +487,3 @@ void freeGraphics() messageBox = NULL; } } - - -SDL_Surface *loadImage(const char *filename) -{ - SDL_Surface *image, *newImage; - - image = IMG_Load(filename); - - if (image == NULL) { - printf("Couldn't load %s: %s\n", filename, SDL_GetError()); - showErrorAndExit(0, filename); - } - - newImage = SDL_ConvertSurface(image, screen->format, 0); - if ( newImage ) { - SDL_FreeSurface(image); - } - else - { - // This happens when we are loading the window icon image - newImage = image; - } - - return gfx_setTransparent(newImage); -} diff --git a/src/gfx.h b/src/gfx.h index 0e5fd56..0278094 100644 --- a/src/gfx.h +++ b/src/gfx.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -42,10 +42,9 @@ void gfx_drawRect(SDL_Surface *dest, int x, int y, int w, int h, Uint8 red, Uint SDL_Surface *gfx_createSurface(int width, int height); SDL_Surface *gfx_createTextSurface(const char *inString, int color); void gfx_createTextObject(int index, const char *inString, int x, int y, int fontColor); -extern SDL_Surface *alphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue); -extern void createMessageBox(SDL_Surface *face, const char *message, signed char transparent); -extern void freeGraphics(); - -extern SDL_Surface *loadImage(const char *filename); +SDL_Surface *gfx_createAlphaRect(int width, int height, Uint8 red, Uint8 green, Uint8 blue); +void gfx_createMessageBox(SDL_Surface *face, const char *message, signed char transparent); +SDL_Surface *gfx_loadImage(const char *filename); +void gfx_free(); #endif diff --git a/src/init.cpp b/src/init.cpp deleted file mode 100644 index f45c9da..0000000 --- a/src/init.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/* -Copyright (C) 2003 Parallel Realities -Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2012, 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 "Starfighter.h" - -#include -#include -#include -#include - -/* -Initalises a whole load of variables -*/ -void initVars() -{ - srand(time(NULL)); - - if (engine.useAudio) - { - Mix_Volume(-1, 100); - Mix_VolumeMusic(engine.musicVolume); - } -} - -/* -Something went wrong. This stops the game, present the error message and -prompts the user to press space or ctrl to exit the game. This is unlikely to -be seen by people unless something really stoopid happens! -*/ -void showErrorAndExit(int errorId, const char *name) -{ - screen_clear(black); - - if (errorId != 2) - { - screen_renderString("A file error has occurred", -1, 200, FONT_RED); - } - else - { - printf("Couldn't create or write to directory '%s'\n", name); - exit(1); - } - - char string[255]; - - switch(errorId) - { - case 0: - sprintf(string, "%s was not found in the Starfighter data package", name); - screen_renderString(string, -1, 250, FONT_WHITE); - screen_renderString("Please try again. If this error persists, contact the authors", -1, 275, FONT_WHITE); - screen_renderString("or reinstall the game", -1, 300, FONT_WHITE); - break; - case 1: - screen_renderString("Project: Starfighter encountered an error whilst", -1, 250, FONT_WHITE); - screen_renderString("attempting to load game data. Please try running", -1, 275, FONT_WHITE); - screen_renderString("the game again. If the errors persist, reinstall the game", -1, 300, FONT_WHITE); - break; - case 2: - screen_renderString("Project: Starfighter encountered a critical error", -1, 250, FONT_WHITE); - screen_renderString("while attempting to perform a required program function.", -1, 275, FONT_WHITE); - screen_renderString("Please contact the authors with details.", -1, 300, FONT_WHITE); - break; - } - - screen_renderString("Project: Starfighter will now exit", -1, 450, FONT_WHITE); - screen_renderString("Press Space to continue", -1, 475, FONT_WHITE); - - renderer_update(); - - engine.keyState[KEY_ALTFIRE] = 0; - - while (!engine.keyState[KEY_ALTFIRE]) - { - getPlayerInput(); - game_delayFrame(); - } - - exit(1); -} - -/* -This gets the user's home directory, then creates the .parallelrealities -and .parallelrealities/starfighter directories so that saves and -temporary data files can be written there. -*/ -static void setupUserHomeDirectory() -{ - const char *userHome; - - if ((userHome = getenv("HOME")) == NULL) - userHome = getpwuid(getuid())->pw_dir; - - char dir[PATH_MAX]; - strcpy(dir, ""); - - sprintf(dir, "%s/.parallelrealities", userHome); - if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) - showErrorAndExit(2, dir); - - sprintf(dir, "%s/.parallelrealities/starfighter", userHome); - if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) - showErrorAndExit(2, dir); - - sprintf(engine.userHomeDirectory, "%s/.parallelrealities/starfighter/", userHome); -} - -/* -Chugg chugg chugg.... brrr... chugg chugg chugg...brrrrrr... chugg ch.. -BRRRRRRRRRRRRRRRRRMMMMMMMMMMMMMMMMMMM!! Well, hopefully anyway! ;) -*/ -void initSystem() -{ - strcpy(engine.userHomeDirectory, ""); - - setupUserHomeDirectory(); - - /* Initialize the SDL library */ - if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_JOYSTICK) < 0) - { - printf("Couldn't initialize SDL: %s\n", SDL_GetError()); - exit(1); - } - - char filename[PATH_MAX]; - int fullScreen = 0; - int useSound = 1; - int useMusic = 1; - int autoPause = 0; - - FILE *fp; - sprintf(filename, "%sconf", engine.userHomeDirectory); - fp = fopen(filename, "rb"); - - if (fp != NULL) - { - if (fscanf(fp, "%d %d %d %d", &fullScreen, &useSound, &useMusic, &autoPause) < 4) - printf("Warning: Config file \"%s\" is not correctly formatted\n", filename); - fclose(fp); - } - - engine.fullScreen = fullScreen; - engine.useSound = useSound; - engine.useMusic = useMusic; - engine.autoPause = autoPause; - - screen = SDL_CreateRGBSurface(0, screenWidth, screenHeight, 32, 0xff0000, 0xff00, 0xff, 0xff000000); - - if (!screen) - { - printf("Couldn't create %ix%ix32 surface: %s\n", screenWidth, screenHeight, SDL_GetError()); - exit(1); - } - - window = SDL_CreateWindow("Project: Starfighter", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, screen->w, screen->h, 0); - - if (window == NULL) - { - printf("Could not create window: %s\n", SDL_GetError()); - exit(1); - } - - SDL_SetWindowIcon(window, loadImage("gfx/alienDevice.png")); - SDL_SetWindowFullscreen(window, engine.fullScreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); - - renderer = SDL_CreateRenderer(window, -1, 0); - - if (!renderer) - { - printf("Could not create renderer: %s\n", SDL_GetError()); - exit(1); - } - - SDL_RenderSetLogicalSize(renderer, screen->w, screen->h); - - renderer_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, screen->w, screen->h); - - if (!renderer_texture) - { - printf("Couldn't create %ix%ix32 texture: %s\n", screen->w, screen->h, SDL_GetError()); - exit(1); - } - - if (engine.useAudio) - { - if (Mix_OpenAudio(44100, AUDIO_S16, engine.useAudio * 2, 1024) < 0) - { - printf("Warning: Couldn't set 44100 Hz 16-bit stereo audio - Reason:\n%s\n", Mix_GetError()); - printf("Sound and Music will be disabled\n"); - engine.useAudio = false; - } - } - - SDL_ShowCursor(SDL_DISABLE); - SDL_EventState(SDL_MOUSEMOTION, SDL_DISABLE); - - SDL_JoystickEventState(SDL_ENABLE); - SDL_JoystickOpen(0); -} - -/* -Removes [hopefully] all the resources that has been -loaded and created during the game. This is called by -atexit(); -*/ -void cleanUp() -{ - freeGraphics(); - SDL_FreeSurface(gfx_background); - audio_free(); - resetLists(); - delete(engine.bulletHead); - delete(engine.explosionHead); - delete(engine.collectableHead); - delete(screen_bufferHead); - - for (int i = 0 ; i < MAX_FONTSHAPES ; i++) - { - if (fontShape[i] != NULL) - SDL_FreeSurface(fontShape[i]); - } - - char filename[PATH_MAX]; - strcpy(filename, ""); - - sprintf(filename, "%smusic.mod", engine.userHomeDirectory); - remove(filename); - - sprintf(filename, "%smusic.s3m", engine.userHomeDirectory); - remove(filename); - - if (engine.useAudio) - { - Mix_CloseAudio(); - } - - // Save the config using current settings - FILE *fp; - sprintf(filename, "%sconf", engine.userHomeDirectory); - fp = fopen(filename, "wb"); - if (fp != NULL) - { - fprintf(fp, "%d %d %d %d\n", engine.fullScreen, engine.useSound, - engine.useMusic, engine.autoPause); - fclose(fp); - } - else - { - printf("Error saving config\n"); - } - - SDL_Quit(); - printf("Thank You for playing Starfighter\n"); -} - diff --git a/src/init.h b/src/init.h deleted file mode 100644 index a58848c..0000000 --- a/src/init.h +++ /dev/null @@ -1,28 +0,0 @@ -/* -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 INIT_H -#define INIT_H - -extern void initVars(); -extern void showErrorAndExit(int errorId, const char *name); -extern void initSystem(); -extern void cleanUp(); - -#endif diff --git a/src/intermission.cpp b/src/intermission.cpp index f348341..5960739 100644 --- a/src/intermission.cpp +++ b/src/intermission.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2012, 2015 Julian Marchant +Copyright (C) 2012, 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -567,7 +567,7 @@ selected an icon. */ int intermission() { - freeGraphics(); + gfx_free(); checkForBossMission(); // double check just to make sure! @@ -587,33 +587,33 @@ int intermission() engine.cursor_x = screen->w / 2; engine.cursor_y = screen->h / 2; - shape[0] = loadImage("gfx/cursor.png"); + shape[0] = gfx_loadImage("gfx/cursor.png"); // Icons 1 - 29 for (int i = 0 ; i < 26 ; i++) { sprintf(string, "gfx/icon%d.png", (i + 1)); - shape[i + 1] = loadImage(string); + shape[i + 1] = gfx_loadImage(string); } - shape[27] = loadImage("gfx/buyIcon.png"); - shape[28] = loadImage("gfx/sellIcon.png"); - shape[29] = loadImage("gfx/firefly1.png"); + shape[27] = gfx_loadImage("gfx/buyIcon.png"); + shape[28] = gfx_loadImage("gfx/sellIcon.png"); + shape[29] = gfx_loadImage("gfx/firefly1.png"); // Planets 30 - 39 - shape[30] = loadImage("gfx/planet_sun.png"); - shape[31] = loadImage("gfx/planet_green.png"); - shape[32] = loadImage("gfx/planet_blue.png"); - shape[33] = loadImage("gfx/planet_red.png"); - shape[34] = loadImage("gfx/planet_orange.png"); + shape[30] = gfx_loadImage("gfx/planet_sun.png"); + shape[31] = gfx_loadImage("gfx/planet_green.png"); + shape[32] = gfx_loadImage("gfx/planet_blue.png"); + shape[33] = gfx_loadImage("gfx/planet_red.png"); + shape[34] = gfx_loadImage("gfx/planet_orange.png"); // Faces (as defines) - shape[FACE_CHRIS] = loadImage("gfx/face_chris.png"); - shape[FACE_SID] = loadImage("gfx/face_sid.png"); - shape[FACE_KRASS] = loadImage("gfx/face_krass.png"); - shape[FACE_PHOEBE] = loadImage("gfx/face_phoebe.png"); - shape[FACE_URSULA] = loadImage("gfx/face_ursula.png"); - shape[FACE_KLINE] = loadImage("gfx/face_kline.png"); + shape[FACE_CHRIS] = gfx_loadImage("gfx/face_chris.png"); + shape[FACE_SID] = gfx_loadImage("gfx/face_sid.png"); + shape[FACE_KRASS] = gfx_loadImage("gfx/face_krass.png"); + shape[FACE_PHOEBE] = gfx_loadImage("gfx/face_phoebe.png"); + shape[FACE_URSULA] = gfx_loadImage("gfx/face_ursula.png"); + shape[FACE_KLINE] = gfx_loadImage("gfx/face_kline.png"); engine.done = 0; engine.keyState[KEY_FIRE] = 0; @@ -629,7 +629,7 @@ int intermission() initShop(); intermission_setSystemPlanets(); - SDL_Surface *statsSurface = alphaRect(600, 330, 0x00, 0x00, 0x99); + SDL_Surface *statsSurface = gfx_createAlphaRect(600, 330, 0x00, 0x00, 0x99); SDL_Surface *savesSurface = gfx_createSurface(350, 300); SDL_Surface *optionsSurface = gfx_createSurface(320, 240); SDL_Surface *commsSurface = gfx_createSurface(450, 400); diff --git a/src/intermission.h b/src/intermission.h index e6ae69c..652b86c 100644 --- a/src/intermission.h +++ b/src/intermission.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/loadSave.cpp b/src/loadSave.cpp index 18ab5a3..eaecef4 100644 --- a/src/loadSave.cpp +++ b/src/loadSave.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -42,7 +42,7 @@ int initSaveSlots() //READ SAVE GAME DATA for (int i = 0 ; i <= 5 ; i++) { - sprintf(fileName, "%ssave%.2d.dat", engine.userHomeDirectory, i); + sprintf(fileName, "%ssave%.2d.dat", engine.configDirectory, i); fp = fopen(fileName, "rb"); if (fp == NULL) @@ -96,7 +96,7 @@ bool loadGame(int slot) { char filename[PATH_MAX]; FILE *fp; - sprintf(filename, "%ssave%.2d.dat", engine.userHomeDirectory, slot); + sprintf(filename, "%ssave%.2d.dat", engine.configDirectory, slot); fp = fopen(filename, "rb"); @@ -139,7 +139,7 @@ void saveGame(int slot) return; } - sprintf(fileName, "%ssave%.2d.dat", engine.userHomeDirectory, slot); + sprintf(fileName, "%ssave%.2d.dat", engine.configDirectory, slot); fp = fopen(fileName, "wb"); game.saveFormat = 3; @@ -265,7 +265,7 @@ int showSaveSlots(SDL_Surface *savesSurface, signed char saveSlot) 365, 100, 25)) { char filename[PATH_MAX]; - sprintf(filename, "%ssave%.2d.dat", engine.userHomeDirectory, + sprintf(filename, "%ssave%.2d.dat", engine.configDirectory, saveSlot); remove(filename); initSaveSlots(); diff --git a/src/loadSave.h b/src/loadSave.h index 8356291..9eefedf 100644 --- a/src/loadSave.h +++ b/src/loadSave.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/messages.cpp b/src/messages.cpp index bbd7fa2..5338180 100644 --- a/src/messages.cpp +++ b/src/messages.cpp @@ -1,6 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012 Guus Sliepen +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/messages.h b/src/messages.h index ca0d0af..3844e72 100644 --- a/src/messages.h +++ b/src/messages.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/misc.cpp b/src/misc.cpp index 42254b1..7951f6b 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -83,7 +83,7 @@ void setRadioMessage(signed char face, const char *in, int priority) if (face > -1) faceShape = shape[face]; - createMessageBox(faceShape, in, 1); + gfx_createMessageBox(faceShape, in, 1); } static const char *faces[] = { diff --git a/src/misc.h b/src/misc.h index 78efea7..68f694a 100644 --- a/src/misc.h +++ b/src/misc.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/missions.cpp b/src/missions.cpp index aa58008..2dd8c59 100644 --- a/src/missions.cpp +++ b/src/missions.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2012, 2015 Julian Marchant +Copyright (C) 2012, 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/missions.h b/src/missions.h index e7f4008..8bd74d0 100644 --- a/src/missions.h +++ b/src/missions.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/player.cpp b/src/player.cpp index fd483fa..adb4438 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2012, 2015 Julian Marchant +Copyright (C) 2012, 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/player.h b/src/player.h index 0f70ada..9e3e388 100644 --- a/src/player.h +++ b/src/player.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/renderer.cpp b/src/renderer.cpp index 0e08341..cd46d81 100644 --- a/src/renderer.cpp +++ b/src/renderer.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/renderer.h b/src/renderer.h index e9f786d..19de26e 100644 --- a/src/renderer.h +++ b/src/renderer.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/resources.cpp b/src/resources.cpp index c0980bb..43c0bf4 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -26,7 +26,7 @@ void loadBackground(const char *filename) SDL_FreeSurface(gfx_background); gfx_background = NULL; } - gfx_background = loadImage(filename); + gfx_background = gfx_loadImage(filename); SDL_SetColorKey(gfx_background, 0, 0); } @@ -39,10 +39,10 @@ void loadGameGraphics() Uint16 *p16; Uint8 *p8; - freeGraphics(); + gfx_free(); - shipShape[0] = loadImage("gfx/firefly1.png"); - shipShape[1] = loadImage("gfx/firefly2.png"); + shipShape[0] = gfx_loadImage("gfx/firefly1.png"); + shipShape[1] = gfx_loadImage("gfx/firefly2.png"); switch(game.system) { @@ -67,7 +67,7 @@ void loadGameGraphics() while (fscanf(fp, "%d %s", &index, string) == 2) { - shipShape[index] = loadImage(string); + shipShape[index] = gfx_loadImage(string); } fclose(fp); @@ -131,7 +131,7 @@ void loadGameGraphics() while (fscanf(fp, "%d %s", &index, string) == 2) { - shape[index] = loadImage(string); + shape[index] = gfx_loadImage(string); } fclose(fp); diff --git a/src/resources.h b/src/resources.h index f0e75c5..7ad200b 100644 --- a/src/resources.h +++ b/src/resources.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/screen.cpp b/src/screen.cpp index d7db0d6..66f11dc 100644 --- a/src/screen.cpp +++ b/src/screen.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -21,8 +21,8 @@ along with this program. If not, see . #include "SDL.h" +#include "engine.h" #include "gfx.h" -#include "init.h" #include "structs.h" SDL_Surface *screen; @@ -102,7 +102,7 @@ void screen_unBuffer() if (SDL_BlitSurface(gfx_background, &blitRect, screen, &blitRect) < 0) { printf("BlitSurface error: %s\n", SDL_GetError()); - showErrorAndExit(2, ""); + engine_showError(2, ""); } prevRect->next = rect->next; diff --git a/src/screen.h b/src/screen.h index 563739b..a13ee8f 100644 --- a/src/screen.h +++ b/src/screen.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/script.cpp b/src/script.cpp index 0e42269..88dd6de 100644 --- a/src/script.cpp +++ b/src/script.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2012, 2015 Julian Marchant +Copyright (C) 2012, 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -199,7 +199,7 @@ void doCutscene(int scene) engine.smy = 0; screen_flushBuffer(); - freeGraphics(); + gfx_free(); resetLists(); loadGameGraphics(); @@ -294,7 +294,7 @@ void doCutscene(int scene) face = NULL; if (cutMessage[currentMessage].face != -1) face = shape[cutMessage[currentMessage].face]; - createMessageBox(face, cutMessage[currentMessage].message, 0); + gfx_createMessageBox(face, cutMessage[currentMessage].message, 0); } } @@ -311,7 +311,7 @@ void doCutscene(int scene) } screen_flushBuffer(); - freeGraphics(); + gfx_free(); screen_clear(black); renderer_update(); } diff --git a/src/script.h b/src/script.h index 29ec9ec..8bba7d8 100644 --- a/src/script.h +++ b/src/script.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/ship.cpp b/src/ship.cpp index 05c42f7..97be05f 100644 --- a/src/ship.cpp +++ b/src/ship.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/ship.h b/src/ship.h index 1031382..47c3452 100644 --- a/src/ship.h +++ b/src/ship.h @@ -1,5 +1,5 @@ /* -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/shop.cpp b/src/shop.cpp index f79fca7..9053a19 100644 --- a/src/shop.cpp +++ b/src/shop.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -161,7 +161,7 @@ static void drawShop() gfx_drawRect(shopSurface[i], 0, 0, 245, 20, 0x00, 0x00, 0x99); } - shopSurface[4] = alphaRect(601, 101, 0x00, 0x00, 0x00); + shopSurface[4] = gfx_createAlphaRect(601, 101, 0x00, 0x00, 0x00); gfx_drawRect(shopSurface[4], 0, 0, 600, 100, 0x00, 0x00, 0x33); switch (shopSelectedItem) diff --git a/src/shop.h b/src/shop.h index ba93fe9..5301621 100644 --- a/src/shop.h +++ b/src/shop.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/structs.h b/src/structs.h index 58ca24c..431bec9 100644 --- a/src/structs.h +++ b/src/structs.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -303,7 +303,7 @@ struct Engine { bool fullScreen; bool autoPause; - char userHomeDirectory[1024]; + char configDirectory[1024]; char keyState[KEY_LAST]; diff --git a/src/title.cpp b/src/title.cpp index c047790..8977ae1 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2012, 2015 Julian Marchant +Copyright (C) 2012, 2015, 2016 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -181,7 +181,7 @@ int doTitle() engine.gameSection = SECTION_TITLE; screen_flushBuffer(); - freeGraphics(); + gfx_free(); resetLists(); // required to stop the title screen crashing @@ -199,8 +199,8 @@ int doTitle() loadBackground("gfx/spirit.jpg"); SDL_Surface *prlogo, *sflogo; - prlogo = loadImage("gfx/prlogo.png"); - sflogo = loadImage("gfx/sflogo.png"); + prlogo = gfx_loadImage("gfx/prlogo.png"); + sflogo = gfx_loadImage("gfx/sflogo.png"); int prx = ((screen->w - prlogo->w) / 2); int pry = ((screen->h - prlogo->h) / 2); @@ -569,7 +569,7 @@ Scrolls the intro text up the screen and nothing else. */ void showStory() { - freeGraphics(); + gfx_free(); int y = screen->h + 20; @@ -634,13 +634,13 @@ The game over screen :( void gameover() { screen_flushBuffer(); - freeGraphics(); + gfx_free(); SDL_FillRect(gfx_background, NULL, black); engine.keyState[KEY_FIRE] = engine.keyState[KEY_ALTFIRE] = 0; engine.gameSection = SECTION_INTERMISSION; - SDL_Surface *gameover = loadImage("gfx/gameover.png"); + SDL_Surface *gameover = gfx_loadImage("gfx/gameover.png"); screen_clear(black); renderer_update(); @@ -683,7 +683,7 @@ void doCredits() { loadBackground("gfx/credits.jpg"); screen_flushBuffer(); - freeGraphics(); + gfx_free(); FILE *fp; int lastCredit = -1; diff --git a/src/title.h b/src/title.h index 316cae3..eb3fe6e 100644 --- a/src/title.h +++ b/src/title.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/weapons.cpp b/src/weapons.cpp index 79be417..d09f1af 100644 --- a/src/weapons.cpp +++ b/src/weapons.cpp @@ -1,6 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2013 Guus Sliepen +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/weapons.h b/src/weapons.h index 0fd8493..7d9f2c4 100644 --- a/src/weapons.h +++ b/src/weapons.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/window.cpp b/src/window.cpp index 66c1502..944b25d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011, 2012, 2013 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License diff --git a/src/window.h b/src/window.h index e8ab0e6..ae158b4 100644 --- a/src/window.h +++ b/src/window.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003 Parallel Realities Copyright (C) 2011 Guus Sliepen -Copyright (C) 2015 Julian Marchant +Copyright (C) 2015 onpon4 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License