-
Notifications
You must be signed in to change notification settings - Fork 0
/
application_HT.h
executable file
·278 lines (225 loc) · 11.1 KB
/
application_HT.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
/*
* Delta3D Open Source Game and Simulation Engine
* Copyright (C) 2004-2005 MOVES Institute
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 2.1 of the License, or (at your option)
* any later version.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef HT_APPLICATION
#define HT_APPLICATION
#include "common.h"
#include <dtCore/refptr.h>
#include <dtABC/baseabc.h>
#include <dtABC/export.h>
#include <dtCore/generickeyboardlistener.h>
#include <dtCore/genericmouselistener.h>
#include <dtUtil/configproperties.h>
#include <string>
#include <map>
#include "HTAppBase.h"
///@cond
namespace osgViewer
{
class CompositeViewer;
class Viewer;
}
///@endcond
namespace dtCore
{
class Keyboard;
class Mouse;
class StatsHandler;
class DeltaWin;
}
namespace dtABC
{
struct ApplicationConfigData;
}
///Base generic Application class
/** The Application class of the dtCore Application Base Class library
* is the base level class for most applications. It contains the basic
* components required for applications.
* An optional XML configuration file can be supplied on the constructor which
* contains the attributes for the internal DeltaWin, Camera, and Scene.
* A default Config File can be created by calling GenerateDefaultConfigFile().
* This file will contain the default parameters and can be edited, then
* supplied to the constructor.
*
* Typical use:
* \code
* Application *app = new Application("Mydatafile.xml");
* app->Config();
* app->Run();
* \endcode
*/
class DT_ABC_EXPORT Application_HT : public HTAppBase, public dtUtil::ConfigProperties
{
DECLARE_MANAGEMENT_LAYER(Application_HT)
typedef HTAppBase BaseClass;
public:
/**
* Configuration property.
* <br>
* Sets the fixed simulated frame rate of the system. This only matters if a fixed time step
* is used.
* @see dtCore::System
*/
static const std::string SIM_FRAME_RATE;
/**
* Configuration property.
* <br>
* When using a fixed time step, it is possible that the time required to simulate could be
* so great that the system would never have time to draw a frame. This time is used an as
* override so that it be guaranteed to at least draw a frame every so often. This time is a
* floating point number in seconds.
* @see dtCore::System
*/
static const std::string MAX_TIME_BETWEEN_DRAWS;
/**
* Configuration property.
* <br>
* Set to true or false.
* <br>
* This value defaults to false, which will make the delta time be equivalent to the time since the
* beginning of the last frame times the current time scale. If this is set to true, the delta
* time will be a fixed value multiplied times the time scale. This helps make things like motion models
* physics, and other time-based calculations deterministic. They also won't suffer from
* anomalies that occur with frame hiccups.
* @see dtCore::System
*/
static const std::string USE_FIXED_TIME_STEP;
//Application(const std::string& configFilename = "", dtCore::DeltaWin* win = NULL);
Application_HT( const std::string& configFilename,
const std::string& hostName, int port, bool wait_for_client, const std::string& scenarioFilename, int id, std::string& replayFile, std::string& configFile, dtCore::DeltaWin* win = NULL);
///Start the Application
virtual void Run();
//overridden the load config properties into settings.
virtual void Config();
/// Generate a default configuration file.
/// This method writes out all the default attributes from the internal Application
/// members and writes them out to a .xml file ("config.xml").
/// @param the file path to be used when writing.
/// @return the file path to the newly created file, as seen by the delta3d resource management tool,
/// unless the file already exists, then the path to the existing file is returned.
static std::string GenerateDefaultConfigFile(const std::string& filename="config.xml");
/// Called when a key is pressed.
/// @param keyboard the source of the event
/// @param key the key pressed
virtual bool KeyPressed(const dtCore::Keyboard* keyboard, int kc);
/// Called when a key is released.
/// @param keyboard the source of the event
/// @param key the key released
virtual bool KeyReleased(const dtCore::Keyboard* keyboard, int kc);
/// @return the instance of the keyboard listener used for callbacks
const dtCore::GenericKeyboardListener* GetKeyboardListener() const { return mKeyboardListener.get(); }
/// @return the instance of the keyboard listener used for callbacks
dtCore::GenericKeyboardListener* GetKeyboardListener() { return mKeyboardListener.get(); }
/** Called when a mouse button is pressed. Overwrite for custom functionality.
* @param mouse Handle to the Mouse that triggered this
* @param button The button index
*/
virtual bool MouseButtonPressed(const dtCore::Mouse *mouse, dtCore::Mouse::MouseButton button);
/** Called when a mouse button is released. Overwrite for custom functionality.
* @param mouse Handle to the Mouse that triggered this
* @param button The button index
*/
virtual bool MouseButtonReleased(const dtCore::Mouse *mouse, dtCore::Mouse::MouseButton button);
/** Called when a mouse button has been "double-clicked". Overwrite for custom
* functionality.
* @param mouse Handle to the Mouse that triggered this
* @param button The button index
* @param clickCount : The number of times the button was clicked
*/
virtual bool MouseButtonDoubleClicked(const dtCore::Mouse *mouse, dtCore::Mouse::MouseButton button, int clickCount);
/** Called when a mouse is moved. Overwrite for custom functionality.
* @param mouse Handle to the Mouse that triggered this
* @param x The left-right distance the mouse traveled
* @param y The up-down distance the mouse traveled
*/
virtual bool MouseMoved(const dtCore::Mouse* mouse, float x, float y);
/** Called when a mouse is dragged (button down). Overwrite for custom functionality.
* @param mouse Handle to the Mouse that triggered this
* @param x The left-right distance the mouse traveled
* @param y The up-down distance the mouse traveled
*/
virtual bool MouseDragged(const dtCore::Mouse* mouse, float x, float y);
/** Called when a mouse scroll wheel moved. Overwrite for custom functionality.
* @param mouse Handle to the Mouse that triggered this
* @param delta The amount of wheel scrolled
*/
virtual bool MouseScrolled(const dtCore::Mouse* mouse, int delta);
/// @return the instance of the mouse listener used for callbacks
const dtCore::GenericMouseListener* GetMouseListener() const { return mMouseListener.get(); }
/// @return the instance of the mouse listener used for callbacks
dtCore::GenericMouseListener* GetMouseListener() { return mMouseListener.get(); }
/// the publicized default settings for a generated config file.
static dtABC::ApplicationConfigData GetDefaultConfigData();
/// @return a string value that is paired with the given name. The default is returned if the property is not set.
const std::string& GetConfigPropertyValue(const std::string& name, const std::string& defaultValue = "") const;
/// Sets the value of a given config property.
void SetConfigPropertyValue(const std::string& name, const std::string& value);
/// Removes a property with the given name
void RemoveConfigPropertyValue(const std::string& name);
/// Add a view to the Viewer
void AddView(dtCore::View &view);
/// Remove a view to the Viewer
void RemoveView(dtCore::View &view);
///Cycle through the statistics modes
void SetNextStatisticsType();
protected:
virtual ~Application_HT();
///override for preframe
virtual void PreFrame( const double deltaSimTime );
///override for frame
virtual void Frame( const double deltaSimTime );
///override for postframe
virtual void PostFrame( const double deltaSimTime );
///Create basic instances and set up system hooks
virtual void CreateInstances(const std::string& name="defaultWin", int x=100, int y=100, int width=640, int height=480, bool cursor=true, bool fullScreen=false );
/// Read the supplied config file, called from the constructor
/// Read an existing data file and setup the internal class
/// members with attributes from the data file.
/// @param file the name of the data file to be parsed.
/// @return true, if both parsing and applying went well.
bool ParseConfigFile(const std::string& file);
/// @return the instance of the osgViewer::CompositeViewer
const osgViewer::CompositeViewer* GetCompositeViewer() const { return mCompositeViewer.get(); }
/// @return the instance of the osgViewer::CompositeViewer
osgViewer::CompositeViewer* GetCompositeViewer() { return mCompositeViewer.get(); }
/**
* Forces the application to re-read the set of config properties it handles.
* This is virtual so a subclass can add new properties.
*/
virtual void ReadSystemProperties();
private:
/// A utility to apply the parsed data to the Application instance
class AppXMLApplicator
{
public:
/// the method to apply the data
/// @param data The data to be applied
/// @param app The application to apply the data to
/// @return true, if all went well.
bool operator ()(const dtABC::ApplicationConfigData& data, Application_HT* app);
};
dtCore::RefPtr<osgViewer::CompositeViewer> mCompositeViewer;
dtCore::RefPtr<dtCore::GenericKeyboardListener> mKeyboardListener;
dtCore::RefPtr<dtCore::GenericMouseListener> mMouseListener;
typedef std::map<std::string, std::string> AppConfigPropertyMap;
AppConfigPropertyMap mConfigProperties;
dtCore::StatsHandler *mStats; ///<for stats rendering/controlling
};
//}
#endif // HT_APPLICATION