16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-22 23:19:19 +02:00

gui changes, consist teleport command, etc

This commit is contained in:
milek7
2019-04-02 20:42:18 +02:00
parent 691f0f28b2
commit 155217243c
18 changed files with 124 additions and 44 deletions

View File

@@ -1519,6 +1519,44 @@ TDynamicObject::~TDynamicObject() {
SafeDeleteArray( pAnimated ); // lista animowanych submodeli SafeDeleteArray( pAnimated ); // lista animowanych submodeli
} }
void TDynamicObject::place_on_track(TTrack *Track, double fDist, bool Reversed)
{
for( auto &axle : m_axlesounds ) {
// wyszukiwanie osi (0 jest na końcu, dlatego dodajemy długość?)
axle.distance = (
Reversed ?
-axle.offset :
( axle.offset + MoverParameters->Dim.L ) ) + fDist;
}
double fAxleDistHalf = fAxleDist * 0.5;
// przesuwanie pojazdu tak, aby jego początek był we wskazanym miejcu
fDist -= 0.5 * MoverParameters->Dim.L; // dodajemy pół długości pojazdu, bo ustawiamy jego środek (zliczanie na minus)
switch (iNumAxles) {
// Ra: pojazdy wstawiane są na tor początkowy, a potem przesuwane
case 2: // ustawianie osi na torze
Axle0.Init(Track, this, iDirection ? 1 : -1);
Axle0.Move((iDirection ? fDist : -fDist) + fAxleDistHalf, false);
Axle1.Init(Track, this, iDirection ? 1 : -1);
Axle1.Move((iDirection ? fDist : -fDist) - fAxleDistHalf, false); // false, żeby nie generować eventów
break;
case 4:
Axle0.Init(Track, this, iDirection ? 1 : -1);
Axle0.Move((iDirection ? fDist : -fDist) + (fAxleDistHalf + MoverParameters->ADist * 0.5), false);
Axle1.Init(Track, this, iDirection ? 1 : -1);
Axle1.Move((iDirection ? fDist : -fDist) - (fAxleDistHalf + MoverParameters->ADist * 0.5), false);
// Axle2.Init(Track,this,iDirection?1:-1);
// Axle2.Move((iDirection?fDist:-fDist)-(fAxleDistHalf-MoverParameters->ADist*0.5),false);
// Axle3.Init(Track,this,iDirection?1:-1);
// Axle3.Move((iDirection?fDist:-fDist)+(fAxleDistHalf-MoverParameters->ADist*0.5),false);
break;
}
// potrzebne do wyliczenia aktualnej pozycji; nie może być zero, bo nie przeliczy pozycji
// teraz jeszcze trzeba przypisać pojazdy do nowego toru, bo przesuwanie początkowe osi nie
// zrobiło tego
Move( 0.0001 );
ABuCheckMyTrack(); // zmiana toru na ten, co oś Axle0 (oś z przodu)
}
double double
TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424" TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
std::string BaseDir, // z którego katalogu wczytany, np. "PKP/EU07" std::string BaseDir, // z którego katalogu wczytany, np. "PKP/EU07"
@@ -1964,13 +2002,6 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
smBuforPrawy[ i ]->WillBeAnimated(); smBuforPrawy[ i ]->WillBeAnimated();
} }
} }
for( auto &axle : m_axlesounds ) {
// wyszukiwanie osi (0 jest na końcu, dlatego dodajemy długość?)
axle.distance = (
Reversed ?
-axle.offset :
( axle.offset + MoverParameters->Dim.L ) ) + fDist;
}
// McZapkie-250202 end. // McZapkie-250202 end.
Track->AddDynamicObject(this); // wstawiamy do toru na pozycję 0, a potem przesuniemy Track->AddDynamicObject(this); // wstawiamy do toru na pozycję 0, a potem przesuniemy
// McZapkie: zmieniono na ilosc osi brane z chk // McZapkie: zmieniono na ilosc osi brane z chk
@@ -1981,33 +2012,8 @@ TDynamicObject::Init(std::string Name, // nazwa pojazdu, np. "EU07-424"
std::max( MoverParameters->BDist, MoverParameters->ADist ), std::max( MoverParameters->BDist, MoverParameters->ADist ),
0.2, //żeby się dało wektory policzyć 0.2, //żeby się dało wektory policzyć
MoverParameters->Dim.L - 0.2 ); // nie mogą być za daleko bo będzie "walenie w mur" MoverParameters->Dim.L - 0.2 ); // nie mogą być za daleko bo będzie "walenie w mur"
double fAxleDistHalf = fAxleDist * 0.5; place_on_track(Track, fDist, Reversed);
// przesuwanie pojazdu tak, aby jego początek był we wskazanym miejcu initial_track = MyTrack;
fDist -= 0.5 * MoverParameters->Dim.L; // dodajemy pół długości pojazdu, bo ustawiamy jego środek (zliczanie na minus)
switch (iNumAxles) {
// Ra: pojazdy wstawiane są na tor początkowy, a potem przesuwane
case 2: // ustawianie osi na torze
Axle0.Init(Track, this, iDirection ? 1 : -1);
Axle0.Move((iDirection ? fDist : -fDist) + fAxleDistHalf, false);
Axle1.Init(Track, this, iDirection ? 1 : -1);
Axle1.Move((iDirection ? fDist : -fDist) - fAxleDistHalf, false); // false, żeby nie generować eventów
break;
case 4:
Axle0.Init(Track, this, iDirection ? 1 : -1);
Axle0.Move((iDirection ? fDist : -fDist) + (fAxleDistHalf + MoverParameters->ADist * 0.5), false);
Axle1.Init(Track, this, iDirection ? 1 : -1);
Axle1.Move((iDirection ? fDist : -fDist) - (fAxleDistHalf + MoverParameters->ADist * 0.5), false);
// Axle2.Init(Track,this,iDirection?1:-1);
// Axle2.Move((iDirection?fDist:-fDist)-(fAxleDistHalf-MoverParameters->ADist*0.5),false);
// Axle3.Init(Track,this,iDirection?1:-1);
// Axle3.Move((iDirection?fDist:-fDist)+(fAxleDistHalf-MoverParameters->ADist*0.5),false);
break;
}
// potrzebne do wyliczenia aktualnej pozycji; nie może być zero, bo nie przeliczy pozycji
// teraz jeszcze trzeba przypisać pojazdy do nowego toru, bo przesuwanie początkowe osi nie
// zrobiło tego
Move( 0.0001 );
ABuCheckMyTrack(); // zmiana toru na ten, co oś Axle0 (oś z przodu)
// Ra: ustawienie pozycji do obliczania sprzęgów // Ra: ustawienie pozycji do obliczania sprzęgów
MoverParameters->Loc = { MoverParameters->Loc = {
-vPosition.x, -vPosition.x,

View File

@@ -508,8 +508,12 @@ private:
TTractionParam tmpTraction; TTractionParam tmpTraction;
double fAdjustment; // korekcja - docelowo przenieść do TrkFoll.cpp wraz z odległością od poprzedniego double fAdjustment; // korekcja - docelowo przenieść do TrkFoll.cpp wraz z odległością od poprzedniego
TTrack *initial_track = nullptr;
TDynamicObject(); TDynamicObject();
~TDynamicObject(); ~TDynamicObject();
void place_on_track(TTrack *Track, double fDist, bool Reversed);
// zwraca długość pojazdu albo 0, jeśli błąd // zwraca długość pojazdu albo 0, jeśli błąd
double Init( double Init(
std::string Name, std::string BaseDir, std::string asReplacableSkin, std::string Type_Name, std::string Name, std::string BaseDir, std::string asReplacableSkin, std::string Type_Name,

View File

@@ -882,6 +882,10 @@ global_settings::ConfigParse(cParser &Parser) {
Parser.getTokens(1); Parser.getTokens(1);
Parser >> map_highlight_distance; Parser >> map_highlight_distance;
} }
else if (token == "gui.screensscale") {
Parser.getTokens(1);
Parser >> gui_screensscale;
}
} while ((token != "") && (token != "endconfig")); //(!Parser->EndOfFile) } while ((token != "") && (token != "endconfig")); //(!Parser->EndOfFile)
// na koniec trochę zależności // na koniec trochę zależności
if (!bLoadTraction) // wczytywanie drutów i słupów if (!bLoadTraction) // wczytywanie drutów i słupów

View File

@@ -208,6 +208,7 @@ struct global_settings {
bool gfx_usegles = false; bool gfx_usegles = false;
float map_highlight_distance = 3000.0f; float map_highlight_distance = 3000.0f;
float gui_screensscale = 0.5f;
struct extraviewport_config { struct extraviewport_config {
std::string monitor; std::string monitor;

View File

@@ -31,6 +31,8 @@ bool TTrackFollower::Init(TTrack *pTrack, TDynamicObject *NewOwner, double fDir)
fDirection = fDir; fDirection = fDir;
Owner = NewOwner; Owner = NewOwner;
SetCurrentTrack(pTrack, 0); SetCurrentTrack(pTrack, 0);
fCurrentDistance = 0.0;
fDirection = 1.0;
iEventFlag = 3; // na torze startowym również wykonać eventy 1/2 iEventFlag = 3; // na torze startowym również wykonać eventy 1/2
iEventallFlag = 3; iEventallFlag = 3;
if ((pCurrentSegment)) // && (pCurrentSegment->GetLength()<fFirstDistance)) if ((pCurrentSegment)) // && (pCurrentSegment->GetLength()<fFirstDistance))

View File

@@ -150,6 +150,10 @@ double eu07_application::generate_sync() {
return sync; return sync;
} }
void eu07_application::queue_quit() {
glfwSetWindowShouldClose(m_windows[0], GLFW_TRUE);
}
int int
eu07_application::run() { eu07_application::run() {

View File

@@ -84,6 +84,8 @@ public:
// generate network sync verification number // generate network sync verification number
double double
generate_sync(); generate_sync();
void
queue_quit();
private: private:
// types // types

View File

@@ -251,6 +251,8 @@ commanddescription_sequence Commands_descriptions = {
{ "insertmodel", command_target::simulation, command_mode::oneoff }, { "insertmodel", command_target::simulation, command_mode::oneoff },
{ "deletemodel", command_target::simulation, command_mode::oneoff }, { "deletemodel", command_target::simulation, command_mode::oneoff },
{ "trainsetmove", command_target::simulation, command_mode::oneoff }, { "trainsetmove", command_target::simulation, command_mode::oneoff },
{ "consistteleport", command_target::simulation, command_mode::oneoff },
{ "notifyquit", command_target::simulation, command_mode::oneoff },
}; };
} // simulation } // simulation

View File

@@ -245,6 +245,9 @@ enum class user_command {
insertmodel, insertmodel,
deletemodel, deletemodel,
dynamicmove, dynamicmove,
consistteleport,
quitsimulation,
none = -1 none = -1
}; };

View File

@@ -237,7 +237,7 @@ driver_ui::render_() {
m_relay.post(user_command::pausetoggle, 0.0, 0.0, GLFW_PRESS, 0); m_relay.post(user_command::pausetoggle, 0.0, 0.0, GLFW_PRESS, 0);
} }
if( ImGui::Button( locale::strings[ locale::string::driver_pause_quit ].c_str(), ImVec2( popupwidth, 0 ) ) ) { if( ImGui::Button( locale::strings[ locale::string::driver_pause_quit ].c_str(), ImVec2( popupwidth, 0 ) ) ) {
glfwSetWindowShouldClose( m_window, 1 ); m_relay.post(user_command::quitsimulation, 0.0, 0.0, GLFW_PRESS, 0);
} }
if (!m_paused) if (!m_paused)
{ {

View File

@@ -160,8 +160,8 @@ void network::client::update()
// client // client
std::tuple<double, double, command_queue::commands_map> network::client::get_next_delta(int counter) std::tuple<double, double, command_queue::commands_map> network::client::get_next_delta(int counter)
{ {
if (counter == 1) {
auto now = std::chrono::high_resolution_clock::now(); auto now = std::chrono::high_resolution_clock::now();
if (counter == 1) {
frame_time = now - last_frame; frame_time = now - last_frame;
last_frame = now; last_frame = now;
} }
@@ -194,6 +194,7 @@ std::tuple<double, double, command_queue::commands_map> network::client::get_nex
} }
delta_queue.pop(); delta_queue.pop();
last_update = now;
return std::make_tuple(entry.dt, entry.sync, entry.commands); return std::make_tuple(entry.dt, entry.sync, entry.commands);
} else { } else {

View File

@@ -90,6 +90,7 @@ namespace network
float jitteriness = 1.0f; float jitteriness = 1.0f;
float consume_counter = 0.0f; float consume_counter = 0.0f;
std::chrono::high_resolution_clock::time_point last_update;
std::chrono::high_resolution_clock::time_point last_frame; std::chrono::high_resolution_clock::time_point last_frame;
std::chrono::high_resolution_clock::duration frame_time; std::chrono::high_resolution_clock::duration frame_time;

View File

@@ -2170,6 +2170,9 @@ bool opengl_renderer::Render(TDynamicObject *Dynamic)
{ {
glDebug("Render TDynamicObject"); glDebug("Render TDynamicObject");
if (!Global.render_cab && Global.pCamera.m_owner == Dynamic)
return false;
Dynamic->renderme = m_renderpass.pass_camera.visible(Dynamic); Dynamic->renderme = m_renderpass.pass_camera.visible(Dynamic);
if (false == Dynamic->renderme) if (false == Dynamic->renderme)
{ {
@@ -3184,6 +3187,8 @@ void opengl_renderer::Render_Alpha(scene::lines_node const &Lines)
bool opengl_renderer::Render_Alpha(TDynamicObject *Dynamic) bool opengl_renderer::Render_Alpha(TDynamicObject *Dynamic)
{ {
if (!Global.render_cab && Global.pCamera.m_owner == Dynamic)
return false;
if (false == Dynamic->renderme) if (false == Dynamic->renderme)
{ {

View File

@@ -23,6 +23,7 @@ http://mozilla.org/MPL/2.0/.
#include "lightarray.h" #include "lightarray.h"
#include "scene.h" #include "scene.h"
#include "Train.h" #include "Train.h"
#include "application.h"
namespace simulation { namespace simulation {
@@ -232,6 +233,37 @@ void state_manager::process_commands() {
vehicle->move_set(commanddata.param1); vehicle->move_set(commanddata.param1);
} }
if (commanddata.command == user_command::consistteleport) {
std::istringstream ss(commanddata.payload);
std::string track_name;
std::string vehicle_name;
std::getline(ss, vehicle_name, '%');
std::getline(ss, track_name, '%');
TTrack *track = simulation::Paths.find(track_name);
TDynamicObject *vehicle = simulation::Vehicles.find(vehicle_name);
while (vehicle) {
if (vehicle->Next())
vehicle = vehicle->Next();
else
break;
}
double offset = 0.0;
while (vehicle) {
vehicle->place_on_track(track, offset, false);
offset += vehicle->MoverParameters->Dim.L;
vehicle = vehicle->Prev();
}
}
if (commanddata.command == user_command::quitsimulation) {
Application.queue_quit();
}
if (DebugModeFlag) { if (DebugModeFlag) {
if (commanddata.command == user_command::timejump) { if (commanddata.command == user_command::timejump) {
Time.update(commanddata.param1); Time.update(commanddata.param1);

View File

@@ -116,8 +116,9 @@ init() {
"Vehicle parameters", "Vehicle parameters",
"Radiostop", "Radiostop",
"Reset trainset", "Reset position",
"Reset main pipe", "Stop and repair",
"Refill main pipe",
"Move +500m", "Move +500m",
"Move -500m", "Move -500m",
@@ -322,7 +323,8 @@ init() {
u8"Parametry pojazdu", u8"Parametry pojazdu",
u8"Radiostop", u8"Radiostop",
u8"Zresetuj skład", u8"Zresetuj pozycję",
u8"Zatrzymaj i napraw",
u8"Napełnij ZG", u8"Napełnij ZG",
u8"Przesuń +500m", u8"Przesuń +500m",
u8"Przesuń -500m", u8"Przesuń -500m",

View File

@@ -105,6 +105,7 @@ enum string {
vehicleparams_window, vehicleparams_window,
vehicleparams_radiostop, vehicleparams_radiostop,
vehicleparams_resetposition,
vehicleparams_reset, vehicleparams_reset,
vehicleparams_resetpipe, vehicleparams_resetpipe,
vehicleparams_move500f, vehicleparams_move500f,

View File

@@ -196,7 +196,8 @@ bool ui_layer::on_key(int const Key, int const Action)
if (m_quit_active) if (m_quit_active)
{ {
if (Key == GLFW_KEY_Y) { if (Key == GLFW_KEY_Y) {
glfwSetWindowShouldClose(m_window, GLFW_TRUE); command_relay relay;
relay.post(user_command::quitsimulation, 0.0, 0.0, GLFW_PRESS, 0);
return true; return true;
} else if (Key == GLFW_KEY_N) { } else if (Key == GLFW_KEY_N) {
m_quit_active = false; m_quit_active = false;
@@ -266,8 +267,10 @@ void ui_layer::render_quit_widget()
ImGui::SetNextWindowSize(ImVec2(0, 0)); ImGui::SetNextWindowSize(ImVec2(0, 0));
ImGui::Begin(LOC_STR(ui_quit), &m_quit_active, ImGuiWindowFlags_NoResize); ImGui::Begin(LOC_STR(ui_quit), &m_quit_active, ImGuiWindowFlags_NoResize);
ImGui::TextUnformatted(LOC_STR(ui_quit_simulation_q)); ImGui::TextUnformatted(LOC_STR(ui_quit_simulation_q));
if (ImGui::Button(LOC_STR(ui_yes))) if (ImGui::Button(LOC_STR(ui_yes))) {
glfwSetWindowShouldClose(m_window, GLFW_TRUE); command_relay relay;
relay.post(user_command::quitsimulation, 0.0, 0.0, GLFW_PRESS, 0);
}
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(LOC_STR(ui_no))) if (ImGui::Button(LOC_STR(ui_no)))
m_quit_active = false; m_quit_active = false;

View File

@@ -35,7 +35,9 @@ void ui::vehicleparams_panel::render_contents()
glm::vec2 uv0 = glm::vec2(proj * glm::vec3(0.0f, 1.0f, 1.0f)); glm::vec2 uv0 = glm::vec2(proj * glm::vec3(0.0f, 1.0f, 1.0f));
glm::vec2 uv1 = glm::vec2(proj * glm::vec3(1.0f, 0.0f, 1.0f)); glm::vec2 uv1 = glm::vec2(proj * glm::vec3(1.0f, 0.0f, 1.0f));
ImGui::Image(reinterpret_cast<void*>(std::get<1>(entry)->shared_tex), ImVec2(500, 500 * aspect), ImVec2(uv0.x, uv0.y), ImVec2(uv1.x, uv1.y)); glm::vec2 size = glm::vec2(500.0f, 500.0f * aspect) * Global.gui_screensscale;
ImGui::Image(reinterpret_cast<void*>(std::get<1>(entry)->shared_tex), ImVec2(size.x, size.y), ImVec2(uv0.x, uv0.y), ImVec2(uv1.x, uv1.y));
} }
} }
} }
@@ -192,6 +194,11 @@ void ui::vehicleparams_panel::render_contents()
m_relay.post(user_command::resetconsist, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); m_relay.post(user_command::resetconsist, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name());
ImGui::SameLine(); ImGui::SameLine();
if (ImGui::Button(LOC_STR(vehicleparams_resetposition))) {
std::string payload = vehicle_ptr->name() + '%' + vehicle_ptr->initial_track->name();
m_relay.post(user_command::consistteleport, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &payload);
}
if (ImGui::Button(LOC_STR(vehicleparams_resetpipe))) if (ImGui::Button(LOC_STR(vehicleparams_resetpipe)))
m_relay.post(user_command::fillcompressor, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); m_relay.post(user_command::fillcompressor, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name());
ImGui::SameLine(); ImGui::SameLine();