From: <the...@us...> - 2007-04-01 18:42:24
|
Revision: 14 http://qonk.svn.sourceforge.net/qonk/?rev=14&view=rev Author: thebohemian Date: 2007-04-01 11:42:18 -0700 (Sun, 01 Apr 2007) Log Message: ----------- - Initial half-working version with autoconf support. Modified Paths: -------------- branches/autoconf-2007-03-26-thebohemian/src/actions.cpp branches/autoconf-2007-03-26-thebohemian/src/animations.cpp branches/autoconf-2007-03-26-thebohemian/src/animations.h branches/autoconf-2007-03-26-thebohemian/src/coordinate.cpp branches/autoconf-2007-03-26-thebohemian/src/extensions.cpp branches/autoconf-2007-03-26-thebohemian/src/extensions.h branches/autoconf-2007-03-26-thebohemian/src/main.cpp branches/autoconf-2007-03-26-thebohemian/src/messages.cpp branches/autoconf-2007-03-26-thebohemian/src/messages.h branches/autoconf-2007-03-26-thebohemian/src/planets.cpp branches/autoconf-2007-03-26-thebohemian/src/planets.h branches/autoconf-2007-03-26-thebohemian/src/players.cpp branches/autoconf-2007-03-26-thebohemian/src/players.h branches/autoconf-2007-03-26-thebohemian/src/selection.cpp branches/autoconf-2007-03-26-thebohemian/src/selection.h branches/autoconf-2007-03-26-thebohemian/src/ships.cpp branches/autoconf-2007-03-26-thebohemian/src/ships.h branches/autoconf-2007-03-26-thebohemian/src/stars.cpp branches/autoconf-2007-03-26-thebohemian/src/stars.h branches/autoconf-2007-03-26-thebohemian/src/timer.h branches/autoconf-2007-03-26-thebohemian/src/universe.cpp branches/autoconf-2007-03-26-thebohemian/src/universe.h Added Paths: ----------- branches/autoconf-2007-03-26-thebohemian/Makefile.am branches/autoconf-2007-03-26-thebohemian/autogen.sh branches/autoconf-2007-03-26-thebohemian/config.h.in branches/autoconf-2007-03-26-thebohemian/configure.ac branches/autoconf-2007-03-26-thebohemian/data/Makefile.am branches/autoconf-2007-03-26-thebohemian/src/Makefile.am branches/autoconf-2007-03-26-thebohemian/src/readconf.cpp branches/autoconf-2007-03-26-thebohemian/src/readconf.h branches/autoconf-2007-03-26-thebohemian/src/settings.cpp branches/autoconf-2007-03-26-thebohemian/src/settings.h Removed Paths: ------------- branches/autoconf-2007-03-26-thebohemian/src/ReadConf.cpp branches/autoconf-2007-03-26-thebohemian/src/ReadConf.h branches/autoconf-2007-03-26-thebohemian/src/config.cpp branches/autoconf-2007-03-26-thebohemian/src/config.h Added: branches/autoconf-2007-03-26-thebohemian/Makefile.am =================================================================== --- branches/autoconf-2007-03-26-thebohemian/Makefile.am (rev 0) +++ branches/autoconf-2007-03-26-thebohemian/Makefile.am 2007-04-01 18:42:18 UTC (rev 14) @@ -0,0 +1,4 @@ +SUBDIRS = src data + +EXTRA_DIST = README COPYING missing Makefile.manual TODO + Added: branches/autoconf-2007-03-26-thebohemian/autogen.sh =================================================================== --- branches/autoconf-2007-03-26-thebohemian/autogen.sh (rev 0) +++ branches/autoconf-2007-03-26-thebohemian/autogen.sh 2007-04-01 18:42:18 UTC (rev 14) @@ -0,0 +1,3 @@ +#!/bin/sh + +aclocal && automake --foreign && autoheader && autoconf Property changes on: branches/autoconf-2007-03-26-thebohemian/autogen.sh ___________________________________________________________________ Name: svn:executable + * Added: branches/autoconf-2007-03-26-thebohemian/config.h.in =================================================================== --- branches/autoconf-2007-03-26-thebohemian/config.h.in (rev 0) +++ branches/autoconf-2007-03-26-thebohemian/config.h.in 2007-04-01 18:42:18 UTC (rev 14) @@ -0,0 +1,106 @@ +/* config.h.in. Generated from configure.ac by autoheader. */ + +/* Define to 1 if you have the `atexit' function. */ +#undef HAVE_ATEXIT + +/* Define to 1 if you have the <inttypes.h> header file. */ +#undef HAVE_INTTYPES_H + +/* Define to 1 if you have the `SDL' library (-lSDL). */ +#undef HAVE_LIBSDL + +/* Define to 1 if you have the `SDL_gfx' library (-lSDL_gfx). */ +#undef HAVE_LIBSDL_GFX + +/* Define to 1 if you have the `SDL_ttf' library (-lSDL_ttf). */ +#undef HAVE_LIBSDL_TTF + +/* Define to 1 if you have the <memory.h> header file. */ +#undef HAVE_MEMORY_H + +/* Define to 1 if you have the `mkdir' function. */ +#undef HAVE_MKDIR + +/* Define to 1 if you have the <SDL/SDL_gfxPrimitives.h> header file. */ +#undef HAVE_SDL_SDL_GFXPRIMITIVES_H + +/* Define to 1 if you have the <SDL/SDL.h> header file. */ +#undef HAVE_SDL_SDL_H + +/* Define to 1 if you have the <SDL/SDL_ttf.h> header file. */ +#undef HAVE_SDL_SDL_TTF_H + +/* Define to 1 if you have the `select' function. */ +#undef HAVE_SELECT + +/* Define to 1 if you have the `sqrt' function. */ +#undef HAVE_SQRT + +/* Define to 1 if stdbool.h conforms to C99. */ +#undef HAVE_STDBOOL_H + +/* Define to 1 if you have the <stdint.h> header file. */ +#undef HAVE_STDINT_H + +/* Define to 1 if you have the <stdlib.h> header file. */ +#undef HAVE_STDLIB_H + +/* Define to 1 if you have the <strings.h> header file. */ +#undef HAVE_STRINGS_H + +/* Define to 1 if you have the <string.h> header file. */ +#undef HAVE_STRING_H + +/* Define to 1 if you have the <sys/select.h> header file. */ +#undef HAVE_SYS_SELECT_H + +/* Define to 1 if you have the <sys/socket.h> header file. */ +#undef HAVE_SYS_SOCKET_H + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#undef HAVE_SYS_STAT_H + +/* Define to 1 if you have the <sys/types.h> header file. */ +#undef HAVE_SYS_TYPES_H + +/* Define to 1 if you have the <unistd.h> header file. */ +#undef HAVE_UNISTD_H + +/* Define to 1 if the system has the type `_Bool'. */ +#undef HAVE__BOOL + +/* Name of package */ +#undef PACKAGE + +/* Define to the address where bug reports for this package should be sent. */ +#undef PACKAGE_BUGREPORT + +/* Define to the full name of this package. */ +#undef PACKAGE_NAME + +/* Define to the full name and version of this package. */ +#undef PACKAGE_STRING + +/* Define to the one symbol short name of this package. */ +#undef PACKAGE_TARNAME + +/* Define to the version of this package. */ +#undef PACKAGE_VERSION + +/* Define to the type of arg 1 for `select'. */ +#undef SELECT_TYPE_ARG1 + +/* Define to the type of args 2, 3 and 4 for `select'. */ +#undef SELECT_TYPE_ARG234 + +/* Define to the type of arg 5 for `select'. */ +#undef SELECT_TYPE_ARG5 + +/* Define to 1 if you have the ANSI C header files. */ +#undef STDC_HEADERS + +/* Version number of package */ +#undef VERSION + +/* Define to empty if `const' does not conform to ANSI C. */ +#undef const Added: branches/autoconf-2007-03-26-thebohemian/configure.ac =================================================================== --- branches/autoconf-2007-03-26-thebohemian/configure.ac (rev 0) +++ branches/autoconf-2007-03-26-thebohemian/configure.ac 2007-04-01 18:42:18 UTC (rev 14) @@ -0,0 +1,42 @@ +# -*- Autoconf -*- +# Process this file with autoconf to produce a configure script. + +AC_PREREQ(2.61) +AC_INIT([qonk], [0.0.3], [qon...@li...]) +AC_CANONICAL_TARGET +AM_INIT_AUTOMAKE + +AC_CONFIG_SRCDIR([src/animations.h]) +AC_CONFIG_HEADER([config.h]) + +# Checks for programs. +AC_PROG_CXX +AC_PROG_CC + +AC_LANG_C + +AM_PATH_SDL([1.2.0], [:], + AC_MSG_ERROR([No proper SDL found. Please install at least version 1.2.0!])) + + +# Checks for libraries. +AC_CHECK_LIB([SDL], [SDL_Init]) +AC_CHECK_LIB([SDL_ttf], [TTF_Init]) +AC_CHECK_LIB([SDL_gfx], [pixelColor]) + +# Checks for header files. +AC_HEADER_STDC +AC_CHECK_HEADERS([stdlib.h SDL/SDL.h SDL/SDL_gfxPrimitives.h SDL/SDL_ttf.h]) + +# Checks for typedefs, structures, and compiler characteristics. +AC_HEADER_STDBOOL +AC_C_CONST + +# Checks for library functions. +AC_FUNC_SELECT_ARGTYPES +AC_CHECK_FUNCS([atexit mkdir select sqrt]) + +AC_CONFIG_FILES([Makefile + data/Makefile + src/Makefile]) +AC_OUTPUT Added: branches/autoconf-2007-03-26-thebohemian/data/Makefile.am =================================================================== --- branches/autoconf-2007-03-26-thebohemian/data/Makefile.am (rev 0) +++ branches/autoconf-2007-03-26-thebohemian/data/Makefile.am 2007-04-01 18:42:18 UTC (rev 14) @@ -0,0 +1,5 @@ +pkgdatadir = $(datadir)/games/@PACKAGE@/data/ + +pkgdata_DATA = font.ttf + +EXTRA_DIST = $(pkgdata_DATA) Added: branches/autoconf-2007-03-26-thebohemian/src/Makefile.am =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/Makefile.am (rev 0) +++ branches/autoconf-2007-03-26-thebohemian/src/Makefile.am 2007-04-01 18:42:18 UTC (rev 14) @@ -0,0 +1,36 @@ +AM_CPPFLAGS = -DPKG_DATA_DIR="\"$(pkgdatadir)\"" + +bin_PROGRAMS = qonk + +qonk_SOURCES = " \ + actions.cpp \ + actions.h \ + animations.cpp \ + animations.h \ + coordinate.cpp \ + coordinate.h \ + extensions.cpp \ + extensions.h \ + fonts.cpp \ + fonts.h \ + main.cpp \ + messages.cpp \ + messages.h \ + planets.cpp \ + planets.h \ + players.cpp \ + players.h \ + readconf.cpp \ + readconf.h \ + selection.cpp \ + selection.h \ + settings.cpp \ + settings.h \ + ships.cpp \ + ships.h \ + stars.cpp \ + stars.h \ + timer.cpp \ + timer.h \ + universe.cpp \ + universe.h " Deleted: branches/autoconf-2007-03-26-thebohemian/src/ReadConf.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/ReadConf.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/ReadConf.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,91 +0,0 @@ -#include "ReadConf.h" - -Config::Config( const std::string& configFileName ){ - std::ifstream file( configFileName.c_str() ); - while (!file.eof()){ - std::string line; - getline( file, line ); - std::string::size_type loc = line.find( "=", 0 ); - if( line[0] != '#' ) - if( loc != std::string::npos ) { - std::string parameter = stripWhiteSpace( line.substr( 0, loc ) ); - std::string value = stripWhiteSpace( line.substr( loc + 1 ) ); - data[ parameter ] = value; - } - } - file.close(); - std::cout << "config file read" << std::endl; -} - -std::string -Config::getValue( const std::string& parameter ) const { - std::map< std::string, std::string >::const_iterator i = data.find( parameter ); - if( i != data.end() ) - return i->second; - else - return ""; -} - -bool -Config::getValueBOOL( const std::string& parameter ) const { - std::string s = getValue(parameter); - return str2bool(s); -} - -int -Config::getValueINT( const std::string& parameter ) const { - std::string s = getValue(parameter); - return str2int(s); -} - -void -Config::print() const { - for( std::map< std::string, std::string >::const_iterator i = data.begin(); i != data.end(); i++ ) - std::cout << "'" << i->first << "' => '" << i->second << "'" << std::endl; -} - -bool -fileExists( const std::string& fileName ) { - std::ifstream infile( fileName.c_str() ); - bool result = infile.good(); - infile.close(); - return result; -} - -void -createFile( const std::string& fileName, std::vector< std::string > content ){ - if( !fileExists( fileName ) ){ - std::ofstream outfile( fileName.c_str() ); - for( std::vector< std::string >::const_iterator iter = content.begin(); iter != content.end(); iter++ ) { - outfile.write( (*iter).data(), (*iter).size() ); - outfile.write( "\n", 1 ); - } - outfile.close(); - } -} - -bool -str2bool( const std::string& s ) { - if (s == std::string("true")) { - return true; - } else if (s == std::string("false")){ - return false; - } else { - std::cerr << "Invalid bool type"; - } -} - -int -str2int( const std::string& s ) { - std::istringstream i(s); - int x; - i>>x; - return x; -} - -std::string -stripWhiteSpace( const std::string& original ) { - int begin = original.find_first_not_of( " " ); - int end = original.find_last_not_of( " " ); - return original.substr( begin, end - begin + 1 ); -} Deleted: branches/autoconf-2007-03-26-thebohemian/src/ReadConf.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/ReadConf.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/ReadConf.h 2007-04-01 18:42:18 UTC (rev 14) @@ -1,36 +0,0 @@ -// ReadConf.h -// Class for reading named values from configuration files -// Troels Kofoed Jacobsen, Mar 19 2007, tkj...@gm... -// Licensed under GPLv2 -#ifndef READCONF_H -#define READCONF_H - -#include <string> -#include <map> -#include <vector> -#include <fstream> -#include <iostream> -#include <cctype> -#include <sstream> - -class Config { -public: - Config( const std::string& fileName ); - - std::string getValue( const std::string& parameter ) const; - bool getValueBOOL( const std::string& parameter ) const; - int getValueINT( const std::string& parameter ) const; - - void print() const; - -private: - std::map< std::string, std::string > data; -}; - -bool fileExists( const std::string& ); -void createFile( const std::string&, std::vector< std::string > ); -bool str2bool(const std::string& ); -int str2int(const std::string& ); -std::string stripWhiteSpace( const std::string& ); - -#endif Modified: branches/autoconf-2007-03-26-thebohemian/src/actions.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/actions.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/actions.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -2,7 +2,7 @@ #include "actions.h" -#include "config.h" +#include "settings.h" #include <iostream> // ##### ACTION ##### Modified: branches/autoconf-2007-03-26-thebohemian/src/animations.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/animations.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/animations.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,9 +1,11 @@ // Copyright 2005 by Anthony Liekens an...@li... +#include <SDL/SDL_gfxPrimitives.h> + #include "animations.h" -#include <SDL_gfxPrimitives.h> +#include "timer.h" +#include "planets.h" -#include <iostream> void AnimationQueue::render( SDL_Surface* screen ) { @@ -33,8 +35,8 @@ Uint32 currentTime = timer.getTime(); if( ( currentTime > startTime ) && ( currentTime < endTime ) ) { double percentage = (double)( currentTime - startTime ) / ( endTime - startTime ); - filledCircleRGBA( screen, planet->getLocation().getXMapped(), planet->getLocation().getYMapped(), (int)( size * sin( percentage * PI ) ), r, g, b, (int)( ( 255 - 255 * percentage ) * 0.05 ) ); + filledCircleRGBA( screen, planet->getLocation().getXMapped(), planet->getLocation().getYMapped(), (int)( size * sin( percentage * M_PI ) ), r, g, b, (int)( ( 255 - 255 * percentage ) * 0.05 ) ); if( circle ) - aacircleRGBA( screen, planet->getLocation().getXMapped(), planet->getLocation().getYMapped(), (int)( size * sin( percentage * PI ) ), r, g, b, 255 - (int)( 255 * percentage ) ); + aacircleRGBA( screen, planet->getLocation().getXMapped(), planet->getLocation().getYMapped(), (int)( size * sin( percentage * M_PI ) ), r, g, b, 255 - (int)( 255 * percentage ) ); } } Modified: branches/autoconf-2007-03-26-thebohemian/src/animations.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/animations.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/animations.h 2007-04-01 18:42:18 UTC (rev 14) @@ -3,13 +3,10 @@ #ifndef ANIMATIONS_H #define ANIMATIONS_H +#include <SDL/SDL.h> + #include "actions.h" -#include "coordinate.h" -#include "config.h" -#include "planets.h" -#include <math.h> - class Planet; class Animation : public Action { Deleted: branches/autoconf-2007-03-26-thebohemian/src/config.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/config.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/config.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,76 +0,0 @@ -// Copyright 2005 by Anthony Liekens an...@li... - -#include "config.h" -#include <iostream> - -class Config; - -Settings::Settings() { - //setResolution( 800, 600 ); - //setFullscreen( true ); - - //Create configuration file if it does not exist - if (!fileExists("qonk.conf")){ - vector<string> v; - v.push_back("# Qonk configuration file "); - v.push_back("# Format: entry = value (The spaces is optional)\n"); - v.push_back("# Window"); - v.push_back("fullscreen = true"); - v.push_back("width = 1024"); - v.push_back("height = 768\n"); - v.push_back("# Settings for first round"); - v.push_back("numberOfPlanets = 6"); - v.push_back("numberOfComputerPlayers = 1"); - createFile("qonk.conf",v); - } - Config config("qonk.conf"); - //Read settings form qonk.conf - bool fs = config.getValueBOOL("fullscreen"); - int h = config.getValueINT("height"); - int w = config.getValueINT("width"); - setResolution(w, h ); - setFullscreen( fs ); -} - -Settings::Settings(int w, int h, bool fs) { - setResolution( w, h ); - setFullscreen( fs ); -} - -void -Settings::setResolution( int width, int height ) { - screenWidth = width; - screenHeight = height; - gameWidth = height; - gameHeight = height; - gameOffsetX = ( width - height ) / 2; -} - -void -Settings::setFullscreen( bool b ) { - fullscreen = b; -} - -int Settings::getScreenWidth() { - return screenWidth; -} - -int Settings::getScreenHeight() { - return screenHeight; -} - -int Settings::getGameWidth() { - return gameWidth; -} - -int Settings::getGameHeight() { - return gameHeight; -} - -int Settings::getGameOffsetX() { - return gameOffsetX; -} - -bool Settings::getFullscreen() { - return fullscreen; -} Deleted: branches/autoconf-2007-03-26-thebohemian/src/config.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/config.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/config.h 2007-04-01 18:42:18 UTC (rev 14) @@ -1,35 +0,0 @@ -// Copyright 2005 by Anthony Liekens an...@li... - -#ifndef CONFIG_H -#define CONFIG_H - -#define PI 3.14159265 - -#include "timer.h" -#include "ReadConf.h" -#include <vector> -#include <string> - -static Timer timer; - -class Settings { -private: - int screenWidth, screenHeight, gameWidth, gameHeight, gameOffsetX; - bool fullscreen; -public: - Settings(); - Settings(int, int, bool); - void setResolution( int width, int height ); - void setFullscreen( bool b ); - int getScreenWidth(); - int getScreenHeight(); - int getGameWidth(); - int getGameHeight(); - int getGameOffsetX(); - bool getFullscreen(); -}; - -static Settings settings; -//static Config config("qonk.conf"); - -#endif Modified: branches/autoconf-2007-03-26-thebohemian/src/coordinate.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/coordinate.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/coordinate.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -2,7 +2,7 @@ #include "coordinate.h" -#include "config.h" +#include "settings.h" #include <math.h> Coordinate::Coordinate() { Modified: branches/autoconf-2007-03-26-thebohemian/src/extensions.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/extensions.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/extensions.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,7 +1,7 @@ // Copyright 2005 by Anthony Liekens an...@li... +#include <SDL/SDL_gfxPrimitives.h> #include "extensions.h" -#include <SDL_gfxPrimitives.h> void alphaBlend( SDL_Surface* surface, Uint8 alpha ) { Modified: branches/autoconf-2007-03-26-thebohemian/src/extensions.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/extensions.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/extensions.h 2007-04-01 18:42:18 UTC (rev 14) @@ -3,10 +3,7 @@ #ifndef EXTENSIONS_H #define EXTENSIONS_H -#include "config.h" #include <SDL/SDL.h> -#include <sstream> -using namespace std; void alphaBlend( SDL_Surface* surface, Uint8 alpha ); Modified: branches/autoconf-2007-03-26-thebohemian/src/main.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/main.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/main.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,4 +1,7 @@ // Copyright 2005 by Anthony Liekens an...@li... +#include <SDL/SDL_gfxPrimitives.h> +#include <SDL/SDL.h> +#include <SDL/SDL_ttf.h> #include "coordinate.h" #include "stars.h" @@ -7,12 +10,9 @@ #include "players.h" #include "universe.h" #include "fonts.h" -#include "ReadConf.h" -#include "config.h" +#include "settings.h" +#include "extensions.h" -#include <SDL_gfxPrimitives.h> -#include <SDL/SDL.h> -#include <SDL/SDL_ttf.h> #include <math.h> #include <iostream> @@ -66,14 +66,6 @@ int main(int argc, char** argv) { - -/* bool fullscreen = config.getValueBOOL("fullscreen"); - int h = config.getValueINT("height"); - int w = config.getValueINT("width"); - - settings.setResolution( w, h ); - settings.setFullscreen( fullscreen ); -*/ bool FirstRun = true; int numberOfPlanets; @@ -85,17 +77,21 @@ if (FirstRun){ FirstRun=false; - if( argc != 3 ) { - //cerr << "Usage: " << argv[ 0 ] << " numberOfPlanets numberOfComputerPlayers" << endl; - //cerr << "Setting to default 6 planets and 1 computer player" << endl; -// numberOfPlanets = config.getValueINT("numberOfPlanets"); -// numberOfComputerPlayers = config.getValueINT("numberOfComputerPlayers"); - numberOfPlanets = 6; - numberOfComputerPlayers = 1; - } else { - numberOfPlanets = atoi( argv[ 1 ] ); - numberOfComputerPlayers = atoi( argv[ 2 ] ); + switch (argc) { + case 3: + numberOfPlanets = atoi( argv[ 1 ] ); + numberOfComputerPlayers = atoi( argv[ 2 ] ); + break; + case 1: + numberOfPlanets = settings.getNumberOfPlanets(); + numberOfComputerPlayers = settings.getNumberOfComputerPlayers(); + break; + default: + cerr << "Usage: " << argv[ 0 ] << " numberOfPlanets numberOfComputerPlayers" << endl; + exit(1); + break; } + if( numberOfPlanets <= 1 ) { cerr << "Resetting to least of 2 planets" << endl; numberOfPlanets = 2; @@ -132,7 +128,7 @@ exit( 1 ); } atexit( TTF_Quit ); - font = new Font( "font.ttf", 18 ); + font = new Font( PKG_DATA_DIR "font.ttf", 18 ); srand( time( NULL) ); @@ -293,6 +289,9 @@ // SDL_Delay( 20 ); } + + cout << "Saving progress and settings." << endl; + settings.store(); delete font; delete universe; Modified: branches/autoconf-2007-03-26-thebohemian/src/messages.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/messages.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/messages.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,6 +1,11 @@ // Copyright 2005 by Anthony Liekens an...@li... #include "messages.h" +#include "timer.h" +#include "settings.h" +#include "coordinate.h" +#include "extensions.h" +#include "universe.h" Message::Message( string message, Uint32 displayTime, Uint8 r, Uint8 g, Uint8 b ) { @@ -79,7 +84,7 @@ } Messages::Messages() { - font = new Font( "font.ttf", 12 ); + font = new Font( PKG_DATA_DIR "font.ttf", 12 ); } Messages::~Messages() { Modified: branches/autoconf-2007-03-26-thebohemian/src/messages.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/messages.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/messages.h 2007-04-01 18:42:18 UTC (rev 14) @@ -3,15 +3,12 @@ #ifndef MESSAGES_H #define MESSAGES_H -#include "fonts.h" -#include "extensions.h" -#include "config.h" -#include "universe.h" -#include <SDL/SDL.h> #include <map> -#include <string> -using namespace std; +#include <SDL/SDL.h> + +#include "fonts.h" + class Universe; class Message { Modified: branches/autoconf-2007-03-26-thebohemian/src/planets.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/planets.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/planets.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,12 +1,14 @@ // Copyright 2005 by Anthony Liekens an...@li... +#include <SDL/SDL_gfxPrimitives.h> + #include "planets.h" +#include "timer.h" +#include "ships.h" +#include "extensions.h" +#include "settings.h" -#include <SDL_gfxPrimitives.h> -#include <iostream> -#include <math.h> - // ##### PLANET ##### Planet::Planet() { @@ -197,8 +199,8 @@ int counter = 0; double offset = 500 * rotationDistance + (double)timer.getTime() / 10000; for( list< Ship* >::iterator i = residentShips.begin(); i != residentShips.end(); i++ ) { - double shipX = location.getX() + 0.02 * cos( offset + counter * 2 * PI / residentShips.size() ); - double shipY = location.getY() + 0.02 * sin( offset + counter * 2 * PI / residentShips.size() ); + double shipX = location.getX() + 0.02 * cos( offset + counter * 2 * M_PI / residentShips.size() ); + double shipY = location.getY() + 0.02 * sin( offset + counter * 2 * M_PI / residentShips.size() ); (*i)->setLocation( shipX, shipY ); counter++; } Modified: branches/autoconf-2007-03-26-thebohemian/src/planets.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/planets.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/planets.h 2007-04-01 18:42:18 UTC (rev 14) @@ -3,22 +3,18 @@ #ifndef PLANETS_H #define PLANETS_H +#include <list> + +#include <SDL/SDL.h> + #include "coordinate.h" -#include "ships.h" -#include "extensions.h" -#include "selection.h" +#include "players.h" #include "actions.h" -#include "config.h" -#include <SDL/SDL.h> -#include <sstream> -#include <list> +#include "universe.h" + using namespace std; class Ship; -class Ships; -class Player; -class Players; -class Universe; class Planet { private: Modified: branches/autoconf-2007-03-26-thebohemian/src/players.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/players.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/players.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,11 +1,16 @@ // Copyright 2005 by Anthony Liekens an...@li... -#include "players.h" +#include <map> -#include <SDL_gfxPrimitives.h> +#include <SDL/SDL_gfxPrimitives.h> -#include <iostream> -#include <map> +#include "players.h" +#include "planets.h" +#include "universe.h" +#include "ships.h" +#include "extensions.h" +#include "timer.h" +#include "settings.h" // ##### PLAYER ##### Modified: branches/autoconf-2007-03-26-thebohemian/src/players.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/players.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/players.h 2007-04-01 18:42:18 UTC (rev 14) @@ -3,20 +3,17 @@ #ifndef PLAYERS_H #define PLAYERS_H -#include "ships.h" -#include "planets.h" -#include "universe.h" -#include "actions.h" -#include "messages.h" +#include <vector> #include <list> using namespace std; -class Ship; +#include "actions.h" +#include "messages.h" +#include "selection.h" + class Ships; -class Planet; -class Planets; -class Selection; class Universe; +class Planet; class Player { public: Copied: branches/autoconf-2007-03-26-thebohemian/src/readconf.cpp (from rev 13, branches/autoconf-2007-03-26-thebohemian/src/ReadConf.cpp) =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/readconf.cpp (rev 0) +++ branches/autoconf-2007-03-26-thebohemian/src/readconf.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -0,0 +1,138 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <sys/stat.h> + +#include "readconf.h" + +Config *Config::instance = 0; + +Config& +Config::getInstance() { + if (!instance) { + instance = new Config("qonk.settings"); + } + + return *instance; +} + +Config::Config( const std::string& configFileName ){ + std::string pathname = ""; +#ifdef WINDOWS + // Do nothing. Falls back to application directory. +#elif MAC_OSX + // Get from some mysterious directory ... +#else + // GNU/LINUX/BSD/POSIX/... + if(getenv("HOME")!=NULL) { + pathname = getenv("HOME"); + pathname += "/.qonk/"; + mkdir(pathname.c_str(), 0755); + } +#endif + + fileName = pathname + configFileName; +} + +bool +Config::load() { + if( !fileExists(fileName)) + return false; + + std::ifstream file( fileName.c_str() ); + while (!file.eof()){ + std::string line; + getline( file, line ); + std::string::size_type loc = line.find( "=", 0 ); + if( line[0] != '#' ) + if( loc != std::string::npos ) { + std::string parameter = stripWhiteSpace( line.substr( 0, loc ) ); + std::string value = stripWhiteSpace( line.substr( loc + 1 ) ); + data[ parameter ] = value; + } + } + file.close(); + + return true; +} + +bool +Config::save() { + std::ofstream outfile( fileName.c_str() ); + for( std::map< std::string, std::string >::const_iterator i = data.begin(); i != data.end(); i++ ) { + std::string temp = i->first + "=" + i->second; + outfile.write( temp.data(), temp.size() ); + outfile.write( "\n", 1 ); + } + outfile.close(); + + return true; +} + +std::string +Config::getValue( const std::string& parameter, std::string defaultValue ) const { + std::map< std::string, std::string >::const_iterator i = data.find( parameter ); + if( i != data.end() ) + return i->second; + else + return defaultValue; +} + +bool +Config::getValueBOOL( const std::string& parameter, bool defaultValue ) const { + std::map< std::string, std::string >::const_iterator i = data.find( parameter ); + if( i != data.end() ) + return str2bool(i->second); + else + return defaultValue; +} + +int +Config::getValueINT( const std::string& parameter, int defaultValue ) const { + std::map< std::string, std::string >::const_iterator i = data.find( parameter ); + if( i != data.end() ) + return str2int(i->second); + else + return defaultValue; +} + +void +Config::print() const { + for( std::map< std::string, std::string >::const_iterator i = data.begin(); i != data.end(); i++ ) + std::cout << "'" << i->first << "' => '" << i->second << "'" << std::endl; +} + +bool +fileExists( const std::string& fileName ) { + std::ifstream infile( fileName.c_str() ); + bool result = infile.good(); + infile.close(); + return result; +} + +bool +str2bool( const std::string& s ) { + if (s == std::string("true")) { + return true; + } else if (s == std::string("false")){ + return false; + } else { + std::cerr << "Invalid bool type"; + } +} + +int +str2int( const std::string& s ) { + std::istringstream i(s); + int x; + i>>x; + return x; +} + +std::string +stripWhiteSpace( const std::string& original ) { + int begin = original.find_first_not_of( " " ); + int end = original.find_last_not_of( " " ); + return original.substr( begin, end - begin + 1 ); +} Copied: branches/autoconf-2007-03-26-thebohemian/src/readconf.h (from rev 13, branches/autoconf-2007-03-26-thebohemian/src/ReadConf.h) =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/readconf.h (rev 0) +++ branches/autoconf-2007-03-26-thebohemian/src/readconf.h 2007-04-01 18:42:18 UTC (rev 14) @@ -0,0 +1,44 @@ +// ReadConf.h +// Class for reading named values from configuration files +// Troels Kofoed Jacobsen, Mar 19 2007, tkj...@gm... +// Licensed under GPLv2 +#ifndef READCONF_H +#define READCONF_H + +#include <string> +#include <map> +#include <vector> +#include <fstream> +#include <iostream> +#include <cctype> +#include <sstream> + +class Config { +public: + static Config& getInstance(); + + bool load(); + bool save(); + + std::string getValue( const std::string& parameter, std::string defaultValue = "") const; + bool getValueBOOL( const std::string& parameter, bool defaultValue = false ) const; + int getValueINT( const std::string& parameter, int defaultValue = 0 ) const; + + void print() const; + +private: + Config( const std::string& fileName ); + + std::map< std::string, std::string > data; + + std::string fileName; + + static Config *instance; +}; + +bool fileExists( const std::string& ); +bool str2bool(const std::string& ); +int str2int(const std::string& ); +std::string stripWhiteSpace( const std::string& ); + +#endif Modified: branches/autoconf-2007-03-26-thebohemian/src/selection.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/selection.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/selection.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,8 +1,9 @@ // Copyright 2005 by Anthony Liekens an...@li... +#include <iostream> +#include <SDL/SDL_gfxPrimitives.h> + #include "selection.h" -#include <SDL_gfxPrimitives.h> -#include <iostream> Selection::Selection() { state = NOT_SELECTING; Modified: branches/autoconf-2007-03-26-thebohemian/src/selection.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/selection.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/selection.h 2007-04-01 18:42:18 UTC (rev 14) @@ -3,7 +3,6 @@ #ifndef SELECTION_H #define SELECTION_H -#include "config.h" #include "coordinate.h" #include <SDL/SDL.h> Copied: branches/autoconf-2007-03-26-thebohemian/src/settings.cpp (from rev 13, branches/autoconf-2007-03-26-thebohemian/src/config.cpp) =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/settings.cpp (rev 0) +++ branches/autoconf-2007-03-26-thebohemian/src/settings.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -0,0 +1,38 @@ +// Copyright 2005 by Anthony Liekens an...@li... + +#include "readconf.h" +#include "settings.h" + +#include <iostream> +#include <fstream> + +Settings::Settings() : config(Config::getInstance()) { + if (config.load()) + std::cout << "configuration successfully loaded" << std::endl; + else + std::cout << "configuration was not available - using defaults" << std::endl; + + setFullscreen(config.getValueBOOL("fullscreen", false)); + setResolution(config.getValueINT("height", 768), + config.getValueINT("width", 1024)); + setNumberOfPlanets( config.getValueINT("numberOfPlanets", 6)); + setNumberOfComputerPlayers( config.getValueINT("numberOfComputerPlayers", 1)); +} + +void +Settings::setResolution( int width, int height ) { + screenWidth = width; + screenHeight = height; + gameWidth = height; + gameHeight = height; + gameOffsetX = ( width - height ) / 2; +} + +void +Settings::store() +{ + if (config.save()) + std::cout << "Setting saved successfully." << std::endl; + else + std::cout << "Setting could not be saved." << std::endl; +} Copied: branches/autoconf-2007-03-26-thebohemian/src/settings.h (from rev 13, branches/autoconf-2007-03-26-thebohemian/src/config.h) =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/settings.h (rev 0) +++ branches/autoconf-2007-03-26-thebohemian/src/settings.h 2007-04-01 18:42:18 UTC (rev 14) @@ -0,0 +1,45 @@ +// Copyright 2005 by Anthony Liekens an...@li... + +#ifndef SETTINGS_H +#define SETTINGS_H + +#include "timer.h" +#include "readconf.h" + +#include <vector> +#include <string> + +class Settings { +private: + int screenWidth, screenHeight, gameWidth, gameHeight, gameOffsetX; + bool fullscreen; + + int numberOfPlanets; + int numberOfComputerPlayers; + + Config& config; + +public: + Settings(); + void setFullscreen( bool b ) { fullscreen = b; } + bool getFullscreen() { return fullscreen; } + + void setResolution(int, int); + int getScreenWidth() { return screenWidth; } + int getScreenHeight() { return screenHeight; } + int getGameWidth() { return gameWidth; } + int getGameHeight() { return gameHeight; } + int getGameOffsetX() { return gameOffsetX; } + + int getNumberOfPlanets() { return numberOfPlanets; } + int setNumberOfPlanets(int p) { numberOfPlanets = p; } + + int getNumberOfComputerPlayers() { return numberOfComputerPlayers; } + int setNumberOfComputerPlayers(int p) { numberOfComputerPlayers = p; } + + void store(); +}; + +static Settings settings; + +#endif Modified: branches/autoconf-2007-03-26-thebohemian/src/ships.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/ships.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/ships.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,9 +1,11 @@ // Copyright 2005 by Anthony Liekens an...@li... +#include <iostream> +#include <SDL/SDL_gfxPrimitives.h> + #include "ships.h" #include "extensions.h" -#include <SDL_gfxPrimitives.h> -#include <iostream> +#include "timer.h" /* ##### SHIP ##### */ @@ -97,8 +99,8 @@ } else { double direction = getDirection(); Coordinate head = Coordinate( locx + 5.0 * cos( direction ), locy + 5.0 * sin( direction ) ); - Coordinate leftTip = Coordinate( locx + 2.0 * cos( direction + PI / 3.0 ), locy + 2.0 * sin( direction + PI / 3.0 ) ); - Coordinate rightTip = Coordinate( locx + 2.0 * cos( direction - PI / 3.0 ), locy + 2.0 * sin( direction - PI / 3.0 ) ); + Coordinate leftTip = Coordinate( locx + 2.0 * cos( direction + M_PI / 3.0 ), locy + 2.0 * sin( direction + M_PI / 3.0 ) ); + Coordinate rightTip = Coordinate( locx + 2.0 * cos( direction - M_PI / 3.0 ), locy + 2.0 * sin( direction - M_PI / 3.0 ) ); aalineRGBA( screen, leftTip.getX(), leftTip.getY(), head.getX(), head.getY(), red, green, blue, 255 ); aalineRGBA( screen, rightTip.getX(), rightTip.getY(), head.getX(), head.getY(), red, green, blue, 255 ); aalineRGBA( screen, rightTip.getX(), rightTip.getY(), leftTip.getX(), leftTip.getY(), red, green, blue, 255 ); Modified: branches/autoconf-2007-03-26-thebohemian/src/ships.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/ships.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/ships.h 2007-04-01 18:42:18 UTC (rev 14) @@ -3,15 +3,19 @@ #ifndef SHIPS_H #define SHIPS_H +#include <list> +using namespace std; + +#include <SDL/SDL.h> + +#include "coordinate.h" #include "players.h" #include "planets.h" #include "actions.h" #include "selection.h" -#include <SDL/SDL.h> -#include <list> -using namespace std; class Planet; +class Player; class Ship { public: @@ -28,8 +32,8 @@ // for movement purposes only - Coordinate fromLocation, toLocation; - Uint32 fromTime, toTime; + Coordinate fromLocation, toLocation; + Uint32 fromTime, toTime; public: Ship( Player*, Planet* ); Modified: branches/autoconf-2007-03-26-thebohemian/src/stars.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/stars.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/stars.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,7 +1,8 @@ // Copyright 2005 by Anthony Liekens an...@li... +#include <SDL/SDL_gfxPrimitives.h> + #include "stars.h" -#include "config.h" // ##### STAR METHODS ##### Modified: branches/autoconf-2007-03-26-thebohemian/src/stars.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/stars.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/stars.h 2007-04-01 18:42:18 UTC (rev 14) @@ -3,12 +3,12 @@ #ifndef STARS_H #define STARS_H -#include <SDL_gfxPrimitives.h> -#include "coordinate.h" -#include <SDL/SDL.h> #include <vector> -#include <stdlib.h> +#include <SDL/SDL.h> + +#include "coordinate.h" + class Star { private: Coordinate c; Modified: branches/autoconf-2007-03-26-thebohemian/src/timer.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/timer.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/timer.h 2007-04-01 18:42:18 UTC (rev 14) @@ -26,4 +26,6 @@ }; +static Timer timer; + #endif Modified: branches/autoconf-2007-03-26-thebohemian/src/universe.cpp =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/universe.cpp 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/universe.cpp 2007-04-01 18:42:18 UTC (rev 14) @@ -1,8 +1,15 @@ // Copyright 2005 by Anthony Liekens an...@li... +#include <iostream> +#include <SDL/SDL_gfxPrimitives.h> + #include "universe.h" -#include <SDL_gfxPrimitives.h> -#include <iostream> +#include "planets.h" +#include "stars.h" +#include "messages.h" +#include "actions.h" +#include "timer.h" +#include "settings.h" Universe::Universe() { stars = new Stars( 100 ); Modified: branches/autoconf-2007-03-26-thebohemian/src/universe.h =================================================================== --- branches/autoconf-2007-03-26-thebohemian/src/universe.h 2007-04-01 15:00:42 UTC (rev 13) +++ branches/autoconf-2007-03-26-thebohemian/src/universe.h 2007-04-01 18:42:18 UTC (rev 14) @@ -3,8 +3,6 @@ #ifndef UNIVERSE_H #define UNIVERSE_H -#include "stars.h" -#include "planets.h" #include "actions.h" #include "animations.h" #include "messages.h" @@ -12,8 +10,6 @@ class Stars; class Planet; class Planets; -class AnimationQueue; -class Messages; class Universe { public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |