forked from tmj-fstate/maszyna
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathdrivermode.h
115 lines (102 loc) · 3.38 KB
/
drivermode.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
/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "applicationmode.h"
#include "driverkeyboardinput.h"
#include "drivermouseinput.h"
#include "gamepadinput.h"
#include "Console.h"
#include "Camera.h"
#include "Classes.h"
#ifdef WITH_UART
#include "uart.h"
#endif
class driver_mode : public application_mode {
public:
// constructors
driver_mode();
// methods
// initializes internal data structures of the mode. returns: true on success, false otherwise
bool
init() override;
// mode-specific update of simulation data. returns: false on error, true otherwise
bool
update() override;
// maintenance method, called when the mode is activated
void
enter() override;
// maintenance method, called when the mode is deactivated
void
exit() override;
// input handlers
void
on_key( int const Key, int const Scancode, int const Action, int const Mods ) override;
void
on_cursor_pos( double const Horizontal, double const Vertical ) override;
void
on_mouse_button( int const Button, int const Action, int const Mods ) override;
void
on_scroll( double const Xoffset, double const Yoffset ) override;
void
on_event_poll() override;
private:
// types
enum view {
consistfront,
consistrear,
bogie,
driveby,
count_
};
struct view_config {
TDynamicObject const *owner { nullptr };
Math3D::vector3 offset {};
Math3D::vector3 angle {};
};
struct drivermode_input {
gamepad_input gamepad;
drivermouse_input mouse;
glm::dvec2 mouse_pickmodepos; // stores last mouse position in control picking mode
driverkeyboard_input keyboard;
#ifdef _WIN32
Console console;
#endif
#ifdef WITH_UART
std::unique_ptr<uart_input> uart;
#endif
std::unique_ptr<motiontelemetry> telemetry;
bool init();
void poll();
};
// methods
void update_camera( const double Deltatime );
// handles vehicle change flag
void OnKeyDown( int cKey );
void ChangeDynamic();
void InOutKey();
void CabView();
void ExternalView();
void DistantView( bool const Near = false );
void set_picking( bool const Picking );
// members
drivermode_input m_input;
std::array<basic_event *, 10> KeyEvents { nullptr }; // eventy wyzwalane z klawiaury
TCamera Camera;
TCamera DebugCamera;
int m_externalviewmode { view::consistfront }; // selected external view mode
bool m_externalview { false };
std::array<view_config, view::count_> m_externalviewconfigs;
TDynamicObject *pDynamicNearest { nullptr }; // vehicle nearest to the active camera. TODO: move to camera
double fTime50Hz { 0.0 }; // bufor czasu dla komunikacji z PoKeys
double const m_primaryupdaterate { 1.0 / 100.0 };
double const m_secondaryupdaterate { 1.0 / 50.0 };
double m_primaryupdateaccumulator { m_secondaryupdaterate }; // keeps track of elapsed simulation time, for core fixed step routines
double m_secondaryupdateaccumulator { m_secondaryupdaterate }; // keeps track of elapsed simulation time, for less important fixed step routines
int iPause { 0 }; // wykrywanie zmian w zapauzowaniu
};