mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 18:47:06 +01:00
fbb9dc1e89
end and side were unscoped enums: front, rear, left and right sat in the
global namespace (the test PCH had to leave mover.h out for it), and an end
went into any int, a side into an end, without a word from the compiler. They
become enum class VehicleEnd and VehicleSide (physics/vehicletypes.h); the
names follow the rule for types, and leave "end" and "side" to the many
locals of that name. The numbers stay: front 0, rear 1, right 0, left 1.
- ByEnd<T> / BySide<T>: two values indexed by the enum, and by a number
where a loop or a format counts them. The arrays of the ends and the sides
are these now: Couplers, Neighbours, Pantographs, MotorBlowers, Lights,
iLights, Doors.instances, pVehicles, IsAnyDoor*, m_lighthints, vCoulpler,
m_couplersounds, m_mirrormotion, iInventory, and the voltages of the
couplers
- VehicleEnds / VehicleSides to go through them, Opposite() in place of
1 - end, NumberOf() where a number is needed
- the couplers and the collisions take the ends they work on as VehicleEnd:
CouplerForce, CouplerVelocityDifference, CollisionDetect, crush_hit,
CompatibleCoupling and the rest of their family, DirF, DirPatch, and of
the vehicle couple, uncouple, the adapters, off_track_gap, has_signal_on;
Attach, Dettach and DettachStatus have overloads by the ends
- neighbour_data::FacingEnd() and TCoupling::ConnectedEnd() give the end of
the other vehicle as VehicleEnd; the fields stay numbers, as they hold -1
and 2 for "none" in places
The walks along the consist (FirstFind, Neighbour, the AI's coupling and
uncoupling) still carry the ends as numbers; where one of them meets a typed
end, NumberOf() and EndOf() say so, and keep the number as it was.
Kept as it was, and worth a look: TDynamicObject::SetLights() switches the
headlights A/B off by CabActive with the cases end::front and end::rear, that
is CabActive 0 and 1, while CabActive is 1 or -1 for the cabs; the cases are
NumberOf(VehicleEnd::front / rear) now, the same numbers.
No change in behaviour: 1144/1144 tests, golden traces exact against staging
62f7a29b. betterRenderer/, not built, has had only end:: and side:: renamed.
76 lines
3.9 KiB
C++
76 lines
3.9 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 <vector>
|
|
#include "physics/vehicletypes.h"
|
|
|
|
#include "vehicle/cameraviews.h"
|
|
|
|
class TCamera;
|
|
class TDynamicObject;
|
|
|
|
// The outside views of the user's train that go with one of its vehicles (eu07/maszyna#551), after the four views
|
|
// [Shift]+[F4] had before: the orbit around a vehicle, the shunting view from above, the view beside a coupling
|
|
// and the trackside view of a railfan. [ and ] pick the vehicle (the coupling) the view goes with. The camera
|
|
// follows from cameraviews.h; this class hands over the vehicles of the train and keeps what the user set.
|
|
class consist_views {
|
|
|
|
public:
|
|
enum class kind { orbit, shunting, coupling, trackside };
|
|
|
|
// starts the View of the train of the Driven vehicle, with the vehicle (or the coupling) picked before when it's
|
|
// still in the train; returns the vehicle the camera goes with, nullptr when there's no train
|
|
TDynamicObject *enter(kind View, TDynamicObject *Driven);
|
|
// picks the vehicle Step places towards the rear of the train (towards its front for a negative Step); the
|
|
// coupling in the coupling view
|
|
void select(int Step);
|
|
// places the Camera for this frame of Seconds (real time): the movement keys come from its Velocity, the mouse of
|
|
// the orbit from its Angle. returns the vehicle the camera goes with, nullptr when the train is gone
|
|
TDynamicObject *update(TCamera &Camera, TDynamicObject *Driven, double Seconds);
|
|
|
|
private:
|
|
struct coupling_place {
|
|
TDynamicObject *vehicle{nullptr}; // the vehicle the coupler is on
|
|
cameraviews::coupler coupler;
|
|
bool other{false};
|
|
glm::dvec3 otherposition{}; // the facing coupler of the vehicle beyond, coupled or coming closer
|
|
double gap{-1.0}; // at an end of the train: the distance to a vehicle coming closer, negative for none
|
|
};
|
|
|
|
// the vehicles of the train of the Driven vehicle, from its front to its rear
|
|
static std::vector<TDynamicObject *> train_of(TDynamicObject *Driven);
|
|
// the vehicle the camera goes with in the Train: the one picked before, or the Driven one
|
|
TDynamicObject *pick(std::vector<TDynamicObject *> const &Train, TDynamicObject *Driven);
|
|
// the Index coupling of the Train, 0 its front end, Train.size() its rear end
|
|
static coupling_place coupling_at(std::vector<TDynamicObject *> const &Train, int Index);
|
|
// the distance to a vehicle not coupled beyond the End of the Vehicle, negative for none
|
|
static double gap_beyond(TDynamicObject const *Vehicle, VehicleEnd End);
|
|
// keeps up the way the train goes and works out where its ends are, for the trackside view
|
|
cameraviews::train_motion motion_of(std::vector<TDynamicObject *> const &Train, TDynamicObject const *Driven);
|
|
|
|
cameraviews::placement place_orbit(TCamera &Camera, double Seconds);
|
|
cameraviews::placement place_shunting(TCamera const &Camera, std::vector<TDynamicObject *> const &Train, TDynamicObject const *Driven, double Seconds);
|
|
cameraviews::placement place_coupling(TCamera const &Camera, std::vector<TDynamicObject *> const &Train, double Seconds);
|
|
cameraviews::placement place_trackside(std::vector<TDynamicObject *> const &Train, TDynamicObject const *Driven);
|
|
|
|
kind m_view{kind::orbit};
|
|
TDynamicObject *m_vehicle{nullptr}; // the vehicle picked; only compared with the vehicles of the train, never followed
|
|
int m_step{0}; // vehicles to step over in the next update, from [ and ]
|
|
int m_coupling{-1}; // the coupling picked in the coupling view, -1 not yet
|
|
cameraviews::orbit m_orbit;
|
|
cameraviews::topdown m_topdown;
|
|
cameraviews::coupler_view m_coupler;
|
|
cameraviews::trackside m_trackside;
|
|
glm::dvec3 m_lastposition{}; // of the vehicle picked, where the trackside view last saw it move
|
|
glm::dvec3 m_direction{0.0, 0.0, -1.0}; // the way the train goes, for the trackside view
|
|
bool m_moved{false}; // m_lastposition is known
|
|
};
|