Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

celestiacore.h

Go to the documentation of this file.
00001 // celestiacore.h
00002 // 
00003 // Copyright (C) 2001, Chris Laurel <claurel@shatters.net>
00004 //
00005 // This program is free software; you can redistribute it and/or
00006 // modify it under the terms of the GNU General Public License
00007 // as published by the Free Software Foundation; either version 2
00008 // of the License, or (at your option) any later version.
00009 
00010 #ifndef _CELESTIACORE_H_
00011 #define _CELESTIACORE_H_
00012 
00013 // #include "gl.h"
00014 #include <celutil/timer.h>
00015 #include <celutil/watcher.h>
00016 // #include <celutil/watchable.h>
00017 #include <celengine/solarsys.h>
00018 #include <celengine/overlay.h>
00019 #include <celengine/command.h>
00020 #include <celengine/execution.h>
00021 #include <celengine/texture.h>
00022 #include <celengine/universe.h>
00023 #include <celengine/render.h>
00024 #include <celengine/simulation.h>
00025 #include <celengine/gl.h>
00026 #include "configfile.h"
00027 #include "favorites.h"
00028 #include "destination.h"
00029 #include "moviecapture.h"
00030 #ifdef CELX
00031 #include "celx.h"
00032 #endif
00033 class Url;
00034 
00035 // class CelestiaWatcher;
00036 class CelestiaCore;
00037 
00038 typedef Watcher<CelestiaCore> CelestiaWatcher;
00039 
00040 class ProgressNotifier
00041 {
00042 public:
00043     ProgressNotifier() {};
00044     virtual ~ProgressNotifier() {};
00045     
00046     virtual void update(const std::string&) = 0;
00047 };
00048 
00049 class View
00050 {
00051  public:
00052     enum Type {
00053         ViewWindow      = 1,
00054         HorizontalSplit = 2,
00055         VerticalSplit   = 3
00056     };
00057 
00058     View(Type, Observer*, float, float, float, float);
00059 
00060     void mapWindowToView(float, float, float&, float&) const;
00061 
00062  public:
00063     Type type;
00064 
00065     Observer* observer;
00066     View *parent;
00067     View *child1;
00068     View *child2;
00069     float x;
00070     float y;
00071     float width;
00072     float height;
00073     int renderFlags;
00074     int labelMode;
00075     float zoom;
00076     float alternateZoom;
00077 
00078     void walkTreeResize(View*, int);
00079     bool walkTreeResizeDelta(View*, float, bool);
00080 };
00081 
00082 
00083 class CelestiaCore // : public Watchable<CelestiaCore>
00084 {
00085  public:
00086     enum {
00087         LeftButton   = 0x01,
00088         MiddleButton = 0x02,
00089         RightButton  = 0x04,
00090         ShiftKey     = 0x08,
00091         ControlKey   = 0x10,
00092     };
00093 
00094     enum CursorShape {
00095         ArrowCursor         = 0,
00096         UpArrowCursor       = 1,
00097         CrossCursor         = 2,
00098         InvertedCrossCursor = 3,
00099         WaitCursor          = 4,
00100         BusyCursor          = 5,
00101         IbeamCursor         = 6,
00102         SizeVerCursor       = 7,
00103         SizeHorCursor       = 8,
00104         SizeBDiagCursor     = 9,
00105         SizeFDiagCursor     = 10,
00106         SizeAllCursor       = 11,
00107         SplitVCursor        = 12,
00108         SplitHCursor        = 13,
00109         PointingHandCursor  = 14,
00110         ForbiddenCursor     = 15,
00111         WhatsThisCursor     = 16,
00112     };
00113     
00114     enum {
00115         Joy_XAxis           = 0,
00116         Joy_YAxis           = 1,
00117         Joy_ZAxis           = 2,
00118     };
00119 
00120     enum {
00121         JoyButton1          = 0,
00122         JoyButton2          = 1,
00123         JoyButton3          = 2,
00124         JoyButton4          = 3,
00125         JoyButton5          = 4,
00126         JoyButton6          = 5,
00127         JoyButton7          = 6,
00128         JoyButton8          = 7,
00129         JoyButtonCount      = 8,
00130     };
00131 
00132     enum {
00133         Key_Left            =  1,
00134         Key_Right           =  2,
00135         Key_Up              =  3,
00136         Key_Down            =  4,
00137         Key_Home            =  5,
00138         Key_End             =  6,
00139         Key_PageUp          =  7,
00140         Key_PageDown        =  8,
00141         Key_Insert          =  9,
00142         Key_Delete          = 10,
00143         Key_F1              = 11,
00144         Key_F2              = 12,
00145         Key_F3              = 13,
00146         Key_F4              = 14,
00147         Key_F5              = 15,
00148         Key_F6              = 16,
00149         Key_F7              = 17,
00150         Key_F8              = 18,
00151         Key_F9              = 19,
00152         Key_F10             = 20,
00153         Key_F11             = 21,
00154         Key_F12             = 22,
00155         Key_NumPadDecimal   = 23,
00156         Key_NumPad0         = 24,
00157         Key_NumPad1         = 25,
00158         Key_NumPad2         = 26,
00159         Key_NumPad3         = 27,
00160         Key_NumPad4         = 28,
00161         Key_NumPad5         = 29,
00162         Key_NumPad6         = 30,
00163         Key_NumPad7         = 31,
00164         Key_NumPad8         = 32,
00165         Key_NumPad9         = 33,
00166         Key_BackTab         = 127,
00167         KeyCount            = 128,
00168     };
00169 
00170     enum
00171     {
00172         LabelFlagsChanged       = 1,
00173         RenderFlagsChanged      = 2,
00174         VerbosityLevelChanged   = 4,
00175         TimeZoneChanged         = 8,
00176         AmbientLightChanged     = 16,
00177         FaintestChanged         = 32,
00178         HistoryChanged          = 64,
00179         TextEnterModeChanged    = 128,
00180         GalaxyLightGainChanged  = 256,
00181     };
00182 
00183     enum
00184     {
00185         KbNormal         = 0,
00186         KbAutoComplete   = 1,
00187         KbPassToScript   = 2,
00188     };        
00189 
00190     typedef void (*ContextMenuFunc)(float, float, Selection);
00191 
00192  public:
00193     CelestiaCore();
00194     ~CelestiaCore();
00195 
00196     bool initSimulation(const std::string* = NULL,
00197                         const std::vector<std::string>* extrasDirs = NULL,
00198                         ProgressNotifier* progressNotifier = NULL);
00199     bool initRenderer();
00200     void start(double t);
00201     void getLightTravelDelay(double distance, int&, int&, float&);
00202     void setLightTravelDelay(double distance);
00203 
00204     // URLs and history navigation
00205     void setStartURL(std::string url);
00206     void goToUrl(const std::string& url);
00207     void addToHistory();
00208     void back();
00209     void forward();
00210     const std::vector<Url>& getHistory() const;
00211     std::vector<Url>::size_type getHistoryCurrent() const;
00212     void setHistoryCurrent(std::vector<Url>::size_type curr);
00213 
00214     // event processing methods
00215     void charEntered(const char*, int modifiers = 0);
00216     void charEntered(char, int modifiers = 0);
00217     void keyDown(int key, int modifiers = 0);
00218     void keyUp(int key, int modifiers = 0);
00219     void mouseWheel(float, int);
00220     void mouseButtonDown(float, float, int);
00221     void mouseButtonUp(float, float, int);
00222     void mouseMove(float, float, int);
00223     void mouseMove(float, float);
00224     void pickView(float, float);
00225     void joystickAxis(int axis, float amount);
00226     void joystickButton(int button, bool down);
00227     void resize(GLsizei w, GLsizei h);
00228     void draw();
00229     void tick();
00230 
00231     Simulation* getSimulation() const;
00232     Renderer* getRenderer() const;
00233     void showText(std::string s,
00234                   int horig = 0, int vorig = 0,
00235                   int hoff = 0, int voff = 0, 
00236                   double duration = 1.0e9);
00237     int getTextWidth(string s) const;
00238 
00239     void readFavoritesFile();
00240     void writeFavoritesFile();
00241     void activateFavorite(FavoritesEntry&);
00242     void addFavorite(std::string, std::string, FavoritesList::iterator* iter=NULL);
00243     void addFavoriteFolder(std::string, FavoritesList::iterator* iter=NULL);
00244     FavoritesList* getFavorites();
00245 
00246     const DestinationList* getDestinations();
00247 
00248     int getTimeZoneBias() const;
00249     void setTimeZoneBias(int);
00250     std::string getTimeZoneName() const;
00251     void setTimeZoneName(const std::string&);
00252     void setTextEnterMode(int);
00253     int getTextEnterMode() const;
00254 
00255     void initMovieCapture(MovieCapture*);
00256     void recordBegin();
00257     void recordPause();
00258     void recordEnd();
00259     bool isCaptureActive();
00260     bool isRecording();
00261 
00262     void runScript(CommandSequence*);
00263     void runScript(const std::string& filename);
00264     void cancelScript();
00265     void resumeScript();
00266 
00267     int getHudDetail();
00268     void setHudDetail(int);
00269 
00270     void setContextMenuCallback(ContextMenuFunc);
00271 
00272     void addWatcher(CelestiaWatcher*);
00273     void removeWatcher(CelestiaWatcher*);
00274     
00275     void setFaintest(float);
00276     void setFaintestAutoMag();
00277 
00278     void splitView(View::Type type, View* av = NULL, float splitPos = 0.5f);
00279     void singleView(View* av = NULL);
00280     void deleteView(View* v = NULL);
00281     bool getFramesVisible() const;
00282     void setFramesVisible(bool);
00283     bool getActiveFrameVisible() const;
00284     void setActiveFrameVisible(bool);
00285     bool getLightDelayActive() const;
00286     void setLightDelayActive(bool);
00287     int getScreenDpi() const;
00288     void setScreenDpi(int);
00289     int getDistanceToScreen() const;
00290     void setDistanceToScreen(int);
00291 
00292     void setFOVFromZoom();
00293     void setZoomFromFOV();
00294 
00295     void flash(const std::string&, double duration = 1.0);
00296 
00297     CelestiaConfig* getConfig() const;
00298 
00299     void notifyWatchers(int);
00300 
00301     class Alerter
00302     {
00303     public:
00304         virtual ~Alerter() {};
00305         virtual void fatalError(const std::string&) = 0;
00306     };
00307 
00308     void setAlerter(Alerter*);
00309     Alerter* getAlerter() const;
00310 
00311     class CursorHandler
00312     {
00313     public:
00314         virtual ~CursorHandler() {};
00315         virtual void setCursorShape(CursorShape) = 0;
00316         virtual CursorShape getCursorShape() const = 0;
00317     };
00318     
00319     void setCursorHandler(CursorHandler*);
00320     CursorHandler* getCursorHandler() const;
00321     
00322  private:
00323     bool readStars(const CelestiaConfig&, ProgressNotifier*);
00324     void renderOverlay();
00325     void fatalError(const std::string&);
00326 
00327  private:
00328     CelestiaConfig* config;
00329 
00330     Universe* universe;
00331 
00332     FavoritesList* favorites;
00333     DestinationList* destinations;
00334 
00335     Simulation* sim;
00336     Renderer* renderer;
00337     Overlay* overlay;
00338     int width;
00339     int height;
00340 
00341     TextureFont* font;
00342     TextureFont* titleFont;
00343 
00344     std::string messageText;
00345     int messageHOrigin;
00346     int messageVOrigin;
00347     int messageHOffset;
00348     int messageVOffset;
00349     double messageStart;
00350     double messageDuration;
00351     std::string typedText;
00352     std::vector<std::string> typedTextCompletion;
00353     int typedTextCompletionIdx;
00354     int textEnterMode;
00355     int hudDetail;
00356     bool wireframe;
00357     bool editMode;
00358     bool altAzimuthMode;
00359     bool showConsole;
00360     bool lightTravelFlag;
00361     double flashFrameStart;
00362 
00363     Timer* timer;
00364 
00365     Execution* runningScript;
00366     ExecutionEnvironment* execEnv;
00367 
00368 #ifdef CELX
00369     LuaState* celxScript;
00370 #endif // CELX    
00371 
00372     int timeZoneBias;              // Diff in secs between local time and GMT
00373     std:: string timeZoneName;     // Name of the current time zone
00374 
00375     // Frame rate counter variables
00376     bool showFPSCounter;
00377     int nFrames;
00378     double fps;
00379     double fpsCounterStartTime;
00380 
00381     float oldFOV;
00382     float mouseMotion;
00383     double dollyMotion;
00384     double dollyTime;
00385     double zoomMotion;
00386     double zoomTime;
00387 
00388     double sysTime;
00389     double currentTime;
00390     double timeScale;
00391     bool paused;
00392     bool scriptPaused;
00393 
00394     Vec3f joystickRotation;
00395     bool joyButtonsPressed[JoyButtonCount];
00396     bool keysPressed[KeyCount];
00397     bool shiftKeysPressed[KeyCount];
00398     double KeyAccel;
00399 
00400     MovieCapture* movieCapture;
00401     bool recording;
00402 
00403     ContextMenuFunc contextMenuCallback;
00404 
00405     Texture* logoTexture;
00406 
00407     Alerter* alerter;
00408     std::vector<CelestiaWatcher*> watchers;
00409     CursorHandler* cursorHandler;
00410     CursorShape defaultCursorShape;
00411     
00412     std::vector<Url> history;
00413     std::vector<Url>::size_type historyCurrent;
00414     std::string startURL;
00415 
00416     std::vector<View*> views;
00417     int activeView;
00418     bool showActiveViewFrame;
00419     bool showViewFrames;
00420     View *resizeSplit;
00421 
00422     int screenDpi;
00423     int distanceToScreen;
00424 
00425     Selection lastSelection;
00426     string selectionNames;
00427 
00428 #ifdef CELX
00429     friend View* getViewByObserver(CelestiaCore*, Observer*);
00430     friend void getObservers(CelestiaCore*, std::vector<Observer*>&);
00431 #endif
00432 };
00433 
00434 #endif // _CELESTIACORE_H_

Generated on Sat Jan 14 22:30:30 2006 for Celestia by  doxygen 1.4.1