Game Develop C++ Platform: CodeCompiler.h Source File

| Game Develop C++ Platform Platform for developing native games based on OpenGL and SFML with Game Develop

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
CodeCompiler.h
Go to the documentation of this file.
1
6 #if defined(GD_IDE_ONLY) && !defined(GD_NO_WX_GUI)
7
8 #ifndef CODECOMPILER_H
9 #define CODECOMPILER_H
10 #include <string>
11 #include <vector>
12 #include <set>
13 #include <SFML/System.hpp>
14 #include <boost/shared_ptr.hpp>
15 #include <wx/event.h>
16 #include <wx/process.h>
17 #include <wx/thread.h>
18 class CodeCompilerExtraWork;
19 namespace gd { class Layout; }
20 class CodeCompilerThreadStateNotifier;
21
27 class GD_API CodeCompilerCall
28 {
29 public:
30
34 CodeCompilerCall();
35
39 std::string GetFullCall() const;
40
41 const std::string & GetCompilerExecutable() const { return compilerExecutable; }
42 void SetCompilerExecutable(const std::string & compilerExecutableFullPath) { compilerExecutable = compilerExecutableFullPath; }
43
44 bool link;
45 std::string inputFile;
46 std::string outputFile;
47
48 std::vector<std::string> extraObjectFiles;
49 std::vector<std::string> extraLibFiles;
50 std::vector<std::string> extraHeaderDirectories;
51 std::vector<std::string> extraOptions;
52
53 bool optimize;
54 bool compilationForRuntime;
55 bool eventsGeneratedCode;
56
60 bool IsSameAs(CodeCompilerCall & other) const {
61 return (inputFile == other.inputFile && outputFile == other.outputFile && compilationForRuntime == other.compilationForRuntime
62 && optimize == other.optimize && eventsGeneratedCode == other.eventsGeneratedCode );
63 }
64
65 private:
66
67 std::string compilerExecutable;
68 };
69
75 class GD_API CodeCompilerTask
76 {
77 public:
78 CodeCompilerTask() : emptyTask(false), scene(NULL) {};
79 virtual ~CodeCompilerTask() {};
80
81 bool emptyTask;
82
83 boost::shared_ptr<CodeCompilerExtraWork> postWork;
84 boost::shared_ptr<CodeCompilerExtraWork> preWork;
85 CodeCompilerCall compilerCall;
86
87 std::string userFriendlyName;
88 gd::Layout * scene;
89
93 bool IsSameTaskAs(CodeCompilerTask & other) const {
94 return (emptyTask == other.emptyTask &&compilerCall.IsSameAs(other.compilerCall) && scene == other.scene);
95 }
96 };
97
103 class GD_API CodeCompilerExtraWork
104 {
105 public:
109 virtual bool Execute() {return true;};
110
111 bool requestRelaunchCompilationLater;
112 bool compilationSucceeded;
113
114 CodeCompilerExtraWork();
115 virtual ~CodeCompilerExtraWork();
116 };
117
124 class CodeCompilerProcess : public wxProcess
125 {
126 public:
127 CodeCompilerProcess(wxEvtHandler * parent);
128 virtual ~CodeCompilerProcess() {};
129
130 std::vector<std::string> output;
131 std::vector<std::string> outputErrors;
132 wxEvtHandler * parent;
133 int exitCode;
134
137 void WatchOutput();
138
139 protected:
140 virtual void OnTerminate( int pid, int status );
141 private:
142
145 void ReadOutput();
146
147 bool stopWatchOutput;
148 };
149
157 class GD_API CodeCompiler : public wxEvtHandler
158 {
159 public:
160
166 void AddTask(CodeCompilerTask task);
167
171 bool HasTaskRelatedTo(gd::Layout & scene) const;
172
177 void EnableTaskRelatedTo(gd::Layout & scene);
178
184 void DisableTaskRelatedTo(gd::Layout & scene);
185
189 void RemovePendingTasksRelatedTo(gd::Layout & scene);
190
194 bool CompilationInProcess() const;
195
199 std::vector < CodeCompilerTask > GetCurrentTasks() const;
200
206 void AddHeaderDirectory(const std::string & dir);
207
211 const std::set<std::string> & GetAllHeadersDirectories() const { return headersDirectories; }
212
216 void AddNotifiedControl(wxEvtHandler * control) { notifiedControls.insert(control); };
217
221 void RemoveNotifiedControl(wxEvtHandler * control) { notifiedControls.erase(control); };
222
226 bool LastTaskFailed() { return lastTaskFailed; };
227
231 const std::string & GetLastTaskMessages() { return lastTaskMessages; };
232
236 void SetMustDeleteTemporaries(bool mustDeleteTemporaries_) { mustDeleteTemporaries = mustDeleteTemporaries_; };
237
241 bool MustDeleteTemporaries() { return mustDeleteTemporaries; };
242
247 void SetBaseDirectory(std::string baseDir_);
248
252 const std::string & GetBaseDirectory() const { return baseDir; };
253
258 void SetOutputDirectory(std::string outputDir_);
259
263 const std::string & GetOutputDirectory() const { return outputDir; };
264
268 void ClearOutputDirectory();
269
278 void AllowMultithread(bool allow = true, unsigned int maxThread = 3);
279
280 static CodeCompiler * GetInstance();
281 static void DestroySingleton();
282
283 static sf::Mutex openSaveDialogMutex;
284 static const wxEventType refreshEventType;
285 static const wxEventType processEndedEventType;
286
287 private:
288
296 void StartTheNextTask();
297
301 void NotifyControls();
302
306 void SendCurrentProcessToGarbage();
307
308 #if defined(LINUX)
309 public:
310 #endif
311
317 void ProcessEndedWork(wxCommandEvent& event);
318 #if defined(LINUX)
319 private:
320 #endif
321
322 //Current task
323 bool processLaunched;
324 CodeCompilerTask currentTask;
325 CodeCompilerProcess * currentTaskProcess;
326 sf::Thread * currentTaskOutputThread;
327
328 //Pending task management
329 std::vector < CodeCompilerTask > pendingTasks;
330 mutable sf::Mutex pendingTasksMutex;
331 std::vector < gd::Layout* > compilationDisallowed;
332
333 //Global compiler configuration
334 std::string baseDir;
335 std::string outputDir;
336 std::set < std::string > headersDirectories;
337 bool mustDeleteTemporaries;
338
339 //Gui related
340 std::set<wxEvtHandler*> notifiedControls;
341 std::string lastTaskMessages;
342 bool lastTaskFailed;
343
344 CodeCompiler();
345 virtual ~CodeCompiler();
346 static CodeCompiler *_singleton;
347 };
348
349 #endif // CODECOMPILER_H
350 #endif