From e6e5d6645b1b903c4d2cbc12506c400deee2c475 Mon Sep 17 00:00:00 2001 From: milek7 Date: Sun, 17 Mar 2019 23:55:40 +0100 Subject: [PATCH] shader fix, vehicle move feature --- DynObj.cpp | 14 ++++++++++++++ DynObj.h | 1 + Train.cpp | 25 ++----------------------- Train.h | 4 ---- command.cpp | 2 +- command.h | 2 +- simulation.cpp | 6 ++++++ translation.cpp | 4 ++++ translation.h | 2 ++ widgets/map.cpp | 4 ++-- widgets/vehicleparams.cpp | 10 +++++++++- 11 files changed, 42 insertions(+), 32 deletions(-) diff --git a/DynObj.cpp b/DynObj.cpp index 48b441bc..c3a3b7eb 100644 --- a/DynObj.cpp +++ b/DynObj.cpp @@ -3507,6 +3507,20 @@ glm::dvec3 TDynamicObject::get_future_movement() const return m_future_movement; } +void TDynamicObject::move_set(double distance) +{ + TDynamicObject *d = this; + while( d ) { + d->Move( distance * d->DirectionGet() ); + d = d->Next(); // pozostałe też + } + d = Prev(); + while( d ) { + d->Move( distance * d->DirectionGet() ); + d = d->Prev(); // w drugą stronę też + } +} + bool TDynamicObject::FastUpdate(double dt) { if (dt == 0.0) diff --git a/DynObj.h b/DynObj.h index 40fdd6ec..ba3ce0a4 100644 --- a/DynObj.h +++ b/DynObj.h @@ -633,6 +633,7 @@ private: void DestinationSet(std::string to, std::string numer); void OverheadTrack(float o); glm::dvec3 get_future_movement() const; + void move_set(double distance); double MED[9][8]; // lista zmiennych do debugowania hamulca ED static std::string const MED_labels[ 8 ]; diff --git a/Train.cpp b/Train.cpp index 3e3b6f8a..50351316 100644 --- a/Train.cpp +++ b/Train.cpp @@ -351,7 +351,6 @@ TTrain::commandhandler_map const TTrain::m_commandhandlers = { { user_command::generictoggle8, &TTrain::OnCommand_generictoggle }, { user_command::generictoggle9, &TTrain::OnCommand_generictoggle }, - { user_command::vehiclemove, &TTrain::OnCommand_vehiclemove }, { user_command::vehiclemoveforwards, &TTrain::OnCommand_vehiclemoveforwards }, { user_command::vehiclemovebackwards, &TTrain::OnCommand_vehiclemovebackwards }, { user_command::vehicleboost, &TTrain::OnCommand_vehicleboost }, @@ -5008,38 +5007,18 @@ void TTrain::OnCommand_cabchangebackward( TTrain *Train, command_data const &Com } } -void TTrain::vehiclemove(float distance) { - TDynamicObject *d = DynamicObject; - while( d ) { - d->Move( distance * d->DirectionGet() ); - d = d->Next(); // pozostałe też - } - d = DynamicObject->Prev(); - while( d ) { - d->Move( distance * d->DirectionGet() ); - d = d->Prev(); // w drugą stronę też - } -} - -void TTrain::OnCommand_vehiclemove(TTrain *Train, const command_data &Command) { - if (Command.action == GLFW_RELEASE || !DebugModeFlag) - return; - - Train->vehiclemove(Command.param1); -} - void TTrain::OnCommand_vehiclemoveforwards(TTrain *Train, const command_data &Command) { if (Command.action == GLFW_RELEASE || !DebugModeFlag) return; - Train->vehiclemove(100.0); + Train->DynamicObject->move_set(100.0); } void TTrain::OnCommand_vehiclemovebackwards(TTrain *Train, const command_data &Command) { if (Command.action == GLFW_RELEASE || !DebugModeFlag) return; - Train->vehiclemove(-100.0); + Train->DynamicObject->move_set(-100.0); } void TTrain::OnCommand_vehicleboost(TTrain *Train, const command_data &Command) { diff --git a/Train.h b/Train.h index be898179..8071fcb1 100644 --- a/Train.h +++ b/Train.h @@ -349,14 +349,10 @@ class TTrain static void OnCommand_cabchangeforward( TTrain *Train, command_data const &Command ); static void OnCommand_cabchangebackward( TTrain *Train, command_data const &Command ); static void OnCommand_generictoggle( TTrain *Train, command_data const &Command ); - static void OnCommand_vehiclemove( TTrain *Train, command_data const &Command ); static void OnCommand_vehiclemoveforwards( TTrain *Train, command_data const &Command ); static void OnCommand_vehiclemovebackwards( TTrain *Train, command_data const &Command ); static void OnCommand_vehicleboost( TTrain *Train, command_data const &Command ); - void vehiclemove(float distance); - - // members TDynamicObject *DynamicObject { nullptr }; // przestawia zmiana pojazdu [F5] TMoverParameters *mvControlled { nullptr }; // człon, w którym sterujemy silnikiem diff --git a/command.cpp b/command.cpp index d0f4651f..18df88b3 100644 --- a/command.cpp +++ b/command.cpp @@ -236,7 +236,6 @@ commanddescription_sequence Commands_descriptions = { { "setdatetime", command_target::simulation, command_mode::oneoff }, { "setweather", command_target::simulation, command_mode::oneoff }, { "settemperature", command_target::simulation, command_mode::oneoff }, - { "vehiclemove", command_target::vehicle, command_mode::oneoff }, { "vehiclemoveforwards", command_target::vehicle, command_mode::oneoff }, { "vehiclemovebackwards", command_target::vehicle, command_mode::oneoff }, { "vehicleboost", command_target::vehicle, command_mode::oneoff }, @@ -249,6 +248,7 @@ commanddescription_sequence Commands_descriptions = { { "setlight", command_target::simulation, command_mode::oneoff }, { "insertmodel", command_target::simulation, command_mode::oneoff }, { "deletemodel", command_target::simulation, command_mode::oneoff }, + { "trainsetmove", command_target::simulation, command_mode::oneoff }, }; } // simulation diff --git a/command.h b/command.h index c2d24809..c53d8f65 100644 --- a/command.h +++ b/command.h @@ -230,7 +230,6 @@ enum class user_command { setdatetime, setweather, settemperature, - vehiclemove, vehiclemoveforwards, vehiclemovebackwards, vehicleboost, @@ -243,6 +242,7 @@ enum class user_command { setlight, insertmodel, deletemodel, + dynamicmove, none = -1 }; diff --git a/simulation.cpp b/simulation.cpp index e8e34cb0..d83f730b 100644 --- a/simulation.cpp +++ b/simulation.cpp @@ -203,6 +203,12 @@ void state_manager::process_commands() { } } + if (commanddata.command == user_command::dynamicmove) { + TDynamicObject *vehicle = simulation::Vehicles.find(commanddata.payload); + if (vehicle) + vehicle->move_set(commanddata.param1); + } + if (DebugModeFlag) { if (commanddata.command == user_command::timejump) { Time.update(commanddata.param1); diff --git a/translation.cpp b/translation.cpp index b57ce2ca..e6346076 100644 --- a/translation.cpp +++ b/translation.cpp @@ -117,6 +117,8 @@ init() { "Vehicle parameters", "Radiostop", "Reset trainset", + "Move +500m", + "Move -500m", "master controller", "master controller", @@ -320,6 +322,8 @@ init() { u8"Parametry pojazdu", u8"Radiostop", u8"Zresetuj skład", + u8"Przesuń +500m", + u8"Przesuń -500m", u8"nastawnik jazdy", u8"nastawnik jazdy", diff --git a/translation.h b/translation.h index a1be84cd..15bede4f 100644 --- a/translation.h +++ b/translation.h @@ -106,6 +106,8 @@ enum string { vehicleparams_window, vehicleparams_radiostop, vehicleparams_reset, + vehicleparams_move500f, + vehicleparams_move500b, cab_mainctrl, cab_jointctrl, diff --git a/widgets/map.cpp b/widgets/map.cpp index 8bc195dd..f30cefc3 100644 --- a/widgets/map.cpp +++ b/widgets/map.cpp @@ -18,7 +18,7 @@ ui::map_panel::map_panel() : ui_panel(LOC_STR(ui_map), false) gl::shader frag("map.frag"); m_track_shader = std::unique_ptr(new gl::program({vert, frag})); - if (GLAD_GL_EXT_geometry_shader) { + if (!Global.gfx_usegles || GLAD_GL_EXT_geometry_shader) { gl::shader poi_frag("map_poi.frag"); gl::shader poi_geom("map_poi.geom"); m_poi_shader = std::unique_ptr(new gl::program({vert, poi_frag, poi_geom})); @@ -123,7 +123,7 @@ void ui::map_panel::render_map_texture(glm::mat4 transform, glm::vec2 surface_si scene_ubo->update(scene_ubs); GfxRenderer.Draw_Geometry(m_switch_handles.begin(), m_switch_handles.end()); - if (GLAD_GL_EXT_geometry_shader) { + if (!Global.gfx_usegles || GLAD_GL_EXT_geometry_shader) { GfxRenderer.Bind_Texture(0, m_icon_atlas); m_poi_shader->bind(); scene_ubs.scene_extra = glm::vec3(1.0f / (surface_size / 200.0f), 1.0f); diff --git a/widgets/vehicleparams.cpp b/widgets/vehicleparams.cpp index ee1ff0a7..a8a7c3c8 100644 --- a/widgets/vehicleparams.cpp +++ b/widgets/vehicleparams.cpp @@ -186,9 +186,17 @@ void ui::vehicleparams_panel::render_contents() if (ImGui::Button(LOC_STR(vehicleparams_radiostop))) m_relay.post(user_command::radiostop, 0.0, 0.0, GLFW_PRESS, 0, vehicle_ptr->GetPosition()); - ImGui::SameLine(); if (ImGui::Button(LOC_STR(vehicleparams_reset))) m_relay.post(user_command::resettrainset, 0.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); + ImGui::SameLine(); + + if (ImGui::Button(LOC_STR(vehicleparams_move500f))) + m_relay.post(user_command::dynamicmove, 500.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); + ImGui::SameLine(); + + if (ImGui::Button(LOC_STR(vehicleparams_move500b))) + m_relay.post(user_command::dynamicmove, -500.0, 0.0, GLFW_PRESS, 0, glm::vec3(0.0f), &vehicle_ptr->name()); + ImGui::SameLine(); }