# HG changeset patch # User Tero Marttila # Date 1232581985 -7200 # Node ID c503e0c6a7406f9e8deaaca24b469fc53767dc84 # Parent 38cba347a3a959c59ae8848d458f0f497b111d7b support for building without Network/Graphics, although the disable-graphics case is kind of hackish still diff -r 38cba347a3a9 -r c503e0c6a740 src/Application.cc --- a/src/Application.cc Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Application.cc Thu Jan 22 01:53:05 2009 +0200 @@ -1,7 +1,15 @@ #include "Application.hh" +#include "Config.hh" -#include +#if GRAPHICS_ENABLED + // for dump_display_modes + #include "Graphics/Display.hh" + + // for CL_SetupGL + #include +#endif + #include #include #include @@ -37,42 +45,62 @@ * Set the arg_* members */ bool Main::parse_args (int argc, char **argv) { - // set up the options - args.add_option(ARG_HELP, "help", "", - "display argument help and exit"); - - args.add_option(ARG_PORT, "port", "PORT", - "set network port used"); - - args.add_option(ARG_SERVER, "server", "", - "act as a network server"); - args.add_option(ARG_CLIENT, "client", "SERVERHOST", - "act as a network client"); - - args.add_option(ARG_GRAPHICS, "graphics", "", - "run graphics/local input. Implied with --connect"); + // set up the options + args.add_usage("[OPTIONS]"); + args.set_help_indent(30); + + if (NETWORK_ENABLED) { + args.add_group("Network"); - args.add_option(ARG_FULLSCREEN, "fullscreen", "", - "run graphics in fullscreen mode"); + args.add_option(ARG_PORT, "port", "PORT", + "set network port used"); - args.add_option(ARG_RESOLUTION, "resolution", "WIDTHxHEIGHT", - "set graphics resolution"); - - args.add_option(ARG_LIST_MODES, "list-modes", "", - "output a list of available display modes and exit"); + args.add_option(ARG_SERVER, "server", "", + "act as a network server"); + + // require graphics for network-client + if (GRAPHICS_ENABLED) + args.add_option(ARG_CLIENT, "client", "SERVERHOST", + "act as a network client"); + } + if (GRAPHICS_ENABLED) { + args.add_group("Graphics"); + + args.add_option(ARG_GRAPHICS, "graphics", "", + "run graphics/local input. Implied with --client"); + + args.add_option(ARG_FULLSCREEN, "fullscreen", "", + "run graphics in fullscreen mode"); + + args.add_option(ARG_RESOLUTION, "resolution", "WIDTHxHEIGHT", + "set graphics resolution"); + + args.add_option(ARG_LIST_MODES, "list-modes", "", + "output a list of available display modes and exit"); + } + + args.add_group("Game"); args.add_option(ARG_TERRAIN_SEED, "terrain-seed", "SEED", "set seed for terrain random generator"); args.add_option(ARG_TERRAIN_SIZE, "terrain-size", "WIDTHxHEIGHT", "set terrain size for random generator"); + + args.add_group("General"); + args.add_option(ARG_HELP, "help", "", + "display argument help and exit"); + args.add_option(ARG_VERSION, "version", "", - "output application version and exit"); + "output application version plus configuration and exit"); +#if GRAPHICS_ENABLED // extra state bool resolution_default = true; + +#endif try { // parse args @@ -88,6 +116,7 @@ args.print_help(); return false; +#if NETWORK_ENABLED case ARG_PORT: net_port = args.get_argument(); break; @@ -100,6 +129,9 @@ net_connect = args.get_argument(); break; +#endif + +#if GRAPHICS_ENABLED case ARG_GRAPHICS: graphics_enabled = true; break; @@ -125,6 +157,7 @@ case ARG_LIST_MODES: dump_display_modes(); return false; +#endif case ARG_VERSION: dump_version(); @@ -147,14 +180,18 @@ } } +#if NETWORK_ENABLED // check for invalid combinations of arugments if (net_server and !net_connect.empty()) throw ArgumentError("cannot be both server and client"); +#endif +#if GRAPHICS_ENABLED // enable graphics by default unless server if (!net_server) graphics_enabled = true; - +#endif + // continue return true; } @@ -180,18 +217,39 @@ return PixelDimensions(w, h); } - + +#if GRAPHICS_ENABLED void Main::dump_display_modes (void) { + // get the list of display modes from graphics const std::vector &modes = graphics::Display::getDisplayModes(); + PixelCoordinate last_resolution; std::cout << "Available display modes:" << std::endl; - - for (std::vector::const_iterator it = modes.begin(); it != modes.end(); it++) - std::cout << "\t" << it->get_resolution().width << "x" << it->get_resolution().height << std::endl; + + // iterate over the list of available display modes + for (std::vector::const_iterator it = modes.begin(); it != modes.end(); it++) { + PixelCoordinate resolution(it->get_resolution().width, it->get_resolution().height); + + // filter out those that haven't changed + if (resolution != last_resolution) + std::cout << "\t" << it->get_resolution().width << "x" << it->get_resolution().height << std::endl; + + // update for next item + last_resolution = resolution; + } } +#endif void Main::dump_version (void) { - std::cout << PROJECT_LONG_NAME << " version " << PROJECT_VERSION << " built " << PROJECT_BUILD_TIMESTAMP << std::endl; + std::cout + << PROJECT_LONG_NAME << " version " << PROJECT_VERSION << " built [" << PROJECT_BUILD_TIMESTAMP << "]" << std::endl; + + // then some additional stuff about what's enabled + std::cout + << std::endl + << "Enabled components:" << std::endl + << "\tGraphics:\t" << (GRAPHICS_ENABLED ? "Yes" : "No") << std::endl + << "\tNetwork:\t" << (NETWORK_ENABLED ? "Yes" : "No") << std::endl; } /** @@ -200,8 +258,12 @@ int Main::main (int argc, char **argv) { // initialize the ClanLib components that we use CL_SetupCore setup_core; + +#if GRAPHICS_ENABLED + // XXX: move to Graphics/Graphics.hh? CL_SetupDisplay setup_disp; CL_SetupGL setup_gl; +#endif try { // parse arugments, exit if false @@ -226,8 +288,12 @@ } else if (!net_connect.empty()) { engine.setupNetworkClient(net_connect, net_port); + } else if (graphics_enabled) { + engine.setupSinglePlayer(); + } else { - engine.setupSinglePlayer(); + throw ArgumentError("Nothing to do"); + } // run the main loop @@ -237,11 +303,14 @@ return 0; } catch (ArgumentError &e) { - std::cerr << e.what() << std::endl; + std::cerr + << "Error: " << e.what() << std::endl + << std::endl; + args.print_help(); - // XXX: handle --help return 1; + } catch (CL_Error &e) { std::cerr << "main: CL_Error:" << e.message << std::endl; diff -r 38cba347a3a9 -r c503e0c6a740 src/Application.hh --- a/src/Application.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Application.hh Thu Jan 22 01:53:05 2009 +0200 @@ -28,7 +28,7 @@ /** * --fullscreen and --resolution */ - graphics::DisplayConfig display; + DisplayConfig display; /** * --terrain-seed and --terrain-size @@ -74,7 +74,7 @@ void dump_display_modes (void); /** - * Print out our project version + * Print out our project version and some configuration info */ void dump_version (void); diff -r 38cba347a3a9 -r c503e0c6a740 src/CMakeLists.txt --- a/src/CMakeLists.txt Thu Jan 22 00:28:26 2009 +0200 +++ b/src/CMakeLists.txt Thu Jan 22 01:53:05 2009 +0200 @@ -1,22 +1,37 @@ -FILE(GLOB SOURCE_FILES "*.cc" "Network/*.cc") -FILE(GLOB HEADER_FILES "*.hh" "Network/*.hh") +FILE(GLOB SOURCE_FILES "*.cc") +FILE(GLOB HEADER_FILES "*.hh") set_source_files_properties("version.c" PROPERTIES GENERATED true) +# Component selection +set (GRAPHICS_ENABLED true) +set (NETWORK_ENABLED true) + +mark_as_advanced (CLEAR GRAPHICS_ENABLED NETWORK_ENABLED) + # Generate config.h configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.in" "${CMAKE_CURRENT_BINARY_DIR}/config.h" @ONLY) include_directories("${CMAKE_CURRENT_BINARY_DIR}") # main module set (CORE_CLANLIB_COMPONENTS Core App Signals) -set (CORE_SOURCES ${SOURCE_FILES} ${HEADER_FILES}) +set (CORE_SOURCES ${SOURCE_FILES} ${HEADER_FILES} "version.c") # Graphics module -add_subdirectory(Graphics) +if (GRAPHICS_ENABLED) + add_subdirectory (Graphics) + +endif (GRAPHICS_ENABLED) + +# Network module +if (NETWORK_ENABLED) + add_subdirectory (Network) + +endif (NETWORK_ENABLED) # Libraries set (CLANLIB_VERSION 0.8) -set (CLANLIB_COMPONENTS ${CORE_CLANLIB_COMPONENTS} ${GRAPHICS_CLANLIB_COMPONENTS}) +set (CLANLIB_COMPONENTS ${CORE_CLANLIB_COMPONENTS} ${GRAPHICS_CLANLIB_COMPONENTS} ${NETWORK_CLANLIB_COMPONENTS}) # ClanLib 0.8 message (STATUS "Finding ClanLib version=${CLANLIB_VERSION}, components=${CLANLIB_COMPONENTS}" ) @@ -26,7 +41,7 @@ # build list of libs/source files set(LIBS ${LIBS} ${ClanLib_LIBRARIES}) -set(SOURCES ${CORE_SOURCES} ${GRAPHICS_SOURCES} "version.c") +set(SOURCES ${CORE_SOURCES} ${GRAPHICS_SOURCES} ${NETWORK_SOURCES}) # Assumes the project generates only one executable. If you need more, you'll need to alter # the script and replace ${PROJECT_SHORT_NAME} by executable name. diff -r 38cba347a3a9 -r c503e0c6a740 src/Config.hh --- a/src/Config.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Config.hh Thu Jan 22 01:53:05 2009 +0200 @@ -134,8 +134,33 @@ */ const PixelDimension GRAPHICS_INFO_TEXT_LINE_OFFSET = 5; -// Filesystem paths +/** + * @name Network + * @{ + */ + +/** Default port used for network games */ +const std::string NETWORK_PORT_STR = "9338"; + +/** Maximum packet size used for normal NetworkPackets... aligned to a sensible UDP mtu */ +const size_t NETWORK_PACKET_SIZE = 1280; + +/** Backlog used for TCP server... doesn't really matter all that much */ +const int NETWORK_LISTEN_BACKLOG = 5; + +/** Magic string used to identify game between client/server */ +const char NETWORK_MAGIC_STR[8+1] = "KISNGLIS"; +const uint64_t NETWORK_MAGIC_ID = * ((const uint64_t *) NETWORK_MAGIC_STR); + +// @} + +/** + * @name Filesystem paths + * @{ + */ const std::string PLAYER_SKIN_PATH = (PROJECT_DATA_DIR "/skin.png"); const std::string RESOURCE_XML_PATH = (PROJECT_DATA_DIR "/resources.xml"); +// @} + #endif diff -r 38cba347a3a9 -r c503e0c6a740 src/Configuration.hh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Configuration.hh Thu Jan 22 01:53:05 2009 +0200 @@ -0,0 +1,44 @@ +#ifndef CONFIGURATION_HH +#define CONFIGURATION_HH + +/** + * @file + * + * Various classes/modules have their own configuration structures, which are defined here + * + * XXX: rename to "Settings" to distinguish from Config/config? + */ + +#include "Types.hh" +#include "Config.hh" + +/** + * Terrain configuration + */ +struct TerrainConfig { + /** Size of the terrain field*/ + PixelDimensions dimensions; + + /** Set to nonzero to generate random map */ + int random_seed; + + /** Defaults */ + TerrainConfig (void) : dimensions(TERRAIN_WIDTH, TERRAIN_HEIGHT), random_seed(TERRAIN_RANDOM_SEED) { } +}; + +/** + * Graphics display configuration + */ +struct DisplayConfig { + /** Display resolution */ + PixelDimensions resolution; + + /** Fullscreen mode? */ + bool fullscreen; + + /** Defaults */ + DisplayConfig (void) : resolution(GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT), fullscreen(GRAPHICS_FULLSCREEN) { } +}; + + +#endif diff -r 38cba347a3a9 -r c503e0c6a740 src/Engine.cc --- a/src/Engine.cc Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Engine.cc Thu Jan 22 01:53:05 2009 +0200 @@ -1,10 +1,23 @@ #include "Engine.hh" #include "SinglePlayer.hh" -#include "Network/Reactor.hh" #include "Config.hh" +// XXX: how does this work if we don't have NETWORK_ENABLED? +#include "Network/Reactor.hh" + +// include the real component definitions +#if NETWORK_ENABLED + #include "Network/Client.hh" + #include "Network/Server.hh" +#endif + +#if GRAPHICS_ENABLED + #include "Graphics/Graphics.hh" +#endif + #include +#include Engine::Engine (const std::string resource_xml_path) : terrain(NULL), game_state(NULL), graphics(NULL), net_server(NULL), net_client_connect(NULL), @@ -22,13 +35,9 @@ // create the GameState game_state = new GameState(*terrain); + + // XXX: NetworkClient + GameView? - // put graphics into GameView mode - // XXX: this state is a mess, this is done in three places in weird ways - // this depends on graphics not yet being set in client mode, but not in singleplayer mode - if (graphics) - graphics->displayGameView(*game_state, game_state->getLocalPlayer()); - return *game_state; } @@ -37,12 +46,42 @@ setupGame(new Terrain(config)); } -void Engine::setupGraphics (const graphics::DisplayConfig &config) { +void Engine::setupGraphics (const DisplayConfig &config) { + +#if GRAPHICS_ENABLED + assert(!graphics); + // create the graphics graphics = new graphics::Graphics(*this, resources, config); + +#else + (void) config; + + throw Error("No Graphics support available"); + +#endif + +} + +void Engine::startGameView (LocalPlayer *player) { + +#if GRAPHICS_ENABLED + assert(graphics); + + graphics->displayGameView(*game_state, player); + +#else + (void) player; + + throw Error("No Graphics support available"); + +#endif + } void Engine::setupNetworkServer (const std::string &listen_port) { + +#if NETWORK_EANBLED NetworkEndpoint listen_addr(listen_port); assert(terrain && game_state); @@ -52,16 +91,33 @@ // put graphics into GameView mode if (graphics) - graphics->displayGameView(*game_state, NULL); - + startGameView(NULL); + +#else + (void) listen_port; + + throw Error("No Network support available"); + +#endif } void Engine::setupNetworkClient (const std::string &connect_host, const std::string &connect_port) { + +#if NETWORK_EANBLED // connect_to NetworkEndpoint connect_addr(connect_host, connect_port); // begin connecting, the client will callback us with setupGame once it's connected net_client_connect = new NetworkClientConnect(*this, connect_addr); + +#else + (void) connect_host; + (void) connect_port; + + throw Error("No Network support available"); + +#endif + } void Engine::setupSinglePlayer (void) { @@ -75,7 +131,7 @@ // put graphics into GameView mode if (graphics) - graphics->displayGameView(*game_state, lp); + startGameView(lp); } @@ -84,26 +140,21 @@ } void Engine::run (void) { - // our NetworkReactor - NetworkReactor *reactor = NetworkReactor::current; - - // timeout info - timeval timeout; - while (is_running) { - // this does.... magical things - CL_System::keep_alive(); + /* + * Run internal ClanLib stuff (also includes our timers) until our timeout has elapsed + */ + CL_System::keep_alive(ENGINE_TIMEOUT_MS); - // setup our timeout to ENGINE_TIMEOUT_MS - timeout.tv_sec = 0; - timeout.tv_usec = ENGINE_TIMEOUT_MS * 1000; - +#if NETWORK_ENABLED /* * Thursday came and went, I re-wrote clan-event. * - * We use the NetworkReactor for sleeping, as it handles it effeciently even if we're not using network. + * (actually, we only use it for zero-timeout polling now... not sure if this is better than using the above + * CL_System::keep_alive) */ - reactor->poll(&timeout); + NetworkReactor::current->poll(NULL); +#endif } } diff -r 38cba347a3a9 -r c503e0c6a740 src/Engine.hh --- a/src/Engine.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Engine.hh Thu Jan 22 01:53:05 2009 +0200 @@ -5,11 +5,15 @@ class Engine; #include "GameState.hh" -#include "Graphics/Graphics.hh" -#include "Network/Server.hh" -#include "Network/Client.hh" +#include "Configuration.hh" +#include "Logger.hh" -#include "Logger.hh" +// forward-declare component pointer types +// XXX: move to some kind of Components.hh file? +namespace graphics { class Graphics; } +class NetworkServer; +class NetworkClientConnect; +class NetworkClient; /** * This is the core class that glues all the other components together and runs the main loop @@ -51,17 +55,23 @@ void setupGame (const TerrainConfig &config); /** - * Enable graphics + * Enable graphics. + * + * Requires: GRAPHICS_ENABLED */ - void setupGraphics (const graphics::DisplayConfig &config); + void setupGraphics (const DisplayConfig &config); /** * Setup server, must call setupGame first + * + * Requires: NETWORK_ENABLED */ void setupNetworkServer (const std::string &listen_port); /** * Setup client, do *not* call setupGame, configuration comes from the server + * + * Requires: NETWORK_ENABLED */ void setupNetworkClient (const std::string &connect_host, const std::string &connect_port); @@ -82,9 +92,9 @@ private: /** - * Actually start graphics, requires that game_state is now set + * Puts graphics into GameView mode, using our GameState and the given player */ - void startGraphics (void); + void startGameView (LocalPlayer *player); public: // get a pointer to our resource manager diff -r 38cba347a3a9 -r c503e0c6a740 src/GameState.cc --- a/src/GameState.cc Thu Jan 22 00:28:26 2009 +0200 +++ b/src/GameState.cc Thu Jan 22 01:53:05 2009 +0200 @@ -2,6 +2,7 @@ #include "GameState.hh" #include "Engine.hh" #include "Config.hh" +#include "Error.hh" GameState::GameState (Terrain &terrain) : world(Vector(0, MAP_GRAVITY), Vector(terrain.getWidth(), terrain.getHeight()), terrain), @@ -49,7 +50,8 @@ if (event_handler) event_handler->on_player_left(player); } - + +#if GRAPHICS_ENABLED void GameState::draw (graphics::Display &display, PixelCoordinate camera, bool displayWeapon) { // Draw terrain terrain.draw(display, camera); @@ -70,4 +72,5 @@ (*it)->draw(display, camera); } } - +#endif + diff -r 38cba347a3a9 -r c503e0c6a740 src/GameState.hh --- a/src/GameState.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/GameState.hh Thu Jan 22 01:53:05 2009 +0200 @@ -93,11 +93,13 @@ * Removes the given player from player_list. If the given player was the local_player, set that to NULL */ void removePlayer (Player *player); - + +#if GRAPHICS_ENABLED /** * Draws the terrain, players and projectiles */ virtual void draw (graphics::Display &display, PixelCoordinate camera, bool displayWeapon); +#endif }; #endif diff -r 38cba347a3a9 -r c503e0c6a740 src/Graphics/CMakeLists.txt --- a/src/Graphics/CMakeLists.txt Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Graphics/CMakeLists.txt Thu Jan 22 01:53:05 2009 +0200 @@ -3,5 +3,7 @@ # what ClanLib components we need set (GRAPHICS_CLANLIB_COMPONENTS Display GL GUI PARENT_SCOPE) + +# list of source files set (GRAPHICS_SOURCES ${GRAPHICS_SOURCE_FILES} ${GRAPHICS_HEADER_FILES} PARENT_SCOPE) diff -r 38cba347a3a9 -r c503e0c6a740 src/Graphics/Display.hh --- a/src/Graphics/Display.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Graphics/Display.hh Thu Jan 22 01:53:05 2009 +0200 @@ -7,23 +7,13 @@ namespace graphics { -struct DisplayConfig { - /** Display resolution */ - PixelDimensions resolution; - - /** Fullscreen mode? */ - bool fullscreen; - - /** Defaults */ - DisplayConfig (void) : resolution(GRAPHICS_RESOLUTION_WIDTH, GRAPHICS_RESOLUTION_HEIGHT), fullscreen(GRAPHICS_FULLSCREEN) { } -}; - class Display; } #include "View.hh" #include "../Timer.hh" +#include "../Configuration.hh" #include diff -r 38cba347a3a9 -r c503e0c6a740 src/Network/Buffer.cc --- a/src/Network/Buffer.cc Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Network/Buffer.cc Thu Jan 22 01:53:05 2009 +0200 @@ -1,6 +1,6 @@ #include "Buffer.hh" -#include "Config.hh" +#include "../Config.hh" #include #include diff -r 38cba347a3a9 -r c503e0c6a740 src/Network/CMakeLists.txt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/Network/CMakeLists.txt Thu Jan 22 01:53:05 2009 +0200 @@ -0,0 +1,9 @@ +FILE(GLOB NETWORK_SOURCE_FILES "*.cc") +FILE(GLOB NETWORK_HEADER_FILES "*.hh") + +# what ClanLib components we need +set (NETWORK_CLANLIB_COMPONENTS "" PARENT_SCOPE) + +# list of source files +set (NETWORK_SOURCES ${NETWORK_SOURCE_FILES} ${NETWORK_HEADER_FILES} PARENT_SCOPE) + diff -r 38cba347a3a9 -r c503e0c6a740 src/Network/Client.cc --- a/src/Network/Client.cc Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Network/Client.cc Thu Jan 22 01:53:05 2009 +0200 @@ -1,7 +1,7 @@ #include "Client.hh" #include "Protocol.hh" -#include "Config.hh" +#include "../Config.hh" #include "../Engine.hh" #include "../Logger.hh" diff -r 38cba347a3a9 -r c503e0c6a740 src/Network/Config.hh --- a/src/Network/Config.hh Thu Jan 22 00:28:26 2009 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -#ifndef NETWORK_CONFIG_HH -#define NETWORK_CONFIG_HH - -/** - * @file - * - * Network-related configuration - */ - -#include - -/** Default port used for network games */ -const std::string NETWORK_PORT_STR = "9338"; - -/** Maximum packet size used for normal NetworkPackets... aligned to a sensible UDP mtu */ -const size_t NETWORK_PACKET_SIZE = 1280; - -/** Backlog used for TCP server... doesn't really matter all that much */ -const int NETWORK_LISTEN_BACKLOG = 5; - -/** Magic string used to identify game between client/server */ -const char NETWORK_MAGIC_STR[8+1] = "KISNGLIS"; -const uint64_t NETWORK_MAGIC_ID = * ((const uint64_t *) NETWORK_MAGIC_STR); - -#endif /* NETWORK_CONFIG_HH */ diff -r 38cba347a3a9 -r c503e0c6a740 src/Network/Packet.hh --- a/src/Network/Packet.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Network/Packet.hh Thu Jan 22 01:53:05 2009 +0200 @@ -7,7 +7,7 @@ * Provides the NetworkPackets that are used to communicate over a NetworkTCP/NetworkUDP sockets. */ -#include "Config.hh" +#include "../Config.hh" #include "../Types.hh" #include "../Error.hh" diff -r 38cba347a3a9 -r c503e0c6a740 src/Network/Server.cc --- a/src/Network/Server.cc Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Network/Server.cc Thu Jan 22 01:53:05 2009 +0200 @@ -1,7 +1,7 @@ #include "Server.hh" #include "Protocol.hh" -#include "Config.hh" +#include "../Config.hh" #include "../Engine.hh" #include "../Logger.hh" diff -r 38cba347a3a9 -r c503e0c6a740 src/Player.cc --- a/src/Player.cc Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Player.cc Thu Jan 22 01:53:05 2009 +0200 @@ -11,11 +11,15 @@ #include #include - -// player static state +#if GRAPHICS_ENABLED +/* + * Static draw-related state + */ bool Player::skin_loaded = false; CL_Surface Player::skin_surface; +#endif + // XXX: give these better names and move elsewhere const int img_num_aim = 5; const int img_num_step = 4; @@ -325,6 +329,7 @@ kills++; } +#if GRAPHICS_ENABLED void Player::draw (graphics::Display &display, PixelCoordinate camera) { CL_GraphicContext *gc = display.get_gc(); @@ -399,4 +404,5 @@ ); } } +#endif diff -r 38cba347a3a9 -r c503e0c6a740 src/Player.hh --- a/src/Player.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Player.hh Thu Jan 22 01:53:05 2009 +0200 @@ -152,6 +152,7 @@ */ void addKill (); +#if GRAPHICS_ENABLED /* * Drawing requires the skin texture, which is loaded on-demand when draw is called */ @@ -162,7 +163,8 @@ * Draw this player */ virtual void draw (graphics::Display &display, PixelCoordinate camera); - +#endif + /** * Returns statistics on the number of kills for this player */ @@ -200,10 +202,12 @@ */ virtual void handleInput (PlayerInput input, TimeMS dt); +#if GRAPHICS_ENABLED /** * As Player, but also draws the current weapon name if displayWeapon */ virtual void draw (graphics::Display &display, bool displayWeapon, PixelCoordinate camera); +#endif }; /** diff -r 38cba347a3a9 -r c503e0c6a740 src/Projectile.cc --- a/src/Projectile.cc Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Projectile.cc Thu Jan 22 01:53:05 2009 +0200 @@ -74,6 +74,7 @@ PhysicsObject::tick(dt); } +#if GRAPHICS_ENABLED void Projectile::draw(graphics::Display &display, PixelCoordinate camera) const { CL_GraphicContext *gc = display.get_gc(); @@ -92,4 +93,5 @@ gc->fill_quad(projectile, CL_Color::green); } } - +#endif + diff -r 38cba347a3a9 -r c503e0c6a740 src/Projectile.hh --- a/src/Projectile.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Projectile.hh Thu Jan 22 01:53:05 2009 +0200 @@ -48,11 +48,6 @@ virtual ~Projectile (void); /** - * Draw - */ - virtual void draw (graphics::Display &display, PixelCoordinate camera) const; - - /** * Get damage inflicted by this projectile. * * @return Damage inflicted by projectile. @@ -94,6 +89,18 @@ * If we have expired, call onDestory and removeGround */ virtual void tick (TimeMS dt); + +public: + +#if GRAPHICS_ENABLED + /** + * Draw + */ + virtual void draw (graphics::Display &display, PixelCoordinate camera) const; + +#endif + + }; #endif diff -r 38cba347a3a9 -r c503e0c6a740 src/Rope.cc --- a/src/Rope.cc Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Rope.cc Thu Jan 22 01:53:05 2009 +0200 @@ -1,6 +1,9 @@ + +// XXX: must include Player first, as it contains an instance of Rope #include "Player.hh" #include "Rope.hh" #include "Engine.hh" +#include "Error.hh" #include #include @@ -150,6 +153,7 @@ this->length = length; } +#if GRAPHICS_ENABLED void Rope::draw (graphics::Display &display, PixelCoordinate camera) { PixelCoordinate player_pos = player.getCoordinate() - camera; PixelCoordinate target_pos; @@ -181,6 +185,7 @@ ROPE_COLOR_DARK ); } +#endif void Rope::tick (TimeMS dt) { if (state == ROPE_FLYING) { diff -r 38cba347a3a9 -r c503e0c6a740 src/Rope.hh --- a/src/Rope.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Rope.hh Thu Jan 22 01:53:05 2009 +0200 @@ -5,11 +5,6 @@ // and the Player wants to know the rope. class Rope; -#include "Player.hh" -#include "PhysicsObject.hh" - -#include "Graphics/Drawable.hh" - /** * The rope can be in one of three states... * @@ -21,6 +16,11 @@ ROPE_FIXED //<<< The rope is attached to something }; +#include "Player.hh" +#include "PhysicsObject.hh" + +#include "Graphics/Drawable.hh" + /** * A rope is a PhysicsObject that can be thrown, whereupon it then flies until it hits something, whereupon * it attaches to that, and sets itself as the player's pivot. @@ -84,10 +84,12 @@ virtual void tick (TimeMS dt); +#if GRAPHICS_ENABLED /* * Draw the rope, in the FLYING/FIXED state */ virtual void draw (graphics::Display &display, PixelCoordinate camera); +#endif }; #endif diff -r 38cba347a3a9 -r c503e0c6a740 src/Terrain.cc --- a/src/Terrain.cc Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Terrain.cc Thu Jan 22 01:53:05 2009 +0200 @@ -101,6 +101,8 @@ } void Terrain::generatePixelBuffer (void) { + +#if GRAPHICS_ENABLED // initialize textures generateTexture(); @@ -114,6 +116,12 @@ pixbuf.draw_pixel(x, y, getTexturePixel(x, y)); } } + +#else + // no-op + +#endif + } /* @@ -410,6 +418,7 @@ return normal; } +#if GRAPHICS_ENABLED void Terrain::draw (graphics::Display &display, PixelCoordinate camera) { // XXX: can we optimize this somehow? @@ -419,4 +428,5 @@ // draw it onto the graphics, offset by camera position surf.draw(-camera.x, -camera.y, display.get_gc()); } +#endif diff -r 38cba347a3a9 -r c503e0c6a740 src/Terrain.hh --- a/src/Terrain.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Terrain.hh Thu Jan 22 01:53:05 2009 +0200 @@ -4,9 +4,12 @@ #include "Vector.hh" #include "Types.hh" #include "Config.hh" +#include "Configuration.hh" #include "Graphics/Drawable.hh" +#include + /** * Different types of terrain available */ @@ -22,27 +25,6 @@ }; /** - * Terrain "pixel" type - */ -typedef uint8_t TerrainPixel; - -/** - * Terrain configuration - */ -struct TerrainConfig { - /** Size of the terrain field*/ - PixelDimensions dimensions; - - /** Set to nonzero to generate random map */ - int random_seed; - - /** Defaults */ - TerrainConfig (void) : dimensions(TERRAIN_WIDTH, TERRAIN_HEIGHT), random_seed(TERRAIN_RANDOM_SEED) { } -}; - -#include - -/** * Terrain class. Represents game terrain and contains member * functions to manipulate terrain and get info about it. * @@ -59,10 +41,13 @@ /** Terrain dimensions */ PixelDimension width, height; - + +#if GRAPHICS_ENABLED /** We pre-render the textured terrain data for display */ CL_PixelBuffer pixbuf; +#endif + // XXX: terrain texture std::vector > texture; @@ -103,8 +88,10 @@ inline void setType (PixelDimension x, PixelDimension y, TerrainType t) { terrain_buf[y * width + x] = (TerrainPixel) t; +#if GRAPHICS_ENABLED // XXX: locking? pixbuf.draw_pixel(x, y, getTexturePixel(x, y)); +#endif } /** @@ -241,6 +228,7 @@ */ Vector getNormal (Vector point, Vector prevPoint) const; +#if GRAPHICS_ENABLED /** * Draw the terrain onto the given graphics context * @@ -248,6 +236,7 @@ * @param camera view position */ virtual void draw (graphics::Display &display, PixelCoordinate camera = PixelCoordinate(0, 0)); +#endif }; #endif diff -r 38cba347a3a9 -r c503e0c6a740 src/Types.hh --- a/src/Types.hh Thu Jan 22 00:28:26 2009 +0200 +++ b/src/Types.hh Thu Jan 22 01:53:05 2009 +0200 @@ -63,4 +63,11 @@ */ typedef int32_t TickCount; +/** + * Terrain "pixel" type + * + * @see TerrainType + */ +typedef uint8_t TerrainPixel; + #endif diff -r 38cba347a3a9 -r c503e0c6a740 src/config.h.in --- a/src/config.h.in Thu Jan 22 00:28:26 2009 +0200 +++ b/src/config.h.in Thu Jan 22 01:53:05 2009 +0200 @@ -13,5 +13,17 @@ */ extern const char *PROJECT_VERSION, *PROJECT_BUILD_TIMESTAMP; +/** + * Provide possibility to compile without graphics code. + * + * Defined as a boolean value (so use #if GRAPHICS_ENABLED / if (GRAPHICS_ENABLED) ) + */ +#define GRAPHICS_ENABLED @GRAPHICS_ENABLED@ + +/** + * Provide possibility to compile without network code. + */ +#define NETWORK_ENABLED @NETWORK_ENABLED@ + #endif