comparison Applications/Sdl/SdlStoneApplicationRunner.cpp @ 294:faccc4b07b92 am-2

renamings
author am@osimis.io
date Thu, 30 Aug 2018 17:17:11 +0200
parents Applications/Sdl/BasicSdlApplication.cpp@017044be141b
children 6cc3ce74dc05
comparison
equal deleted inserted replaced
293:017044be141b 294:faccc4b07b92
1 /**
2 * Stone of Orthanc
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics
4 * Department, University Hospital of Liege, Belgium
5 * Copyright (C) 2017-2018 Osimis S.A., Belgium
6 *
7 * This program is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Affero General Public License
9 * as published by the Free Software Foundation, either version 3 of
10 * the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 **/
20
21
22 #if ORTHANC_ENABLE_SDL != 1
23 #error this file shall be included only with the ORTHANC_ENABLE_SDL set to 1
24 #endif
25
26 #include "SdlStoneApplicationRunner.h"
27 #include <boost/program_options.hpp>
28
29 #include "../../Framework/Toolbox/MessagingToolbox.h"
30 #include "SdlEngine.h"
31
32 #include <Core/Logging.h>
33 #include <Core/HttpClient.h>
34 #include <Core/Toolbox.h>
35 #include <Plugins/Samples/Common/OrthancHttpConnection.h>
36 #include "../../Platforms/Generic/OracleWebService.h"
37
38 namespace OrthancStone
39 {
40 void SdlStoneApplicationRunner::Initialize()
41 {
42 SdlWindow::GlobalInitialize();
43 }
44
45 void SdlStoneApplicationRunner::DeclareCommandLineOptions(boost::program_options::options_description& options)
46 {
47 boost::program_options::options_description sdl("SDL options");
48 sdl.add_options()
49 ("width", boost::program_options::value<int>()->default_value(1024), "Initial width of the SDL window")
50 ("height", boost::program_options::value<int>()->default_value(768), "Initial height of the SDL window")
51 ("opengl", boost::program_options::value<bool>()->default_value(true), "Enable OpenGL in SDL")
52 ;
53
54 options.add(sdl);
55 }
56
57 void SdlStoneApplicationRunner::ParseCommandLineOptions(const boost::program_options::variables_map& parameters)
58 {
59 if (!parameters.count("width") ||
60 !parameters.count("height") ||
61 !parameters.count("opengl"))
62 {
63 LOG(ERROR) << "Parameter \"width\", \"height\" or \"opengl\" is missing";
64 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
65 }
66
67 int w = parameters["width"].as<int>();
68 int h = parameters["height"].as<int>();
69 if (w <= 0 || h <= 0)
70 {
71 LOG(ERROR) << "Parameters \"width\" and \"height\" must be positive";
72 throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
73 }
74
75 width_ = static_cast<unsigned int>(w);
76 height_ = static_cast<unsigned int>(h);
77 LOG(WARNING) << "Initial display size: " << width_ << "x" << height_;
78
79 enableOpenGl_ = parameters["opengl"].as<bool>();
80 if (enableOpenGl_)
81 {
82 LOG(WARNING) << "OpenGL is enabled, disable it with option \"--opengl=off\" if the application crashes";
83 }
84 else
85 {
86 LOG(WARNING) << "OpenGL is disabled, enable it with option \"--opengl=on\" for best performance";
87 }
88
89 }
90
91 void SdlStoneApplicationRunner::Run(NativeStoneApplicationContext& context, const std::string& title, int argc, char* argv[])
92 {
93 /**************************************************************
94 * Run the application inside a SDL window
95 **************************************************************/
96
97 LOG(WARNING) << "Starting the application";
98
99 SdlWindow window(title.c_str(), width_, height_, enableOpenGl_);
100 SdlEngine sdl(window, context);
101
102 {
103 NativeStoneApplicationContext::GlobalMutexLocker locker(context);
104 context.GetCentralViewport().Register(sdl); // (*)
105 }
106
107 context.Start();
108 sdl.Run();
109
110 LOG(WARNING) << "Stopping the application";
111
112 // Don't move the "Stop()" command below out of the block,
113 // otherwise the application might crash, because the
114 // "SdlEngine" is an observer of the viewport (*) and the
115 // update thread started by "context.Start()" would call a
116 // destructed object (the "SdlEngine" is deleted with the
117 // lexical scope).
118 context.Stop();
119 }
120
121 void SdlStoneApplicationRunner::Finalize()
122 {
123 SdlWindow::GlobalFinalize();
124 }
125
126
127 }