Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

robwxstruct.h

00001 /*
00002  * robwxstruct.h
00003  * 
00004  * Copyright (c) 2000-2004 by Florian Fischer (florianfischer@gmx.de)
00005  * and Martin Trautmann (martintrautmann@gmx.de) 
00006  * 
00007  * This file may be distributed and/or modified under the terms of the 
00008  * GNU General Public License version 2 as published by the Free Software 
00009  * Foundation. 
00010  * 
00011  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013  * 
00014  */
00015 
00016 // Data structures for data exchange between GUI and simulation
00017 
00018 #ifndef __ROB_WX_STRUCT__
00019 #define __ROB_WX_STRUCT__
00020 
00021 #include <rtcollect.h>
00022 #include <rtlist.h>
00023 
00024 #include "robmanage.h"
00025 #include "robvars.h"
00026 
00027 // predefines // 
00028 namespace rt { class Bot; }
00029 namespace lrt {
00030         template<class T> class Vector;
00031         template<class K, class V> class Pair;
00032         class String;
00033 }
00034 class wxCriticalSection;
00035 
00036 // helpy classes //
00037 class RequestQueue; // a thread-safe FIFO buffer
00038 class Request;
00039 class DebugRequest;
00040 
00041 // infostructures //
00042 struct GuiInfo; 
00043 struct BotInfo;
00044 struct SimInfo; 
00045 struct TourInfo; 
00046 struct TourSetupInfo;
00047 typedef lrt::Vector< lrt::Pair<lrt::String, lrt::String> > PlayerInfo; // there is no struct PlayerInfo; 
00048 struct MsgInfo;
00049 struct DebugInfo; 
00050 
00051 // helpy classes //
00052 class Request {
00053 public:
00054         virtual ~Request() {}
00055         virtual Request* clone() const { return new Request(*this); }
00056 protected:
00057         Request() {}
00058 };
00059 
00060 class DebugRequest : public Request {
00061 public:
00062         DebugRequest() : debugX(-1), debugY(-1), debugCloseID(-1) {}
00063         ~DebugRequest() {}
00064         Request* clone() const { return new DebugRequest(*this); }
00065 
00066         int debugX, debugY, debugCloseID;
00067 };
00068 
00069 class RequestQueue : lrt::List<Request*> {
00070 public:
00071         RequestQueue();
00072         ~RequestQueue();
00073         void append(const Request&);
00074         Request* removeFirst(); // returned Request must be deleted
00075         void clear();
00076 private:
00077         wxCriticalSection* critSect;
00078 };
00079 
00080 
00081 // info structures ///////////////
00082 enum GuiTourRestartState { // should we create a new tournament if the current one is finished?
00083         gtourExit,              // no, no more tournament, exit simulation thread instead
00084         gtourNotYet,    // user is undecided yet, wait until he decides
00085         gtourNew                // yes, create a new one immediately
00086 };
00087 
00088 struct GuiInfo
00089 {
00090         // UIstate
00091         int numEvents; // (RoboTourEvents) processed so far; increase when done
00092         int numEventsSent; // (RoboTourEvents) sent so far
00093         bool abortPressed;
00094         bool startPressed;
00095         bool startLocked;
00096         bool slowMode; 
00097         bool pausePressed;
00098         int speed; // simulation speed
00099         int reqPlayerInfo; // Information about that player is requested if rPI >= 0
00100         bool isDestroyed; 
00101 
00102         bool abortTourPressed; // should the current tournament be stopped? 
00103         GuiTourRestartState restart; // should a new tournament be started if the current finishes?
00104         bool haveSimThread;
00105 
00106         RequestQueue reqDebug;
00107 
00108         GuiInfo() : numEvents(0), numEventsSent(0), abortPressed(false), startPressed(false), startLocked(false),
00109                 slowMode(false), pausePressed(false), speed(10), reqPlayerInfo(-1), isDestroyed(false),
00110                 abortTourPressed(false), restart(gtourNew), haveSimThread(true) {}
00111 };
00112 
00113 struct BotInfo
00114 {
00115         int program;
00116         int type;
00117         int head[4];
00118         int active;
00119         int banks; 
00120 
00121         BotInfo(rt::Bot* bot);
00122         BotInfo() : program(-1), type(0), active(1) { for(int i = 0; i < 4; i++) head[i] = -1; }
00123 
00124         bool operator==(const BotInfo&) const;
00125 };
00126 
00127 struct SimInfo
00128 {
00129         int simNum; // the how many'th sim in this tournament? (value is 1..SimCount)
00130         int width;
00131         int height;
00132         int cycle;
00133         int timeout;
00134         int maxBanks;
00135         int maxBots; 
00136         int winner; // -1 while running, a programNumber when finished (or -2 = TIE)
00137         lrt::String winnerName; 
00138 
00139         SimInfo() : width(-1), height(-1), cycle(0), timeout(0), simNum(0), maxBanks(0), maxBots(100), winner(-1) {}
00140         SimInfo(int width, int height, int cycle, int timeout) : width(width), height(height), cycle(cycle), timeout(timeout), maxBanks(0), maxBots(100), winner(-1) {}
00141 };
00142 
00143 struct TourInfo : public rt::TourResult 
00144 {
00145         TourInfo() : rt::TourResult(), numBots(-1), playerNum(-1) {}
00146         TourInfo(const rt::TourResult& tr) : rt::TourResult(tr), numBots(-1), playerNum(-1) {}
00147 
00148         int playerNum; 
00149         int numBots;
00150 };
00151 
00152 struct TourSetupInfo
00153 {
00154         TourSetupInfo() : ok(false), type(Single), numRepeats(10), optionFile("robocom.rco"), sound(false), 
00155                 profile(false), profileType(0), haveSound(false), haveProfiler(false) {}
00156 
00157         enum TourType {
00158                 Single = 0,
00159                 Charts = 1,
00160                 AllInOne = 30
00161         };
00162 
00163         bool ok;
00164         TourType type;
00165         int numRepeats;
00166         lrt::String optionFile;
00167         lrt::Vector<lrt::String> files;
00168         bool sound;
00169         bool profile;
00170         int profileType;
00171 
00172         bool haveSound, haveProfiler;
00173 };
00174 
00175 struct MsgInfo
00176 {
00177         MsgInfo() : id(0), program(0) {}
00178 
00179         int id; // all-purpose identifier
00180         lrt::String msg;
00181         int program; 
00182 };
00183 
00184 struct DebugInfo 
00185 {
00186         struct TaskInfo {
00187                 TaskInfo() : dir(-1), runBank(-1), instrPos(-1), hasChanged(false) {}
00188                 bool updateFrom(rt::Task*);
00189                 bool hasChanged;
00190                 int dir;
00191                 int runBank;
00192                 int instrPos;
00193                 lrt::String instrText;
00194         };
00195 
00196         struct BankInfo {
00197                 BankInfo() : id(0), owner(-1), hasChanged(false) {}
00198                 bool updateFrom(rt::Bank*);
00199                 int id;
00200                 int owner;
00201                 lrt::String name;
00202                 lrt::Vector<lrt::String> instructions;
00203                 bool hasChanged;
00204         };
00205 
00206         DebugInfo() : debugID(-1), botID(0), alive(false), namedVars(rt::botVarLength), namedVarsHasChanged(false), unnamedVarsHasChanged(false) {}
00207         DebugInfo(int debugID) : debugID(debugID), botID(0), alive(false), namedVars(rt::botVarLength), namedVarsHasChanged(false), unnamedVarsHasChanged(false) {}
00208         bool updateFrom(rt::Bot*, bool alive); // returns TRUE if ANYTHING has changed
00209 
00210         int debugID; // which debugging session is this? (each bot gets a new one)
00211         int botID;
00212 
00213         bool alive; 
00214 
00215         lrt::Vector<TaskInfo> tasks;
00216         lrt::Vector<BankInfo> banks;
00217         lrt::Array<rt::rint> namedVars;
00218         bool namedVarsHasChanged;
00219         lrt::Vector<rt::rint> unnamedVars;
00220         bool unnamedVarsHasChanged;
00221         BotInfo botInfo;
00222         lrt::String programName;
00223 };
00224 
00225 
00226 
00227 #endif // FILE

This is the RoboTour API documentation version 0.1 • Copyright (C) by Florian Fischer