From 67e6191020aea31d694abae1d4260b44dffc0203 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Wed, 3 Jun 2009 16:35:05 +0100 Subject: [PATCH] Minor code tidy --- config.h.in | 8 +- configure.ac | 4 + m4/ax_boost_base.m4 | 219 ++++++++++++++++++++++++++++++++++++++ m4/ax_boost_filesystem.m4 | 112 +++++++++++++++++++ src/Geometry.hpp | 3 +- src/HighScores.cpp | 15 ++- src/HighScores.hpp | 7 +- src/Main.cpp | 65 +++++------ src/Makefile.am | 2 +- src/ObjectGrid.hpp | 1 + src/OpenGL.hpp | 10 +- src/Platform.hpp | 2 +- src/Ship.cpp | 14 +-- src/SoundEffect.cpp | 4 +- src/SoundEffect.hpp | 2 +- src/Texture.cpp | 4 +- src/Texture.hpp | 2 +- 17 files changed, 402 insertions(+), 72 deletions(-) create mode 100644 m4/ax_boost_base.m4 create mode 100644 m4/ax_boost_filesystem.m4 diff --git a/config.h.in b/config.h.in index 58fd294..465ac82 100644 --- a/config.h.in +++ b/config.h.in @@ -7,6 +7,12 @@ /* Define to 1 if you have the `atexit' function. */ #undef HAVE_ATEXIT +/* define if the Boost library is available */ +#undef HAVE_BOOST + +/* define if the Boost::Filesystem library is available */ +#undef HAVE_BOOST_FILESYSTEM + /* Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the CoreFoundation framework. */ #undef HAVE_CFLOCALECOPYCURRENT @@ -119,7 +125,7 @@ #undef VERSION /* Define for Solaris 2.5.1 so the uint32_t typedef from , - , or is not used. If the typedef were allowed, the + , or is not used. If the typedef was allowed, the #define below would cause a syntax error. */ #undef _UINT32_T diff --git a/configure.ac b/configure.ac index 420e95f..dc37c9b 100644 --- a/configure.ac +++ b/configure.ac @@ -26,6 +26,10 @@ AC_FUNC_MALLOC AC_FUNC_STAT AC_CHECK_FUNCS([atexit memset pow setlocale sqrt]) +dnl Check for Boost +AX_BOOST_BASE(1.33) +AX_BOOST_FILESYSTEM + dnl Check for SDL SDL_VERSION=1.2.5 AM_PATH_SDL($SDL_VERSION, diff --git a/m4/ax_boost_base.m4 b/m4/ax_boost_base.m4 new file mode 100644 index 0000000..b2a00b8 --- /dev/null +++ b/m4/ax_boost_base.m4 @@ -0,0 +1,219 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/ax_boost_base.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_BOOST_BASE([MINIMUM-VERSION]) +# +# DESCRIPTION +# +# Test for the Boost C++ libraries of a particular version (or newer) +# +# If no path to the installed boost library is given the macro searchs +# under /usr, /usr/local, /opt and /opt/local and evaluates the +# $BOOST_ROOT environment variable. Further documentation is available at +# . +# +# This macro calls: +# +# AC_SUBST(BOOST_CPPFLAGS) / AC_SUBST(BOOST_LDFLAGS) +# +# And sets: +# +# HAVE_BOOST +# +# LICENSE +# +# Copyright (c) 2008 Thomas Porschberg +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AX_BOOST_BASE], +[ +AC_ARG_WITH([boost], + AS_HELP_STRING([--with-boost@<:@=DIR@:>@], [use boost (default is yes) - it is possible to specify the root directory for boost (optional)]), + [ + if test "$withval" = "no"; then + want_boost="no" + elif test "$withval" = "yes"; then + want_boost="yes" + ac_boost_path="" + else + want_boost="yes" + ac_boost_path="$withval" + fi + ], + [want_boost="yes"]) + + +AC_ARG_WITH([boost-libdir], + AS_HELP_STRING([--with-boost-libdir=LIB_DIR], + [Force given directory for boost libraries. Note that this will overwrite library path detection, so use this parameter only if default library detection fails and you know exactly where your boost libraries are located.]), + [ + if test -d $withval + then + ac_boost_lib_path="$withval" + else + AC_MSG_ERROR(--with-boost-libdir expected directory name) + fi + ], + [ac_boost_lib_path=""] +) + +if test "x$want_boost" = "xyes"; then + boost_lib_version_req=ifelse([$1], ,1.20.0,$1) + boost_lib_version_req_shorten=`expr $boost_lib_version_req : '\([[0-9]]*\.[[0-9]]*\)'` + boost_lib_version_req_major=`expr $boost_lib_version_req : '\([[0-9]]*\)'` + boost_lib_version_req_minor=`expr $boost_lib_version_req : '[[0-9]]*\.\([[0-9]]*\)'` + boost_lib_version_req_sub_minor=`expr $boost_lib_version_req : '[[0-9]]*\.[[0-9]]*\.\([[0-9]]*\)'` + if test "x$boost_lib_version_req_sub_minor" = "x" ; then + boost_lib_version_req_sub_minor="0" + fi + WANT_BOOST_VERSION=`expr $boost_lib_version_req_major \* 100000 \+ $boost_lib_version_req_minor \* 100 \+ $boost_lib_version_req_sub_minor` + AC_MSG_CHECKING(for boostlib >= $boost_lib_version_req) + succeeded=no + + dnl first we check the system location for boost libraries + dnl this location ist chosen if boost libraries are installed with the --layout=system option + dnl or if you install boost with RPM + if test "$ac_boost_path" != ""; then + BOOST_LDFLAGS="-L$ac_boost_path/lib" + BOOST_CPPFLAGS="-I$ac_boost_path/include" + else + for ac_boost_path_tmp in /usr /usr/local /opt /opt/local ; do + if test -d "$ac_boost_path_tmp/include/boost" && test -r "$ac_boost_path_tmp/include/boost"; then + BOOST_LDFLAGS="-L$ac_boost_path_tmp/lib" + BOOST_CPPFLAGS="-I$ac_boost_path_tmp/include" + break; + fi + done + fi + + dnl overwrite ld flags if we have required special directory with + dnl --with-boost-libdir parameter + if test "$ac_boost_lib_path" != ""; then + BOOST_LDFLAGS="-L$ac_boost_lib_path" + fi + + CPPFLAGS_SAVED="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + + LDFLAGS_SAVED="$LDFLAGS" + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_LANG_PUSH(C++) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + @%:@include + ]], [[ + #if BOOST_VERSION >= $WANT_BOOST_VERSION + // Everything is okay + #else + # error Boost version is too old + #endif + ]])],[ + AC_MSG_RESULT(yes) + succeeded=yes + found_system=yes + ],[ + ]) + AC_LANG_POP([C++]) + + + + dnl if we found no boost with system layout we search for boost libraries + dnl built and installed without the --layout=system option or for a staged(not installed) version + if test "x$succeeded" != "xyes"; then + _version=0 + if test "$ac_boost_path" != ""; then + if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then + for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do + _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` + V_CHECK=`expr $_version_tmp \> $_version` + if test "$V_CHECK" = "1" ; then + _version=$_version_tmp + fi + VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` + BOOST_CPPFLAGS="-I$ac_boost_path/include/boost-$VERSION_UNDERSCORE" + done + fi + else + for ac_boost_path in /usr /usr/local /opt /opt/local ; do + if test -d "$ac_boost_path" && test -r "$ac_boost_path"; then + for i in `ls -d $ac_boost_path/include/boost-* 2>/dev/null`; do + _version_tmp=`echo $i | sed "s#$ac_boost_path##" | sed 's/\/include\/boost-//' | sed 's/_/./'` + V_CHECK=`expr $_version_tmp \> $_version` + if test "$V_CHECK" = "1" ; then + _version=$_version_tmp + best_path=$ac_boost_path + fi + done + fi + done + + VERSION_UNDERSCORE=`echo $_version | sed 's/\./_/'` + BOOST_CPPFLAGS="-I$best_path/include/boost-$VERSION_UNDERSCORE" + if test "$ac_boost_lib_path" = "" + then + BOOST_LDFLAGS="-L$best_path/lib" + fi + + if test "x$BOOST_ROOT" != "x"; then + if test -d "$BOOST_ROOT" && test -r "$BOOST_ROOT" && test -d "$BOOST_ROOT/stage/lib" && test -r "$BOOST_ROOT/stage/lib"; then + version_dir=`expr //$BOOST_ROOT : '.*/\(.*\)'` + stage_version=`echo $version_dir | sed 's/boost_//' | sed 's/_/./g'` + stage_version_shorten=`expr $stage_version : '\([[0-9]]*\.[[0-9]]*\)'` + V_CHECK=`expr $stage_version_shorten \>\= $_version` + if test "$V_CHECK" = "1" -a "$ac_boost_lib_path" = "" ; then + AC_MSG_NOTICE(We will use a staged boost library from $BOOST_ROOT) + BOOST_CPPFLAGS="-I$BOOST_ROOT" + BOOST_LDFLAGS="-L$BOOST_ROOT/stage/lib" + fi + fi + fi + fi + + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + AC_LANG_PUSH(C++) + AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ + @%:@include + ]], [[ + #if BOOST_VERSION >= $WANT_BOOST_VERSION + // Everything is okay + #else + # error Boost version is too old + #endif + ]])],[ + AC_MSG_RESULT(yes) + succeeded=yes + found_system=yes + ],[ + ]) + AC_LANG_POP([C++]) + fi + + if test "$succeeded" != "yes" ; then + if test "$_version" = "0" ; then + AC_MSG_ERROR([[We could not detect the boost libraries (version $boost_lib_version_req_shorten or higher). If you have a staged boost library (still not installed) please specify \$BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in . See http://randspringer.de/boost for more documentation.]]) + else + AC_MSG_NOTICE([Your boost libraries seems to old (version $_version).]) + fi + else + AC_SUBST(BOOST_CPPFLAGS) + AC_SUBST(BOOST_LDFLAGS) + AC_DEFINE(HAVE_BOOST,,[define if the Boost library is available]) + fi + + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" +fi + +]) diff --git a/m4/ax_boost_filesystem.m4 b/m4/ax_boost_filesystem.m4 new file mode 100644 index 0000000..5f366f9 --- /dev/null +++ b/m4/ax_boost_filesystem.m4 @@ -0,0 +1,112 @@ +# =========================================================================== +# http://www.nongnu.org/autoconf-archive/ax_boost_filesystem.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_BOOST_FILESYSTEM +# +# DESCRIPTION +# +# Test for Filesystem library from the Boost C++ libraries. The macro +# requires a preceding call to AX_BOOST_BASE. Further documentation is +# available at . +# +# This macro calls: +# +# AC_SUBST(BOOST_FILESYSTEM_LIB) +# +# And sets: +# +# HAVE_BOOST_FILESYSTEM +# +# LICENSE +# +# Copyright (c) 2009 Thomas Porschberg +# Copyright (c) 2009 Michael Tindal +# Copyright (c) 2009 Roman Rybalko +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. + +AC_DEFUN([AX_BOOST_FILESYSTEM], +[ + AC_ARG_WITH([boost-filesystem], + AS_HELP_STRING([--with-boost-filesystem@<:@=special-lib@:>@], + [use the Filesystem library from boost - it is possible to specify a certain library for the linker + e.g. --with-boost-filesystem=boost_filesystem-gcc-mt ]), + [ + if test "$withval" = "no"; then + want_boost="no" + elif test "$withval" = "yes"; then + want_boost="yes" + ax_boost_user_filesystem_lib="" + else + want_boost="yes" + ax_boost_user_filesystem_lib="$withval" + fi + ], + [want_boost="yes"] + ) + + if test "x$want_boost" = "xyes"; then + AC_REQUIRE([AC_PROG_CC]) + CPPFLAGS_SAVED="$CPPFLAGS" + CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" + export CPPFLAGS + + LDFLAGS_SAVED="$LDFLAGS" + LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" + export LDFLAGS + + LIBS_SAVED=$LIBS + LIBS="$LIBS $BOOST_SYSTEM_LIB" + export LIBS + + AC_CACHE_CHECK(whether the Boost::Filesystem library is available, + ax_cv_boost_filesystem, + [AC_LANG_PUSH([C++]) + AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[@%:@include ]], + [[using namespace boost::filesystem; + path my_path( "foo/bar/data.txt" ); + return 0;]]), + ax_cv_boost_filesystem=yes, ax_cv_boost_filesystem=no) + AC_LANG_POP([C++]) + ]) + if test "x$ax_cv_boost_filesystem" = "xyes"; then + AC_DEFINE(HAVE_BOOST_FILESYSTEM,,[define if the Boost::Filesystem library is available]) + BOOSTLIBDIR=`echo $BOOST_LDFLAGS | sed -e 's/@<:@^\/@:>@*//'` + if test "x$ax_boost_user_filesystem_lib" = "x"; then + for libextension in `ls $BOOSTLIBDIR/libboost_filesystem*.{so,dylib,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^lib\(boost_filesystem.*\)\.so.*$;\1;' -e 's;^lib\(boost_filesystem.*\)\.a*$;\1;' -e 's;^lib\(boost_filesystem.*\)\.dylib$;\1;'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], + [link_filesystem="no"]) + done + if test "x$link_program_options" != "xyes"; then + for libextension in `ls $BOOSTLIBDIR/boost_filesystem*.{dll,a}* 2>/dev/null | sed 's,.*/,,' | sed -e 's;^\(boost_filesystem.*\)\.dll.*$;\1;' -e 's;^\(boost_filesystem.*\)\.a*$;\1;'` ; do + ax_lib=${libextension} + AC_CHECK_LIB($ax_lib, exit, + [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], + [link_filesystem="no"]) + done + fi + else + for ax_lib in $ax_boost_user_filesystem_lib boost_filesystem-$ax_boost_user_filesystem_lib; do + AC_CHECK_LIB($ax_lib, exit, + [BOOST_FILESYSTEM_LIB="-l$ax_lib"; AC_SUBST(BOOST_FILESYSTEM_LIB) link_filesystem="yes"; break], + [link_filesystem="no"]) + done + + fi + if test "x$link_filesystem" != "xyes"; then + AC_MSG_ERROR(Could not link against $ax_lib !) + fi + fi + + CPPFLAGS="$CPPFLAGS_SAVED" + LDFLAGS="$LDFLAGS_SAVED" + LIBS="$LIBS_SAVED" + fi +]) diff --git a/src/Geometry.hpp b/src/Geometry.hpp index 83b9d6d..6438662 100644 --- a/src/Geometry.hpp +++ b/src/Geometry.hpp @@ -23,9 +23,8 @@ struct Point int x, y; }; -class LineSegment +struct LineSegment { -public: LineSegment(int x1, int y1, int x2, int y2) { p1.x=x1; p1.y=y1; p2.x=x2; p2.y=y2; } LineSegment() diff --git a/src/HighScores.cpp b/src/HighScores.cpp index 2797508..ad87525 100644 --- a/src/HighScores.cpp +++ b/src/HighScores.cpp @@ -21,6 +21,11 @@ #include "Input.hpp" #include "InterfaceSounds.hpp" +#include + +const float HighScores::FADE_IN_SPEED(0.2f); +const float HighScores::FADE_OUT_SPEED(-0.02f); + HighScores::HighScores() : hscoreImage("images/hscore.png"), largeFont(LocateResource("Default_Font.ttf"), 15), @@ -57,7 +62,7 @@ void HighScores::Process() || input.QueryAction(Input::FIRE)) { // Go back to main menu - fade = HS_FADE_OUT_SPEED; + fade = FADE_OUT_SPEED; for (i = 0; i < MAX_FIREWORKS; i++) { fw[i].em->maxspeed = 200; fw[i].speed = 0; @@ -82,7 +87,7 @@ void HighScores::Process() scoreFile.Save(); state = hssDisplay; flAlpha = 0.0f; - fade = HS_FADE_IN_SPEED; + fade = FADE_IN_SPEED; input.ResetAction(Input::FIRE); InterfaceSounds::PlaySelect(); @@ -240,7 +245,7 @@ void HighScores::DisplayScores() // Fade in flAlpha = 0.0f; - fade = HS_FADE_IN_SPEED; + fade = FADE_IN_SPEED; } // @@ -267,7 +272,7 @@ void HighScores::CheckScore(int score) // Fade in flAlpha = 0.0f; - fade = HS_FADE_IN_SPEED; + fade = FADE_IN_SPEED; } ScoreFile::ScoreFile() @@ -301,7 +306,7 @@ void ScoreFile::Load() { // Check for file's existence string hsname(GetHighScoreFile()); - if (!FileExists(hsname)) { + if (!boost::filesystem::exists(hsname)) { // Write a dummy score file Save(); } diff --git a/src/HighScores.hpp b/src/HighScores.hpp index 64588ee..09443f4 100644 --- a/src/HighScores.hpp +++ b/src/HighScores.hpp @@ -27,9 +27,6 @@ #include "Font.hpp" #include "SoundEffect.hpp" -#define HS_FADE_IN_SPEED 0.2f -#define HS_FADE_OUT_SPEED -0.02f - class ScoreFile { public: ScoreFile(); @@ -96,7 +93,9 @@ private: ScoreFile scoreFile; Font largeFont, scoreNameFont; SoundEffect fwBang; - + + static const float FADE_IN_SPEED, FADE_OUT_SPEED; + // Fireworks static const int MAX_FIREWORKS = 7; class Firework { diff --git a/src/Main.cpp b/src/Main.cpp index e621eb3..92353eb 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -32,22 +32,27 @@ namespace CF { #include -static MainMenu* menu = NULL; -static Game* game = NULL; -static HighScores* scores = NULL; -static Options* options = NULL; +#include +#include -static void DestroyScreens() -{ - ScreenManager::GetInstance().RemoveAllScreens(); - if (menu) - delete menu; - if (game) - delete game; - if (scores) - delete scores; - if (options) - delete options; +namespace { + MainMenu* menu = NULL; + Game* game = NULL; + HighScores* scores = NULL; + Options* options = NULL; + + void DestroyScreens() + { + ScreenManager::GetInstance().RemoveAllScreens(); + if (menu) + delete menu; + if (game) + delete game; + if (scores) + delete scores; + if (options) + delete options; + } } // See LoadOnce.hpp @@ -130,7 +135,7 @@ int main(int argc, char **argv) DestroyScreens(); } - catch (std::runtime_error& e) { + catch (const std::runtime_error& e) { #ifdef WIN32 MessageBox(NULL, e.what(), "Runtime Error", MB_OK | MB_ICONSTOP); #else /* #ifdef WIN32 */ @@ -144,18 +149,19 @@ int main(int argc, char **argv) // // Find a filename in the installation tree. // -const char* LocateResource(const char* file) +string LocateResource(const string& file) { - static char path[PATH_MAX]; #ifdef MACOSX - using namespace CF; + using namespace CF; + + static char path[PATH_MAX]; CFURLRef resURL; CFBundleRef mainBundle; CFStringRef cfBase, cfExt, cfPath; const char* ext = ""; - char* copy = strdup(file); + char* copy = strdup(file.c_str()); if (char* p = strrchr(copy, '.')) { *p = '\0'; ext = ++p; @@ -181,29 +187,12 @@ const char* LocateResource(const char* file) #endif #ifdef DATADIR - snprintf(path, PATH_MAX, "%s/%s", DATADIR, file); - return path; + return boost::lexical_cast(DATADIR) + "/" + file; #else return file; #endif } -bool FileExists(const string& file) -{ -#ifdef UNIX - struct stat buf; - return stat(file.c_str(), &buf) == 0; -#else - FILE* f = fopen(file.c_str(), "r"); - if (NULL == f) - return false; - else { - fclose(f); - return true; - } -#endif -} - string GetConfigDir() { #ifdef UNIX diff --git a/src/Makefile.am b/src/Makefile.am index ae5b4c2..ca67fb2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = lander # Add -pg for profiling AM_CXXFLAGS=$(LANDER_CFLAGS) $(SDL_CFLAGS) -Wall -AM_LDFLAGS=$(LANDER_LIBS) $(SDL_LIBS) -lGLU $(LTLIBINTL) +AM_LDFLAGS=$(LANDER_LIBS) $(SDL_LIBS) $(BOOST_FILESYSTEM_LIB) -lGLU $(LTLIBINTL) lander_SOURCES = Main.cpp Game.hpp Game.cpp \ Font.cpp Font.hpp HighScores.cpp HighScores.hpp Input.cpp \ Input.hpp Platform.hpp LoadOnce.hpp GraphicsFwd.hpp \ diff --git a/src/ObjectGrid.hpp b/src/ObjectGrid.hpp index 185a0f7..4a3320f 100644 --- a/src/ObjectGrid.hpp +++ b/src/ObjectGrid.hpp @@ -52,6 +52,7 @@ public: StaticObject(int xpos, int ypos, int width=1, int height=1) : xpos(xpos), ypos(ypos), width(width), height(height) {} StaticObject() { StaticObject(0, 0, 1, 1); } + virtual ~StaticObject() {} bool ObjectInScreen(Viewport* viewport); diff --git a/src/OpenGL.hpp b/src/OpenGL.hpp index 57a7377..8a48500 100644 --- a/src/OpenGL.hpp +++ b/src/OpenGL.hpp @@ -25,10 +25,8 @@ #define WINDOW_TITLE "Lunar Lander" #define FRAME_RATE 35 -#define PI 3.1415926535f -class Renderable { -public: +struct Renderable { Renderable(int x, int y, int width, int height, float r, float g, float b); virtual ~Renderable() {} @@ -42,8 +40,7 @@ public: float red, green, blue; }; -class ColourQuad : public Renderable { -public: +struct ColourQuad : Renderable { ColourQuad(int x=0, int y=0, int width=0, int height=0, float r=1, float g=1, float b=1); void Render(); @@ -53,8 +50,7 @@ public: // // A polygon with four points and a texture. // -class TextureQuad : public Renderable { -public: +struct TextureQuad : Renderable { TextureQuad(int qx=0, int qy=0, int width=0, int height=0, GLuint tex=0, float r=1, float g=1, float b=1); void Render(); diff --git a/src/Platform.hpp b/src/Platform.hpp index 1949604..35e010d 100644 --- a/src/Platform.hpp +++ b/src/Platform.hpp @@ -159,7 +159,7 @@ using namespace std; #endif /* #ifdef LANDER_BIG_ENDIAN */ void RecreateScreens(); -const char* LocateResource(const char* file); +string LocateResource(const string& file); bool FileExists(const string& file); string GetConfigDir(); diff --git a/src/Ship.cpp b/src/Ship.cpp index 0555587..e15175a 100644 --- a/src/Ship.cpp +++ b/src/Ship.cpp @@ -57,7 +57,7 @@ void Ship::DrawExplosion() void Ship::Move() { - RotatePoints(hotspots, points, NUM_HOTSPOTS, angle*PI/180, -16, 16); + RotatePoints(hotspots, points, NUM_HOTSPOTS, angle*M_PI/180, -16, 16); xpos += speedX; ypos += speedY; @@ -85,13 +85,13 @@ void Ship::Move() } exhaust.xpos = xpos + shipImage.GetWidth()/2 - - (shipImage.GetWidth()/2)*sin(angle*(PI/180)); + - (shipImage.GetWidth()/2)*sin(angle*(M_PI/180)); exhaust.ypos = ypos + shipImage.GetHeight()/2 - + (shipImage.GetHeight()/2)*cos(angle*(PI/180)); + + (shipImage.GetHeight()/2)*cos(angle*(M_PI/180)); const float SCALE = 1.0f; - exhaust.yi_bias = SCALE * cosf(angle*PI/180) + speedY; - exhaust.xi_bias = SCALE * -sinf(angle*PI/180) + speedX; + exhaust.yi_bias = SCALE * cosf(angle*M_PI/180) + speedY; + exhaust.xi_bias = SCALE * -sinf(angle*M_PI/180) + speedX; explosion.xpos = xpos + shipImage.GetWidth()/2; explosion.ypos = ypos + shipImage.GetHeight()/2; @@ -115,8 +115,8 @@ void Ship::ThrustOff() void Ship::Thrust(double speed) { - speedX += speed * sin(angle*(PI/180)); - speedY -= speed * cos(angle*(PI/180)); + speedX += speed * sin(angle*(M_PI/180)); + speedY -= speed * cos(angle*(M_PI/180)); } void Ship::Turn(double delta) diff --git a/src/SoundEffect.cpp b/src/SoundEffect.cpp index c7e1f67..772a87e 100644 --- a/src/SoundEffect.cpp +++ b/src/SoundEffect.cpp @@ -25,7 +25,7 @@ int SoundEffect::audioBuffers(1024); Uint16 SoundEffect::audioFormat(AUDIO_S16); bool SoundEffect::enabled(true); -SoundEffect::SoundEffect(const char* filename, Uint8 volume) +SoundEffect::SoundEffect(const string& filename, Uint8 volume) : sound(NULL), channel(-1) { if (++loadCount == 1) { @@ -44,7 +44,7 @@ SoundEffect::SoundEffect(const char* filename, Uint8 volume) if (!enabled) return; - if (!(sound = Mix_LoadWAV(filename))) { + if (!(sound = Mix_LoadWAV(filename.c_str()))) { ostringstream ss; ss << "Error loading " << filename << ": "; ss << Mix_GetError(); diff --git a/src/SoundEffect.hpp b/src/SoundEffect.hpp index 4197541..030cb8d 100644 --- a/src/SoundEffect.hpp +++ b/src/SoundEffect.hpp @@ -25,7 +25,7 @@ class SoundEffect { public: - SoundEffect(const char* filename, Uint8 volume = MIX_MAX_VOLUME); + SoundEffect(const string& filename, Uint8 volume = MIX_MAX_VOLUME); ~SoundEffect(); static void SetEnabled(bool state) { enabled = state; } diff --git a/src/Texture.cpp b/src/Texture.cpp index 1929f90..cfe1b6e 100644 --- a/src/Texture.cpp +++ b/src/Texture.cpp @@ -20,9 +20,9 @@ #include -Texture::Texture(const char* file) +Texture::Texture(const string& file) { - SDL_Surface* surface = IMG_Load(LocateResource(file)); + SDL_Surface* surface = IMG_Load(LocateResource(file).c_str()); if (NULL == surface) { ostringstream os; os << "Failed to load image: " << IMG_GetError(); diff --git a/src/Texture.hpp b/src/Texture.hpp index f6baa91..dd3147c 100644 --- a/src/Texture.hpp +++ b/src/Texture.hpp @@ -22,7 +22,7 @@ class Texture { public: - Texture(const char* file); + Texture(const string& file); virtual ~Texture(); GLuint GetGLTexture() const { return texture; } -- 2.39.2