diff --git a/judge/manager/game.cpp b/judge/manager/game.cpp index 3d6dcc805ab091e57fac2121c64ee0bf2f1cf273..df7a061ab1352241cbac23a92bec0318f87dc8fc 100644 --- a/judge/manager/game.cpp +++ b/judge/manager/game.cpp @@ -1,5 +1,5 @@ #include "game.h" - +#include <stdarg.h> using namespace std; @@ -20,8 +20,10 @@ Game::Game(const char * redPath, const char * bluePath, const bool enableGraphic signal(SIGPIPE, Game::HandleBrokenPipe); + #ifdef BUILD_GRAPHICS if (graphicsEnabled && (!Graphics::Initialised())) Graphics::Initialise("Stratego", theBoard.Width()*32, theBoard.Height()*32); + #endif //BUILD_GRAPHICS if (strcmp(redPath, "human") == 0) red = new Human_Controller(Piece::RED, graphicsEnabled); @@ -49,9 +51,10 @@ Game::Game(const char * fromFile, const bool enableGraphics, double newStallTime Game::theGame = this; signal(SIGPIPE, Game::HandleBrokenPipe); - + #ifdef BUILD_GRAPHICS if (graphicsEnabled && (!Graphics::Initialised())) Graphics::Initialise("Stratego", theBoard.Width()*32, theBoard.Height()*32); + #endif //BUILD_GRAPHICS input = fopen(fromFile, "r"); @@ -201,16 +204,18 @@ void Game::Wait(double wait) TimerThread timer(wait*1000000); //Wait in seconds timer.Start(); + #ifdef BUILD_GRAPHICS if (!graphicsEnabled) { while (!timer.Finished()); timer.Stop(); return; } - + #endif //BUILD_GRAPHICS while (!timer.Finished()) { + #ifdef BUILD_GRAPHICS SDL_Event event; while (SDL_PollEvent(&event)) { @@ -222,6 +227,7 @@ void Game::Wait(double wait) break; } } + #endif //BUILD_GRAPHICS } timer.Stop(); @@ -256,6 +262,8 @@ void Game::HandleBrokenPipe(int sig) if (Game::theGame->printBoard) Game::theGame->theBoard.PrintPretty(stdout, Piece::BOTH); + + #ifdef BUILD_GRAPHICS if (Game::theGame->graphicsEnabled && theGame->log == stdout) { theGame->logMessage("CLOSE WINDOW TO EXIT\n"); @@ -275,6 +283,7 @@ void Game::HandleBrokenPipe(int sig) } } else + #endif //BUILD_GRAPHICS { if (theGame->log == stdout) { @@ -396,6 +405,8 @@ void Game::PrintEndMessage(const MovementResult & result) theBoard.PrintPretty(stdout, Piece::BOTH); fprintf(stdout, "\n"); } + + #ifdef BUILD_GRAPHICS if (graphicsEnabled && log == stdout) { logMessage("CLOSE WINDOW TO EXIT\n"); @@ -415,6 +426,7 @@ void Game::PrintEndMessage(const MovementResult & result) } } else + #endif //BUILD_GRAPHICS { if (log == stdout) { @@ -459,8 +471,10 @@ MovementResult Game::Play() fprintf(stdout, "\n\n"); } + #ifdef BUILD_GRAPHICS if (graphicsEnabled) theBoard.Draw(toReveal); + #endif //BUILD_GRAPHICS turn = Piece::RED; logMessage( "%d RED: ", turnCount); @@ -485,8 +499,11 @@ MovementResult Game::Play() theBoard.PrintPretty(stdout, toReveal); fprintf(stdout, "\n\n"); } + + #ifdef BUILD_GRAPHICS if (graphicsEnabled) theBoard.Draw(toReveal); + #endif //BUILD_GRAPHICS diff --git a/judge/manager/game.h b/judge/manager/game.h index 1212b891e924d9a4cd741b1fe66a1eb4ddd6f25d..43f4d0e7f6cb287393cd77c32794880051f6fc07 100644 --- a/judge/manager/game.h +++ b/judge/manager/game.h @@ -4,7 +4,7 @@ #include "stratego.h" #include "ai_controller.h" #include "human_controller.h" - +#include <cstring> /** diff --git a/judge/manager/graphics.cpp b/judge/manager/graphics.cpp index 5b708df75ab0b5edf833db1b455e6388737e8d33..7cc22d0a495237de04994ea3af01aff23682d1bc 100644 --- a/judge/manager/graphics.cpp +++ b/judge/manager/graphics.cpp @@ -3,6 +3,7 @@ #include <cassert> #include <iostream> +#ifdef BUILD_GRAPHICS #undef DEBUG //#define DEBUG @@ -127,6 +128,7 @@ void Texture::Draw(int x, int y, double angle , double scale ) } + Font::Font(const char * filename, int newWidth, int newHeight) : Texture(filename), width(newWidth), height(newHeight) { @@ -442,8 +444,9 @@ Colour Graphics::ConvertColour(Uint8 from) return result; } +void Graphics::Wait(int n) +{ + SDL_Delay(n); +} - - - - +#endif //BUILD_GRAPHICS diff --git a/judge/manager/graphics.h b/judge/manager/graphics.h index f81bdb3b50329e41f17482a43080e3f9a7c24af0..2a969327d8a14790564067c76e9426ce8ee76083 100644 --- a/judge/manager/graphics.h +++ b/judge/manager/graphics.h @@ -1,19 +1,26 @@ +//#define BUILD_GRAPHICS +#ifdef BUILD_GRAPHICS + #ifndef GRAPHICS_H #define GRAPHICS_H + #include <SDL/SDL.h> #include <SDL/SDL_opengl.h> +typedef SDL_Surface Screen; +typedef SDL_Rect Rectangle; +typedef short unsigned int SUint; +typedef unsigned char Uint8; #include <vector> #include <list> -typedef SDL_Surface Screen; -typedef SDL_Rect Rectangle; -typedef short unsigned int SUint; + + class Texture; class Font; @@ -72,8 +79,8 @@ class Graphics static SDL_Surface * TextureFromColours(std::vector<SUint> * R, std::vector<SUint> * G, std::vector<SUint> * B, std::vector<SUint> * A = NULL); static SDL_Surface * TextureFromColours(std::vector<std::vector<SUint> > * R, std::vector<std::vector<SUint> > * G, std::vector<std::vector<SUint> > * B, std::vector<std::vector<SUint> > * A = NULL); - - static void Wait(int n) {SDL_Delay(n);} + + static void Wait(int n); template <class T> class TextureManager @@ -120,6 +127,7 @@ class Texture int width() const {return surface->w;} int height() const {return surface->h;} + protected: SDL_Surface * surface; GLuint texture; @@ -145,4 +153,6 @@ class Font : private Texture #endif //GRAPHICS_H +#endif //BUILD_GRAPHICS + //EOF diff --git a/judge/manager/human_controller.cpp b/judge/manager/human_controller.cpp index bf43e8d71eda1323b89a486a39afd81430f926ea..c2470d3311019e40fe15f03e78e69b08c77f178e 100644 --- a/judge/manager/human_controller.cpp +++ b/judge/manager/human_controller.cpp @@ -110,9 +110,10 @@ MovementResult Human_Controller::QueryMove(string & buffer) } - + #ifdef BUILD_GRAPHICS if (graphicsEnabled) { + fprintf(stdout, "Click to move!\n"); SDL_Event event; int mouseClick = 0; @@ -164,8 +165,10 @@ MovementResult Human_Controller::QueryMove(string & buffer) } } fprintf(stdout, "Move complete!\n"); + } else + #endif //BUILD_GRAPHICS { buffer.clear(); for (char in = fgetc(stdin); in != '\n'; in = fgetc(stdin)) diff --git a/judge/manager/main.cpp b/judge/manager/main.cpp index 0fbd6aef6c35d51476a33407681a28a2e11a6530..9d2cad145534087e35552e5d1731c7a1b2f8d75b 100644 --- a/judge/manager/main.cpp +++ b/judge/manager/main.cpp @@ -8,6 +8,7 @@ #include "game.h" + using namespace std; Piece::Colour SetupGame(int argc, char ** argv); @@ -82,7 +83,13 @@ Piece::Colour SetupGame(int argc, char ** argv) ++ii; break; case 'g': + #ifdef BUILD_GRAPHICS graphics = !graphics; + #else + fprintf(stderr, "ERROR: -g switch supplied, but the program was not built with graphics.\n Please do not use the -g switch."); + exit(EXIT_FAILURE); + #endif //BUILD_GRAPHICS + break; case 'p': printBoard = !printBoard; diff --git a/judge/manager/stratego.cpp b/judge/manager/stratego.cpp index 410b70a29116c32828069680997ce964466cdafd..e7cf60ac8b50573d98d3cfce3a7961ae01852404 100644 --- a/judge/manager/stratego.cpp +++ b/judge/manager/stratego.cpp @@ -14,12 +14,9 @@ int Piece::maxUnits[] = {0,0,1,1,8,5,4,4,4,3,2,1,1,6,0}; - +#ifdef BUILD_GRAPHICS Piece::TextureManager Piece::textures; - - - Piece::TextureManager::~TextureManager() { Array<Texture*>::Iterator i(*this); @@ -41,7 +38,7 @@ Texture & Piece::TextureManager::operator[](const LUint & at) } return *(Array<Texture*>::operator[](at)); } - +#endif //BUILD_GRAPHICS /** * Gets the type of a piece, based off a character token @@ -197,7 +194,7 @@ void Board::PrintPretty(FILE * stream, const Piece::Colour & reveal) } - +#ifdef BUILD_GRAPHICS /** * Draw the board state to graphics * @param reveal - Pieces matching this colour will be revealed. If Piece::BOTH, all pieces will be revealed @@ -206,6 +203,7 @@ void Board::PrintPretty(FILE * stream, const Piece::Colour & reveal) */ void Board::Draw(const Piece::Colour & reveal, bool showRevealed) { + if (!Graphics::Initialised()) { fprintf(stderr, "ERROR - Board::Draw called whilst graphics disabled!!!\n"); @@ -256,6 +254,7 @@ void Board::Draw(const Piece::Colour & reveal, bool showRevealed) Graphics::UpdateScreen(); } +#endif //BUILD_GRAPHICS /** * Adds a piece to the board diff --git a/judge/manager/stratego.h b/judge/manager/stratego.h index fe73aa13ff0b4311c3d10acea02c493f9b6dd610..c8f4f9d76a6b58643c4a0ecf96f74888ab566363 100644 --- a/judge/manager/stratego.h +++ b/judge/manager/stratego.h @@ -6,9 +6,8 @@ #include <assert.h> - - #include "graphics.h" - #include "array.h" +#include "graphics.h" +#include "array.h" #include <vector> @@ -58,6 +57,7 @@ class Piece public: + #ifdef BUILD_GRAPHICS class TextureManager : public Graphics::TextureManager<LUint>, private Array<Texture*> { public: @@ -86,7 +86,7 @@ class Piece break; } } - + #endif //BUILD_GRAPHICS @@ -108,8 +108,9 @@ class Board void Print(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board void PrintPretty(FILE * stream, const Piece::Colour & reveal=Piece::BOTH); //Print board using colour + #ifdef BUILD_GRAPHICS void Draw(const Piece::Colour & reveal=Piece::BOTH, bool showRevealed = true); //Draw board - + #endif //BUILD_GRAPHICS bool AddPiece(int x, int y, const Piece::Type & newType, const Piece::Colour & newColour); //Add piece to board diff --git a/web/doc/manager_manual.txt b/web/doc/manager_manual.txt index 239c6acaf1d47778ee705e6509e820bdc69f5afe..9024c74b1accde33a6b6057cc330766d7d682f19 100644 --- a/web/doc/manager_manual.txt +++ b/web/doc/manager_manual.txt @@ -36,6 +36,8 @@ A WARNING ABOUT BUFFERING OPTIONS -g + NOTE: This switch only functions if stratego is built with graphics enabled. See BUILDING for more information. + By default, graphics are disabled. If the -g switch is present, stratego will draw the game as it is played using SDL/OpenGL -p @@ -216,6 +218,24 @@ EXIT/OUTPUT If an error occurs within stratego itself, an error message will be printed to stderr and return exit code 1. If possible, stratego will print the message "QUIT" to both AI programs, and they should exit as soon as possible. + +BUILDING + To build from source, simply run make in the source directory. + + stratego can be built with or without graphics enabled. By default, graphics are disabled. + + To enable graphics, ensure that the first line of the source file "graphics.h" reads: + + #define BUILD_GRAPHICS + + To disable graphics, comment out the first line of "graphics.h" i.e ensure that it reads: + + //#define BUILD_GRAPHICS + + If you intend to build with graphics enabled, you will need the SDL and OpenGL developement libraries installed first. + If you intend to use graphics, please ensure the "images" directory is located in the executable's run directory. + + BUGS @@ -242,5 +262,5 @@ NOTES irc://irc.ucc.asn.au #progcomp THIS PAGE LAST UPDATED - 20/12/11 by Sam Moore + 23/12/11 by Sam Moore