mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 23:17:56 +01:00
d0387753f8
The physics of a vehicle loses the name it had from the Pascal of 2001. Done by
tools/rename/mover_to_physics.py, committed with it:
physics/mover.h physics/vehicle.h
TMoverParameters physics::Vehicle (in namespace physics)
TDynamicObject::MoverParameters physics
mvOccupied, mvControlled occupied, controlled (TTrain, TController)
mvSecond, mvThird secondUnit, thirdUnit
mvPantographUnit pantographUnit
mover, Mover, movers physics, Physics, vehicles (locals, params)
m_mover, othermover, currentMover, from_movers, renderMoverEventSounds
m_physics, otherPhysics, currentPhysics,
from_vehicles, renderPhysicsEventSounds
The code and the comments are renamed, the string literals are not: no text
the game shows, logs or looks up has changed (none had the names). The movers
of the editor, the tracks a slide moves, keep their name.
By hand: two member functions of TDynamicObject (gather_off_track_terrain,
begin_off_track) had a local mover aliasing their own MoverParameters, which
the rename made physics { *physics }; the alias is gone, they use physics->.
No other function has a renamed local meeting a renamed member (checked over
all the functions of the code before the rename).
For the branches made before it: run the script on the branch (python
tools/rename/mover_to_physics.py, from the root of the repository) before
merging it with this one, and the names don't conflict. It can be run again;
the second time it changes nothing.
The class is the same as it was; breaking it into its parts (braking,
electrics, controls, load) and making its data private are the next stages.
No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
174 lines
4.8 KiB
C++
174 lines
4.8 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/.
|
|
*/
|
|
/*
|
|
MaSzyna EU07 locomotive simulator
|
|
Copyright (C) 2001-2004 Marcin Wozniak, Maciej Czapkiewicz and others
|
|
|
|
*/
|
|
|
|
// the screens of the cab
|
|
|
|
#include "stdafx.h"
|
|
#include "vehicle/Train.h"
|
|
#include "vehicle/horn.h"
|
|
#include "vehicle/linebreaker.h"
|
|
#include "vehicle/holdcoillever.h"
|
|
#include "vehicle/compartmentlightsswitch.h"
|
|
#include "vehicle/odometer.h"
|
|
#include "vehicle/mainctrlact.h"
|
|
#include "utilities/Globals.h"
|
|
#include "simulation/simulation.h"
|
|
#include "simulation/blackboxrecorder.h"
|
|
#include "world/Event.h"
|
|
#include "simulation/simulationtime.h"
|
|
#include "vehicle/Camera.h"
|
|
#include "utilities/Logs.h"
|
|
#include "model/MdlMngr.h"
|
|
#include "model/Model3d.h"
|
|
#include "utilities/Timer.h"
|
|
#include "vehicle/Driver.h"
|
|
#include "vehicle/DynObj.h"
|
|
#include "world/mtable.h"
|
|
#include "Console.h"
|
|
#include "application/application.h"
|
|
#include "rendering/renderer.h"
|
|
#include "physics/vehicle.h"
|
|
#include <future>
|
|
#include <thread>
|
|
#include <cmath>
|
|
#include <algorithm>
|
|
#include <format>
|
|
#include "vehicle/cab/internal.h"
|
|
|
|
|
|
void TTrain::update_screens(double dt)
|
|
{
|
|
for (auto &screen : m_screens)
|
|
{
|
|
if (screen.updatetimecounter >= 0)
|
|
screen.updatetimecounter += dt;
|
|
|
|
if (screen.updatetimecounter <= screen.updatetime)
|
|
continue;
|
|
|
|
screen.updatetimecounter = screen.updatetime > 0 ? 0 : -1;
|
|
|
|
auto state_dict = GetTrainState(screen.parameters);
|
|
|
|
state_dict->insert("touches", *screen.touch_list);
|
|
screen.touch_list->clear();
|
|
|
|
Application.request({screen.script, state_dict, screen.rt});
|
|
}
|
|
}
|
|
|
|
void TTrain::update_script_screens()
|
|
{
|
|
auto &queue{Application.screens()};
|
|
for (auto &entry : m_scriptscreens)
|
|
{
|
|
if (false == queue.due(*entry.screen))
|
|
{
|
|
continue;
|
|
}
|
|
auto input{GetTrainState(entry.parameters)};
|
|
input->insert("touches", *entry.touch_list);
|
|
entry.touch_list->clear();
|
|
queue.submit(entry.screen, std::move(input), id());
|
|
}
|
|
}
|
|
|
|
bool TTrain::find_screen_surface(std::string const &Target, std::string_view const Kind, TSubModel *&Submodel, ITexture *&Texture) const
|
|
{
|
|
Submodel = DynamicObject->mdKabina ? DynamicObject->mdKabina->GetFromName(Target) :
|
|
DynamicObject->mdLowPolyInt ? DynamicObject->mdLowPolyInt->GetFromName(Target) :
|
|
nullptr;
|
|
if (Submodel == nullptr)
|
|
{
|
|
WriteLog(std::format("{}: submodel {} not found - Ignoring screen", Kind, Target));
|
|
return false;
|
|
}
|
|
auto const material{Submodel->GetMaterial()};
|
|
if (material <= 0)
|
|
{
|
|
// sub model nie posiada tekstury lub tekstura wymienna - nie obslugiwana
|
|
WriteLog(std::format("{}: invalid texture id {} - Ignoring screen", Kind, material));
|
|
return false;
|
|
}
|
|
|
|
Texture = &GfxRenderer->Texture(GfxRenderer->Material(material)->GetTexture(0));
|
|
return true;
|
|
}
|
|
|
|
void TTrain::load_script_screen(cParser &Parser, script_language const Language)
|
|
{
|
|
script_screen_entry entry;
|
|
// the block is read whole even when the script screens are off
|
|
entry.config.deserialize(Parser);
|
|
if (entry.config.script.empty())
|
|
{
|
|
return;
|
|
}
|
|
if (auto path{script_screens::screen_script_path(DynamicObject->asBaseDir, entry.config.script)}; path.has_value())
|
|
{
|
|
entry.config.script = std::move(*path);
|
|
}
|
|
else
|
|
{
|
|
ErrorLog(std::format("Bad script screen: \"{}\" leads outside the game's folder", entry.config.script));
|
|
return;
|
|
}
|
|
|
|
TSubModel *submodel{nullptr};
|
|
ITexture *texture{nullptr};
|
|
auto &queue{Application.screens()};
|
|
if (false == queue.runs(Language))
|
|
{
|
|
// the screens of the language are off
|
|
return;
|
|
}
|
|
if (entry.config.target != "none" &&
|
|
false == find_screen_surface(entry.config.target, Language == script_language::lua ? "Lua Screen" : "WASM Screen", submodel, texture))
|
|
{
|
|
return;
|
|
}
|
|
|
|
entry.screen = queue.acquire({.kind = script_screen_kind::cab,
|
|
.language = Language,
|
|
.script = entry.config.script,
|
|
.key = std::format("cab:{}:{}:{}", DynamicObject->name(), entry.config.target, entry.config.script),
|
|
.texture = texture,
|
|
.frames = entry.config.frames});
|
|
if (entry.screen == nullptr)
|
|
{
|
|
return;
|
|
}
|
|
if (texture != nullptr)
|
|
{
|
|
// make the surface static so it doesn't get destroyed by garbage collector if the user spends long time outside cab
|
|
texture->create(true);
|
|
}
|
|
if (false == entry.config.parameters.empty())
|
|
{
|
|
entry.parameters = dictionary_source(entry.config.parameters);
|
|
}
|
|
entry.touch_list = std::make_shared<std::vector<glm::vec2>>();
|
|
if (submodel != nullptr)
|
|
{
|
|
submodel->screen_touch_list = entry.touch_list;
|
|
}
|
|
m_scriptscreens.emplace_back(std::move(entry));
|
|
}
|
|
|
|
const TTrain::screenentry_sequence &TTrain::get_screens()
|
|
{
|
|
update_screens(Timer::GetDeltaTime());
|
|
return m_screens;
|
|
}
|