SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
AppCommon.h
Go to the documentation of this file.
1 /**
2  * \file AppCommon.h
3  * \brief The AppCommon class holds the top-level instances of the app-demo
4  * \details For more info on how to create a new app with SLProject see:
5  * https://github.com/cpvrlab/SLProject4/wiki/Creating-a-New-App
6  * For more info about App framework see:
7  * https://cpvrlab.github.io/SLProject4/app-framework.html
8  * \date February 2018
9  * \authors Marcus Hudritsch
10  * \copyright http://opensource.org/licenses/GPL-3.0
11  * \remarks Please use clangformat to format the code. See more code style on
12  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
13  */
14 
15 #ifndef SLAPPCOMMON_H
16 #define SLAPPCOMMON_H
17 
18 #include <atomic>
19 #include <mutex>
20 #include <map>
21 #include <optional>
22 
23 #include <CVTypes.h>
24 #include <SLDeviceLocation.h>
25 #include <SLDeviceRotation.h>
26 #include <SLInputManager.h>
27 #include <SLSceneView.h>
28 #include <SLEnums.h>
29 #include <SLFileStorage.h>
30 
31 class SLScene;
32 class SLAssetLoader;
33 class SLImGui;
35 class SLUiInterface;
36 
37 using std::optional;
38 
39 //-----------------------------------------------------------------------------
40 //! Top level class for the major global instances off an SLProject app.
41 /*!
42  The AppCommon holds static instances of top-level items such as the asset
43  manager, the scene pointer, the vector of all sceneviews, the gui pointer,
44  the camera calibration objects and the device rotation and location
45  information.<br>
46  The static function createApp is called by the C-interface functions
47  slCreateApp and the function deleteApp by slTerminate. At the moment only
48  one scene can be open at the time.
49  <br>
50  AppCommon holds two static video camera calibrations, one for a main camera
51  (mainCam) and one for the selfie camera on mobile devices (scndCam).
52  The pointer activeCamera points to the active one.
53 */
54 class AppCommon
55 {
56 public:
57  // Major owned instances of the app
58  static SLInputManager inputManager; //!< Input events manager
59  static SLAssetManager* assetManager; //!< asset manager is the owner of all assets
60  static SLAssetLoader* assetLoader; //!< Asset-loader for async asset loading
61  static SLScene* scene; //!< Pointer to the one and only SLScene instance
62  static SLVSceneView sceneViews; //!< Vector of sceneview pointers
63  static SLUiInterface* gui; //!< Pointer to the GUI
64  static SLDeviceRotation devRot; //!< Mobile device rotation from IMU
65  static SLDeviceLocation devLoc; //!< Mobile device location from GPS
66 
67  static void createApp(SLstring appName);
68  static void registerCoreAssetsLoad();
70  static void deleteApp();
71 
72  static SLstring name; //!< Application name
73  static SLstring appTag; //!< Tag string used in logging
74  static SLstring version; //!< SLProject version string
75  static SLstring asciiLabel; //!< SLProject ascii label string
76  static SLstring configuration; //!< Debug or Release configuration
77  static SLstring gitBranch; //!< Current GIT branch
78  static SLstring gitCommit; //!< Current GIT commit short hash id
79  static SLstring gitDate; //!< Current GIT commit date
80  static SLstring exePath; //!< executable root path
81  static SLstring configPath; //!< Default path for calibration files
82  static SLstring externalPath; //!< Default path for external file storage
83  static SLstring dataPath; //!< Path to data directory (it is set platform dependent)
84  static SLstring shaderPath; //!< Path to GLSL shader programs
85  static SLstring modelPath; //!< Path to 3D models
86  static SLstring texturePath; //!< Path to texture images
87  static SLstring fontPath; //!< Path to font images
88  static SLstring videoPath; //!< Path to video files
89  static SLSceneID sceneID; //!< ID of currently loaded scene
90  static optional<SLSceneID> sceneToLoad; //!< Scene id to load at start up
91 
92  // static methods for parallel job processing
93  static void handleParallelJob();
94  static void jobProgressMsg(string msg);
95  static void jobProgressNum(int num) { _jobProgressNum = num; }
96  static void jobProgressMax(int max) { _jobProgressMax = max; }
97  static string jobProgressMsg();
98  static int jobProgressNum() { return _jobProgressNum; }
99  static int jobProgressMax() { return _jobProgressMax; }
100 
101  static map<string, string> deviceParameter; //!< Generic device parameter
102  static deque<function<void(void)>> jobsToBeThreaded; //!< Queue of functions to be executed in a thread
103  static deque<function<void(void)>> jobsToFollowInMain; //!< Queue of function to follow in the main thread
104  static atomic<bool> jobIsRunning; //!< True if a parallel job is running
105 
108  static SLstring calibIniPath; //!< That's where data/calibrations folder is located
109  static SLstring calibFilePath; //!< That's where calibrations are stored and loaded from
110 
113 
114  static const string CALIB_FTP_HOST; //!< ftp host for calibration up and download
115  static const string CALIB_FTP_USER; //!< ftp login user for calibration up and download
116  static const string CALIB_FTP_PWD; //!< ftp login pwd for calibration up and download
117  static const string CALIB_FTP_DIR; //!< ftp directory for calibration up and download
118  static const string PROFILE_FTP_DIR; //!< ftp directory for profiles upload
119 
120 private:
121  static void onDoneLoading(SLSceneView* sv, SLScene* s, SLfloat startLoadMS);
122  static void onDoneAssembling(SLSceneView* sv, SLScene* s, SLfloat startLoadMS);
123 
124  static string _jobProgressMsg; //!< Text message to show during progress
125  static atomic<int> _jobProgressNum; //!< Integer value to show progress
126  static atomic<int> _jobProgressMax; //!< Max. integer progress value
127  static mutex _jobMutex; //!< Mutex to protect parallel access
128 };
129 //-----------------------------------------------------------------------------
130 #endif
float SLfloat
Definition: SL.h:173
string SLstring
Definition: SL.h:158
Mobile device location class declaration.
Mobile device rotation class declaration.
int SLSceneID
Scene identifier.
Definition: SLEnums.h:91
typedef void(SL_STDCALL *cbOnImGuiBuild)(SLScene *s
Callback function typedef for ImGui build function.
SLScene SLSceneView SLint sceneID
Definition: SLScene.h:33
vector< SLSceneView * > SLVSceneView
Definition: SLSceneView.h:300
Top level class for the major global instances off an SLProject app.
Definition: AppCommon.h:55
static void handleParallelJob()
Starts parallel job if one is queued.
Definition: AppCommon.cpp:359
static SLstring asciiLabel
SLProject ascii label string.
Definition: AppCommon.h:75
static const string CALIB_FTP_HOST
ftp host for calibration up and download
Definition: AppCommon.h:114
static CVCalibrationEstimator * calibrationEstimator
Definition: AppCommon.h:107
static SLstring version
SLProject version string.
Definition: AppCommon.h:74
static SLDeviceRotation devRot
Mobile device rotation from IMU.
Definition: AppCommon.h:64
static int jobProgressMax()
Definition: AppCommon.h:99
static SLstring name
Application name.
Definition: AppCommon.h:72
static void registerCoreAssetsLoad()
Definition: AppCommon.cpp:143
static SLIOBuffer fontDataProp
Definition: AppCommon.h:111
static const string CALIB_FTP_USER
ftp login user for calibration up and download
Definition: AppCommon.h:115
static SLstring fontPath
Path to font images.
Definition: AppCommon.h:87
static atomic< int > _jobProgressMax
Max. integer progress value.
Definition: AppCommon.h:126
static deque< function< void(void)> > jobsToBeThreaded
Queue of functions to be executed in a thread.
Definition: AppCommon.h:102
static const string CALIB_FTP_DIR
ftp directory for calibration up and download
Definition: AppCommon.h:117
static SLstring configPath
Default path for calibration files.
Definition: AppCommon.h:81
static SLstring calibIniPath
That's where data/calibrations folder is located.
Definition: AppCommon.h:108
static optional< SLSceneID > sceneToLoad
Scene id to load at start up.
Definition: AppCommon.h:90
static string jobProgressMsg()
Thread-safe getter of the progress message.
Definition: AppCommon.cpp:392
static string _jobProgressMsg
Text message to show during progress.
Definition: AppCommon.h:124
static SLAssetManager * assetManager
asset manager is the owner of all assets
Definition: AppCommon.h:59
static SLstring exePath
executable root path
Definition: AppCommon.h:80
static const string CALIB_FTP_PWD
ftp login pwd for calibration up and download
Definition: AppCommon.h:116
static SLstring gitCommit
Current GIT commit short hash id.
Definition: AppCommon.h:78
static atomic< bool > jobIsRunning
True if a parallel job is running.
Definition: AppCommon.h:104
static SLDeviceLocation devLoc
Mobile device location from GPS.
Definition: AppCommon.h:65
static SLUiInterface * gui
Pointer to the GUI.
Definition: AppCommon.h:63
static const string PROFILE_FTP_DIR
ftp directory for profiles upload
Definition: AppCommon.h:118
static SLstring modelPath
Path to 3D models.
Definition: AppCommon.h:85
static SLstring gitBranch
Current GIT branch.
Definition: AppCommon.h:77
static int jobProgressNum()
Definition: AppCommon.h:98
static atomic< int > _jobProgressNum
Integer value to show progress.
Definition: AppCommon.h:125
static SLVSceneView sceneViews
Vector of sceneview pointers.
Definition: AppCommon.h:62
static SLIOBuffer fontDataFixed
Definition: AppCommon.h:112
static SLstring texturePath
Path to texture images.
Definition: AppCommon.h:86
static deque< function< void(void)> > jobsToFollowInMain
Queue of function to follow in the main thread.
Definition: AppCommon.h:103
static void onDoneLoading(SLSceneView *sv, SLScene *s, SLfloat startLoadMS)
Definition: AppCommon.cpp:248
static void switchScene(SLSceneView *sv, SLSceneID sceneID)
Definition: AppCommon.cpp:175
static CVCalibrationEstimatorParams calibrationEstimatorParams
Definition: AppCommon.h:106
static SLstring videoPath
Path to video files.
Definition: AppCommon.h:88
static SLstring gitDate
Current GIT commit date.
Definition: AppCommon.h:79
static SLstring configuration
Debug or Release configuration.
Definition: AppCommon.h:76
static void jobProgressMax(int max)
Definition: AppCommon.h:96
static void createApp(SLstring appName)
Application creation function.
Definition: AppCommon.cpp:111
static SLstring shaderPath
Path to GLSL shader programs.
Definition: AppCommon.h:84
static SLAssetLoader * assetLoader
Asset-loader for async asset loading.
Definition: AppCommon.h:60
static SLInputManager inputManager
Input events manager.
Definition: AppCommon.h:58
static void onDoneAssembling(SLSceneView *sv, SLScene *s, SLfloat startLoadMS)
Definition: AppCommon.cpp:267
static mutex _jobMutex
Mutex to protect parallel access.
Definition: AppCommon.h:127
static SLstring appTag
Tag string used in logging.
Definition: AppCommon.h:73
static SLstring externalPath
Default path for external file storage.
Definition: AppCommon.h:82
static SLSceneID sceneID
ID of currently loaded scene.
Definition: AppCommon.h:89
static void jobProgressNum(int num)
Definition: AppCommon.h:95
static SLScene * scene
Pointer to the one and only SLScene instance.
Definition: AppCommon.h:61
static map< string, string > deviceParameter
Generic device parameter.
Definition: AppCommon.h:101
static SLstring calibFilePath
That's where calibrations are stored and loaded from.
Definition: AppCommon.h:109
static SLstring dataPath
Path to data directory (it is set platform dependent)
Definition: AppCommon.h:83
static void deleteApp()
Calls the destructor of the single scene instance.
Definition: AppCommon.cpp:298
Toplevel holder of the assets meshes, materials, textures and shaders.
Encapsulation of a mobile device location set by the device's GPS sensor.
Encapsulation of a mobile device rotation set by the device's IMU sensor.
ImGui Interface class for forwarding all events to the original ImGui Handlers.
Definition: SLImGui.h:62
SLInputManager. manages system input and custom input devices.
The SLScene class represents the top level instance holding the scene structure.
Definition: SLScene.h:47
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
Interface for ui integration in SLSceneView.
Definition: SLUiInterface.h:24
Utility struct that holds a pointer and its length.
Definition: SLFileStorage.h:28