Added build option to build "stratego" without graphics
authorSam Moore <[email protected]>
Fri, 23 Dec 2011 04:30:38 +0000 (12:30 +0800)
committerSam Moore <[email protected]>
Fri, 23 Dec 2011 04:30:38 +0000 (12:30 +0800)
I need this for mufasa (vm), which doesn't have SDL or OpenGL or even GNOME
Besides, it doesn't need it, and attempting to install them did not end well...

Still need to test that it actually builds on mufasa

judge/manager/game.cpp
judge/manager/game.h
judge/manager/graphics.cpp
judge/manager/graphics.h
judge/manager/human_controller.cpp
judge/manager/main.cpp
judge/manager/stratego.cpp
judge/manager/stratego.h
web/doc/manager_manual.txt

index 3d6dcc8..df7a061 100644 (file)
@@ -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
 
                
                
index 1212b89..43f4d0e 100644 (file)
@@ -4,7 +4,7 @@
 #include "stratego.h"
 #include "ai_controller.h"
 #include "human_controller.h"
-
+#include <cstring>
 
 
 /**
index 5b708df..7cc22d0 100644 (file)
@@ -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
index f81bdb3..2a96932 100644 (file)
@@ -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
index bf43e8d..c2470d3 100644 (file)
@@ -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))
index 0fbd6ae..9d2cad1 100644 (file)
@@ -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;
index 410b70a..e7cf60a 100644 (file)
@@ -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
index fe73aa1..c8f4f9d 100644 (file)
@@ -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
 
index 239c6ac..9024c74 100644 (file)
@@ -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
        

UCC git Repository :: git.ucc.asn.au