RigsofRods
Soft-body Physics Simulation
AppContext.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2020 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
26 
27 #pragma once
28 
29 #include "Application.h"
30 #include "ForceFeedback.h"
31 
32 #include <Bites/OgreWindowEventUtilities.h>
33 #include <Ogre.h>
34 #include <OIS.h>
35 
36 namespace RoR {
37 
40 
43 class AppContext: public OgreBites::WindowEventListener,
44  public OIS::MouseListener,
45  public OIS::KeyListener,
46  public OIS::JoyStickListener
47 {
48 public:
49  // Startup (in order)
50  void SetUpThreads();
51  bool SetUpProgramPaths();
52  void SetUpLogging();
53  bool SetUpResourcesDir();
54  bool SetUpRendering();
55  bool SetUpConfigSkeleton();
56  bool SetUpInput();
58 
59  // Rendering
60  Ogre::RenderWindow* CreateCustomRenderWindow(std::string const& name, int width, int height);
61  void CaptureScreenshot();
62  void ActivateFullscreen(bool val);
63 
64  // Getters
65  Ogre::Root* GetOgreRoot() { return m_ogre_root; }
66  Ogre::Viewport* GetViewport() { return m_viewport; }
67  Ogre::RenderWindow* GetRenderWindow() { return m_render_window; }
69  std::thread::id GetMainThreadID() { return m_mainthread_id; }
70 
71 private:
72  // OgreBites::WindowEventListener
73  virtual void windowResized(Ogre::RenderWindow* rw) override;
74  virtual void windowFocusChange(Ogre::RenderWindow* rw) override;
75 
76  // OIS::MouseListener
77  virtual bool mouseMoved(const OIS::MouseEvent& arg) override;
78  virtual bool mousePressed(const OIS::MouseEvent& arg, OIS::MouseButtonID id) override;
79  virtual bool mouseReleased(const OIS::MouseEvent& arg, OIS::MouseButtonID id) override;
80 
81  // OIS::KeyListener
82  virtual bool keyPressed(const OIS::KeyEvent& arg) override;
83  virtual bool keyReleased(const OIS::KeyEvent& arg) override;
84 
85  // OIS::JoyStickListener
86  virtual bool buttonPressed(const OIS::JoyStickEvent& arg, int button) override;
87  virtual bool buttonReleased(const OIS::JoyStickEvent& arg, int button) override;
88  virtual bool axisMoved(const OIS::JoyStickEvent& arg, int axis) override;
89  virtual bool sliderMoved(const OIS::JoyStickEvent& arg, int) override;
90  virtual bool povMoved(const OIS::JoyStickEvent& arg, int) override;
91 
92  // Rendering and window management
93  void SetRenderWindowIcon(Ogre::RenderWindow* rw);
94 
95  // Variables
96 
97  Ogre::Root* m_ogre_root = nullptr;
98  Ogre::RenderWindow* m_render_window = nullptr;
99  Ogre::Viewport* m_viewport = nullptr;
100  bool m_windowed_fix = false;
101 
104 
106 
107  std::thread::id m_mainthread_id;
108 };
109 
111 
112 } // namespace RoR
RoR::AppContext::SetUpProgramPaths
bool SetUpProgramPaths()
Definition: AppContext.cpp:456
RoR::AppContext::mousePressed
virtual bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id) override
Definition: AppContext.cpp:96
RoR::AppContext::m_viewport
Ogre::Viewport * m_viewport
Definition: AppContext.h:99
RoR::AppContext::m_windowed_fix
bool m_windowed_fix
Workaround OGRE glitch when switching from fullscreen.
Definition: AppContext.h:100
RoR::AppContext::CreateCustomRenderWindow
Ogre::RenderWindow * CreateCustomRenderWindow(std::string const &name, int width, int height)
Definition: AppContext.cpp:381
RoR::AppContext::mouseReleased
virtual bool mouseReleased(const OIS::MouseEvent &arg, OIS::MouseButtonID id) override
Definition: AppContext.cpp:117
ForceFeedback.h
RoR::AppContext::m_prev_screenshot_index
int m_prev_screenshot_index
Definition: AppContext.h:103
RoR::AppContext::keyPressed
virtual bool keyPressed(const OIS::KeyEvent &arg) override
Definition: AppContext.cpp:137
RoR::AppContext::GetRenderWindow
Ogre::RenderWindow * GetRenderWindow()
Definition: AppContext.h:67
RoR::AppContext::SetUpRendering
bool SetUpRendering()
Definition: AppContext.cpp:219
RoR::AppContext::GetMainThreadID
std::thread::id GetMainThreadID()
Definition: AppContext.h:69
RoR::AppContext::buttonReleased
virtual bool buttonReleased(const OIS::JoyStickEvent &arg, int button) override
Definition: AppContext.cpp:169
RoR::AppContext::GetViewport
Ogre::Viewport * GetViewport()
Definition: AppContext.h:66
RoR::AppContext::SetUpResourcesDir
bool SetUpResourcesDir()
Definition: AppContext.cpp:520
RoR::AppContext::SetUpConfigSkeleton
bool SetUpConfigSkeleton()
Definition: AppContext.cpp:538
RoR::AppContext::GetForceFeedback
RoR::ForceFeedback & GetForceFeedback()
Definition: AppContext.h:68
RoR::AppContext::buttonPressed
virtual bool buttonPressed(const OIS::JoyStickEvent &arg, int button) override
Definition: AppContext.cpp:168
RoR::AppContext::m_render_window
Ogre::RenderWindow * m_render_window
Definition: AppContext.h:98
RoR::AppContext
Central setup and event handler for input/windowing/rendering.
Definition: AppContext.h:43
RoR::AppContext::keyReleased
virtual bool keyReleased(const OIS::KeyEvent &arg) override
Definition: AppContext.cpp:150
RoR::AppContext::mouseMoved
virtual bool mouseMoved(const OIS::MouseEvent &arg) override
Definition: AppContext.cpp:76
RoR::AppContext::SetRenderWindowIcon
void SetRenderWindowIcon(Ogre::RenderWindow *rw)
Definition: AppContext.cpp:200
RoR::AppContext::m_mainthread_id
std::thread::id m_mainthread_id
Definition: AppContext.h:107
RoR::AppContext::m_prev_screenshot_time
std::time_t m_prev_screenshot_time
Definition: AppContext.h:102
Application.h
Central state/object manager and communications hub.
RoR::AppContext::axisMoved
virtual bool axisMoved(const OIS::JoyStickEvent &arg, int axis) override
Definition: AppContext.cpp:170
RoR::AppContext::CaptureScreenshot
void CaptureScreenshot()
Definition: AppContext.cpp:391
RoR::AppContext::SetUpLogging
void SetUpLogging()
Definition: AppContext.cpp:504
RoR::AppContext::SetUpThreads
void SetUpThreads()
Definition: AppContext.cpp:614
RoR::AppContext::ActivateFullscreen
void ActivateFullscreen(bool val)
Definition: AppContext.cpp:438
RoR::AppContext::SetUpObsoleteConfMarker
void SetUpObsoleteConfMarker()
Definition: AppContext.cpp:582
RoR::AppContext::povMoved
virtual bool povMoved(const OIS::JoyStickEvent &arg, int) override
Definition: AppContext.cpp:172
RoR::AppContext::m_ogre_root
Ogre::Root * m_ogre_root
Definition: AppContext.h:97
RoR::AppContext::windowFocusChange
virtual void windowFocusChange(Ogre::RenderWindow *rw) override
Definition: AppContext.cpp:187
RoR::AppContext::GetOgreRoot
Ogre::Root * GetOgreRoot()
Definition: AppContext.h:65
RoR::AppContext::windowResized
virtual void windowResized(Ogre::RenderWindow *rw) override
Definition: AppContext.cpp:174
RoR::AppContext::m_force_feedback
RoR::ForceFeedback m_force_feedback
Definition: AppContext.h:105
RoR::AppContext::SetUpInput
bool SetUpInput()
Definition: AppContext.cpp:62
RoR::AppContext::sliderMoved
virtual bool sliderMoved(const OIS::JoyStickEvent &arg, int) override
Definition: AppContext.cpp:171
RoR
Definition: AppContext.h:36
RoR::ForceFeedback
Definition: ForceFeedback.h:29