1 #ifndef ENGINE_H
2 #define ENGINE_H
3 
4 #include <components/compiler/extensions.hpp>
5 #include <components/files/collections.hpp>
6 #include <components/translation/translation.hpp>
7 #include <components/settings/settings.hpp>
8 
9 #include <osgViewer/Viewer>
10 #include <osgViewer/ViewerEventHandlers>
11 
12 #include "mwbase/environment.hpp"
13 
14 #include "mwworld/ptr.hpp"
15 
16 namespace Resource
17 {
18     class ResourceSystem;
19 }
20 
21 namespace SceneUtil
22 {
23     class WorkQueue;
24 }
25 
26 namespace VFS
27 {
28     class Manager;
29 }
30 
31 namespace Compiler
32 {
33     class Context;
34 }
35 
36 namespace Files
37 {
38     struct ConfigurationManager;
39 }
40 
41 namespace osgViewer
42 {
43     class ScreenCaptureHandler;
44 }
45 
46 struct SDL_Window;
47 
48 namespace OMW
49 {
50     /// \brief Main engine class, that brings together all the components of OpenMW
51     class Engine
52     {
53             SDL_Window* mWindow;
54             std::unique_ptr<VFS::Manager> mVFS;
55             std::unique_ptr<Resource::ResourceSystem> mResourceSystem;
56             osg::ref_ptr<SceneUtil::WorkQueue> mWorkQueue;
57             MWBase::Environment mEnvironment;
58             ToUTF8::FromType mEncoding;
59             ToUTF8::Utf8Encoder* mEncoder;
60             Files::PathContainer mDataDirs;
61             std::vector<std::string> mArchives;
62             boost::filesystem::path mResDir;
63             osg::ref_ptr<osgViewer::Viewer> mViewer;
64             osg::ref_ptr<osgViewer::ScreenCaptureHandler> mScreenCaptureHandler;
65             osgViewer::ScreenCaptureHandler::CaptureOperation *mScreenCaptureOperation;
66             std::string mCellName;
67             std::vector<std::string> mContentFiles;
68             std::vector<std::string> mGroundcoverFiles;
69             bool mSkipMenu;
70             bool mUseSound;
71             bool mCompileAll;
72             bool mCompileAllDialogue;
73             int mWarningsMode;
74             std::string mFocusName;
75             bool mScriptConsoleMode;
76             std::string mStartupScript;
77             int mActivationDistanceOverride;
78             std::string mSaveGameFile;
79             // Grab mouse?
80             bool mGrab;
81 
82             bool mExportFonts;
83             unsigned int mRandomSeed;
84 
85             Compiler::Extensions mExtensions;
86             Compiler::Context *mScriptContext;
87 
88             Files::Collections mFileCollections;
89             bool mFSStrict;
90             Translation::Storage mTranslationDataStorage;
91             std::vector<std::string> mScriptBlacklist;
92             bool mScriptBlacklistUse;
93             bool mNewGame;
94 
95             // not implemented
96             Engine (const Engine&);
97             Engine& operator= (const Engine&);
98 
99             void executeLocalScripts();
100 
101             bool frame (float dt);
102 
103             /// Load settings from various files, returns the path to the user settings file
104             std::string loadSettings (Settings::Manager & settings);
105 
106             /// Prepare engine for game play
107             void prepareEngine (Settings::Manager & settings);
108 
109             void createWindow(Settings::Manager& settings);
110             void setWindowIcon();
111 
112         public:
113             Engine(Files::ConfigurationManager& configurationManager);
114             virtual ~Engine();
115 
116             /// Enable strict filesystem mode (do not fold case)
117             ///
118             /// \attention The strict mode must be specified before any path-related settings
119             /// are given to the engine.
120             void enableFSStrict(bool fsStrict);
121 
122             /// Set data dirs
123             void setDataDirs(const Files::PathContainer& dataDirs);
124 
125             /// Add BSA archive
126             void addArchive(const std::string& archive);
127 
128             /// Set resource dir
129             void setResourceDir(const boost::filesystem::path& parResDir);
130 
131             /// Set start cell name
132             void setCell(const std::string& cellName);
133 
134             /**
135              * @brief addContentFile - Adds content file (ie. esm/esp, or omwgame/omwaddon) to the content files container.
136              * @param file - filename (extension is required)
137              */
138             void addContentFile(const std::string& file);
139             void addGroundcoverFile(const std::string& file);
140 
141             /// Disable or enable all sounds
142             void setSoundUsage(bool soundUsage);
143 
144             /// Skip main menu and go directly into the game
145             ///
146             /// \param newGame Start a new game instead off dumping the player into the game
147             /// (ignored if !skipMenu).
148             void setSkipMenu (bool skipMenu, bool newGame);
149 
setGrabMouse(bool grab)150             void setGrabMouse(bool grab) { mGrab = grab; }
151 
152             /// Initialise and enter main loop.
153             void go();
154 
155             /// Compile all scripts (excludign dialogue scripts) at startup?
156             void setCompileAll (bool all);
157 
158             /// Compile all dialogue scripts at startup?
159             void setCompileAllDialogue (bool all);
160 
161             /// Font encoding
162             void setEncoding(const ToUTF8::FromType& encoding);
163 
164             /// Enable console-only script functionality
165             void setScriptConsoleMode (bool enabled);
166 
167             /// Set path for a script that is run on startup in the console.
168             void setStartupScript (const std::string& path);
169 
170             /// Override the game setting specified activation distance.
171             void setActivationDistanceOverride (int distance);
172 
173             void setWarningsMode (int mode);
174 
175             void setScriptBlacklist (const std::vector<std::string>& list);
176 
177             void setScriptBlacklistUse (bool use);
178 
179             void enableFontExport(bool exportFonts);
180 
181             /// Set the save game file to load after initialising the engine.
182             void setSaveGameFile(const std::string& savegame);
183 
184             void setRandomSeed(unsigned int seed);
185 
186         private:
187             Files::ConfigurationManager& mCfgMgr;
188     };
189 }
190 
191 #endif /* ENGINE_H */
192