mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-27 21:45:16 +01:00
[Shift]+[F4] goes on after the four views it had (front of the train, its rear, a bogie, drive-by) to four views that go with one vehicle of the train: - orbit: around the middle of the vehicle. Left/right arrows (and the mouse) turn the camera around it, up/down arrows bring it closer and further (from outside the body to 250 m), PgUp/PgDn (and the mouse) raise and lower it; it never goes below 0.5 m above the rails. It turns with the vehicle. - shunting: straight down from above the vehicle, the way the user drives up the screen, going with it. Arrows move it along and across the train, PgUp/PgDn up and down (from above the roof to 300 m). - coupling: low beside a coupler, looking at it. At an end of the train with another vehicle (not coupled) closer than 150 m, it starts at that end and steps back from the track as the gap grows, looking between the two couplers. Left/right arrows pick the side of the track, up/down the distance, PgUp/PgDn the height. - trackside: a railfan beside the line ahead of the train, looking at the vehicle picked as the train comes and goes by. Once its tail is 40 m past (or the train is 1 km away) the railfan walks to a new spot ahead, 15 s of the train's run away (80-500 m, along the curve of the line), on the other side of the track. [ and ] pick the vehicle the view goes with (the coupling, in the coupling view), towards the front and the rear of the train; the view starts with the vehicle the user drives. [ and ] are bound to nothing by default nor in the shipped eu07_input-keyboard.ini; [Ctrl]+[ / ] stay the debug train moves. The camera follows from pure functions in vehicle/cameraviews.cpp (eu07_core), tested in tests/unit/test_camera_views.cpp; application/consistviews.cpp hands them the vehicles of the train and keeps what the user set. The four older views and their order don't change. "consistviews no" in eu07.ini keeps the cycle of [Shift]+[F4] to the four older views. The black box writes the new views as 4-7 (blackbox_doc.md).
132 lines
4.4 KiB
C++
132 lines
4.4 KiB
C++
/*
|
|
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 "application/applicationmode.h"
|
|
|
|
#include "input/driverkeyboardinput.h"
|
|
#include "input/drivermouseinput.h"
|
|
#include "input/gamepadinput.h"
|
|
#include "Console.h"
|
|
#include "vehicle/Camera.h"
|
|
#include "application/consistviews.h"
|
|
#include "utilities/Classes.h"
|
|
#ifdef WITH_UART
|
|
#include "utilities/uart.h"
|
|
#endif
|
|
#ifdef WITH_ZMQ
|
|
#include "input/zmq_input.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 Key, int Scancode, int Action, int Mods ) override;
|
|
void on_cursor_pos( double Horizontal, double Vertical ) override;
|
|
void on_mouse_button( int Button, int Action, int Mods ) override;
|
|
void on_scroll( double Xoffset, double Yoffset ) override;
|
|
void on_window_resize( int w, int h ) override { ; }
|
|
void on_event_poll() override;
|
|
bool is_command_processor() const override;
|
|
|
|
private:
|
|
// types
|
|
enum view {
|
|
consistfront,
|
|
consistrear,
|
|
bogie,
|
|
driveby,
|
|
// the views of consist_views (eu07/maszyna#551), left out of the cycle with consistviews off in eu07.ini
|
|
orbit,
|
|
shunting,
|
|
coupling,
|
|
trackside,
|
|
count_
|
|
};
|
|
|
|
struct view_config {
|
|
TDynamicObject const *owner { nullptr };
|
|
glm::vec3 offset {};
|
|
glm::vec3 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
|
|
#ifdef WITH_ZMQ
|
|
std::unique_ptr<zmq_input> zmq;
|
|
#endif
|
|
std::unique_ptr<motiontelemetry> telemetry;
|
|
|
|
bool init();
|
|
void poll();
|
|
std::string
|
|
binding_hints( std::pair<user_command, user_command> const &Commands ) const;
|
|
std::pair<user_command, user_command>
|
|
command_fallback( user_command const Command ) const;
|
|
};
|
|
|
|
// methods
|
|
void update_camera( const double Deltatime );
|
|
// handles vehicle change flag
|
|
void OnKeyDown( int cKey );
|
|
void InOutKey();
|
|
void CabView();
|
|
void ExternalView();
|
|
void DistantView( bool const Near = false );
|
|
// whether the camera shows one of the views of consist_views now
|
|
bool consist_view_active() const;
|
|
// places the camera of the view of consist_views for the frame
|
|
void update_consist_view( double const Deltatime );
|
|
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 { true };
|
|
std::array<view_config, view::count_> m_externalviewconfigs;
|
|
consist_views m_consistviews; // the orbit, shunting, coupling and trackside views
|
|
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
|
|
command_relay m_relay;
|
|
std::string change_train; // train name awaiting entering
|
|
bool m_editorpending { false }; // scenery was opened for editing, switch to the editor after the initial update
|
|
};
|